|
10 | 10 | // we are going to use raw Vulkan here to initialize VK_EXT_mesh_shader |
11 | 11 | #include <lvk/vulkan/VulkanUtils.h> |
12 | 12 |
|
| 13 | +const char* codeSlang = R"( |
| 14 | +struct VertexOutput { |
| 15 | + float4 sv_Position : SV_Position; |
| 16 | + float3 color : COLOR0; |
| 17 | +}; |
| 18 | +
|
| 19 | +struct PrimitiveOutput { |
| 20 | + bool sv_CullPrimitive : SV_CullPrimitive; |
| 21 | +}; |
| 22 | +
|
| 23 | +struct MeshPayload { |
| 24 | + uint unused; |
| 25 | +}; |
| 26 | +
|
| 27 | +[shader("amplification")] |
| 28 | +[numthreads(1, 1, 1)] |
| 29 | +void taskMain() { |
| 30 | + MeshPayload p; |
| 31 | + DispatchMesh(1, 1, 1, p); // Slang requires the payload arg |
| 32 | +} |
| 33 | +
|
| 34 | +[shader("mesh")] |
| 35 | +[numthreads(1, 1, 1)] |
| 36 | +[outputtopology("triangle")] |
| 37 | +void meshMain( |
| 38 | + in payload MeshPayload meshPayload, |
| 39 | + OutputVertices<VertexOutput, 3> verts, |
| 40 | + OutputIndices<uint3, 1> triangles, |
| 41 | + OutputPrimitives<PrimitiveOutput, 1> primitives) |
| 42 | +{ |
| 43 | + const float2 pos[3] = { |
| 44 | + float2(-0.6, -0.4), |
| 45 | + float2( 0.6, -0.4), |
| 46 | + float2( 0.0, 0.6) |
| 47 | + }; |
| 48 | +
|
| 49 | + const float3 col[3] = { |
| 50 | + float3(1.0, 0.0, 0.0), |
| 51 | + float3(0.0, 1.0, 0.0), |
| 52 | + float3(0.0, 0.0, 1.0) |
| 53 | + }; |
| 54 | +
|
| 55 | + SetMeshOutputCounts(3, 1); |
| 56 | +
|
| 57 | + for (uint i = 0; i < 3; i++) { |
| 58 | + verts[i].sv_Position = float4(pos[i], 0.0, 1.0); |
| 59 | + verts[i].color = col[i]; |
| 60 | + } |
| 61 | +
|
| 62 | + primitives[0].sv_CullPrimitive = false; |
| 63 | + triangles[0] = uint3(0, 1, 2); |
| 64 | +} |
| 65 | +
|
| 66 | +[shader("fragment")] |
| 67 | +float4 fragmentMain(VertexOutput input) : SV_Target { |
| 68 | + return float4(input.color, 1.0); |
| 69 | +} |
| 70 | +)"; |
| 71 | + |
13 | 72 | const char* codeTask = R"( |
14 | 73 | layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; |
15 | 74 |
|
@@ -83,9 +142,15 @@ VULKAN_APP_MAIN { |
83 | 142 |
|
84 | 143 | lvk::IContext* ctx = app.ctx_.get(); |
85 | 144 |
|
| 145 | +#if defined(LVK_DEMO_WITH_SLANG) |
| 146 | + res.task_ = ctx->createShaderModule({codeSlang, lvk::Stage_Task, "Shader Module: main (task)"}); |
| 147 | + res.mesh_ = ctx->createShaderModule({codeSlang, lvk::Stage_Mesh, "Shader Module: main (mesh)"}); |
| 148 | + res.frag_ = ctx->createShaderModule({codeSlang, lvk::Stage_Frag, "Shader Module: main (frag)"}); |
| 149 | +#else |
86 | 150 | res.task_ = ctx->createShaderModule({codeTask, lvk::Stage_Task, "Shader Module: main (task)"}); |
87 | 151 | res.mesh_ = ctx->createShaderModule({codeMesh, lvk::Stage_Mesh, "Shader Module: main (mesh)"}); |
88 | 152 | res.frag_ = ctx->createShaderModule({codeFrag, lvk::Stage_Frag, "Shader Module: main (frag)"}); |
| 153 | +#endif // defined(LVK_DEMO_WITH_SLANG) |
89 | 154 |
|
90 | 155 | res.renderPipelineState_Triangle_ = ctx->createRenderPipeline( |
91 | 156 | { |
|
0 commit comments