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 27, 2021
1 parent ec131ca commit d6c0480
Show file tree
Hide file tree
Showing 21 changed files with 669 additions and 1 deletion.
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 @@ -791,6 +791,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 @@ -239,6 +239,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 @@ -299,6 +300,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/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
image_type: inst.operands[0].unwrap_id_ref(),
}
.def(self.span(), self),
Op::TypeRayQueryKHR => SpirvType::RayQueryKhr.def(self.span(), self),
Op::Variable if inst.operands[0].unwrap_storage_class() != StorageClass::Function => {
// OpVariable with Function storage class should be emitted inside the function,
// however, all other OpVariables should appear in the global scope instead.
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 @@ -534,6 +534,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 @@ -179,6 +179,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
| SpirvType::Sampler
| SpirvType::SampledImage { .. }
| SpirvType::AccelerationStructureKhr
| SpirvType::RayQueryKhr
=> TypeKind::Token,
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/rustc_codegen_spirv/src/spirv_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub enum SpirvType {
},

AccelerationStructureKhr,
RayQueryKhr,
}

impl SpirvType {
Expand Down Expand Up @@ -251,6 +252,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),

Self::InterfaceBlock { inner_type } => {
Expand Down Expand Up @@ -352,6 +354,7 @@ impl SpirvType {
Self::Pointer { .. } => cx.tcx.data_layout.pointer_size,
Self::Image { .. }
| Self::AccelerationStructureKhr
| Self::RayQueryKhr
| Self::Sampler
| Self::SampledImage { .. } => Size::from_bytes(4),

Expand Down Expand Up @@ -383,6 +386,7 @@ impl SpirvType {
Self::Pointer { .. } => cx.tcx.data_layout.pointer_align.abi,
Self::Image { .. }
| Self::AccelerationStructureKhr
| Self::RayQueryKhr
| Self::Sampler
| Self::SampledImage { .. } => Align::from_bytes(4).unwrap(),

Expand Down Expand Up @@ -529,6 +533,7 @@ impl fmt::Debug for SpirvTypePrinter<'_, '_> {
.field("inner_type", &self.cx.debug_type(inner_type))
.finish(),
SpirvType::AccelerationStructureKhr => f.debug_struct("AccelerationStructure").finish(),
SpirvType::RayQueryKhr => f.debug_struct("RayQuery").finish(),
};
{
let mut debug_stack = DEBUG_STACK.lock().unwrap();
Expand Down Expand Up @@ -684,6 +689,7 @@ impl SpirvTypePrinter<'_, '_> {
f.write_str(" }")
}
SpirvType::AccelerationStructureKhr => f.write_str("AccelerationStructureKhr"),
SpirvType::RayQueryKhr => f.write_str("RayQuery"),
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/rustc_codegen_spirv/src/spirv_type_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,10 @@ 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 => {
// NOTE(eddyb) we actually use these despite not being in the standard yet.
// reserved!(SPV_KHR_ray_query)
}

// 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 @@ -321,6 +321,10 @@ impl Symbols {
"acceleration_structure",
SpirvAttribute::IntrinsicType(IntrinsicType::AccelerationStructureKhr),
),
(
"ray_query",
SpirvAttribute::IntrinsicType(IntrinsicType::RayQueryKhr),
),
("block", SpirvAttribute::Block),
("flat", SpirvAttribute::Flat),
("invariant", SpirvAttribute::Invariant),
Expand Down
Loading

0 comments on commit d6c0480

Please sign in to comment.