Skip to content

Commit

Permalink
[spv-out] Decorate all non-uniform binding array access chains as `No…
Browse files Browse the repository at this point in the history
…nUniform`, not just buffer binding arrays.

Apply the `NonUniform` decoration to the results of all access chains rooted in binding arrays that use non-uniform values as indices, regardless of the binding array's element type and address space. Previously, Naga only decorated non-uniform access chains for binding arrays of buffers.
  • Loading branch information
teoxoy committed Dec 7, 2023
1 parent ff7b2c3 commit 2aa8671
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
26 changes: 10 additions & 16 deletions naga/src/back/spv/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ impl<'w> BlockContext<'w> {
// but we expect these checks to almost always succeed, and keeping branches to a
// minimum is essential.
let mut accumulated_checks = None;
// Is true if we are accessing into a binding array of buffers with a non-uniform index.
// Is true if we are accessing into a binding array with a non-uniform index.
let mut is_non_uniform_binding_array = false;

self.temp_list.clear();
Expand All @@ -1473,20 +1473,14 @@ impl<'w> BlockContext<'w> {
if let crate::Expression::GlobalVariable(var_handle) =
self.ir_function.expressions[base]
{
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();
}
}
_ => {}
// The access chain needs to be decorated as NonUniform
// see VUID-RuntimeSpirv-NonUniform-06274
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();
}
}

Expand Down Expand Up @@ -1571,7 +1565,7 @@ 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
// if the binding array was accessed with a non-uniform index
// see VUID-RuntimeSpirv-NonUniform-06274
if is_non_uniform_binding_array {
self.writer
Expand Down
22 changes: 22 additions & 0 deletions naga/tests/out/spv/binding-arrays.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,49 @@ OpMemberDecorate %43 0 Offset 0
OpDecorate %47 Location 0
OpDecorate %47 Flat
OpDecorate %50 Location 0
OpDecorate %90 NonUniform
OpDecorate %91 NonUniform
OpDecorate %113 NonUniform
OpDecorate %114 NonUniform
OpDecorate %115 NonUniform
OpDecorate %116 NonUniform
OpDecorate %140 NonUniform
OpDecorate %141 NonUniform
OpDecorate %142 NonUniform
OpDecorate %143 NonUniform
OpDecorate %179 NonUniform
OpDecorate %180 NonUniform
OpDecorate %207 NonUniform
OpDecorate %208 NonUniform
OpDecorate %223 NonUniform
OpDecorate %224 NonUniform
OpDecorate %239 NonUniform
OpDecorate %240 NonUniform
OpDecorate %260 NonUniform
OpDecorate %261 NonUniform
OpDecorate %262 NonUniform
OpDecorate %263 NonUniform
OpDecorate %284 NonUniform
OpDecorate %285 NonUniform
OpDecorate %286 NonUniform
OpDecorate %287 NonUniform
OpDecorate %308 NonUniform
OpDecorate %309 NonUniform
OpDecorate %310 NonUniform
OpDecorate %311 NonUniform
OpDecorate %332 NonUniform
OpDecorate %333 NonUniform
OpDecorate %334 NonUniform
OpDecorate %335 NonUniform
OpDecorate %356 NonUniform
OpDecorate %357 NonUniform
OpDecorate %358 NonUniform
OpDecorate %359 NonUniform
OpDecorate %380 NonUniform
OpDecorate %381 NonUniform
OpDecorate %382 NonUniform
OpDecorate %383 NonUniform
OpDecorate %405 NonUniform
OpDecorate %406 NonUniform
%2 = OpTypeVoid
%3 = OpTypeInt 32 0
Expand Down

0 comments on commit 2aa8671

Please sign in to comment.