Skip to content

Commit d63b3ed

Browse files
BeastLe9enDFirestar99
authored andcommitted
mesh shader ext: compiletest for mesh shaders, from @BeastLe9enD
1 parent cd0cbf6 commit d63b3ed

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// build-pass
2+
// only-vulkan1.2
3+
// compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader
4+
5+
use spirv_std::arch::set_mesh_outputs_ext;
6+
use spirv_std::glam::{UVec2, Vec4};
7+
use spirv_std::spirv;
8+
9+
#[spirv(mesh_ext(
10+
threads(1),
11+
output_vertices = 2,
12+
output_primitives_ext = 1,
13+
output_lines_ext
14+
))]
15+
pub fn main(
16+
#[spirv(position)] positions: &mut [Vec4; 2],
17+
#[spirv(primitive_line_indices_ext)] indices: &mut [UVec2; 1],
18+
) {
19+
unsafe {
20+
set_mesh_outputs_ext(2, 1);
21+
}
22+
23+
positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0);
24+
positions[1] = Vec4::new(0.5, 0.5, 0.0, 1.0);
25+
26+
indices[0] = UVec2::new(0, 1);
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// build-pass
2+
// only-vulkan1.2
3+
// compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader
4+
5+
use spirv_std::arch::set_mesh_outputs_ext;
6+
use spirv_std::glam::{UVec2, Vec4};
7+
use spirv_std::spirv;
8+
9+
#[spirv(mesh_ext(
10+
threads(1),
11+
output_vertices = 1,
12+
output_primitives_ext = 1,
13+
output_points
14+
))]
15+
pub fn main(
16+
#[spirv(position)] positions: &mut [Vec4; 1],
17+
#[spirv(primitive_point_indices_ext)] indices: &mut [u32; 1],
18+
) {
19+
unsafe {
20+
set_mesh_outputs_ext(1, 1);
21+
}
22+
23+
positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0);
24+
25+
indices[0] = 0;
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// build-pass
2+
// only-vulkan1.2
3+
// compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader
4+
5+
use spirv_std::arch::set_mesh_outputs_ext;
6+
use spirv_std::glam::{UVec3, Vec4};
7+
use spirv_std::spirv;
8+
9+
#[spirv(mesh_ext(
10+
threads(1),
11+
output_vertices = 3,
12+
output_primitives_ext = 1,
13+
output_triangles_ext
14+
))]
15+
pub fn main(
16+
#[spirv(position)] positions: &mut [Vec4; 3],
17+
#[spirv(primitive_triangle_indices_ext)] indices: &mut [UVec3; 1],
18+
) {
19+
unsafe {
20+
set_mesh_outputs_ext(3, 1);
21+
}
22+
23+
positions[0] = Vec4::new(-0.5, 0.5, 0.0, 1.0);
24+
positions[1] = Vec4::new(0.5, 0.5, 0.0, 1.0);
25+
positions[2] = Vec4::new(0.0, -0.5, 0.0, 1.0);
26+
27+
indices[0] = UVec3::new(0, 1, 2);
28+
}

tests/ui/arch/mesh_shader_payload.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// build-pass
2+
// only-vulkan1.2
3+
// compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader
4+
5+
use spirv_std::arch::set_mesh_outputs_ext;
6+
use spirv_std::glam::{UVec3, Vec4};
7+
use spirv_std::spirv;
8+
9+
pub struct Payload {
10+
pub first: f32,
11+
pub second: f32,
12+
pub third: f32
13+
}
14+
15+
#[spirv(mesh_ext(
16+
threads(1),
17+
output_vertices = 3,
18+
output_primitives_ext = 1,
19+
output_triangles_ext
20+
))]
21+
pub fn main(
22+
#[spirv(position)] positions: &mut [Vec4; 3],
23+
#[spirv(primitive_triangle_indices_ext)] indices: &mut [UVec3; 1],
24+
#[spirv(task_payload_workgroup_ext)] payload: &Payload
25+
) {
26+
unsafe {
27+
set_mesh_outputs_ext(3, 1);
28+
}
29+
30+
positions[0] = payload.first * Vec4::new(-0.5, 0.5, 0.0, 1.0);
31+
positions[1] = payload.second * Vec4::new(0.5, 0.5, 0.0, 1.0);
32+
positions[2] = payload.third * Vec4::new(0.0, -0.5, 0.0, 1.0);
33+
34+
indices[0] = UVec3::new(0, 1, 2);
35+
}

tests/ui/arch/task_shader.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// build-pass
2+
// only-vulkan1.2
3+
// compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader
4+
5+
use spirv_std::spirv;
6+
use spirv_std::arch::emit_mesh_tasks_ext;
7+
8+
#[spirv(task_ext(threads(1)))]
9+
pub fn main() {
10+
unsafe {
11+
emit_mesh_tasks_ext(1, 2, 3);
12+
}
13+
}

tests/ui/arch/task_shader_payload.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// build-pass
2+
// only-vulkan1.2
3+
// compile-flags: -Ctarget-feature=+MeshShadingEXT,+ext:SPV_EXT_mesh_shader
4+
5+
use spirv_std::spirv;
6+
use spirv_std::arch::emit_mesh_tasks_ext;
7+
8+
pub struct Payload {
9+
pub first: u32,
10+
pub second: i32
11+
}
12+
13+
#[spirv(task_ext(threads(1)))]
14+
pub fn main(#[spirv(task_payload_workgroup_ext)] payload: &mut Payload) {
15+
payload.first = 1;
16+
payload.second = 2;
17+
18+
unsafe {
19+
emit_mesh_tasks_ext(3, 4, 5);
20+
}
21+
}

0 commit comments

Comments
 (0)