Skip to content

Commit

Permalink
- Removed resource_access::static_fixed, dynamic_fixed and dynamic_va…
Browse files Browse the repository at this point in the history
…riable. 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
  • Loading branch information
harrand committed Jun 22, 2023
1 parent 5369e8a commit 143b94c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 43 deletions.
4 changes: 2 additions & 2 deletions demo/gl/tz_bloom_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion demo/gl/tz_blur_triangle_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
({
Expand Down
2 changes: 1 addition & 1 deletion demo/gl/tz_gpu_driven_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 0 additions & 6 deletions src/tz/gl/api/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
15 changes: 1 addition & 14 deletions src/tz/gl/impl/vulkan/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::byte>();
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions src/tz/gl/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ namespace tz::gl
{
"Static",
"Dynamic",
"Static Fixed (Legacy)",
"Dynamic Fixed (Legacy)",
"Dynamic Variable (Legacy)"
};

std::array<const char*, static_cast<int>(resource_flag::Count)> resource_flag_strings
{
"Index Buffer",
"renderer Output",
"Renderer Output",
"Image Filter: Nearest",
"Image Filter: Linear",
"Image Mip Filter: Nearest",
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions test/gl/tz_renderer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

//--------------------------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions test/gl/tz_resource_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand All @@ -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");
}
{
Expand All @@ -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");
}
}
Expand Down

0 comments on commit 143b94c

Please sign in to comment.