@@ -64,30 +64,32 @@ more control over the entire pipeline by letting them directly process batches o
64
64
vertices and primitives in compute-like shaders. This allows for more efficient culling,
65
65
level-of-detail calculations, and custom pipeline logic—all on the GPU.
66
66
67
- An example of a Rust GPU mesh shader that outputs points :
67
+ An example of a Rust GPU mesh shader that outputs a triangle :
68
68
69
69
```
70
70
use spirv_std::arch::set_mesh_outputs_ext;
71
- use spirv_std::glam::{UVec2 , Vec4};
71
+ use spirv_std::glam::{UVec3 , Vec4};
72
72
use spirv_std::spirv;
73
73
74
74
#[spirv(mesh_ext(
75
75
threads(1),
76
- output_vertices = 1 ,
76
+ output_vertices = 3 ,
77
77
output_primitives_ext = 1,
78
- output_points
78
+ output_triangles_ext
79
79
))]
80
80
pub fn main(
81
- #[spirv(position)] positions: &mut [Vec4; 1 ],
82
- #[spirv(primitive_point_indices_ext )] indices: &mut [u32 ; 1],
81
+ #[spirv(position)] positions: &mut [Vec4; 3 ],
82
+ #[spirv(primitive_triangle_indices_ext )] indices: &mut [UVec3 ; 1],
83
83
) {
84
84
unsafe {
85
- set_mesh_outputs_ext(1 , 1);
85
+ set_mesh_outputs_ext(3 , 1);
86
86
}
87
87
88
88
positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0);
89
+ positions[1] = Vec4::new(0.5, 0.5, 0.0, 1.0);
90
+ positions[2] = Vec4::new(0.0, -0.5, 0.0, 1.0);
89
91
90
- indices[0] = 0 ;
92
+ indices[0] = UVec3::new(0, 1, 2) ;
91
93
}
92
94
```
93
95
@@ -110,39 +112,21 @@ pub fn main() {
110
112
[ @Firestar99 ] ( https://github.com/firestar99 ) also added support for subgroups via
111
113
[ subgroup intrinsics] ( https://github.com/Rust-GPU/rust-gpu/pull/14 ) .
112
114
113
- [ Subgroups] ( https://www.khronos.org/blog/vulkan-subgroup-tutorial ) are small groups of
114
- threads within a workgroup that can share data and perform synchronized operations more
115
+ [ Subgroups] ( https://www.khronos.org/blog/vulkan-subgroup-tutorial ) allow a group of
116
+ threads of vendor-defined size to share data and perform synchronized operations more
115
117
efficiently. For example, using subgroup intrinsics you can:
116
118
117
119
- Perform reductions (e.g., sum, min, max) across threads in a subgroup.
118
120
- Share intermediate results without relying on global memory, reducing latency.
119
121
- Implement algorithms like prefix sums or parallel sorting more effectively.
120
122
121
- Here is a simple Rust GPU example to demonstrate subgroup reduction:
122
-
123
- ``` rust
124
- use glam :: UVec3 ;
125
- use spirv_std :: spirv;
126
-
127
- unsafe fn subgroup_i_add_reduce (value : u32 ) -> u32 {
128
- spirv_std :: arch :: subgroup_i_add (value )
129
- }
130
-
131
- #[spirv(compute(threads(32, 1, 1)))]
132
- pub fn main (#[spirv (local_invocation_id )] local_invocation_id : UVec3 ) {
133
- unsafe {
134
- subgroup_i_add_reduce (local_invocation_id . x);
135
- }
136
- }
137
- ```
138
-
139
123
## Added ` TypedBuffer `
140
124
141
125
[ @eddyb ] ( https://github.com/eddyb ) and [ @Firestar99 ] ( https://github.com/firestar99 )
142
126
[ introduced ` TypedBuffer ` ] ( https://github.com/Rust-GPU/rust-gpu/pull/16 ) , an explicit
143
127
way to declare inputs and outputs as buffers. This enables declaring an "array of buffer
144
- descriptors containing something" as is common in [ bindless
145
- textures ] ( https://computergraphics.stackexchange.com/questions/10794/binding-vs-bindless ) .
128
+ descriptors containing something" as is common in
129
+ [ bindless ] ( https://computergraphics.stackexchange.com/questions/10794/binding-vs-bindless ) .
146
130
147
131
Here is an example of using
148
132
[ ` TypedBuffer ` ] ( https://rust-gpu.github.io/rust-gpu/api/spirv_std/struct.TypedBuffer.html )
0 commit comments