Skip to content

Commit

Permalink
[spv-out] decorate the result of the OpLoad with NonUniform (not …
Browse files Browse the repository at this point in the history
…the access chain) when loading images/samplers (resources in the Handle address space)
  • Loading branch information
teoxoy authored and cwfitzgerald committed Aug 4, 2023
1 parent e51b4af commit c3e35df
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
31 changes: 25 additions & 6 deletions src/back/spv/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ impl<'w> BlockContext<'w> {
None,
));

// Subsequent image operations require the image/sampler to be decorated as NonUniform
// if the image/sampler binding array was accessed with a non-uniform index
// see VUID-RuntimeSpirv-NonUniform-06274
if self.fun_info[index].uniformity.non_uniform_result.is_some() {
self.writer
.decorate_non_uniform_binding_array_access(load_id)?;
}

load_id
}
ref other => {
Expand Down Expand Up @@ -1456,12 +1464,20 @@ impl<'w> BlockContext<'w> {
if let crate::Expression::GlobalVariable(var_handle) =
self.ir_function.expressions[base]
{
let gvar = &self.ir_module.global_variables[var_handle];
if let crate::TypeInner::BindingArray { .. } =
self.ir_module.types[gvar.ty].inner
{
is_non_uniform_binding_array |=
self.fun_info[index].uniformity.non_uniform_result.is_some();
let gvar: &crate::GlobalVariable =
&self.ir_module.global_variables[var_handle];
match gvar.space {
crate::AddressSpace::Storage { .. } | crate::AddressSpace::Uniform => {
if let crate::TypeInner::BindingArray { .. } =
self.ir_module.types[gvar.ty].inner
{
is_non_uniform_binding_array = self.fun_info[index]
.uniformity
.non_uniform_result
.is_some();
}
}
_ => {}
}
}

Expand Down Expand Up @@ -1545,6 +1561,9 @@ impl<'w> BlockContext<'w> {
};
(pointer_id, expr_pointer)
};
// Subsequent load, store and atomic operations require the pointer to be decorated as NonUniform
// if the buffer binding array was accessed with a non-uniform index
// see VUID-RuntimeSpirv-NonUniform-06274
if is_non_uniform_binding_array {
self.writer
.decorate_non_uniform_binding_array_access(pointer_id)?;
Expand Down
44 changes: 22 additions & 22 deletions tests/out/spv/binding-arrays.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ OpMemberDecorate %47 0 Offset 0
OpDecorate %63 Location 0
OpDecorate %63 Flat
OpDecorate %66 Location 0
OpDecorate %95 NonUniform
OpDecorate %118 NonUniform
OpDecorate %120 NonUniform
OpDecorate %145 NonUniform
OpDecorate %147 NonUniform
OpDecorate %183 NonUniform
OpDecorate %211 NonUniform
OpDecorate %227 NonUniform
OpDecorate %243 NonUniform
OpDecorate %264 NonUniform
OpDecorate %266 NonUniform
OpDecorate %288 NonUniform
OpDecorate %290 NonUniform
OpDecorate %312 NonUniform
OpDecorate %314 NonUniform
OpDecorate %336 NonUniform
OpDecorate %338 NonUniform
OpDecorate %360 NonUniform
OpDecorate %362 NonUniform
OpDecorate %384 NonUniform
OpDecorate %386 NonUniform
OpDecorate %409 NonUniform
OpDecorate %96 NonUniform
OpDecorate %119 NonUniform
OpDecorate %121 NonUniform
OpDecorate %146 NonUniform
OpDecorate %148 NonUniform
OpDecorate %184 NonUniform
OpDecorate %212 NonUniform
OpDecorate %228 NonUniform
OpDecorate %244 NonUniform
OpDecorate %265 NonUniform
OpDecorate %267 NonUniform
OpDecorate %289 NonUniform
OpDecorate %291 NonUniform
OpDecorate %313 NonUniform
OpDecorate %315 NonUniform
OpDecorate %337 NonUniform
OpDecorate %339 NonUniform
OpDecorate %361 NonUniform
OpDecorate %363 NonUniform
OpDecorate %385 NonUniform
OpDecorate %387 NonUniform
OpDecorate %410 NonUniform
%2 = OpTypeVoid
%3 = OpTypeInt 32 0
%4 = OpTypeStruct %3
Expand Down

0 comments on commit c3e35df

Please sign in to comment.