Skip to content

Commit b09e4cf

Browse files
committed
const generics: emit inline asm directly to not rely on failing generic_const_exprs
1 parent 384b62d commit b09e4cf

4 files changed

Lines changed: 353 additions & 29 deletions

File tree

crates/spirv-std/nightly/src/arch.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,41 @@ pub use barrier::{control_barrier, memory_barrier};
1111
pub use spirv_std::arch::*;
1212

1313
use crate::glam::UVec2;
14+
#[cfg(target_arch = "spirv")]
15+
use core::arch::asm;
1416
use spirv_std::memory::Scope;
1517

1618
/// See [`spirv_std::arch::read_clock_khr`]
1719
#[spirv_std_macros::gpu_only]
1820
#[doc(alias = "OpReadClockKHR")]
1921
pub fn read_clock_khr<const SCOPE: Scope>() -> u64 {
20-
spirv_std::arch::read_clock_khr::<{ SCOPE as u32 }>()
22+
unsafe {
23+
let mut result: u64;
24+
asm! {
25+
"%uint = OpTypeInt 32 0",
26+
"%scope = OpConstant %uint {scope}",
27+
"{result} = OpReadClockKHR typeof*{result} %scope",
28+
result = out(reg) result,
29+
scope = const SCOPE as u32,
30+
};
31+
result
32+
}
2133
}
2234

2335
/// See [`spirv_std::arch::read_clock_uvec2_khr`]
2436
#[spirv_std_macros::gpu_only]
2537
#[doc(alias = "OpReadClockKHR")]
2638
pub fn read_clock_uvec2_khr<const SCOPE: Scope>() -> UVec2 {
27-
spirv_std::arch::read_clock_uvec2_khr::<{ SCOPE as u32 }>()
39+
unsafe {
40+
let mut result = UVec2::default();
41+
asm! {
42+
"%uint = OpTypeInt 32 0",
43+
"%scope = OpConstant %uint {scope}",
44+
"%result = OpReadClockKHR typeof*{result} %scope",
45+
"OpStore {result} %result",
46+
result = in(reg) &mut result,
47+
scope = const SCOPE as u32,
48+
};
49+
result
50+
}
2851
}

0 commit comments

Comments
 (0)