From 143b94cc3edd303fecbfcb846582722297d0eef9 Mon Sep 17 00:00:00 2001 From: harrand Date: Thu, 22 Jun 2023 02:04:29 +0100 Subject: [PATCH] - Removed resource_access::static_fixed, dynamic_fixed and dynamic_variable. Now, static_access and dynamic_access should only ever be used. resources should now always be resizeable, but static_access can only be written to via a renderer edit --- demo/gl/tz_bloom_demo.cpp | 4 ++-- demo/gl/tz_blur_triangle_demo.cpp | 2 +- demo/gl/tz_gpu_driven_demo.cpp | 2 +- src/tz/gl/api/resource.hpp | 6 ------ src/tz/gl/impl/vulkan/component.cpp | 15 +-------------- src/tz/gl/resource.cpp | 7 ++----- test/gl/tz_renderer_test.cpp | 16 ++++++++-------- test/gl/tz_resource_test.cpp | 12 ++++++------ 8 files changed, 21 insertions(+), 43 deletions(-) diff --git a/demo/gl/tz_bloom_demo.cpp b/demo/gl/tz_bloom_demo.cpp index 1adf987b53..85161728cb 100644 --- a/demo/gl/tz_bloom_demo.cpp +++ b/demo/gl/tz_bloom_demo.cpp @@ -68,7 +68,7 @@ int main() tz::gl::buffer_resource bloom_data_buffer = tz::gl::buffer_resource::from_one(BloomOptions{}, { - .access = tz::gl::resource_access::dynamic_fixed + .access = tz::gl::resource_access::dynamic_access }); tz::gl::renderer_info combine_info; @@ -84,7 +84,7 @@ int main() // Firstly draw some shapes. Brighter pixels are written into a second colour attachment tz::gl::buffer_resource render_data = tz::gl::buffer_resource::from_one(RenderData{}, { - .access = tz::gl::resource_access::dynamic_fixed + .access = tz::gl::resource_access::dynamic_access }); tz::gl::renderer_info rinfo; diff --git a/demo/gl/tz_blur_triangle_demo.cpp b/demo/gl/tz_blur_triangle_demo.cpp index a73d144e28..d2cd6134bc 100644 --- a/demo/gl/tz_blur_triangle_demo.cpp +++ b/demo/gl/tz_blur_triangle_demo.cpp @@ -28,7 +28,7 @@ int main() tz::gl::buffer_resource blur_data = tz::gl::buffer_resource::from_one(BlurData{}, { - .access = tz::gl::resource_access::dynamic_fixed + .access = tz::gl::resource_access::dynamic_access }); tz::gl::image_resource blur_image = tz::gl::image_resource::from_uninitialised ({ diff --git a/demo/gl/tz_gpu_driven_demo.cpp b/demo/gl/tz_gpu_driven_demo.cpp index cff5f14274..44230c6973 100644 --- a/demo/gl/tz_gpu_driven_demo.cpp +++ b/demo/gl/tz_gpu_driven_demo.cpp @@ -28,7 +28,7 @@ int main() })); tz::gl::resource_handle count_bufh = cinfo.add_resource(tz::gl::buffer_resource::from_one(std::uint32_t{1}, { - .access = tz::gl::resource_access::dynamic_fixed + .access = tz::gl::resource_access::dynamic_access })); cinfo.shader().set_shader(tz::gl::shader_stage::compute, ImportedShaderSource(tz_gpu_driven_demo, compute)); cinfo.debug_name("Compute Driver"); diff --git a/src/tz/gl/api/resource.hpp b/src/tz/gl/api/resource.hpp index 502de4e8b7..fc11a7c0c2 100644 --- a/src/tz/gl/api/resource.hpp +++ b/src/tz/gl/api/resource.hpp @@ -63,12 +63,6 @@ namespace tz::gl static_access, /// - resource data can be modified at anytime. dynamic_access, - /// - resource data is written once initially, and cannot be resized. - static_fixed, - /// - resource data is always writable, but cannot be resized. - dynamic_fixed, - /// - resource data is always writeable and resizeable. - dynamic_variable, Count }; diff --git a/src/tz/gl/impl/vulkan/component.cpp b/src/tz/gl/impl/vulkan/component.cpp index 965fd73827..eda0b3ff7f 100644 --- a/src/tz/gl/impl/vulkan/component.cpp +++ b/src/tz/gl/impl/vulkan/component.cpp @@ -32,7 +32,6 @@ namespace tz::gl void buffer_component_vulkan::resize(std::size_t sz) { - //tz::assert(this->resource->get_access() == resource_access::dynamic_variable, "Attempted to resize buffer_component_vulkan, but it not resource_access::dynamic_variable. Please submit a bug report."); // Let's create a new buffer of the correct size. vk2::Buffer& old_buf = this->vk_get_buffer(); vk2::Buffer new_buf @@ -98,16 +97,10 @@ namespace tz::gl default: tz::error("Unrecognised resource_access. Please submit a bug report."); [[fallthrough]]; - case resource_access::static_fixed: - [[fallthrough]]; case resource_access::static_access: usage_field |= vk2::BufferUsage::TransferDestination; residency = vk2::MemoryResidency::GPU; break; - case resource_access::dynamic_fixed: - [[fallthrough]]; - case resource_access::dynamic_variable: - [[fallthrough]]; case resource_access::dynamic_access: residency = vk2::MemoryResidency::CPUPersistent; break; @@ -161,7 +154,7 @@ namespace tz::gl std::string debug_name = this->image.debug_get_name(); this->image = make_image(); this->image.debug_set_name(debug_name); - if(ires->get_access() != tz::gl::resource_access::static_fixed) + if(ires->get_access() != tz::gl::resource_access::static_access) { // After that, let's re-validate the resource data span. It will still have undefined contents for now. auto new_data = this->vk_get_image().map_as(); @@ -208,15 +201,9 @@ namespace tz::gl default: tz::error("Unknown resource_access. Please submit a bug report."); [[fallthrough]]; - case resource_access::static_fixed: - [[fallthrough]]; case resource_access::static_access: residency = vk2::MemoryResidency::GPU; break; - case resource_access::dynamic_fixed: - [[fallthrough]]; - case resource_access::dynamic_variable: - [[fallthrough]]; case resource_access::dynamic_access: residency = vk2::MemoryResidency::CPUPersistent; tiling = vk2::ImageTiling::Linear; diff --git a/src/tz/gl/resource.cpp b/src/tz/gl/resource.cpp index 696a26b1d1..d6b28ace29 100644 --- a/src/tz/gl/resource.cpp +++ b/src/tz/gl/resource.cpp @@ -11,15 +11,12 @@ namespace tz::gl { "Static", "Dynamic", - "Static Fixed (Legacy)", - "Dynamic Fixed (Legacy)", - "Dynamic Variable (Legacy)" }; std::array(resource_flag::Count)> resource_flag_strings { "Index Buffer", - "renderer Output", + "Renderer Output", "Image Filter: Nearest", "Image Filter: Linear", "Image Mip Filter: Nearest", @@ -94,7 +91,7 @@ namespace tz::gl // use imgui_memory_editor to display resource data. static MemoryEditor res_mem_edit; static bool show_mem = false; - if(this->access != tz::gl::resource_access::static_fixed && ImGui::Button("Memory Viewer")) + if(this->access != tz::gl::resource_access::static_access && ImGui::Button("Memory Viewer")) { show_mem = true; } diff --git a/test/gl/tz_renderer_test.cpp b/test/gl/tz_renderer_test.cpp index 6103ac03e8..d0a8ae5ac3 100644 --- a/test/gl/tz_renderer_test.cpp +++ b/test/gl/tz_renderer_test.cpp @@ -132,7 +132,7 @@ TESTFUNC_BEGIN(rendereredit_bufferresize) rinfo.shader().set_shader(tz::gl::shader_stage::fragment, ImportedShaderSource(empty, fragment)); tz::gl::resource_handle bh = rinfo.add_resource(tz::gl::buffer_resource::from_one(1.0f, { - .access = tz::gl::resource_access::dynamic_variable + .access = tz::gl::resource_access::dynamic_access })); tz::gl::renderer_handle rh = tz::gl::get_device().create_renderer(rinfo); @@ -183,7 +183,7 @@ TESTFUNC_BEGIN(rendereredit_imageresize) ({ .format = tz::gl::image_format::RGBA32, .dimensions = old_dims, - .access = tz::gl::resource_access::dynamic_variable + .access = tz::gl::resource_access::dynamic_access })); tz::gl::renderer_handle rh = tz::gl::get_device().create_renderer(rinfo); @@ -229,8 +229,8 @@ TESTFUNC_BEGIN(rendereredit_resourcewrite_buffer) rinfo.shader().set_shader(tz::gl::shader_stage::fragment, ImportedShaderSource(empty, fragment)); tz::gl::resource_handle bh = rinfo.add_resource(tz::gl::buffer_resource::from_many(old_data, { - .access = tz::gl::resource_access::dynamic_fixed - // TODO: Test should pass even if static_fixed (right now because component has no mapped data, the default resource data is unchanged so the asserts will fail) + .access = tz::gl::resource_access::dynamic_access + // TODO: Test should pass even if static_access (right now because component has no mapped data, the default resource data is unchanged so the asserts will fail) })); tz::gl::renderer_handle rh = tz::gl::get_device().create_renderer(rinfo); @@ -290,7 +290,7 @@ TESTFUNC_BEGIN(rendereredit_resourcewrite_image) { .format = tz::gl::image_format::RGBA32, .dimensions = {2u, 2u}, - .access = tz::gl::resource_access::dynamic_fixed + .access = tz::gl::resource_access::dynamic_access })); tz::gl::renderer_handle rh = tz::gl::get_device().create_renderer(rinfo); @@ -326,12 +326,12 @@ TESTFUNC_BEGIN(rendereredit_resourcereference_buffer) // create an empty renderer with a buffer resource. buf contains 0.0f tz::gl::renderer_info rinfo1; rinfo1.shader().set_shader(tz::gl::shader_stage::compute, ImportedShaderSource(empty, compute)); - tz::gl::resource_handle bufres = rinfo1.add_resource(tz::gl::buffer_resource::from_one(0.0f, {.access = tz::gl::resource_access::dynamic_fixed})); + tz::gl::resource_handle bufres = rinfo1.add_resource(tz::gl::buffer_resource::from_one(0.0f, {.access = tz::gl::resource_access::dynamic_access})); // create a second empty renderer with buffer resource. buf contains 1.0f tz::gl::renderer_info rinfo2; rinfo2.shader().set_shader(tz::gl::shader_stage::compute, ImportedShaderSource(empty, compute)); - rinfo2.add_resource(tz::gl::buffer_resource::from_one(1.0f, {.access = tz::gl::resource_access::dynamic_fixed})); + rinfo2.add_resource(tz::gl::buffer_resource::from_one(1.0f, {.access = tz::gl::resource_access::dynamic_access})); tz::gl::renderer_handle r1h = tz::gl::get_device().create_renderer(rinfo1); tz::gl::renderer_handle r2h = tz::gl::get_device().create_renderer(rinfo2); @@ -362,7 +362,7 @@ TESTFUNC_END //-------------------------------------------------------------------------------------------------- TESTFUNC_BEGIN(rendereredit_resourcereference_image) - // todo: implement. could simply do the same as buffer, but write the float in dynamic_fixed image memory, but that seems like a pointless test at this point? maybe it isnt? + // todo: implement. could simply do the same as buffer, but write the float in dynamic_access image memory, but that seems like a pointless test at this point? maybe it isnt? TESTFUNC_END //-------------------------------------------------------------------------------------------------- diff --git a/test/gl/tz_resource_test.cpp b/test/gl/tz_resource_test.cpp index 609d7966e6..9bc3788662 100644 --- a/test/gl/tz_resource_test.cpp +++ b/test/gl/tz_resource_test.cpp @@ -62,17 +62,17 @@ void basic_image() void default_arguments_buffer() { auto nullbuf = tz::gl::buffer_resource::null(); - tz::assert(nullbuf.get_access() == tz::gl::resource_access::static_fixed, "Null Buffer must be resource_access::static_fixed, but it is not."); + tz::assert(nullbuf.get_access() == tz::gl::resource_access::static_access, "Null Buffer must be resource_access::static_access, but it is not."); tz::assert(nullbuf.get_flags().empty(), "Null Buffer must not have any flags"); { auto buf = tz::gl::buffer_resource::from_one(1); - tz::assert(buf.get_access() == tz::gl::resource_access::static_fixed, "Defaulted Buffer must be resource_access::static_fixed, but it is not."); + tz::assert(buf.get_access() == tz::gl::resource_access::static_access, "Defaulted Buffer must be resource_access::static_access, but it is not."); tz::assert(buf.get_flags().empty(), "Defaulted Buffer must not have any flags"); } { auto buf = tz::gl::buffer_resource::from_many({1, 2, 3}); - tz::assert(buf.get_access() == tz::gl::resource_access::static_fixed, "Defaulted Buffer must be resource_access::static_fixed, but it is not."); + tz::assert(buf.get_access() == tz::gl::resource_access::static_access, "Defaulted Buffer must be resource_access::static_access, but it is not."); tz::assert(buf.get_flags().empty(), "Defaulted Buffer must not have any flags"); } } @@ -81,12 +81,12 @@ void default_arguments_buffer() void default_arguments_image() { auto nullimg = tz::gl::image_resource::null(); - tz::assert(nullimg.get_access() == tz::gl::resource_access::static_fixed, "Null Image must be resource_access::static_fixed, but it is not."); + tz::assert(nullimg.get_access() == tz::gl::resource_access::static_access, "Null Image must be resource_access::static_access, but it is not."); tz::assert(nullimg.get_flags().empty(), "Null Image must not have any flags"); { auto img = tz::gl::image_resource::from_uninitialised({.format = tz::gl::image_format::RGBA32, .dimensions = {1u, 1u}}); - tz::assert(img.get_access() == tz::gl::resource_access::static_fixed, "Defaulted Image must be resource_access::static_fixed, but it is not."); + tz::assert(img.get_access() == tz::gl::resource_access::static_access, "Defaulted Image must be resource_access::static_access, but it is not."); tz::assert(img.get_flags().empty(), "Defaulted Image must not have any flags"); } { @@ -96,7 +96,7 @@ void default_arguments_image() std::byte{2}, std::byte{3} }, {.format = tz::gl::image_format::RGBA32, .dimensions = {1u, 1u}}); - tz::assert(img.get_access() == tz::gl::resource_access::static_fixed, "Defaulted Image must be resource_access::static_fixed, but it is not."); + tz::assert(img.get_access() == tz::gl::resource_access::static_access, "Defaulted Image must be resource_access::static_access, but it is not."); tz::assert(img.get_flags().empty(), "Defaulted Image must not have any flags"); } }