From cf51bccc9a4fdcfbab928837c49508b5ac571c20 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Tue, 20 Oct 2026 05:29:16 +0100 Subject: [PATCH] Add shader --- src/shaders/shader.slang | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/shaders/shader.slang diff --git a/src/shaders/shader.slang b/src/shaders/shader.slang new file mode 100644 index 0000000..7675541 --- /dev/null +++ b/src/shaders/shader.slang @@ -0,0 +1,49 @@ +static float2 positions[3] = float2[]( + float2( 0.0, -0.5), + float2( 0.5, 0.5), + float2(-0.5, 0.5), +); + +static float3 colors[3] = float3[]( + float3(1.0, 0.0, 0.0), + float3(0.0, 1.0, 0.0), + float3(0.0, 0.0, 1.0), +); + +struct VertexOutput { + float3 color; + float4 sv_position : SV_Position; +}; + +[shader("vertex")] +VertexOutput vertMain(uint vid : SV_VertexID) { + VertexOutput output; + output.color = colors[vid]; + output.sv_position = float4(positions[vid], 0.0, 1.0); + return output; +} + +[shader("fragment")] +float4 fragMain(VertexOutput inVert) : SV_Target { + return float4(inVert.color, 1.0); +} + +[[vk::binding(0, 0)]] +StructuredBuffer a; + +[[vk::binding(1, 0)]] +StructuredBuffer b; + +[[vk::binding(2, 0)]] +RWStructuredBuffer result; + +[[vk::push_constant]] +uniform uint count; + +[shader("compute")] +[numthreads(64, 1, 1)] +void compMain(uint tid : SV_DispatchThreadID) { + if (tid < count) { + result[tid] = a[tid] + b[tid]; + } +}