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

Commit 5504a1e

Browse files
committed
Add support for SPV_KHR_ray_tracing
1 parent fc8efd4 commit 5504a1e

File tree

22 files changed

+344
-38
lines changed

22 files changed

+344
-38
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 = "7c72c65" }
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/linker/new_structurizer.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ impl Structurizer<'_> {
168168
let block_id = self.func.blocks()[block].label_id().unwrap();
169169
let terminator = self.func.blocks()[block].instructions.last().unwrap();
170170
let mut region = match terminator.class.opcode {
171-
Op::Return | Op::ReturnValue | Op::Kill | Op::Unreachable => Region {
171+
Op::Return
172+
| Op::ReturnValue
173+
| Op::Kill
174+
| Op::IgnoreIntersectionKHR
175+
| Op::TerminateRayKHR
176+
| Op::Unreachable => Region {
172177
merge: block,
173178
merge_id: block_id,
174179
exits: indexmap! {},

crates/rustc_codegen_spirv/src/linker/simple_passes.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ pub fn outgoing_edges(block: &Block) -> Vec<Word> {
9898
.map(|op| op.unwrap_id_ref()),
9999
)
100100
.collect(),
101-
Op::Return | Op::ReturnValue | Op::Kill | Op::Unreachable => Vec::new(),
101+
Op::Return
102+
| Op::ReturnValue
103+
| Op::Kill
104+
| Op::Unreachable
105+
| Op::IgnoreIntersectionKHR
106+
| Op::TerminateRayKHR => Vec::new(),
102107
_ => panic!("Invalid block terminator: {:?}", terminator),
103108
}
104109
}

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
}

0 commit comments

Comments
 (0)