Skip to content

Commit e8cf216

Browse files
committed
Add descriptorindexing rust shader
1 parent 28d62eb commit e8cf216

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

shaders/rust/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shaders/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ members = [
2626
"deferred/deferred",
2727
"deferred/mrt",
2828
"descriptorbuffer/cube",
29+
"descriptorindexing",
2930
"descriptorsets/cube",
3031
"distancefieldfonts/bitmap",
3132
"distancefieldfonts/sdf",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "descriptorindexing"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[lib]
7+
crate-type = ["dylib"]
8+
9+
[dependencies]
10+
spirv-std = { workspace = true }
11+
12+
[package.metadata.rust-gpu.build]
13+
capabilities = ["RuntimeDescriptorArray", "ShaderNonUniform"]
Binary file not shown.
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![no_std]
2+
3+
use spirv_std::spirv;
4+
use spirv_std::{glam::{vec4, Mat4, Vec2, Vec3, Vec4}, Image, RuntimeArray};
5+
use spirv_std::image::SampledImage;
6+
7+
#[repr(C)]
8+
pub struct Matrices {
9+
pub projection: Mat4,
10+
pub view: Mat4,
11+
pub model: Mat4,
12+
}
13+
14+
#[spirv(vertex)]
15+
pub fn main_vs(
16+
#[spirv(vertex_index)] _vertex_index: i32,
17+
in_pos: Vec3,
18+
in_uv: Vec2,
19+
in_texture_index: i32,
20+
#[spirv(uniform, descriptor_set = 0, binding = 0)] matrices: &Matrices,
21+
#[spirv(position)] out_pos: &mut Vec4,
22+
out_uv: &mut Vec2,
23+
#[spirv(flat)] out_tex_index: &mut i32,
24+
) {
25+
*out_uv = in_uv;
26+
*out_tex_index = in_texture_index;
27+
let pos = vec4(in_pos.x, in_pos.y, in_pos.z, 1.0);
28+
*out_pos = matrices.projection * matrices.view * matrices.model * pos;
29+
}
30+
31+
#[spirv(fragment)]
32+
pub fn main_fs(
33+
in_uv: Vec2,
34+
#[spirv(flat)] in_tex_index: i32,
35+
#[spirv(descriptor_set = 0, binding = 1)] textures: &RuntimeArray<SampledImage<Image!(2D, type=f32, sampled)>>,
36+
out_frag_color: &mut Vec4,
37+
) {
38+
unsafe {
39+
let texture = textures.index(in_tex_index as usize);
40+
*out_frag_color = texture.sample(in_uv);
41+
}
42+
}

0 commit comments

Comments
 (0)