fixed vulkan validation errors

This commit is contained in:
Alessandro Mauri 2025-06-19 15:24:46 +02:00
parent 5b0169cd94
commit cd83c528ee
3 changed files with 23 additions and 7 deletions

View File

@ -7,7 +7,7 @@ layout(set = 1, binding = 0) uniform Viewport {
layout(location = 0) in ivec2 position; layout(location = 0) in ivec2 position;
layout(location = 1) in ivec4 attr; // quad x,y,w,h layout(location = 1) in ivec4 attr; // quad x,y,w,h
layout(location = 2) in ivec2 uv; // x,y in the texture layout(location = 2) in ivec2 uv; // x,y in the texture
layout(location = 3) in ivec4 color; layout(location = 3) in uvec4 color;
layout(location = 0) out vec4 out_color; layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_quad_size; layout(location = 1) out vec4 out_quad_size;

View File

@ -7,7 +7,7 @@ layout(set = 1, binding = 0) uniform Viewport {
layout(location = 0) in ivec2 position; layout(location = 0) in ivec2 position;
layout(location = 1) in ivec4 attr; // quad x,y,w,h layout(location = 1) in ivec4 attr; // quad x,y,w,h
layout(location = 2) in ivec2 in_uv; layout(location = 2) in ivec2 in_uv;
layout(location = 3) in ivec4 color; layout(location = 3) in uvec4 color;
layout(location = 0) out vec2 out_uv; layout(location = 0) out vec2 out_uv;
layout(location = 1) out vec4 out_color; layout(location = 1) out vec4 out_color;

View File

@ -86,7 +86,7 @@ struct Renderer {
Id sprite_atlas_id; Id sprite_atlas_id;
Id font_atlas_id; Id font_atlas_id;
uint scissor_x, scissor_y, scissor_w, scissor_h; int scissor_x, scissor_y, scissor_w, scissor_h;
} }
// How each vertex is represented in the gpu // How each vertex is represented in the gpu
@ -291,7 +291,18 @@ fn void Renderer.free(&self)
} }
self.pipelines.free(); self.pipelines.free();
// FIXME: release the quad buffer foreach (&t: self.textures) {
sdl::release_gpu_texture(self.gpu, t.texture);
sdl::release_gpu_sampler(self.gpu, t.sampler);
}
self.textures.free();
QuadBuffer* qb = &self.quad_buffer;
sdl::unmap_gpu_transfer_buffer(self.gpu, qb.attr_ts);
sdl::release_gpu_transfer_buffer(self.gpu, qb.attr_ts);
sdl::release_gpu_buffer(self.gpu, qb.vert_buf);
sdl::release_gpu_buffer(self.gpu, qb.idx_buf);
sdl::release_gpu_buffer(self.gpu, qb.attr_buf);
sdl::release_window_from_gpu_device(self.gpu, self.win); sdl::release_window_from_gpu_device(self.gpu, self.win);
sdl::destroy_gpu_device(self.gpu); sdl::destroy_gpu_device(self.gpu);
@ -377,12 +388,14 @@ fn void Renderer.load_spirv_shader_from_file(&self, String name, String vert_pat
char[] frag_code; char[] frag_code;
// create vertex shader // create vertex shader
vert_code = mem::new_array(char, file::get_size(vert_path)!!+1); usz size = file::get_size(vert_path)!!;
vert_code = mem::new_array(char, size + size%4);
file::load_buffer(vert_path, vert_code)!!; file::load_buffer(vert_path, vert_code)!!;
defer mem::free(vert_code); defer mem::free(vert_code);
// create fragment shader // create fragment shader
frag_code = mem::new_array(char, file::get_size(frag_path)!!+1); size = file::get_size(frag_path)!!;
frag_code = mem::new_array(char, size + size%4);
file::load_buffer(frag_path, frag_code)!!; file::load_buffer(frag_path, frag_code)!!;
defer mem::free(frag_code); defer mem::free(frag_code);
@ -810,8 +823,11 @@ fn void Renderer.bind_texture(&self, String texture_name)
); );
} }
fn void Renderer.set_scissor(&self, uint x, uint y, uint w, uint h) fn void Renderer.set_scissor(&self, int x, int y, int w, int h)
{ {
// in vulkan scissor size must be positive, clamp to zero
w = max(w, 0);
h = max(h, 0);
sdl::set_gpu_scissor(self.render_pass, &&(sdl::Rect){x,y,w,h}); sdl::set_gpu_scissor(self.render_pass, &&(sdl::Rect){x,y,w,h});
} }