diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d0c4fb4..7325ec585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Bottom level categories: #### naga +- Initial wgsl-in ray tracing pipelines. By @Vecvec in [#8570](https://github.com/gfx-rs/wgpu/pull/8570). - Allow parsing shaders which make use of `SPV_KHR_non_semantic_info` for debug info. Also removes `naga::front::spv::SUPPORTED_EXT_SETS`. By @inner-daemons in #8827. ### Changes diff --git a/docs/api-specs/ray_tracing.md b/docs/api-specs/ray_tracing.md index fd5ec5729..22c8d01c5 100644 --- a/docs/api-specs/ray_tracing.md +++ b/docs/api-specs/ray_tracing.md @@ -93,10 +93,12 @@ fn render(/*whatever args you need to render*/) { ## `naga`'s raytracing API: -`naga` supports ray queries (also known as inline raytracing) only. To enable basic ray query functions you must add +`naga` supports ray queries (also known as inline raytracing). To enable basic ray query functions you must add `enable wgpu_ray_query` to the shader, ray queries and acceleration structures also support tags which require extra -`enable` extensions (see Acceleration structure tags for more info). Ray tracing pipelines -are currently unsupported. Naming is mostly taken from vulkan. +`enable` extensions (see Acceleration structure tags for more info). Ray tracing pipelines are currently in +development. Naming is mostly taken from vulkan. + +### Ray Queries ```wgsl // - Initializes the `ray_query` to check where (if anywhere) the ray defined by `ray_desc` hits in `acceleration_structure` @@ -148,7 +150,7 @@ getCandidateHitVertexPositions(rq: ptr>) -> a > [!CAUTION] > -> ### ⚠️Undefined behavior ⚠️: +> #### ⚠️Undefined behavior ⚠️: > - Calling `rayQueryGetCommittedIntersection` or `rayQueryGetCandidateIntersection` when `rayQueryProceed` has not been > called on this ray query since it was initialized (or if the ray query has not been previously initialized). > - Calling `rayQueryGetCommittedIntersection` when `rayQueryProceed`'s latest return on this ray query is considered @@ -272,6 +274,39 @@ const RAY_QUERY_INTERSECTION_GENERATED = 2; const RAY_QUERY_INTERSECTION_AABB = 3; ``` +### Ray Tracing Pipelines + +Functions +```wgsl +// Begins to check where (if anywhere) the ray defined by `ray_desc` hits in `acceleration_structure` calling through the `any_hit` shaders and `closest_hit` shader if something was hit or the `miss` shader if no hit was found +traceRay(acceleration_structure: acceleration_structure, ray_desc: RayDesc, payload: ptr) +``` + +> [!CAUTION] +> +> #### ⚠️Undefined behavior ⚠️: +> Calling `traceRay` inside another `traceRay` more than `max_recursion_depth` times +> +> *this is only known undefined behaviour, and will be worked around in the future. + +New shader stages +```wgsl +// First stage to be called, allowed to call `traceRay` +@ray_generation +fn rg() {} + +// Stage called on any hit that is not opaque, not allowed to call `traceRay` +@any_hit +fn ah() {} + +// Stage called on the closest hit, allowed to call `traceRay` +@closest_hit +fn ch() {} + +// Stage call if there was never a hit, allowed to call `traceRay` +@miss +fn miss() {} +``` ### Acceleration structure tags These are tags that can be added to a acceleration structure (`acceleration_structure` -> diff --git a/naga/src/back/dot/mod.rs b/naga/src/back/dot/mod.rs index 7be93c900..9c617a3b1 100644 --- a/naga/src/back/dot/mod.rs +++ b/naga/src/back/dot/mod.rs @@ -413,6 +413,22 @@ impl StatementGraph { "CoopStore" } } + S::RayPipelineFunction(func) => match func { + crate::RayPipelineFunction::TraceRay { + acceleration_structure, + descriptor, + payload, + } => { + self.dependencies.push(( + id, + acceleration_structure, + "acceleration_structure", + )); + self.dependencies.push((id, descriptor, "descriptor")); + self.dependencies.push((id, payload, "payload")); + "TraceRay" + } + }, }; // Set the last node to the merge node last_node = merge_id; diff --git a/naga/src/back/glsl/conv.rs b/naga/src/back/glsl/conv.rs index f9393dfee..dad78cb73 100644 --- a/naga/src/back/glsl/conv.rs +++ b/naga/src/back/glsl/conv.rs @@ -126,7 +126,20 @@ pub(in crate::back::glsl) const fn glsl_built_in( | Bi::VertexCount | Bi::PrimitiveCount | Bi::Vertices - | Bi::Primitives => { + | Bi::Primitives + | Bi::RayInvocationId + | Bi::NumRayInvocations + | Bi::InstanceCustomData + | Bi::GeometryIndex + | Bi::WorldRayOrigin + | Bi::WorldRayDirection + | Bi::ObjectRayOrigin + | Bi::ObjectRayDirection + | Bi::RayTmin + | Bi::RayTCurrentMax + | Bi::ObjectToWorld + | Bi::WorldToObject + | Bi::HitKind => { unimplemented!() } } @@ -146,7 +159,7 @@ pub(in crate::back::glsl) const fn glsl_storage_qualifier( As::Handle => Some("uniform"), As::WorkGroup => Some("shared"), As::Immediate => Some("uniform"), - As::TaskPayload => unreachable!(), + As::TaskPayload | As::RayPayload | As::IncomingRayPayload => unreachable!(), } } diff --git a/naga/src/back/glsl/mod.rs b/naga/src/back/glsl/mod.rs index a69ec5491..bb4ef4525 100644 --- a/naga/src/back/glsl/mod.rs +++ b/naga/src/back/glsl/mod.rs @@ -146,6 +146,10 @@ impl crate::AddressSpace { | crate::AddressSpace::Handle | crate::AddressSpace::Immediate | crate::AddressSpace::TaskPayload => false, + + crate::AddressSpace::RayPayload | crate::AddressSpace::IncomingRayPayload => { + unreachable!() + } } } } @@ -509,7 +513,15 @@ impl fmt::Display for VaryingName<'_> { (ShaderStage::Vertex, true) | (ShaderStage::Fragment, false) => "vs2fs", // fragment to pipeline (ShaderStage::Fragment, true) => "fs2p", - (ShaderStage::Task | ShaderStage::Mesh, _) => unreachable!(), + ( + ShaderStage::Task + | ShaderStage::Mesh + | ShaderStage::RayGeneration + | ShaderStage::AnyHit + | ShaderStage::ClosestHit + | ShaderStage::Miss, + _, + ) => unreachable!(), }; write!(f, "_{prefix}_location{location}",) } @@ -526,7 +538,12 @@ impl ShaderStage { ShaderStage::Compute => "cs", ShaderStage::Fragment => "fs", ShaderStage::Vertex => "vs", - ShaderStage::Task | ShaderStage::Mesh => unreachable!(), + ShaderStage::Task + | ShaderStage::Mesh + | ShaderStage::RayGeneration + | ShaderStage::AnyHit + | ShaderStage::ClosestHit + | ShaderStage::Miss => unreachable!(), } } } diff --git a/naga/src/back/glsl/writer.rs b/naga/src/back/glsl/writer.rs index 5fdd875f4..f28466338 100644 --- a/naga/src/back/glsl/writer.rs +++ b/naga/src/back/glsl/writer.rs @@ -729,6 +729,10 @@ impl<'a, W: Write> Writer<'a, W> { crate::AddressSpace::Function => unreachable!(), // Textures and samplers are handled directly in `Writer::write`. crate::AddressSpace::Handle => unreachable!(), + // ray tracing pipelines unsupported + crate::AddressSpace::RayPayload | crate::AddressSpace::IncomingRayPayload => { + unreachable!() + } } Ok(()) @@ -1095,7 +1099,12 @@ impl<'a, W: Write> Writer<'a, W> { ShaderStage::Vertex => output, ShaderStage::Fragment => !output, ShaderStage::Compute => false, - ShaderStage::Task | ShaderStage::Mesh => unreachable!(), + ShaderStage::Task + | ShaderStage::Mesh + | ShaderStage::RayGeneration + | ShaderStage::AnyHit + | ShaderStage::ClosestHit + | ShaderStage::Miss => unreachable!(), }; // Write the I/O locations, if allowed @@ -2231,6 +2240,7 @@ impl<'a, W: Write> Writer<'a, W> { writeln!(self.out, ");")?; } Statement::CooperativeStore { .. } => unimplemented!(), + Statement::RayPipelineFunction(_) => unimplemented!(), } Ok(()) diff --git a/naga/src/back/hlsl/conv.rs b/naga/src/back/hlsl/conv.rs index 47532b9a3..d38a7b7d5 100644 --- a/naga/src/back/hlsl/conv.rs +++ b/naga/src/back/hlsl/conv.rs @@ -192,6 +192,19 @@ impl crate::BuiltIn { | Self::PrimitiveCount | Self::Vertices | Self::Primitives => unreachable!(), + Self::RayInvocationId + | Self::NumRayInvocations + | Self::InstanceCustomData + | Self::GeometryIndex + | Self::WorldRayOrigin + | Self::WorldRayDirection + | Self::ObjectRayOrigin + | Self::ObjectRayDirection + | Self::RayTmin + | Self::RayTCurrentMax + | Self::ObjectToWorld + | Self::WorldToObject + | Self::HitKind => unreachable!(), }) } } diff --git a/naga/src/back/hlsl/mod.rs b/naga/src/back/hlsl/mod.rs index ca6bfb64f..a75bb8359 100644 --- a/naga/src/back/hlsl/mod.rs +++ b/naga/src/back/hlsl/mod.rs @@ -283,6 +283,7 @@ impl crate::ShaderStage { Self::Compute => "cs", Self::Task => "as", Self::Mesh => "ms", + Self::RayGeneration | Self::AnyHit | Self::ClosestHit | Self::Miss => "lib", } } } diff --git a/naga/src/back/hlsl/writer.rs b/naga/src/back/hlsl/writer.rs index ec852dacf..d11dc861a 100644 --- a/naga/src/back/hlsl/writer.rs +++ b/naga/src/back/hlsl/writer.rs @@ -1015,6 +1015,9 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, "ConstantBuffer<")?; "b" } + crate::AddressSpace::RayPayload | crate::AddressSpace::IncomingRayPayload => { + unimplemented!() + } }; // If the global is a immediate data write the type now because it will be a @@ -2802,6 +2805,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { writeln!(self.out, ");")?; } Statement::CooperativeStore { .. } => unimplemented!(), + Statement::RayPipelineFunction(_) => unreachable!(), } Ok(()) @@ -3132,7 +3136,9 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { | crate::AddressSpace::Private | crate::AddressSpace::WorkGroup | crate::AddressSpace::Immediate - | crate::AddressSpace::TaskPayload, + | crate::AddressSpace::TaskPayload + | crate::AddressSpace::RayPayload + | crate::AddressSpace::IncomingRayPayload, ) | None => true, Some(crate::AddressSpace::Uniform) => { diff --git a/naga/src/back/msl/mod.rs b/naga/src/back/msl/mod.rs index 79538f595..36da152aa 100644 --- a/naga/src/back/msl/mod.rs +++ b/naga/src/back/msl/mod.rs @@ -723,7 +723,20 @@ impl ResolvedBinding { | Bi::VertexCount | Bi::PrimitiveCount | Bi::Vertices - | Bi::Primitives => unreachable!(), + | Bi::Primitives + | Bi::RayInvocationId + | Bi::NumRayInvocations + | Bi::InstanceCustomData + | Bi::GeometryIndex + | Bi::WorldRayOrigin + | Bi::WorldRayDirection + | Bi::ObjectRayOrigin + | Bi::ObjectRayDirection + | Bi::RayTmin + | Bi::RayTCurrentMax + | Bi::ObjectToWorld + | Bi::WorldToObject + | Bi::HitKind => unreachable!(), }; write!(out, "{name}")?; } diff --git a/naga/src/back/msl/writer.rs b/naga/src/back/msl/writer.rs index 48b928cef..5a5222cf9 100644 --- a/naga/src/back/msl/writer.rs +++ b/naga/src/back/msl/writer.rs @@ -628,6 +628,7 @@ impl crate::AddressSpace { | Self::Handle | Self::TaskPayload => true, Self::Function => false, + Self::RayPayload | Self::IncomingRayPayload => unreachable!(), } } @@ -639,7 +640,7 @@ impl crate::AddressSpace { // may end up with "const" even if the binding is read-write, // and that should be OK. Self::Storage { .. } => true, - Self::TaskPayload => unimplemented!(), + Self::TaskPayload | Self::RayPayload | Self::IncomingRayPayload => unimplemented!(), // These should always be read-write. Self::Private | Self::WorkGroup => false, // These translate to `constant` address space, no need for qualifiers. @@ -654,9 +655,13 @@ impl crate::AddressSpace { Self::Handle => None, Self::Uniform | Self::Immediate => Some("constant"), Self::Storage { .. } => Some("device"), - Self::Private | Self::Function => Some("thread"), + // note for `RayPayload`, this probably needs to be emulated as a + // private variable, as metal has essentially an inout input + // for where it is passed. + Self::Private | Self::Function | Self::RayPayload => Some("thread"), Self::WorkGroup => Some("threadgroup"), Self::TaskPayload => Some("object_data"), + Self::IncomingRayPayload => Some("ray_data"), } } } @@ -4279,6 +4284,7 @@ impl Writer { } writeln!(self.out, ");")?; } + crate::Statement::RayPipelineFunction(_) => unreachable!(), } } @@ -6875,6 +6881,10 @@ template false, ), crate::ShaderStage::Task | crate::ShaderStage::Mesh => unimplemented!(), + crate::ShaderStage::RayGeneration + | crate::ShaderStage::AnyHit + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::Miss => unimplemented!(), }; // Should this entry point be modified to do vertex pulling? @@ -6947,6 +6957,8 @@ template crate::AddressSpace::Function | crate::AddressSpace::Private | crate::AddressSpace::WorkGroup => {} + crate::AddressSpace::RayPayload + | crate::AddressSpace::IncomingRayPayload => unimplemented!(), } } if needs_buffer_sizes { diff --git a/naga/src/back/pipeline_constants.rs b/naga/src/back/pipeline_constants.rs index fdcc0b4d4..79eaeeb32 100644 --- a/naga/src/back/pipeline_constants.rs +++ b/naga/src/back/pipeline_constants.rs @@ -882,6 +882,17 @@ fn adjust_stmt(new_pos: &HandleVec>, stmt: &mut S adjust(&mut data.pointer); adjust(&mut data.stride); } + Statement::RayPipelineFunction(ref mut func) => match *func { + crate::RayPipelineFunction::TraceRay { + ref mut acceleration_structure, + ref mut descriptor, + ref mut payload, + } => { + adjust(acceleration_structure); + adjust(descriptor); + adjust(payload); + } + }, Statement::Break | Statement::Continue | Statement::Kill diff --git a/naga/src/back/spv/block.rs b/naga/src/back/spv/block.rs index aa4737281..2e1450a75 100644 --- a/naga/src/back/spv/block.rs +++ b/naga/src/back/spv/block.rs @@ -4194,6 +4194,7 @@ impl BlockContext<'_> { } }; } + Statement::RayPipelineFunction(_) => unreachable!(), } } diff --git a/naga/src/back/spv/helpers.rs b/naga/src/back/spv/helpers.rs index dc865308d..3adf1e1f2 100644 --- a/naga/src/back/spv/helpers.rs +++ b/naga/src/back/spv/helpers.rs @@ -56,6 +56,7 @@ pub(super) const fn map_storage_class(space: crate::AddressSpace) -> spirv::Stor crate::AddressSpace::WorkGroup => spirv::StorageClass::Workgroup, crate::AddressSpace::Immediate => spirv::StorageClass::PushConstant, crate::AddressSpace::TaskPayload => spirv::StorageClass::TaskPayloadWorkgroupEXT, + crate::AddressSpace::IncomingRayPayload | crate::AddressSpace::RayPayload => unreachable!(), } } diff --git a/naga/src/back/spv/writer.rs b/naga/src/back/spv/writer.rs index ad8df39a1..ba4ac1406 100644 --- a/naga/src/back/spv/writer.rs +++ b/naga/src/back/spv/writer.rs @@ -1819,6 +1819,10 @@ impl Writer { .to_words(&mut self.logical_layout.execution_modes); spirv::ExecutionModel::MeshEXT } + crate::ShaderStage::RayGeneration + | crate::ShaderStage::AnyHit + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::Miss => unreachable!(), }; //self.check(exec_model.required_capabilities())?; @@ -3174,6 +3178,19 @@ impl Writer { Bi::VertexCount | Bi::Vertices | Bi::PrimitiveCount | Bi::Primitives => { unreachable!() } + Bi::RayInvocationId + | Bi::NumRayInvocations + | Bi::InstanceCustomData + | Bi::GeometryIndex + | Bi::WorldRayOrigin + | Bi::WorldRayDirection + | Bi::ObjectRayOrigin + | Bi::ObjectRayDirection + | Bi::RayTmin + | Bi::RayTCurrentMax + | Bi::ObjectToWorld + | Bi::WorldToObject + | Bi::HitKind => unreachable!(), }; use crate::ScalarKind as Sk; diff --git a/naga/src/back/wgsl/writer.rs b/naga/src/back/wgsl/writer.rs index a57ca5a6f..ffeece59b 100644 --- a/naga/src/back/wgsl/writer.rs +++ b/naga/src/back/wgsl/writer.rs @@ -243,6 +243,10 @@ impl Writer { Attribute::WorkGroupSize(ep.workgroup_size), ] } + ShaderStage::RayGeneration + | ShaderStage::AnyHit + | ShaderStage::ClosestHit + | ShaderStage::Miss => unreachable!(), }; self.write_attributes(&attributes)?; // Add a newline after attribute @@ -488,6 +492,10 @@ impl Writer { ShaderStage::Task => "task", //Handled by another variant in the Attribute enum, so this code should never be hit. ShaderStage::Mesh => unreachable!(), + ShaderStage::RayGeneration + | ShaderStage::AnyHit + | ShaderStage::ClosestHit + | ShaderStage::Miss => unreachable!(), }; write!(self.out, "@{stage_str} ")?; @@ -1086,6 +1094,7 @@ impl Writer { self.write_expr(module, data.stride, func_ctx)?; writeln!(self.out, ");")? } + Statement::RayPipelineFunction(_) => unreachable!(), } Ok(()) diff --git a/naga/src/common/wgsl/to_wgsl.rs b/naga/src/common/wgsl/to_wgsl.rs index c434c6577..c59a5d954 100644 --- a/naga/src/common/wgsl/to_wgsl.rs +++ b/naga/src/common/wgsl/to_wgsl.rs @@ -200,7 +200,20 @@ impl TryToWgsl for crate::BuiltIn { | Bi::PointSize | Bi::DrawID | Bi::PointCoord - | Bi::WorkGroupSize => return None, + | Bi::WorkGroupSize + | Bi::RayInvocationId + | Bi::NumRayInvocations + | Bi::InstanceCustomData + | Bi::GeometryIndex + | Bi::WorldRayOrigin + | Bi::WorldRayDirection + | Bi::ObjectRayOrigin + | Bi::ObjectRayDirection + | Bi::RayTmin + | Bi::RayTCurrentMax + | Bi::ObjectToWorld + | Bi::WorldToObject + | Bi::HitKind => return None, }) } } @@ -374,6 +387,7 @@ pub const fn address_space_str( As::Handle => return (None, None), As::Function => "function", As::TaskPayload => "task_payload", + As::IncomingRayPayload | As::RayPayload => return (None, None), }), None, ) diff --git a/naga/src/compact/statements.rs b/naga/src/compact/statements.rs index af72cb872..4b9dd13c8 100644 --- a/naga/src/compact/statements.rs +++ b/naga/src/compact/statements.rs @@ -157,6 +157,17 @@ impl FunctionTracer<'_> { self.expressions_used.insert(data.pointer); self.expressions_used.insert(data.stride); } + St::RayPipelineFunction(func) => match func { + crate::RayPipelineFunction::TraceRay { + acceleration_structure, + descriptor, + payload, + } => { + self.expressions_used.insert(acceleration_structure); + self.expressions_used.insert(descriptor); + self.expressions_used.insert(payload); + } + }, // Trivial statements. St::Break @@ -384,6 +395,17 @@ impl FunctionMap { adjust(&mut data.pointer); adjust(&mut data.stride); } + St::RayPipelineFunction(ref mut func) => match *func { + crate::RayPipelineFunction::TraceRay { + ref mut acceleration_structure, + ref mut descriptor, + ref mut payload, + } => { + adjust(acceleration_structure); + adjust(descriptor); + adjust(payload); + } + }, // Trivial statements. St::Break diff --git a/naga/src/front/glsl/functions.rs b/naga/src/front/glsl/functions.rs index 3c22e46f3..b26061cec 100644 --- a/naga/src/front/glsl/functions.rs +++ b/naga/src/front/glsl/functions.rs @@ -1377,6 +1377,7 @@ impl Frontend { }, mesh_info: None, task_payload: None, + incoming_ray_payload: None, }); Ok(()) diff --git a/naga/src/front/spv/function.rs b/naga/src/front/spv/function.rs index 6b247a788..df96dc460 100644 --- a/naga/src/front/spv/function.rs +++ b/naga/src/front/spv/function.rs @@ -610,6 +610,7 @@ impl> super::Frontend { function, mesh_info: None, task_payload: None, + incoming_ray_payload: None, }); Ok(()) diff --git a/naga/src/front/spv/mod.rs b/naga/src/front/spv/mod.rs index 963548a96..136e7eb3e 100644 --- a/naga/src/front/spv/mod.rs +++ b/naga/src/front/spv/mod.rs @@ -1612,7 +1612,8 @@ impl> Frontend { | S::RayQuery { .. } | S::SubgroupBallot { .. } | S::SubgroupCollectiveOperation { .. } - | S::SubgroupGather { .. } => {} + | S::SubgroupGather { .. } + | S::RayPipelineFunction(..) => {} S::Call { function: ref mut callee, ref arguments, diff --git a/naga/src/front/wgsl/error.rs b/naga/src/front/wgsl/error.rs index 936e3236f..24e1ee6a6 100644 --- a/naga/src/front/wgsl/error.rs +++ b/naga/src/front/wgsl/error.rs @@ -434,6 +434,7 @@ pub(crate) enum Error<'a> { description: &'static str, }, UnexpectedExprForTypeExpression(Span), + MissingIncomingPayload(Span), } impl From for Error<'_> { @@ -1473,7 +1474,15 @@ impl<'a> Error<'a> { message: "unexpected expression".to_string(), labels: vec![(expr_span, "needs to be an identifier resolving to a type declaration (alias or struct) or predeclared type(-generator)".into())], notes: vec![], - } + }, + Error::MissingIncomingPayload(span) => ParseError { + message: "incoming payload is missing on a `closest_hit`, `any_hit` or `miss` shader entry point".to_string(), + labels: vec![( + span, + "must be paired with a `@incoming_payload` attribute".into(), + )], + notes: vec![], + }, } } } diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index 705ecd4de..0ad3624c3 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -1701,6 +1701,21 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { None }; + let incoming_ray_payload = + if let Some((var_name, var_span)) = entry.ray_incoming_payload { + Some(match ctx.globals.get(var_name) { + Some(&LoweredGlobalDecl::Var(handle)) => handle, + Some(_) => { + return Err(Box::new(Error::ExpectedGlobalVariable { + name_span: var_span, + })) + } + None => return Err(Box::new(Error::UnknownIdent(var_span, var_name))), + }) + } else { + None + }; + ctx.module.entry_points.push(ir::EntryPoint { name: f.name.name.to_string(), stage: entry.stage, @@ -1710,6 +1725,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { function, mesh_info, task_payload, + incoming_ray_payload, }); Ok(LoweredGlobalDecl::EntryPoint( ctx.module.entry_points.len() - 1, @@ -3687,6 +3703,28 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { ir::Expression::CooperativeMultiplyAdd { a, b, c } } + "traceRay" => { + let mut args = ctx.prepare_args(arguments, 3, function_span); + let acceleration_structure = self.expression(args.next()?, ctx)?; + let descriptor = self.expression(args.next()?, ctx)?; + let payload = self.expression(args.next()?, ctx)?; + args.finish()?; + + let _ = ctx.module.generate_ray_desc_type(); + let fun = ir::RayPipelineFunction::TraceRay { + acceleration_structure, + descriptor, + payload, + }; + + let rctx = ctx.runtime_expression_ctx(function_span)?; + rctx.block + .extend(rctx.emitter.finish(&rctx.function.expressions)); + rctx.emitter.start(&rctx.function.expressions); + rctx.block + .push(ir::Statement::RayPipelineFunction(fun), function_span); + return Ok(None); + } _ => return Err(Box::new(Error::UnknownIdent(function_span, function_name))), } }; diff --git a/naga/src/front/wgsl/parse/ast.rs b/naga/src/front/wgsl/parse/ast.rs index 2ef96b5fd..f6a45d595 100644 --- a/naga/src/front/wgsl/parse/ast.rs +++ b/naga/src/front/wgsl/parse/ast.rs @@ -220,6 +220,7 @@ pub struct EntryPoint<'a> { pub workgroup_size: Option<[Option>>; 3]>, pub mesh_output_variable: Option<(&'a str, Span)>, pub task_payload: Option<(&'a str, Span)>, + pub ray_incoming_payload: Option<(&'a str, Span)>, } #[cfg(doc)] diff --git a/naga/src/front/wgsl/parse/conv.rs b/naga/src/front/wgsl/parse/conv.rs index ccd806f69..d951ab0b0 100644 --- a/naga/src/front/wgsl/parse/conv.rs +++ b/naga/src/front/wgsl/parse/conv.rs @@ -30,6 +30,26 @@ pub fn map_address_space<'a>( })) } } + "ray_payload" => { + if enable_extensions.contains(ImplementedEnableExtension::WgpuRayTracingPipeline) { + Ok(crate::AddressSpace::RayPayload) + } else { + Err(Box::new(Error::EnableExtensionNotEnabled { + span, + kind: ImplementedEnableExtension::WgpuRayTracingPipeline.into(), + })) + } + } + "incoming_ray_payload" => { + if enable_extensions.contains(ImplementedEnableExtension::WgpuRayTracingPipeline) { + Ok(crate::AddressSpace::IncomingRayPayload) + } else { + Err(Box::new(Error::EnableExtensionNotEnabled { + span, + kind: ImplementedEnableExtension::WgpuRayTracingPipeline.into(), + })) + } + } _ => Err(Box::new(Error::UnknownAddressSpace(span))), } } @@ -116,6 +136,20 @@ pub fn map_built_in( "vertices" => crate::BuiltIn::Vertices, "primitive_count" => crate::BuiltIn::PrimitiveCount, "primitives" => crate::BuiltIn::Primitives, + // ray tracing pipeline + "ray_invocation_id" => crate::BuiltIn::RayInvocationId, + "num_ray_invocations" => crate::BuiltIn::NumRayInvocations, + "instance_custom_data" => crate::BuiltIn::InstanceCustomData, + "geometry_index" => crate::BuiltIn::GeometryIndex, + "world_ray_origin" => crate::BuiltIn::WorldRayOrigin, + "world_ray_direction" => crate::BuiltIn::WorldRayDirection, + "object_ray_origin" => crate::BuiltIn::ObjectRayOrigin, + "object_ray_direction" => crate::BuiltIn::ObjectRayDirection, + "ray_t_min" => crate::BuiltIn::RayTmin, + "ray_t_current_max" => crate::BuiltIn::RayTCurrentMax, + "object_to_world" => crate::BuiltIn::ObjectToWorld, + "world_to_object" => crate::BuiltIn::WorldToObject, + "hit_kind" => crate::BuiltIn::HitKind, _ => return Err(Box::new(Error::UnknownBuiltin(span))), }; match built_in { @@ -536,26 +570,34 @@ pub fn map_predeclared_type( }; // Check for the enable extension required to use this type, if any. - let extension_needed = match ty { + // Slice should be at least len one otherwise extension_needed should be None. + let extensions_needed: Option<&[_]> = match ty { PredeclaredType::TypeInner(ref ty) if ty.scalar() == Some(Sc::F16) => { - Some(ImplementedEnableExtension::F16) + Some(&[ImplementedEnableExtension::F16]) } PredeclaredType::RayDesc | PredeclaredType::RayIntersection | PredeclaredType::TypeGenerator(TypeGenerator::AccelerationStructure) - | PredeclaredType::TypeGenerator(TypeGenerator::RayQuery) => { - Some(ImplementedEnableExtension::WgpuRayQuery) - } + | PredeclaredType::TypeGenerator(TypeGenerator::RayQuery) => Some(&[ + ImplementedEnableExtension::WgpuRayQuery, + ImplementedEnableExtension::WgpuRayTracingPipeline, + ]), PredeclaredType::TypeGenerator(TypeGenerator::CooperativeMatrix { .. }) => { - Some(ImplementedEnableExtension::WgpuCooperativeMatrix) + Some(&[ImplementedEnableExtension::WgpuCooperativeMatrix]) } _ => None, }; - if let Some(extension_needed) = extension_needed { - if !enable_extensions.contains(extension_needed) { + if let Some(extensions_needed) = extensions_needed { + let mut any_extension_enabled = false; + for extension_needed in extensions_needed { + if enable_extensions.contains(*extension_needed) { + any_extension_enabled = true; + } + } + if !any_extension_enabled { return Err(Box::new(Error::EnableExtensionNotEnabled { span, - kind: extension_needed.into(), + kind: extensions_needed[0].into(), })); } } diff --git a/naga/src/front/wgsl/parse/directive/enable_extension.rs b/naga/src/front/wgsl/parse/directive/enable_extension.rs index 927290884..ebea5e2b3 100644 --- a/naga/src/front/wgsl/parse/directive/enable_extension.rs +++ b/naga/src/front/wgsl/parse/directive/enable_extension.rs @@ -13,6 +13,7 @@ pub(crate) struct EnableExtensions { wgpu_mesh_shader: bool, wgpu_ray_query: bool, wgpu_ray_query_vertex_return: bool, + wgpu_ray_tracing_pipelines: bool, dual_source_blending: bool, /// Whether `enable f16;` was written earlier in the shader module. f16: bool, @@ -26,6 +27,7 @@ impl EnableExtensions { wgpu_mesh_shader: false, wgpu_ray_query: false, wgpu_ray_query_vertex_return: false, + wgpu_ray_tracing_pipelines: false, f16: false, dual_source_blending: false, clip_distances: false, @@ -41,6 +43,9 @@ impl EnableExtensions { ImplementedEnableExtension::WgpuRayQueryVertexReturn => { &mut self.wgpu_ray_query_vertex_return } + ImplementedEnableExtension::WgpuRayTracingPipeline => { + &mut self.wgpu_ray_tracing_pipelines + } ImplementedEnableExtension::DualSourceBlending => &mut self.dual_source_blending, ImplementedEnableExtension::F16 => &mut self.f16, ImplementedEnableExtension::ClipDistances => &mut self.clip_distances, @@ -57,6 +62,7 @@ impl EnableExtensions { ImplementedEnableExtension::WgpuRayQueryVertexReturn => { self.wgpu_ray_query_vertex_return } + ImplementedEnableExtension::WgpuRayTracingPipeline => self.wgpu_ray_tracing_pipelines, ImplementedEnableExtension::DualSourceBlending => self.dual_source_blending, ImplementedEnableExtension::F16 => self.f16, ImplementedEnableExtension::ClipDistances => self.clip_distances, @@ -93,6 +99,7 @@ impl EnableExtension { const MESH_SHADER: &'static str = "wgpu_mesh_shader"; const RAY_QUERY: &'static str = "wgpu_ray_query"; const RAY_QUERY_VERTEX_RETURN: &'static str = "wgpu_ray_query_vertex_return"; + const RAY_TRACING_PIPELINE: &'static str = "wgpu_ray_tracing_pipeline"; const COOPERATIVE_MATRIX: &'static str = "wgpu_cooperative_matrix"; const SUBGROUPS: &'static str = "subgroups"; const PRIMITIVE_INDEX: &'static str = "primitive_index"; @@ -110,6 +117,9 @@ impl EnableExtension { Self::RAY_QUERY_VERTEX_RETURN => { Self::Implemented(ImplementedEnableExtension::WgpuRayQueryVertexReturn) } + Self::RAY_TRACING_PIPELINE => { + Self::Implemented(ImplementedEnableExtension::WgpuRayTracingPipeline) + } Self::COOPERATIVE_MATRIX => { Self::Implemented(ImplementedEnableExtension::WgpuCooperativeMatrix) } @@ -134,6 +144,7 @@ impl EnableExtension { ImplementedEnableExtension::DualSourceBlending => Self::DUAL_SOURCE_BLENDING, ImplementedEnableExtension::F16 => Self::F16, ImplementedEnableExtension::ClipDistances => Self::CLIP_DISTANCES, + ImplementedEnableExtension::WgpuRayTracingPipeline => Self::RAY_TRACING_PIPELINE, }, Self::Unimplemented(kind) => match kind { UnimplementedEnableExtension::Subgroups => Self::SUBGROUPS, @@ -170,6 +181,8 @@ pub enum ImplementedEnableExtension { WgpuRayQuery, /// Enables the `wgpu_ray_query_vertex_return` extension, native only. WgpuRayQueryVertexReturn, + /// Enables the `wgpu_ray_tracing_pipeline` extension, native only. + WgpuRayTracingPipeline, /// Enables the `wgpu_cooperative_matrix` extension, native only. WgpuCooperativeMatrix, } diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index 7a3e92234..67a838a9f 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -1821,13 +1821,18 @@ impl Parser { // read attributes let mut binding = None; let mut stage = ParsedAttribute::default(); - let mut compute_like_span = Span::new(0, 0); + // Span in case we need to report an error for a shader stage missing something (e.g. its workgroup size). + // Doesn't need to be set in the vertex and fragment stages because they don't have errors like that. + let mut shader_stage_error_span = Span::new(0, 0); let mut workgroup_size = ParsedAttribute::default(); let mut early_depth_test = ParsedAttribute::default(); let (mut bind_index, mut bind_group) = (ParsedAttribute::default(), ParsedAttribute::default()); let mut id = ParsedAttribute::default(); + // the payload variable for a mesh shader let mut payload = ParsedAttribute::default(); + // the incoming payload from a traceRay call + let mut incoming_payload = ParsedAttribute::default(); let mut mesh_output = ParsedAttribute::default(); let mut must_use: ParsedAttribute = ParsedAttribute::default(); @@ -1886,7 +1891,7 @@ impl Parser { } "compute" => { stage.set(ShaderStage::Compute, name_span)?; - compute_like_span = name_span; + shader_stage_error_span = name_span; } "task" => { lexer.require_enable_extension( @@ -1894,7 +1899,7 @@ impl Parser { name_span, )?; stage.set(ShaderStage::Task, name_span)?; - compute_like_span = name_span; + shader_stage_error_span = name_span; } "mesh" => { lexer.require_enable_extension( @@ -1902,12 +1907,44 @@ impl Parser { name_span, )?; stage.set(ShaderStage::Mesh, name_span)?; - compute_like_span = name_span; + shader_stage_error_span = name_span; lexer.expect(Token::Paren('('))?; mesh_output.set(lexer.next_ident_with_span()?, name_span)?; lexer.expect(Token::Paren(')'))?; } + "ray_generation" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuRayTracingPipeline, + name_span, + )?; + stage.set(ShaderStage::RayGeneration, name_span)?; + shader_stage_error_span = name_span; + } + "any_hit" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuRayTracingPipeline, + name_span, + )?; + stage.set(ShaderStage::AnyHit, name_span)?; + shader_stage_error_span = name_span; + } + "closest_hit" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuRayTracingPipeline, + name_span, + )?; + stage.set(ShaderStage::ClosestHit, name_span)?; + shader_stage_error_span = name_span; + } + "miss" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuRayTracingPipeline, + name_span, + )?; + stage.set(ShaderStage::Miss, name_span)?; + shader_stage_error_span = name_span; + } "payload" => { lexer.require_enable_extension( ImplementedEnableExtension::WgpuMeshShader, @@ -1917,6 +1954,15 @@ impl Parser { payload.set(lexer.next_ident_with_span()?, name_span)?; lexer.expect(Token::Paren(')'))?; } + "incoming_payload" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuRayTracingPipeline, + name_span, + )?; + lexer.expect(Token::Paren('('))?; + incoming_payload.set(lexer.next_ident_with_span()?, name_span)?; + lexer.expect(Token::Paren(')'))?; + } "workgroup_size" => { lexer.expect(Token::Paren('('))?; let mut new_workgroup_size = [None; 3]; @@ -2069,7 +2115,20 @@ impl Parser { Some(ast::GlobalDeclKind::Fn(ast::Function { entry_point: if let Some(stage) = stage.value { if stage.compute_like() && workgroup_size.value.is_none() { - return Err(Box::new(Error::MissingWorkgroupSize(compute_like_span))); + return Err(Box::new(Error::MissingWorkgroupSize( + shader_stage_error_span, + ))); + } + + match stage { + ShaderStage::AnyHit | ShaderStage::ClosestHit | ShaderStage::Miss => { + if incoming_payload.value.is_none() { + return Err(Box::new(Error::MissingIncomingPayload( + shader_stage_error_span, + ))); + } + } + _ => {} } Some(ast::EntryPoint { @@ -2078,6 +2137,7 @@ impl Parser { workgroup_size: workgroup_size.value, mesh_output_variable: mesh_output.value, task_payload: payload.value, + ray_incoming_payload: incoming_payload.value, }) } else { None diff --git a/naga/src/ir/mod.rs b/naga/src/ir/mod.rs index adf22ca67..70623b4d1 100644 --- a/naga/src/ir/mod.rs +++ b/naga/src/ir/mod.rs @@ -335,6 +335,18 @@ pub enum ShaderStage { /// Compute pipeline shader. Compute, + + /// A ray generation shader, in a ray tracing pipeline. + RayGeneration, + + /// A miss shader, in a ray tracing pipeline. + Miss, + + /// A any hit shader, in a ray tracing pipeline. + AnyHit, + + /// A closest hit shader, in a ray tracing pipeline. + ClosestHit, } /// Addressing space of variables. @@ -373,6 +385,14 @@ pub enum AddressSpace { Immediate, /// Task shader to mesh shader payload TaskPayload, + + /// Ray tracing payload, for inputting in TraceRays + RayPayload, + /// Ray tracing payload, for entrypoints invoked by a TraceRays call + /// + /// Each entrypoint may reference only one variable in this scope, as + /// only one may be passed as a payload. + IncomingRayPayload, } /// Built-in inputs and outputs. @@ -394,7 +414,7 @@ pub enum BuiltIn { ClipDistance, /// Written in vertex & mesh shaders CullDistance, - /// Read in vertex shaders + /// Read in vertex, any- and closest-hit shaders InstanceIndex, /// Written in vertex & mesh shaders PointSize, @@ -409,7 +429,7 @@ pub enum BuiltIn { PointCoord, /// Read in fragment shaders FrontFacing, - /// Read in fragment shaders, written in mesh shaders + /// Read in fragment shaders, written in mesh shaders, read in any and closest hit shaders. PrimitiveIndex, /// Read in fragment shaders Barycentric { perspective: bool }, @@ -459,6 +479,46 @@ pub enum BuiltIn { PrimitiveCount, /// Written to a workgroup variable in mesh shaders Primitives, + + /// Read in all ray tracing pipeline shaders, the id within the number of + /// rays that this current ray is. + RayInvocationId, + /// Read in all ray tracing pipeline shaders, the number of rays created. + NumRayInvocations, + /// Read in closest hit and any hit shaders, the custom data in the tlas + /// instance + InstanceCustomData, + /// Read in closest hit and any hit shaders, the index of the geometry in + /// the blas. + GeometryIndex, + /// Read in closest hit, any hit, and miss shaders, the origin of the ray. + WorldRayOrigin, + /// Read in closest hit, any hit, and miss shaders, the direction of the + /// ray. + WorldRayDirection, + /// Read in closest hit and any hit shaders, the direction of the ray in + /// object space. + ObjectRayOrigin, + /// Read in closest hit and any hit shaders, the direction of the ray in + /// object space. + ObjectRayDirection, + /// Read in closest hit, any hit, and miss shaders, the t min provided by + /// in the ray desc. + RayTmin, + /// Read in closest hit, any hit, and miss shaders, the final bounds at which + /// a hit is accepted (the closest committed hit if there is one otherwise, t + /// max provided in the ray desc). + RayTCurrentMax, + /// Read in closest hit and any hit shaders, the matrix for converting from + /// object space to world space + ObjectToWorld, + /// Read in closest hit and any hit shaders, the matrix for converting from + /// world space to object space + WorldToObject, + /// Read in closest hit and any hit shaders, the type of hit as provided by + /// the intersection function if any, otherwise this is 254 (0xFE) for a + /// front facing triangle and 255 (0xFF) for a back facing triangle + HitKind, } /// Number of bytes per scalar. @@ -2278,6 +2338,8 @@ pub enum Statement { /// The specific operation we're performing on `query`. fun: RayQueryFunction, }, + /// A ray tracing pipeline shader intrinsic. + RayPipelineFunction(RayPipelineFunction), /// Calculate a bitmask using a boolean from each active thread in the subgroup SubgroupBallot { /// The [`SubgroupBallotResult`] expression representing this load's result. @@ -2462,6 +2524,9 @@ pub struct EntryPoint { pub mesh_info: Option, /// The unique global variable used as a task payload from task shader to mesh shader pub task_payload: Option>, + /// The unique global variable used as an incoming ray payload going into any hit, closest hit and miss shaders. + /// Unlike the outgoing ray payload, an incoming ray payload must be unique + pub incoming_ray_payload: Option>, } /// Return types predeclared for the frexp, modf, and atomicCompareExchangeWeak built-in functions. @@ -2677,6 +2742,36 @@ pub struct MeshStageInfo { pub output_variable: Handle, } +/// Ray tracing pipeline intrinsics +#[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(Serialize))] +#[cfg_attr(feature = "deserialize", derive(Deserialize))] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +pub enum RayPipelineFunction { + /// Traces a ray through the given acceleration structure + TraceRay { + /// The acceleration structure within which this ray should search for hits. + /// + /// The expression must be an [`AccelerationStructure`]. + /// + /// [`AccelerationStructure`]: TypeInner::AccelerationStructure + acceleration_structure: Handle, + + #[allow(rustdoc::private_intra_doc_links)] + /// A struct of detailed parameters for the ray query. + /// + /// This expression should have the struct type given in + /// [`SpecialTypes::ray_desc`]. This is available in the WGSL + /// front end as the `RayDesc` type. + descriptor: Handle, + + /// A pointer in the ray_payload or incoming_ray_payload address spaces + payload: Handle, + // Do we want miss index? What about sbt offset and sbt stride (could be hard to validate)? + // https://github.com/gfx-rs/wgpu/issues/8894 + }, +} + /// Shader module. /// /// A module is a set of constants, global variables and functions, as well as diff --git a/naga/src/proc/mod.rs b/naga/src/proc/mod.rs index 832abc9ac..689351916 100644 --- a/naga/src/proc/mod.rs +++ b/naga/src/proc/mod.rs @@ -212,6 +212,9 @@ impl super::AddressSpace { // TaskPayload isn't always writable, but this is checked for elsewhere, // when not using multiple payloads and matching the entry payload is checked. crate::AddressSpace::TaskPayload => Sa::LOAD | Sa::STORE, + crate::AddressSpace::RayPayload | crate::AddressSpace::IncomingRayPayload => { + Sa::LOAD | Sa::STORE + } } } } @@ -662,6 +665,7 @@ impl super::ShaderStage { match self { Self::Vertex | Self::Fragment => false, Self::Compute | Self::Task | Self::Mesh => true, + Self::RayGeneration | Self::AnyHit | Self::ClosestHit | Self::Miss => false, } } } diff --git a/naga/src/proc/namer.rs b/naga/src/proc/namer.rs index fb0135946..388003e0f 100644 --- a/naga/src/proc/namer.rs +++ b/naga/src/proc/namer.rs @@ -262,7 +262,12 @@ impl Namer { crate::ShaderStage::Vertex => "VertexOutput", crate::ShaderStage::Fragment => "FragmentOutput", crate::ShaderStage::Compute => "ComputeOutput", - crate::ShaderStage::Task | crate::ShaderStage::Mesh => unreachable!(), + crate::ShaderStage::Task + | crate::ShaderStage::Mesh + | crate::ShaderStage::RayGeneration + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::AnyHit + | crate::ShaderStage::Miss => unreachable!(), }; entrypoint_type_fallbacks.insert(result.ty, label); } diff --git a/naga/src/proc/terminator.rs b/naga/src/proc/terminator.rs index 6ffd81593..3e3e32f5c 100644 --- a/naga/src/proc/terminator.rs +++ b/naga/src/proc/terminator.rs @@ -44,7 +44,8 @@ pub fn ensure_block_returns(block: &mut crate::Block) { | S::SubgroupGather { .. } | S::ControlBarrier(_) | S::MemoryBarrier(_) - | S::CooperativeStore { .. }), + | S::CooperativeStore { .. } + | S::RayPipelineFunction(_)), ) | None => block.push(S::Return { value: None }, Default::default()), } diff --git a/naga/src/valid/analyzer.rs b/naga/src/valid/analyzer.rs index 47f35eca1..6ffb23add 100644 --- a/naga/src/valid/analyzer.rs +++ b/naga/src/valid/analyzer.rs @@ -653,7 +653,7 @@ impl FunctionInfo { let var = &resolve_context.global_vars[gh]; let uniform = match var.space { // local data is non-uniform - As::Function | As::Private => false, + As::Function | As::Private | As::RayPayload | As::IncomingRayPayload => false, // workgroup memory is exclusively accessed by the group // task payload memory is very similar to workgroup memory As::WorkGroup | As::TaskPayload => true, @@ -1190,6 +1190,20 @@ impl FunctionInfo { }, exit: ExitFlags::empty(), }, + S::RayPipelineFunction(ref fun) => { + match *fun { + crate::RayPipelineFunction::TraceRay { + acceleration_structure, + descriptor, + payload, + } => { + let _ = self.add_ref(acceleration_structure); + let _ = self.add_ref(descriptor); + let _ = self.add_ref(payload); + } + } + FunctionUniformity::new() + } }; disruptor = disruptor.or(uniformity.exit_disruptor()); diff --git a/naga/src/valid/function.rs b/naga/src/valid/function.rs index 160a067b6..a03564c00 100644 --- a/naga/src/valid/function.rs +++ b/naga/src/valid/function.rs @@ -228,6 +228,12 @@ pub enum FunctionError { ConflictingTaskPayloadVariables(Handle, Handle), #[error("Mesh shader output at {0:?} is not a user-defined struct")] InvalidMeshShaderOutputType(Handle), + #[error("The payload type passed to `traceRay` must be a pointer")] + InvalidPayloadType, + #[error("The payload type passed to `traceRay` must be a pointer with an address space of `ray_payload` or `incoming_ray_payload`, instead got {0:?}")] + InvalidPayloadAddressSpace(crate::AddressSpace), + #[error("The payload type ({0:?}) passed to `traceRay` does not match the previous one {1:?}")] + MismatchedPayloadType(Handle, Handle), } bitflags::bitflags! { @@ -1678,6 +1684,81 @@ impl super::Validator { )); } } + S::RayPipelineFunction(ref fun) => match *fun { + crate::RayPipelineFunction::TraceRay { + acceleration_structure, + descriptor, + payload, + } => { + match *context.resolve_type_inner( + acceleration_structure, + &self.valid_expression_set, + )? { + crate::TypeInner::AccelerationStructure { vertex_return } => { + if !vertex_return { + self.trace_rays_vertex_return = + super::TraceRayVertexReturnState::NoVertexReturn(span); + } else if let super::TraceRayVertexReturnState::NoTraceRays = + self.trace_rays_vertex_return + { + self.trace_rays_vertex_return = + super::TraceRayVertexReturnState::VertexReturn; + } + } + _ => { + return Err(FunctionError::InvalidAccelerationStructure( + acceleration_structure, + ) + .with_span_handle(acceleration_structure, context.expressions)) + } + } + + let current_payload_ty = match *context + .resolve_type_inner(payload, &self.valid_expression_set)? + { + crate::TypeInner::Pointer { base, space } => { + match space { + AddressSpace::RayPayload | AddressSpace::IncomingRayPayload => { + } + space => { + return Err(FunctionError::InvalidPayloadAddressSpace( + space, + ) + .with_span_handle(payload, context.expressions)) + } + } + base + } + _ => { + return Err(FunctionError::InvalidPayloadType + .with_span_handle(payload, context.expressions)) + } + }; + + let ty = *self + .trace_rays_payload_type + .get_or_insert(current_payload_ty); + + if ty != current_payload_ty { + return Err(FunctionError::MismatchedPayloadType( + current_payload_ty, + ty, + ) + .with_span_handle(ty, context.types)); + } + + let desc_ty_given = + context.resolve_type_inner(descriptor, &self.valid_expression_set)?; + let desc_ty_expected = context + .special_types + .ray_desc + .map(|handle| &context.types[handle].inner); + if Some(desc_ty_given) != desc_ty_expected { + return Err(FunctionError::InvalidRayDescriptor(descriptor) + .with_span_static(span, "invalid ray descriptor")); + } + } + }, } } Ok(BlockInfo { stages }) diff --git a/naga/src/valid/handles.rs b/naga/src/valid/handles.rs index a7fd4c553..fd0b4ed8d 100644 --- a/naga/src/valid/handles.rs +++ b/naga/src/valid/handles.rs @@ -863,6 +863,18 @@ impl super::Validator { validate_expr(data.stride)?; Ok(()) } + crate::Statement::RayPipelineFunction(fun) => match fun { + crate::RayPipelineFunction::TraceRay { + acceleration_structure, + descriptor, + payload, + } => { + validate_expr(acceleration_structure)?; + validate_expr(descriptor)?; + validate_expr(payload)?; + Ok(()) + } + }, crate::Statement::Break | crate::Statement::Continue | crate::Statement::Kill diff --git a/naga/src/valid/interface.rs b/naga/src/valid/interface.rs index 51b5f8357..ceddbe524 100644 --- a/naga/src/valid/interface.rs +++ b/naga/src/valid/interface.rs @@ -170,6 +170,10 @@ pub enum EntryPointError { WrongMeshOutputAddressSpace, #[error("Task payload must be at least 4 bytes, but is {0} bytes")] TaskPayloadTooSmall(u32), + #[error("Only the `ray_generation`, `closest_hit`, and `any_hit` shader stages can access a global variable in the `ray_payload` address space")] + RayPayloadInInvalidStage(crate::ShaderStage), + #[error("Only the `closest_hit`, `any_hit`, and `miss` shader stages can access a global variable in the `incoming_ray_payload` address space")] + IncomingRayPayloadInInvalidStage(crate::ShaderStage), } fn storage_usage(access: crate::StorageAccess) -> GlobalUse { @@ -239,7 +243,10 @@ impl VaryingContext<'_> { let required = match built_in { Bi::ClipDistance => Capabilities::CLIP_DISTANCE, Bi::CullDistance => Capabilities::CULL_DISTANCE, - Bi::PrimitiveIndex => Capabilities::PRIMITIVE_INDEX, + // Primitive index is allowed w/o any other extensions in any- and closest-hit shaders + Bi::PrimitiveIndex if !matches!(ep.stage, St::AnyHit | St::ClosestHit) => { + Capabilities::PRIMITIVE_INDEX + } Bi::Barycentric { .. } => Capabilities::SHADER_BARYCENTRICS, Bi::ViewIndex => Capabilities::MULTIVIEW, Bi::SampleIndex => Capabilities::MULTISAMPLED_SHADING, @@ -262,10 +269,15 @@ impl VaryingContext<'_> { } let (visible, type_good) = match built_in { - Bi::BaseInstance | Bi::BaseVertex | Bi::InstanceIndex | Bi::VertexIndex => ( + Bi::BaseInstance | Bi::BaseVertex | Bi::VertexIndex => ( self.stage == St::Vertex && !self.output, *ty_inner == Ti::Scalar(crate::Scalar::U32), ), + Bi::InstanceIndex => ( + matches!(self.stage, St::Vertex | St::AnyHit | St::ClosestHit) + && !self.output, + *ty_inner == Ti::Scalar(crate::Scalar::U32), + ), Bi::DrawID => ( // Always allowed in task/vertex stage. Allowed in mesh stage if there is no task stage in the pipeline. (self.stage == St::Vertex @@ -304,6 +316,7 @@ impl VaryingContext<'_> { St::Vertex | St::Mesh => self.output, St::Fragment => !self.output, St::Compute | St::Task => false, + St::RayGeneration | St::AnyHit | St::ClosestHit | St::Miss => false, }, *ty_inner == Ti::Vector { @@ -314,7 +327,11 @@ impl VaryingContext<'_> { Bi::ViewIndex => ( match self.stage { St::Vertex | St::Fragment | St::Task | St::Mesh => !self.output, - St::Compute => false, + St::Compute + | St::RayGeneration + | St::AnyHit + | St::ClosestHit + | St::Miss => false, }, *ty_inner == Ti::Scalar(crate::Scalar::U32), ), @@ -327,7 +344,8 @@ impl VaryingContext<'_> { *ty_inner == Ti::Scalar(crate::Scalar::BOOL), ), Bi::PrimitiveIndex => ( - (self.stage == St::Fragment && !self.output) + (matches!(self.stage, St::Fragment | St::AnyHit | St::ClosestHit) + && !self.output) || (self.stage == St::Mesh && self.output && self.mesh_output_type == MeshOutputType::PrimitiveOutput), @@ -371,7 +389,14 @@ impl VaryingContext<'_> { ), Bi::SubgroupSize | Bi::SubgroupInvocationId => ( match self.stage { - St::Compute | St::Fragment | St::Task | St::Mesh => !self.output, + St::Compute + | St::Fragment + | St::Task + | St::Mesh + | St::RayGeneration + | St::AnyHit + | St::ClosestHit + | St::Miss => !self.output, St::Vertex => false, }, *ty_inner == Ti::Scalar(crate::Scalar::U32), @@ -408,6 +433,193 @@ impl VaryingContext<'_> { scalar: crate::Scalar::U32, }, ), + Bi::RayInvocationId => ( + match self.stage { + St::Vertex | St::Fragment | St::Compute | St::Mesh | St::Task => false, + St::RayGeneration | St::AnyHit | St::ClosestHit | St::Miss => true, + }, + *ty_inner + == Ti::Vector { + size: Vs::Tri, + scalar: crate::Scalar::U32, + }, + ), + Bi::NumRayInvocations => ( + match self.stage { + St::Vertex | St::Fragment | St::Compute | St::Mesh | St::Task => false, + St::RayGeneration | St::AnyHit | St::ClosestHit | St::Miss => true, + }, + *ty_inner + == Ti::Vector { + size: Vs::Tri, + scalar: crate::Scalar::U32, + }, + ), + Bi::InstanceCustomData => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner == Ti::Scalar(crate::Scalar::U32), + ), + Bi::GeometryIndex => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner == Ti::Scalar(crate::Scalar::U32), + ), + Bi::WorldRayOrigin => ( + match self.stage { + St::RayGeneration + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit | St::Miss => true, + }, + *ty_inner + == Ti::Vector { + size: Vs::Tri, + scalar: crate::Scalar::F32, + }, + ), + Bi::WorldRayDirection => ( + match self.stage { + St::RayGeneration + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit | St::Miss => true, + }, + *ty_inner + == Ti::Vector { + size: Vs::Tri, + scalar: crate::Scalar::F32, + }, + ), + Bi::ObjectRayOrigin => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner + == Ti::Vector { + size: Vs::Tri, + scalar: crate::Scalar::F32, + }, + ), + Bi::ObjectRayDirection => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner + == Ti::Vector { + size: Vs::Tri, + scalar: crate::Scalar::F32, + }, + ), + Bi::RayTmin => ( + match self.stage { + St::RayGeneration + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit | St::Miss => true, + }, + *ty_inner == Ti::Scalar(crate::Scalar::F32), + ), + Bi::RayTCurrentMax => ( + match self.stage { + St::RayGeneration + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit | St::Miss => true, + }, + *ty_inner == Ti::Scalar(crate::Scalar::F32), + ), + Bi::ObjectToWorld => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner + == Ti::Matrix { + columns: crate::VectorSize::Quad, + rows: crate::VectorSize::Tri, + scalar: crate::Scalar::F32, + }, + ), + Bi::WorldToObject => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner + == Ti::Matrix { + columns: crate::VectorSize::Quad, + rows: crate::VectorSize::Tri, + scalar: crate::Scalar::F32, + }, + ), + Bi::HitKind => ( + match self.stage { + St::RayGeneration + | St::Miss + | St::Vertex + | St::Fragment + | St::Compute + | St::Mesh + | St::Task => false, + St::AnyHit | St::ClosestHit => true, + }, + *ty_inner == Ti::Scalar(crate::Scalar::U32), + ), // Validated elsewhere, shouldn't be here Bi::VertexCount | Bi::PrimitiveCount | Bi::Vertices | Bi::Primitives => { (false, true) @@ -568,7 +780,12 @@ impl VaryingContext<'_> { let needs_interpolation = match self.stage { crate::ShaderStage::Vertex => self.output, crate::ShaderStage::Fragment => !self.output && !per_primitive, - crate::ShaderStage::Compute | crate::ShaderStage::Task => false, + crate::ShaderStage::Compute + | crate::ShaderStage::Task + | crate::ShaderStage::RayGeneration + | crate::ShaderStage::AnyHit + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::Miss => false, crate::ShaderStage::Mesh => self.output, }; @@ -868,6 +1085,17 @@ impl super::Validator { false, ) } + crate::AddressSpace::RayPayload | crate::AddressSpace::IncomingRayPayload => { + if !self + .capabilities + .contains(Capabilities::RAY_TRACING_PIPELINE) + { + return Err(GlobalVariableError::UnsupportedCapability( + Capabilities::RAY_TRACING_PIPELINE, + )); + } + (TypeFlags::DATA | TypeFlags::SIZED, false) + } }; if !type_info.flags.contains(required_type_flags) { @@ -973,14 +1201,28 @@ impl super::Validator { module: &crate::Module, mod_info: &ModuleInfo, ) -> Result> { - if matches!( - ep.stage, + match ep.stage { crate::ShaderStage::Task | crate::ShaderStage::Mesh - ) && !self.capabilities.contains(Capabilities::MESH_SHADER) - { - return Err( - EntryPointError::UnsupportedCapability(Capabilities::MESH_SHADER).with_span(), - ); + if !self.capabilities.contains(Capabilities::MESH_SHADER) => + { + return Err( + EntryPointError::UnsupportedCapability(Capabilities::MESH_SHADER).with_span(), + ); + } + crate::ShaderStage::RayGeneration + | crate::ShaderStage::AnyHit + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::Miss + if !self + .capabilities + .contains(Capabilities::RAY_TRACING_PIPELINE) => + { + return Err(EntryPointError::UnsupportedCapability( + Capabilities::RAY_TRACING_PIPELINE, + ) + .with_span()); + } + _ => {} } if ep.early_depth_test.is_some() { let required = Capabilities::EARLY_DEPTH_TEST; @@ -1069,6 +1311,10 @@ impl super::Validator { crate::ShaderStage::Compute => ShaderStages::COMPUTE, crate::ShaderStage::Mesh => ShaderStages::MESH, crate::ShaderStage::Task => ShaderStages::TASK, + crate::ShaderStage::RayGeneration => ShaderStages::RAY_GENERATION, + crate::ShaderStage::AnyHit => ShaderStages::ANY_HIT, + crate::ShaderStage::ClosestHit => ShaderStages::CLOSEST_HIT, + crate::ShaderStage::Miss => ShaderStages::MISS, }; if !info.available_stages.contains(stage_bit) { @@ -1206,6 +1452,30 @@ impl super::Validator { } } crate::AddressSpace::Immediate => GlobalUse::READ, + crate::AddressSpace::RayPayload => { + if !matches!( + ep.stage, + crate::ShaderStage::RayGeneration + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::Miss + ) { + return Err(EntryPointError::RayPayloadInInvalidStage(ep.stage) + .with_span_handle(var_handle, &module.global_variables)); + } + GlobalUse::READ | GlobalUse::QUERY | GlobalUse::WRITE + } + crate::AddressSpace::IncomingRayPayload => { + if !matches!( + ep.stage, + crate::ShaderStage::AnyHit + | crate::ShaderStage::ClosestHit + | crate::ShaderStage::Miss + ) { + return Err(EntryPointError::IncomingRayPayloadInInvalidStage(ep.stage) + .with_span_handle(var_handle, &module.global_variables)); + } + GlobalUse::READ | GlobalUse::QUERY | GlobalUse::WRITE + } }; if !allowed_usage.contains(usage) { log::warn!("\tUsage error for: {var:?}"); diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index 705a21dd8..903d21a76 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -205,6 +205,8 @@ bitflags::bitflags! { const COOPERATIVE_MATRIX = 1 << 36; /// Support for per-vertex fragment input. const PER_VERTEX = 1 << 37; + /// Support for ray generation, any hit, closest hit, and miss shaders. + const RAY_TRACING_PIPELINE = 1 << 38; } } @@ -225,6 +227,7 @@ impl Capabilities { Self::RAY_QUERY => Some(Ext::WgpuRayQuery), Self::RAY_HIT_VERTEX_POSITION => Some(Ext::WgpuRayQueryVertexReturn), Self::COOPERATIVE_MATRIX => Some(Ext::WgpuCooperativeMatrix), + Self::RAY_TRACING_PIPELINE => Some(Ext::WgpuRayTracingPipeline), _ => None, } } @@ -297,12 +300,16 @@ bitflags::bitflags! { #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] #[derive(Clone, Copy, Debug, Eq, PartialEq)] - pub struct ShaderStages: u8 { + pub struct ShaderStages: u16 { const VERTEX = 0x1; const FRAGMENT = 0x2; const COMPUTE = 0x4; const MESH = 0x8; const TASK = 0x10; + const RAY_GENERATION = 0x20; + const ANY_HIT = 0x40; + const CLOSEST_HIT = 0x80; + const MISS = 0x100; const COMPUTE_LIKE = Self::COMPUTE.bits() | Self::TASK.bits() | Self::MESH.bits(); } } @@ -377,6 +384,32 @@ pub struct Validator { /// [`Expression`]: crate::Expression /// [`Statement`]: crate::Statement needs_visit: HandleSet, + + /// Whether any trace rays call is called, and whether all have vertex return. + /// If one call doesn't use vertex ruturn, builtins for triangle vertex positions + /// (not yet implemented) are not allowed. + trace_rays_vertex_return: TraceRayVertexReturnState, + + /// The type of the ray payload, this must always be the same type in a particular + /// entrypoint + trace_rays_payload_type: Option>, +} + +#[derive(Debug)] +enum TraceRayVertexReturnState { + /// No trace ray calls yet have been found. + NoTraceRays, + /// Trace ray calls have been found, at least + /// one uses an acceleration structure that + /// does not have the flag enabling vertex return. + // Don't yet have vertex return builtins to return. + // this error for. + #[expect(unused)] + NoVertexReturn(crate::Span), + /// Trace ray calls have been found, all + /// acceleration structures have the flag enabling + /// vertex return. + VertexReturn, } #[derive(Clone, Debug, thiserror::Error)] @@ -576,6 +609,8 @@ impl Validator { override_ids: FastHashSet::default(), overrides_resolved: false, needs_visit: HandleSet::new(), + trace_rays_vertex_return: TraceRayVertexReturnState::NoTraceRays, + trace_rays_payload_type: None, } } diff --git a/naga/src/valid/type.rs b/naga/src/valid/type.rs index 7fdf627e9..dc5d5a48a 100644 --- a/naga/src/valid/type.rs +++ b/naga/src/valid/type.rs @@ -221,7 +221,7 @@ fn check_member_layout( const fn ptr_space_argument_flag(space: crate::AddressSpace) -> TypeFlags { use crate::AddressSpace as As; match space { - As::Function | As::Private => TypeFlags::ARGUMENT, + As::Function | As::Private | As::RayPayload | As::IncomingRayPayload => TypeFlags::ARGUMENT, As::Uniform | As::Storage { .. } | As::Handle @@ -800,7 +800,8 @@ impl super::Validator { Alignment::ONE, ), Ti::AccelerationStructure { vertex_return } => { - self.require_type_capability(Capabilities::RAY_QUERY)?; + self.require_type_capability(Capabilities::RAY_TRACING_PIPELINE) + .or_else(|_| self.require_type_capability(Capabilities::RAY_QUERY))?; if vertex_return { self.require_type_capability(Capabilities::RAY_HIT_VERTEX_POSITION)?; } diff --git a/naga/tests/in/wgsl/ray-tracing-pipeline.toml b/naga/tests/in/wgsl/ray-tracing-pipeline.toml new file mode 100644 index 000000000..58be3448f --- /dev/null +++ b/naga/tests/in/wgsl/ray-tracing-pipeline.toml @@ -0,0 +1,2 @@ +capabilities = "RAY_TRACING_PIPELINE" +targets = "IR" diff --git a/naga/tests/in/wgsl/ray-tracing-pipeline.wgsl b/naga/tests/in/wgsl/ray-tracing-pipeline.wgsl new file mode 100644 index 000000000..02a40b05c --- /dev/null +++ b/naga/tests/in/wgsl/ray-tracing-pipeline.wgsl @@ -0,0 +1,34 @@ +enable wgpu_ray_tracing_pipeline; + +struct HitCounters { + hit_num: u32, + selected_hit: u32, +} + +var hit_num: HitCounters; + +@group(0) @binding(0) +var acc_struct: acceleration_structure; + +@ray_generation +fn ray_gen_main() { + hit_num = HitCounters(); + traceRay(acc_struct, RayDesc(RAY_FLAG_NONE, 0xff, 0.01, 100.0, vec3(0.0), vec3(0.0, 1.0, 0.0)), &hit_num); +} + +var incoming_hit_num: HitCounters; + +@miss +@incoming_payload(incoming_hit_num) +fn miss() {} + +@any_hit +@incoming_payload(incoming_hit_num) +fn any_hit_main() { + incoming_hit_num.hit_num++; + incoming_hit_num.selected_hit = incoming_hit_num.hit_num; +} + +@closest_hit +@incoming_payload(incoming_hit_num) +fn closest_hit_main() {} \ No newline at end of file diff --git a/naga/tests/naga/snapshots.rs b/naga/tests/naga/snapshots.rs index e4e970da2..7c68812bc 100644 --- a/naga/tests/naga/snapshots.rs +++ b/naga/tests/naga/snapshots.rs @@ -335,7 +335,12 @@ fn write_output_hlsl( naga::ShaderStage::Vertex => &mut config.vertex, naga::ShaderStage::Fragment => &mut config.fragment, naga::ShaderStage::Compute => &mut config.compute, - naga::ShaderStage::Task | naga::ShaderStage::Mesh => unreachable!(), + naga::ShaderStage::Task + | naga::ShaderStage::Mesh + | naga::ShaderStage::RayGeneration + | naga::ShaderStage::AnyHit + | naga::ShaderStage::ClosestHit + | naga::ShaderStage::Miss => unreachable!(), } .push(hlsl_snapshots::ConfigItem { entry_point: name.clone(), diff --git a/naga/tests/naga/validation.rs b/naga/tests/naga/validation.rs index ebce0838e..7a66bccd6 100644 --- a/naga/tests/naga/validation.rs +++ b/naga/tests/naga/validation.rs @@ -1273,6 +1273,7 @@ fn unexpected_task_payload() { function: ir::Function::default(), mesh_info: None, task_payload: Some(payload_handle), // invalid for compute stage + incoming_ray_payload: None, }; module.entry_points.push(entry_point); diff --git a/naga/tests/naga/wgsl_errors.rs b/naga/tests/naga/wgsl_errors.rs index 6ea23933c..44efea434 100644 --- a/naga/tests/naga/wgsl_errors.rs +++ b/naga/tests/naga/wgsl_errors.rs @@ -1049,8 +1049,17 @@ macro_rules! check_one_validation { /// /// NOTE: The only reason we don't use a function for this is because we need to syntactically /// re-use `$val_err_pat`. +/// +/// The optional $other_caps argument at the end specifies capabilities that +/// allow, the shader or would change the error message if enabled, but do not +/// get enabled by the specified enable extension. This is only currently the +/// case for `acceleration_structures` which are enabled by both ray queries +/// and ray tracing pipelines. macro_rules! check_extension_validation { - ( $caps:expr, $source:expr, $parse_err:expr, $val_err_pat:pat ) => { + ( $caps:expr, $source:expr, $parse_err:expr, $val_err_pat:pat $(, $other_caps:expr)? ) => { + #[allow(unused_mut, unused_assignments)] + let mut other_caps = naga::valid::Capabilities::empty(); + $(other_caps = $other_caps;)? let caps = $caps; let source = $source; let mut ext = None; @@ -1102,7 +1111,9 @@ macro_rules! check_extension_validation { }; // Second check, for the expected validation error when the capability is not present - let error = naga::valid::Validator::new(naga::valid::ValidationFlags::all(), !caps) + // Don't check with explicitly allowed caps, as certain things (currently just + // `acceleration_structure`s) can be enabled by multiple extensions + let error = naga::valid::Validator::new(naga::valid::ValidationFlags::all(), !(caps | other_caps)) .validate(&module) .map_err(|e| e.into_inner()); // TODO(https://github.com/gfx-rs/wgpu/issues/8153): Add tests for spans #[allow(clippy::redundant_pattern_matching)] @@ -4359,7 +4370,7 @@ fn enumerant_with_template_parameters() { } #[test] -fn ray_query_enable_extension() { +fn ray_types_enable_extension() { check_extension_validation!( Capabilities::RAY_QUERY, r#"fn foo() { @@ -4381,6 +4392,7 @@ fn ray_query_enable_extension() { }) ); + // can be enabled by either of these extensions check_extension_validation!( Capabilities::RAY_QUERY, r#"@group(0) @binding(0) @@ -4398,7 +4410,28 @@ fn ray_query_enable_extension() { Err(naga::valid::ValidationError::Type { source: naga::valid::TypeError::MissingCapability(Capabilities::RAY_QUERY), .. - }) + }), + Capabilities::RAY_TRACING_PIPELINE + ); + check_extension_validation!( + Capabilities::RAY_TRACING_PIPELINE, + r#"@group(0) @binding(0) + var acc_struct: acceleration_structure; + "#, + r#"error: the `wgpu_ray_query` enable extension is not enabled + ┌─ wgsl:2:25 + │ +2 │ var acc_struct: acceleration_structure; + │ ^^^^^^^^^^^^^^^^^^^^^^ the `wgpu_ray_query` "Enable Extension" is needed for this functionality, but it is not currently enabled. + │ + = note: You can enable this extension by adding `enable wgpu_ray_query;` at the top of the shader, before any other items. + +"#, + Err(naga::valid::ValidationError::Type { + source: naga::valid::TypeError::MissingCapability(Capabilities::RAY_QUERY), + .. + }), + Capabilities::RAY_QUERY ); } @@ -4739,3 +4772,139 @@ fn mesh_shader_enable_extension() { }) ); } + +/// Checks that every ray tracing pipeline binding in naga is invalid in other stages. +#[test] +fn check_ray_tracing_pipeline_bindings() { + for (builtin, ty) in [ + ("ray_invocation_id", "vec3"), + ("num_ray_invocations", "vec3"), + ("instance_custom_data", "u32"), + ("geometry_index", "u32"), + ("world_ray_origin", "vec3"), + ("world_ray_direction", "vec3"), + ("object_ray_origin", "vec3"), + ("object_ray_direction", "vec3"), + ("ray_t_min", "f32"), + ("ray_t_current_max", "f32"), + ("object_to_world", "mat4x3"), + ("world_to_object", "mat4x3"), + ("hit_kind", "u32"), + ] { + for stage in ["@compute @workgroup_size(1)", " @vertex", "@fragment"] { + check_one_validation!( + &format!( + "{stage} + fn main(@builtin({builtin}) v: {ty}) {{}} + " + ), + Err(naga::valid::ValidationError::EntryPoint { + source: naga::valid::EntryPointError::Argument( + 0, + naga::valid::VaryingError::InvalidBuiltInStage(_), + ), + .. + },) + ); + } + } +} + +/// Checks ray generation stage is invalid without enable extension (other stages require `@incoming_payload` which forces a ray payload which is checked in [`check_ray_tracing_pipeline_payload`]) +#[test] +fn check_ray_tracing_pipeline_ray_generation() { + check_extension_validation!( + Capabilities::RAY_TRACING_PIPELINE, + "@ray_generation + fn main() {{}}", + "error: the `wgpu_ray_tracing_pipeline` enable extension is not enabled + ┌─ wgsl:1:2 + │ +1 │ @ray_generation + │ ^^^^^^^^^^^^^^ the `wgpu_ray_tracing_pipeline` \"Enable Extension\" is needed for this functionality, but it is not currently enabled. + │ + = note: You can enable this extension by adding `enable wgpu_ray_tracing_pipeline;` at the top of the shader, before any other items. + +", + Err(naga::valid::ValidationError::EntryPoint { + source: naga::valid::EntryPointError::UnsupportedCapability(naga::valid::Capabilities::RAY_TRACING_PIPELINE), + .. + },) + ); +} + +#[test] +fn check_ray_tracing_pipeline_payload() { + for space in ["ray_payload", "incoming_ray_payload"] { + // ascii is a byte per char so length is fine + let space_arrows = "^".to_string().repeat(space.len()); + check_extension_validation!( + Capabilities::RAY_TRACING_PIPELINE, + &format!("var<{space}> payload: u32;"), + &format!("error: the `wgpu_ray_tracing_pipeline` enable extension is not enabled + ┌─ wgsl:1:5 + │ +1 │ var<{space}> payload: u32; + │ {space_arrows} the `wgpu_ray_tracing_pipeline` \"Enable Extension\" is needed for this functionality, but it is not currently enabled. + │ + = note: You can enable this extension by adding `enable wgpu_ray_tracing_pipeline;` at the top of the shader, before any other items. + +"), + Err(naga::valid::ValidationError::GlobalVariable { + source: naga::valid::GlobalVariableError::UnsupportedCapability(naga::valid::Capabilities::RAY_TRACING_PIPELINE), + .. + },) + ); + } +} + +#[test] +fn check_ray_tracing_pipeline_incoming_payload_required() { + for stage in ["any_hit", "closest_hit", "miss"] { + // ascii is a byte per char so length is fine + let stage_arrows = "^".to_string().repeat(stage.len()); + check( + &format!("enable wgpu_ray_tracing_pipeline; @{stage} fn main() {{}}"), + &format!("error: incoming payload is missing on a `closest_hit`, `any_hit` or `miss` shader entry point + ┌─ wgsl:1:36 + │ +1 │ enable wgpu_ray_tracing_pipeline; @{stage} fn main() {{}} + │ {stage_arrows} must be paired with a `@incoming_payload` attribute + +"), + ); + } +} + +#[test] +fn check_ray_tracing_pipeline_payload_disallowed() { + for (stage, output, stmt) in [ + ( + "var incoming: u32; @any_hit @incoming_payload(incoming)", + "", + "", + ), + ("@compute @workgroup_size(1)", "", ""), + ( + "@vertex", + " -> @builtin(position) vec4", + "return vec4();", + ), + ("@fragment", "", ""), + ] { + check_one_validation!( + &format!( + "enable wgpu_ray_tracing_pipeline; + @group(0) @binding(0) var acc_struct: acceleration_structure; + var payload: u32; + + {stage} fn main() {output} {{_ = payload; {stmt}}}" + ), + Err(naga::valid::ValidationError::EntryPoint { + source: naga::valid::EntryPointError::RayPayloadInInvalidStage(_), + .. + },), + Capabilities::RAY_TRACING_PIPELINE + ); + } +} diff --git a/naga/tests/out/analysis/spv-shadow.info.ron b/naga/tests/out/analysis/spv-shadow.info.ron index 381f841d5..c2adf7d22 100644 --- a/naga/tests/out/analysis/spv-shadow.info.ron +++ b/naga/tests/out/analysis/spv-shadow.info.ron @@ -18,7 +18,7 @@ functions: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(1), requirements: (""), @@ -416,7 +416,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(1), requirements: (""), @@ -1596,7 +1596,7 @@ entry_points: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(1), requirements: (""), diff --git a/naga/tests/out/analysis/wgsl-access.info.ron b/naga/tests/out/analysis/wgsl-access.info.ron index c22cd768f..32ba1b0b2 100644 --- a/naga/tests/out/analysis/wgsl-access.info.ron +++ b/naga/tests/out/analysis/wgsl-access.info.ron @@ -42,7 +42,7 @@ functions: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -1200,7 +1200,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -2526,7 +2526,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), @@ -2566,7 +2566,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), @@ -2615,7 +2615,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -2658,7 +2658,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -2752,7 +2752,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -2873,7 +2873,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), @@ -2925,7 +2925,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -2980,7 +2980,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), @@ -3032,7 +3032,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -3087,7 +3087,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), @@ -3151,7 +3151,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(2), requirements: (""), @@ -3224,7 +3224,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(2), requirements: (""), @@ -3300,7 +3300,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -3400,7 +3400,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(1), requirements: (""), @@ -3598,7 +3598,7 @@ entry_points: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), @@ -4293,7 +4293,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -4745,7 +4745,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(0), requirements: (""), diff --git a/naga/tests/out/analysis/wgsl-collatz.info.ron b/naga/tests/out/analysis/wgsl-collatz.info.ron index 219e016f8..9647887a0 100644 --- a/naga/tests/out/analysis/wgsl-collatz.info.ron +++ b/naga/tests/out/analysis/wgsl-collatz.info.ron @@ -8,7 +8,7 @@ functions: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(3), requirements: (""), @@ -280,7 +280,7 @@ entry_points: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: Some(3), requirements: (""), diff --git a/naga/tests/out/analysis/wgsl-overrides.info.ron b/naga/tests/out/analysis/wgsl-overrides.info.ron index 92e99112e..d6fcee4aa 100644 --- a/naga/tests/out/analysis/wgsl-overrides.info.ron +++ b/naga/tests/out/analysis/wgsl-overrides.info.ron @@ -8,7 +8,7 @@ entry_points: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), diff --git a/naga/tests/out/analysis/wgsl-storage-textures.info.ron b/naga/tests/out/analysis/wgsl-storage-textures.info.ron index 8bb298a64..95b9484bd 100644 --- a/naga/tests/out/analysis/wgsl-storage-textures.info.ron +++ b/naga/tests/out/analysis/wgsl-storage-textures.info.ron @@ -11,7 +11,7 @@ entry_points: [ ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), @@ -187,7 +187,7 @@ ), ( flags: ("EXPRESSIONS | BLOCKS | CONTROL_FLOW_UNIFORMITY | STRUCT_LAYOUTS | CONSTANTS | BINDINGS"), - available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK"), + available_stages: ("VERTEX | FRAGMENT | COMPUTE | MESH | TASK | RAY_GENERATION | ANY_HIT | CLOSEST_HIT | MISS"), uniformity: ( non_uniform_result: None, requirements: (""), diff --git a/naga/tests/out/ir/spv-fetch_depth.compact.ron b/naga/tests/out/ir/spv-fetch_depth.compact.ron index 98f4426c3..56efde17e 100644 --- a/naga/tests/out/ir/spv-fetch_depth.compact.ron +++ b/naga/tests/out/ir/spv-fetch_depth.compact.ron @@ -198,6 +198,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/spv-fetch_depth.ron b/naga/tests/out/ir/spv-fetch_depth.ron index 104de852c..161f0fc8f 100644 --- a/naga/tests/out/ir/spv-fetch_depth.ron +++ b/naga/tests/out/ir/spv-fetch_depth.ron @@ -268,6 +268,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/spv-shadow.compact.ron b/naga/tests/out/ir/spv-shadow.compact.ron index bed86a533..9a9851610 100644 --- a/naga/tests/out/ir/spv-shadow.compact.ron +++ b/naga/tests/out/ir/spv-shadow.compact.ron @@ -1037,6 +1037,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/spv-shadow.ron b/naga/tests/out/ir/spv-shadow.ron index bdda1d185..3ea0a97b3 100644 --- a/naga/tests/out/ir/spv-shadow.ron +++ b/naga/tests/out/ir/spv-shadow.ron @@ -1315,6 +1315,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/spv-spec-constants.compact.ron b/naga/tests/out/ir/spv-spec-constants.compact.ron index 67eb29c24..8bfa9f142 100644 --- a/naga/tests/out/ir/spv-spec-constants.compact.ron +++ b/naga/tests/out/ir/spv-spec-constants.compact.ron @@ -619,6 +619,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/spv-spec-constants.ron b/naga/tests/out/ir/spv-spec-constants.ron index 51686aa20..d835ace11 100644 --- a/naga/tests/out/ir/spv-spec-constants.ron +++ b/naga/tests/out/ir/spv-spec-constants.ron @@ -725,6 +725,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-access.compact.ron b/naga/tests/out/ir/wgsl-access.compact.ron index c3df0c8c5..3e2798767 100644 --- a/naga/tests/out/ir/wgsl-access.compact.ron +++ b/naga/tests/out/ir/wgsl-access.compact.ron @@ -2657,6 +2657,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "foo_frag", @@ -2853,6 +2854,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "foo_compute", @@ -2914,6 +2916,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-access.ron b/naga/tests/out/ir/wgsl-access.ron index c3df0c8c5..3e2798767 100644 --- a/naga/tests/out/ir/wgsl-access.ron +++ b/naga/tests/out/ir/wgsl-access.ron @@ -2657,6 +2657,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "foo_frag", @@ -2853,6 +2854,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "foo_compute", @@ -2914,6 +2916,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-collatz.compact.ron b/naga/tests/out/ir/wgsl-collatz.compact.ron index fc4daaa12..dc741ac0e 100644 --- a/naga/tests/out/ir/wgsl-collatz.compact.ron +++ b/naga/tests/out/ir/wgsl-collatz.compact.ron @@ -336,6 +336,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-collatz.ron b/naga/tests/out/ir/wgsl-collatz.ron index fc4daaa12..dc741ac0e 100644 --- a/naga/tests/out/ir/wgsl-collatz.ron +++ b/naga/tests/out/ir/wgsl-collatz.ron @@ -336,6 +336,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-const_assert.compact.ron b/naga/tests/out/ir/wgsl-const_assert.compact.ron index f6bb53776..f0716e9d3 100644 --- a/naga/tests/out/ir/wgsl-const_assert.compact.ron +++ b/naga/tests/out/ir/wgsl-const_assert.compact.ron @@ -60,6 +60,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-const_assert.ron b/naga/tests/out/ir/wgsl-const_assert.ron index f6bb53776..f0716e9d3 100644 --- a/naga/tests/out/ir/wgsl-const_assert.ron +++ b/naga/tests/out/ir/wgsl-const_assert.ron @@ -60,6 +60,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-diagnostic-filter.compact.ron b/naga/tests/out/ir/wgsl-diagnostic-filter.compact.ron index 9a2bf193f..fbf499354 100644 --- a/naga/tests/out/ir/wgsl-diagnostic-filter.compact.ron +++ b/naga/tests/out/ir/wgsl-diagnostic-filter.compact.ron @@ -75,6 +75,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [ diff --git a/naga/tests/out/ir/wgsl-diagnostic-filter.ron b/naga/tests/out/ir/wgsl-diagnostic-filter.ron index 9a2bf193f..fbf499354 100644 --- a/naga/tests/out/ir/wgsl-diagnostic-filter.ron +++ b/naga/tests/out/ir/wgsl-diagnostic-filter.ron @@ -75,6 +75,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [ diff --git a/naga/tests/out/ir/wgsl-index-by-value.compact.ron b/naga/tests/out/ir/wgsl-index-by-value.compact.ron index addd0e587..0bfcbf179 100644 --- a/naga/tests/out/ir/wgsl-index-by-value.compact.ron +++ b/naga/tests/out/ir/wgsl-index-by-value.compact.ron @@ -467,6 +467,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-index-by-value.ron b/naga/tests/out/ir/wgsl-index-by-value.ron index addd0e587..0bfcbf179 100644 --- a/naga/tests/out/ir/wgsl-index-by-value.ron +++ b/naga/tests/out/ir/wgsl-index-by-value.ron @@ -467,6 +467,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-local-const.compact.ron b/naga/tests/out/ir/wgsl-local-const.compact.ron index 0e4e2e4d4..fad6bed6f 100644 --- a/naga/tests/out/ir/wgsl-local-const.compact.ron +++ b/naga/tests/out/ir/wgsl-local-const.compact.ron @@ -102,6 +102,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-local-const.ron b/naga/tests/out/ir/wgsl-local-const.ron index 0e4e2e4d4..fad6bed6f 100644 --- a/naga/tests/out/ir/wgsl-local-const.ron +++ b/naga/tests/out/ir/wgsl-local-const.ron @@ -102,6 +102,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-must-use.compact.ron b/naga/tests/out/ir/wgsl-must-use.compact.ron index 16e925f2f..ddbb0d849 100644 --- a/naga/tests/out/ir/wgsl-must-use.compact.ron +++ b/naga/tests/out/ir/wgsl-must-use.compact.ron @@ -203,6 +203,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-must-use.ron b/naga/tests/out/ir/wgsl-must-use.ron index 16e925f2f..ddbb0d849 100644 --- a/naga/tests/out/ir/wgsl-must-use.ron +++ b/naga/tests/out/ir/wgsl-must-use.ron @@ -203,6 +203,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.compact.ron b/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.compact.ron index 33f7bb278..e76537924 100644 --- a/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.compact.ron +++ b/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.compact.ron @@ -130,6 +130,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.ron b/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.ron index 33f7bb278..e76537924 100644 --- a/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.ron +++ b/naga/tests/out/ir/wgsl-overrides-atomicCompareExchangeWeak.ron @@ -130,6 +130,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-overrides-ray-query.compact.ron b/naga/tests/out/ir/wgsl-overrides-ray-query.compact.ron index 152a45008..5b681bef4 100644 --- a/naga/tests/out/ir/wgsl-overrides-ray-query.compact.ron +++ b/naga/tests/out/ir/wgsl-overrides-ray-query.compact.ron @@ -265,6 +265,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-overrides-ray-query.ron b/naga/tests/out/ir/wgsl-overrides-ray-query.ron index 152a45008..5b681bef4 100644 --- a/naga/tests/out/ir/wgsl-overrides-ray-query.ron +++ b/naga/tests/out/ir/wgsl-overrides-ray-query.ron @@ -265,6 +265,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-overrides.compact.ron b/naga/tests/out/ir/wgsl-overrides.compact.ron index fe136e71e..0711878a9 100644 --- a/naga/tests/out/ir/wgsl-overrides.compact.ron +++ b/naga/tests/out/ir/wgsl-overrides.compact.ron @@ -223,6 +223,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-overrides.ron b/naga/tests/out/ir/wgsl-overrides.ron index fe136e71e..0711878a9 100644 --- a/naga/tests/out/ir/wgsl-overrides.ron +++ b/naga/tests/out/ir/wgsl-overrides.ron @@ -223,6 +223,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-ray-tracing-pipeline.compact.ron b/naga/tests/out/ir/wgsl-ray-tracing-pipeline.compact.ron new file mode 100644 index 000000000..5a9dac09e --- /dev/null +++ b/naga/tests/out/ir/wgsl-ray-tracing-pipeline.compact.ron @@ -0,0 +1,350 @@ +( + types: [ + ( + name: None, + inner: Scalar(( + kind: Uint, + width: 4, + )), + ), + ( + name: Some("HitCounters"), + inner: Struct( + members: [ + ( + name: Some("hit_num"), + ty: 0, + binding: None, + offset: 0, + ), + ( + name: Some("selected_hit"), + ty: 0, + binding: None, + offset: 4, + ), + ], + span: 8, + ), + ), + ( + name: None, + inner: AccelerationStructure( + vertex_return: false, + ), + ), + ( + name: None, + inner: Scalar(( + kind: Float, + width: 4, + )), + ), + ( + name: None, + inner: Vector( + size: Tri, + scalar: ( + kind: Float, + width: 4, + ), + ), + ), + ( + name: Some("RayDesc"), + inner: Struct( + members: [ + ( + name: Some("flags"), + ty: 0, + binding: None, + offset: 0, + ), + ( + name: Some("cull_mask"), + ty: 0, + binding: None, + offset: 4, + ), + ( + name: Some("tmin"), + ty: 3, + binding: None, + offset: 8, + ), + ( + name: Some("tmax"), + ty: 3, + binding: None, + offset: 12, + ), + ( + name: Some("origin"), + ty: 4, + binding: None, + offset: 16, + ), + ( + name: Some("dir"), + ty: 4, + binding: None, + offset: 32, + ), + ], + span: 48, + ), + ), + ], + special_types: ( + ray_desc: Some(5), + ray_intersection: None, + ray_vertex_return: None, + external_texture_params: None, + external_texture_transfer_function: None, + predeclared_types: {}, + ), + constants: [], + overrides: [], + global_variables: [ + ( + name: Some("hit_num"), + space: RayPayload, + binding: None, + ty: 1, + init: None, + ), + ( + name: Some("acc_struct"), + space: Handle, + binding: Some(( + group: 0, + binding: 0, + )), + ty: 2, + init: None, + ), + ( + name: Some("incoming_hit_num"), + space: IncomingRayPayload, + binding: None, + ty: 1, + init: None, + ), + ], + global_expressions: [], + functions: [], + entry_points: [ + ( + name: "ray_gen_main", + stage: RayGeneration, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("ray_gen_main"), + arguments: [], + result: None, + local_variables: [], + expressions: [ + GlobalVariable(0), + ZeroValue(1), + GlobalVariable(1), + Literal(U32(0)), + Literal(U32(255)), + Literal(F32(0.01)), + Literal(F32(100.0)), + Literal(F32(0.0)), + Splat( + size: Tri, + value: 7, + ), + Literal(F32(0.0)), + Literal(F32(1.0)), + Literal(F32(0.0)), + Compose( + ty: 4, + components: [ + 9, + 10, + 11, + ], + ), + Compose( + ty: 5, + components: [ + 3, + 4, + 5, + 6, + 8, + 12, + ], + ), + GlobalVariable(0), + ], + named_expressions: {}, + body: [ + Store( + pointer: 0, + value: 1, + ), + Emit(( + start: 0, + end: 0, + )), + Emit(( + start: 0, + end: 0, + )), + Emit(( + start: 8, + end: 9, + )), + Emit(( + start: 12, + end: 14, + )), + RayPipelineFunction(TraceRay( + acceleration_structure: 2, + descriptor: 13, + payload: 14, + )), + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: None, + ), + ( + name: "miss", + stage: Miss, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("miss"), + arguments: [], + result: None, + local_variables: [], + expressions: [], + named_expressions: {}, + body: [ + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: Some(2), + ), + ( + name: "any_hit_main", + stage: AnyHit, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("any_hit_main"), + arguments: [], + result: None, + local_variables: [], + expressions: [ + GlobalVariable(2), + AccessIndex( + base: 0, + index: 0, + ), + Literal(U32(1)), + Load( + pointer: 1, + ), + Binary( + op: Add, + left: 3, + right: 2, + ), + GlobalVariable(2), + AccessIndex( + base: 5, + index: 1, + ), + GlobalVariable(2), + AccessIndex( + base: 7, + index: 0, + ), + Load( + pointer: 8, + ), + ], + named_expressions: {}, + body: [ + Emit(( + start: 1, + end: 2, + )), + Emit(( + start: 3, + end: 5, + )), + Store( + pointer: 1, + value: 4, + ), + Emit(( + start: 6, + end: 7, + )), + Emit(( + start: 8, + end: 10, + )), + Store( + pointer: 6, + value: 9, + ), + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: Some(2), + ), + ( + name: "closest_hit_main", + stage: ClosestHit, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("closest_hit_main"), + arguments: [], + result: None, + local_variables: [], + expressions: [], + named_expressions: {}, + body: [ + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: Some(2), + ), + ], + diagnostic_filters: [], + diagnostic_filter_leaf: None, + doc_comments: None, +) \ No newline at end of file diff --git a/naga/tests/out/ir/wgsl-ray-tracing-pipeline.ron b/naga/tests/out/ir/wgsl-ray-tracing-pipeline.ron new file mode 100644 index 000000000..5a9dac09e --- /dev/null +++ b/naga/tests/out/ir/wgsl-ray-tracing-pipeline.ron @@ -0,0 +1,350 @@ +( + types: [ + ( + name: None, + inner: Scalar(( + kind: Uint, + width: 4, + )), + ), + ( + name: Some("HitCounters"), + inner: Struct( + members: [ + ( + name: Some("hit_num"), + ty: 0, + binding: None, + offset: 0, + ), + ( + name: Some("selected_hit"), + ty: 0, + binding: None, + offset: 4, + ), + ], + span: 8, + ), + ), + ( + name: None, + inner: AccelerationStructure( + vertex_return: false, + ), + ), + ( + name: None, + inner: Scalar(( + kind: Float, + width: 4, + )), + ), + ( + name: None, + inner: Vector( + size: Tri, + scalar: ( + kind: Float, + width: 4, + ), + ), + ), + ( + name: Some("RayDesc"), + inner: Struct( + members: [ + ( + name: Some("flags"), + ty: 0, + binding: None, + offset: 0, + ), + ( + name: Some("cull_mask"), + ty: 0, + binding: None, + offset: 4, + ), + ( + name: Some("tmin"), + ty: 3, + binding: None, + offset: 8, + ), + ( + name: Some("tmax"), + ty: 3, + binding: None, + offset: 12, + ), + ( + name: Some("origin"), + ty: 4, + binding: None, + offset: 16, + ), + ( + name: Some("dir"), + ty: 4, + binding: None, + offset: 32, + ), + ], + span: 48, + ), + ), + ], + special_types: ( + ray_desc: Some(5), + ray_intersection: None, + ray_vertex_return: None, + external_texture_params: None, + external_texture_transfer_function: None, + predeclared_types: {}, + ), + constants: [], + overrides: [], + global_variables: [ + ( + name: Some("hit_num"), + space: RayPayload, + binding: None, + ty: 1, + init: None, + ), + ( + name: Some("acc_struct"), + space: Handle, + binding: Some(( + group: 0, + binding: 0, + )), + ty: 2, + init: None, + ), + ( + name: Some("incoming_hit_num"), + space: IncomingRayPayload, + binding: None, + ty: 1, + init: None, + ), + ], + global_expressions: [], + functions: [], + entry_points: [ + ( + name: "ray_gen_main", + stage: RayGeneration, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("ray_gen_main"), + arguments: [], + result: None, + local_variables: [], + expressions: [ + GlobalVariable(0), + ZeroValue(1), + GlobalVariable(1), + Literal(U32(0)), + Literal(U32(255)), + Literal(F32(0.01)), + Literal(F32(100.0)), + Literal(F32(0.0)), + Splat( + size: Tri, + value: 7, + ), + Literal(F32(0.0)), + Literal(F32(1.0)), + Literal(F32(0.0)), + Compose( + ty: 4, + components: [ + 9, + 10, + 11, + ], + ), + Compose( + ty: 5, + components: [ + 3, + 4, + 5, + 6, + 8, + 12, + ], + ), + GlobalVariable(0), + ], + named_expressions: {}, + body: [ + Store( + pointer: 0, + value: 1, + ), + Emit(( + start: 0, + end: 0, + )), + Emit(( + start: 0, + end: 0, + )), + Emit(( + start: 8, + end: 9, + )), + Emit(( + start: 12, + end: 14, + )), + RayPipelineFunction(TraceRay( + acceleration_structure: 2, + descriptor: 13, + payload: 14, + )), + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: None, + ), + ( + name: "miss", + stage: Miss, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("miss"), + arguments: [], + result: None, + local_variables: [], + expressions: [], + named_expressions: {}, + body: [ + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: Some(2), + ), + ( + name: "any_hit_main", + stage: AnyHit, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("any_hit_main"), + arguments: [], + result: None, + local_variables: [], + expressions: [ + GlobalVariable(2), + AccessIndex( + base: 0, + index: 0, + ), + Literal(U32(1)), + Load( + pointer: 1, + ), + Binary( + op: Add, + left: 3, + right: 2, + ), + GlobalVariable(2), + AccessIndex( + base: 5, + index: 1, + ), + GlobalVariable(2), + AccessIndex( + base: 7, + index: 0, + ), + Load( + pointer: 8, + ), + ], + named_expressions: {}, + body: [ + Emit(( + start: 1, + end: 2, + )), + Emit(( + start: 3, + end: 5, + )), + Store( + pointer: 1, + value: 4, + ), + Emit(( + start: 6, + end: 7, + )), + Emit(( + start: 8, + end: 10, + )), + Store( + pointer: 6, + value: 9, + ), + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: Some(2), + ), + ( + name: "closest_hit_main", + stage: ClosestHit, + early_depth_test: None, + workgroup_size: (0, 0, 0), + workgroup_size_overrides: None, + function: ( + name: Some("closest_hit_main"), + arguments: [], + result: None, + local_variables: [], + expressions: [], + named_expressions: {}, + body: [ + Return( + value: None, + ), + ], + diagnostic_filter_leaf: None, + ), + mesh_info: None, + task_payload: None, + incoming_ray_payload: Some(2), + ), + ], + diagnostic_filters: [], + diagnostic_filter_leaf: None, + doc_comments: None, +) \ No newline at end of file diff --git a/naga/tests/out/ir/wgsl-storage-textures.compact.ron b/naga/tests/out/ir/wgsl-storage-textures.compact.ron index 68c867a19..f2d3b49b7 100644 --- a/naga/tests/out/ir/wgsl-storage-textures.compact.ron +++ b/naga/tests/out/ir/wgsl-storage-textures.compact.ron @@ -220,6 +220,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "csStore", @@ -319,6 +320,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-storage-textures.ron b/naga/tests/out/ir/wgsl-storage-textures.ron index 68c867a19..f2d3b49b7 100644 --- a/naga/tests/out/ir/wgsl-storage-textures.ron +++ b/naga/tests/out/ir/wgsl-storage-textures.ron @@ -220,6 +220,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "csStore", @@ -319,6 +320,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-template-list-trailing-comma.compact.ron b/naga/tests/out/ir/wgsl-template-list-trailing-comma.compact.ron index db619dff8..f4335f9b1 100644 --- a/naga/tests/out/ir/wgsl-template-list-trailing-comma.compact.ron +++ b/naga/tests/out/ir/wgsl-template-list-trailing-comma.compact.ron @@ -192,6 +192,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-template-list-trailing-comma.ron b/naga/tests/out/ir/wgsl-template-list-trailing-comma.ron index db619dff8..f4335f9b1 100644 --- a/naga/tests/out/ir/wgsl-template-list-trailing-comma.ron +++ b/naga/tests/out/ir/wgsl-template-list-trailing-comma.ron @@ -192,6 +192,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-texture-external.compact.ron b/naga/tests/out/ir/wgsl-texture-external.compact.ron index 689fe215e..f22b5f8b8 100644 --- a/naga/tests/out/ir/wgsl-texture-external.compact.ron +++ b/naga/tests/out/ir/wgsl-texture-external.compact.ron @@ -419,6 +419,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "vertex_main", @@ -457,6 +458,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "compute_main", @@ -490,6 +492,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-texture-external.ron b/naga/tests/out/ir/wgsl-texture-external.ron index 689fe215e..f22b5f8b8 100644 --- a/naga/tests/out/ir/wgsl-texture-external.ron +++ b/naga/tests/out/ir/wgsl-texture-external.ron @@ -419,6 +419,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "vertex_main", @@ -457,6 +458,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ( name: "compute_main", @@ -490,6 +492,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-types_with_comments.compact.ron b/naga/tests/out/ir/wgsl-types_with_comments.compact.ron index 7c0d85694..b11618912 100644 --- a/naga/tests/out/ir/wgsl-types_with_comments.compact.ron +++ b/naga/tests/out/ir/wgsl-types_with_comments.compact.ron @@ -118,6 +118,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/naga/tests/out/ir/wgsl-types_with_comments.ron b/naga/tests/out/ir/wgsl-types_with_comments.ron index 34e44cb96..038535768 100644 --- a/naga/tests/out/ir/wgsl-types_with_comments.ron +++ b/naga/tests/out/ir/wgsl-types_with_comments.ron @@ -174,6 +174,7 @@ ), mesh_info: None, task_payload: None, + incoming_ray_payload: None, ), ], diagnostic_filters: [], diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 0e0c4578a..a0c94a03a 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -1454,6 +1454,12 @@ impl Interface { naga::ShaderStage::Compute | naga::ShaderStage::Task | naga::ShaderStage::Mesh => (false, false), + naga::ShaderStage::RayGeneration + | naga::ShaderStage::AnyHit + | naga::ShaderStage::ClosestHit + | naga::ShaderStage::Miss => { + unreachable!() + } }; if !compatible { return Err(InputError::WrongType(provided.ty)); diff --git a/wgpu-core/src/validation/shader_io_deductions.rs b/wgpu-core/src/validation/shader_io_deductions.rs index b3c46945b..0a16d53b5 100644 --- a/wgpu-core/src/validation/shader_io_deductions.rs +++ b/wgpu-core/src/validation/shader_io_deductions.rs @@ -65,11 +65,9 @@ impl MaxFragmentShaderInputDeduction { BuiltIn::PrimitiveIndex => InterStageBuiltIn::PrimitiveIndex, BuiltIn::SubgroupSize => InterStageBuiltIn::SubgroupSize, BuiltIn::SubgroupInvocationId => InterStageBuiltIn::SubgroupInvocationId, - BuiltIn::PointCoord => InterStageBuiltIn::PointCoord, BuiltIn::Barycentric { .. } => InterStageBuiltIn::Barycentric, BuiltIn::ViewIndex => InterStageBuiltIn::ViewIndex, - BuiltIn::BaseInstance | BuiltIn::BaseVertex | BuiltIn::ClipDistance @@ -95,7 +93,20 @@ impl MaxFragmentShaderInputDeduction { | BuiltIn::VertexCount | BuiltIn::Vertices | BuiltIn::PrimitiveCount - | BuiltIn::Primitives => return None, + | BuiltIn::Primitives + | BuiltIn::RayInvocationId + | BuiltIn::NumRayInvocations + | BuiltIn::InstanceCustomData + | BuiltIn::GeometryIndex + | BuiltIn::WorldRayOrigin + | BuiltIn::WorldRayDirection + | BuiltIn::ObjectRayOrigin + | BuiltIn::ObjectRayDirection + | BuiltIn::RayTmin + | BuiltIn::RayTCurrentMax + | BuiltIn::ObjectToWorld + | BuiltIn::WorldToObject + | BuiltIn::HitKind => return None, })) } } diff --git a/wgpu-hal/src/auxil/mod.rs b/wgpu-hal/src/auxil/mod.rs index 39054da18..9a5a231d6 100644 --- a/wgpu-hal/src/auxil/mod.rs +++ b/wgpu-hal/src/auxil/mod.rs @@ -62,6 +62,10 @@ pub fn map_naga_stage(stage: naga::ShaderStage) -> wgt::ShaderStages { naga::ShaderStage::Compute => wgt::ShaderStages::COMPUTE, naga::ShaderStage::Task => wgt::ShaderStages::TASK, naga::ShaderStage::Mesh => wgt::ShaderStages::MESH, + naga::ShaderStage::RayGeneration => wgt::ShaderStages::RAY_GENERATION, + naga::ShaderStage::AnyHit => wgt::ShaderStages::ANY_HIT, + naga::ShaderStage::ClosestHit => wgt::ShaderStages::CLOSEST_HIT, + naga::ShaderStage::Miss => wgt::ShaderStages::MISS, } } diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 9f41b7738..f2192fcd3 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -99,7 +99,12 @@ impl CompilationContext<'_> { unsafe { gl.bind_frag_data_location(program, location.location, &name) } } naga::ShaderStage::Compute => {} - naga::ShaderStage::Task | naga::ShaderStage::Mesh => unreachable!(), + naga::ShaderStage::Task + | naga::ShaderStage::Mesh + | naga::ShaderStage::RayGeneration + | naga::ShaderStage::AnyHit + | naga::ShaderStage::ClosestHit + | naga::ShaderStage::Miss => unreachable!(), } } @@ -175,7 +180,12 @@ impl super::Device { naga::ShaderStage::Vertex => glow::VERTEX_SHADER, naga::ShaderStage::Fragment => glow::FRAGMENT_SHADER, naga::ShaderStage::Compute => glow::COMPUTE_SHADER, - naga::ShaderStage::Task | naga::ShaderStage::Mesh => unreachable!(), + naga::ShaderStage::Task + | naga::ShaderStage::Mesh + | naga::ShaderStage::RayGeneration + | naga::ShaderStage::AnyHit + | naga::ShaderStage::ClosestHit + | naga::ShaderStage::Miss => unreachable!(), }; let raw = unsafe { gl.create_shader(target) }.unwrap(); diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index 719ce0f00..77841f512 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -260,6 +260,7 @@ impl super::CommandEncoder { S::Task => &bg_info.base_resource_indices.ts, S::Mesh => &bg_info.base_resource_indices.ms, S::Compute => &bg_info.base_resource_indices.cs, + S::RayGeneration | S::AnyHit | S::ClosestHit | S::Miss => unimplemented!(), }; let buffers = match encoder.stage() { S::Vertex => group.counters.vs.buffers, @@ -267,6 +268,7 @@ impl super::CommandEncoder { S::Task => group.counters.ts.buffers, S::Mesh => group.counters.ms.buffers, S::Compute => group.counters.cs.buffers, + S::RayGeneration | S::AnyHit | S::ClosestHit | S::Miss => unimplemented!(), }; let mut changes_sizes_buffer = false; for index in 0..buffers { @@ -304,6 +306,7 @@ impl super::CommandEncoder { S::Task => group.counters.ts.samplers, S::Mesh => group.counters.ms.samplers, S::Compute => group.counters.cs.samplers, + S::RayGeneration | S::AnyHit | S::ClosestHit | S::Miss => unimplemented!(), }; for index in 0..samplers { let res = group.samplers[(index_base.samplers + index) as usize]; @@ -318,6 +321,7 @@ impl super::CommandEncoder { S::Task => group.counters.ts.textures, S::Mesh => group.counters.ms.textures, S::Compute => group.counters.cs.textures, + S::RayGeneration | S::AnyHit | S::ClosestHit | S::Miss => unimplemented!(), }; for index in 0..textures { let res = group.textures[(index_base.textures + index) as usize]; diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 5461153ff..9c04a31ef 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -663,6 +663,10 @@ impl ops::Index for MultiStageData { naga::ShaderStage::Compute => &self.cs, naga::ShaderStage::Task => &self.ts, naga::ShaderStage::Mesh => &self.ms, + naga::ShaderStage::RayGeneration + | naga::ShaderStage::AnyHit + | naga::ShaderStage::ClosestHit + | naga::ShaderStage::Miss => unimplemented!(), } } } diff --git a/wgpu-types/src/binding.rs b/wgpu-types/src/binding.rs index c1e873a4a..db7a15b3b 100644 --- a/wgpu-types/src/binding.rs +++ b/wgpu-types/src/binding.rs @@ -221,6 +221,14 @@ bitflags::bitflags! { const TASK = 1 << 3; /// Binding is visible from the mesh shader of a mesh pipeline. const MESH = 1 << 4; + /// Binding is visible from the ray generation shader of a ray tracing pipeline. + const RAY_GENERATION = 1 << 5; + /// Binding is visible from the ray any hit shader of a ray tracing pipeline. + const ANY_HIT = 1 << 6; + /// Binding is visible from the ray closest hit shader of a ray tracing pipeline. + const CLOSEST_HIT = 1 << 7; + /// Binding is visible from the ray miss shader of a ray tracing pipeline. + const MISS = 1 << 8; } }