Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SPV_KHR_ray_tracing #563

Merged
merged 7 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ syn = { version = "1", features = ["visit", "visit-mut"] }
# Normal dependencies.
bimap = "0.6"
indexmap = "1.6.0"
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "ee1e913" }
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "719cf08" }
rustc-demangle = "0.1.18"
sanitize-filename = "0.3"
serde = { version = "1.0", features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,9 @@ fn trans_intrinsic_type<'tcx>(
}
Ok(SpirvType::Sampler.def(span, cx))
}
IntrinsicType::AccelerationStructureKhr => {
Ok(SpirvType::AccelerationStructureKhr.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 @@ -71,6 +71,7 @@ pub enum IntrinsicType {
access_qualifier: Option<AccessQualifier>,
},
Sampler,
AccelerationStructureKhr,
SampledImage,
}

Expand Down
6 changes: 6 additions & 0 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
SpirvType::Sampler => self.fatal("cannot memset sampler"),
SpirvType::SampledImage { .. } => self.fatal("cannot memset sampled image"),
SpirvType::InterfaceBlock { .. } => self.fatal("cannot memset interface block"),
SpirvType::AccelerationStructureKhr => {
self.fatal("cannot memset acceleration structure")
}
}
}

Expand Down Expand Up @@ -293,6 +296,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
SpirvType::Sampler => self.fatal("cannot memset sampler"),
SpirvType::SampledImage { .. } => self.fatal("cannot memset sampled image"),
SpirvType::InterfaceBlock { .. } => self.fatal("cannot memset interface block"),
SpirvType::AccelerationStructureKhr => {
self.fatal("cannot memset acceleration structure")
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ impl<'tcx> CodegenCx<'tcx> {
.tcx
.sess
.fatal("Cannot create a constant interface block value"),
SpirvType::AccelerationStructureKhr => self
.tcx
.sess
.fatal("Cannot create a constant acceleration structure"),
}
}
}
5 changes: 4 additions & 1 deletion crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ impl<'tcx> CodegenCx<'tcx> {
let spirv_ty = self.layout_of(value_ty).spirv_type(hir_param.ty_span, self);
// Some types automatically specify a storage class. Compute that here.
let inferred_storage_class_from_ty = match self.lookup_type(spirv_ty) {
SpirvType::Image { .. } | SpirvType::Sampler | SpirvType::SampledImage { .. } => {
SpirvType::Image { .. }
| SpirvType::Sampler
| SpirvType::SampledImage { .. }
| SpirvType::AccelerationStructureKhr => {
if is_ref {
Some(StorageClass::UniformConstant)
} else {
Expand Down
8 changes: 5 additions & 3 deletions crates/rustc_codegen_spirv/src/codegen_cx/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> {
SpirvType::Function { .. } => TypeKind::Function,
// HACK(eddyb) this is probably the closest `TypeKind` (which is still
// very much LLVM-specific, sadly) has to offer to "resource handle".
SpirvType::Image { .. } | SpirvType::Sampler | SpirvType::SampledImage { .. } => {
TypeKind::Token
}
| SpirvType::Image { .. }
| SpirvType::Sampler
| SpirvType::SampledImage { .. }
| SpirvType::AccelerationStructureKhr
=> TypeKind::Token,
}
}
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type {
Expand Down
12 changes: 9 additions & 3 deletions crates/rustc_codegen_spirv/src/linker/new_structurizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ struct Region {
/// After structurizing a region, all paths through it must lead to a single
/// "merge" block (i.e. `merge` post-dominates the entire region).
/// The `merge` block must be terminated by one of `OpReturn`, `OpReturnValue`,
/// `OpKill`, or `OpUnreachable`. If `exits` isn't empty, `merge` will
/// receive an `OpBranch` from its parent region (to an outer merge block).
/// `OpKill`, `OpIgnoreIntersectionKHR`, `OpTerminateRayKHR` or
/// `OpUnreachable`. If `exits` isn't empty, `merge` will receive an
/// `OpBranch` from its parent region (to an outer merge block).
merge: BlockIdx,
merge_id: BlockId,

Expand Down Expand Up @@ -168,7 +169,12 @@ impl Structurizer<'_> {
let block_id = self.func.blocks()[block].label_id().unwrap();
let terminator = self.func.blocks()[block].instructions.last().unwrap();
let mut region = match terminator.class.opcode {
Op::Return | Op::ReturnValue | Op::Kill | Op::Unreachable => Region {
Op::Return
| Op::ReturnValue
| Op::Kill
| Op::IgnoreIntersectionKHR
| Op::TerminateRayKHR
| Op::Unreachable => Region {
XAMPPRocky marked this conversation as resolved.
Show resolved Hide resolved
merge: block,
merge_id: block_id,
exits: indexmap! {},
Expand Down
7 changes: 6 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/simple_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ pub fn outgoing_edges(block: &Block) -> impl Iterator<Item = Word> + '_ {
Op::Branch => (0..1).step_by(1),
Op::BranchConditional => (1..3).step_by(1),
Op::Switch => (1..terminator.operands.len()).step_by(2),
Op::Return | Op::ReturnValue | Op::Kill | Op::Unreachable => (0..0).step_by(1),
Op::Return
| Op::ReturnValue
| Op::Kill
| Op::Unreachable
| Op::IgnoreIntersectionKHR
| Op::TerminateRayKHR => (0..0).step_by(1),
_ => panic!("Invalid block terminator: {:?}", terminator),
};
operand_indices.map(move |i| terminator.operands[i].unwrap_id_ref())
Expand Down
19 changes: 13 additions & 6 deletions crates/rustc_codegen_spirv/src/spirv_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub enum SpirvType {
InterfaceBlock {
inner_type: Word,
},

AccelerationStructureKhr,
}

impl SpirvType {
Expand Down Expand Up @@ -248,6 +250,7 @@ impl SpirvType {
access_qualifier,
),
Self::Sampler => cx.emit_global().type_sampler(),
Self::AccelerationStructureKhr => cx.emit_global().type_acceleration_structure_khr(),
Self::SampledImage { image_type } => cx.emit_global().type_sampled_image(image_type),

Self::InterfaceBlock { inner_type } => {
Expand Down Expand Up @@ -347,7 +350,10 @@ impl SpirvType {
cx.lookup_type(element).sizeof(cx)? * cx.builder.lookup_const_u64(count).unwrap()
}
Self::Pointer { .. } => cx.tcx.data_layout.pointer_size,
Self::Image { .. } | Self::Sampler | Self::SampledImage { .. } => Size::from_bytes(4),
Self::Image { .. }
| Self::AccelerationStructureKhr
| Self::Sampler
| Self::SampledImage { .. } => Size::from_bytes(4),

Self::InterfaceBlock { inner_type } => cx.lookup_type(inner_type).sizeof(cx)?,
};
Expand Down Expand Up @@ -375,9 +381,10 @@ impl SpirvType {
cx.lookup_type(element).alignof(cx)
}
Self::Pointer { .. } => cx.tcx.data_layout.pointer_align.abi,
Self::Image { .. } | Self::Sampler | Self::SampledImage { .. } => {
Align::from_bytes(4).unwrap()
}
Self::Image { .. }
| Self::AccelerationStructureKhr
| Self::Sampler
| Self::SampledImage { .. } => Align::from_bytes(4).unwrap(),

Self::InterfaceBlock { inner_type } => cx.lookup_type(inner_type).alignof(cx),
}
Expand Down Expand Up @@ -516,12 +523,12 @@ impl fmt::Debug for SpirvTypePrinter<'_, '_> {
.field("id", &self.id)
.field("image_type", &self.cx.debug_type(image_type))
.finish(),

SpirvType::InterfaceBlock { inner_type } => f
.debug_struct("InterfaceBlock")
.field("id", &self.id)
.field("inner_type", &self.cx.debug_type(inner_type))
.finish(),
SpirvType::AccelerationStructureKhr => f.debug_struct("AccelerationStructure").finish(),
};
{
let mut debug_stack = DEBUG_STACK.lock().unwrap();
Expand Down Expand Up @@ -671,12 +678,12 @@ impl SpirvTypePrinter<'_, '_> {
.debug_struct("SampledImage")
.field("image_type", &self.cx.debug_type(image_type))
.finish(),

SpirvType::InterfaceBlock { inner_type } => {
f.write_str("interface block { ")?;
ty(self.cx, stack, f, inner_type)?;
f.write_str(" }")
}
SpirvType::AccelerationStructureKhr => f.write_str("AccelerationStructureKhr"),
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions crates/rustc_codegen_spirv/src/spirv_type_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,21 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
| Op::ExecuteCallableKHR
| Op::ConvertUToAccelerationStructureKHR
| Op::IgnoreIntersectionKHR
| Op::TerminateRayKHR => reserved!(SPV_KHR_ray_tracing),
| Op::TerminateRayKHR => {
// NOTE(eddyb) we actually use these despite not being in the standard yet.
// reserved!(SPV_KHR_ray_tracing)
}
// SPV_KHR_ray_query
Op::TypeRayQueryKHR
| Op::RayQueryInitializeKHR
| Op::RayQueryTerminateKHR
| Op::RayQueryGenerateIntersectionKHR
| Op::RayQueryConfirmIntersectionKHR
| Op::RayQueryProceedKHR
| Op::RayQueryGetIntersectionTypeKHR => reserved!(SPV_KHR_ray_query),
| Op::RayQueryGetIntersectionTypeKHR => {
// NOTE(eddyb) we actually use these despite not being in the standard yet.
// reserved!(SPV_KHR_ray_query)
}
// SPV_AMD_shader_fragment_mask
Op::FragmentMaskFetchAMD | Op::FragmentFetchAMD => reserved!(SPV_AMD_shader_fragment_mask),
// SPV_KHR_shader_clock
Expand All @@ -748,7 +754,10 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
| Op::TerminateRayNV
| Op::TraceNV
| Op::TypeAccelerationStructureNV
| Op::ExecuteCallableNV => reserved!(SPV_NV_ray_tracing),
| Op::ExecuteCallableNV => {
// NOTE(eddyb) Some KHR variants are aliased to the the NV instructions.
// reserved!(SPV_NV_ray_tracing)
}
// SPV_NV_cooperative_matrix
Op::TypeCooperativeMatrixNV
| Op::CooperativeMatrixLoadNV
Expand Down
Loading