Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Commit da59652

Browse files
committed
Add support for SPV_KHR_ray_tracing
1 parent 9723e12 commit da59652

19 files changed

+325
-34
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ syn = { version = "1", features = ["visit", "visit-mut"] }
3737
# Normal dependencies.
3838
bimap = "0.6"
3939
indexmap = "1.6.0"
40-
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "ee1e913" }
40+
rspirv = { git = "https://github.com/EmbarkStudios/rspirv.git", rev = "1f225ed" }
4141
rustc-demangle = "0.1.18"
4242
sanitize-filename = "0.3"
4343
serde = { version = "1.0", features = ["derive"] }

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,9 @@ fn trans_intrinsic_type<'tcx>(
825825
}
826826
Ok(SpirvType::Sampler.def(span, cx))
827827
}
828+
IntrinsicType::AccelerationStructureKhr => {
829+
Ok(SpirvType::AccelerationStructureKhr.def(span, cx))
830+
}
828831
IntrinsicType::SampledImage => {
829832
// see SpirvType::sizeof
830833
if ty.size != Size::from_bytes(4) {

crates/rustc_codegen_spirv/src/attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub enum IntrinsicType {
7171
access_qualifier: Option<AccessQualifier>,
7272
},
7373
Sampler,
74+
AccelerationStructureKhr,
7475
SampledImage,
7576
}
7677

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
232232
SpirvType::Image { .. } => self.fatal("cannot memset image"),
233233
SpirvType::Sampler => self.fatal("cannot memset sampler"),
234234
SpirvType::SampledImage { .. } => self.fatal("cannot memset sampled image"),
235+
SpirvType::AccelerationStructureKhr => {
236+
self.fatal("cannot memset acceleration structure")
237+
}
235238
}
236239
}
237240

@@ -288,6 +291,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
288291
SpirvType::Image { .. } => self.fatal("cannot memset image"),
289292
SpirvType::Sampler => self.fatal("cannot memset sampler"),
290293
SpirvType::SampledImage { .. } => self.fatal("cannot memset sampled image"),
294+
SpirvType::AccelerationStructureKhr => {
295+
self.fatal("cannot memset acceleration structure")
296+
}
291297
}
292298
}
293299

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ impl<'tcx> CodegenCx<'tcx> {
524524
.tcx
525525
.sess
526526
.fatal("Cannot create a constant sampled image value"),
527+
SpirvType::AccelerationStructureKhr => self
528+
.tcx
529+
.sess
530+
.fatal("Cannot create a constant acceleration structure"),
527531
}
528532
}
529533
}

crates/rustc_codegen_spirv/src/codegen_cx/type_.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
174174
SpirvType::Function { .. } => TypeKind::Function,
175175
// HACK(eddyb) this is probably the closest `TypeKind` (which is still
176176
// very much LLVM-specific, sadly) has to offer to "resource handle".
177-
SpirvType::Image { .. } |
178-
SpirvType::Sampler |
179-
SpirvType::SampledImage { .. } => TypeKind::Token,
177+
| SpirvType::Image { .. }
178+
| SpirvType::Sampler
179+
| SpirvType::SampledImage { .. }
180+
| SpirvType::AccelerationStructureKhr
181+
=> TypeKind::Token,
180182
}
181183
}
182184
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type {

crates/rustc_codegen_spirv/src/spirv_type.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub enum SpirvType {
8080
SampledImage {
8181
image_type: Word,
8282
},
83+
AccelerationStructureKhr,
8384
}
8485

8586
impl SpirvType {
@@ -247,6 +248,7 @@ impl SpirvType {
247248
access_qualifier,
248249
),
249250
Self::Sampler => cx.emit_global().type_sampler(),
251+
Self::AccelerationStructureKhr => cx.emit_global().type_acceleration_structure_khr(),
250252
Self::SampledImage { image_type } => cx.emit_global().type_sampled_image(image_type),
251253
};
252254
cx.type_cache.def(result, self);
@@ -320,7 +322,8 @@ impl SpirvType {
320322
Self::Void
321323
| Self::Opaque { .. }
322324
| Self::RuntimeArray { .. }
323-
| Self::Function { .. } => return None,
325+
| Self::Function { .. }
326+
| Self::AccelerationStructureKhr => return None,
324327

325328
Self::Bool => Size::from_bytes(1),
326329
Self::Integer(width, _) | Self::Float(width) => Size::from_bits(width),
@@ -340,9 +343,10 @@ impl SpirvType {
340343
pub fn alignof<'tcx>(&self, cx: &CodegenCx<'tcx>) -> Align {
341344
match *self {
342345
// Types that have no concept of size or alignment.
343-
Self::Void | Self::Opaque { .. } | Self::Function { .. } => {
344-
Align::from_bytes(0).unwrap()
345-
}
346+
Self::Void
347+
| Self::Opaque { .. }
348+
| Self::Function { .. }
349+
| Self::AccelerationStructureKhr => Align::from_bytes(0).unwrap(),
346350

347351
Self::Bool => Align::from_bytes(1).unwrap(),
348352
Self::Integer(width, _) | Self::Float(width) => Align::from_bits(width as u64).unwrap(),
@@ -499,6 +503,9 @@ impl fmt::Debug for SpirvTypePrinter<'_, '_> {
499503
.field("id", &self.id)
500504
.field("image_type", &self.cx.debug_type(image_type))
501505
.finish(),
506+
SpirvType::AccelerationStructureKhr => {
507+
f.debug_struct("AccelerationStructureKhr").finish()
508+
}
502509
};
503510
{
504511
let mut debug_stack = DEBUG_STACK.lock().unwrap();
@@ -654,6 +661,7 @@ impl SpirvTypePrinter<'_, '_> {
654661
.debug_struct("SampledImage")
655662
.field("image_type", &self.cx.debug_type(image_type))
656663
.finish(),
664+
SpirvType::AccelerationStructureKhr => f.write_str("AccelerationStructureKhr"),
657665
}
658666
}
659667
}

crates/rustc_codegen_spirv/src/spirv_type_constraints.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,15 +727,15 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
727727
| Op::ExecuteCallableKHR
728728
| Op::ConvertUToAccelerationStructureKHR
729729
| Op::IgnoreIntersectionKHR
730-
| Op::TerminateRayKHR => reserved!(SPV_KHR_ray_tracing),
730+
| Op::TerminateRayKHR => {}
731731
// SPV_KHR_ray_query
732732
Op::TypeRayQueryKHR
733733
| Op::RayQueryInitializeKHR
734734
| Op::RayQueryTerminateKHR
735735
| Op::RayQueryGenerateIntersectionKHR
736736
| Op::RayQueryConfirmIntersectionKHR
737737
| Op::RayQueryProceedKHR
738-
| Op::RayQueryGetIntersectionTypeKHR => reserved!(SPV_KHR_ray_query),
738+
| Op::RayQueryGetIntersectionTypeKHR => {}
739739
// SPV_AMD_shader_fragment_mask
740740
Op::FragmentMaskFetchAMD | Op::FragmentFetchAMD => reserved!(SPV_AMD_shader_fragment_mask),
741741
// SPV_KHR_shader_clock
@@ -748,7 +748,7 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
748748
| Op::TerminateRayNV
749749
| Op::TraceNV
750750
| Op::TypeAccelerationStructureNV
751-
| Op::ExecuteCallableNV => reserved!(SPV_NV_ray_tracing),
751+
| Op::ExecuteCallableNV => {}
752752
// SPV_NV_cooperative_matrix
753753
Op::TypeCooperativeMatrixNV
754754
| Op::CooperativeMatrixLoadNV

crates/rustc_codegen_spirv/src/symbols.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,21 @@ const BUILTINS: &[(&str, BuiltIn)] = {
129129
("bary_coord_no_persp_nv", BaryCoordNoPerspNV),
130130
("frag_size_ext", FragSizeEXT),
131131
("frag_invocation_count_ext", FragInvocationCountEXT),
132-
("launch_id_nv", LaunchIdNV),
133-
("launch_size_nv", LaunchSizeNV),
134-
("world_ray_origin_nv", WorldRayOriginNV),
135-
("world_ray_direction_nv", WorldRayDirectionNV),
136-
("object_ray_origin_nv", ObjectRayOriginNV),
137-
("object_ray_direction_nv", ObjectRayDirectionNV),
138-
("ray_tmin_nv", RayTminNV),
139-
("ray_tmax_nv", RayTmaxNV),
140-
("instance_custom_index_nv", InstanceCustomIndexNV),
141-
("object_to_world_nv", ObjectToWorldNV),
142-
("world_to_object_nv", WorldToObjectNV),
143-
("hit_t_nv", HitTNV),
144-
("hit_kind_nv", HitKindNV),
145-
("incoming_ray_flags_nv", IncomingRayFlagsNV),
132+
("launch_id_khr", LaunchIdNV),
133+
("launch_size_khr", LaunchSizeNV),
134+
("instance_custom_index_khr", InstanceCustomIndexNV),
146135
("ray_geometry_index_khr", RayGeometryIndexKHR),
136+
("world_ray_origin_khr", WorldRayOriginNV),
137+
("world_ray_direction_khr", WorldRayDirectionNV),
138+
("object_ray_origin_khr", ObjectRayOriginNV),
139+
("object_ray_direction_khr", ObjectRayDirectionNV),
140+
("ray_tmin_khr", RayTminNV),
141+
("ray_tmax_khr", RayTmaxNV),
142+
("object_to_world_khr", ObjectToWorldNV),
143+
("world_to_object_khr", WorldToObjectNV),
144+
("hit_kind_khr", HitKindNV),
145+
("incoming_ray_flags_khr", IncomingRayFlagsNV),
146+
("hit_t_nv", HitTNV),
147147
("warps_per_sm_nv", WarpsPerSMNV),
148148
("sm_count_nv", SMCountNV),
149149
("warp_id_nv", WarpIDNV),
@@ -198,12 +198,12 @@ const EXECUTION_MODELS: &[(&str, ExecutionModel)] = {
198198
("kernel", Kernel),
199199
("task_nv", TaskNV),
200200
("mesh_nv", MeshNV),
201-
("ray_generation_nv", RayGenerationNV),
202-
("intersection_nv", IntersectionNV),
203-
("any_hit_nv", AnyHitNV),
204-
("closest_hit_nv", ClosestHitNV),
205-
("miss_nv", MissNV),
206-
("callable_nv", CallableNV),
201+
("ray_generation_khr", RayGenerationNV),
202+
("intersection_khr", IntersectionNV),
203+
("any_hit_khr", AnyHitNV),
204+
("closest_hit_khr", ClosestHitNV),
205+
("miss_khr", MissNV),
206+
("callable_khr", CallableNV),
207207
]
208208
};
209209

@@ -334,6 +334,10 @@ impl Symbols {
334334
"sampler",
335335
SpirvAttribute::IntrinsicType(IntrinsicType::Sampler),
336336
),
337+
(
338+
"acceleration_structure_khr",
339+
SpirvAttribute::IntrinsicType(IntrinsicType::AccelerationStructureKhr),
340+
),
337341
("block", SpirvAttribute::Block),
338342
("flat", SpirvAttribute::Flat),
339343
("invariant", SpirvAttribute::Invariant),

0 commit comments

Comments
 (0)