From 96b7872f7728526ced73fb2faa1f74cfc77b08d2 Mon Sep 17 00:00:00 2001 From: Inner Daemons <85136135+inner-daemons@users.noreply.github.com> Date: Sun, 15 Mar 2026 15:25:19 -0500 Subject: [PATCH] Fix local_invocation_id and local_invocation_index handling (#9099) Co-authored-by: Andreas Reich --- CHANGELOG.md | 1 + naga/src/back/hlsl/writer.rs | 60 +++++++++++++------ naga/src/back/msl/keywords.rs | 2 + ...20-multiple-local-invocation-index-id.wgsl | 15 +++++ ...-invocation-index-id.compute1.Compute.glsl | 27 +++++++++ .../out/hlsl/spv-subgroup-operations-s.hlsl | 4 +- ...20-multiple-local-invocation-index-id.hlsl | 19 ++++++ ...820-multiple-local-invocation-index-id.ron | 12 ++++ naga/tests/out/hlsl/wgsl-atomicOps-int64.hlsl | 4 +- naga/tests/out/hlsl/wgsl-atomicOps.hlsl | 4 +- naga/tests/out/hlsl/wgsl-globals.hlsl | 4 +- naga/tests/out/hlsl/wgsl-interface.hlsl | 4 +- .../out/hlsl/wgsl-subgroup-operations.hlsl | 4 +- .../wgsl-workgroup-uniform-load-atomic.hlsl | 4 +- .../out/hlsl/wgsl-workgroup-uniform-load.hlsl | 4 +- .../out/hlsl/wgsl-workgroup-var-init.hlsl | 4 +- ...0-multiple-local-invocation-index-id.metal | 28 +++++++++ ...-multiple-local-invocation-index-id.spvasm | 56 +++++++++++++++++ ...20-multiple-local-invocation-index-id.wgsl | 14 +++++ 19 files changed, 235 insertions(+), 35 deletions(-) create mode 100644 naga/tests/in/wgsl/8820-multiple-local-invocation-index-id.wgsl create mode 100644 naga/tests/out/glsl/wgsl-8820-multiple-local-invocation-index-id.compute1.Compute.glsl create mode 100644 naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.hlsl create mode 100644 naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.ron create mode 100644 naga/tests/out/msl/wgsl-8820-multiple-local-invocation-index-id.metal create mode 100644 naga/tests/out/spv/wgsl-8820-multiple-local-invocation-index-id.spvasm create mode 100644 naga/tests/out/wgsl/wgsl-8820-multiple-local-invocation-index-id.wgsl diff --git a/CHANGELOG.md b/CHANGELOG.md index eb85ed189..de6bdc532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -210,6 +210,7 @@ By @kpreid in [#9042](https://github.com/gfx-rs/wgpu/pull/9042). - Renamed `EXPERIMENTAL_PASSTHROUGH_SHADERS` to `PASSTHROUGH_SHADERS` and made this no longer an experimental feature. by @inner-daemons in [#9054](https://github.com/gfx-rs/wgpu/pull/9054). - BREAKING: End offsets in trace and `player` commands are now represented using `offset` + `size` instead. By @ErichDonGubler in [9073](https://github.com/gfx-rs/wgpu/pull/9073). - Validate some uncaught cases where buffer transfer operations could overflow when computing an end offset. By @ErichDonGubler in [9073](https://github.com/gfx-rs/wgpu/pull/9073). +- Fix `local_invocation_id` and `local_invocation_index` being written multiple times in HLSL/MSL backends, and naming conflicts when users name variables `__local_invocation_id` or `__local_invocation_index`. By @inner-daemons in [#9099](https://github.com/gfx-rs/wgpu/pull/9099). - Added internal labels to validation GPU objects and timestamp normalization code to improve clarity in graphics debuggers. By @szostid in [9094](https://github.com/gfx-rs/wgpu/pull/9094) - Fix multi-planar texture copying. By @noituri [#9069](https://github.com/gfx-rs/wgpu/pull/9069) diff --git a/naga/src/back/hlsl/writer.rs b/naga/src/back/hlsl/writer.rs index 4a08e9f18..55675c68d 100644 --- a/naga/src/back/hlsl/writer.rs +++ b/naga/src/back/hlsl/writer.rs @@ -74,6 +74,7 @@ struct EntryPointBinding { ty_name: String, /// Members of generated structure members: Vec, + local_invocation_index_name: Option, } pub(super) struct EntryPointInterface { @@ -619,11 +620,23 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, "struct {struct_name}")?; writeln!(self.out, " {{")?; + let mut local_invocation_index_name = None; + let mut subgroup_id_used = false; for m in members.iter() { // Sanity check that each IO member is a built-in or is assigned a // location. Also see note about nesting in `write_ep_input_struct`. debug_assert!(m.binding.is_some()); + match m.binding { + Some(crate::Binding::BuiltIn(crate::BuiltIn::SubgroupId)) => { + subgroup_id_used = true; + } + Some(crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationIndex)) => { + local_invocation_index_name = Some(m.name.clone()); + } + _ => (), + } + if is_subgroup_builtin_binding(&m.binding) { continue; } @@ -636,17 +649,10 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { self.write_semantic(&m.binding, Some(shader_stage))?; writeln!(self.out, ";")?; } - if members.iter().any(|arg| { - matches!( - arg.binding, - Some(crate::Binding::BuiltIn(crate::BuiltIn::SubgroupId)) - ) - }) { - writeln!( - self.out, - "{}uint __local_invocation_index : SV_GroupIndex;", - back::INDENT - )?; + if subgroup_id_used && local_invocation_index_name.is_none() { + let name = self.namer.call("local_invocation_index"); + writeln!(self.out, "{}uint {name} : SV_GroupIndex;", back::INDENT)?; + local_invocation_index_name = Some(name); } writeln!(self.out, "}};")?; writeln!(self.out)?; @@ -666,6 +672,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { arg_name: self.namer.call(struct_name.to_lowercase().as_str()), ty_name: struct_name, members, + local_invocation_index_name, }) } @@ -845,8 +852,10 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { Some(crate::Binding::BuiltIn(crate::BuiltIn::SubgroupId)) => { write!( self.out, - "{}.__local_invocation_index / WaveGetLaneCount()", - ep_input.arg_name + "{}.{} / WaveGetLaneCount()", + ep_input.arg_name, + // When writing SubgroupId, we always guarantee that local_invocation_index_name is written + ep_input.local_invocation_index_name.as_ref().unwrap() )?; } _ => { @@ -1593,6 +1602,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let need_workgroup_variables_initialization = self.need_workgroup_variables_initialization(func_ctx, module); + let needs_local_invocation_id_name = need_workgroup_variables_initialization; + let mut local_invocation_id_name = None; // Write function arguments for non entry point functions match func_ctx.ty { back::FunctionType::Function(handle) => { @@ -1620,6 +1631,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let argument_name = &self.names[&NameKey::EntryPointArgument(ep_index, index as u32)]; + if arg.binding + == Some(crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationId)) + { + local_invocation_id_name = Some(argument_name.clone()); + } + write!(self.out, " {argument_name}")?; if let TypeInner::Array { base, size, .. } = module.types[arg.ty].inner { self.write_array_size(module, base, size)?; @@ -1628,7 +1645,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { self.write_semantic(&arg.binding, Some((stage, Io::Input)))?; } } - if need_workgroup_variables_initialization { + if needs_local_invocation_id_name && local_invocation_id_name.is_none() { if self .entry_point_io .get(&(ep_index as usize)) @@ -1639,7 +1656,9 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { { write!(self.out, ", ")?; } - write!(self.out, "uint3 __local_invocation_id : SV_GroupThreadID")?; + let var_name = self.namer.call("local_invocation_id"); + write!(self.out, "uint3 {var_name} : SV_GroupThreadID")?; + local_invocation_id_name = Some(var_name); } } } @@ -1659,7 +1678,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { writeln!(self.out, "{{")?; if need_workgroup_variables_initialization { - self.write_workgroup_variables_initialization(func_ctx, module)?; + self.write_workgroup_variables_initialization( + func_ctx, + module, + // need_workgroup_variables_initialization forces this to be written + // if the user doesn't specify it (so this must be Some()) + local_invocation_id_name.unwrap(), + )?; } if let back::FunctionType::EntryPoint(index) = func_ctx.ty { @@ -1810,12 +1835,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { &mut self, func_ctx: &back::FunctionCtx, module: &Module, + local_invocation_id_name: String, ) -> BackendResult { let level = back::Level(1); writeln!( self.out, - "{level}if (all(__local_invocation_id == uint3(0u, 0u, 0u))) {{" + "{level}if (all({local_invocation_id_name} == uint3(0u, 0u, 0u))) {{" )?; let vars = module.global_variables.iter().filter(|&(handle, var)| { diff --git a/naga/src/back/msl/keywords.rs b/naga/src/back/msl/keywords.rs index 2658d4097..f0ed9154d 100644 --- a/naga/src/back/msl/keywords.rs +++ b/naga/src/back/msl/keywords.rs @@ -343,6 +343,8 @@ const RESERVED: &[&str] = &[ "M_SQRT1_2", // Naga utilities "DefaultConstructible", + // Naga builtin names + "__local_invocation_id", super::writer::FREXP_FUNCTION, super::writer::MODF_FUNCTION, super::writer::ABS_FUNCTION, diff --git a/naga/tests/in/wgsl/8820-multiple-local-invocation-index-id.wgsl b/naga/tests/in/wgsl/8820-multiple-local-invocation-index-id.wgsl new file mode 100644 index 000000000..24740facb --- /dev/null +++ b/naga/tests/in/wgsl/8820-multiple-local-invocation-index-id.wgsl @@ -0,0 +1,15 @@ +var wg_var: u32; + +struct Input { + @builtin(local_invocation_id) + local_invocation_id: vec3, + @builtin(local_invocation_index) + local_invocation_index: u32, +} + +@compute +@workgroup_size(1) +fn compute1(input: Input) { + wg_var = input.local_invocation_index * 2; + wg_var += input.local_invocation_id.x; +} diff --git a/naga/tests/out/glsl/wgsl-8820-multiple-local-invocation-index-id.compute1.Compute.glsl b/naga/tests/out/glsl/wgsl-8820-multiple-local-invocation-index-id.compute1.Compute.glsl new file mode 100644 index 000000000..cbb8f506c --- /dev/null +++ b/naga/tests/out/glsl/wgsl-8820-multiple-local-invocation-index-id.compute1.Compute.glsl @@ -0,0 +1,27 @@ +#version 310 es + +precision highp float; +precision highp int; + +layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +struct Input { + uvec3 local_invocation_id; + uint local_invocation_index; +}; +shared uint wg_var; + + +void main() { + if (gl_LocalInvocationID == uvec3(0u)) { + wg_var = 0u; + } + memoryBarrierShared(); + barrier(); + Input input_ = Input(gl_LocalInvocationID, gl_LocalInvocationIndex); + wg_var = (input_.local_invocation_index * 2u); + uint _e6 = wg_var; + wg_var = (_e6 + input_.local_invocation_id.x); + return; +} + diff --git a/naga/tests/out/hlsl/spv-subgroup-operations-s.hlsl b/naga/tests/out/hlsl/spv-subgroup-operations-s.hlsl index c9680b633..8dbacb110 100644 --- a/naga/tests/out/hlsl/spv-subgroup-operations-s.hlsl +++ b/naga/tests/out/hlsl/spv-subgroup-operations-s.hlsl @@ -4,7 +4,7 @@ static uint global_2 = (uint)0; static uint global_3 = (uint)0; struct ComputeInput_main { - uint __local_invocation_index : SV_GroupIndex; + uint local_invocation_index : SV_GroupIndex; }; void function() @@ -39,7 +39,7 @@ void function() void main(ComputeInput_main computeinput_main) { uint param = (1u + WaveGetLaneCount() - 1u) / WaveGetLaneCount(); - uint param_1 = computeinput_main.__local_invocation_index / WaveGetLaneCount(); + uint param_1 = computeinput_main.local_invocation_index / WaveGetLaneCount(); uint param_2 = WaveGetLaneCount(); uint param_3 = WaveGetLaneIndex(); global = param; diff --git a/naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.hlsl b/naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.hlsl new file mode 100644 index 000000000..f2861ce5c --- /dev/null +++ b/naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.hlsl @@ -0,0 +1,19 @@ +struct Input { + uint3 local_invocation_id : SV_GroupThreadID; + uint local_invocation_index : SV_GroupIndex; +}; + +groupshared uint wg_var; + +[numthreads(1, 1, 1)] +void compute1_(Input input, uint3 local_invocation_id : SV_GroupThreadID) +{ + if (all(local_invocation_id == uint3(0u, 0u, 0u))) { + wg_var = (uint)0; + } + GroupMemoryBarrierWithGroupSync(); + wg_var = (input.local_invocation_index * 2u); + uint _e6 = wg_var; + wg_var = (_e6 + input.local_invocation_id.x); + return; +} diff --git a/naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.ron b/naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.ron new file mode 100644 index 000000000..59b5cf92f --- /dev/null +++ b/naga/tests/out/hlsl/wgsl-8820-multiple-local-invocation-index-id.ron @@ -0,0 +1,12 @@ +( + vertex:[ + ], + fragment:[ + ], + compute:[ + ( + entry_point:"compute1_", + target_profile:"cs_5_1", + ), + ], +) diff --git a/naga/tests/out/hlsl/wgsl-atomicOps-int64.hlsl b/naga/tests/out/hlsl/wgsl-atomicOps-int64.hlsl index eaebd0f59..e4370e91b 100644 --- a/naga/tests/out/hlsl/wgsl-atomicOps-int64.hlsl +++ b/naga/tests/out/hlsl/wgsl-atomicOps-int64.hlsl @@ -30,9 +30,9 @@ groupshared int64_t workgroup_atomic_arr[2]; groupshared Struct workgroup_struct; [numthreads(2, 1, 1)] -void cs_main(uint3 id : SV_GroupThreadID, uint3 __local_invocation_id : SV_GroupThreadID) +void cs_main(uint3 id : SV_GroupThreadID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(id == uint3(0u, 0u, 0u))) { workgroup_atomic_scalar = (uint64_t)0; workgroup_atomic_arr = (int64_t[2])0; workgroup_struct = (Struct)0; diff --git a/naga/tests/out/hlsl/wgsl-atomicOps.hlsl b/naga/tests/out/hlsl/wgsl-atomicOps.hlsl index d32d953a1..333a772ae 100644 --- a/naga/tests/out/hlsl/wgsl-atomicOps.hlsl +++ b/naga/tests/out/hlsl/wgsl-atomicOps.hlsl @@ -21,9 +21,9 @@ groupshared int workgroup_atomic_arr[2]; groupshared Struct workgroup_struct; [numthreads(2, 1, 1)] -void cs_main(uint3 id : SV_GroupThreadID, uint3 __local_invocation_id : SV_GroupThreadID) +void cs_main(uint3 id : SV_GroupThreadID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(id == uint3(0u, 0u, 0u))) { workgroup_atomic_scalar = (uint)0; workgroup_atomic_arr = (int[2])0; workgroup_struct = (Struct)0; diff --git a/naga/tests/out/hlsl/wgsl-globals.hlsl b/naga/tests/out/hlsl/wgsl-globals.hlsl index af2951a33..3c44b3df5 100644 --- a/naga/tests/out/hlsl/wgsl-globals.hlsl +++ b/naga/tests/out/hlsl/wgsl-globals.hlsl @@ -110,9 +110,9 @@ uint NagaBufferLength(ByteAddressBuffer buffer) } [numthreads(1, 1, 1)] -void main(uint3 __local_invocation_id : SV_GroupThreadID) +void main(uint3 local_invocation_id : SV_GroupThreadID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(local_invocation_id == uint3(0u, 0u, 0u))) { wg = (float[10])0; at_1 = (uint)0; } diff --git a/naga/tests/out/hlsl/wgsl-interface.hlsl b/naga/tests/out/hlsl/wgsl-interface.hlsl index 6187ca097..0db61c5da 100644 --- a/naga/tests/out/hlsl/wgsl-interface.hlsl +++ b/naga/tests/out/hlsl/wgsl-interface.hlsl @@ -75,9 +75,9 @@ FragmentOutput fragment(FragmentInput_fragment fragmentinput_fragment) } [numthreads(1, 1, 1)] -void compute(uint3 global_id : SV_DispatchThreadID, uint3 local_id : SV_GroupThreadID, uint local_index : SV_GroupIndex, uint3 wg_id : SV_GroupID, uint3 num_wgs : SV_GroupID, uint3 __local_invocation_id : SV_GroupThreadID) +void compute(uint3 global_id : SV_DispatchThreadID, uint3 local_id : SV_GroupThreadID, uint local_index : SV_GroupIndex, uint3 wg_id : SV_GroupID, uint3 num_wgs : SV_GroupID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(local_id == uint3(0u, 0u, 0u))) { output = (uint[1])0; } GroupMemoryBarrierWithGroupSync(); diff --git a/naga/tests/out/hlsl/wgsl-subgroup-operations.hlsl b/naga/tests/out/hlsl/wgsl-subgroup-operations.hlsl index ef9a65b02..8e42f3183 100644 --- a/naga/tests/out/hlsl/wgsl-subgroup-operations.hlsl +++ b/naga/tests/out/hlsl/wgsl-subgroup-operations.hlsl @@ -4,14 +4,14 @@ struct Structure { }; struct ComputeInput_main { - uint __local_invocation_index : SV_GroupIndex; + uint local_invocation_index : SV_GroupIndex; }; [numthreads(1, 1, 1)] void main(ComputeInput_main computeinput_main) { Structure sizes = { (1u + WaveGetLaneCount() - 1u) / WaveGetLaneCount(), WaveGetLaneCount() }; - uint subgroup_id = computeinput_main.__local_invocation_index / WaveGetLaneCount(); + uint subgroup_id = computeinput_main.local_invocation_index / WaveGetLaneCount(); uint subgroup_invocation_id = WaveGetLaneIndex(); const uint4 _e7 = WaveActiveBallot(((subgroup_invocation_id & 1u) == 1u)); const uint4 _e8 = WaveActiveBallot(true); diff --git a/naga/tests/out/hlsl/wgsl-workgroup-uniform-load-atomic.hlsl b/naga/tests/out/hlsl/wgsl-workgroup-uniform-load-atomic.hlsl index cbbdb7feb..cefad7940 100644 --- a/naga/tests/out/hlsl/wgsl-workgroup-uniform-load-atomic.hlsl +++ b/naga/tests/out/hlsl/wgsl-workgroup-uniform-load-atomic.hlsl @@ -8,9 +8,9 @@ groupshared int wg_signed; groupshared AtomicStruct wg_struct; [numthreads(64, 1, 1)] -void test_atomic_workgroup_uniform_load(uint3 workgroup_id : SV_GroupID, uint3 local_id : SV_GroupThreadID, uint3 __local_invocation_id : SV_GroupThreadID) +void test_atomic_workgroup_uniform_load(uint3 workgroup_id : SV_GroupID, uint3 local_id : SV_GroupThreadID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(local_id == uint3(0u, 0u, 0u))) { wg_scalar = (uint)0; wg_signed = (int)0; wg_struct = (AtomicStruct)0; diff --git a/naga/tests/out/hlsl/wgsl-workgroup-uniform-load.hlsl b/naga/tests/out/hlsl/wgsl-workgroup-uniform-load.hlsl index 0bfb55cb6..a33f1feec 100644 --- a/naga/tests/out/hlsl/wgsl-workgroup-uniform-load.hlsl +++ b/naga/tests/out/hlsl/wgsl-workgroup-uniform-load.hlsl @@ -3,9 +3,9 @@ static const uint SIZE = 128u; groupshared int arr_i32_[128]; [numthreads(4, 1, 1)] -void test_workgroupUniformLoad(uint3 workgroup_id : SV_GroupID, uint3 __local_invocation_id : SV_GroupThreadID) +void test_workgroupUniformLoad(uint3 workgroup_id : SV_GroupID, uint3 local_invocation_id : SV_GroupThreadID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(local_invocation_id == uint3(0u, 0u, 0u))) { arr_i32_ = (int[128])0; } GroupMemoryBarrierWithGroupSync(); diff --git a/naga/tests/out/hlsl/wgsl-workgroup-var-init.hlsl b/naga/tests/out/hlsl/wgsl-workgroup-var-init.hlsl index 49b4fe621..b9da039d9 100644 --- a/naga/tests/out/hlsl/wgsl-workgroup-var-init.hlsl +++ b/naga/tests/out/hlsl/wgsl-workgroup-var-init.hlsl @@ -8,9 +8,9 @@ groupshared WStruct w_mem; RWByteAddressBuffer output : register(u0); [numthreads(1, 1, 1)] -void main(uint3 __local_invocation_id : SV_GroupThreadID) +void main(uint3 local_invocation_id : SV_GroupThreadID) { - if (all(__local_invocation_id == uint3(0u, 0u, 0u))) { + if (all(local_invocation_id == uint3(0u, 0u, 0u))) { w_mem = (WStruct)0; } GroupMemoryBarrierWithGroupSync(); diff --git a/naga/tests/out/msl/wgsl-8820-multiple-local-invocation-index-id.metal b/naga/tests/out/msl/wgsl-8820-multiple-local-invocation-index-id.metal new file mode 100644 index 000000000..45b85b79c --- /dev/null +++ b/naga/tests/out/msl/wgsl-8820-multiple-local-invocation-index-id.metal @@ -0,0 +1,28 @@ +// language: metal1.0 +#include +#include + +using metal::uint; + +struct Input { + metal::packed_uint3 local_invocation_id; + uint local_invocation_index; +}; + +struct compute1_Input { +}; +kernel void compute1_( + metal::uint3 local_invocation_id [[thread_position_in_threadgroup]] +, uint local_invocation_index [[thread_index_in_threadgroup]] +, threadgroup uint& wg_var +) { + if (metal::all(local_invocation_id == metal::uint3(0u))) { + wg_var = {}; + } + metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup); + const Input input = { local_invocation_id, local_invocation_index }; + wg_var = input.local_invocation_index * 2u; + uint _e6 = wg_var; + wg_var = _e6 + input.local_invocation_id[0]; + return; +} diff --git a/naga/tests/out/spv/wgsl-8820-multiple-local-invocation-index-id.spvasm b/naga/tests/out/spv/wgsl-8820-multiple-local-invocation-index-id.spvasm new file mode 100644 index 000000000..81c24700c --- /dev/null +++ b/naga/tests/out/spv/wgsl-8820-multiple-local-invocation-index-id.spvasm @@ -0,0 +1,56 @@ +; SPIR-V +; Version: 1.1 +; Generator: rspirv +; Bound: 34 +OpCapability Shader +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint GLCompute %16 "compute1" %10 %13 +OpExecutionMode %16 LocalSize 1 1 1 +OpMemberDecorate %5 0 Offset 0 +OpMemberDecorate %5 1 Offset 12 +OpDecorate %10 BuiltIn LocalInvocationId +OpDecorate %13 BuiltIn LocalInvocationIndex +%2 = OpTypeVoid +%3 = OpTypeInt 32 0 +%4 = OpTypeVector %3 3 +%5 = OpTypeStruct %4 %3 +%7 = OpTypePointer Workgroup %3 +%6 = OpVariable %7 Workgroup +%11 = OpTypePointer Input %4 +%10 = OpVariable %11 Input +%14 = OpTypePointer Input %3 +%13 = OpVariable %14 Input +%17 = OpTypeFunction %2 +%18 = OpConstant %3 2 +%20 = OpConstantNull %3 +%21 = OpConstant %3 0 +%23 = OpTypeBool +%26 = OpConstant %3 264 +%16 = OpFunction %2 None %17 +%8 = OpLabel +%12 = OpLoad %4 %10 +%15 = OpLoad %3 %13 +%9 = OpCompositeConstruct %5 %12 %15 +OpBranch %19 +%19 = OpLabel +%22 = OpIEqual %23 %15 %21 +OpSelectionMerge %24 None +OpBranchConditional %22 %25 %24 +%25 = OpLabel +OpStore %6 %20 +OpBranch %24 +%24 = OpLabel +OpControlBarrier %18 %18 %26 +OpBranch %27 +%27 = OpLabel +%28 = OpCompositeExtract %3 %9 1 +%29 = OpIMul %3 %28 %18 +OpStore %6 %29 +%30 = OpLoad %3 %6 +%31 = OpCompositeExtract %4 %9 0 +%32 = OpCompositeExtract %3 %31 0 +%33 = OpIAdd %3 %30 %32 +OpStore %6 %33 +OpReturn +OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/wgsl/wgsl-8820-multiple-local-invocation-index-id.wgsl b/naga/tests/out/wgsl/wgsl-8820-multiple-local-invocation-index-id.wgsl new file mode 100644 index 000000000..d7d37296f --- /dev/null +++ b/naga/tests/out/wgsl/wgsl-8820-multiple-local-invocation-index-id.wgsl @@ -0,0 +1,14 @@ +struct Input { + @builtin(local_invocation_id) local_invocation_id: vec3, + @builtin(local_invocation_index) local_invocation_index: u32, +} + +var wg_var: u32; + +@compute @workgroup_size(1, 1, 1) +fn compute1_(input: Input) { + wg_var = (input.local_invocation_index * 2u); + let _e6 = wg_var; + wg_var = (_e6 + input.local_invocation_id.x); + return; +}