Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ depth_stencil: Some(wgpu::DepthStencilState::stencil(
- Initial wgsl-in ray tracing pipelines. By @Vecvec in [#8570](https://github.com/gfx-rs/wgpu/pull/8570).
- wgsl-out ray tracing pipelines. By @Vecvec in [#8970](https://github.com/gfx-rs/wgpu/pull/8970).
- 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.
- spirv-out ray tracing pipelines. By @Vecvec in [#9085](https://github.com/gfx-rs/wgpu/pull/9085).

#### GLES

Expand Down
1 change: 1 addition & 0 deletions naga-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl SpirvOutParameters {
use_storage_input_output_16: self.use_storage_input_output_16,
task_dispatch_limits: shared_info.task_limits,
mesh_shader_primitive_indices_clamp: shared_info.mesh_output_validation,
trace_ray_argument_validation: true,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion naga/src/back/spv/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4175,7 +4175,9 @@ impl BlockContext<'_> {
}
};
}
Statement::RayPipelineFunction(_) => unreachable!(),
Statement::RayPipelineFunction(ref fun) => {
self.write_ray_tracing_pipeline_function(fun, &mut block);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion naga/src/back/spv/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ 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!(),
// We can't require capabilities here but we request capabilities on the ray pipeline stages.
// Therefore we also don't need the capabilities here because these are only allowed to be accessed
// in the ray pipeline stages
crate::AddressSpace::RayPayload => spirv::StorageClass::RayPayloadKHR,
crate::AddressSpace::IncomingRayPayload => spirv::StorageClass::IncomingRayPayloadKHR,
}
}

Expand Down
33 changes: 33 additions & 0 deletions naga/src/back/spv/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,39 @@ impl super::Instruction {
instruction
}

//
// Ray Tracing Pipeline Instructions
//

#[expect(clippy::too_many_arguments)]
pub(super) fn trace_ray(
acceleration_structure: Word,
ray_flags: Word,
cull_mask: Word,
sbt_offset: Word,
sbt_stride: Word,
miss_idx: Word,
ray_origin: Word,
ray_tmin: Word,
ray_dir: Word,
ray_tmax: Word,
payload: Word,
) -> Self {
let mut instruction = Self::new(Op::TraceRayKHR);
instruction.add_operand(acceleration_structure);
instruction.add_operand(ray_flags);
instruction.add_operand(cull_mask);
instruction.add_operand(sbt_offset);
instruction.add_operand(sbt_stride);
instruction.add_operand(miss_idx);
instruction.add_operand(ray_origin);
instruction.add_operand(ray_tmin);
instruction.add_operand(ray_dir);
instruction.add_operand(ray_tmax);
instruction.add_operand(payload);
instruction
}

//
// Conversion Instructions
//
Expand Down
28 changes: 27 additions & 1 deletion naga/src/back/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,14 @@ enum LookupRayQueryFunction {
Terminate,
}

// Just one supported function right now, more in the future.
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
enum LookupRaytracingFunction {
TraceRay {
payload: Handle<crate::GlobalVariable>,
},
}

#[derive(Debug)]
enum Dimension {
Scalar,
Expand Down Expand Up @@ -962,6 +970,10 @@ pub struct Writer {

ray_query_functions: crate::FastHashMap<LookupRayQueryFunction, Word>,

ray_tracing_functions: crate::FastHashMap<LookupRaytracingFunction, Word>,

has_ray_tracing_pipeline: bool,

/// F16 I/O polyfill manager for handling `f16` input/output variables
/// when `StorageInputOutput16` capability is not available.
io_f16_polyfills: f16_polyfill::F16IoPolyfill,
Expand All @@ -970,6 +982,9 @@ pub struct Writer {
debug_printf: Option<Word>,
pub(crate) ray_query_initialization_tracking: bool,

/// Whether the arguments to trace ray should be validated
pub(crate) trace_ray_argument_validation: bool,

/// Limits to the mesh shader dispatch group a task workgroup can dispatch.
///
/// Metal for example limits to 1024 workgroups per task shader dispatch. Dispatching more is
Expand Down Expand Up @@ -1017,6 +1032,13 @@ bitflags::bitflags! {
/// Note: VK_KHR_shader_non_semantic_info must be enabled. This will have no
/// effect if `options.ray_query_initialization_tracking` is set to false.
const PRINT_ON_RAY_QUERY_INITIALIZATION_FAIL = 0x20;

/// Instead of silently failing if the arguments to `traceRays` are
/// invalid, uses debug printf extension to print to the command line
///
/// Note: VK_KHR_shader_non_semantic_info must be enabled. This will have no
/// effect if `options.trace_ray_argument_validation` is set to false.
const PRINT_ON_TRACE_RAYS_FAIL = 0x40;
}
}

Expand Down Expand Up @@ -1078,6 +1100,9 @@ pub struct Options<'a> {
/// misuse.
pub ray_query_initialization_tracking: bool,

/// If set, arguments to `traceRays` calls will be validated.
pub trace_ray_argument_validation: bool,

/// Whether to use the `StorageInputOutput16` capability for `f16` shader I/O.
/// When false, `f16` I/O is polyfilled using `f32` types with conversions.
pub use_storage_input_output_16: bool,
Expand Down Expand Up @@ -1107,6 +1132,7 @@ impl Default for Options<'_> {
zero_initialize_workgroup_memory: ZeroInitializeWorkgroupMemoryMode::Polyfill,
force_loop_bounding: true,
ray_query_initialization_tracking: true,
trace_ray_argument_validation: true,
use_storage_input_output_16: true,
debug_info: None,
task_dispatch_limits: None,
Expand Down Expand Up @@ -1188,6 +1214,6 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
| Caps::STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
| Caps::COOPERATIVE_MATRIX
| Caps::PER_VERTEX
// No RAY_TRACING_PIPELINE
| Caps::RAY_TRACING_PIPELINE
| Caps::DRAW_INDEX
}
Loading