Skip to content

Commit 6f7ceac

Browse files
committed
move mod: move read_clock() to mod shader_clock
1 parent 222ed89 commit 6f7ceac

File tree

4 files changed

+57
-47
lines changed

4 files changed

+57
-47
lines changed

crates/spirv-std/src/arch.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::Integer;
88
use crate::{Scalar, SignedInteger, UnsignedInteger, Vector};
99
#[cfg(target_arch = "spirv")]
1010
use core::arch::asm;
11-
use glam::UVec2;
1211

1312
mod atomics;
1413
mod barrier;
@@ -120,51 +119,6 @@ pub unsafe fn vector_insert_dynamic<T: Scalar, V: Vector<T, N>, const N: usize>(
120119
}
121120
}
122121

123-
/// Read from the shader clock with either the `Subgroup` or `Device` scope.
124-
///
125-
/// See:
126-
/// <https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_shader_clock.html>
127-
#[spirv_std_macros::gpu_only]
128-
#[doc(alias = "OpReadClockKHR")]
129-
pub fn read_clock_khr<const SCOPE: u32>() -> u64 {
130-
unsafe {
131-
let mut result: u64;
132-
133-
asm! {
134-
"%uint = OpTypeInt 32 0",
135-
"%scope = OpConstant %uint {scope}",
136-
"{result} = OpReadClockKHR typeof*{result} %scope",
137-
result = out(reg) result,
138-
scope = const SCOPE,
139-
};
140-
141-
result
142-
}
143-
}
144-
145-
/// Like `read_clock_khr` but returns a vector to avoid requiring the `Int64`
146-
/// capability. It returns a 'vector of two-components of 32-bit unsigned
147-
/// integer type with the first component containing the 32 least significant
148-
/// bits and the second component containing the 32 most significant bits.'
149-
#[spirv_std_macros::gpu_only]
150-
#[doc(alias = "OpReadClockKHR")]
151-
pub fn read_clock_uvec2_khr<const SCOPE: u32>() -> UVec2 {
152-
unsafe {
153-
let mut result = UVec2::default();
154-
155-
asm! {
156-
"%uint = OpTypeInt 32 0",
157-
"%scope = OpConstant %uint {scope}",
158-
"%result = OpReadClockKHR typeof*{result} %scope",
159-
"OpStore {result} %result",
160-
result = in(reg) &mut result,
161-
scope = const SCOPE,
162-
};
163-
164-
result
165-
}
166-
}
167-
168122
#[cfg(target_arch = "spirv")]
169123
unsafe fn call_glsl_op_with_ints<T: Integer, const OP: u32>(a: T, b: T) -> T {
170124
unsafe {

crates/spirv-std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ mod runtime_array;
106106
mod sampler;
107107
mod scalar;
108108
mod scalar_or_vector;
109+
pub mod shader_clock;
109110
pub mod subgroup;
110111
pub mod task;
111112
mod typed_buffer;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Intrinsics for reading the shader clock.
2+
//!
3+
//! GLSL: [`GL_EXT_shader_realtime_clock`](https://github.com/KhronosGroup/GLSL/blob/main/extensions/ext/GL_EXT_shader_realtime_clock.txt)
4+
//! SPIRV: [`SPV_KHR_shader_clock`](https://github.khronos.org/SPIRV-Registry/extensions/KHR/SPV_KHR_shader_clock.html)
5+
6+
#[cfg(target_arch = "spirv")]
7+
use core::arch::asm;
8+
use glam::UVec2;
9+
10+
/// Read from the shader clock with either the `Subgroup` or `Device` scope.
11+
///
12+
/// See: <https://github.khronos.org/SPIRV-Registry/extensions/KHR/SPV_KHR_shader_clock.html>
13+
#[spirv_std_macros::gpu_only]
14+
#[doc(alias = "OpReadClockKHR")]
15+
pub fn read_clock_khr<const SCOPE: u32>() -> u64 {
16+
unsafe {
17+
let mut result: u64;
18+
19+
asm! {
20+
"%uint = OpTypeInt 32 0",
21+
"%scope = OpConstant %uint {scope}",
22+
"{result} = OpReadClockKHR typeof*{result} %scope",
23+
result = out(reg) result,
24+
scope = const SCOPE,
25+
};
26+
27+
result
28+
}
29+
}
30+
31+
/// Like `read_clock_khr` but returns a vector to avoid requiring the `Int64`
32+
/// capability. It returns a 'vector of two-components of 32-bit unsigned
33+
/// integer type with the first component containing the 32 least significant
34+
/// bits and the second component containing the 32 most significant bits.'
35+
///
36+
/// See:
37+
/// <https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/KHR/SPV_KHR_shader_clock.html>
38+
#[spirv_std_macros::gpu_only]
39+
#[doc(alias = "OpReadClockKHR")]
40+
pub fn read_clock_uvec2_khr<const SCOPE: u32>() -> UVec2 {
41+
unsafe {
42+
let mut result = UVec2::default();
43+
44+
asm! {
45+
"%uint = OpTypeInt 32 0",
46+
"%scope = OpConstant %uint {scope}",
47+
"%result = OpReadClockKHR typeof*{result} %scope",
48+
"OpStore {result} %result",
49+
result = in(reg) &mut result,
50+
scope = const SCOPE,
51+
};
52+
53+
result
54+
}
55+
}

tests/compiletests/ui/arch/read_clock_khr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use glam::UVec2;
55
use spirv_std::spirv;
66
use spirv_std::{
7-
arch::{read_clock_khr, read_clock_uvec2_khr},
87
memory::Scope,
8+
shader_clock::{read_clock_khr, read_clock_uvec2_khr},
99
};
1010

1111
#[spirv(fragment)]

0 commit comments

Comments
 (0)