Skip to content

Commit 158e966

Browse files
committed
Add ifdef to test both HiZ code paths.
1 parent 3e5428a commit 158e966

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tests/meshlet_viewer.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#include <float.h>
4646
#include <stdexcept>
4747

48+
#define FULL_RES 0
49+
4850
using namespace Granite;
4951
using namespace Vulkan;
5052
using namespace Vulkan::Meshlet;
@@ -464,10 +466,18 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
464466

465467
ubo->view = render_context.get_render_parameters().view;
466468
ubo->viewport_scale_bias = viewport_scale_bias;
469+
470+
#if FULL_RES
471+
ubo->hiz_resolution.x = hiz->get_view_width();
472+
ubo->hiz_resolution.y = hiz->get_view_height();
473+
ubo->hiz_min_lod = 0;
474+
ubo->hiz_max_lod = hiz->get_create_info().levels - 1;
475+
#else
467476
ubo->hiz_resolution.x = hiz->get_view_width() * 2;
468477
ubo->hiz_resolution.y = hiz->get_view_height() * 2;
469478
ubo->hiz_min_lod = 1;
470479
ubo->hiz_max_lod = hiz->get_create_info().levels;
480+
#endif
471481
}
472482
};
473483

@@ -807,11 +817,20 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
807817
(depth_view.get_view_width() + 63u) & ~63u,
808818
(depth_view.get_view_height() + 63u) & ~63u,
809819
VK_FORMAT_R32_SFLOAT);
820+
821+
#if !FULL_RES
810822
info.width /= 2;
811823
info.height /= 2;
824+
#endif
825+
812826
info.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
813827
info.initial_layout = VK_IMAGE_LAYOUT_UNDEFINED;
814-
info.levels = Util::floor_log2(max(depth_view.get_view_width(), depth_view.get_view_height())) - 1;
828+
info.levels = Util::floor_log2(max(depth_view.get_view_width(), depth_view.get_view_height()));
829+
830+
#if !FULL_RES
831+
info.levels -= 1;
832+
#endif
833+
815834
info.misc |= IMAGE_MISC_CREATE_PER_MIP_LEVEL_VIEWS_BIT;
816835

817836
auto hiz = device.create_image(info);
@@ -839,17 +858,25 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
839858

840859
Push push = {};
841860
push.z_transform = inv_z;
842-
push.resolution = uvec2(info.width * 2, info.height * 2);
861+
push.resolution = uvec2(info.width, info.height);
862+
#if !FULL_RES
863+
push.resolution *= 2u;
864+
#endif
843865
push.inv_resolution = vec2(1.0f / float(depth_view.get_view_width()), 1.0f / float(depth_view.get_view_height()));
844866
push.mips = info.levels + 1;
845867

846868
uint32_t wg_x = (push.resolution.x + 63) / 64;
847869
uint32_t wg_y = (push.resolution.y + 63) / 64;
848870
push.target_counter = wg_x * wg_y;
849871

850-
cmd->set_program("builtin://shaders/post/hiz.comp");
872+
cmd->set_program("builtin://shaders/post/hiz.comp", {{ "WRITE_TOP_LEVEL", FULL_RES }});
873+
#if FULL_RES
874+
for (unsigned i = 0; i < 13; i++)
875+
cmd->set_storage_texture_level(0, i, hiz->get_view(), i < info.levels ? i : (info.levels - 1));
876+
#else
851877
for (unsigned i = 0; i < 12; i++)
852878
cmd->set_storage_texture_level(0, i + 1, hiz->get_view(), i < info.levels ? i : (info.levels - 1));
879+
#endif
853880
cmd->set_texture(1, 0, depth_view, StockSampler::NearestClamp);
854881
cmd->set_storage_buffer(1, 1, *counter);
855882
cmd->push_constants(&push, 0, sizeof(push));

0 commit comments

Comments
 (0)