From 6bca1014b2aa5d8c2b6a7ae316afd875c2f4a65a Mon Sep 17 00:00:00 2001 From: Inner Daemons <85136135+inner-daemons@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:47:42 -0600 Subject: [PATCH] Various SPIR-V fixes for mesh shaders (#8756) * Initial commit adding miscellaneous changes from msl-write and hlsl-write * Same as previous commit * Fixed divergence issue * Removed some unnecessary barriers * Zero init workgroup memory * Added limits validation * Added changelog * Handled overflow, removed todo * Lets see if this fixes llvmpipe * Also this commit fixes llvmpipe maybe * Unfortunate but not too unexpected at this point * Updated feature to say to use ShaderRuntimeChecks::unchecked() * Updated snapshots and took some changes from the hlsl writer * Snapshots * 2 quick tweaks * Updated framework with suggestions by Connor in #8752 * Moved the task runtime limits into naga::back * Fixed soem stuff * Fixed checks: >= into > * Cant believe I forgot this * Removed code using u64 to check stuff * Removed thing with limiting it to 2<<21 * Some more work * Fixed compiles * Added new field to spv options * Updated some stuff to pass around the task runtime limits in more ways * New PR started * Did another quick fix * Another quick fix * Added changelog entry * Added some explanation docs * Fixed a warning * Fixed shader * Fixed some things & added docs * Reverted dxc thing * Fixed thing * Refactored to TaskDispatchLimits * Fixed compile error --- CHANGELOG.md | 4 + benches/benches/wgpu-benchmark/shader.rs | 10 +- docs/api-specs/mesh_shading.md | 4 +- examples/features/src/mesh_shader/mod.rs | 14 +- examples/features/src/mesh_shader/shader.wgsl | 46 +- naga-cli/src/bin/naga.rs | 31 + naga-test/src/lib.rs | 25 +- naga/src/back/mod.rs | 9 + naga/src/back/spv/block.rs | 35 +- naga/src/back/spv/mesh_shader.rs | 389 ++++-- naga/src/back/spv/mod.rs | 18 + naga/src/back/spv/writer.rs | 161 ++- naga/src/back/wgsl/writer.rs | 31 +- naga/src/proc/mod.rs | 90 ++ naga/src/valid/analyzer.rs | 2 +- naga/src/valid/interface.rs | 8 +- naga/tests/in/wgsl/mesh-shader-empty.wgsl | 4 +- naga/tests/in/wgsl/mesh-shader-lines.wgsl | 4 +- naga/tests/in/wgsl/mesh-shader-points.wgsl | 4 +- naga/tests/in/wgsl/mesh-shader.wgsl | 22 +- naga/tests/naga/snapshots.rs | 12 +- .../spv/wgsl-abstract-types-operators.spvasm | 44 +- .../tests/out/spv/wgsl-atomicOps-int64.spvasm | 11 +- naga/tests/out/spv/wgsl-atomicOps.spvasm | 11 +- naga/tests/out/spv/wgsl-globals.spvasm | 144 +- .../out/spv/wgsl-interface.compute.spvasm | 49 +- .../out/spv/wgsl-mesh-shader-empty.spvasm | 288 ++-- .../out/spv/wgsl-mesh-shader-lines.spvasm | 288 ++-- .../out/spv/wgsl-mesh-shader-points.spvasm | 288 ++-- naga/tests/out/spv/wgsl-mesh-shader.spvasm | 1244 +++++++++-------- ...errides-atomicCompareExchangeWeak.f.spvasm | 40 +- naga/tests/out/spv/wgsl-policy-mix.spvasm | 33 +- .../wgsl-workgroup-uniform-load-atomic.spvasm | 11 +- .../spv/wgsl-workgroup-uniform-load.spvasm | 65 +- .../out/spv/wgsl-workgroup-var-init.spvasm | 44 +- .../out/wgsl/wgsl-mesh-shader-empty.wgsl | 4 +- .../out/wgsl/wgsl-mesh-shader-lines.wgsl | 4 +- .../out/wgsl/wgsl-mesh-shader-points.wgsl | 4 +- naga/tests/out/wgsl/wgsl-mesh-shader.wgsl | 28 +- tests/tests/wgpu-gpu/mesh_shader/shader.wgsl | 4 +- wgpu-hal/src/vulkan/adapter.rs | 12 +- wgpu-hal/src/vulkan/device.rs | 10 +- wgpu-types/src/features.rs | 7 + wgpu-types/src/shader.rs | 9 + 44 files changed, 2061 insertions(+), 1504 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f269e2215..51dc48219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999). - Added `Dx12BackendOptions::force_shader_model` to allow using advanced features in passthrough shaders without bundling DXC. By @inner-daemons in [#8984](https://github.com/gfx-rs/wgpu/pull/8984). - Changed passthrough shaders to not require an entry point parameter, so that the same shader module may be used in multiple entry points. Also added support for metallib passthrough. By @inner-daemons in #8886. - Added `Dx12Compiler::Auto` to automatically use static or dynamic DXC if available, before falling back to FXC. By @inner-daemons in [#8882](https://github.com/gfx-rs/wgpu/pull/8882). +- Added support for `insert_debug_marker`, `push_debug_group` and `pop_debug_group` on WebGPU. By @evilpie in [#9017](https://github.com/gfx-rs/wgpu/pull/9017). - Added support for `@builtin(draw_index)` to the vulkan backend. By @inner-daemons in #8883. - Added support for `enable primitive_index` and `@builtin(primitive_index)` with support on all platforms. By @inner-daemons in #8879. @@ -127,6 +128,9 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999). - Fix incorrect acceptance of some swizzle selectors that are not valid for their operand, e.g. `const v = vec2(); let r = v.xyz`. By @andyleiserson in [#8949](https://github.com/gfx-rs/wgpu/pull/8949). - Fixed calculation of the total number of bindings in a pipeline layout when validating against device limits. By @andyleiserson in [#8997](https://github.com/gfx-rs/wgpu/pull/8997). +#### Vulkan +- Fixed a variety of mesh shader SPIR-V writer issues from the original implementation. By @inner-daemons in [#8756](https://github.com/gfx-rs/wgpu/pull/8756) + #### GLES - `DisplayHandle` should now be passed to `InstanceDescriptor` for correct EGL initialization on Wayland. By @MarijnS95 in [#8012](https://github.com/gfx-rs/wgpu/pull/8012) diff --git a/benches/benches/wgpu-benchmark/shader.rs b/benches/benches/wgpu-benchmark/shader.rs index 63b9cf0f9..e85fd75e4 100644 --- a/benches/benches/wgpu-benchmark/shader.rs +++ b/benches/benches/wgpu-benchmark/shader.rs @@ -366,14 +366,16 @@ pub fn backends(ctx: BenchmarkContext) -> anyhow::Result> { let mut data = Vec::new(); let mut writer = naga::back::spv::Writer::new(&Default::default()).unwrap(); for input in &inputs.inner { + let shared_info = WriterSharedOptions { + mesh_output_validation: input.options.mesh_output_validation, + task_limits: input.options.task_limits, + bounds_checks_policies: input.options.bounds_check_policies, + }; if input.options.targets.unwrap().contains(Targets::SPIRV) { if input.filename().contains("pointer-function-arg") { continue; } - let opt = input - .options - .spv - .to_options(input.options.bounds_check_policies, None); + let opt = input.options.spv.to_options(&shared_info, None); if writer.set_options(&opt).is_ok() { let _ = writer.write( input.module.as_ref().unwrap(), diff --git a/docs/api-specs/mesh_shading.md b/docs/api-specs/mesh_shading.md index c2b0a5202..7cc6fea0a 100644 --- a/docs/api-specs/mesh_shading.md +++ b/docs/api-specs/mesh_shading.md @@ -130,13 +130,11 @@ A task shader entry point must have a `@workgroup_size` attribute, meeting the s A task shader entry point must also have a `@payload(G)` property, where `G` is the name of a global variable in the `task_payload` address space. Each task shader workgroup has its own instance of this variable, visible to all invocations in the workgroup. Whatever value the workgroup collectively stores in that global variable becomes the **task payload**, and is provided to all invocations in the mesh shader grid dispatched for the workgroup. A task payload variable must be at least 4 bytes in size. -A task shader entry point must return a `vec3` value. The return value of each workgroup's first invocation (that is, the one whose `local_invocation_index` is `0`) is taken as the size of a **mesh shader grid** to dispatch, measured in workgroups. (If the task shader entry point returns `vec3(0, 0, 0)`, then no mesh shaders are dispatched.) Mesh shader grids are described in the next section. +A task shader entry point must return a `vec3` value decorated with `@builtin(mesh_task_size)`. The return value of each workgroup's first invocation (that is, the one whose `local_invocation_index` is `0`) is taken as the size of a **mesh shader grid** to dispatch, measured in workgroups. (If the task shader entry point returns `vec3(0, 0, 0)`, then no mesh shaders are dispatched.) Mesh shader grids are described in the next section. Each task shader workgroup dispatches an independent mesh shader grid: in mesh shader invocations, `@builtin` values like `workgroup_id` and `global_invocation_id` describe the position of the workgroup and invocation within that grid; and `@builtin(num_workgroups)` matches the task shader workgroup's return value. Mesh shaders dispatched for other task shader workgroups are not included in the count. If it is necessary for a mesh shader to know which task shader workgroup dispatched it, the task shader can include its own workgroup id in the task payload. -Task shaders must return a value of type `vec3` decorated with `@builtin(mesh_task_size)`. - Task shaders can use compute and subgroup builtin inputs, in addition to `view_index` and `draw_id`. ### Mesh shader diff --git a/examples/features/src/mesh_shader/mod.rs b/examples/features/src/mesh_shader/mod.rs index bd36ed97f..d3ebec03e 100644 --- a/examples/features/src/mesh_shader/mod.rs +++ b/examples/features/src/mesh_shader/mod.rs @@ -1,9 +1,15 @@ // Same as in mesh shader tests fn compile_wgsl(device: &wgpu::Device) -> wgpu::ShaderModule { - device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: None, - source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), - }) + // Workgroup memory zero initialization can be expensive for mesh shaders + unsafe { + device.create_shader_module_trusted( + wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), + }, + wgpu::ShaderRuntimeChecks::unchecked(), + ) + } } fn compile_hlsl(device: &wgpu::Device, entry: &str, stage_str: &str) -> wgpu::ShaderModule { let out_path = format!( diff --git a/examples/features/src/mesh_shader/shader.wgsl b/examples/features/src/mesh_shader/shader.wgsl index e0d03ea13..feca332cc 100644 --- a/examples/features/src/mesh_shader/shader.wgsl +++ b/examples/features/src/mesh_shader/shader.wgsl @@ -33,12 +33,15 @@ var workgroupData: f32; @task @payload(taskPayload) -@workgroup_size(1) -fn ts_main() -> @builtin(mesh_task_size) vec3 { - workgroupData = 1.0; - taskPayload.colorMask = vec4(1.0, 1.0, 0.0, 1.0); - taskPayload.visible = true; - return vec3(1, 1, 1); +@workgroup_size(64) +fn ts_main(@builtin(local_invocation_id) thread_id: vec3) -> @builtin(mesh_task_size) vec3 { + if thread_id.x == 0 { + workgroupData = 1.0; + taskPayload.colorMask = vec4(1.0, 1.0, 0.0, 1.0); + taskPayload.visible = true; + return vec3(1, 1, 1); + } + return vec3(0, 0, 0); } struct MeshOutput { @@ -52,24 +55,21 @@ var mesh_output: MeshOutput; @mesh(mesh_output) @payload(taskPayload) -@workgroup_size(1) -fn ms_main() { - mesh_output.vertex_count = 3; - mesh_output.primitive_count = 1; - workgroupData = 2.0; +@workgroup_size(64) +fn ms_main(@builtin(local_invocation_id) thread_id: vec3) { + if thread_id.x == 0 { + mesh_output.vertex_count = 3; + mesh_output.primitive_count = 1; + workgroupData = 2.0; - mesh_output.vertices[0].position = positions[0]; - mesh_output.vertices[0].color = colors[0] * taskPayload.colorMask; - - mesh_output.vertices[1].position = positions[1]; - mesh_output.vertices[1].color = colors[1] * taskPayload.colorMask; - - mesh_output.vertices[2].position = positions[2]; - mesh_output.vertices[2].color = colors[2] * taskPayload.colorMask; - - mesh_output.primitives[0].indices = vec3(0, 1, 2); - mesh_output.primitives[0].cull = !taskPayload.visible; - mesh_output.primitives[0].colorMask = vec4(1.0, 0.0, 1.0, 1.0); + mesh_output.primitives[0].indices = vec3(0, 1, 2); + mesh_output.primitives[0].cull = !taskPayload.visible; + mesh_output.primitives[0].colorMask = vec4(1.0, 0.0, 1.0, 1.0); + } + if thread_id.x < 3 { + mesh_output.vertices[thread_id.x].position = positions[thread_id.x]; + mesh_output.vertices[thread_id.x].color = colors[thread_id.x] * taskPayload.colorMask; + } } @fragment diff --git a/naga-cli/src/bin/naga.rs b/naga-cli/src/bin/naga.rs index b2366faff..a7653bb72 100644 --- a/naga-cli/src/bin/naga.rs +++ b/naga-cli/src/bin/naga.rs @@ -152,6 +152,34 @@ struct Args { /// "67108864"), the string "none", or the string "all". #[argh(option, default = "CapabilitiesArg(naga::valid::Capabilities::all())")] capabilities: CapabilitiesArg, + + /// the limits on the task shader dispatch size + #[argh(option, default = "TaskDispatchLimitsArg(None)")] + task_limits: TaskDispatchLimitsArg, + + /// whether or not the mesh shader output should be validated. + #[argh(option, default = "true")] + validate_mesh_output: bool, +} + +/// Newtype so we can implement [`FromStr`] for `Option`. +#[derive(Debug, Clone, Copy)] +struct TaskDispatchLimitsArg(Option); + +impl FromStr for TaskDispatchLimitsArg { + type Err = String; + + fn from_str(s: &str) -> Result { + let values = s + .split_once(",") + .ok_or_else(|| format!("No comma present for --task-limits value: {s}"))?; + let x = values.0.parse::().map_err(|e| e.to_string())?; + let y = values.1.parse::().map_err(|e| e.to_string())?; + Ok(Self(Some(naga::back::TaskDispatchLimits { + max_mesh_workgroups_per_dim: x, + max_mesh_workgroups_total: y, + }))) + } } /// Newtype so we can implement [`FromStr`] for `BoundsCheckPolicy`. @@ -545,6 +573,9 @@ fn run() -> anyhow::Result<()> { params.compact = args.compact; params.capabilities = args.capabilities.0; + params.spv_out.mesh_shader_primitive_indices_clamp = args.validate_mesh_output; + params.spv_out.task_dispatch_limits = args.task_limits.0; + if args.bulk_validate { return bulk_validate(&args, ¶ms); } diff --git a/naga-test/src/lib.rs b/naga-test/src/lib.rs index c6ea2d0f6..011227479 100644 --- a/naga-test/src/lib.rs +++ b/naga-test/src/lib.rs @@ -75,6 +75,14 @@ where Ok(map) } +#[derive(Default, serde::Deserialize)] +#[serde(default)] +pub struct WriterSharedOptions { + pub mesh_output_validation: bool, + pub task_limits: Option, + pub bounds_checks_policies: naga::proc::BoundsCheckPolicies, +} + #[derive(Default, serde::Deserialize)] #[serde(default)] pub struct WgslInParameters { @@ -137,7 +145,7 @@ impl Default for SpirvOutParameters { impl SpirvOutParameters { pub fn to_options<'a>( &'a self, - bounds_check_policies: naga::proc::BoundsCheckPolicies, + shared_info: &WriterSharedOptions, debug_info: Option>, ) -> naga::back::spv::Options<'a> { use naga::back::spv; @@ -157,7 +165,7 @@ impl SpirvOutParameters { } else { Some(self.capabilities.clone()) }, - bounds_check_policies, + bounds_check_policies: shared_info.bounds_checks_policies, fake_missing_bindings: true, binding_map: self.binding_map.clone(), zero_initialize_workgroup_memory: spv::ZeroInitializeWorkgroupMemoryMode::Polyfill, @@ -165,6 +173,8 @@ impl SpirvOutParameters { ray_query_initialization_tracking: true, debug_info, use_storage_input_output_16: self.use_storage_input_output_16, + task_dispatch_limits: shared_info.task_limits, + mesh_shader_primitive_indices_clamp: shared_info.mesh_output_validation, } } } @@ -235,6 +245,17 @@ pub struct Parameters { pub bounds_check_policies: naga::proc::BoundsCheckPolicies, pub pipeline_constants: naga::back::PipelineConstants, + + pub mesh_output_validation: bool, + #[serde(default = "default_task_limits")] + pub task_limits: Option, +} + +fn default_task_limits() -> Option { + Some(naga::back::TaskDispatchLimits { + max_mesh_workgroups_per_dim: 256, + max_mesh_workgroups_total: 1024, + }) } /// Information about a shader input file. diff --git a/naga/src/back/mod.rs b/naga/src/back/mod.rs index 8e1dcef80..24b3ec83a 100644 --- a/naga/src/back/mod.rs +++ b/naga/src/back/mod.rs @@ -148,6 +148,7 @@ fn get_entry_points( /// [`EntryPoint`]: crate::EntryPoint /// [`Module`]: crate::Module /// [`Module::entry_points`]: crate::Module::entry_points +#[derive(Clone, Copy, Debug)] pub enum FunctionType { /// A regular function. Function(crate::Handle), @@ -391,3 +392,11 @@ pub enum RayIntersectionType { Triangle = 1, BoundingBox = 4, } + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +pub struct TaskDispatchLimits { + pub max_mesh_workgroups_per_dim: u32, + pub max_mesh_workgroups_total: u32, +} diff --git a/naga/src/back/spv/block.rs b/naga/src/back/spv/block.rs index 2e1450a75..7b864dd6e 100644 --- a/naga/src/back/spv/block.rs +++ b/naga/src/back/spv/block.rs @@ -237,12 +237,11 @@ impl Writer { ir_result: &crate::FunctionResult, result_members: &[ResultMember], body: &mut Vec, - task_payload: Option, ) -> Result { for (index, res_member) in result_members.iter().enumerate() { // This isn't a real builtin, and is handled elsewhere if res_member.built_in == Some(crate::BuiltIn::MeshTaskSize) { - continue; + return Ok(Instruction::return_value(value_id)); } let member_value_id = match ir_result.binding { Some(_) => value_id, @@ -274,13 +273,7 @@ impl Writer { _ => {} } } - self.try_write_entry_point_task_return( - value_id, - ir_result, - result_members, - body, - task_payload, - ) + Ok(Instruction::return_void()) } } @@ -3754,7 +3747,6 @@ impl BlockContext<'_> { self.ir_function.result.as_ref().unwrap(), &context.results, &mut block.body, - context.task_payload_variable_id, )?, None => Instruction::return_value(value_id), }; @@ -3762,18 +3754,7 @@ impl BlockContext<'_> { return Ok(BlockExitDisposition::Discarded); } Statement::Return { value: None } => { - if let Some(super::EntryPointContext { - mesh_state: Some(ref mesh_state), - .. - }) = self.function.entry_point_context - { - self.function.consume( - block, - Instruction::branch(mesh_state.entry_point_epilogue_id), - ); - } else { - self.function.consume(block, Instruction::return_void()); - } + self.function.consume(block, Instruction::return_void()); return Ok(BlockExitDisposition::Discarded); } Statement::Kill => { @@ -4242,16 +4223,6 @@ impl BlockContext<'_> { LoopContext::default(), debug_info, )?; - if let Some(super::EntryPointContext { - mesh_state: Some(ref mesh_state), - .. - }) = self.function.entry_point_context - { - let mut block = Block::new(mesh_state.entry_point_epilogue_id); - self.writer - .write_mesh_shader_return(mesh_state, &mut block)?; - self.function.consume(block, Instruction::return_void()); - } Ok(()) } diff --git a/naga/src/back/spv/mesh_shader.rs b/naga/src/back/spv/mesh_shader.rs index a026c763a..33f7827cc 100644 --- a/naga/src/back/spv/mesh_shader.rs +++ b/naga/src/back/spv/mesh_shader.rs @@ -4,7 +4,7 @@ use spirv::Word; use crate::{ back::spv::{ helpers::BindingDecorations, writer::FunctionInterface, Block, EntryPointContext, Error, - Instruction, ResultMember, WriterFlags, + Instruction, WriterFlags, }, non_max_u32::NonMaxU32, Handle, @@ -36,15 +36,9 @@ pub struct MeshReturnInfo { /// All members of the output variable struct type out_members: Vec, /// Id of the input variable for local invocation id - local_invocation_index_id: Word, + local_invocation_index_var_id: Word, /// Total workgroup size (product) workgroup_size: u32, - /// Variable to be used later when saving the output as a loop index - loop_counter_vertices: Word, - /// Variable to be used later when saving the output as a loop index - loop_counter_primitives: Word, - /// The id of the label to jump to when `return` is called - pub entry_point_epilogue_id: Word, /// Vertex-specific info vertex_info: PerOutputTypeMeshReturnInfo, @@ -55,16 +49,6 @@ pub struct MeshReturnInfo { } impl super::Writer { - pub(super) fn require_mesh_shaders(&mut self) -> Result<(), Error> { - self.use_extension("SPV_EXT_mesh_shader"); - self.require_any("Mesh Shaders", &[spirv::Capability::MeshShadingEXT])?; - let lang_version = self.lang_version(); - if lang_version.0 <= 1 && lang_version.1 < 4 { - return Err(Error::SpirvVersionTooLow(1, 4)); - } - Ok(()) - } - /// Sets up an output variable that will handle part of the mesh shader output pub(super) fn write_mesh_return_global_variable( &mut self, @@ -88,7 +72,6 @@ impl super::Writer { iface: &mut FunctionInterface, local_invocation_index_id: Option, ir_module: &crate::Module, - prelude: &mut Block, ep_context: &mut EntryPointContext, ) -> Result<(), Error> { let Some(ref mesh_info) = iface.mesh_info else { @@ -146,7 +129,7 @@ impl super::Writer { _ => unreachable!(), }; // In the final return, we do a giant memcpy, for which this is helpful - let local_invocation_index_id = match local_invocation_index_id { + let local_invocation_index_var_id = match local_invocation_index_id { Some(a) => a, None => { let u32_id = self.get_u32_type_id(); @@ -166,48 +149,17 @@ impl super::Writer { .to_words(&mut self.logical_layout.annotations); iface.varying_ids.push(var); - let loaded_value = self.id_gen.next(); - prelude - .body - .push(Instruction::load(u32_id, loaded_value, var, None)); - loaded_value + var } }; - let u32_id = self.get_u32_type_id(); - // A general function variable that we guarantee to allow in the final return. It must be - // declared at the top of the function. Currently it is used in the memcpy part to keep - // track of the current index to copy. - let loop_counter_1 = self.id_gen.next(); - let loop_counter_2 = self.id_gen.next(); - prelude.body.insert( - 0, - Instruction::variable( - self.get_pointer_type_id(u32_id, spirv::StorageClass::Function), - loop_counter_1, - spirv::StorageClass::Function, - None, - ), - ); - prelude.body.insert( - 1, - Instruction::variable( - self.get_pointer_type_id(u32_id, spirv::StorageClass::Function), - loop_counter_2, - spirv::StorageClass::Function, - None, - ), - ); // This is the information that is passed to the function writer // so that it can write the final return logic let mut mesh_return_info = MeshReturnInfo { out_variable_id: self.global_variables[mesh_info.output_variable].var_id, out_members, - local_invocation_index_id, + local_invocation_index_var_id, workgroup_size: self .get_constant_scalar(crate::Literal::U32(iface.workgroup_size.iter().product())), - loop_counter_vertices: loop_counter_1, - loop_counter_primitives: loop_counter_2, - entry_point_epilogue_id: self.id_gen.next(), vertex_info: PerOutputTypeMeshReturnInfo { array_type_id: vertex_array_type_id, @@ -457,60 +409,33 @@ impl super::Writer { Ok(()) } - pub(super) fn try_write_entry_point_task_return( + pub(super) fn write_entry_point_task_return( &mut self, value_id: Word, - ir_result: &crate::FunctionResult, - result_members: &[ResultMember], body: &mut Vec, - task_payload: Option, + task_payload: Word, ) -> Result { // OpEmitMeshTasksEXT must be called right before exiting (after setting other // output variables if there are any) - for (index, res_member) in result_members.iter().enumerate() { - if res_member.built_in == Some(crate::BuiltIn::MeshTaskSize) { - self.write_control_barrier(crate::Barrier::WORK_GROUP, body); - // If its a function like `fn a() -> @builtin(...) vec3 ...` - // then just use the output value. If it's a struct, extract the - // value from the struct. - let member_value_id = match ir_result.binding { - Some(_) => value_id, - None => { - let member_value_id = self.id_gen.next(); - body.push(Instruction::composite_extract( - res_member.type_id, - member_value_id, - value_id, - &[index as Word], - )); - member_value_id - } - }; - // Extract the vec3 into 3 u32's - let values = [self.id_gen.next(), self.id_gen.next(), self.id_gen.next()]; - for (i, &value) in values.iter().enumerate() { - let instruction = Instruction::composite_extract( - self.get_u32_type_id(), - value, - member_value_id, - &[i as Word], - ); - body.push(instruction); - } - // TODO: make this guaranteed to be uniform - let mut instruction = Instruction::new(spirv::Op::EmitMeshTasksEXT); - for id in values { - instruction.add_operand(id); - } - // We have to include the task payload in our call - if let Some(task_payload) = task_payload { - instruction.add_operand(task_payload); - } - return Ok(instruction); - } + // Extract the vec3 into 3 u32's + let values = [self.id_gen.next(), self.id_gen.next(), self.id_gen.next()]; + for (i, &value) in values.iter().enumerate() { + let instruction = Instruction::composite_extract( + self.get_u32_type_id(), + value, + value_id, + &[i as Word], + ); + body.push(instruction); } - Ok(Instruction::return_void()) + let mut instruction = Instruction::new(spirv::Op::EmitMeshTasksEXT); + for id in values { + instruction.add_operand(id); + } + // We have to include the task payload in our call + instruction.add_operand(task_payload); + Ok(instruction) } /// This writes the actual loop @@ -708,9 +633,10 @@ impl super::Writer { &mut self, return_info: &MeshReturnInfo, block: &mut Block, + loop_counter_vertices: u32, + loop_counter_primitives: u32, + local_invocation_index_id: Word, ) -> Result<(), Error> { - // Start with a control barrier so that everything that follows is guaranteed to see the same variables - self.write_control_barrier(crate::Barrier::WORK_GROUP, &mut block.body); let u32_id = self.get_u32_type_id(); // Load the actual vertex and primitive counts @@ -780,8 +706,6 @@ impl super::Writer { return_info.primitive_info.array_type_id, ); - self.write_control_barrier(crate::Barrier::WORK_GROUP, &mut block.body); - // This must be called exactly once before any other mesh outputs are written { let mut ins = Instruction::new(spirv::Op::SetMeshOutputsEXT); @@ -798,8 +722,8 @@ impl super::Writer { let func_end = self.id_gen.next(); block.body.push(Instruction::store( - return_info.loop_counter_vertices, - return_info.local_invocation_index_id, + loop_counter_vertices, + local_invocation_index_id, None, )); block.body.push(Instruction::branch(vertex_loop_header)); @@ -807,7 +731,7 @@ impl super::Writer { let vertex_copy_body = self.write_mesh_copy_body( false, return_info, - return_info.loop_counter_vertices, + loop_counter_vertices, vert_array_ptr, prim_array_ptr, ); @@ -818,7 +742,7 @@ impl super::Writer { vertex_loop_header, in_between_loops, vert_count_id, - return_info.loop_counter_vertices, + loop_counter_vertices, return_info, ); @@ -827,8 +751,8 @@ impl super::Writer { block.body.push(Instruction::label(in_between_loops)); block.body.push(Instruction::store( - return_info.loop_counter_primitives, - return_info.local_invocation_index_id, + loop_counter_primitives, + local_invocation_index_id, None, )); @@ -837,7 +761,7 @@ impl super::Writer { let primitive_copy_body = self.write_mesh_copy_body( true, return_info, - return_info.loop_counter_primitives, + loop_counter_primitives, vert_array_ptr, prim_array_ptr, ); @@ -848,11 +772,254 @@ impl super::Writer { prim_loop_header, func_end, prim_count_id, - return_info.loop_counter_primitives, + loop_counter_primitives, return_info, ); block.body.push(Instruction::label(func_end)); Ok(()) } + + pub(super) fn write_mesh_shader_wrapper( + &mut self, + return_info: &MeshReturnInfo, + inner_id: u32, + ) -> Result { + let out_id = self.id_gen.next(); + let mut function = super::Function::default(); + let lookup_function_type = super::LookupFunctionType { + parameter_type_ids: alloc::vec![], + return_type_id: self.void_type, + }; + let function_type = self.get_function_type(lookup_function_type); + function.signature = Some(Instruction::function( + self.void_type, + out_id, + spirv::FunctionControl::empty(), + function_type, + )); + let u32_id = self.get_u32_type_id(); + { + let mut block = Block::new(self.id_gen.next()); + // A general function variable that we guarantee to allow in the final return. It must be + // declared at the top of the function. Currently it is used in the memcpy part to keep + // track of the current index to copy. + let loop_counter_vertices = self.id_gen.next(); + let loop_counter_primitives = self.id_gen.next(); + block.body.insert( + 0, + Instruction::variable( + self.get_pointer_type_id(u32_id, spirv::StorageClass::Function), + loop_counter_vertices, + spirv::StorageClass::Function, + None, + ), + ); + block.body.insert( + 1, + Instruction::variable( + self.get_pointer_type_id(u32_id, spirv::StorageClass::Function), + loop_counter_primitives, + spirv::StorageClass::Function, + None, + ), + ); + let local_invocation_index_id = self.id_gen.next(); + block.body.push(Instruction::load( + u32_id, + local_invocation_index_id, + return_info.local_invocation_index_var_id, + None, + )); + block.body.push(Instruction::function_call( + self.void_type, + self.id_gen.next(), + inner_id, + &[], + )); + self.write_control_barrier(crate::Barrier::WORK_GROUP, &mut block.body); + self.write_mesh_shader_return( + return_info, + &mut block, + loop_counter_vertices, + loop_counter_primitives, + local_invocation_index_id, + )?; + function.consume(block, Instruction::return_void()); + } + function.to_words(&mut self.logical_layout.function_definitions); + Ok(out_id) + } + + pub(super) fn write_task_shader_wrapper( + &mut self, + task_payload: Word, + inner_id: u32, + ) -> Result { + let out_id = self.id_gen.next(); + let mut function = super::Function::default(); + let lookup_function_type = super::LookupFunctionType { + parameter_type_ids: alloc::vec![], + return_type_id: self.void_type, + }; + let function_type = self.get_function_type(lookup_function_type); + function.signature = Some(Instruction::function( + self.void_type, + out_id, + spirv::FunctionControl::empty(), + function_type, + )); + + { + let mut block = Block::new(self.id_gen.next()); + let result = self.id_gen.next(); + block.body.push(Instruction::function_call( + self.get_vec3u_type_id(), + result, + inner_id, + &[], + )); + self.write_control_barrier(crate::Barrier::WORK_GROUP, &mut block.body); + let final_value = if let Some(task_limits) = self.task_dispatch_limits { + let zero_u32 = self.get_constant_scalar(crate::Literal::U32(0)); + let max_per_dim = self.get_constant_scalar(crate::Literal::U32( + task_limits.max_mesh_workgroups_per_dim, + )); + let max_total = self.get_constant_scalar(crate::Literal::U32( + task_limits.max_mesh_workgroups_total, + )); + let combined_struct_type = self.get_tuple_of_u32s_ty_id(); + let values = [self.id_gen.next(), self.id_gen.next(), self.id_gen.next()]; + for (i, value) in values.into_iter().enumerate() { + block.body.push(Instruction::composite_extract( + self.get_u32_type_id(), + value, + result, + &[i as u32], + )); + } + let prod_1 = self.id_gen.next(); + let overflows = [self.id_gen.next(), self.id_gen.next()]; + { + let struct_out = self.id_gen.next(); + block.body.push(Instruction::binary( + spirv::Op::UMulExtended, + combined_struct_type, + struct_out, + values[0], + values[1], + )); + block.body.push(Instruction::composite_extract( + self.get_u32_type_id(), + prod_1, + struct_out, + &[0], + )); + block.body.push(Instruction::composite_extract( + self.get_u32_type_id(), + overflows[0], + struct_out, + &[1], + )); + } + let prod_final = self.id_gen.next(); + { + let struct_out = self.id_gen.next(); + block.body.push(Instruction::binary( + spirv::Op::UMulExtended, + combined_struct_type, + struct_out, + prod_1, + values[2], + )); + block.body.push(Instruction::composite_extract( + self.get_u32_type_id(), + prod_final, + struct_out, + &[0], + )); + block.body.push(Instruction::composite_extract( + self.get_u32_type_id(), + overflows[1], + struct_out, + &[1], + )); + } + let total_too_large = self.id_gen.next(); + block.body.push(Instruction::binary( + spirv::Op::UGreaterThan, + self.get_bool_type_id(), + total_too_large, + prod_final, + max_total, + )); + + let too_large = [self.id_gen.next(), self.id_gen.next(), self.id_gen.next()]; + for (i, value) in values.into_iter().enumerate() { + block.body.push(Instruction::binary( + spirv::Op::UGreaterThan, + self.get_bool_type_id(), + too_large[i], + value, + max_per_dim, + )); + } + let overflow_happens = [self.id_gen.next(), self.id_gen.next()]; + for (i, value) in overflows.into_iter().enumerate() { + block.body.push(Instruction::binary( + spirv::Op::INotEqual, + self.get_bool_type_id(), + overflow_happens[i], + value, + zero_u32, + )); + } + let mut current_violates_limits = total_too_large; + for is_too_large in too_large { + let new = self.id_gen.next(); + block.body.push(Instruction::binary( + spirv::Op::LogicalOr, + self.get_bool_type_id(), + new, + current_violates_limits, + is_too_large, + )); + current_violates_limits = new; + } + for overflow_happens in overflow_happens { + let new = self.id_gen.next(); + block.body.push(Instruction::binary( + spirv::Op::LogicalOr, + self.get_bool_type_id(), + new, + current_violates_limits, + overflow_happens, + )); + current_violates_limits = new; + } + let zero_vec3 = self.id_gen.next(); + block.body.push(Instruction::composite_construct( + self.get_vec3u_type_id(), + zero_vec3, + &[zero_u32, zero_u32, zero_u32], + )); + let final_result = self.id_gen.next(); + block.body.push(Instruction::select( + self.get_vec3u_type_id(), + final_result, + current_violates_limits, + zero_vec3, + result, + )); + final_result + } else { + result + }; + let ins = + self.write_entry_point_task_return(final_value, &mut block.body, task_payload)?; + function.consume(block, ins); + } + function.to_words(&mut self.logical_layout.function_definitions); + Ok(out_id) + } } diff --git a/naga/src/back/spv/mod.rs b/naga/src/back/spv/mod.rs index 00ada4a91..7eeb39e13 100644 --- a/naga/src/back/spv/mod.rs +++ b/naga/src/back/spv/mod.rs @@ -120,6 +120,7 @@ use spirv::Word; use thiserror::Error; use crate::arena::{Handle, HandleVec}; +use crate::back::TaskDispatchLimits; use crate::proc::{BoundsCheckPolicies, TypeResolution}; #[derive(Clone)] @@ -933,6 +934,7 @@ pub struct Writer { force_loop_bounding: bool, use_storage_input_output_16: bool, void_type: Word, + tuple_of_u32s_ty_id: Option, //TODO: convert most of these into vectors, addressable by handle indices lookup_type: crate::FastHashMap, lookup_function: crate::FastHashMap, Word>, @@ -967,6 +969,16 @@ pub struct Writer { /// Non semantic debug printf extension `OpExtInstImport` debug_printf: Option, pub(crate) ray_query_initialization_tracking: bool, + + /// Limits to the mesh shader dispatch group a task workgroup can dispatch. + /// + /// Metal for example limits to 1024 workgroups per task shader dispatch. Dispatching more is + /// undefined behavior, so this would validate that to dispatch zero workgroups. + task_dispatch_limits: Option, + /// If true, naga may generate checks that the primitive indices are valid in the output. + /// + /// Currently this validation is unimplemented. + mesh_shader_primitive_indices_clamp: bool, } bitflags::bitflags! { @@ -1071,6 +1083,10 @@ pub struct Options<'a> { pub use_storage_input_output_16: bool, pub debug_info: Option>, + + pub task_dispatch_limits: Option, + + pub mesh_shader_primitive_indices_clamp: bool, } impl Default for Options<'_> { @@ -1093,6 +1109,8 @@ impl Default for Options<'_> { ray_query_initialization_tracking: true, use_storage_input_output_16: true, debug_info: None, + task_dispatch_limits: None, + mesh_shader_primitive_indices_clamp: true, } } } diff --git a/naga/src/back/spv/writer.rs b/naga/src/back/spv/writer.rs index af6e6750f..e41de1098 100644 --- a/naga/src/back/spv/writer.rs +++ b/naga/src/back/spv/writer.rs @@ -96,6 +96,7 @@ impl Writer { ray_query_initialization_tracking: options.ray_query_initialization_tracking, use_storage_input_output_16: options.use_storage_input_output_16, void_type, + tuple_of_u32s_ty_id: None, lookup_type: crate::FastHashMap::default(), lookup_function: crate::FastHashMap::default(), lookup_function_type: crate::FastHashMap::default(), @@ -114,6 +115,8 @@ impl Writer { options.use_storage_input_output_16, ), debug_printf: None, + task_dispatch_limits: options.task_dispatch_limits, + mesh_shader_primitive_indices_clamp: options.mesh_shader_primitive_indices_clamp, }) } @@ -132,6 +135,8 @@ impl Writer { self.binding_map = options.binding_map.clone(); self.io_f16_polyfills = super::f16_polyfill::F16IoPolyfill::new(options.use_storage_input_output_16); + self.task_dispatch_limits = options.task_dispatch_limits; + self.mesh_shader_primitive_indices_clamp = options.mesh_shader_primitive_indices_clamp; Ok(()) } @@ -170,10 +175,13 @@ impl Writer { capabilities_available: take(&mut self.capabilities_available), fake_missing_bindings: self.fake_missing_bindings, binding_map: take(&mut self.binding_map), + task_dispatch_limits: self.task_dispatch_limits, + mesh_shader_primitive_indices_clamp: self.mesh_shader_primitive_indices_clamp, // Initialized afresh: id_gen, void_type, + tuple_of_u32s_ty_id: None, gl450_ext_inst_id, // Reclaimed: @@ -408,14 +416,6 @@ impl Writer { self.get_pointer_type_id(vec2u_id, class) } - pub(super) fn get_vec3u_pointer_type_id(&mut self, class: spirv::StorageClass) -> Word { - let vec3u_id = self.get_numeric_type_id(NumericType::Vector { - size: crate::VectorSize::Tri, - scalar: crate::Scalar::U32, - }); - self.get_pointer_type_id(vec3u_id, class) - } - pub(super) fn get_bool_type_id(&mut self) -> Word { self.get_numeric_type_id(NumericType::Scalar(crate::Scalar::BOOL)) } @@ -434,6 +434,23 @@ impl Writer { }) } + /// Used for "mulhi" to get the upper bits of multiplication. + /// + /// More specifically, `OpUMulExtended` multiplies 2 numbers and returns the lower and upper bits of the result + /// as a user-defined struct type with 2 u32s. This defines that struct. + pub(super) fn get_tuple_of_u32s_ty_id(&mut self) -> Word { + if let Some(val) = self.tuple_of_u32s_ty_id { + val + } else { + let id = self.id_gen.next(); + let u32_id = self.get_u32_type_id(); + let ins = Instruction::type_struct(id, &[u32_id, u32_id]); + ins.to_words(&mut self.logical_layout.declarations); + self.tuple_of_u32s_ty_id = Some(id); + id + } + } + pub(super) fn decorate(&mut self, id: Word, decoration: spirv::Decoration, operands: &[Word]) { self.annotations .push(Instruction::decorate(id, decoration, operands)); @@ -1195,10 +1212,9 @@ impl Writer { mesh_state: None, }; - let mut local_invocation_id = None; - let mut parameter_type_ids = Vec::with_capacity(ir_function.arguments.len()); + let mut local_invocation_index_var_id = None; let mut local_invocation_index_id = None; for argument in ir_function.arguments.iter() { @@ -1228,13 +1244,9 @@ impl Writer { varying_id, argument_type_id, ); - - if binding == &crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationId) { - local_invocation_id = Some(id); - } else if binding - == &crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationIndex) - { + if binding == &crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationIndex) { local_invocation_index_id = Some(id); + local_invocation_index_var_id = Some(varying_id); } id @@ -1259,13 +1271,10 @@ impl Writer { let id = self.load_io_with_f16_polyfill(&mut prelude.body, varying_id, type_id); constituent_ids.push(id); - - if binding == &crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationId) { - local_invocation_id = Some(id); - } else if binding - == &crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationIndex) + if binding == &crate::Binding::BuiltIn(crate::BuiltIn::LocalInvocationIndex) { local_invocation_index_id = Some(id); + local_invocation_index_var_id = Some(varying_id); } } prelude.body.push(Instruction::composite_construct( @@ -1393,7 +1402,11 @@ impl Writer { .body .push(Instruction::store(varying_id, default_value_id, None)); } - self.void_type + if iface.stage == crate::ShaderStage::Task { + self.get_vec3u_type_id() + } else { + self.void_type + } } else { self.get_handle_type_id(result.ty) } @@ -1409,9 +1422,8 @@ impl Writer { } self.write_entry_point_mesh_shader_info( iface, - local_invocation_index_id, + local_invocation_index_var_id, ir_module, - &mut prelude, &mut ep_context, )?; } @@ -1654,7 +1666,7 @@ impl Writer { next_id, ir_module, info, - local_invocation_id, + local_invocation_index_id, interface, context.function, ), @@ -1679,7 +1691,21 @@ impl Writer { function.to_words(&mut self.logical_layout.function_definitions); - Ok(function_id) + if let Some(EntryPointContext { + mesh_state: Some(ref mesh_state), + .. + }) = function.entry_point_context + { + self.write_mesh_shader_wrapper(mesh_state, function_id) + } else if let Some(EntryPointContext { + task_payload_variable_id: Some(tp), + .. + }) = function.entry_point_context + { + self.write_task_shader_wrapper(tp, function_id) + } else { + Ok(function_id) + } } fn write_execution_mode( @@ -1702,6 +1728,7 @@ impl Writer { debug_info: &Option, ) -> Result { let mut interface_ids = Vec::new(); + let function_id = self.write_function( &entry_point.function, info, @@ -2705,7 +2732,7 @@ impl Writer { entry_id: Word, ir_module: &crate::Module, info: &FunctionInfo, - local_invocation_id: Option, + local_invocation_index: Option, interface: &mut FunctionInterface, function: &mut Function, ) -> Option { @@ -2713,7 +2740,10 @@ impl Writer { .global_variables .iter() .filter(|&(handle, var)| { - !info[handle].is_empty() && var.space == crate::AddressSpace::WorkGroup + let task_exception = (var.space == crate::AddressSpace::TaskPayload) + && interface.stage == crate::ShaderStage::Task; + !info[handle].is_empty() + && (var.space == crate::AddressSpace::WorkGroup || task_exception) }) .map(|(handle, var)| { // It's safe to use `var_id` here, not `access_id`, because only @@ -2730,16 +2760,15 @@ impl Writer { return None; } - let uint3_type_id = self.get_vec3u_type_id(); - let mut pre_if_block = Block::new(entry_id); - let local_invocation_id = if let Some(local_invocation_id) = local_invocation_id { - local_invocation_id + let local_invocation_index = if let Some(local_invocation_index) = local_invocation_index { + local_invocation_index } else { let varying_id = self.id_gen.next(); let class = spirv::StorageClass::Input; - let pointer_type_id = self.get_vec3u_pointer_type_id(class); + let u32_ty_id = self.get_u32_type_id(); + let pointer_type_id = self.get_pointer_type_id(u32_ty_id, class); Instruction::variable(pointer_type_id, varying_id, class, None) .to_words(&mut self.logical_layout.declarations); @@ -2747,39 +2776,29 @@ impl Writer { self.decorate( varying_id, spirv::Decoration::BuiltIn, - &[spirv::BuiltIn::LocalInvocationId as u32], + &[spirv::BuiltIn::LocalInvocationIndex as u32], ); interface.varying_ids.push(varying_id); let id = self.id_gen.next(); pre_if_block .body - .push(Instruction::load(uint3_type_id, id, varying_id, None)); + .push(Instruction::load(u32_ty_id, id, varying_id, None)); id }; - let zero_id = self.get_constant_null(uint3_type_id); - let bool3_type_id = self.get_vec3_bool_type_id(); + let zero_id = self.get_constant_scalar(crate::Literal::U32(0)); let eq_id = self.id_gen.next(); pre_if_block.body.push(Instruction::binary( spirv::Op::IEqual, - bool3_type_id, + self.get_bool_type_id(), eq_id, - local_invocation_id, + local_invocation_index, zero_id, )); - let condition_id = self.id_gen.next(); - let bool_type_id = self.get_bool_type_id(); - pre_if_block.body.push(Instruction::relational( - spirv::Op::All, - bool_type_id, - condition_id, - eq_id, - )); - let merge_id = self.id_gen.next(); pre_if_block.body.push(Instruction::selection_merge( merge_id, @@ -2789,7 +2808,7 @@ impl Writer { let accept_id = self.id_gen.next(); function.consume( pre_if_block, - Instruction::branch_conditional(condition_id, accept_id, merge_id), + Instruction::branch_conditional(eq_id, accept_id, merge_id), ); let accept_block = Block { @@ -3022,7 +3041,6 @@ impl Writer { } if per_primitive && stage == crate::ShaderStage::Fragment { others.push(Decoration::PerPrimitiveEXT); - self.require_mesh_shaders()?; } Ok(BindingDecorations::Location { location, @@ -3034,13 +3052,6 @@ impl Writer { use crate::BuiltIn as Bi; let mut others = ArrayVec::new(); - if matches!( - built_in, - Bi::CullPrimitive | Bi::PointIndex | Bi::LineIndices | Bi::TriangleIndices - ) { - self.require_mesh_shaders()?; - } - let built_in = match built_in { Bi::Position { invariant } => { if invariant { @@ -3164,22 +3175,12 @@ impl Writer { BuiltIn::SubgroupLocalInvocationId } Bi::CullPrimitive => { - self.require_mesh_shaders()?; others.push(Decoration::PerPrimitiveEXT); BuiltIn::CullPrimitiveEXT } - Bi::PointIndex => { - self.require_mesh_shaders()?; - BuiltIn::PrimitivePointIndicesEXT - } - Bi::LineIndices => { - self.require_mesh_shaders()?; - BuiltIn::PrimitiveLineIndicesEXT - } - Bi::TriangleIndices => { - self.require_mesh_shaders()?; - BuiltIn::PrimitiveTriangleIndicesEXT - } + Bi::PointIndex => BuiltIn::PrimitivePointIndicesEXT, + Bi::LineIndices => BuiltIn::PrimitiveLineIndicesEXT, + Bi::TriangleIndices => BuiltIn::PrimitiveTriangleIndicesEXT, // No decoration, this EmitMeshTasksEXT is called at function return Bi::MeshTaskSize => return Ok(BindingDecorations::None), // These aren't normal builtins and don't occur in function output @@ -3554,17 +3555,6 @@ impl Writer { | ir_module.special_types.ray_intersection.is_some(); let has_vertex_return = ir_module.special_types.ray_vertex_return.is_some(); - // Ways mesh shaders are required: - // * Mesh entry point used - checked for - // * Mesh function like setVertex used outside mesh entry point, this is handled when those are written - // * Fragment shader with per primitive data - handled in `map_binding` - let has_mesh_shaders = ir_module.entry_points.iter().any(|entry| { - entry.stage == crate::ShaderStage::Mesh || entry.stage == crate::ShaderStage::Task - }) || ir_module - .global_variables - .iter() - .any(|gvar| gvar.1.space == crate::AddressSpace::TaskPayload); - for (_, &crate::Type { ref inner, .. }) in ir_module.types.iter() { // spirv does not know whether these have vertex return - that is done by us if let &crate::TypeInner::AccelerationStructure { .. } @@ -3591,8 +3581,13 @@ impl Writer { Instruction::extension("SPV_KHR_ray_tracing_position_fetch") .to_words(&mut self.logical_layout.extensions); } - if has_mesh_shaders { - self.require_mesh_shaders()?; + if ir_module.uses_mesh_shaders() { + self.use_extension("SPV_EXT_mesh_shader"); + self.require_any("Mesh Shaders", &[spirv::Capability::MeshShadingEXT])?; + let lang_version = self.lang_version(); + if lang_version.0 <= 1 && lang_version.1 < 4 { + return Err(Error::SpirvVersionTooLow(1, 4)); + } } Instruction::type_void(self.void_type).to_words(&mut self.logical_layout.declarations); Instruction::ext_inst_import(self.gl450_ext_inst_id, "GLSL.std.450") diff --git a/naga/src/back/wgsl/writer.rs b/naga/src/back/wgsl/writer.rs index 22209592e..039bcc156 100644 --- a/naga/src/back/wgsl/writer.rs +++ b/naga/src/back/wgsl/writer.rs @@ -288,7 +288,10 @@ impl Writer { cooperative_matrix: bool, draw_index: bool, } - let mut needed = RequiredEnabled::default(); + let mut needed = RequiredEnabled { + mesh_shaders: module.uses_mesh_shaders(), + ..Default::default() + }; let check_binding = |binding: &crate::Binding, needed: &mut RequiredEnabled| match *binding { @@ -310,19 +313,6 @@ impl Writer { needed.mesh_shaders = true; } crate::Binding::BuiltIn(crate::BuiltIn::DrawIndex) => needed.draw_index = true, - crate::Binding::BuiltIn( - crate::BuiltIn::MeshTaskSize - | crate::BuiltIn::CullPrimitive - | crate::BuiltIn::PointIndex - | crate::BuiltIn::LineIndices - | crate::BuiltIn::TriangleIndices - | crate::BuiltIn::VertexCount - | crate::BuiltIn::Vertices - | crate::BuiltIn::PrimitiveCount - | crate::BuiltIn::Primitives, - ) => { - needed.mesh_shaders = true; - } _ => {} }; @@ -347,9 +337,6 @@ impl Writer { } for ep in &module.entry_points { - if matches!(ep.stage, ShaderStage::Mesh | ShaderStage::Task) { - needed.mesh_shaders = true; - } if let Some(res) = ep.function.result.as_ref().and_then(|a| a.binding.as_ref()) { check_binding(res, &mut needed); } @@ -363,14 +350,6 @@ impl Writer { } } - if module - .global_variables - .iter() - .any(|gv| gv.1.space == crate::AddressSpace::TaskPayload) - { - needed.mesh_shaders = true; - } - // Write required declarations let mut any_written = false; if needed.f16 { @@ -385,7 +364,7 @@ impl Writer { writeln!(self.out, "enable clip_distances;")?; any_written = true; } - if needed.mesh_shaders { + if module.uses_mesh_shaders() { writeln!(self.out, "enable wgpu_mesh_shader;")?; any_written = true; } diff --git a/naga/src/proc/mod.rs b/naga/src/proc/mod.rs index af709d1ce..2ea239e56 100644 --- a/naga/src/proc/mod.rs +++ b/naga/src/proc/mod.rs @@ -673,6 +673,14 @@ impl super::ShaderStage { Self::RayGeneration | Self::AnyHit | Self::ClosestHit | Self::Miss => false, } } + + /// Mesh or task shader + pub const fn mesh_like(self) -> bool { + match self { + Self::Task | Self::Mesh => true, + _ => false, + } + } } #[test] @@ -862,4 +870,86 @@ impl crate::Module { .map(|a| a.with_span_handle(self.global_variables[gv].ty, &self.types)), ) } + + pub fn uses_mesh_shaders(&self) -> bool { + let binding_uses_mesh = |b: &crate::Binding| { + matches!( + b, + crate::Binding::BuiltIn( + crate::BuiltIn::MeshTaskSize + | crate::BuiltIn::CullPrimitive + | crate::BuiltIn::PointIndex + | crate::BuiltIn::LineIndices + | crate::BuiltIn::TriangleIndices + | crate::BuiltIn::VertexCount + | crate::BuiltIn::Vertices + | crate::BuiltIn::PrimitiveCount + | crate::BuiltIn::Primitives, + ) | crate::Binding::Location { + per_primitive: true, + .. + } + ) + }; + for (_, ty) in self.types.iter() { + match ty.inner { + crate::TypeInner::Struct { ref members, .. } => { + for binding in members.iter().filter_map(|m| m.binding.as_ref()) { + if binding_uses_mesh(binding) { + return true; + } + } + } + _ => (), + } + } + for ep in &self.entry_points { + if matches!( + ep.stage, + crate::ShaderStage::Mesh | crate::ShaderStage::Task + ) { + return true; + } + for binding in ep + .function + .arguments + .iter() + .filter_map(|arg| arg.binding.as_ref()) + .chain( + ep.function + .result + .iter() + .filter_map(|res| res.binding.as_ref()), + ) + { + if binding_uses_mesh(binding) { + return true; + } + } + } + if self + .global_variables + .iter() + .any(|gv| gv.1.space == crate::AddressSpace::TaskPayload) + { + return true; + } + false + } +} + +impl crate::MeshOutputTopology { + pub const fn to_builtin(self) -> crate::BuiltIn { + match self { + Self::Points => crate::BuiltIn::PointIndex, + Self::Lines => crate::BuiltIn::LineIndices, + Self::Triangles => crate::BuiltIn::TriangleIndices, + } + } +} + +impl crate::AddressSpace { + pub const fn is_workgroup_like(self) -> bool { + matches!(self, Self::WorkGroup | Self::TaskPayload) + } } diff --git a/naga/src/valid/analyzer.rs b/naga/src/valid/analyzer.rs index 6ffb23add..06d116a0b 100644 --- a/naga/src/valid/analyzer.rs +++ b/naga/src/valid/analyzer.rs @@ -269,7 +269,7 @@ pub struct FunctionInfo { /// `FunctionInfo` implements `core::ops::Index>`, /// so you can simply index this struct with a global handle to retrieve /// its usage information. - global_uses: Box<[GlobalUse]>, + pub global_uses: Box<[GlobalUse]>, /// Information about each expression in this function's body. /// diff --git a/naga/src/valid/interface.rs b/naga/src/valid/interface.rs index 6f470b2d8..e8cafe559 100644 --- a/naga/src/valid/interface.rs +++ b/naga/src/valid/interface.rs @@ -1372,9 +1372,11 @@ impl super::Validator { } // Task shaders must have a single `MeshTaskSize` output, and nothing else. if ep.stage == crate::ShaderStage::Task { - let ok = result_built_ins.contains(&crate::BuiltIn::MeshTaskSize) - && result_built_ins.len() == 1 - && self.location_mask.is_empty(); + let ok = module.types[fr.ty].inner + == crate::TypeInner::Vector { + size: crate::VectorSize::Tri, + scalar: crate::Scalar::U32, + }; if !ok { return Err(EntryPointError::WrongTaskShaderEntryResult.with_span()); } diff --git a/naga/tests/in/wgsl/mesh-shader-empty.wgsl b/naga/tests/in/wgsl/mesh-shader-empty.wgsl index 98a6bf844..27ed99661 100644 --- a/naga/tests/in/wgsl/mesh-shader-empty.wgsl +++ b/naga/tests/in/wgsl/mesh-shader-empty.wgsl @@ -17,7 +17,7 @@ var taskPayload: TaskPayload; @task @payload(taskPayload) -@workgroup_size(1) +@workgroup_size(64) fn ts_main() -> @builtin(mesh_task_size) vec3 { return vec3(1, 1, 1); } @@ -33,5 +33,5 @@ var mesh_output: MeshOutput; @mesh(mesh_output) @payload(taskPayload) -@workgroup_size(1) +@workgroup_size(64) fn ms_main() {} diff --git a/naga/tests/in/wgsl/mesh-shader-lines.wgsl b/naga/tests/in/wgsl/mesh-shader-lines.wgsl index c475ff106..c07bc2a7a 100644 --- a/naga/tests/in/wgsl/mesh-shader-lines.wgsl +++ b/naga/tests/in/wgsl/mesh-shader-lines.wgsl @@ -17,7 +17,7 @@ var taskPayload: TaskPayload; @task @payload(taskPayload) -@workgroup_size(1) +@workgroup_size(64) fn ts_main() -> @builtin(mesh_task_size) vec3 { return vec3(1, 1, 1); } @@ -33,5 +33,5 @@ var mesh_output: MeshOutput; @mesh(mesh_output) @payload(taskPayload) -@workgroup_size(1) +@workgroup_size(64) fn ms_main() {} diff --git a/naga/tests/in/wgsl/mesh-shader-points.wgsl b/naga/tests/in/wgsl/mesh-shader-points.wgsl index 84516ee8f..31429e2df 100644 --- a/naga/tests/in/wgsl/mesh-shader-points.wgsl +++ b/naga/tests/in/wgsl/mesh-shader-points.wgsl @@ -17,7 +17,7 @@ var taskPayload: TaskPayload; @task @payload(taskPayload) -@workgroup_size(1) +@workgroup_size(64) fn ts_main() -> @builtin(mesh_task_size) vec3 { return vec3(1, 1, 1); } @@ -33,5 +33,5 @@ var mesh_output: MeshOutput; @mesh(mesh_output) @payload(taskPayload) -@workgroup_size(1) +@workgroup_size(64) fn ms_main() {} diff --git a/naga/tests/in/wgsl/mesh-shader.wgsl b/naga/tests/in/wgsl/mesh-shader.wgsl index ca2f9c911..9b57acd10 100644 --- a/naga/tests/in/wgsl/mesh-shader.wgsl +++ b/naga/tests/in/wgsl/mesh-shader.wgsl @@ -31,13 +31,21 @@ struct PrimitiveInput { var taskPayload: TaskPayload; var workgroupData: f32; +fn helper_reader() -> bool { + return taskPayload.visible; +} +fn helper_writer(value: bool) { + taskPayload.visible = value; +} + @task @payload(taskPayload) @workgroup_size(1) fn ts_main() -> @builtin(mesh_task_size) vec3 { workgroupData = 1.0; taskPayload.colorMask = vec4(1.0, 1.0, 0.0, 1.0); - taskPayload.visible = true; + helper_writer(true); + taskPayload.visible = helper_reader(); return vec3(1, 1, 1); } @@ -45,8 +53,8 @@ fn ts_main() -> @builtin(mesh_task_size) vec3 { @task @payload(taskPayload) @workgroup_size(2) -fn ts_divergent(@builtin(local_invocation_index) thread_id: u32) -> @builtin(mesh_task_size) vec3 { - if thread_id == 0 { +fn ts_divergent(@builtin(local_invocation_id) thread_id: vec3) -> @builtin(mesh_task_size) vec3 { + if thread_id.x == 0 { taskPayload.colorMask = vec4(1.0, 1.0, 0.0, 1.0); taskPayload.visible = true; return vec3(1, 1, 1); @@ -82,7 +90,7 @@ fn ms_main() { mesh_output.vertices[2].color = colors[2] * taskPayload.colorMask; mesh_output.primitives[0].indices = vec3(0, 1, 2); - mesh_output.primitives[0].cull = !taskPayload.visible; + mesh_output.primitives[0].cull = !helper_reader(); mesh_output.primitives[0].colorMask = vec4(1.0, 0.0, 1.0, 1.0); } @@ -109,9 +117,9 @@ fn ms_no_ts() { // See ts_divergent comment @mesh(mesh_output) -@workgroup_size(1) -fn ms_divergent(@builtin(local_invocation_index) thread_id: u32) { - if thread_id == 0 { +@workgroup_size(2) +fn ms_divergent(@builtin(local_invocation_id) thread_id: vec3) { + if thread_id.x == 0 { mesh_output.vertex_count = 3; mesh_output.primitive_count = 1; workgroupData = 2.0; diff --git a/naga/tests/naga/snapshots.rs b/naga/tests/naga/snapshots.rs index 7c68812bc..a2a6a5466 100644 --- a/naga/tests/naga/snapshots.rs +++ b/naga/tests/naga/snapshots.rs @@ -57,6 +57,12 @@ fn check_targets(input: &Input, module: &mut naga::Module, source_code: Option<& }) }; + let shared_info = WriterSharedOptions { + mesh_output_validation: params.mesh_output_validation, + task_limits: params.task_limits, + bounds_checks_policies: params.bounds_check_policies, + }; + { if targets.contains(Targets::ANALYSIS) { let config = ron::ser::PrettyConfig::default().new_line("\n".to_string()); @@ -84,8 +90,8 @@ fn check_targets(input: &Input, module: &mut naga::Module, source_code: Option<& &info, debug_info, ¶ms.spv, - params.bounds_check_policies, ¶ms.pipeline_constants, + &shared_info, ); } @@ -169,12 +175,12 @@ fn write_output_spv( info: &naga::valid::ModuleInfo, debug_info: Option, params: &SpirvOutParameters, - bounds_check_policies: naga::proc::BoundsCheckPolicies, pipeline_constants: &naga::back::PipelineConstants, + shared_options: &WriterSharedOptions, ) { use naga::back::spv; - let options = params.to_options(bounds_check_policies, debug_info); + let options = params.to_options(shared_options, debug_info); let (module, info) = naga::back::pipeline_constants::process_overrides(module, info, None, pipeline_constants) diff --git a/naga/tests/out/spv/wgsl-abstract-types-operators.spvasm b/naga/tests/out/spv/wgsl-abstract-types-operators.spvasm index 4ce80049d..c64e2c1b7 100644 --- a/naga/tests/out/spv/wgsl-abstract-types-operators.spvasm +++ b/naga/tests/out/spv/wgsl-abstract-types-operators.spvasm @@ -1,14 +1,14 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 131 +; Bound: 127 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %112 "main" %116 +OpEntryPoint GLCompute %112 "main" %115 OpExecutionMode %112 LocalSize 1 1 1 OpDecorate %6 ArrayStride 4 -OpDecorate %116 BuiltIn LocalInvocationId +OpDecorate %115 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeFloat 32 %4 = OpTypeInt 32 1 @@ -56,13 +56,10 @@ OpDecorate %116 BuiltIn LocalInvocationId %102 = OpConstant %3 7 %108 = OpTypePointer Workgroup %5 %114 = OpConstantNull %6 -%115 = OpTypeVector %5 3 -%117 = OpTypePointer Input %115 -%116 = OpVariable %117 Input -%119 = OpConstantNull %115 -%121 = OpTypeBool -%120 = OpTypeVector %121 3 -%126 = OpConstant %5 264 +%116 = OpTypePointer Input %5 +%115 = OpVariable %116 Input +%119 = OpTypeBool +%122 = OpConstant %5 264 %20 = OpFunction %2 None %21 %19 = OpLabel %63 = OpVariable %36 Function %64 @@ -152,20 +149,19 @@ OpFunctionEnd %111 = OpLabel OpBranch %113 %113 = OpLabel -%118 = OpLoad %115 %116 -%122 = OpIEqual %120 %118 %119 -%123 = OpAll %121 %122 -OpSelectionMerge %124 None -OpBranchConditional %123 %125 %124 -%125 = OpLabel +%117 = OpLoad %5 %115 +%118 = OpIEqual %119 %117 %11 +OpSelectionMerge %120 None +OpBranchConditional %118 %121 %120 +%121 = OpLabel OpStore %17 %114 -OpBranch %124 -%124 = OpLabel -OpControlBarrier %30 %30 %126 -OpBranch %127 -%127 = OpLabel -%128 = OpFunctionCall %2 %20 -%129 = OpFunctionCall %2 %100 -%130 = OpFunctionCall %2 %105 +OpBranch %120 +%120 = OpLabel +OpControlBarrier %30 %30 %122 +OpBranch %123 +%123 = OpLabel +%124 = OpFunctionCall %2 %20 +%125 = OpFunctionCall %2 %100 +%126 = OpFunctionCall %2 %105 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-atomicOps-int64.spvasm b/naga/tests/out/spv/wgsl-atomicOps-int64.spvasm index 15ecf9db0..678c70a71 100644 --- a/naga/tests/out/spv/wgsl-atomicOps-int64.spvasm +++ b/naga/tests/out/spv/wgsl-atomicOps-int64.spvasm @@ -8,7 +8,7 @@ OpCapability Int64Atomics OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %32 "cs_main" %29 +OpEntryPoint GLCompute %32 "cs_main" %29 %49 OpExecutionMode %32 LocalSize 2 1 1 OpDecorate %5 ArrayStride 8 OpMemberDecorate %8 0 Offset 0 @@ -30,6 +30,7 @@ OpDecorate %19 Binding 2 OpDecorate %20 Block OpMemberDecorate %20 0 Offset 0 OpDecorate %29 BuiltIn LocalInvocationId +OpDecorate %49 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 64 0 %4 = OpTypeInt 64 1 @@ -70,8 +71,8 @@ OpDecorate %29 BuiltIn LocalInvocationId %46 = OpConstantNull %3 %47 = OpConstantNull %5 %48 = OpConstantNull %8 -%49 = OpConstantNull %9 -%50 = OpTypeVector %10 3 +%50 = OpTypePointer Input %7 +%49 = OpVariable %50 Input %55 = OpConstant %7 264 %58 = OpTypeInt 32 1 %57 = OpConstant %58 1 @@ -87,8 +88,8 @@ OpDecorate %29 BuiltIn LocalInvocationId %40 = OpAccessChain %39 %19 %35 OpBranch %45 %45 = OpLabel -%51 = OpIEqual %50 %31 %49 -%52 = OpAll %10 %51 +%51 = OpLoad %7 %49 +%52 = OpIEqual %10 %51 %35 OpSelectionMerge %53 None OpBranchConditional %52 %54 %53 %54 = OpLabel diff --git a/naga/tests/out/spv/wgsl-atomicOps.spvasm b/naga/tests/out/spv/wgsl-atomicOps.spvasm index 839200d76..70f07928d 100644 --- a/naga/tests/out/spv/wgsl-atomicOps.spvasm +++ b/naga/tests/out/spv/wgsl-atomicOps.spvasm @@ -6,7 +6,7 @@ OpCapability Shader OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %31 "cs_main" %28 +OpEntryPoint GLCompute %31 "cs_main" %28 %47 OpExecutionMode %31 LocalSize 2 1 1 OpDecorate %5 ArrayStride 4 OpMemberDecorate %7 0 Offset 0 @@ -28,6 +28,7 @@ OpDecorate %18 Binding 2 OpDecorate %19 Block OpMemberDecorate %19 0 Offset 0 OpDecorate %28 BuiltIn LocalInvocationId +OpDecorate %47 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 0 %4 = OpTypeInt 32 1 @@ -66,8 +67,8 @@ OpDecorate %28 BuiltIn LocalInvocationId %44 = OpConstantNull %3 %45 = OpConstantNull %5 %46 = OpConstantNull %7 -%47 = OpConstantNull %8 -%48 = OpTypeVector %9 3 +%48 = OpTypePointer Input %3 +%47 = OpVariable %48 Input %53 = OpConstant %3 264 %55 = OpTypePointer StorageBuffer %4 %59 = OpTypePointer Workgroup %4 @@ -79,8 +80,8 @@ OpDecorate %28 BuiltIn LocalInvocationId %39 = OpAccessChain %38 %18 %34 OpBranch %43 %43 = OpLabel -%49 = OpIEqual %48 %30 %47 -%50 = OpAll %9 %49 +%49 = OpLoad %3 %47 +%50 = OpIEqual %9 %49 %34 OpSelectionMerge %51 None OpBranchConditional %50 %52 %51 %52 = OpLabel diff --git a/naga/tests/out/spv/wgsl-globals.spvasm b/naga/tests/out/spv/wgsl-globals.spvasm index 2b68ed5a1..7253b9aab 100644 --- a/naga/tests/out/spv/wgsl-globals.spvasm +++ b/naga/tests/out/spv/wgsl-globals.spvasm @@ -1,12 +1,12 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 197 +; Bound: 193 OpCapability Shader OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %114 "main" %139 +OpEntryPoint GLCompute %114 "main" %138 OpExecutionMode %114 LocalSize 1 1 1 OpDecorate %5 ArrayStride 4 OpMemberDecorate %9 0 Offset 0 @@ -57,7 +57,7 @@ OpDecorate %52 DescriptorSet 0 OpDecorate %52 Binding 7 OpDecorate %53 Block OpMemberDecorate %53 0 Offset 0 -OpDecorate %139 BuiltIn LocalInvocationId +OpDecorate %138 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeBool %4 = OpTypeFloat 32 @@ -139,28 +139,25 @@ OpDecorate %139 BuiltIn LocalInvocationId %134 = OpTypePointer Function %3 %136 = OpConstantNull %5 %137 = OpConstantNull %7 -%138 = OpTypeVector %7 3 -%140 = OpTypePointer Input %138 -%139 = OpVariable %140 Input -%142 = OpConstantNull %138 -%143 = OpTypeVector %3 3 -%148 = OpConstant %7 264 -%151 = OpTypePointer Workgroup %4 -%152 = OpTypePointer Uniform %21 -%153 = OpTypePointer Uniform %20 -%154 = OpTypePointer Uniform %26 -%158 = OpTypePointer Uniform %17 -%159 = OpTypePointer Uniform %16 -%160 = OpTypePointer Uniform %12 -%165 = OpConstant %7 7 -%172 = OpConstant %7 6 -%174 = OpTypePointer StorageBuffer %10 -%175 = OpConstant %7 1 -%178 = OpConstant %7 5 -%180 = OpTypePointer Uniform %4 -%181 = OpConstant %7 3 -%184 = OpConstant %7 4 -%196 = OpConstant %23 2 +%139 = OpTypePointer Input %7 +%138 = OpVariable %139 Input +%144 = OpConstant %7 264 +%147 = OpTypePointer Workgroup %4 +%148 = OpTypePointer Uniform %21 +%149 = OpTypePointer Uniform %20 +%150 = OpTypePointer Uniform %26 +%154 = OpTypePointer Uniform %17 +%155 = OpTypePointer Uniform %16 +%156 = OpTypePointer Uniform %12 +%161 = OpConstant %7 7 +%168 = OpConstant %7 6 +%170 = OpTypePointer StorageBuffer %10 +%171 = OpConstant %7 1 +%174 = OpConstant %7 5 +%176 = OpTypePointer Uniform %4 +%177 = OpConstant %7 3 +%180 = OpConstant %7 4 +%192 = OpConstant %23 2 %57 = OpFunction %2 None %58 %56 = OpFunctionParameter %8 %55 = OpLabel @@ -231,58 +228,57 @@ OpFunctionEnd %127 = OpAccessChain %126 %52 %64 OpBranch %135 %135 = OpLabel -%141 = OpLoad %138 %139 -%144 = OpIEqual %143 %141 %142 -%145 = OpAll %3 %144 -OpSelectionMerge %146 None -OpBranchConditional %145 %147 %146 -%147 = OpLabel +%140 = OpLoad %7 %138 +%141 = OpIEqual %3 %140 %64 +OpSelectionMerge %142 None +OpBranchConditional %141 %143 %142 +%143 = OpLabel OpStore %30 %136 OpStore %32 %137 -OpBranch %146 -%146 = OpLabel -OpControlBarrier %18 %18 %148 -OpBranch %149 -%149 = OpLabel -%150 = OpFunctionCall %2 %61 -%155 = OpAccessChain %154 %127 %64 %64 -%156 = OpLoad %26 %155 -%157 = OpFunctionCall %20 %96 %156 -%161 = OpAccessChain %160 %125 %64 %64 %64 -%162 = OpLoad %12 %161 -%163 = OpMatrixTimesVector %10 %157 %162 -%164 = OpCompositeExtract %4 %163 0 -%166 = OpAccessChain %151 %30 %165 -OpStore %166 %164 -%167 = OpLoad %25 %123 -%168 = OpFunctionCall %15 %105 %167 -%169 = OpLoad %8 %121 -%170 = OpMatrixTimesVector %10 %168 %169 -%171 = OpCompositeExtract %4 %170 0 -%173 = OpAccessChain %151 %30 %172 -OpStore %173 %171 -%176 = OpAccessChain %77 %117 %175 %175 -%177 = OpLoad %4 %176 -%179 = OpAccessChain %151 %30 %178 -OpStore %179 %177 -%182 = OpAccessChain %180 %119 %64 %181 +OpBranch %142 +%142 = OpLabel +OpControlBarrier %18 %18 %144 +OpBranch %145 +%145 = OpLabel +%146 = OpFunctionCall %2 %61 +%151 = OpAccessChain %150 %127 %64 %64 +%152 = OpLoad %26 %151 +%153 = OpFunctionCall %20 %96 %152 +%157 = OpAccessChain %156 %125 %64 %64 %64 +%158 = OpLoad %12 %157 +%159 = OpMatrixTimesVector %10 %153 %158 +%160 = OpCompositeExtract %4 %159 0 +%162 = OpAccessChain %147 %30 %161 +OpStore %162 %160 +%163 = OpLoad %25 %123 +%164 = OpFunctionCall %15 %105 %163 +%165 = OpLoad %8 %121 +%166 = OpMatrixTimesVector %10 %164 %165 +%167 = OpCompositeExtract %4 %166 0 +%169 = OpAccessChain %147 %30 %168 +OpStore %169 %167 +%172 = OpAccessChain %77 %117 %171 %171 +%173 = OpLoad %4 %172 +%175 = OpAccessChain %147 %30 %174 +OpStore %175 %173 +%178 = OpAccessChain %176 %119 %64 %177 +%179 = OpLoad %4 %178 +%181 = OpAccessChain %147 %30 %180 +OpStore %181 %179 +%182 = OpAccessChain %77 %115 %171 %183 = OpLoad %4 %182 -%185 = OpAccessChain %151 %30 %184 -OpStore %185 %183 -%186 = OpAccessChain %77 %115 %175 -%187 = OpLoad %4 %186 -%188 = OpAccessChain %151 %30 %181 -OpStore %188 %187 -%189 = OpAccessChain %77 %115 %64 %64 -%190 = OpLoad %4 %189 -%191 = OpAccessChain %151 %30 %18 +%184 = OpAccessChain %147 %30 %177 +OpStore %184 %183 +%185 = OpAccessChain %77 %115 %64 %64 +%186 = OpLoad %4 %185 +%187 = OpAccessChain %147 %30 %18 +OpStore %187 %186 +%188 = OpAccessChain %77 %115 %171 +OpStore %188 %130 +%189 = OpArrayLength %7 %37 0 +%190 = OpConvertUToF %4 %189 +%191 = OpAccessChain %147 %30 %171 OpStore %191 %190 -%192 = OpAccessChain %77 %115 %175 -OpStore %192 %130 -%193 = OpArrayLength %7 %37 0 -%194 = OpConvertUToF %4 %193 -%195 = OpAccessChain %151 %30 %175 -OpStore %195 %194 -OpAtomicStore %32 %196 %64 %18 +OpAtomicStore %32 %192 %64 %18 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-interface.compute.spvasm b/naga/tests/out/spv/wgsl-interface.compute.spvasm index 912d28d5b..c3fb080b7 100644 --- a/naga/tests/out/spv/wgsl-interface.compute.spvasm +++ b/naga/tests/out/spv/wgsl-interface.compute.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.0 ; Generator: rspirv -; Bound: 53 +; Bound: 50 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 @@ -43,12 +43,10 @@ OpDecorate %27 BuiltIn NumWorkgroups %27 = OpVariable %18 Input %30 = OpTypeFunction %2 %32 = OpConstantNull %9 -%33 = OpConstantNull %11 -%34 = OpTypeVector %8 3 -%39 = OpConstant %6 2 -%40 = OpConstant %6 264 -%42 = OpTypePointer Workgroup %6 -%51 = OpConstant %6 0 +%33 = OpConstant %6 0 +%37 = OpConstant %6 2 +%38 = OpConstant %6 264 +%40 = OpTypePointer Workgroup %6 %29 = OpFunction %2 None %30 %16 = OpLabel %19 = OpLoad %11 %17 @@ -58,26 +56,25 @@ OpDecorate %27 BuiltIn NumWorkgroups %28 = OpLoad %11 %27 OpBranch %31 %31 = OpLabel -%35 = OpIEqual %34 %21 %33 -%36 = OpAll %8 %35 -OpSelectionMerge %37 None -OpBranchConditional %36 %38 %37 -%38 = OpLabel +%34 = OpIEqual %8 %24 %33 +OpSelectionMerge %35 None +OpBranchConditional %34 %36 %35 +%36 = OpLabel OpStore %14 %32 -OpBranch %37 -%37 = OpLabel -OpControlBarrier %39 %39 %40 -OpBranch %41 -%41 = OpLabel -%43 = OpCompositeExtract %6 %19 0 -%44 = OpCompositeExtract %6 %21 0 -%45 = OpIAdd %6 %43 %44 -%46 = OpIAdd %6 %45 %24 -%47 = OpCompositeExtract %6 %26 0 +OpBranch %35 +%35 = OpLabel +OpControlBarrier %37 %37 %38 +OpBranch %39 +%39 = OpLabel +%41 = OpCompositeExtract %6 %19 0 +%42 = OpCompositeExtract %6 %21 0 +%43 = OpIAdd %6 %41 %42 +%44 = OpIAdd %6 %43 %24 +%45 = OpCompositeExtract %6 %26 0 +%46 = OpIAdd %6 %44 %45 +%47 = OpCompositeExtract %6 %28 0 %48 = OpIAdd %6 %46 %47 -%49 = OpCompositeExtract %6 %28 0 -%50 = OpIAdd %6 %48 %49 -%52 = OpAccessChain %42 %14 %51 -OpStore %52 %50 +%49 = OpAccessChain %40 %14 %33 +OpStore %49 %48 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-mesh-shader-empty.spvasm b/naga/tests/out/spv/wgsl-mesh-shader-empty.spvasm index 378341328..0f03fdb21 100644 --- a/naga/tests/out/spv/wgsl-mesh-shader-empty.spvasm +++ b/naga/tests/out/spv/wgsl-mesh-shader-empty.spvasm @@ -1,23 +1,23 @@ ; SPIR-V ; Version: 1.4 ; Generator: rspirv -; Bound: 100 +; Bound: 135 OpCapability Shader OpCapability MeshShadingEXT OpExtension "SPV_EXT_mesh_shader" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint TaskEXT %20 "ts_main" %15 -OpEntryPoint MeshEXT %44 "ms_main" %15 %30 %40 %43 %17 %47 -OpExecutionMode %20 LocalSize 1 1 1 -OpExecutionMode %44 LocalSize 1 1 1 -OpExecutionMode %44 OutputTrianglesEXT -OpExecutionMode %44 OutputVertices 3 -OpExecutionMode %44 OutputPrimitivesEXT 1 -OpDecorate %30 BuiltIn LocalInvocationIndex -OpMemberDecorate %37 0 BuiltIn Position -OpDecorate %37 Block -OpDecorate %43 BuiltIn PrimitiveTriangleIndicesEXT +OpEntryPoint TaskEXT %36 "ts_main" %15 %25 +OpEntryPoint MeshEXT %87 "ms_main" %15 %69 %74 %77 %17 %81 +OpExecutionMode %36 LocalSize 64 1 1 +OpExecutionMode %87 LocalSize 64 1 1 +OpExecutionMode %87 OutputTrianglesEXT +OpExecutionMode %87 OutputVertices 3 +OpExecutionMode %87 OutputPrimitivesEXT 1 +OpDecorate %69 BuiltIn LocalInvocationIndex +OpMemberDecorate %71 0 BuiltIn Position +OpDecorate %71 Block +OpDecorate %77 BuiltIn PrimitiveTriangleIndicesEXT OpMemberDecorate %4 0 Offset 0 OpMemberDecorate %7 0 Offset 0 OpMemberDecorate %9 0 Offset 0 @@ -27,7 +27,8 @@ OpMemberDecorate %14 0 Offset 0 OpMemberDecorate %14 1 Offset 48 OpMemberDecorate %14 2 Offset 64 OpMemberDecorate %14 3 Offset 68 -OpDecorate %47 BuiltIn LocalInvocationId +OpDecorate %25 BuiltIn LocalInvocationIndex +OpDecorate %81 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 0 %4 = OpTypeStruct %3 @@ -45,119 +46,162 @@ OpDecorate %47 BuiltIn LocalInvocationId %15 = OpVariable %16 TaskPayloadWorkgroupEXT %18 = OpTypePointer Workgroup %14 %17 = OpVariable %18 Workgroup -%21 = OpTypeFunction %2 +%21 = OpTypeFunction %8 %22 = OpConstantComposite %8 %13 %13 %13 -%24 = OpConstant %3 2 -%25 = OpConstant %3 264 -%31 = OpTypePointer Input %3 -%30 = OpVariable %31 Input -%35 = OpTypePointer Function %3 -%37 = OpTypeStruct %5 -%38 = OpTypeArray %37 %11 -%39 = OpTypePointer Output %38 -%40 = OpVariable %39 Output -%41 = OpTypeArray %8 %13 -%42 = OpTypePointer Output %41 -%43 = OpVariable %42 Output -%46 = OpConstantNull %14 -%48 = OpTypePointer Input %8 -%47 = OpVariable %48 Input -%50 = OpConstantNull %8 -%52 = OpTypeBool -%51 = OpTypeVector %52 3 -%59 = OpTypePointer Workgroup %3 -%66 = OpTypePointer Workgroup %10 -%67 = OpConstant %3 0 -%69 = OpTypePointer Workgroup %12 -%76 = OpTypePointer Workgroup %5 -%79 = OpTypePointer Output %5 -%89 = OpTypePointer Workgroup %8 -%92 = OpTypePointer Output %8 -%20 = OpFunction %2 None %21 +%24 = OpConstantNull %4 +%26 = OpTypePointer Input %3 +%25 = OpVariable %26 Input +%28 = OpConstant %3 0 +%30 = OpTypeBool +%33 = OpConstant %3 2 +%34 = OpConstant %3 264 +%37 = OpTypeFunction %2 +%40 = OpConstant %3 256 +%41 = OpConstant %3 1024 +%42 = OpTypeStruct %3 %3 +%69 = OpVariable %26 Input +%70 = OpConstant %3 64 +%71 = OpTypeStruct %5 +%72 = OpTypeArray %71 %11 +%73 = OpTypePointer Output %72 +%74 = OpVariable %73 Output +%75 = OpTypeArray %8 %13 +%76 = OpTypePointer Output %75 +%77 = OpVariable %76 Output +%80 = OpConstantNull %14 +%81 = OpVariable %26 Input +%91 = OpTypePointer Function %3 +%95 = OpTypePointer Workgroup %3 +%102 = OpTypePointer Workgroup %10 +%104 = OpTypePointer Workgroup %12 +%111 = OpTypePointer Workgroup %5 +%114 = OpTypePointer Output %5 +%124 = OpTypePointer Workgroup %8 +%127 = OpTypePointer Output %8 +%20 = OpFunction %8 None %21 %19 = OpLabel OpBranch %23 %23 = OpLabel -OpControlBarrier %24 %24 %25 -%26 = OpCompositeExtract %3 %22 0 -%27 = OpCompositeExtract %3 %22 1 -%28 = OpCompositeExtract %3 %22 2 -OpEmitMeshTasksEXT %26 %27 %28 %15 +%27 = OpLoad %3 %25 +%29 = OpIEqual %30 %27 %28 +OpSelectionMerge %31 None +OpBranchConditional %29 %32 %31 +%32 = OpLabel +OpStore %15 %24 +OpBranch %31 +%31 = OpLabel +OpControlBarrier %33 %33 %34 +OpBranch %35 +%35 = OpLabel +OpReturnValue %22 OpFunctionEnd -%44 = OpFunction %2 None %21 -%29 = OpLabel -%33 = OpVariable %35 Function -%34 = OpVariable %35 Function -%32 = OpLoad %3 %30 -OpBranch %45 -%45 = OpLabel -%49 = OpLoad %8 %47 -%53 = OpIEqual %51 %49 %50 -%54 = OpAll %52 %53 -OpSelectionMerge %55 None -OpBranchConditional %54 %56 %55 -%56 = OpLabel -OpStore %17 %46 -OpBranch %55 -%55 = OpLabel -OpControlBarrier %24 %24 %25 -OpBranch %57 -%57 = OpLabel -OpBranch %36 -%36 = OpLabel -OpControlBarrier %24 %24 %25 -%58 = OpAccessChain %59 %17 %24 -%60 = OpLoad %3 %58 -%61 = OpExtInst %3 %1 UMin %60 %11 -%62 = OpAccessChain %59 %17 %11 -%63 = OpLoad %3 %62 -%64 = OpExtInst %3 %1 UMin %63 %13 -%65 = OpAccessChain %66 %17 %67 -%68 = OpAccessChain %69 %17 %13 -OpControlBarrier %24 %24 %25 -OpSetMeshOutputsEXT %61 %64 -OpStore %33 %32 -OpBranch %70 -%70 = OpLabel -OpLoopMerge %72 %81 None -OpBranch %80 -%80 = OpLabel -%83 = OpLoad %3 %33 -%84 = OpULessThan %52 %83 %61 -OpBranchConditional %84 %82 %72 -%82 = OpLabel -%74 = OpLoad %3 %33 -%75 = OpAccessChain %76 %65 %74 %67 -%77 = OpLoad %5 %75 -%78 = OpAccessChain %79 %40 %74 %67 -OpStore %78 %77 -OpBranch %81 -%81 = OpLabel -%85 = OpLoad %3 %33 -%86 = OpIAdd %3 %85 %13 -OpStore %33 %86 -OpBranch %70 -%72 = OpLabel -OpStore %34 %32 -OpBranch %71 -%71 = OpLabel -OpLoopMerge %73 %94 None -OpBranch %93 -%93 = OpLabel -%96 = OpLoad %3 %34 -%97 = OpULessThan %52 %96 %64 -OpBranchConditional %97 %95 %73 -%95 = OpLabel -%87 = OpLoad %3 %34 -%88 = OpAccessChain %89 %68 %87 %67 -%90 = OpLoad %8 %88 -%91 = OpAccessChain %92 %43 %87 -OpStore %91 %90 -OpBranch %94 -%94 = OpLabel -%98 = OpLoad %3 %34 -%99 = OpIAdd %3 %98 %13 -OpStore %34 %99 -OpBranch %71 -%73 = OpLabel +%36 = OpFunction %2 None %37 +%38 = OpLabel +%39 = OpFunctionCall %8 %20 +OpControlBarrier %33 %33 %34 +%43 = OpCompositeExtract %3 %39 0 +%44 = OpCompositeExtract %3 %39 1 +%45 = OpCompositeExtract %3 %39 2 +%49 = OpUMulExtended %42 %43 %44 +%46 = OpCompositeExtract %3 %49 0 +%47 = OpCompositeExtract %3 %49 1 +%51 = OpUMulExtended %42 %46 %45 +%50 = OpCompositeExtract %3 %51 0 +%48 = OpCompositeExtract %3 %51 1 +%52 = OpUGreaterThan %30 %50 %41 +%53 = OpUGreaterThan %30 %43 %40 +%54 = OpUGreaterThan %30 %44 %40 +%55 = OpUGreaterThan %30 %45 %40 +%56 = OpINotEqual %30 %47 %28 +%57 = OpINotEqual %30 %48 %28 +%58 = OpLogicalOr %30 %52 %53 +%59 = OpLogicalOr %30 %58 %54 +%60 = OpLogicalOr %30 %59 %55 +%61 = OpLogicalOr %30 %60 %56 +%62 = OpLogicalOr %30 %61 %57 +%63 = OpCompositeConstruct %8 %28 %28 %28 +%64 = OpSelect %8 %62 %63 %39 +%65 = OpCompositeExtract %3 %64 0 +%66 = OpCompositeExtract %3 %64 1 +%67 = OpCompositeExtract %3 %64 2 +OpEmitMeshTasksEXT %65 %66 %67 %15 +OpFunctionEnd +%78 = OpFunction %2 None %37 +%68 = OpLabel +OpBranch %79 +%79 = OpLabel +%82 = OpLoad %3 %81 +%83 = OpIEqual %30 %82 %28 +OpSelectionMerge %84 None +OpBranchConditional %83 %85 %84 +%85 = OpLabel +OpStore %17 %80 +OpBranch %84 +%84 = OpLabel +OpControlBarrier %33 %33 %34 +OpBranch %86 +%86 = OpLabel +OpReturn +OpFunctionEnd +%87 = OpFunction %2 None %37 +%88 = OpLabel +%89 = OpVariable %91 Function +%90 = OpVariable %91 Function +%92 = OpLoad %3 %69 +%93 = OpFunctionCall %2 %78 +OpControlBarrier %33 %33 %34 +%94 = OpAccessChain %95 %17 %33 +%96 = OpLoad %3 %94 +%97 = OpExtInst %3 %1 UMin %96 %11 +%98 = OpAccessChain %95 %17 %11 +%99 = OpLoad %3 %98 +%100 = OpExtInst %3 %1 UMin %99 %13 +%101 = OpAccessChain %102 %17 %28 +%103 = OpAccessChain %104 %17 %13 +OpSetMeshOutputsEXT %97 %100 +OpStore %89 %92 +OpBranch %105 +%105 = OpLabel +OpLoopMerge %107 %116 None +OpBranch %115 +%115 = OpLabel +%118 = OpLoad %3 %89 +%119 = OpULessThan %30 %118 %97 +OpBranchConditional %119 %117 %107 +%117 = OpLabel +%109 = OpLoad %3 %89 +%110 = OpAccessChain %111 %101 %109 %28 +%112 = OpLoad %5 %110 +%113 = OpAccessChain %114 %74 %109 %28 +OpStore %113 %112 +OpBranch %116 +%116 = OpLabel +%120 = OpLoad %3 %89 +%121 = OpIAdd %3 %120 %70 +OpStore %89 %121 +OpBranch %105 +%107 = OpLabel +OpStore %90 %92 +OpBranch %106 +%106 = OpLabel +OpLoopMerge %108 %129 None +OpBranch %128 +%128 = OpLabel +%131 = OpLoad %3 %90 +%132 = OpULessThan %30 %131 %100 +OpBranchConditional %132 %130 %108 +%130 = OpLabel +%122 = OpLoad %3 %90 +%123 = OpAccessChain %124 %103 %122 %28 +%125 = OpLoad %8 %123 +%126 = OpAccessChain %127 %77 %122 +OpStore %126 %125 +OpBranch %129 +%129 = OpLabel +%133 = OpLoad %3 %90 +%134 = OpIAdd %3 %133 %70 +OpStore %90 %134 +OpBranch %106 +%108 = OpLabel OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-mesh-shader-lines.spvasm b/naga/tests/out/spv/wgsl-mesh-shader-lines.spvasm index 0bf21f6ad..b281d20fa 100644 --- a/naga/tests/out/spv/wgsl-mesh-shader-lines.spvasm +++ b/naga/tests/out/spv/wgsl-mesh-shader-lines.spvasm @@ -1,23 +1,23 @@ ; SPIR-V ; Version: 1.4 ; Generator: rspirv -; Bound: 101 +; Bound: 136 OpCapability Shader OpCapability MeshShadingEXT OpExtension "SPV_EXT_mesh_shader" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint TaskEXT %21 "ts_main" %16 -OpEntryPoint MeshEXT %44 "ms_main" %16 %30 %40 %43 %18 %47 -OpExecutionMode %21 LocalSize 1 1 1 -OpExecutionMode %44 LocalSize 1 1 1 -OpExecutionMode %44 OutputLinesEXT -OpExecutionMode %44 OutputVertices 2 -OpExecutionMode %44 OutputPrimitivesEXT 1 -OpDecorate %30 BuiltIn LocalInvocationIndex -OpMemberDecorate %37 0 BuiltIn Position -OpDecorate %37 Block -OpDecorate %43 BuiltIn PrimitiveLineIndicesEXT +OpEntryPoint TaskEXT %36 "ts_main" %16 %26 +OpEntryPoint MeshEXT %87 "ms_main" %16 %69 %74 %77 %18 %81 +OpExecutionMode %36 LocalSize 64 1 1 +OpExecutionMode %87 LocalSize 64 1 1 +OpExecutionMode %87 OutputLinesEXT +OpExecutionMode %87 OutputVertices 2 +OpExecutionMode %87 OutputPrimitivesEXT 1 +OpDecorate %69 BuiltIn LocalInvocationIndex +OpMemberDecorate %71 0 BuiltIn Position +OpDecorate %71 Block +OpDecorate %77 BuiltIn PrimitiveLineIndicesEXT OpMemberDecorate %4 0 Offset 0 OpMemberDecorate %7 0 Offset 0 OpMemberDecorate %9 0 Offset 0 @@ -27,7 +27,8 @@ OpMemberDecorate %15 0 Offset 0 OpMemberDecorate %15 1 Offset 32 OpMemberDecorate %15 2 Offset 40 OpMemberDecorate %15 3 Offset 44 -OpDecorate %47 BuiltIn LocalInvocationId +OpDecorate %26 BuiltIn LocalInvocationIndex +OpDecorate %81 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 0 %4 = OpTypeStruct %3 @@ -46,119 +47,162 @@ OpDecorate %47 BuiltIn LocalInvocationId %16 = OpVariable %17 TaskPayloadWorkgroupEXT %19 = OpTypePointer Workgroup %15 %18 = OpVariable %19 Workgroup -%22 = OpTypeFunction %2 +%22 = OpTypeFunction %10 %23 = OpConstantComposite %10 %14 %14 %14 -%25 = OpConstant %3 264 -%31 = OpTypePointer Input %3 -%30 = OpVariable %31 Input -%35 = OpTypePointer Function %3 -%37 = OpTypeStruct %5 -%38 = OpTypeArray %37 %12 -%39 = OpTypePointer Output %38 -%40 = OpVariable %39 Output -%41 = OpTypeArray %8 %14 -%42 = OpTypePointer Output %41 -%43 = OpVariable %42 Output -%46 = OpConstantNull %15 -%48 = OpTypePointer Input %10 -%47 = OpVariable %48 Input -%50 = OpConstantNull %10 -%52 = OpTypeBool -%51 = OpTypeVector %52 3 -%59 = OpTypePointer Workgroup %3 -%63 = OpConstant %3 3 -%67 = OpTypePointer Workgroup %11 -%68 = OpConstant %3 0 -%70 = OpTypePointer Workgroup %13 -%77 = OpTypePointer Workgroup %5 -%80 = OpTypePointer Output %5 -%90 = OpTypePointer Workgroup %8 -%93 = OpTypePointer Output %8 -%21 = OpFunction %2 None %22 +%25 = OpConstantNull %4 +%27 = OpTypePointer Input %3 +%26 = OpVariable %27 Input +%29 = OpConstant %3 0 +%31 = OpTypeBool +%34 = OpConstant %3 264 +%37 = OpTypeFunction %2 +%40 = OpConstant %3 256 +%41 = OpConstant %3 1024 +%42 = OpTypeStruct %3 %3 +%69 = OpVariable %27 Input +%70 = OpConstant %3 64 +%71 = OpTypeStruct %5 +%72 = OpTypeArray %71 %12 +%73 = OpTypePointer Output %72 +%74 = OpVariable %73 Output +%75 = OpTypeArray %8 %14 +%76 = OpTypePointer Output %75 +%77 = OpVariable %76 Output +%80 = OpConstantNull %15 +%81 = OpVariable %27 Input +%91 = OpTypePointer Function %3 +%95 = OpTypePointer Workgroup %3 +%99 = OpConstant %3 3 +%103 = OpTypePointer Workgroup %11 +%105 = OpTypePointer Workgroup %13 +%112 = OpTypePointer Workgroup %5 +%115 = OpTypePointer Output %5 +%125 = OpTypePointer Workgroup %8 +%128 = OpTypePointer Output %8 +%21 = OpFunction %10 None %22 %20 = OpLabel OpBranch %24 %24 = OpLabel -OpControlBarrier %12 %12 %25 -%26 = OpCompositeExtract %3 %23 0 -%27 = OpCompositeExtract %3 %23 1 -%28 = OpCompositeExtract %3 %23 2 -OpEmitMeshTasksEXT %26 %27 %28 %16 +%28 = OpLoad %3 %26 +%30 = OpIEqual %31 %28 %29 +OpSelectionMerge %32 None +OpBranchConditional %30 %33 %32 +%33 = OpLabel +OpStore %16 %25 +OpBranch %32 +%32 = OpLabel +OpControlBarrier %12 %12 %34 +OpBranch %35 +%35 = OpLabel +OpReturnValue %23 OpFunctionEnd -%44 = OpFunction %2 None %22 -%29 = OpLabel -%33 = OpVariable %35 Function -%34 = OpVariable %35 Function -%32 = OpLoad %3 %30 -OpBranch %45 -%45 = OpLabel -%49 = OpLoad %10 %47 -%53 = OpIEqual %51 %49 %50 -%54 = OpAll %52 %53 -OpSelectionMerge %55 None -OpBranchConditional %54 %56 %55 -%56 = OpLabel -OpStore %18 %46 -OpBranch %55 -%55 = OpLabel -OpControlBarrier %12 %12 %25 -OpBranch %57 -%57 = OpLabel -OpBranch %36 -%36 = OpLabel -OpControlBarrier %12 %12 %25 -%58 = OpAccessChain %59 %18 %12 -%60 = OpLoad %3 %58 -%61 = OpExtInst %3 %1 UMin %60 %12 -%62 = OpAccessChain %59 %18 %63 -%64 = OpLoad %3 %62 -%65 = OpExtInst %3 %1 UMin %64 %14 -%66 = OpAccessChain %67 %18 %68 -%69 = OpAccessChain %70 %18 %14 -OpControlBarrier %12 %12 %25 -OpSetMeshOutputsEXT %61 %65 -OpStore %33 %32 -OpBranch %71 -%71 = OpLabel -OpLoopMerge %73 %82 None -OpBranch %81 -%81 = OpLabel -%84 = OpLoad %3 %33 -%85 = OpULessThan %52 %84 %61 -OpBranchConditional %85 %83 %73 -%83 = OpLabel -%75 = OpLoad %3 %33 -%76 = OpAccessChain %77 %66 %75 %68 -%78 = OpLoad %5 %76 -%79 = OpAccessChain %80 %40 %75 %68 -OpStore %79 %78 -OpBranch %82 -%82 = OpLabel -%86 = OpLoad %3 %33 -%87 = OpIAdd %3 %86 %14 -OpStore %33 %87 -OpBranch %71 -%73 = OpLabel -OpStore %34 %32 -OpBranch %72 -%72 = OpLabel -OpLoopMerge %74 %95 None -OpBranch %94 -%94 = OpLabel -%97 = OpLoad %3 %34 -%98 = OpULessThan %52 %97 %65 -OpBranchConditional %98 %96 %74 -%96 = OpLabel -%88 = OpLoad %3 %34 -%89 = OpAccessChain %90 %69 %88 %68 -%91 = OpLoad %8 %89 -%92 = OpAccessChain %93 %43 %88 -OpStore %92 %91 -OpBranch %95 -%95 = OpLabel -%99 = OpLoad %3 %34 -%100 = OpIAdd %3 %99 %14 -OpStore %34 %100 -OpBranch %72 -%74 = OpLabel +%36 = OpFunction %2 None %37 +%38 = OpLabel +%39 = OpFunctionCall %10 %21 +OpControlBarrier %12 %12 %34 +%43 = OpCompositeExtract %3 %39 0 +%44 = OpCompositeExtract %3 %39 1 +%45 = OpCompositeExtract %3 %39 2 +%49 = OpUMulExtended %42 %43 %44 +%46 = OpCompositeExtract %3 %49 0 +%47 = OpCompositeExtract %3 %49 1 +%51 = OpUMulExtended %42 %46 %45 +%50 = OpCompositeExtract %3 %51 0 +%48 = OpCompositeExtract %3 %51 1 +%52 = OpUGreaterThan %31 %50 %41 +%53 = OpUGreaterThan %31 %43 %40 +%54 = OpUGreaterThan %31 %44 %40 +%55 = OpUGreaterThan %31 %45 %40 +%56 = OpINotEqual %31 %47 %29 +%57 = OpINotEqual %31 %48 %29 +%58 = OpLogicalOr %31 %52 %53 +%59 = OpLogicalOr %31 %58 %54 +%60 = OpLogicalOr %31 %59 %55 +%61 = OpLogicalOr %31 %60 %56 +%62 = OpLogicalOr %31 %61 %57 +%63 = OpCompositeConstruct %10 %29 %29 %29 +%64 = OpSelect %10 %62 %63 %39 +%65 = OpCompositeExtract %3 %64 0 +%66 = OpCompositeExtract %3 %64 1 +%67 = OpCompositeExtract %3 %64 2 +OpEmitMeshTasksEXT %65 %66 %67 %16 +OpFunctionEnd +%78 = OpFunction %2 None %37 +%68 = OpLabel +OpBranch %79 +%79 = OpLabel +%82 = OpLoad %3 %81 +%83 = OpIEqual %31 %82 %29 +OpSelectionMerge %84 None +OpBranchConditional %83 %85 %84 +%85 = OpLabel +OpStore %18 %80 +OpBranch %84 +%84 = OpLabel +OpControlBarrier %12 %12 %34 +OpBranch %86 +%86 = OpLabel +OpReturn +OpFunctionEnd +%87 = OpFunction %2 None %37 +%88 = OpLabel +%89 = OpVariable %91 Function +%90 = OpVariable %91 Function +%92 = OpLoad %3 %69 +%93 = OpFunctionCall %2 %78 +OpControlBarrier %12 %12 %34 +%94 = OpAccessChain %95 %18 %12 +%96 = OpLoad %3 %94 +%97 = OpExtInst %3 %1 UMin %96 %12 +%98 = OpAccessChain %95 %18 %99 +%100 = OpLoad %3 %98 +%101 = OpExtInst %3 %1 UMin %100 %14 +%102 = OpAccessChain %103 %18 %29 +%104 = OpAccessChain %105 %18 %14 +OpSetMeshOutputsEXT %97 %101 +OpStore %89 %92 +OpBranch %106 +%106 = OpLabel +OpLoopMerge %108 %117 None +OpBranch %116 +%116 = OpLabel +%119 = OpLoad %3 %89 +%120 = OpULessThan %31 %119 %97 +OpBranchConditional %120 %118 %108 +%118 = OpLabel +%110 = OpLoad %3 %89 +%111 = OpAccessChain %112 %102 %110 %29 +%113 = OpLoad %5 %111 +%114 = OpAccessChain %115 %74 %110 %29 +OpStore %114 %113 +OpBranch %117 +%117 = OpLabel +%121 = OpLoad %3 %89 +%122 = OpIAdd %3 %121 %70 +OpStore %89 %122 +OpBranch %106 +%108 = OpLabel +OpStore %90 %92 +OpBranch %107 +%107 = OpLabel +OpLoopMerge %109 %130 None +OpBranch %129 +%129 = OpLabel +%132 = OpLoad %3 %90 +%133 = OpULessThan %31 %132 %101 +OpBranchConditional %133 %131 %109 +%131 = OpLabel +%123 = OpLoad %3 %90 +%124 = OpAccessChain %125 %104 %123 %29 +%126 = OpLoad %8 %124 +%127 = OpAccessChain %128 %77 %123 +OpStore %127 %126 +OpBranch %130 +%130 = OpLabel +%134 = OpLoad %3 %90 +%135 = OpIAdd %3 %134 %70 +OpStore %90 %135 +OpBranch %107 +%109 = OpLabel OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-mesh-shader-points.spvasm b/naga/tests/out/spv/wgsl-mesh-shader-points.spvasm index 40417f670..b1ee7101a 100644 --- a/naga/tests/out/spv/wgsl-mesh-shader-points.spvasm +++ b/naga/tests/out/spv/wgsl-mesh-shader-points.spvasm @@ -1,23 +1,23 @@ ; SPIR-V ; Version: 1.4 ; Generator: rspirv -; Bound: 99 +; Bound: 134 OpCapability Shader OpCapability MeshShadingEXT OpExtension "SPV_EXT_mesh_shader" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint TaskEXT %19 "ts_main" %14 -OpEntryPoint MeshEXT %43 "ms_main" %14 %29 %39 %42 %16 %46 -OpExecutionMode %19 LocalSize 1 1 1 -OpExecutionMode %43 LocalSize 1 1 1 -OpExecutionMode %43 OutputPoints -OpExecutionMode %43 OutputVertices 1 -OpExecutionMode %43 OutputPrimitivesEXT 1 -OpDecorate %29 BuiltIn LocalInvocationIndex -OpMemberDecorate %36 0 BuiltIn Position -OpDecorate %36 Block -OpDecorate %42 BuiltIn PrimitivePointIndicesEXT +OpEntryPoint TaskEXT %35 "ts_main" %14 %24 +OpEntryPoint MeshEXT %86 "ms_main" %14 %68 %73 %76 %16 %80 +OpExecutionMode %35 LocalSize 64 1 1 +OpExecutionMode %86 LocalSize 64 1 1 +OpExecutionMode %86 OutputPoints +OpExecutionMode %86 OutputVertices 1 +OpExecutionMode %86 OutputPrimitivesEXT 1 +OpDecorate %68 BuiltIn LocalInvocationIndex +OpMemberDecorate %70 0 BuiltIn Position +OpDecorate %70 Block +OpDecorate %76 BuiltIn PrimitivePointIndicesEXT OpMemberDecorate %4 0 Offset 0 OpMemberDecorate %7 0 Offset 0 OpMemberDecorate %8 0 Offset 0 @@ -27,7 +27,8 @@ OpMemberDecorate %13 0 Offset 0 OpMemberDecorate %13 1 Offset 16 OpMemberDecorate %13 2 Offset 20 OpMemberDecorate %13 3 Offset 24 -OpDecorate %46 BuiltIn LocalInvocationId +OpDecorate %24 BuiltIn LocalInvocationIndex +OpDecorate %80 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 0 %4 = OpTypeStruct %3 @@ -44,119 +45,162 @@ OpDecorate %46 BuiltIn LocalInvocationId %14 = OpVariable %15 TaskPayloadWorkgroupEXT %17 = OpTypePointer Workgroup %13 %16 = OpVariable %17 Workgroup -%20 = OpTypeFunction %2 +%20 = OpTypeFunction %9 %21 = OpConstantComposite %9 %11 %11 %11 -%23 = OpConstant %3 2 -%24 = OpConstant %3 264 -%30 = OpTypePointer Input %3 -%29 = OpVariable %30 Input -%34 = OpTypePointer Function %3 -%36 = OpTypeStruct %5 -%37 = OpTypeArray %36 %11 -%38 = OpTypePointer Output %37 -%39 = OpVariable %38 Output -%40 = OpTypeArray %3 %11 -%41 = OpTypePointer Output %40 -%42 = OpVariable %41 Output -%45 = OpConstantNull %13 -%47 = OpTypePointer Input %9 -%46 = OpVariable %47 Input -%49 = OpConstantNull %9 -%51 = OpTypeBool -%50 = OpTypeVector %51 3 -%58 = OpTypePointer Workgroup %3 -%62 = OpConstant %3 3 -%66 = OpTypePointer Workgroup %10 -%67 = OpConstant %3 0 -%69 = OpTypePointer Workgroup %12 -%76 = OpTypePointer Workgroup %5 -%79 = OpTypePointer Output %5 -%91 = OpTypePointer Output %3 -%19 = OpFunction %2 None %20 +%23 = OpConstantNull %4 +%25 = OpTypePointer Input %3 +%24 = OpVariable %25 Input +%27 = OpConstant %3 0 +%29 = OpTypeBool +%32 = OpConstant %3 2 +%33 = OpConstant %3 264 +%36 = OpTypeFunction %2 +%39 = OpConstant %3 256 +%40 = OpConstant %3 1024 +%41 = OpTypeStruct %3 %3 +%68 = OpVariable %25 Input +%69 = OpConstant %3 64 +%70 = OpTypeStruct %5 +%71 = OpTypeArray %70 %11 +%72 = OpTypePointer Output %71 +%73 = OpVariable %72 Output +%74 = OpTypeArray %3 %11 +%75 = OpTypePointer Output %74 +%76 = OpVariable %75 Output +%79 = OpConstantNull %13 +%80 = OpVariable %25 Input +%90 = OpTypePointer Function %3 +%94 = OpTypePointer Workgroup %3 +%98 = OpConstant %3 3 +%102 = OpTypePointer Workgroup %10 +%104 = OpTypePointer Workgroup %12 +%111 = OpTypePointer Workgroup %5 +%114 = OpTypePointer Output %5 +%126 = OpTypePointer Output %3 +%19 = OpFunction %9 None %20 %18 = OpLabel OpBranch %22 %22 = OpLabel -OpControlBarrier %23 %23 %24 -%25 = OpCompositeExtract %3 %21 0 -%26 = OpCompositeExtract %3 %21 1 -%27 = OpCompositeExtract %3 %21 2 -OpEmitMeshTasksEXT %25 %26 %27 %14 +%26 = OpLoad %3 %24 +%28 = OpIEqual %29 %26 %27 +OpSelectionMerge %30 None +OpBranchConditional %28 %31 %30 +%31 = OpLabel +OpStore %14 %23 +OpBranch %30 +%30 = OpLabel +OpControlBarrier %32 %32 %33 +OpBranch %34 +%34 = OpLabel +OpReturnValue %21 OpFunctionEnd -%43 = OpFunction %2 None %20 -%28 = OpLabel -%32 = OpVariable %34 Function -%33 = OpVariable %34 Function -%31 = OpLoad %3 %29 -OpBranch %44 -%44 = OpLabel -%48 = OpLoad %9 %46 -%52 = OpIEqual %50 %48 %49 -%53 = OpAll %51 %52 -OpSelectionMerge %54 None -OpBranchConditional %53 %55 %54 -%55 = OpLabel -OpStore %16 %45 -OpBranch %54 -%54 = OpLabel -OpControlBarrier %23 %23 %24 -OpBranch %56 -%56 = OpLabel -OpBranch %35 -%35 = OpLabel -OpControlBarrier %23 %23 %24 -%57 = OpAccessChain %58 %16 %23 -%59 = OpLoad %3 %57 -%60 = OpExtInst %3 %1 UMin %59 %11 -%61 = OpAccessChain %58 %16 %62 -%63 = OpLoad %3 %61 -%64 = OpExtInst %3 %1 UMin %63 %11 -%65 = OpAccessChain %66 %16 %67 -%68 = OpAccessChain %69 %16 %11 -OpControlBarrier %23 %23 %24 -OpSetMeshOutputsEXT %60 %64 -OpStore %32 %31 -OpBranch %70 -%70 = OpLabel -OpLoopMerge %72 %81 None -OpBranch %80 -%80 = OpLabel -%83 = OpLoad %3 %32 -%84 = OpULessThan %51 %83 %60 -OpBranchConditional %84 %82 %72 -%82 = OpLabel -%74 = OpLoad %3 %32 -%75 = OpAccessChain %76 %65 %74 %67 -%77 = OpLoad %5 %75 -%78 = OpAccessChain %79 %39 %74 %67 -OpStore %78 %77 -OpBranch %81 -%81 = OpLabel -%85 = OpLoad %3 %32 -%86 = OpIAdd %3 %85 %11 -OpStore %32 %86 -OpBranch %70 -%72 = OpLabel -OpStore %33 %31 -OpBranch %71 -%71 = OpLabel -OpLoopMerge %73 %93 None -OpBranch %92 -%92 = OpLabel -%95 = OpLoad %3 %33 -%96 = OpULessThan %51 %95 %64 -OpBranchConditional %96 %94 %73 -%94 = OpLabel -%87 = OpLoad %3 %33 -%88 = OpAccessChain %58 %68 %87 %67 -%89 = OpLoad %3 %88 -%90 = OpAccessChain %91 %42 %87 -OpStore %90 %89 -OpBranch %93 -%93 = OpLabel -%97 = OpLoad %3 %33 -%98 = OpIAdd %3 %97 %11 -OpStore %33 %98 -OpBranch %71 -%73 = OpLabel +%35 = OpFunction %2 None %36 +%37 = OpLabel +%38 = OpFunctionCall %9 %19 +OpControlBarrier %32 %32 %33 +%42 = OpCompositeExtract %3 %38 0 +%43 = OpCompositeExtract %3 %38 1 +%44 = OpCompositeExtract %3 %38 2 +%48 = OpUMulExtended %41 %42 %43 +%45 = OpCompositeExtract %3 %48 0 +%46 = OpCompositeExtract %3 %48 1 +%50 = OpUMulExtended %41 %45 %44 +%49 = OpCompositeExtract %3 %50 0 +%47 = OpCompositeExtract %3 %50 1 +%51 = OpUGreaterThan %29 %49 %40 +%52 = OpUGreaterThan %29 %42 %39 +%53 = OpUGreaterThan %29 %43 %39 +%54 = OpUGreaterThan %29 %44 %39 +%55 = OpINotEqual %29 %46 %27 +%56 = OpINotEqual %29 %47 %27 +%57 = OpLogicalOr %29 %51 %52 +%58 = OpLogicalOr %29 %57 %53 +%59 = OpLogicalOr %29 %58 %54 +%60 = OpLogicalOr %29 %59 %55 +%61 = OpLogicalOr %29 %60 %56 +%62 = OpCompositeConstruct %9 %27 %27 %27 +%63 = OpSelect %9 %61 %62 %38 +%64 = OpCompositeExtract %3 %63 0 +%65 = OpCompositeExtract %3 %63 1 +%66 = OpCompositeExtract %3 %63 2 +OpEmitMeshTasksEXT %64 %65 %66 %14 +OpFunctionEnd +%77 = OpFunction %2 None %36 +%67 = OpLabel +OpBranch %78 +%78 = OpLabel +%81 = OpLoad %3 %80 +%82 = OpIEqual %29 %81 %27 +OpSelectionMerge %83 None +OpBranchConditional %82 %84 %83 +%84 = OpLabel +OpStore %16 %79 +OpBranch %83 +%83 = OpLabel +OpControlBarrier %32 %32 %33 +OpBranch %85 +%85 = OpLabel +OpReturn +OpFunctionEnd +%86 = OpFunction %2 None %36 +%87 = OpLabel +%88 = OpVariable %90 Function +%89 = OpVariable %90 Function +%91 = OpLoad %3 %68 +%92 = OpFunctionCall %2 %77 +OpControlBarrier %32 %32 %33 +%93 = OpAccessChain %94 %16 %32 +%95 = OpLoad %3 %93 +%96 = OpExtInst %3 %1 UMin %95 %11 +%97 = OpAccessChain %94 %16 %98 +%99 = OpLoad %3 %97 +%100 = OpExtInst %3 %1 UMin %99 %11 +%101 = OpAccessChain %102 %16 %27 +%103 = OpAccessChain %104 %16 %11 +OpSetMeshOutputsEXT %96 %100 +OpStore %88 %91 +OpBranch %105 +%105 = OpLabel +OpLoopMerge %107 %116 None +OpBranch %115 +%115 = OpLabel +%118 = OpLoad %3 %88 +%119 = OpULessThan %29 %118 %96 +OpBranchConditional %119 %117 %107 +%117 = OpLabel +%109 = OpLoad %3 %88 +%110 = OpAccessChain %111 %101 %109 %27 +%112 = OpLoad %5 %110 +%113 = OpAccessChain %114 %73 %109 %27 +OpStore %113 %112 +OpBranch %116 +%116 = OpLabel +%120 = OpLoad %3 %88 +%121 = OpIAdd %3 %120 %69 +OpStore %88 %121 +OpBranch %105 +%107 = OpLabel +OpStore %89 %91 +OpBranch %106 +%106 = OpLabel +OpLoopMerge %108 %128 None +OpBranch %127 +%127 = OpLabel +%130 = OpLoad %3 %89 +%131 = OpULessThan %29 %130 %100 +OpBranchConditional %131 %129 %108 +%129 = OpLabel +%122 = OpLoad %3 %89 +%123 = OpAccessChain %94 %103 %122 %27 +%124 = OpLoad %3 %123 +%125 = OpAccessChain %126 %76 %122 +OpStore %125 %124 +OpBranch %128 +%128 = OpLabel +%132 = OpLoad %3 %89 +%133 = OpIAdd %3 %132 %69 +OpStore %89 %133 +OpBranch %106 +%108 = OpLabel OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-mesh-shader.spvasm b/naga/tests/out/spv/wgsl-mesh-shader.spvasm index 4fe27cf36..da0c90bb5 100644 --- a/naga/tests/out/spv/wgsl-mesh-shader.spvasm +++ b/naga/tests/out/spv/wgsl-mesh-shader.spvasm @@ -1,65 +1,66 @@ ; SPIR-V ; Version: 1.4 ; Generator: rspirv -; Bound: 384 +; Bound: 459 OpCapability Shader OpCapability MeshShadingEXT OpExtension "SPV_EXT_mesh_shader" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint TaskEXT %24 "ts_main" %17 %19 %33 -OpEntryPoint TaskEXT %57 "ts_divergent" %54 %17 -OpEntryPoint MeshEXT %95 "ms_main" %17 %72 %81 %85 %88 %91 %94 %19 %21 %107 -OpEntryPoint MeshEXT %214 "ms_no_ts" %192 %200 %204 %207 %210 %213 %19 %21 %217 -OpEntryPoint MeshEXT %301 "ms_divergent" %279 %287 %291 %294 %297 %300 %19 %21 %303 -OpEntryPoint Fragment %379 "fs_main" %370 %373 %376 %378 -OpExecutionMode %24 LocalSize 1 1 1 -OpExecutionMode %57 LocalSize 2 1 1 -OpExecutionMode %95 LocalSize 1 1 1 -OpExecutionMode %95 OutputTrianglesEXT -OpExecutionMode %95 OutputVertices 3 -OpExecutionMode %95 OutputPrimitivesEXT 1 -OpExecutionMode %214 LocalSize 1 1 1 -OpExecutionMode %214 OutputTrianglesEXT -OpExecutionMode %214 OutputVertices 3 -OpExecutionMode %214 OutputPrimitivesEXT 1 -OpExecutionMode %301 LocalSize 1 1 1 -OpExecutionMode %301 OutputTrianglesEXT -OpExecutionMode %301 OutputVertices 3 -OpExecutionMode %301 OutputPrimitivesEXT 1 -OpExecutionMode %379 OriginUpperLeft -OpDecorate %72 BuiltIn LocalInvocationIndex -OpMemberDecorate %78 0 BuiltIn Position -OpDecorate %78 Block -OpMemberDecorate %82 0 BuiltIn CullPrimitiveEXT -OpMemberDecorate %82 0 PerPrimitiveEXT -OpDecorate %82 Block -OpDecorate %85 PerPrimitiveEXT -OpDecorate %88 Location 0 -OpDecorate %91 BuiltIn PrimitiveTriangleIndicesEXT -OpDecorate %94 Location 1 -OpDecorate %94 PerPrimitiveEXT -OpDecorate %192 BuiltIn LocalInvocationIndex -OpMemberDecorate %197 0 BuiltIn Position -OpDecorate %197 Block -OpMemberDecorate %201 0 BuiltIn CullPrimitiveEXT -OpMemberDecorate %201 0 PerPrimitiveEXT -OpDecorate %201 Block -OpDecorate %204 PerPrimitiveEXT -OpDecorate %207 Location 0 -OpDecorate %210 BuiltIn PrimitiveTriangleIndicesEXT -OpDecorate %213 Location 1 -OpDecorate %213 PerPrimitiveEXT -OpMemberDecorate %284 0 BuiltIn Position -OpDecorate %284 Block -OpMemberDecorate %288 0 BuiltIn CullPrimitiveEXT -OpMemberDecorate %288 0 PerPrimitiveEXT -OpDecorate %288 Block -OpDecorate %291 PerPrimitiveEXT -OpDecorate %294 Location 0 -OpDecorate %297 BuiltIn PrimitiveTriangleIndicesEXT -OpDecorate %300 Location 1 -OpDecorate %300 PerPrimitiveEXT +OpEntryPoint TaskEXT %62 "ts_main" %17 %19 %47 +OpEntryPoint TaskEXT %113 "ts_divergent" %95 %17 %101 +OpEntryPoint MeshEXT %208 "ms_main" %17 %142 %146 %150 %153 %156 %159 %19 %21 %172 +OpEntryPoint MeshEXT %300 "ms_no_ts" %262 %266 %270 %273 %276 %279 %19 %21 %283 +OpEntryPoint MeshEXT %394 "ms_divergent" %350 %352 %356 %360 %363 %366 %369 %19 %21 %372 +OpEntryPoint Fragment %454 "fs_main" %445 %448 %451 %453 +OpExecutionMode %62 LocalSize 1 1 1 +OpExecutionMode %113 LocalSize 2 1 1 +OpExecutionMode %208 LocalSize 1 1 1 +OpExecutionMode %208 OutputTrianglesEXT +OpExecutionMode %208 OutputVertices 3 +OpExecutionMode %208 OutputPrimitivesEXT 1 +OpExecutionMode %300 LocalSize 1 1 1 +OpExecutionMode %300 OutputTrianglesEXT +OpExecutionMode %300 OutputVertices 3 +OpExecutionMode %300 OutputPrimitivesEXT 1 +OpExecutionMode %394 LocalSize 2 1 1 +OpExecutionMode %394 OutputTrianglesEXT +OpExecutionMode %394 OutputVertices 3 +OpExecutionMode %394 OutputPrimitivesEXT 1 +OpExecutionMode %454 OriginUpperLeft +OpDecorate %142 BuiltIn LocalInvocationIndex +OpMemberDecorate %143 0 BuiltIn Position +OpDecorate %143 Block +OpMemberDecorate %147 0 BuiltIn CullPrimitiveEXT +OpMemberDecorate %147 0 PerPrimitiveEXT +OpDecorate %147 Block +OpDecorate %150 PerPrimitiveEXT +OpDecorate %153 Location 0 +OpDecorate %156 BuiltIn PrimitiveTriangleIndicesEXT +OpDecorate %159 Location 1 +OpDecorate %159 PerPrimitiveEXT +OpDecorate %262 BuiltIn LocalInvocationIndex +OpMemberDecorate %263 0 BuiltIn Position +OpDecorate %263 Block +OpMemberDecorate %267 0 BuiltIn CullPrimitiveEXT +OpMemberDecorate %267 0 PerPrimitiveEXT +OpDecorate %267 Block +OpDecorate %270 PerPrimitiveEXT +OpDecorate %273 Location 0 +OpDecorate %276 BuiltIn PrimitiveTriangleIndicesEXT +OpDecorate %279 Location 1 +OpDecorate %279 PerPrimitiveEXT +OpDecorate %352 BuiltIn LocalInvocationIndex +OpMemberDecorate %353 0 BuiltIn Position +OpDecorate %353 Block +OpMemberDecorate %357 0 BuiltIn CullPrimitiveEXT +OpMemberDecorate %357 0 PerPrimitiveEXT +OpDecorate %357 Block +OpDecorate %360 PerPrimitiveEXT +OpDecorate %363 Location 0 +OpDecorate %366 BuiltIn PrimitiveTriangleIndicesEXT +OpDecorate %369 Location 1 +OpDecorate %369 PerPrimitiveEXT OpMemberDecorate %6 0 Offset 0 OpMemberDecorate %6 1 Offset 16 OpMemberDecorate %7 0 Offset 0 @@ -74,17 +75,18 @@ OpMemberDecorate %16 0 Offset 0 OpMemberDecorate %16 1 Offset 96 OpMemberDecorate %16 2 Offset 128 OpMemberDecorate %16 3 Offset 132 -OpDecorate %33 BuiltIn LocalInvocationId -OpDecorate %54 BuiltIn LocalInvocationIndex -OpDecorate %107 BuiltIn LocalInvocationId -OpDecorate %217 BuiltIn LocalInvocationId -OpDecorate %279 BuiltIn LocalInvocationIndex -OpDecorate %303 BuiltIn LocalInvocationId -OpDecorate %370 BuiltIn FragCoord -OpDecorate %373 Location 0 -OpDecorate %376 Location 1 -OpDecorate %376 PerPrimitiveEXT -OpDecorate %378 Location 0 +OpDecorate %47 BuiltIn LocalInvocationIndex +OpDecorate %95 BuiltIn LocalInvocationId +OpDecorate %101 BuiltIn LocalInvocationIndex +OpDecorate %172 BuiltIn LocalInvocationIndex +OpDecorate %283 BuiltIn LocalInvocationIndex +OpDecorate %350 BuiltIn LocalInvocationId +OpDecorate %372 BuiltIn LocalInvocationIndex +OpDecorate %445 BuiltIn FragCoord +OpDecorate %448 Location 0 +OpDecorate %451 Location 1 +OpDecorate %451 PerPrimitiveEXT +OpDecorate %453 Location 0 %2 = OpTypeVoid %3 = OpTypeFloat 32 %4 = OpTypeVector %3 4 @@ -106,536 +108,628 @@ OpDecorate %378 Location 0 %19 = OpVariable %20 Workgroup %22 = OpTypePointer Workgroup %16 %21 = OpVariable %22 Workgroup -%25 = OpTypeFunction %2 -%26 = OpConstant %3 1 -%27 = OpConstant %3 0 -%28 = OpConstantComposite %4 %26 %26 %27 %26 -%29 = OpConstantTrue %5 -%30 = OpConstantComposite %9 %15 %15 %15 -%32 = OpConstantNull %3 -%34 = OpTypePointer Input %9 -%33 = OpVariable %34 Input -%36 = OpConstantNull %9 -%37 = OpTypeVector %5 3 -%42 = OpConstant %8 2 -%43 = OpConstant %8 264 -%45 = OpTypePointer TaskPayloadWorkgroupEXT %4 -%46 = OpConstant %8 0 -%48 = OpTypePointer TaskPayloadWorkgroupEXT %5 -%55 = OpTypePointer Input %8 -%54 = OpVariable %55 Input -%58 = OpConstantComposite %9 %42 %42 %42 -%72 = OpVariable %55 Input -%76 = OpTypePointer Function %8 -%78 = OpTypeStruct %4 -%79 = OpTypeArray %78 %13 -%80 = OpTypePointer Output %79 -%81 = OpVariable %80 Output -%82 = OpTypeStruct %5 -%83 = OpTypeArray %82 %15 -%84 = OpTypePointer Output %83 -%85 = OpVariable %84 Output -%86 = OpTypeArray %4 %13 -%87 = OpTypePointer Output %86 -%88 = OpVariable %87 Output -%89 = OpTypeArray %9 %15 -%90 = OpTypePointer Output %89 -%91 = OpVariable %90 Output -%92 = OpTypeArray %4 %15 -%93 = OpTypePointer Output %92 -%94 = OpVariable %93 Output -%96 = OpConstant %3 2 -%97 = OpConstantComposite %4 %27 %26 %27 %26 -%98 = OpConstant %3 -1 -%99 = OpConstantComposite %4 %98 %98 %27 %26 -%100 = OpConstantComposite %4 %27 %27 %26 %26 -%101 = OpConstantComposite %4 %26 %98 %27 %26 -%102 = OpConstantComposite %4 %26 %27 %27 %26 -%103 = OpConstantComposite %9 %46 %15 %42 -%104 = OpConstantComposite %4 %26 %27 %26 %26 -%106 = OpConstantNull %16 -%107 = OpVariable %34 Input -%114 = OpTypePointer Workgroup %8 -%117 = OpTypePointer Workgroup %12 -%118 = OpTypePointer Workgroup %7 -%119 = OpTypePointer Workgroup %4 -%135 = OpTypePointer Workgroup %14 -%136 = OpTypePointer Workgroup %10 -%137 = OpTypePointer Workgroup %9 -%139 = OpTypePointer Workgroup %5 -%161 = OpTypePointer Output %4 -%176 = OpTypePointer Output %9 -%180 = OpTypePointer Output %5 -%192 = OpVariable %55 Input -%197 = OpTypeStruct %4 -%198 = OpTypeArray %197 %13 -%199 = OpTypePointer Output %198 -%200 = OpVariable %199 Output -%201 = OpTypeStruct %5 -%202 = OpTypeArray %201 %15 -%203 = OpTypePointer Output %202 -%204 = OpVariable %203 Output -%205 = OpTypeArray %4 %13 -%206 = OpTypePointer Output %205 -%207 = OpVariable %206 Output -%208 = OpTypeArray %9 %15 -%209 = OpTypePointer Output %208 -%210 = OpVariable %209 Output -%211 = OpTypeArray %4 %15 -%212 = OpTypePointer Output %211 -%213 = OpVariable %212 Output -%215 = OpConstantFalse %5 -%217 = OpVariable %34 Input -%279 = OpVariable %55 Input -%284 = OpTypeStruct %4 -%285 = OpTypeArray %284 %13 -%286 = OpTypePointer Output %285 -%287 = OpVariable %286 Output -%288 = OpTypeStruct %5 -%289 = OpTypeArray %288 %15 -%290 = OpTypePointer Output %289 -%291 = OpVariable %290 Output -%292 = OpTypeArray %4 %13 -%293 = OpTypePointer Output %292 -%294 = OpVariable %293 Output -%295 = OpTypeArray %9 %15 -%296 = OpTypePointer Output %295 -%297 = OpVariable %296 Output -%298 = OpTypeArray %4 %15 -%299 = OpTypePointer Output %298 -%300 = OpVariable %299 Output -%303 = OpVariable %34 Input -%371 = OpTypePointer Input %4 -%370 = OpVariable %371 Input -%373 = OpVariable %371 Input -%376 = OpVariable %371 Input -%378 = OpVariable %161 Output -%24 = OpFunction %2 None %25 +%25 = OpTypeFunction %5 +%27 = OpTypePointer TaskPayloadWorkgroupEXT %5 +%33 = OpTypeFunction %2 %5 +%38 = OpTypeFunction %9 +%39 = OpConstant %3 1 +%40 = OpConstant %3 0 +%41 = OpConstantComposite %4 %39 %39 %40 %39 +%42 = OpConstantTrue %5 +%43 = OpConstantComposite %9 %15 %15 %15 +%45 = OpConstantNull %6 +%46 = OpConstantNull %3 +%48 = OpTypePointer Input %8 +%47 = OpVariable %48 Input +%50 = OpConstant %8 0 +%54 = OpConstant %8 2 +%55 = OpConstant %8 264 +%57 = OpTypePointer TaskPayloadWorkgroupEXT %4 +%63 = OpTypeFunction %2 +%66 = OpConstant %8 256 +%67 = OpConstant %8 1024 +%68 = OpTypeStruct %8 %8 +%96 = OpTypePointer Input %9 +%95 = OpVariable %96 Input +%99 = OpConstantComposite %9 %54 %54 %54 +%101 = OpVariable %48 Input +%142 = OpVariable %48 Input +%143 = OpTypeStruct %4 +%144 = OpTypeArray %143 %13 +%145 = OpTypePointer Output %144 +%146 = OpVariable %145 Output +%147 = OpTypeStruct %5 +%148 = OpTypeArray %147 %15 +%149 = OpTypePointer Output %148 +%150 = OpVariable %149 Output +%151 = OpTypeArray %4 %13 +%152 = OpTypePointer Output %151 +%153 = OpVariable %152 Output +%154 = OpTypeArray %9 %15 +%155 = OpTypePointer Output %154 +%156 = OpVariable %155 Output +%157 = OpTypeArray %4 %15 +%158 = OpTypePointer Output %157 +%159 = OpVariable %158 Output +%161 = OpConstant %3 2 +%162 = OpConstantComposite %4 %40 %39 %40 %39 +%163 = OpConstant %3 -1 +%164 = OpConstantComposite %4 %163 %163 %40 %39 +%165 = OpConstantComposite %4 %40 %40 %39 %39 +%166 = OpConstantComposite %4 %39 %163 %40 %39 +%167 = OpConstantComposite %4 %39 %40 %40 %39 +%168 = OpConstantComposite %9 %50 %15 %54 +%169 = OpConstantComposite %4 %39 %40 %39 %39 +%171 = OpConstantNull %16 +%172 = OpVariable %48 Input +%178 = OpTypePointer Workgroup %8 +%181 = OpTypePointer Workgroup %12 +%182 = OpTypePointer Workgroup %7 +%183 = OpTypePointer Workgroup %4 +%199 = OpTypePointer Workgroup %14 +%200 = OpTypePointer Workgroup %10 +%201 = OpTypePointer Workgroup %9 +%203 = OpTypePointer Workgroup %5 +%212 = OpTypePointer Function %8 +%231 = OpTypePointer Output %4 +%246 = OpTypePointer Output %9 +%250 = OpTypePointer Output %5 +%262 = OpVariable %48 Input +%263 = OpTypeStruct %4 +%264 = OpTypeArray %263 %13 +%265 = OpTypePointer Output %264 +%266 = OpVariable %265 Output +%267 = OpTypeStruct %5 +%268 = OpTypeArray %267 %15 +%269 = OpTypePointer Output %268 +%270 = OpVariable %269 Output +%271 = OpTypeArray %4 %13 +%272 = OpTypePointer Output %271 +%273 = OpVariable %272 Output +%274 = OpTypeArray %9 %15 +%275 = OpTypePointer Output %274 +%276 = OpVariable %275 Output +%277 = OpTypeArray %4 %15 +%278 = OpTypePointer Output %277 +%279 = OpVariable %278 Output +%281 = OpConstantFalse %5 +%283 = OpVariable %48 Input +%350 = OpVariable %96 Input +%352 = OpVariable %48 Input +%353 = OpTypeStruct %4 +%354 = OpTypeArray %353 %13 +%355 = OpTypePointer Output %354 +%356 = OpVariable %355 Output +%357 = OpTypeStruct %5 +%358 = OpTypeArray %357 %15 +%359 = OpTypePointer Output %358 +%360 = OpVariable %359 Output +%361 = OpTypeArray %4 %13 +%362 = OpTypePointer Output %361 +%363 = OpVariable %362 Output +%364 = OpTypeArray %9 %15 +%365 = OpTypePointer Output %364 +%366 = OpVariable %365 Output +%367 = OpTypeArray %4 %15 +%368 = OpTypePointer Output %367 +%369 = OpVariable %368 Output +%372 = OpVariable %48 Input +%446 = OpTypePointer Input %4 +%445 = OpVariable %446 Input +%448 = OpVariable %446 Input +%451 = OpVariable %446 Input +%453 = OpVariable %231 Output +%24 = OpFunction %5 None %25 %23 = OpLabel -OpBranch %31 -%31 = OpLabel -%35 = OpLoad %9 %33 -%38 = OpIEqual %37 %35 %36 -%39 = OpAll %5 %38 -OpSelectionMerge %40 None -OpBranchConditional %39 %41 %40 -%41 = OpLabel -OpStore %19 %32 -OpBranch %40 -%40 = OpLabel -OpControlBarrier %42 %42 %43 -OpBranch %44 -%44 = OpLabel -OpStore %19 %26 -%47 = OpAccessChain %45 %17 %46 -OpStore %47 %28 -%49 = OpAccessChain %48 %17 %15 -OpStore %49 %29 -OpControlBarrier %42 %42 %43 -%50 = OpCompositeExtract %8 %30 0 -%51 = OpCompositeExtract %8 %30 1 -%52 = OpCompositeExtract %8 %30 2 -OpEmitMeshTasksEXT %50 %51 %52 %17 +OpBranch %26 +%26 = OpLabel +%28 = OpAccessChain %27 %17 %15 +%29 = OpLoad %5 %28 +OpReturnValue %29 OpFunctionEnd -%57 = OpFunction %2 None %25 -%53 = OpLabel -%56 = OpLoad %8 %54 -OpBranch %59 -%59 = OpLabel -%60 = OpIEqual %5 %56 %46 -OpSelectionMerge %61 None -OpBranchConditional %60 %62 %61 -%62 = OpLabel -%63 = OpAccessChain %45 %17 %46 -OpStore %63 %28 -%64 = OpAccessChain %48 %17 %15 -OpStore %64 %29 -OpControlBarrier %42 %42 %43 -%65 = OpCompositeExtract %8 %30 0 -%66 = OpCompositeExtract %8 %30 1 -%67 = OpCompositeExtract %8 %30 2 -OpEmitMeshTasksEXT %65 %66 %67 %17 -%61 = OpLabel -OpControlBarrier %42 %42 %43 -%68 = OpCompositeExtract %8 %58 0 -%69 = OpCompositeExtract %8 %58 1 -%70 = OpCompositeExtract %8 %58 2 -OpEmitMeshTasksEXT %68 %69 %70 %17 -OpFunctionEnd -%95 = OpFunction %2 None %25 -%71 = OpLabel -%74 = OpVariable %76 Function -%75 = OpVariable %76 Function -%73 = OpLoad %8 %72 -OpBranch %105 -%105 = OpLabel -%108 = OpLoad %9 %107 -%109 = OpIEqual %37 %108 %36 -%110 = OpAll %5 %109 -OpSelectionMerge %111 None -OpBranchConditional %110 %112 %111 -%112 = OpLabel -OpStore %19 %32 -OpStore %21 %106 -OpBranch %111 -%111 = OpLabel -OpControlBarrier %42 %42 %43 -OpBranch %113 -%113 = OpLabel -%115 = OpAccessChain %114 %21 %42 -OpStore %115 %13 -%116 = OpAccessChain %114 %21 %13 -OpStore %116 %15 -OpStore %19 %96 -%120 = OpAccessChain %119 %21 %46 %46 %46 -OpStore %120 %97 -%121 = OpAccessChain %45 %17 %46 -%122 = OpLoad %4 %121 -%123 = OpFMul %4 %97 %122 -%124 = OpAccessChain %119 %21 %46 %46 %15 -OpStore %124 %123 -%125 = OpAccessChain %119 %21 %46 %15 %46 -OpStore %125 %99 -%126 = OpAccessChain %45 %17 %46 -%127 = OpLoad %4 %126 -%128 = OpFMul %4 %100 %127 -%129 = OpAccessChain %119 %21 %46 %15 %15 -OpStore %129 %128 -%130 = OpAccessChain %119 %21 %46 %42 %46 -OpStore %130 %101 -%131 = OpAccessChain %45 %17 %46 -%132 = OpLoad %4 %131 -%133 = OpFMul %4 %102 %132 -%134 = OpAccessChain %119 %21 %46 %42 %15 -OpStore %134 %133 -%138 = OpAccessChain %137 %21 %15 %46 %46 -OpStore %138 %103 -%140 = OpAccessChain %48 %17 %15 -%141 = OpLoad %5 %140 -%142 = OpLogicalNot %5 %141 -%143 = OpAccessChain %139 %21 %15 %46 %15 -OpStore %143 %142 -%144 = OpAccessChain %119 %21 %15 %46 %42 -OpStore %144 %104 -OpBranch %77 -%77 = OpLabel -OpControlBarrier %42 %42 %43 -%145 = OpAccessChain %114 %21 %42 -%146 = OpLoad %8 %145 -%147 = OpExtInst %8 %1 UMin %146 %13 -%148 = OpAccessChain %114 %21 %13 -%149 = OpLoad %8 %148 -%150 = OpExtInst %8 %1 UMin %149 %15 -%151 = OpAccessChain %117 %21 %46 -%152 = OpAccessChain %135 %21 %15 -OpControlBarrier %42 %42 %43 -OpSetMeshOutputsEXT %147 %150 -OpStore %74 %73 -OpBranch %153 -%153 = OpLabel -OpLoopMerge %155 %166 None -OpBranch %165 -%165 = OpLabel -%168 = OpLoad %8 %74 -%169 = OpULessThan %5 %168 %147 -OpBranchConditional %169 %167 %155 -%167 = OpLabel -%157 = OpLoad %8 %74 -%158 = OpAccessChain %119 %151 %157 %46 -%159 = OpLoad %4 %158 -%160 = OpAccessChain %161 %81 %157 %46 -OpStore %160 %159 -%162 = OpAccessChain %119 %151 %157 %15 -%163 = OpLoad %4 %162 -%164 = OpAccessChain %161 %88 %157 -OpStore %164 %163 -OpBranch %166 -%166 = OpLabel -%170 = OpLoad %8 %74 -%171 = OpIAdd %8 %170 %15 -OpStore %74 %171 -OpBranch %153 -%155 = OpLabel -OpStore %75 %73 -OpBranch %154 -%154 = OpLabel -OpLoopMerge %156 %185 None -OpBranch %184 -%184 = OpLabel -%187 = OpLoad %8 %75 -%188 = OpULessThan %5 %187 %150 -OpBranchConditional %188 %186 %156 -%186 = OpLabel -%172 = OpLoad %8 %75 -%173 = OpAccessChain %137 %152 %172 %46 -%174 = OpLoad %9 %173 -%175 = OpAccessChain %176 %91 %172 -OpStore %175 %174 -%177 = OpAccessChain %139 %152 %172 %15 -%178 = OpLoad %5 %177 -%179 = OpAccessChain %180 %85 %172 %46 -OpStore %179 %178 -%181 = OpAccessChain %119 %152 %172 %42 -%182 = OpLoad %4 %181 -%183 = OpAccessChain %161 %94 %172 -OpStore %183 %182 -OpBranch %185 -%185 = OpLabel -%189 = OpLoad %8 %75 -%190 = OpIAdd %8 %189 %15 -OpStore %75 %190 -OpBranch %154 -%156 = OpLabel +%32 = OpFunction %2 None %33 +%31 = OpFunctionParameter %5 +%30 = OpLabel +OpBranch %34 +%34 = OpLabel +%35 = OpAccessChain %27 %17 %15 +OpStore %35 %31 OpReturn OpFunctionEnd -%214 = OpFunction %2 None %25 -%191 = OpLabel -%194 = OpVariable %76 Function -%195 = OpVariable %76 Function -%193 = OpLoad %8 %192 -OpBranch %216 -%216 = OpLabel -%218 = OpLoad %9 %217 -%219 = OpIEqual %37 %218 %36 -%220 = OpAll %5 %219 -OpSelectionMerge %221 None -OpBranchConditional %220 %222 %221 -%222 = OpLabel -OpStore %19 %32 -OpStore %21 %106 -OpBranch %221 -%221 = OpLabel -OpControlBarrier %42 %42 %43 +%37 = OpFunction %9 None %38 +%36 = OpLabel +OpBranch %44 +%44 = OpLabel +%49 = OpLoad %8 %47 +%51 = OpIEqual %5 %49 %50 +OpSelectionMerge %52 None +OpBranchConditional %51 %53 %52 +%53 = OpLabel +OpStore %17 %45 +OpStore %19 %46 +OpBranch %52 +%52 = OpLabel +OpControlBarrier %54 %54 %55 +OpBranch %56 +%56 = OpLabel +OpStore %19 %39 +%58 = OpAccessChain %57 %17 %50 +OpStore %58 %41 +%59 = OpFunctionCall %2 %32 %42 +%60 = OpFunctionCall %5 %24 +%61 = OpAccessChain %27 %17 %15 +OpStore %61 %60 +OpReturnValue %43 +OpFunctionEnd +%62 = OpFunction %2 None %63 +%64 = OpLabel +%65 = OpFunctionCall %9 %37 +OpControlBarrier %54 %54 %55 +%69 = OpCompositeExtract %8 %65 0 +%70 = OpCompositeExtract %8 %65 1 +%71 = OpCompositeExtract %8 %65 2 +%75 = OpUMulExtended %68 %69 %70 +%72 = OpCompositeExtract %8 %75 0 +%73 = OpCompositeExtract %8 %75 1 +%77 = OpUMulExtended %68 %72 %71 +%76 = OpCompositeExtract %8 %77 0 +%74 = OpCompositeExtract %8 %77 1 +%78 = OpUGreaterThan %5 %76 %67 +%79 = OpUGreaterThan %5 %69 %66 +%80 = OpUGreaterThan %5 %70 %66 +%81 = OpUGreaterThan %5 %71 %66 +%82 = OpINotEqual %5 %73 %50 +%83 = OpINotEqual %5 %74 %50 +%84 = OpLogicalOr %5 %78 %79 +%85 = OpLogicalOr %5 %84 %80 +%86 = OpLogicalOr %5 %85 %81 +%87 = OpLogicalOr %5 %86 %82 +%88 = OpLogicalOr %5 %87 %83 +%89 = OpCompositeConstruct %9 %50 %50 %50 +%90 = OpSelect %9 %88 %89 %65 +%91 = OpCompositeExtract %8 %90 0 +%92 = OpCompositeExtract %8 %90 1 +%93 = OpCompositeExtract %8 %90 2 +OpEmitMeshTasksEXT %91 %92 %93 %17 +OpFunctionEnd +%98 = OpFunction %9 None %38 +%94 = OpLabel +%97 = OpLoad %9 %95 +OpBranch %100 +%100 = OpLabel +%102 = OpLoad %8 %101 +%103 = OpIEqual %5 %102 %50 +OpSelectionMerge %104 None +OpBranchConditional %103 %105 %104 +%105 = OpLabel +OpStore %17 %45 +OpBranch %104 +%104 = OpLabel +OpControlBarrier %54 %54 %55 +OpBranch %106 +%106 = OpLabel +%107 = OpCompositeExtract %8 %97 0 +%108 = OpIEqual %5 %107 %50 +OpSelectionMerge %109 None +OpBranchConditional %108 %110 %109 +%110 = OpLabel +%111 = OpAccessChain %57 %17 %50 +OpStore %111 %41 +%112 = OpAccessChain %27 %17 %15 +OpStore %112 %42 +OpReturnValue %43 +%109 = OpLabel +OpReturnValue %99 +OpFunctionEnd +%113 = OpFunction %2 None %63 +%114 = OpLabel +%115 = OpFunctionCall %9 %98 +OpControlBarrier %54 %54 %55 +%116 = OpCompositeExtract %8 %115 0 +%117 = OpCompositeExtract %8 %115 1 +%118 = OpCompositeExtract %8 %115 2 +%122 = OpUMulExtended %68 %116 %117 +%119 = OpCompositeExtract %8 %122 0 +%120 = OpCompositeExtract %8 %122 1 +%124 = OpUMulExtended %68 %119 %118 +%123 = OpCompositeExtract %8 %124 0 +%121 = OpCompositeExtract %8 %124 1 +%125 = OpUGreaterThan %5 %123 %67 +%126 = OpUGreaterThan %5 %116 %66 +%127 = OpUGreaterThan %5 %117 %66 +%128 = OpUGreaterThan %5 %118 %66 +%129 = OpINotEqual %5 %120 %50 +%130 = OpINotEqual %5 %121 %50 +%131 = OpLogicalOr %5 %125 %126 +%132 = OpLogicalOr %5 %131 %127 +%133 = OpLogicalOr %5 %132 %128 +%134 = OpLogicalOr %5 %133 %129 +%135 = OpLogicalOr %5 %134 %130 +%136 = OpCompositeConstruct %9 %50 %50 %50 +%137 = OpSelect %9 %135 %136 %115 +%138 = OpCompositeExtract %8 %137 0 +%139 = OpCompositeExtract %8 %137 1 +%140 = OpCompositeExtract %8 %137 2 +OpEmitMeshTasksEXT %138 %139 %140 %17 +OpFunctionEnd +%160 = OpFunction %2 None %63 +%141 = OpLabel +OpBranch %170 +%170 = OpLabel +%173 = OpLoad %8 %172 +%174 = OpIEqual %5 %173 %50 +OpSelectionMerge %175 None +OpBranchConditional %174 %176 %175 +%176 = OpLabel +OpStore %19 %46 +OpStore %21 %171 +OpBranch %175 +%175 = OpLabel +OpControlBarrier %54 %54 %55 +OpBranch %177 +%177 = OpLabel +%179 = OpAccessChain %178 %21 %54 +OpStore %179 %13 +%180 = OpAccessChain %178 %21 %13 +OpStore %180 %15 +OpStore %19 %161 +%184 = OpAccessChain %183 %21 %50 %50 %50 +OpStore %184 %162 +%185 = OpAccessChain %57 %17 %50 +%186 = OpLoad %4 %185 +%187 = OpFMul %4 %162 %186 +%188 = OpAccessChain %183 %21 %50 %50 %15 +OpStore %188 %187 +%189 = OpAccessChain %183 %21 %50 %15 %50 +OpStore %189 %164 +%190 = OpAccessChain %57 %17 %50 +%191 = OpLoad %4 %190 +%192 = OpFMul %4 %165 %191 +%193 = OpAccessChain %183 %21 %50 %15 %15 +OpStore %193 %192 +%194 = OpAccessChain %183 %21 %50 %54 %50 +OpStore %194 %166 +%195 = OpAccessChain %57 %17 %50 +%196 = OpLoad %4 %195 +%197 = OpFMul %4 %167 %196 +%198 = OpAccessChain %183 %21 %50 %54 %15 +OpStore %198 %197 +%202 = OpAccessChain %201 %21 %15 %50 %50 +OpStore %202 %168 +%204 = OpFunctionCall %5 %24 +%205 = OpLogicalNot %5 %204 +%206 = OpAccessChain %203 %21 %15 %50 %15 +OpStore %206 %205 +%207 = OpAccessChain %183 %21 %15 %50 %54 +OpStore %207 %169 +OpReturn +OpFunctionEnd +%208 = OpFunction %2 None %63 +%209 = OpLabel +%210 = OpVariable %212 Function +%211 = OpVariable %212 Function +%213 = OpLoad %8 %142 +%214 = OpFunctionCall %2 %160 +OpControlBarrier %54 %54 %55 +%215 = OpAccessChain %178 %21 %54 +%216 = OpLoad %8 %215 +%217 = OpExtInst %8 %1 UMin %216 %13 +%218 = OpAccessChain %178 %21 %13 +%219 = OpLoad %8 %218 +%220 = OpExtInst %8 %1 UMin %219 %15 +%221 = OpAccessChain %181 %21 %50 +%222 = OpAccessChain %199 %21 %15 +OpSetMeshOutputsEXT %217 %220 +OpStore %210 %213 OpBranch %223 %223 = OpLabel -%224 = OpAccessChain %114 %21 %42 -OpStore %224 %13 -%225 = OpAccessChain %114 %21 %13 -OpStore %225 %15 -OpStore %19 %96 -%226 = OpAccessChain %119 %21 %46 %46 %46 -OpStore %226 %97 -%227 = OpAccessChain %119 %21 %46 %46 %15 -OpStore %227 %97 -%228 = OpAccessChain %119 %21 %46 %15 %46 -OpStore %228 %99 -%229 = OpAccessChain %119 %21 %46 %15 %15 -OpStore %229 %100 -%230 = OpAccessChain %119 %21 %46 %42 %46 -OpStore %230 %101 -%231 = OpAccessChain %119 %21 %46 %42 %15 -OpStore %231 %102 -%232 = OpAccessChain %137 %21 %15 %46 %46 -OpStore %232 %103 -%233 = OpAccessChain %139 %21 %15 %46 %15 -OpStore %233 %215 -%234 = OpAccessChain %119 %21 %15 %46 %42 -OpStore %234 %104 -OpBranch %196 -%196 = OpLabel -OpControlBarrier %42 %42 %43 -%235 = OpAccessChain %114 %21 %42 -%236 = OpLoad %8 %235 -%237 = OpExtInst %8 %1 UMin %236 %13 -%238 = OpAccessChain %114 %21 %13 -%239 = OpLoad %8 %238 -%240 = OpExtInst %8 %1 UMin %239 %15 -%241 = OpAccessChain %117 %21 %46 -%242 = OpAccessChain %135 %21 %15 -OpControlBarrier %42 %42 %43 -OpSetMeshOutputsEXT %237 %240 -OpStore %194 %193 -OpBranch %243 -%243 = OpLabel -OpLoopMerge %245 %255 None +OpLoopMerge %225 %236 None +OpBranch %235 +%235 = OpLabel +%238 = OpLoad %8 %210 +%239 = OpULessThan %5 %238 %217 +OpBranchConditional %239 %237 %225 +%237 = OpLabel +%227 = OpLoad %8 %210 +%228 = OpAccessChain %183 %221 %227 %50 +%229 = OpLoad %4 %228 +%230 = OpAccessChain %231 %146 %227 %50 +OpStore %230 %229 +%232 = OpAccessChain %183 %221 %227 %15 +%233 = OpLoad %4 %232 +%234 = OpAccessChain %231 %153 %227 +OpStore %234 %233 +OpBranch %236 +%236 = OpLabel +%240 = OpLoad %8 %210 +%241 = OpIAdd %8 %240 %15 +OpStore %210 %241 +OpBranch %223 +%225 = OpLabel +OpStore %211 %213 +OpBranch %224 +%224 = OpLabel +OpLoopMerge %226 %255 None OpBranch %254 %254 = OpLabel -%257 = OpLoad %8 %194 -%258 = OpULessThan %5 %257 %237 -OpBranchConditional %258 %256 %245 +%257 = OpLoad %8 %211 +%258 = OpULessThan %5 %257 %220 +OpBranchConditional %258 %256 %226 %256 = OpLabel -%247 = OpLoad %8 %194 -%248 = OpAccessChain %119 %241 %247 %46 -%249 = OpLoad %4 %248 -%250 = OpAccessChain %161 %200 %247 %46 -OpStore %250 %249 -%251 = OpAccessChain %119 %241 %247 %15 +%242 = OpLoad %8 %211 +%243 = OpAccessChain %201 %222 %242 %50 +%244 = OpLoad %9 %243 +%245 = OpAccessChain %246 %156 %242 +OpStore %245 %244 +%247 = OpAccessChain %203 %222 %242 %15 +%248 = OpLoad %5 %247 +%249 = OpAccessChain %250 %150 %242 %50 +OpStore %249 %248 +%251 = OpAccessChain %183 %222 %242 %54 %252 = OpLoad %4 %251 -%253 = OpAccessChain %161 %207 %247 +%253 = OpAccessChain %231 %159 %242 OpStore %253 %252 OpBranch %255 %255 = OpLabel -%259 = OpLoad %8 %194 +%259 = OpLoad %8 %211 %260 = OpIAdd %8 %259 %15 -OpStore %194 %260 -OpBranch %243 -%245 = OpLabel -OpStore %195 %193 -OpBranch %244 -%244 = OpLabel -OpLoopMerge %246 %272 None -OpBranch %271 -%271 = OpLabel -%274 = OpLoad %8 %195 -%275 = OpULessThan %5 %274 %240 -OpBranchConditional %275 %273 %246 -%273 = OpLabel -%261 = OpLoad %8 %195 -%262 = OpAccessChain %137 %242 %261 %46 -%263 = OpLoad %9 %262 -%264 = OpAccessChain %176 %210 %261 -OpStore %264 %263 -%265 = OpAccessChain %139 %242 %261 %15 -%266 = OpLoad %5 %265 -%267 = OpAccessChain %180 %204 %261 %46 -OpStore %267 %266 -%268 = OpAccessChain %119 %242 %261 %42 -%269 = OpLoad %4 %268 -%270 = OpAccessChain %161 %213 %261 -OpStore %270 %269 -OpBranch %272 -%272 = OpLabel -%276 = OpLoad %8 %195 -%277 = OpIAdd %8 %276 %15 -OpStore %195 %277 -OpBranch %244 -%246 = OpLabel +OpStore %211 %260 +OpBranch %224 +%226 = OpLabel OpReturn OpFunctionEnd -%301 = OpFunction %2 None %25 -%278 = OpLabel -%281 = OpVariable %76 Function -%282 = OpVariable %76 Function -%280 = OpLoad %8 %279 -OpBranch %302 -%302 = OpLabel -%304 = OpLoad %9 %303 -%305 = OpIEqual %37 %304 %36 -%306 = OpAll %5 %305 -OpSelectionMerge %307 None -OpBranchConditional %306 %308 %307 -%308 = OpLabel -OpStore %19 %32 -OpStore %21 %106 -OpBranch %307 -%307 = OpLabel -OpControlBarrier %42 %42 %43 -OpBranch %309 -%309 = OpLabel -%310 = OpIEqual %5 %280 %46 -OpSelectionMerge %311 None -OpBranchConditional %310 %312 %313 -%312 = OpLabel -%314 = OpAccessChain %114 %21 %42 -OpStore %314 %13 -%315 = OpAccessChain %114 %21 %13 -OpStore %315 %15 -OpStore %19 %96 -%316 = OpAccessChain %119 %21 %46 %46 %46 -OpStore %316 %97 -%317 = OpAccessChain %119 %21 %46 %46 %15 -OpStore %317 %97 -%318 = OpAccessChain %119 %21 %46 %15 %46 -OpStore %318 %99 -%319 = OpAccessChain %119 %21 %46 %15 %15 -OpStore %319 %100 -%320 = OpAccessChain %119 %21 %46 %42 %46 -OpStore %320 %101 -%321 = OpAccessChain %119 %21 %46 %42 %15 -OpStore %321 %102 -%322 = OpAccessChain %137 %21 %15 %46 %46 -OpStore %322 %103 -%323 = OpAccessChain %139 %21 %15 %46 %15 -OpStore %323 %215 -%324 = OpAccessChain %119 %21 %15 %46 %42 -OpStore %324 %104 -OpBranch %283 -%313 = OpLabel -OpBranch %283 -%311 = OpLabel +%280 = OpFunction %2 None %63 +%261 = OpLabel +OpBranch %282 +%282 = OpLabel +%284 = OpLoad %8 %283 +%285 = OpIEqual %5 %284 %50 +OpSelectionMerge %286 None +OpBranchConditional %285 %287 %286 +%287 = OpLabel +OpStore %19 %46 +OpStore %21 %171 +OpBranch %286 +%286 = OpLabel +OpControlBarrier %54 %54 %55 +OpBranch %288 +%288 = OpLabel +%289 = OpAccessChain %178 %21 %54 +OpStore %289 %13 +%290 = OpAccessChain %178 %21 %13 +OpStore %290 %15 +OpStore %19 %161 +%291 = OpAccessChain %183 %21 %50 %50 %50 +OpStore %291 %162 +%292 = OpAccessChain %183 %21 %50 %50 %15 +OpStore %292 %162 +%293 = OpAccessChain %183 %21 %50 %15 %50 +OpStore %293 %164 +%294 = OpAccessChain %183 %21 %50 %15 %15 +OpStore %294 %165 +%295 = OpAccessChain %183 %21 %50 %54 %50 +OpStore %295 %166 +%296 = OpAccessChain %183 %21 %50 %54 %15 +OpStore %296 %167 +%297 = OpAccessChain %201 %21 %15 %50 %50 +OpStore %297 %168 +%298 = OpAccessChain %203 %21 %15 %50 %15 +OpStore %298 %281 +%299 = OpAccessChain %183 %21 %15 %50 %54 +OpStore %299 %169 OpReturn -%283 = OpLabel -OpControlBarrier %42 %42 %43 -%325 = OpAccessChain %114 %21 %42 -%326 = OpLoad %8 %325 -%327 = OpExtInst %8 %1 UMin %326 %13 -%328 = OpAccessChain %114 %21 %13 -%329 = OpLoad %8 %328 -%330 = OpExtInst %8 %1 UMin %329 %15 -%331 = OpAccessChain %117 %21 %46 -%332 = OpAccessChain %135 %21 %15 -OpControlBarrier %42 %42 %43 -OpSetMeshOutputsEXT %327 %330 -OpStore %281 %280 -OpBranch %333 -%333 = OpLabel -OpLoopMerge %335 %345 None -OpBranch %344 +OpFunctionEnd +%300 = OpFunction %2 None %63 +%301 = OpLabel +%302 = OpVariable %212 Function +%303 = OpVariable %212 Function +%304 = OpLoad %8 %262 +%305 = OpFunctionCall %2 %280 +OpControlBarrier %54 %54 %55 +%306 = OpAccessChain %178 %21 %54 +%307 = OpLoad %8 %306 +%308 = OpExtInst %8 %1 UMin %307 %13 +%309 = OpAccessChain %178 %21 %13 +%310 = OpLoad %8 %309 +%311 = OpExtInst %8 %1 UMin %310 %15 +%312 = OpAccessChain %181 %21 %50 +%313 = OpAccessChain %199 %21 %15 +OpSetMeshOutputsEXT %308 %311 +OpStore %302 %304 +OpBranch %314 +%314 = OpLabel +OpLoopMerge %316 %326 None +OpBranch %325 +%325 = OpLabel +%328 = OpLoad %8 %302 +%329 = OpULessThan %5 %328 %308 +OpBranchConditional %329 %327 %316 +%327 = OpLabel +%318 = OpLoad %8 %302 +%319 = OpAccessChain %183 %312 %318 %50 +%320 = OpLoad %4 %319 +%321 = OpAccessChain %231 %266 %318 %50 +OpStore %321 %320 +%322 = OpAccessChain %183 %312 %318 %15 +%323 = OpLoad %4 %322 +%324 = OpAccessChain %231 %273 %318 +OpStore %324 %323 +OpBranch %326 +%326 = OpLabel +%330 = OpLoad %8 %302 +%331 = OpIAdd %8 %330 %15 +OpStore %302 %331 +OpBranch %314 +%316 = OpLabel +OpStore %303 %304 +OpBranch %315 +%315 = OpLabel +OpLoopMerge %317 %343 None +OpBranch %342 +%342 = OpLabel +%345 = OpLoad %8 %303 +%346 = OpULessThan %5 %345 %311 +OpBranchConditional %346 %344 %317 %344 = OpLabel -%347 = OpLoad %8 %281 -%348 = OpULessThan %5 %347 %327 -OpBranchConditional %348 %346 %335 -%346 = OpLabel -%337 = OpLoad %8 %281 -%338 = OpAccessChain %119 %331 %337 %46 -%339 = OpLoad %4 %338 -%340 = OpAccessChain %161 %287 %337 %46 -OpStore %340 %339 -%341 = OpAccessChain %119 %331 %337 %15 -%342 = OpLoad %4 %341 -%343 = OpAccessChain %161 %294 %337 -OpStore %343 %342 -OpBranch %345 -%345 = OpLabel -%349 = OpLoad %8 %281 -%350 = OpIAdd %8 %349 %15 -OpStore %281 %350 -OpBranch %333 -%335 = OpLabel -OpStore %282 %280 -OpBranch %334 -%334 = OpLabel -OpLoopMerge %336 %362 None -OpBranch %361 -%361 = OpLabel -%364 = OpLoad %8 %282 -%365 = OpULessThan %5 %364 %330 -OpBranchConditional %365 %363 %336 -%363 = OpLabel -%351 = OpLoad %8 %282 -%352 = OpAccessChain %137 %332 %351 %46 -%353 = OpLoad %9 %352 -%354 = OpAccessChain %176 %297 %351 -OpStore %354 %353 -%355 = OpAccessChain %139 %332 %351 %15 -%356 = OpLoad %5 %355 -%357 = OpAccessChain %180 %291 %351 %46 -OpStore %357 %356 -%358 = OpAccessChain %119 %332 %351 %42 -%359 = OpLoad %4 %358 -%360 = OpAccessChain %161 %300 %351 -OpStore %360 %359 -OpBranch %362 -%362 = OpLabel -%366 = OpLoad %8 %282 -%367 = OpIAdd %8 %366 %15 -OpStore %282 %367 -OpBranch %334 -%336 = OpLabel +%332 = OpLoad %8 %303 +%333 = OpAccessChain %201 %313 %332 %50 +%334 = OpLoad %9 %333 +%335 = OpAccessChain %246 %276 %332 +OpStore %335 %334 +%336 = OpAccessChain %203 %313 %332 %15 +%337 = OpLoad %5 %336 +%338 = OpAccessChain %250 %270 %332 %50 +OpStore %338 %337 +%339 = OpAccessChain %183 %313 %332 %54 +%340 = OpLoad %4 %339 +%341 = OpAccessChain %231 %279 %332 +OpStore %341 %340 +OpBranch %343 +%343 = OpLabel +%347 = OpLoad %8 %303 +%348 = OpIAdd %8 %347 %15 +OpStore %303 %348 +OpBranch %315 +%317 = OpLabel OpReturn OpFunctionEnd -%379 = OpFunction %2 None %25 -%368 = OpLabel -%372 = OpLoad %4 %370 -%374 = OpLoad %4 %373 -%369 = OpCompositeConstruct %7 %372 %374 -%377 = OpLoad %4 %376 -%375 = OpCompositeConstruct %11 %377 -OpBranch %380 +%370 = OpFunction %2 None %63 +%349 = OpLabel +%351 = OpLoad %9 %350 +OpBranch %371 +%371 = OpLabel +%373 = OpLoad %8 %372 +%374 = OpIEqual %5 %373 %50 +OpSelectionMerge %375 None +OpBranchConditional %374 %376 %375 +%376 = OpLabel +OpStore %19 %46 +OpStore %21 %171 +OpBranch %375 +%375 = OpLabel +OpControlBarrier %54 %54 %55 +OpBranch %377 +%377 = OpLabel +%378 = OpCompositeExtract %8 %351 0 +%379 = OpIEqual %5 %378 %50 +OpSelectionMerge %380 None +OpBranchConditional %379 %381 %382 +%381 = OpLabel +%383 = OpAccessChain %178 %21 %54 +OpStore %383 %13 +%384 = OpAccessChain %178 %21 %13 +OpStore %384 %15 +OpStore %19 %161 +%385 = OpAccessChain %183 %21 %50 %50 %50 +OpStore %385 %162 +%386 = OpAccessChain %183 %21 %50 %50 %15 +OpStore %386 %162 +%387 = OpAccessChain %183 %21 %50 %15 %50 +OpStore %387 %164 +%388 = OpAccessChain %183 %21 %50 %15 %15 +OpStore %388 %165 +%389 = OpAccessChain %183 %21 %50 %54 %50 +OpStore %389 %166 +%390 = OpAccessChain %183 %21 %50 %54 %15 +OpStore %390 %167 +%391 = OpAccessChain %201 %21 %15 %50 %50 +OpStore %391 %168 +%392 = OpAccessChain %203 %21 %15 %50 %15 +OpStore %392 %281 +%393 = OpAccessChain %183 %21 %15 %50 %54 +OpStore %393 %169 +OpReturn +%382 = OpLabel +OpReturn %380 = OpLabel -%381 = OpCompositeExtract %4 %369 1 -%382 = OpCompositeExtract %4 %375 0 -%383 = OpFMul %4 %381 %382 -OpStore %378 %383 +OpReturn +OpFunctionEnd +%394 = OpFunction %2 None %63 +%395 = OpLabel +%396 = OpVariable %212 Function +%397 = OpVariable %212 Function +%398 = OpLoad %8 %352 +%399 = OpFunctionCall %2 %370 +OpControlBarrier %54 %54 %55 +%400 = OpAccessChain %178 %21 %54 +%401 = OpLoad %8 %400 +%402 = OpExtInst %8 %1 UMin %401 %13 +%403 = OpAccessChain %178 %21 %13 +%404 = OpLoad %8 %403 +%405 = OpExtInst %8 %1 UMin %404 %15 +%406 = OpAccessChain %181 %21 %50 +%407 = OpAccessChain %199 %21 %15 +OpSetMeshOutputsEXT %402 %405 +OpStore %396 %398 +OpBranch %408 +%408 = OpLabel +OpLoopMerge %410 %420 None +OpBranch %419 +%419 = OpLabel +%422 = OpLoad %8 %396 +%423 = OpULessThan %5 %422 %402 +OpBranchConditional %423 %421 %410 +%421 = OpLabel +%412 = OpLoad %8 %396 +%413 = OpAccessChain %183 %406 %412 %50 +%414 = OpLoad %4 %413 +%415 = OpAccessChain %231 %356 %412 %50 +OpStore %415 %414 +%416 = OpAccessChain %183 %406 %412 %15 +%417 = OpLoad %4 %416 +%418 = OpAccessChain %231 %363 %412 +OpStore %418 %417 +OpBranch %420 +%420 = OpLabel +%424 = OpLoad %8 %396 +%425 = OpIAdd %8 %424 %54 +OpStore %396 %425 +OpBranch %408 +%410 = OpLabel +OpStore %397 %398 +OpBranch %409 +%409 = OpLabel +OpLoopMerge %411 %437 None +OpBranch %436 +%436 = OpLabel +%439 = OpLoad %8 %397 +%440 = OpULessThan %5 %439 %405 +OpBranchConditional %440 %438 %411 +%438 = OpLabel +%426 = OpLoad %8 %397 +%427 = OpAccessChain %201 %407 %426 %50 +%428 = OpLoad %9 %427 +%429 = OpAccessChain %246 %366 %426 +OpStore %429 %428 +%430 = OpAccessChain %203 %407 %426 %15 +%431 = OpLoad %5 %430 +%432 = OpAccessChain %250 %360 %426 %50 +OpStore %432 %431 +%433 = OpAccessChain %183 %407 %426 %54 +%434 = OpLoad %4 %433 +%435 = OpAccessChain %231 %369 %426 +OpStore %435 %434 +OpBranch %437 +%437 = OpLabel +%441 = OpLoad %8 %397 +%442 = OpIAdd %8 %441 %54 +OpStore %397 %442 +OpBranch %409 +%411 = OpLabel +OpReturn +OpFunctionEnd +%454 = OpFunction %2 None %63 +%443 = OpLabel +%447 = OpLoad %4 %445 +%449 = OpLoad %4 %448 +%444 = OpCompositeConstruct %7 %447 %449 +%452 = OpLoad %4 %451 +%450 = OpCompositeConstruct %11 %452 +OpBranch %455 +%455 = OpLabel +%456 = OpCompositeExtract %4 %444 1 +%457 = OpCompositeExtract %4 %450 0 +%458 = OpFMul %4 %456 %457 +OpStore %453 %458 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-overrides-atomicCompareExchangeWeak.f.spvasm b/naga/tests/out/spv/wgsl-overrides-atomicCompareExchangeWeak.f.spvasm index 45e71af55..f32cd756b 100644 --- a/naga/tests/out/spv/wgsl-overrides-atomicCompareExchangeWeak.f.spvasm +++ b/naga/tests/out/spv/wgsl-overrides-atomicCompareExchangeWeak.f.spvasm @@ -1,15 +1,15 @@ ; SPIR-V ; Version: 1.0 ; Generator: rspirv -; Bound: 33 +; Bound: 29 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %11 "f" %18 +OpEntryPoint GLCompute %11 "f" %17 OpExecutionMode %11 LocalSize 1 1 1 OpMemberDecorate %6 0 Offset 0 OpMemberDecorate %6 1 Offset 4 -OpDecorate %18 BuiltIn LocalInvocationId +OpDecorate %17 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 1 %4 = OpTypeInt 32 0 @@ -22,31 +22,27 @@ OpDecorate %18 BuiltIn LocalInvocationId %13 = OpConstant %4 2 %14 = OpConstant %4 1 %16 = OpConstantNull %4 -%17 = OpTypeVector %4 3 -%19 = OpTypePointer Input %17 -%18 = OpVariable %19 Input -%21 = OpConstantNull %17 -%22 = OpTypeVector %5 3 -%27 = OpConstant %4 264 -%30 = OpConstant %4 0 +%18 = OpTypePointer Input %4 +%17 = OpVariable %18 Input +%20 = OpConstant %4 0 +%24 = OpConstant %4 264 %11 = OpFunction %2 None %12 %10 = OpLabel OpBranch %15 %15 = OpLabel -%20 = OpLoad %17 %18 -%23 = OpIEqual %22 %20 %21 -%24 = OpAll %5 %23 -OpSelectionMerge %25 None -OpBranchConditional %24 %26 %25 -%26 = OpLabel +%19 = OpLoad %4 %17 +%21 = OpIEqual %5 %19 %20 +OpSelectionMerge %22 None +OpBranchConditional %21 %23 %22 +%23 = OpLabel OpStore %8 %16 +OpBranch %22 +%22 = OpLabel +OpControlBarrier %13 %13 %24 OpBranch %25 %25 = OpLabel -OpControlBarrier %13 %13 %27 -OpBranch %28 -%28 = OpLabel -%31 = OpAtomicCompareExchange %4 %8 %7 %30 %30 %14 %13 -%32 = OpIEqual %5 %31 %13 -%29 = OpCompositeConstruct %6 %31 %32 +%27 = OpAtomicCompareExchange %4 %8 %7 %20 %20 %14 %13 +%28 = OpIEqual %5 %27 %13 +%26 = OpCompositeConstruct %6 %27 %28 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-policy-mix.spvasm b/naga/tests/out/spv/wgsl-policy-mix.spvasm index 8d9209d7b..23f331334 100644 --- a/naga/tests/out/spv/wgsl-policy-mix.spvasm +++ b/naga/tests/out/spv/wgsl-policy-mix.spvasm @@ -1,13 +1,13 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 126 +; Bound: 123 OpCapability Shader OpCapability ImageQuery OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %102 "main" %115 +OpEntryPoint GLCompute %102 "main" %114 OpExecutionMode %102 LocalSize 1 1 1 %3 = OpString "policy-mix.wgsl" OpSource Unknown 0 %3 "// Tests that the index, buffer, and texture bounds checks policies are @@ -82,7 +82,7 @@ OpDecorate %26 Block OpMemberDecorate %26 0 Offset 0 OpDecorate %28 DescriptorSet 0 OpDecorate %28 Binding 2 -OpDecorate %115 BuiltIn LocalInvocationId +OpDecorate %114 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %4 = OpTypeFloat 32 %5 = OpTypeVector %4 4 @@ -147,11 +147,9 @@ OpDecorate %115 BuiltIn LocalInvocationId %110 = OpConstant %18 3 %111 = OpConstant %18 4 %113 = OpConstantNull %14 -%114 = OpTypeVector %8 3 -%116 = OpTypePointer Input %114 -%115 = OpVariable %116 Input -%118 = OpConstantNull %114 -%123 = OpConstant %8 264 +%115 = OpTypePointer Input %8 +%114 = OpVariable %115 Input +%120 = OpConstant %8 264 %39 = OpFunction %5 None %40 %36 = OpFunctionParameter %19 %37 = OpFunctionParameter %18 @@ -214,21 +212,20 @@ OpFunctionEnd %106 = OpLoad %13 %28 OpBranch %112 %112 = OpLabel -%117 = OpLoad %114 %115 -%119 = OpIEqual %74 %117 %118 -%120 = OpAll %67 %119 -OpSelectionMerge %121 None -OpBranchConditional %120 %122 %121 -%122 = OpLabel +%116 = OpLoad %8 %114 +%117 = OpIEqual %67 %116 %42 +OpSelectionMerge %118 None +OpBranchConditional %117 %119 %118 +%119 = OpLabel OpStore %30 %113 +OpBranch %118 +%118 = OpLabel +OpControlBarrier %21 %21 %120 OpBranch %121 %121 = OpLabel -OpControlBarrier %21 %21 %123 -OpBranch %124 -%124 = OpLabel OpLine %3 37 19 OpLine %3 37 19 OpLine %3 37 5 -%125 = OpFunctionCall %5 %39 %109 %110 %111 +%122 = OpFunctionCall %5 %39 %109 %110 %111 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-workgroup-uniform-load-atomic.spvasm b/naga/tests/out/spv/wgsl-workgroup-uniform-load-atomic.spvasm index 616ca534d..2d88d2f04 100644 --- a/naga/tests/out/spv/wgsl-workgroup-uniform-load-atomic.spvasm +++ b/naga/tests/out/spv/wgsl-workgroup-uniform-load-atomic.spvasm @@ -5,13 +5,14 @@ OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %22 "test_atomic_workgroup_uniform_load" %17 %20 +OpEntryPoint GLCompute %22 "test_atomic_workgroup_uniform_load" %17 %20 %42 OpExecutionMode %22 LocalSize 64 1 1 OpDecorate %5 ArrayStride 4 OpMemberDecorate %7 0 Offset 0 OpMemberDecorate %7 1 Offset 4 OpDecorate %17 BuiltIn WorkgroupId OpDecorate %20 BuiltIn LocalInvocationId +OpDecorate %42 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 0 %4 = OpTypeInt 32 1 @@ -44,8 +45,8 @@ OpDecorate %20 BuiltIn LocalInvocationId %39 = OpConstantNull %3 %40 = OpConstantNull %4 %41 = OpConstantNull %7 -%42 = OpConstantNull %8 -%43 = OpTypeVector %9 3 +%43 = OpTypePointer Input %3 +%42 = OpVariable %43 Input %48 = OpConstant %3 264 %57 = OpConstant %4 2 %60 = OpTypePointer Workgroup %5 @@ -58,8 +59,8 @@ OpDecorate %20 BuiltIn LocalInvocationId %21 = OpLoad %8 %20 OpBranch %38 %38 = OpLabel -%44 = OpIEqual %43 %21 %42 -%45 = OpAll %9 %44 +%44 = OpLoad %3 %42 +%45 = OpIEqual %9 %44 %28 OpSelectionMerge %46 None OpBranchConditional %45 %47 %46 %47 = OpLabel diff --git a/naga/tests/out/spv/wgsl-workgroup-uniform-load.spvasm b/naga/tests/out/spv/wgsl-workgroup-uniform-load.spvasm index c2d0de7a0..e82a9a70b 100644 --- a/naga/tests/out/spv/wgsl-workgroup-uniform-load.spvasm +++ b/naga/tests/out/spv/wgsl-workgroup-uniform-load.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 39 +; Bound: 38 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 @@ -9,7 +9,7 @@ OpEntryPoint GLCompute %14 "test_workgroupUniformLoad" %11 %19 OpExecutionMode %14 LocalSize 4 1 1 OpDecorate %5 ArrayStride 4 OpDecorate %11 BuiltIn WorkgroupId -OpDecorate %19 BuiltIn LocalInvocationId +OpDecorate %19 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %3 = OpTypeInt 32 0 %4 = OpTypeInt 32 1 @@ -23,43 +23,42 @@ OpDecorate %19 BuiltIn LocalInvocationId %15 = OpTypeFunction %2 %16 = OpConstant %4 10 %18 = OpConstantNull %5 -%19 = OpVariable %12 Input -%21 = OpConstantNull %7 -%23 = OpTypeBool -%22 = OpTypeVector %23 3 -%28 = OpConstant %3 2 -%29 = OpConstant %3 264 -%32 = OpTypePointer Workgroup %4 +%20 = OpTypePointer Input %3 +%19 = OpVariable %20 Input +%22 = OpConstant %3 0 +%24 = OpTypeBool +%27 = OpConstant %3 2 +%28 = OpConstant %3 264 +%31 = OpTypePointer Workgroup %4 %14 = OpFunction %2 None %15 %10 = OpLabel %13 = OpLoad %7 %11 OpBranch %17 %17 = OpLabel -%20 = OpLoad %7 %19 -%24 = OpIEqual %22 %20 %21 -%25 = OpAll %23 %24 -OpSelectionMerge %26 None -OpBranchConditional %25 %27 %26 -%27 = OpLabel -OpStore %8 %18 -OpBranch %26 +%21 = OpLoad %3 %19 +%23 = OpIEqual %24 %21 %22 +OpSelectionMerge %25 None +OpBranchConditional %23 %26 %25 %26 = OpLabel -OpControlBarrier %28 %28 %29 -OpBranch %30 -%30 = OpLabel -%31 = OpCompositeExtract %3 %13 0 -OpControlBarrier %28 %28 %29 -%33 = OpAccessChain %32 %8 %31 -%34 = OpLoad %4 %33 -OpControlBarrier %28 %28 %29 -%35 = OpSGreaterThan %23 %34 %16 -OpSelectionMerge %36 None -OpBranchConditional %35 %37 %38 -%37 = OpLabel -OpControlBarrier %28 %28 %29 -OpReturn -%38 = OpLabel -OpReturn +OpStore %8 %18 +OpBranch %25 +%25 = OpLabel +OpControlBarrier %27 %27 %28 +OpBranch %29 +%29 = OpLabel +%30 = OpCompositeExtract %3 %13 0 +OpControlBarrier %27 %27 %28 +%32 = OpAccessChain %31 %8 %30 +%33 = OpLoad %4 %32 +OpControlBarrier %27 %27 %28 +%34 = OpSGreaterThan %24 %33 %16 +OpSelectionMerge %35 None +OpBranchConditional %34 %36 %37 %36 = OpLabel +OpControlBarrier %27 %27 %28 +OpReturn +%37 = OpLabel +OpReturn +%35 = OpLabel OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/spv/wgsl-workgroup-var-init.spvasm b/naga/tests/out/spv/wgsl-workgroup-var-init.spvasm index cb214f3e3..801ad15e9 100644 --- a/naga/tests/out/spv/wgsl-workgroup-var-init.spvasm +++ b/naga/tests/out/spv/wgsl-workgroup-var-init.spvasm @@ -1,12 +1,12 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 42 +; Bound: 38 OpCapability Shader OpExtension "SPV_KHR_storage_buffer_storage_class" %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint GLCompute %18 "main" %26 +OpEntryPoint GLCompute %18 "main" %25 OpExecutionMode %18 LocalSize 1 1 1 %3 = OpString "workgroup-var-init.wgsl" OpSource Unknown 0 %3 "struct WStruct { @@ -41,7 +41,7 @@ OpDecorate %14 DescriptorSet 0 OpDecorate %14 Binding 0 OpDecorate %15 Block OpMemberDecorate %15 0 Offset 0 -OpDecorate %26 BuiltIn LocalInvocationId +OpDecorate %25 BuiltIn LocalInvocationIndex %2 = OpTypeVoid %4 = OpTypeInt 32 0 %6 = OpConstant %4 512 @@ -60,36 +60,32 @@ OpDecorate %26 BuiltIn LocalInvocationId %20 = OpTypePointer StorageBuffer %5 %21 = OpConstant %4 0 %24 = OpConstantNull %11 -%25 = OpTypeVector %4 3 -%27 = OpTypePointer Input %25 -%26 = OpVariable %27 Input -%29 = OpConstantNull %25 -%31 = OpTypeBool -%30 = OpTypeVector %31 3 -%36 = OpConstant %4 2 -%37 = OpConstant %4 264 -%39 = OpTypePointer Workgroup %5 +%26 = OpTypePointer Input %4 +%25 = OpVariable %26 Input +%29 = OpTypeBool +%32 = OpConstant %4 2 +%33 = OpConstant %4 264 +%35 = OpTypePointer Workgroup %5 %18 = OpFunction %2 None %19 %17 = OpLabel %22 = OpAccessChain %20 %14 %21 OpBranch %23 %23 = OpLabel -%28 = OpLoad %25 %26 -%32 = OpIEqual %30 %28 %29 -%33 = OpAll %31 %32 -OpSelectionMerge %34 None -OpBranchConditional %33 %35 %34 -%35 = OpLabel +%27 = OpLoad %4 %25 +%28 = OpIEqual %29 %27 %21 +OpSelectionMerge %30 None +OpBranchConditional %28 %31 %30 +%31 = OpLabel OpStore %12 %24 +OpBranch %30 +%30 = OpLabel +OpControlBarrier %32 %32 %33 OpBranch %34 %34 = OpLabel -OpControlBarrier %36 %36 %37 -OpBranch %38 -%38 = OpLabel OpLine %3 14 14 -%40 = OpAccessChain %39 %12 %21 -%41 = OpLoad %5 %40 +%36 = OpAccessChain %35 %12 %21 +%37 = OpLoad %5 %36 OpLine %3 14 5 -OpStore %22 %41 +OpStore %22 %37 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/naga/tests/out/wgsl/wgsl-mesh-shader-empty.wgsl b/naga/tests/out/wgsl/wgsl-mesh-shader-empty.wgsl index c5e853af2..4920dbd86 100644 --- a/naga/tests/out/wgsl/wgsl-mesh-shader-empty.wgsl +++ b/naga/tests/out/wgsl/wgsl-mesh-shader-empty.wgsl @@ -22,12 +22,12 @@ struct MeshOutput { var taskPayload: TaskPayload; var mesh_output: MeshOutput; -@task @payload(taskPayload) @workgroup_size(1, 1, 1) +@task @payload(taskPayload) @workgroup_size(64, 1, 1) fn ts_main() -> @builtin(mesh_task_size) vec3 { return vec3(1u, 1u, 1u); } -@mesh(mesh_output) @workgroup_size(1, 1, 1) @payload(taskPayload) +@mesh(mesh_output) @workgroup_size(64, 1, 1) @payload(taskPayload) fn ms_main() { return; } diff --git a/naga/tests/out/wgsl/wgsl-mesh-shader-lines.wgsl b/naga/tests/out/wgsl/wgsl-mesh-shader-lines.wgsl index fe7c341f3..85fb35599 100644 --- a/naga/tests/out/wgsl/wgsl-mesh-shader-lines.wgsl +++ b/naga/tests/out/wgsl/wgsl-mesh-shader-lines.wgsl @@ -22,12 +22,12 @@ struct MeshOutput { var taskPayload: TaskPayload; var mesh_output: MeshOutput; -@task @payload(taskPayload) @workgroup_size(1, 1, 1) +@task @payload(taskPayload) @workgroup_size(64, 1, 1) fn ts_main() -> @builtin(mesh_task_size) vec3 { return vec3(1u, 1u, 1u); } -@mesh(mesh_output) @workgroup_size(1, 1, 1) @payload(taskPayload) +@mesh(mesh_output) @workgroup_size(64, 1, 1) @payload(taskPayload) fn ms_main() { return; } diff --git a/naga/tests/out/wgsl/wgsl-mesh-shader-points.wgsl b/naga/tests/out/wgsl/wgsl-mesh-shader-points.wgsl index b6eea73d0..0407e21c6 100644 --- a/naga/tests/out/wgsl/wgsl-mesh-shader-points.wgsl +++ b/naga/tests/out/wgsl/wgsl-mesh-shader-points.wgsl @@ -22,12 +22,12 @@ struct MeshOutput { var taskPayload: TaskPayload; var mesh_output: MeshOutput; -@task @payload(taskPayload) @workgroup_size(1, 1, 1) +@task @payload(taskPayload) @workgroup_size(64, 1, 1) fn ts_main() -> @builtin(mesh_task_size) vec3 { return vec3(1u, 1u, 1u); } -@mesh(mesh_output) @workgroup_size(1, 1, 1) @payload(taskPayload) +@mesh(mesh_output) @workgroup_size(64, 1, 1) @payload(taskPayload) fn ms_main() { return; } diff --git a/naga/tests/out/wgsl/wgsl-mesh-shader.wgsl b/naga/tests/out/wgsl/wgsl-mesh-shader.wgsl index 974027fdb..93372453c 100644 --- a/naga/tests/out/wgsl/wgsl-mesh-shader.wgsl +++ b/naga/tests/out/wgsl/wgsl-mesh-shader.wgsl @@ -31,17 +31,29 @@ var taskPayload: TaskPayload; var workgroupData: f32; var mesh_output: MeshOutput; +fn helper_reader() -> bool { + let _e2 = taskPayload.visible; + return _e2; +} + +fn helper_writer(value: bool) { + taskPayload.visible = value; + return; +} + @task @payload(taskPayload) @workgroup_size(1, 1, 1) fn ts_main() -> @builtin(mesh_task_size) vec3 { workgroupData = 1f; taskPayload.colorMask = vec4(1f, 1f, 0f, 1f); - taskPayload.visible = true; + helper_writer(true); + let _e12 = helper_reader(); + taskPayload.visible = _e12; return vec3(1u, 1u, 1u); } @task @payload(taskPayload) @workgroup_size(2, 1, 1) -fn ts_divergent(@builtin(local_invocation_index) thread_id: u32) -> @builtin(mesh_task_size) vec3 { - if (thread_id == 0u) { +fn ts_divergent(@builtin(local_invocation_id) thread_id: vec3) -> @builtin(mesh_task_size) vec3 { + if (thread_id.x == 0u) { taskPayload.colorMask = vec4(1f, 1f, 0f, 1f); taskPayload.visible = true; return vec3(1u, 1u, 1u); @@ -64,8 +76,8 @@ fn ms_main() { let _e67 = taskPayload.colorMask; mesh_output.vertices[2].color = (vec4(1f, 0f, 0f, 1f) * _e67); mesh_output.primitives[0].indices = vec3(0u, 1u, 2u); - let _e88 = taskPayload.visible; - mesh_output.primitives[0].cull = !(_e88); + let _e86 = helper_reader(); + mesh_output.primitives[0].cull = !(_e86); mesh_output.primitives[0].colorMask = vec4(1f, 0f, 1f, 1f); return; } @@ -87,9 +99,9 @@ fn ms_no_ts() { return; } -@mesh(mesh_output) @workgroup_size(1, 1, 1) -fn ms_divergent(@builtin(local_invocation_index) thread_id_1: u32) { - if (thread_id_1 == 0u) { +@mesh(mesh_output) @workgroup_size(2, 1, 1) +fn ms_divergent(@builtin(local_invocation_id) thread_id_1: vec3) { + if (thread_id_1.x == 0u) { mesh_output.vertex_count = 3u; mesh_output.primitive_count = 1u; workgroupData = 2f; diff --git a/tests/tests/wgpu-gpu/mesh_shader/shader.wgsl b/tests/tests/wgpu-gpu/mesh_shader/shader.wgsl index 13f6c225e..8a8d6de11 100644 --- a/tests/tests/wgpu-gpu/mesh_shader/shader.wgsl +++ b/tests/tests/wgpu-gpu/mesh_shader/shader.wgsl @@ -96,9 +96,9 @@ fn ms_no_ts() { @mesh(mesh_output) @workgroup_size(2) -fn ms_divergent(@builtin(local_invocation_index) index: u32) { +fn ms_divergent(@builtin(local_invocation_id) thread_id: vec3) { // Workgroup with 2 threads. They return at different points. - if index == 0 { + if thread_id.x == 0 { mesh_output.vertex_count = 3; mesh_output.primitive_count = 1; workgroupData = 2.0; diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 0db307da8..b6aca05a5 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -2218,6 +2218,7 @@ impl super::Adapter { drop_callback: Option, enabled_extensions: &[&'static CStr], features: wgt::Features, + limits: &wgt::Limits, memory_hints: &wgt::MemoryHints, family_index: u32, queue_index: u32, @@ -2485,6 +2486,11 @@ impl super::Adapter { // We need to build this separately for each invocation, so just default it out here binding_map: BTreeMap::default(), debug_info: None, + task_dispatch_limits: Some(naga::back::TaskDispatchLimits { + max_mesh_workgroups_per_dim: limits.max_task_mesh_workgroups_per_dimension, + max_mesh_workgroups_total: limits.max_task_mesh_workgroup_total_count, + }), + mesh_shader_primitive_indices_clamp: true, } }; @@ -2597,6 +2603,7 @@ impl super::Adapter { pub unsafe fn open_with_callback<'a>( &self, features: wgt::Features, + limits: &wgt::Limits, memory_hints: &wgt::MemoryHints, callback: Option>>, ) -> Result, crate::DeviceError> { @@ -2659,6 +2666,7 @@ impl super::Adapter { None, &enabled_extensions, features, + limits, memory_hints, family_info.queue_family_index, 0, @@ -2673,10 +2681,10 @@ impl crate::Adapter for super::Adapter { unsafe fn open( &self, features: wgt::Features, - _limits: &wgt::Limits, + limits: &wgt::Limits, memory_hints: &wgt::MemoryHints, ) -> Result, crate::DeviceError> { - unsafe { self.open_with_callback(features, memory_hints, None) } + unsafe { self.open_with_callback(features, limits, memory_hints, None) } } unsafe fn texture_format_capabilities( diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 415841d6a..67574d7b8 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -653,7 +653,10 @@ impl super::Device { || !runtime_checks.ray_query_initialization_tracking || !binding_map.is_empty() || naga_shader.debug_source.is_some() - || !stage.zero_initialize_workgroup_memory; + || !stage.zero_initialize_workgroup_memory + || !runtime_checks.task_shader_dispatch_tracking + || !runtime_checks.mesh_shader_primitive_indices_clamp; + let mut temp_options; let options = if needs_temp_options { temp_options = self.naga_options.clone(); @@ -686,6 +689,11 @@ impl super::Device { temp_options.zero_initialize_workgroup_memory = naga::back::spv::ZeroInitializeWorkgroupMemoryMode::None; } + if !runtime_checks.task_shader_dispatch_tracking { + temp_options.task_dispatch_limits = None; + } + temp_options.mesh_shader_primitive_indices_clamp = + runtime_checks.mesh_shader_primitive_indices_clamp; &temp_options } else { diff --git a/wgpu-types/src/features.rs b/wgpu-types/src/features.rs index 755c9f932..6bf7f1b80 100644 --- a/wgpu-types/src/features.rs +++ b/wgpu-types/src/features.rs @@ -1155,6 +1155,10 @@ bitflags_array! { /// /// Naga is only supported on vulkan. On other platforms you will have to use passthrough shaders. /// + /// It is recommended to use [`Device::create_shader_module_trusted`] with [`ShaderRuntimeChecks::unchecked()`] + /// to avoid workgroup memory zero initialization, which can be expensive due to zero initialization being + /// single-threaded currently. + /// /// Some Mesa drivers including LLVMPIPE but not RADV fail to run the naga generated code. /// [This may be our bug and will be investigated.](https://github.com/gfx-rs/wgpu/issues/8727) /// However, due to the nature of the failure, the fact that it is unique, and the random changes @@ -1162,6 +1166,9 @@ bitflags_array! { /// [this Mesa issue.](https://gitlab.freedesktop.org/mesa/mesa/-/issues/14376) /// /// This is a native only feature. + /// + /// [`Device::create_shader_module_trusted`]: https://docs.rs/wgpu/latest/wgpu/struct.Device.html#method.create_shader_module_trusted + /// [`ShaderRuntimeChecks::unchecked()`]: crate::ShaderRuntimeChecks::unchecked const EXPERIMENTAL_MESH_SHADER = 1 << 48; /// ***THIS IS EXPERIMENTAL:*** Features enabled by this may have diff --git a/wgpu-types/src/shader.rs b/wgpu-types/src/shader.rs index 83102f84d..121b7875b 100644 --- a/wgpu-types/src/shader.rs +++ b/wgpu-types/src/shader.rs @@ -43,6 +43,13 @@ pub struct ShaderRuntimeChecks { /// /// It is the aim that these cases will not cause UB if this is set to true, but currently this will still happen on DX12 and Metal. pub ray_query_initialization_tracking: bool, + + /// If false, task shaders will not validate that the mesh shader grid they dispatch is within legal limits. + pub task_shader_dispatch_tracking: bool, + + /// If false, mesh shaders won't clamp the output primitives' vertex indices, which can lead to + /// undefined behavior and arbitrary memory access. + pub mesh_shader_primitive_indices_clamp: bool, } impl ShaderRuntimeChecks { @@ -76,6 +83,8 @@ impl ShaderRuntimeChecks { bounds_checks: all_checks, force_loop_bounding: all_checks, ray_query_initialization_tracking: all_checks, + task_shader_dispatch_tracking: all_checks, + mesh_shader_primitive_indices_clamp: all_checks, } } }