|
45 | 45 | #include <float.h>
|
46 | 46 | #include <stdexcept>
|
47 | 47 |
|
| 48 | +#define FULL_RES 0 |
| 49 | + |
48 | 50 | using namespace Granite;
|
49 | 51 | using namespace Vulkan;
|
50 | 52 | using namespace Vulkan::Meshlet;
|
@@ -464,10 +466,18 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
|
464 | 466 |
|
465 | 467 | ubo->view = render_context.get_render_parameters().view;
|
466 | 468 | 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 |
467 | 476 | ubo->hiz_resolution.x = hiz->get_view_width() * 2;
|
468 | 477 | ubo->hiz_resolution.y = hiz->get_view_height() * 2;
|
469 | 478 | ubo->hiz_min_lod = 1;
|
470 | 479 | ubo->hiz_max_lod = hiz->get_create_info().levels;
|
| 480 | +#endif |
471 | 481 | }
|
472 | 482 | };
|
473 | 483 |
|
@@ -807,11 +817,20 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
|
807 | 817 | (depth_view.get_view_width() + 63u) & ~63u,
|
808 | 818 | (depth_view.get_view_height() + 63u) & ~63u,
|
809 | 819 | VK_FORMAT_R32_SFLOAT);
|
| 820 | + |
| 821 | +#if !FULL_RES |
810 | 822 | info.width /= 2;
|
811 | 823 | info.height /= 2;
|
| 824 | +#endif |
| 825 | + |
812 | 826 | info.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
813 | 827 | 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 | + |
815 | 834 | info.misc |= IMAGE_MISC_CREATE_PER_MIP_LEVEL_VIEWS_BIT;
|
816 | 835 |
|
817 | 836 | auto hiz = device.create_image(info);
|
@@ -839,17 +858,25 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //
|
839 | 858 |
|
840 | 859 | Push push = {};
|
841 | 860 | 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 |
843 | 865 | push.inv_resolution = vec2(1.0f / float(depth_view.get_view_width()), 1.0f / float(depth_view.get_view_height()));
|
844 | 866 | push.mips = info.levels + 1;
|
845 | 867 |
|
846 | 868 | uint32_t wg_x = (push.resolution.x + 63) / 64;
|
847 | 869 | uint32_t wg_y = (push.resolution.y + 63) / 64;
|
848 | 870 | push.target_counter = wg_x * wg_y;
|
849 | 871 |
|
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 |
851 | 877 | for (unsigned i = 0; i < 12; i++)
|
852 | 878 | cmd->set_storage_texture_level(0, i + 1, hiz->get_view(), i < info.levels ? i : (info.levels - 1));
|
| 879 | +#endif |
853 | 880 | cmd->set_texture(1, 0, depth_view, StockSampler::NearestClamp);
|
854 | 881 | cmd->set_storage_buffer(1, 1, *counter);
|
855 | 882 | cmd->push_constants(&push, 0, sizeof(push));
|
|
0 commit comments