From d4b041743f8343e4e47e04bc6b135d5d94124f53 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 17 Sep 2024 06:13:54 +0300 Subject: [PATCH] fix pipeline cleanup --- .gitignore | 1 + Makefile | 4 ++-- sdr/sdr.p.glsl | 10 ++++++++++ sdr/sdr.v.glsl | 26 ++++++++++++++++++++++++++ src/app.c | 16 +++++++++++++--- src/vk.c | 19 ++++++++++++++++++- 6 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 sdr/sdr.p.glsl create mode 100644 sdr/sdr.v.glsl diff --git a/.gitignore b/.gitignore index 5f30f93..9bab0d3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ vktest *.vcxproj.user vktest3/ x64/ +*.spv diff --git a/Makefile b/Makefile index d7c439b..f7c00ca 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,10 @@ LDFLAGS = -lvulkan -lX11 -lX11-xcb $(bin): $(obj) $(spirv) $(CC) -o $@ $(obj) $(LDFLAGS) -%.spv: %.v.glsl +%.v.spv: %.v.glsl glslangValidator -o $@ -S vert -V $< -%.spv: %.p.glsl +%.p.spv: %.p.glsl glslangValidator -o $@ -S frag -V $< -include $(dep) diff --git a/sdr/sdr.p.glsl b/sdr/sdr.p.glsl new file mode 100644 index 0000000..a04f99a --- /dev/null +++ b/sdr/sdr.p.glsl @@ -0,0 +1,10 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +layout(location = 0) in vec3 incol; +layout(location = 0) out vec4 outcol; + +void main() +{ + outcol = vec4(incol, 1.0); +} diff --git a/sdr/sdr.v.glsl b/sdr/sdr.v.glsl new file mode 100644 index 0000000..3a60cbe --- /dev/null +++ b/sdr/sdr.v.glsl @@ -0,0 +1,26 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +out gl_PerVertex { + vec4 gl_Position; +}; + +layout(location = 0) out vec3 color; + +vec2 vpos[3] = vec2[]( + vec2(0.0, -0.5), + vec2(0.5, 0.5), + vec2(-0.5, 0.5) +); + +vec3 vcol[3] = vec3[]( + vec3(1.0, 0.0, 0.0), + vec3(0.0, 1.0, 0.0), + vec3(0.0, 0.0, 1.0) +); + +void main() +{ + gl_Position = vec4(vpos[gl_VertexIndex], 0.0, 1.0); + color = vcol[gl_VertexIndex]; +} diff --git a/src/app.c b/src/app.c index c242b32..4bece43 100644 --- a/src/app.c +++ b/src/app.c @@ -20,6 +20,7 @@ static int *fb; static struct frame frame[NUM_FRM]; static VkSemaphore sem_draw; static VkQueue queue; +static VkShaderModule vsdr, psdr; int app_init(void) { @@ -74,6 +75,13 @@ int app_init(void) vk_pipeln_rpass(pipeln, vk_rpass(rpass)); vk_pipeln_viewport(pipeln, 0, 0, win_width, win_height); + if(!(vsdr = vk_load_shader("sdr/sdr.v.spv")) || !(psdr = vk_load_shader("sdr/sdr.p.spv"))) { + fprintf(stderr, "failed to load shaders\n"); + return -1; + } + vk_pipeln_shader(pipeln, VKSDR_VERTEX, vsdr); + vk_pipeln_shader(pipeln, VKSDR_PIXEL, psdr); + sem_draw = vk_create_sem(); return 0; } @@ -89,6 +97,9 @@ void app_cleanup(void) } vk_free_rpass(rpass); + vk_free_shader(vsdr); + vk_free_shader(psdr); + for(i=0; i= darr_size(pipelines)) { return; } + if(!pipelines[pp].used) { + return; + } + + if(pipelines[pp].vkobj_layout) { + vkDestroyPipelineLayout(vkdev, pipelines[pp].vkobj_layout, 0); + pipelines[pp].vkobj_layout = 0; + } - if(pipelines[pp].used && pipelines[pp].vkobj) { + if(pipelines[pp].vkobj) { vkDestroyPipeline(vkdev, pipelines[pp].vkobj, 0); + pipelines[pp].vkobj = 0; } pipelines[pp].used = 0; } -- 1.7.10.4