Skip to content

Commit

Permalink
Fix issues with terminators
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Mar 31, 2021
1 parent e69a8b5 commit 5747b73
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
8 changes: 7 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/new_structurizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ 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 {
merge: block,
merge_id: block_id,
exits: indexmap! {},
Expand Down
8 changes: 7 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/simple_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ pub fn outgoing_edges(block: &Block) -> Vec<Word> {
.map(|op| op.unwrap_id_ref()),
)
.collect(),
Op::Return | Op::ReturnValue | Op::Kill | Op::Unreachable => Vec::new(),
| Op::Return
| Op::ReturnValue
| Op::Kill
| Op::Unreachable
| Op::IgnoreIntersectionKHR
| Op::TerminateRayKHR
=> Vec::new(),
_ => panic!("Invalid block terminator: {:?}", terminator),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/spirv-std/src/arch/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub unsafe fn report_intersection_khr(hit: f32, hit_kind: u32) -> bool {
#[doc(alias = "OpIgnoreIntersectionKHR")]
#[inline]
pub unsafe fn ignore_intersection_khr() {
asm!("OpIgnoreIntersectionKHR");
asm!("OpIgnoreIntersectionKHR", "%unused = OpLabel")
}

/// Terminates the invocation that executes it, stops the ray traversal, accepts
Expand All @@ -145,7 +145,7 @@ pub unsafe fn ignore_intersection_khr() {
#[doc(alias = "OpTerminateRayKHR")]
#[inline]
pub unsafe fn terminate_ray_khr() {
asm!("OpTerminateRayKHR");
asm!("OpTerminateRayKHR", "%unused = OpLabel")
}

/// Invoke a callable shader.
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/arch/terminate_ray_khr.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// build-pass

use spirv_std as _;

#[spirv(any_hit_khr)]
pub fn main() {
unsafe {
asm!(r#"OpExtension "SPV_KHR_ray_tracing""#);
asm!("OpCapability RayTracingKHR", "OpTerminateRayKHR");
asm!("OpCapability RayTracingKHR");
spirv_std::arch::terminate_ray_khr();
}
}

2 changes: 1 addition & 1 deletion tests/ui/arch/trace_ray_khr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[spirv(ray_generation_khr)]
pub fn main(
acceleration_structure: &spirv_std::ray_tracing::AccelerationStructureKhr,
#[spirv(uniform_constant, descriptor_set = 0, binding = 0)] acceleration_structure: &spirv_std::ray_tracing::AccelerationStructureKhr,
#[spirv(ray_payload_khr)] payload: &mut glam::Vec3,
) {
unsafe {
Expand Down

0 comments on commit 5747b73

Please sign in to comment.