Skip to content

Commit

Permalink
[spv] put NonWritable on buffer variable itself (gfx-rs#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark authored Feb 2, 2021
1 parent 5def021 commit e05baa2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 47 deletions.
71 changes: 25 additions & 46 deletions src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,24 +709,19 @@ impl Writer {
block: true,
ref members,
} => {
//TODO: put NonWritable/NonReadable on the global variable instead?
let storage_access = match self.struct_type_handles.get(&handle) {
Some(&access) => {
let decoration = if access.is_empty() {
spirv::Decoration::Block
} else {
spirv::Decoration::BufferBlock
};
self.annotations
.push(super::instructions::instruction_decorate(
id,
decoration,
&[],
));
access
}
None => crate::StorageAccess::empty(),
};
if let Some(&access) = self.struct_type_handles.get(&handle) {
let decoration = if access.is_empty() {
spirv::Decoration::Block
} else {
spirv::Decoration::BufferBlock
};
self.annotations
.push(super::instructions::instruction_decorate(
id,
decoration,
&[],
));
}

let mut current_offset = 0;
let mut member_ids = Vec::with_capacity(members.len());
Expand Down Expand Up @@ -756,16 +751,6 @@ impl Writer {
}
}

if storage_access == crate::StorageAccess::LOAD {
self.annotations
.push(super::instructions::instruction_member_decorate(
id,
index as u32,
spirv::Decoration::NonWritable,
&[],
));
}

if let crate::TypeInner::Matrix {
columns,
rows: _,
Expand Down Expand Up @@ -939,24 +924,18 @@ impl Writer {
}
}

if let crate::TypeInner::Image {
class: crate::ImageClass::Storage(_),
..
} = ir_module.types[global_variable.ty].inner
{
let decoration = match global_variable.storage_access {
crate::StorageAccess::LOAD => Some(spirv::Decoration::NonWritable),
crate::StorageAccess::STORE => Some(spirv::Decoration::NonReadable),
_ => None,
};
if let Some(decoration) = decoration {
self.annotations
.push(super::instructions::instruction_decorate(
id,
decoration,
&[],
));
}
let access_decoration = match global_variable.storage_access {
crate::StorageAccess::LOAD => Some(spirv::Decoration::NonWritable),
crate::StorageAccess::STORE => Some(spirv::Decoration::NonReadable),
_ => None,
};
if let Some(decoration) = access_decoration {
self.annotations
.push(super::instructions::instruction_decorate(
id,
decoration,
&[],
));
}

if let Some(interpolation) = global_variable.interpolation {
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/snapshots__boids.spvasm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ OpMemberDecorate %45 1 Offset 8
OpDecorate %47 ArrayStride 16
OpDecorate %49 BufferBlock
OpMemberDecorate %49 0 Offset 0
OpDecorate %50 NonWritable
OpDecorate %50 DescriptorSet 0
OpDecorate %50 Binding 1
OpDecorate %121 Block
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/snapshots__shadow.spvasm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OpMemberDecorate %97 2 Offset 80
OpDecorate %99 ArrayStride 96
OpDecorate %101 BufferBlock
OpMemberDecorate %101 0 Offset 0
OpMemberDecorate %101 0 NonWritable
OpDecorate %102 NonWritable
OpDecorate %102 DescriptorSet 0
OpDecorate %102 Binding 1
OpDecorate %111 Location 1
Expand Down

0 comments on commit e05baa2

Please sign in to comment.