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

Commit e7d68f7

Browse files
authored
Add primitive set of arch instructions (#520)
1 parent 89dc8c6 commit e7d68f7

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

crates/spirv-std/src/arch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use crate::{scalar::Scalar, vector::Vector};
99
#[cfg(feature = "const-generics")]
1010
mod arithmetic;
1111
mod derivative;
12+
mod primitive;
1213

1314
#[cfg(feature = "const-generics")]
1415
pub use arithmetic::*;
1516
pub use derivative::*;
17+
pub use primitive::*;
1618

1719
/// Result is true if any component of `vector` is true, otherwise result is
1820
/// false.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/// Emits the current values of all output variables to the current output
2+
/// primitive. After execution, the values of all output variables
3+
/// are undefined. Requires capability `Geometry`.
4+
///
5+
/// # Safety
6+
/// This instruction must only be used when only one stream is present.
7+
#[spirv_std_macros::gpu_only]
8+
#[doc(alias = "OpEmitVertex")]
9+
#[inline]
10+
pub unsafe fn emit_vertex() {
11+
asm! {
12+
"OpEmitVertex",
13+
}
14+
}
15+
16+
/// Finish the current primitive and start a new one. No vertex is emitted.
17+
/// Requires capability `Geometry`.
18+
///
19+
/// # Safety
20+
/// This instruction must only be used when only one stream is present.
21+
#[spirv_std_macros::gpu_only]
22+
#[doc(alias = "OpEndPrimitive")]
23+
#[inline]
24+
pub unsafe fn end_primitive() {
25+
asm! {
26+
"OpEndPrimitive",
27+
}
28+
}
29+
30+
/// Emits the current values of all output variables to the current output
31+
/// primitive. After execution, the values of all output variables
32+
/// are undefined.
33+
///
34+
/// `STREAM` is the output-primitive stream number.
35+
///
36+
/// Requires capability `GeometryStreams`.
37+
///
38+
/// # Safety
39+
/// This instruction must only be used when multiple streams are present.
40+
#[spirv_std_macros::gpu_only]
41+
#[doc(alias = "OpEmitStreamVertex")]
42+
#[inline]
43+
#[cfg(feature = "const-generics")]
44+
pub unsafe fn emit_stream_vertex<const STREAM: i64>() {
45+
asm! {
46+
"%i64 = OpTypeInt 64 1",
47+
"%stream = OpConstant %i64 {stream}",
48+
"OpEmitStreamVertex %stream",
49+
stream = const STREAM,
50+
}
51+
}
52+
53+
/// Finish the current primitive and start a new one. No vertex is emitted.
54+
///
55+
/// `STREAM` is the output-primitive stream number.
56+
///
57+
/// Requires capability `GeometryStreams`.
58+
///
59+
/// # Safety
60+
/// This instruction must only be used when multiple streams are present.
61+
#[spirv_std_macros::gpu_only]
62+
#[doc(alias = "OpEndStreamPrimitive")]
63+
#[inline]
64+
#[cfg(feature = "const-generics")]
65+
pub unsafe fn end_stream_primitive<const STREAM: i64>() {
66+
asm! {
67+
"%i64 = OpTypeInt 64 1",
68+
"%stream = OpConstant %i64 {stream}",
69+
"OpEndStreamPrimitive %stream",
70+
stream = const STREAM,
71+
}
72+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
3+
#[spirv(geometry(input_lines = 2, output_points = 2))]
4+
pub fn main() {
5+
unsafe {
6+
asm!("OpCapability GeometryStreams");
7+
spirv_std::arch::emit_stream_vertex::<2>();
8+
};
9+
}

tests/ui/arch/emit_vertex.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
3+
#[spirv(geometry(input_lines = 2, output_points = 2))]
4+
pub fn main() {
5+
unsafe {
6+
asm!("OpCapability Geometry");
7+
spirv_std::arch::emit_vertex();
8+
};
9+
}

tests/ui/arch/end_primitive.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
3+
#[spirv(geometry(input_lines = 2, output_points = 2))]
4+
pub fn main() {
5+
unsafe {
6+
asm!("OpCapability Geometry");
7+
spirv_std::arch::end_primitive();
8+
};
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
3+
#[spirv(geometry(input_lines = 2, output_points = 2))]
4+
pub fn main() {
5+
unsafe {
6+
asm!("OpCapability GeometryStreams");
7+
spirv_std::arch::end_stream_primitive::<2>();
8+
};
9+
}

0 commit comments

Comments
 (0)