From 36fa7059edda0ff9347cd600490a078c2e363ed8 Mon Sep 17 00:00:00 2001 From: notSanil <44319106+notSanil@users.noreply.github.com> Date: Thu, 10 Mar 2022 23:13:27 +0530 Subject: [PATCH] Fix device limit exceeding for uniform buffer --- drivers/vulkan/rendering_device_vulkan.cpp | 2 +- drivers/vulkan/rendering_device_vulkan.h | 2 +- .../renderer_rd/renderer_canvas_render_rd.cpp | 2 +- .../rendering/renderer_rd/renderer_compositor_rd.cpp | 2 +- servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp | 10 +++++----- servers/rendering/renderer_rd/renderer_storage_rd.cpp | 2 +- servers/rendering/rendering_device.h | 2 +- servers/rendering/shader_language.cpp | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index b86b5f15795..642d94b8115 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -9295,7 +9295,7 @@ String RenderingDeviceVulkan::get_captured_timestamp_name(uint32_t p_index) cons return frames[frame].timestamp_result_names[p_index]; } -int RenderingDeviceVulkan::limit_get(Limit p_limit) { +uint64_t RenderingDeviceVulkan::limit_get(Limit p_limit) { switch (p_limit) { case LIMIT_MAX_BOUND_UNIFORM_SETS: return limits.maxBoundDescriptorSets; diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 126f6f8ad02..a4d5af91a44 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -1203,7 +1203,7 @@ public: /**** Limits ****/ /****************/ - virtual int limit_get(Limit p_limit); + virtual uint64_t limit_get(Limit p_limit); virtual void prepare_screen_for_drawing(); void initialize(VulkanContext *p_context, bool p_local_device = false); diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index 38234cf0e7e..a7411b75ca3 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -2257,7 +2257,7 @@ RendererCanvasRenderRD::RendererCanvasRenderRD(RendererStorageRD *p_storage) { String global_defines; - uint32_t uniform_max_size = RD::get_singleton()->limit_get(RD::LIMIT_MAX_UNIFORM_BUFFER_SIZE); + uint64_t uniform_max_size = RD::get_singleton()->limit_get(RD::LIMIT_MAX_UNIFORM_BUFFER_SIZE); if (uniform_max_size < 65536) { //Yes, you guessed right, ARM again state.max_lights_per_render = 64; diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp index e8978e7dcae..67bafc1972f 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp @@ -287,7 +287,7 @@ RendererCompositorRD::RendererCompositorRD() { canvas = memnew(RendererCanvasRenderRD(storage)); back_end = (bool)(int)GLOBAL_GET("rendering/vulkan/rendering/back_end"); - uint32_t textures_per_stage = RD::get_singleton()->limit_get(RD::LIMIT_MAX_TEXTURES_PER_SHADER_STAGE); + uint64_t textures_per_stage = RD::get_singleton()->limit_get(RD::LIMIT_MAX_TEXTURES_PER_SHADER_STAGE); if (back_end || textures_per_stage < 48) { scene = memnew(RendererSceneRenderImplementation::RenderForwardMobile(storage)); diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index 8f0e1d36db8..dd19b6cc4a8 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -2453,7 +2453,7 @@ void RendererSceneGIRD::VoxelGIInstance::update(bool p_update_light_instances, c passes = 1; //only re-blitting is necessary } int wg_size = 64; - int wg_limit_x = RD::get_singleton()->limit_get(RD::LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X); + uint64_t wg_limit_x = RD::get_singleton()->limit_get(RD::LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X); for (int pass = 0; pass < passes; pass++) { if (p_update_light_instances) { @@ -2476,9 +2476,9 @@ void RendererSceneGIRD::VoxelGIInstance::update(bool p_update_light_instances, c push_constant.cell_offset = mipmaps[i].cell_offset; push_constant.cell_count = mipmaps[i].cell_count; - int wg_todo = (mipmaps[i].cell_count - 1) / wg_size + 1; + int64_t wg_todo = (mipmaps[i].cell_count - 1) / wg_size + 1; while (wg_todo) { - int wg_count = MIN(wg_todo, wg_limit_x); + int64_t wg_count = MIN(wg_todo, wg_limit_x); RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(VoxelGIPushConstant)); RD::get_singleton()->compute_list_dispatch(compute_list, wg_count, 1, 1); wg_todo -= wg_count; @@ -2497,9 +2497,9 @@ void RendererSceneGIRD::VoxelGIInstance::update(bool p_update_light_instances, c push_constant.cell_offset = mipmaps[i].cell_offset; push_constant.cell_count = mipmaps[i].cell_count; - int wg_todo = (mipmaps[i].cell_count - 1) / wg_size + 1; + int64_t wg_todo = (mipmaps[i].cell_count - 1) / wg_size + 1; while (wg_todo) { - int wg_count = MIN(wg_todo, wg_limit_x); + int64_t wg_count = MIN(wg_todo, wg_limit_x); RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(VoxelGIPushConstant)); RD::get_singleton()->compute_list_dispatch(compute_list, wg_count, 1, 1); wg_todo -= wg_count; diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index e4ddc1b41f2..c124f074e0a 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -9962,7 +9962,7 @@ RendererStorageRD::RendererStorageRD() { using_lightmap_array = true; // high end if (using_lightmap_array) { - uint32_t textures_per_stage = RD::get_singleton()->limit_get(RD::LIMIT_MAX_TEXTURES_PER_SHADER_STAGE); + uint64_t textures_per_stage = RD::get_singleton()->limit_get(RD::LIMIT_MAX_TEXTURES_PER_SHADER_STAGE); if (textures_per_stage <= 256) { lightmap_textures.resize(32); diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index 1880415342e..6ed44486386 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -1222,7 +1222,7 @@ public: LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z, }; - virtual int limit_get(Limit p_limit) = 0; + virtual uint64_t limit_get(Limit p_limit) = 0; //methods below not exposed, used by RenderingDeviceRD virtual void prepare_screen_for_drawing() = 0; diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 7683cf20b3d..08f1ced803d 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -7483,8 +7483,8 @@ Error ShaderLanguage::_parse_shader(const Map &p_funct int uniforms = 0; int instance_index = 0; #ifdef DEBUG_ENABLED - int uniform_buffer_size = 0; - int max_uniform_buffer_size = 0; + uint64_t uniform_buffer_size = 0; + uint64_t max_uniform_buffer_size = 0; int uniform_buffer_exceeded_line = -1; bool check_device_limit_warnings = false;