Skip to content

Commit

Permalink
Add support for SPV_KHR_ray_query
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Apr 1, 2021
1 parent 7f688b8 commit bc58064
Show file tree
Hide file tree
Showing 20 changed files with 599 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ fn trans_intrinsic_type<'tcx>(
IntrinsicType::AccelerationStructureKhr => {
Ok(SpirvType::AccelerationStructureKhr.def(span, cx))
}
IntrinsicType::RayQueryKhr => Ok(SpirvType::RayQueryKhr.def(span, cx)),
IntrinsicType::SampledImage => {
// see SpirvType::sizeof
if ty.size != Size::from_bytes(4) {
Expand Down
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub enum IntrinsicType {
Sampler,
AccelerationStructureKhr,
SampledImage,
RayQueryKhr,
}

// NOTE(eddyb) when adding new `#[spirv(...)]` attributes, the tests found inside
Expand Down
2 changes: 2 additions & 0 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
SpirvType::AccelerationStructureKhr => {
self.fatal("cannot memset acceleration structure")
}
SpirvType::RayQueryKhr => self.fatal("cannot memset ray query"),
}
}

Expand Down Expand Up @@ -294,6 +295,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
SpirvType::AccelerationStructureKhr => {
self.fatal("cannot memset acceleration structure")
}
SpirvType::RayQueryKhr => self.fatal("cannot memset ray query"),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ impl<'tcx> CodegenCx<'tcx> {
.tcx
.sess
.fatal("Cannot create a constant acceleration structure"),
SpirvType::RayQueryKhr => self.tcx.sess.fatal("Cannot create a constant ray query"),
}
}
}
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
| SpirvType::Sampler
| SpirvType::SampledImage { .. }
| SpirvType::AccelerationStructureKhr
| SpirvType::RayQueryKhr
=> TypeKind::Token,
}
}
Expand Down
10 changes: 8 additions & 2 deletions crates/rustc_codegen_spirv/src/spirv_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub enum SpirvType {
image_type: Word,
},
AccelerationStructureKhr,
RayQueryKhr,
}

impl SpirvType {
Expand Down Expand Up @@ -249,6 +250,7 @@ impl SpirvType {
),
Self::Sampler => cx.emit_global().type_sampler(),
Self::AccelerationStructureKhr => cx.emit_global().type_acceleration_structure_khr(),
Self::RayQueryKhr => cx.emit_global().type_ray_query_khr(),
Self::SampledImage { image_type } => cx.emit_global().type_sampled_image(image_type),
};
cx.type_cache.def(result, self);
Expand Down Expand Up @@ -323,7 +325,8 @@ impl SpirvType {
| Self::Opaque { .. }
| Self::RuntimeArray { .. }
| Self::Function { .. }
| Self::AccelerationStructureKhr => return None,
| Self::AccelerationStructureKhr
| Self::RayQueryKhr => return None,

Self::Bool => Size::from_bytes(1),
Self::Integer(width, _) | Self::Float(width) => Size::from_bits(width),
Expand All @@ -346,7 +349,8 @@ impl SpirvType {
Self::Void
| Self::Opaque { .. }
| Self::Function { .. }
| Self::AccelerationStructureKhr => Align::from_bytes(0).unwrap(),
| Self::AccelerationStructureKhr
| Self::RayQueryKhr => Align::from_bytes(0).unwrap(),

Self::Bool => Align::from_bytes(1).unwrap(),
Self::Integer(width, _) | Self::Float(width) => Align::from_bits(width as u64).unwrap(),
Expand Down Expand Up @@ -506,6 +510,7 @@ impl fmt::Debug for SpirvTypePrinter<'_, '_> {
SpirvType::AccelerationStructureKhr => {
f.debug_struct("AccelerationStructureKhr").finish()
}
SpirvType::RayQueryKhr => f.debug_struct("RayQueryKhr").finish(),
};
{
let mut debug_stack = DEBUG_STACK.lock().unwrap();
Expand Down Expand Up @@ -662,6 +667,7 @@ impl SpirvTypePrinter<'_, '_> {
.field("image_type", &self.cx.debug_type(image_type))
.finish(),
SpirvType::AccelerationStructureKhr => f.write_str("AccelerationStructureKhr"),
SpirvType::RayQueryKhr => f.write_str("RayQueryKhr"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/spirv_type_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
| Op::RayQueryGetWorldRayDirectionKHR
| Op::RayQueryGetWorldRayOriginKHR
| Op::RayQueryGetIntersectionObjectToWorldKHR
| Op::RayQueryGetIntersectionWorldToObjectKHR => reserved!(SPV_KHR_ray_query),
| Op::RayQueryGetIntersectionWorldToObjectKHR => {}

// Instructions not present in current SPIR-V specification
// SPV_INTEL_function_pointers
Expand Down
4 changes: 4 additions & 0 deletions crates/rustc_codegen_spirv/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ impl Symbols {
"acceleration_structure_khr",
SpirvAttribute::IntrinsicType(IntrinsicType::AccelerationStructureKhr),
),
(
"ray_query_khr",
SpirvAttribute::IntrinsicType(IntrinsicType::RayQueryKhr),
),
("block", SpirvAttribute::Block),
("flat", SpirvAttribute::Flat),
("invariant", SpirvAttribute::Invariant),
Expand Down
Loading

0 comments on commit bc58064

Please sign in to comment.