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
This commit is contained in:
Inner Daemons authored and GitHub committed 2026-02-12 14:47:42 -05:00
1 parent c70b53c123
commit 6bca1014b2
44 files changed
+2061 -1504

No files matched your search

+4
View File
@@ -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<i32>(); 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)
+6 -4
View File
@@ -366,14 +366,16 @@ pub fn backends(ctx: BenchmarkContext) -> anyhow::Result<Vec<SubBenchResult>> {
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(),
+1 -3
View File
@@ -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<u32>` 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<u32>` 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<u32>` 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
+10 -4
View File
@@ -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!(
+23 -23
View File
@@ -33,12 +33,15 @@ var<workgroup> workgroupData: f32;
@task
@payload(taskPayload)
@workgroup_size(1)
fn ts_main() -> @builtin(mesh_task_size) vec3<u32> {
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<u32>) -> @builtin(mesh_task_size) vec3<u32> {
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<workgroup> 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<u32>) {
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<u32>(0, 1, 2);
mesh_output.primitives[0].cull = !taskPayload.visible;
mesh_output.primitives[0].colorMask = vec4<f32>(1.0, 0.0, 1.0, 1.0);
mesh_output.primitives[0].indices = vec3<u32>(0, 1, 2);
mesh_output.primitives[0].cull = !taskPayload.visible;
mesh_output.primitives[0].colorMask = vec4<f32>(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
+31
View File
@@ -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<TaskDispatchLimits>`.
#[derive(Debug, Clone, Copy)]
struct TaskDispatchLimitsArg(Option<naga::back::TaskDispatchLimits>);
impl FromStr for TaskDispatchLimitsArg {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let values = s
.split_once(",")
.ok_or_else(|| format!("No comma present for --task-limits value: {s}"))?;
let x = values.0.parse::<u32>().map_err(|e| e.to_string())?;
let y = values.1.parse::<u32>().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, &params);
}
+23 -2
View File
@@ -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<naga::back::TaskDispatchLimits>,
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::DebugInfo<'a>>,
) -> 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<naga::back::TaskDispatchLimits>,
}
fn default_task_limits() -> Option<naga::back::TaskDispatchLimits> {
Some(naga::back::TaskDispatchLimits {
max_mesh_workgroups_per_dim: 256,
max_mesh_workgroups_total: 1024,
})
}
/// Information about a shader input file.
+9
View File
@@ -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<crate::Function>),
@@ -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,
}
+3 -32
View File
@@ -237,12 +237,11 @@ impl Writer {
ir_result: &crate::FunctionResult,
result_members: &[ResultMember],
body: &mut Vec<Instruction>,
task_payload: Option<Word>,
) -> Result<Instruction, Error> {
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(())
}
+278 -111
View File
@@ -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<MeshReturnMember>,
/// 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<Word>,
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<Instruction>,
task_payload: Option<Word>,
task_payload: Word,
) -> Result<Instruction, Error> {
// 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<u32> ...`
// 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<u32> 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<u32> 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<u32, Error> {
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<u32, Error> {
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)
}
}
+18
View File
@@ -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<Word>,
//TODO: convert most of these into vectors, addressable by handle indices
lookup_type: crate::FastHashMap<LookupType, Word>,
lookup_function: crate::FastHashMap<Handle<crate::Function>, Word>,
@@ -967,6 +969,16 @@ pub struct Writer {
/// Non semantic debug printf extension `OpExtInstImport`
debug_printf: Option<Word>,
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<TaskDispatchLimits>,
/// 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<DebugInfo<'a>>,
pub task_dispatch_limits: Option<TaskDispatchLimits>,
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,
}
}
}
+78 -83
View File
@@ -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<DebugInfoInner>,
) -> Result<Instruction, Error> {
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<Word>,
local_invocation_index: Option<Word>,
interface: &mut FunctionInterface,
function: &mut Function,
) -> Option<Word> {
@@ -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")
+5 -26
View File
@@ -288,7 +288,10 @@ impl<W: Write> Writer<W> {
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<W: Write> Writer<W> {
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<W: Write> Writer<W> {
}
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<W: Write> Writer<W> {
}
}
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<W: Write> Writer<W> {
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;
}
+90
View File
@@ -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)
}
}
+1 -1
View File
@@ -269,7 +269,7 @@ pub struct FunctionInfo {
/// `FunctionInfo` implements `core::ops::Index<Handle<GlobalVariable>>`,
/// 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.
///
+5 -3
View File
@@ -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());
}
+2 -2
View File
@@ -17,7 +17,7 @@ var<task_payload> taskPayload: TaskPayload;
@task
@payload(taskPayload)
@workgroup_size(1)
@workgroup_size(64)
fn ts_main() -> @builtin(mesh_task_size) vec3<u32> {
return vec3(1, 1, 1);
}
@@ -33,5 +33,5 @@ var<workgroup> mesh_output: MeshOutput;
@mesh(mesh_output)
@payload(taskPayload)
@workgroup_size(1)
@workgroup_size(64)
fn ms_main() {}
+2 -2
View File
@@ -17,7 +17,7 @@ var<task_payload> taskPayload: TaskPayload;
@task
@payload(taskPayload)
@workgroup_size(1)
@workgroup_size(64)
fn ts_main() -> @builtin(mesh_task_size) vec3<u32> {
return vec3(1, 1, 1);
}
@@ -33,5 +33,5 @@ var<workgroup> mesh_output: MeshOutput;
@mesh(mesh_output)
@payload(taskPayload)
@workgroup_size(1)
@workgroup_size(64)
fn ms_main() {}
+2 -2
View File
@@ -17,7 +17,7 @@ var<task_payload> taskPayload: TaskPayload;
@task
@payload(taskPayload)
@workgroup_size(1)
@workgroup_size(64)
fn ts_main() -> @builtin(mesh_task_size) vec3<u32> {
return vec3(1, 1, 1);
}
@@ -33,5 +33,5 @@ var<workgroup> mesh_output: MeshOutput;
@mesh(mesh_output)
@payload(taskPayload)
@workgroup_size(1)
@workgroup_size(64)
fn ms_main() {}
+15 -7
View File
@@ -31,13 +31,21 @@ struct PrimitiveInput {
var<task_payload> taskPayload: TaskPayload;
var<workgroup> 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<u32> {
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<u32> {
@task
@payload(taskPayload)
@workgroup_size(2)
fn ts_divergent(@builtin(local_invocation_index) thread_id: u32) -> @builtin(mesh_task_size) vec3<u32> {
if thread_id == 0 {
fn ts_divergent(@builtin(local_invocation_id) thread_id: vec3<u32>) -> @builtin(mesh_task_size) vec3<u32> {
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<u32>(0, 1, 2);
mesh_output.primitives[0].cull = !taskPayload.visible;
mesh_output.primitives[0].cull = !helper_reader();
mesh_output.primitives[0].colorMask = vec4<f32>(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<u32>) {
if thread_id.x == 0 {
mesh_output.vertex_count = 3;
mesh_output.primitive_count = 1;
workgroupData = 2.0;
+9 -3
View File
@@ -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,
&params.spv,
params.bounds_check_policies,
&params.pipeline_constants,
&shared_info,
);
}
@@ -169,12 +175,12 @@ fn write_output_spv(
info: &naga::valid::ModuleInfo,
debug_info: Option<naga::back::spv::DebugInfo>,
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)
@@ -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
@@ -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
+6 -5
View File
@@ -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
+70 -74
View File
@@ -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
@@ -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
+166 -122
View File
@@ -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
+166 -122
View File
@@ -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
+166 -122
View File
@@ -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
File diff suppressed because it is too large. Load diff
@@ -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
+15 -18
View File
@@ -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
@@ -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
@@ -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
@@ -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
@@ -22,12 +22,12 @@ struct MeshOutput {
var<task_payload> taskPayload: TaskPayload;
var<workgroup> 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<u32> {
return vec3<u32>(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;
}
@@ -22,12 +22,12 @@ struct MeshOutput {
var<task_payload> taskPayload: TaskPayload;
var<workgroup> 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<u32> {
return vec3<u32>(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;
}
@@ -22,12 +22,12 @@ struct MeshOutput {
var<task_payload> taskPayload: TaskPayload;
var<workgroup> 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<u32> {
return vec3<u32>(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;
}
+20 -8
View File
@@ -31,17 +31,29 @@ var<task_payload> taskPayload: TaskPayload;
var<workgroup> workgroupData: f32;
var<workgroup> 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<u32> {
workgroupData = 1f;
taskPayload.colorMask = vec4<f32>(1f, 1f, 0f, 1f);
taskPayload.visible = true;
helper_writer(true);
let _e12 = helper_reader();
taskPayload.visible = _e12;
return vec3<u32>(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<u32> {
if (thread_id == 0u) {
fn ts_divergent(@builtin(local_invocation_id) thread_id: vec3<u32>) -> @builtin(mesh_task_size) vec3<u32> {
if (thread_id.x == 0u) {
taskPayload.colorMask = vec4<f32>(1f, 1f, 0f, 1f);
taskPayload.visible = true;
return vec3<u32>(1u, 1u, 1u);
@@ -64,8 +76,8 @@ fn ms_main() {
let _e67 = taskPayload.colorMask;
mesh_output.vertices[2].color = (vec4<f32>(1f, 0f, 0f, 1f) * _e67);
mesh_output.primitives[0].indices = vec3<u32>(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<f32>(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<u32>) {
if (thread_id_1.x == 0u) {
mesh_output.vertex_count = 3u;
mesh_output.primitive_count = 1u;
workgroupData = 2f;
+2 -2
View File
@@ -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<u32>) {
// 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;
+10 -2
View File
@@ -2218,6 +2218,7 @@ impl super::Adapter {
drop_callback: Option<crate::DropCallback>,
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<Box<super::CreateDeviceCallback<'a>>>,
) -> Result<crate::OpenDevice<super::Api>, 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::OpenDevice<super::Api>, 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(
+9 -1
View File
@@ -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 {
+7
View File
@@ -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
+9
View File
@@ -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,
}
}
}