From 90a0afd18f080088cac068d92810fb630225d6be Mon Sep 17 00:00:00 2001 From: ladevieq Date: Wed, 25 Jan 2023 23:06:30 +0100 Subject: Working compute api with uniforms --- shaders/api-test-ui.frag | 20 ++++++++++++++++++++ shaders/api-test-ui.vert | 37 +++++++++++++++++++++++++++++++++++++ shaders/test.comp | 11 ++++++++--- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 shaders/api-test-ui.frag create mode 100644 shaders/api-test-ui.vert (limited to 'shaders') diff --git a/shaders/api-test-ui.frag b/shaders/api-test-ui.frag new file mode 100644 index 0000000..5c6a61f --- /dev/null +++ b/shaders/api-test-ui.frag @@ -0,0 +1,20 @@ +#extension GL_EXT_nonuniform_qualifier : require + +layout(location = 0) out vec4 o_Color; + +layout(location = 0) in struct { + vec2 uv; + vec4 color; +} In; + +layout(set = 0, binding = 0) uniform sampler samplers[]; +layout(set = 0, binding = 1) uniform texture2D textures[]; +layout(set = 0, binding = 2, rgba32f) uniform image2D images[]; +layout(set = 1, binding = 0) uniform parameters { + uint texture_index; + uint sampler_index; +} params; + +void main() { + o_Color = In.color * texture(sampler2D(textures[params.texture_index], samplers[params.sampler_index]), In.uv.xy); +} diff --git a/shaders/api-test-ui.vert b/shaders/api-test-ui.vert new file mode 100644 index 0000000..6a37abc --- /dev/null +++ b/shaders/api-test-ui.vert @@ -0,0 +1,37 @@ +#extension GL_EXT_buffer_reference : require + +struct vertex { + vec2 pos; + vec2 uv; + uint color; + uint[3] padding; +}; + +layout(buffer_reference) readonly buffer vertices { + vertex vertices[]; +}; + +layout(set = 1, binding = 0) uniform parameters { + vertices vertex_buffer; + vec2 scale; + vec2 translate; +} params; + +out gl_PerVertex { + vec4 gl_Position; +}; + +layout(location = 0) out struct { + vec2 uv; + vec4 color; +} Out; + + +void main() { + vertex v = params.vertex_buffer.vertices[gl_VertexIndex]; + + Out.color = unpackUnorm4x8(v.color); + Out.uv = v.uv; + + gl_Position = vec4(v.pos * params.scale + params.translate, 0.0, 1.0); +} diff --git a/shaders/test.comp b/shaders/test.comp index 541cb93..244533e 100644 --- a/shaders/test.comp +++ b/shaders/test.comp @@ -6,13 +6,18 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; layout(set = 0, binding = 0) uniform sampler samplers[]; layout(set = 0, binding = 1) uniform texture2D textures[]; layout(set = 0, binding = 2, rgba32f) uniform image2D images[]; +layout(set = 1, binding = 0) uniform parameters { + uint input_id1; + uint input_id2; + uint output_id; +} params; void main() { ivec2 coords = ivec2(gl_GlobalInvocationID.xy); float t = 0.5; - vec3 color_1 = imageLoad(images[nonuniformEXT(0)], coords).xyz; - vec3 color_2 = imageLoad(images[nonuniformEXT(1)], coords).xyz; + vec3 color_1 = imageLoad(images[nonuniformEXT(params.input_id1)], coords).xyz; + vec3 color_2 = imageLoad(images[nonuniformEXT(params.input_id2)], coords).xyz; vec3 out_color = (t * color_1) + ((1.0 - t) * color_2); - imageStore(images[nonuniformEXT(0)], coords, vec4(out_color, 1.0)); + imageStore(images[nonuniformEXT(params.output_id)], coords, vec4(out_color, 1.0)); } -- cgit v1.3