Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/spirv_type_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ pub fn instruction_signatures(op: Op) -> Option<&'static [InstSig<'static>]> {
// SPV_AMD_shader_fragment_mask
Op::FragmentMaskFetchAMD | Op::FragmentFetchAMD => reserved!(SPV_AMD_shader_fragment_mask),
// SPV_KHR_shader_clock
Op::ReadClockKHR => reserved!(SPV_KHR_shader_clock),
Op::ReadClockKHR => {}
// SPV_NV_mesh_shader
Op::WritePackedPrimitiveIndices4x8NV => reserved!(SPV_NV_mesh_shader),
// SPV_NV_ray_tracing
Expand Down
23 changes: 23 additions & 0 deletions crates/spirv-std/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,26 @@ pub unsafe fn vector_insert_dynamic<T: Scalar, V: Vector<T, N>, const N: usize>(
pub fn kill() -> ! {
unsafe { asm!("OpKill", options(noreturn)) }
}

/// Read from the shader clock.
///
/// Requires the `SPV_KHR_shader_clock` extension and the `ShaderClockKHR` capability.
///
/// See:
/// <https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_shader_clock.html>
#[spirv_std_macros::gpu_only]
#[doc(alias = "OpReadClockKHR")]
pub unsafe fn read_clock_khr() -> u64 {
let mut result: u64 = 0;

asm! {
"%uint = OpTypeInt 32 0",
"%scope = OpConstant %uint {scope}",
"%result = OpReadClockKHR typeof*{result} %scope",
"OpStore {result} %result",
result = in(reg) &mut result,
scope = const crate::memory::Scope::Subgroup as _,
};

result
}