diff options
author | quou <quou@disroot.org> | 2025-01-09 20:38:16 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-01-09 20:38:16 +1100 |
commit | a51515008fcddfd0c8fdd3beac539801f4183ca1 (patch) | |
tree | 3462f19e590e394d2fa2f6db820febcb4fd8c7ac | |
parent | 93ceef3808bb3f9fa2bf9ad0df576be1e2f9cf2e (diff) |
simplify texture transitions
-rw-r--r-- | video.cpp | 78 |
1 files changed, 12 insertions, 66 deletions
@@ -3,7 +3,6 @@ #define device_heap_size (1024 * 1024 * 8) #define max_textures 1024 -#define max_texture_alias 32 #define max_buffers 1024 #define max_vertex_formats 64 #define max_rpos 64 @@ -671,8 +670,6 @@ struct Texture_Vk : public Texture, public Late_Terminated { Vram_Allocator::Allocation memory; Resource_State state; Texture_Id parent; - Texture_Id children[max_texture_alias]; - int child_count; static void init( Texture_Vk* t, @@ -695,9 +692,6 @@ struct Texture_Vk : public Texture, public Late_Terminated { ); void destroy(Device_Vk*) override; void set_name(Device_Vk* dev, const char* name); - void add_child(Texture_Id id); - void rem_child(Texture_Id id); - bool child_states_same(Device_Vk* dev); }; struct Buffer_Vk : public Buffer, public Late_Terminated { @@ -2383,35 +2377,17 @@ void Context::transition(Texture_Id id, Resource_State state) { Device_Vk* dev = ctx->dev; Texture_Vk& tex = *(Texture_Vk*)&dev->get_texture(id); VkImageMemoryBarrier b{}; - int c = tex.child_count; VkImageLayout src_layout = state_to_image_layout(tex.state); VkImageLayout dst_layout = state_to_image_layout(state); VkPipelineStageFlags src_stage, dst_stage; - if (c) { - if (tex.child_states_same(dev)) { - tex.state = - ((Texture_Vk*)&dev->get_texture(tex.children[0]))->state; - src_layout = state_to_image_layout(tex.state); - } else { - ctx->check_end_rp(); - int i; - for (i = 0; i < c; i++) { - transition(tex.children[i], state); - } - tex.state = state; - return; - } + if (tex.parent) { + transition(tex.parent, state); + tex.state = state; + return; } if (tex.state == state) return; ctx->check_end_rp(); - tex.state = state; { - int i; - for (i = 0; i < c; i++) { - Texture_Vk& child = - *(Texture_Vk*)&dev->get_texture(tex.children[i]); - child.state = state; - } - } + tex.state = state; b.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; b.oldLayout = src_layout; b.newLayout = dst_layout; @@ -2576,6 +2552,9 @@ std::pair<Renderpass_Vk&, Framebuffer_Vk&> Context_Vk::begin_rp( for (i = 0; i < c; i++) { VkClearValue clear{}; const auto& tar = rp.colours[i]; + auto& tex = *(Texture_Vk*)&dev->get_texture(tar.id); + if (tex.parent) + transition(tex.id, render_target); const auto col = tar.clear.colour; clear.color.float32[0] = (float)col.r / 255.0f; clear.color.float32[1] = (float)col.g / 255.0f; @@ -2585,6 +2564,9 @@ std::pair<Renderpass_Vk&, Framebuffer_Vk&> Context_Vk::begin_rp( } if (has_depth) { VkClearValue dc{}; + auto& tex = *(Texture_Vk*)&dev->get_texture(rp.depth.id); + if (tex.parent) + transition(tex.id, render_target); dc.depthStencil.depth = rp.depth.clear.depth; dc.depthStencil.stencil = 0; /* todo */ clears[clear_count++] = dc; @@ -3789,7 +3771,7 @@ Texture_Id Device::alias_texture( texture.image, view, Vram_Allocator::Allocation::null(), - Resource_State::undefined, + texture.state, fmt, flags, w, @@ -3801,7 +3783,6 @@ Texture_Id Device::alias_texture( start_array, true ); - texture.add_child(ntid); nt.set_name(dev, name); return ntid; } @@ -3825,37 +3806,6 @@ void Texture_Vk::set_name(Device_Vk* dev, const char* name) { #endif } -void Texture_Vk::add_child(Texture_Id id) { - assert(child_count < max_texture_alias); - children[child_count++] = id; -} - -void Texture_Vk::rem_child(Texture_Id id) { - int i; - for (i = 0; i < child_count; i++) { - if (children[i] == id) { - children[i] = children[child_count - 1]; - return; - } - } -} - -bool Texture_Vk::child_states_same(Device_Vk* dev) { - int i, c = child_count; - bool r = true; - for (i = 0; i < c; i++) { - Texture_Vk& a = - *(Texture_Vk*)&dev->get_texture(children[i]); - int j; - for (j = i + 1; j < c; j++) { - Texture_Vk& b = - *(Texture_Vk*)&dev->get_texture(children[j]); - if (a.state != b.state) r = false; - } - } - return r; -} - Shader& Device::get_shader(Shader_Id id) { Device_Vk* dev = (Device_Vk*)this; assert(id.index); @@ -4137,10 +4087,6 @@ void Texture_Vk::destroy(Device_Vk* dev) { vkDestroyImage(dev->dev, image, &dev->ac); dev->vrama.free(memory); } - if (parent) { - Texture_Vk& t = *(Texture_Vk*)&dev->get_texture(parent); - t.rem_child(id); - } vkDestroyImageView(dev->dev, view, &dev->ac); dev->textures.remove(id); } |