From 4123d42aee69537f6fcede748a5d7b88277ef4af Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 29 Dec 2024 18:39:09 +1100 Subject: functions to destroy objects immediately --- c2.cpp | 2 +- model.cpp | 4 ++-- ui.cpp | 18 +++++++----------- video.cpp | 19 +++++++++++++++++++ video.hpp | 3 +++ 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/c2.cpp b/c2.cpp index b11b769..264f071 100644 --- a/c2.cpp +++ b/c2.cpp @@ -49,7 +49,7 @@ static Buffer_Id upload_verts(Device* dev) { ctx.copy(vbo, stage); dev->submit(ctx); } - dev->destroy_buffer(stage); + dev->destroy_bufferi(stage); return vbo; } diff --git a/model.cpp b/model.cpp index c3d01ac..f102a07 100644 --- a/model.cpp +++ b/model.cpp @@ -114,8 +114,8 @@ Asset* Model_Loader::load(Arena* a, Arena* s, Pack_File* f) { ctx->copy(r->vbo, stage_verts); ctx->copy(r->ibo, stage_indices); dev->submit(*ctx); - dev->destroy_buffer(stage_verts); - dev->destroy_buffer(stage_indices); + dev->destroy_bufferi(stage_verts); + dev->destroy_bufferi(stage_indices); return r; } diff --git a/ui.cpp b/ui.cpp index 47c362c..8264576 100644 --- a/ui.cpp +++ b/ui.cpp @@ -77,10 +77,13 @@ static unsigned font_data[] = { static Texture_Id create_atlas(Device* d, Arena* a) { int x, y; int size = 10 * font_w; - uint8_t* pixels = (uint8_t*)arena_alloc(a, size); - void* bufmem; - Buffer_Id buf; + Buffer_Id buf = d->create_buffer( + size, + Buffer_Flags::copy_src | + Buffer_Flags::cpu_readwrite + ); Texture_Id tex; + uint8_t* pixels = (uint8_t*)d->map_buffer(buf, 0, size); for (y = 0; y < 10; y++) { for (x = 0; x < font_w; x++) { int si = x + y * font_w; @@ -89,13 +92,6 @@ static Texture_Id create_atlas(Device* d, Arena* a) { pixels[si] = bit? 0xff: 0x00; } } - buf = d->create_buffer( - size, - Buffer_Flags::copy_src | - Buffer_Flags::cpu_readwrite - ); - bufmem = d->map_buffer(buf, 0, size); - memcpy(bufmem, pixels, size); d->unmap_buffer(buf); tex = d->create_texture( texture_format_r8i, @@ -104,7 +100,7 @@ static Texture_Id create_atlas(Device* d, Arena* a) { 10, buf ); - d->destroy_buffer(buf); + d->destroy_bufferi(buf); clear_arena(a); return tex; } diff --git a/video.cpp b/video.cpp index 9e9c810..1d71034 100644 --- a/video.cpp +++ b/video.cpp @@ -782,6 +782,7 @@ struct Vertex_Format_Vk { struct Sampler_Vk : public Late_Terminated { VkSampler sampler; + Sampler_Id id; void init(Device_Vk* dev, const Sampler_State& s); void destroy(Device_Vk* dev) override; @@ -2006,6 +2007,11 @@ void Device::destroy_texture(Texture_Id id) { dev->queue_destroy((Texture_Vk*)&dev->get_texture(id)); } +void Device::destroy_texturei(Texture_Id id) { + Device_Vk* dev = (Device_Vk*)this; + ((Texture_Vk*)&dev->get_texture(id))->destroy(dev); +} + void Context::wait() { Context_Vk* ctx = (Context_Vk*)this; Device_Vk* dev = ctx->dev; @@ -3169,6 +3175,12 @@ void Device::destroy_buffer(Buffer_Id id) { dev->queue_destroy(buf); } +void Device::destroy_bufferi(Buffer_Id id) { + Device_Vk* dev = (Device_Vk*)this; + Buffer_Vk* buf = (Buffer_Vk*)&get_buffer(id); + buf->destroy(dev); +} + void* Device::map_buffer( Buffer_Id id, size_t offset, @@ -3288,6 +3300,12 @@ void Device::destroy_sampler(Sampler_Id id) { dev->queue_destroy(&s); } +void Device::destroy_sampleri(Sampler_Id id) { + Device_Vk* dev = (Device_Vk*)this; + Sampler_Vk& s = dev->samplers[id]; + s.destroy(dev); +} + void Shader_Loader::init(Device_Vk* d) { dev = d; } @@ -3557,6 +3575,7 @@ void Sampler_Vk::init(Device_Vk* dev, const Sampler_State& s) { void Sampler_Vk::destroy(Device_Vk* dev) { vkDestroySampler(dev->dev, sampler, &dev->ac); + dev->samplers.remove(id); } void Vram_Allocator::Page::init( diff --git a/video.hpp b/video.hpp index 523ded6..9a5dbe3 100644 --- a/video.hpp +++ b/video.hpp @@ -386,12 +386,14 @@ struct Device { Texture_Id get_depth_target(); Texture& get_texture(Texture_Id id); void destroy_texture(Texture_Id id); + void destroy_texturei(Texture_Id id); Buffer_Id create_buffer(size_t size, int flags); void* map_buffer(Buffer_Id id, size_t offset, size_t size); void unmap_buffer(Buffer_Id id); Buffer& get_buffer(Buffer_Id id); void destroy_buffer(Buffer_Id id); + void destroy_bufferi(Buffer_Id id); Vertex_Format_Id create_vertex_format( const Vertex_Format_Desc& desc @@ -402,6 +404,7 @@ struct Device { Sampler_Id create_sampler(const Sampler_State& state); void destroy_sampler(Sampler_Id id); + void destroy_sampleri(Sampler_Id id); }; struct Context { -- cgit v1.2.3-54-g00ecf