Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato committed Dec 26, 2024
1 parent 94e8738 commit 52fe199
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions blog/2024-12-29-rust-gpu-0.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,32 @@ more control over the entire pipeline by letting them directly process batches o
vertices and primitives in compute-like shaders. This allows for more efficient culling,
level-of-detail calculations, and custom pipeline logic—all on the GPU.

An example of a Rust GPU mesh shader that outputs points:
An example of a Rust GPU mesh shader that outputs a triangle:

```
use spirv_std::arch::set_mesh_outputs_ext;
use spirv_std::glam::{UVec2, Vec4};
use spirv_std::glam::{UVec3, Vec4};
use spirv_std::spirv;
#[spirv(mesh_ext(
threads(1),
output_vertices = 1,
output_vertices = 3,
output_primitives_ext = 1,
output_points
output_triangles_ext
))]
pub fn main(
#[spirv(position)] positions: &mut [Vec4; 1],
#[spirv(primitive_point_indices_ext)] indices: &mut [u32; 1],
#[spirv(position)] positions: &mut [Vec4; 3],
#[spirv(primitive_triangle_indices_ext)] indices: &mut [UVec3; 1],
) {
unsafe {
set_mesh_outputs_ext(1, 1);
set_mesh_outputs_ext(3, 1);
}
positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0);
positions[1] = Vec4::new(0.5, 0.5, 0.0, 1.0);
positions[2] = Vec4::new(0.0, -0.5, 0.0, 1.0);
indices[0] = 0;
indices[0] = UVec3::new(0, 1, 2);
}
```

Expand All @@ -110,39 +112,21 @@ pub fn main() {
[@Firestar99](https://github.com/firestar99) also added support for subgroups via
[subgroup intrinsics](https://github.com/Rust-GPU/rust-gpu/pull/14).

[Subgroups](https://www.khronos.org/blog/vulkan-subgroup-tutorial) are small groups of
threads within a workgroup that can share data and perform synchronized operations more
[Subgroups](https://www.khronos.org/blog/vulkan-subgroup-tutorial) allow a group of
threads of vendor-defined size to share data and perform synchronized operations more
efficiently. For example, using subgroup intrinsics you can:

- Perform reductions (e.g., sum, min, max) across threads in a subgroup.
- Share intermediate results without relying on global memory, reducing latency.
- Implement algorithms like prefix sums or parallel sorting more effectively.

Here is a simple Rust GPU example to demonstrate subgroup reduction:

```rust
use glam::UVec3;
use spirv_std::spirv;

unsafe fn subgroup_i_add_reduce(value: u32) -> u32 {
spirv_std::arch::subgroup_i_add(value)
}

#[spirv(compute(threads(32, 1, 1)))]
pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) {
unsafe {
subgroup_i_add_reduce(local_invocation_id.x);
}
}
```

## Added `TypedBuffer`

[@eddyb](https://github.com/eddyb) and [@Firestar99](https://github.com/firestar99)
[introduced `TypedBuffer`](https://github.com/Rust-GPU/rust-gpu/pull/16), an explicit
way to declare inputs and outputs as buffers. This enables declaring an "array of buffer
descriptors containing something" as is common in [bindless
textures](https://computergraphics.stackexchange.com/questions/10794/binding-vs-bindless).
descriptors containing something" as is common in
[bindless](https://computergraphics.stackexchange.com/questions/10794/binding-vs-bindless).

Here is an example of using
[`TypedBuffer`](https://rust-gpu.github.io/rust-gpu/api/spirv_std/struct.TypedBuffer.html)
Expand Down

0 comments on commit 52fe199

Please sign in to comment.