From 6027cd0a1dc0726b039a96c8d1b811158464540b Mon Sep 17 00:00:00 2001 From: reduz Date: Mon, 16 Aug 2021 14:51:29 -0300 Subject: [PATCH] Fixes to mobile renderer * Make sure shaders are named, to aid in debug in case of failure * SceneRenderRD was being wrongly initialized (virtual functions being called when derivative class not initialized). * Fixed some bugs resulting on the above being corrected. --- doc/classes/RenderingDevice.xml | 4 +- drivers/vulkan/rendering_device_vulkan.cpp | 38 ++++- drivers/vulkan/rendering_device_vulkan.h | 3 +- servers/rendering/renderer_rd/effects_rd.cpp | 142 +++++++++--------- .../render_forward_clustered.cpp | 2 +- .../forward_mobile/render_forward_mobile.cpp | 2 +- .../renderer_rd/renderer_compositor_rd.cpp | 2 + .../renderer_rd/renderer_scene_gi_rd.cpp | 6 +- .../renderer_rd/renderer_scene_gi_rd.h | 4 +- .../renderer_rd/renderer_scene_render_rd.cpp | 8 +- .../renderer_rd/renderer_scene_render_rd.h | 2 + .../renderer_rd/renderer_storage_rd.cpp | 10 -- .../renderer_rd/renderer_storage_rd.h | 5 - servers/rendering/renderer_rd/shader_rd.cpp | 2 +- servers/rendering/rendering_device.cpp | 14 +- servers/rendering/rendering_device.h | 8 +- 16 files changed, 140 insertions(+), 112 deletions(-) diff --git a/doc/classes/RenderingDevice.xml b/doc/classes/RenderingDevice.xml index c3298216462..24f7f4274ea 100644 --- a/doc/classes/RenderingDevice.xml +++ b/doc/classes/RenderingDevice.xml @@ -448,6 +448,7 @@ + @@ -465,8 +466,9 @@ - + + diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index dbe932f74c5..63510d261a1 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -4442,7 +4442,10 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Vector &p_spirv) { +Vector RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Vector &p_spirv, const String &p_shader_name) { RenderingDeviceVulkanShaderBinaryData binary_data; binary_data.vertex_input_mask = 0; binary_data.fragment_outputs = 0; @@ -4835,9 +4839,19 @@ Vector RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Ve binary_data.set_count = uniform_info.size(); binary_data.stage_count = p_spirv.size(); + CharString shader_name_utf = p_shader_name.utf8(); + + binary_data.shader_name_len = shader_name_utf.length(); + uint32_t total_size = sizeof(uint32_t) * 3; //header + version + main datasize; total_size += sizeof(RenderingDeviceVulkanShaderBinaryData); + total_size += binary_data.shader_name_len; + + if ((binary_data.shader_name_len % 4) != 0) { //alignment rules are really strange + total_size += 4 - (binary_data.shader_name_len % 4); + } + for (int i = 0; i < uniform_info.size(); i++) { total_size += sizeof(uint32_t); total_size += uniform_info[i].size() * sizeof(RenderingDeviceVulkanShaderBinaryDataBinding); @@ -4864,6 +4878,12 @@ Vector RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Ve offset += sizeof(uint32_t); memcpy(binptr + offset, &binary_data, sizeof(RenderingDeviceVulkanShaderBinaryData)); offset += sizeof(RenderingDeviceVulkanShaderBinaryData); + memcpy(binptr + offset, shader_name_utf.ptr(), binary_data.shader_name_len); + offset += binary_data.shader_name_len; + + if ((binary_data.shader_name_len % 4) != 0) { //alignment rules are really strange + offset += 4 - (binary_data.shader_name_len % 4); + } for (int i = 0; i < uniform_info.size(); i++) { int count = uniform_info[i].size(); @@ -4934,6 +4954,16 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector &p_ read_offset += sizeof(uint32_t) * 3 + bin_data_size; + String name; + + if (binary_data.shader_name_len) { + name.parse_utf8((const char *)(binptr + read_offset), binary_data.shader_name_len); + read_offset += binary_data.shader_name_len; + if ((binary_data.shader_name_len % 4) != 0) { //alignment rules are really strange + read_offset += 4 - (binary_data.shader_name_len % 4); + } + } + Vector> set_bindings; Vector> uniform_info; @@ -5088,6 +5118,7 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector &p_ shader.compute_local_size[1] = compute_local_size[1]; shader.compute_local_size[2] = compute_local_size[2]; shader.specialization_constants = specialization_constants; + shader.name = name; String error_text; @@ -6449,7 +6480,6 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma specialization_info.write[i].pData = data_ptr; specialization_info.write[i].mapEntryCount = specialization_map_entries[i].size(); specialization_info.write[i].pMapEntries = specialization_map_entries[i].ptr(); - pipeline_stages.write[i].pSpecializationInfo = specialization_info.ptr() + i; } } @@ -6476,7 +6506,7 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma RenderPipeline pipeline; VkResult err = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &graphics_pipeline_create_info, nullptr, &pipeline.pipeline); - ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateGraphicsPipelines failed with error " + itos(err) + "."); + ERR_FAIL_COND_V_MSG(err, RID(), "vkCreateGraphicsPipelines failed with error " + itos(err) + " for shader '" + shader->name + "'."); pipeline.set_formats = shader->set_formats; pipeline.push_constant_stages = shader->push_constant.push_constants_vk_stage; diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 61753692855..5ee2ca07f21 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -639,6 +639,7 @@ class RenderingDeviceVulkan : public RenderingDevice { Vector pipeline_stages; Vector specialization_constants; VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; + String name; //used for debug }; String _shader_uniform_debug(RID p_shader, int p_set = -1); @@ -1088,7 +1089,7 @@ public: /****************/ virtual String shader_get_binary_cache_key() const; - virtual Vector shader_compile_binary_from_spirv(const Vector &p_spirv); + virtual Vector shader_compile_binary_from_spirv(const Vector &p_spirv, const String &p_shader_name = ""); virtual RID shader_create_from_bytecode(const Vector &p_shader_binary); diff --git a/servers/rendering/renderer_rd/effects_rd.cpp b/servers/rendering/renderer_rd/effects_rd.cpp index f5b6be4795a..0c191fe2f7b 100644 --- a/servers/rendering/renderer_rd/effects_rd.cpp +++ b/servers/rendering/renderer_rd/effects_rd.cpp @@ -1914,7 +1914,7 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) { } } - { // Initialize copy + if (!prefer_raster_effects) { // Initialize copy Vector copy_modes; copy_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n"); copy_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n#define DST_IMAGE_8BIT\n"); @@ -2113,7 +2113,7 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) { } } - { + if (!prefer_raster_effects) { // Initialize ssao RD::SamplerState sampler; @@ -2257,7 +2257,7 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) { ERR_FAIL_COND(pipeline != SSAO_MAX); } - { + if (!prefer_raster_effects) { // Initialize roughness limiter Vector shader_modes; shader_modes.push_back(""); @@ -2355,7 +2355,7 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) { } } - { + if (!prefer_raster_effects) { Vector specular_modes; specular_modes.push_back("\n#define MODE_MERGE\n"); specular_modes.push_back("\n#define MODE_MERGE\n#define MODE_SSR\n"); @@ -2391,72 +2391,74 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) { } } - { - Vector ssr_modes; - ssr_modes.push_back("\n"); - ssr_modes.push_back("\n#define MODE_ROUGH\n"); + if (!prefer_raster_effects) { + { + Vector ssr_modes; + ssr_modes.push_back("\n"); + ssr_modes.push_back("\n#define MODE_ROUGH\n"); - ssr.shader.initialize(ssr_modes); + ssr.shader.initialize(ssr_modes); - ssr.shader_version = ssr.shader.version_create(); + ssr.shader_version = ssr.shader.version_create(); - for (int i = 0; i < SCREEN_SPACE_REFLECTION_MAX; i++) { - ssr.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr.shader.version_get_shader(ssr.shader_version, i)); + for (int i = 0; i < SCREEN_SPACE_REFLECTION_MAX; i++) { + ssr.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr.shader.version_get_shader(ssr.shader_version, i)); + } } - } - { - Vector ssr_filter_modes; - ssr_filter_modes.push_back("\n"); - ssr_filter_modes.push_back("\n#define VERTICAL_PASS\n"); + { + Vector ssr_filter_modes; + ssr_filter_modes.push_back("\n"); + ssr_filter_modes.push_back("\n#define VERTICAL_PASS\n"); - ssr_filter.shader.initialize(ssr_filter_modes); + ssr_filter.shader.initialize(ssr_filter_modes); - ssr_filter.shader_version = ssr_filter.shader.version_create(); + ssr_filter.shader_version = ssr_filter.shader.version_create(); - for (int i = 0; i < SCREEN_SPACE_REFLECTION_FILTER_MAX; i++) { - ssr_filter.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr_filter.shader.version_get_shader(ssr_filter.shader_version, i)); + for (int i = 0; i < SCREEN_SPACE_REFLECTION_FILTER_MAX; i++) { + ssr_filter.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr_filter.shader.version_get_shader(ssr_filter.shader_version, i)); + } } - } - { - Vector ssr_scale_modes; - ssr_scale_modes.push_back("\n"); + { + Vector ssr_scale_modes; + ssr_scale_modes.push_back("\n"); - ssr_scale.shader.initialize(ssr_scale_modes); + ssr_scale.shader.initialize(ssr_scale_modes); - ssr_scale.shader_version = ssr_scale.shader.version_create(); + ssr_scale.shader_version = ssr_scale.shader.version_create(); - ssr_scale.pipeline = RD::get_singleton()->compute_pipeline_create(ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0)); - } - - { - Vector sss_modes; - sss_modes.push_back("\n#define USE_11_SAMPLES\n"); - sss_modes.push_back("\n#define USE_17_SAMPLES\n"); - sss_modes.push_back("\n#define USE_25_SAMPLES\n"); - - sss.shader.initialize(sss_modes); - - sss.shader_version = sss.shader.version_create(); - - for (int i = 0; i < sss_modes.size(); i++) { - sss.pipelines[i] = RD::get_singleton()->compute_pipeline_create(sss.shader.version_get_shader(sss.shader_version, i)); + ssr_scale.pipeline = RD::get_singleton()->compute_pipeline_create(ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0)); } - } - { - Vector resolve_modes; - resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n"); - resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n#define VOXEL_GI_RESOLVE\n"); - resolve_modes.push_back("\n#define MODE_RESOLVE_DEPTH\n"); + { + Vector sss_modes; + sss_modes.push_back("\n#define USE_11_SAMPLES\n"); + sss_modes.push_back("\n#define USE_17_SAMPLES\n"); + sss_modes.push_back("\n#define USE_25_SAMPLES\n"); - resolve.shader.initialize(resolve_modes); + sss.shader.initialize(sss_modes); - resolve.shader_version = resolve.shader.version_create(); + sss.shader_version = sss.shader.version_create(); - for (int i = 0; i < RESOLVE_MODE_MAX; i++) { - resolve.pipelines[i] = RD::get_singleton()->compute_pipeline_create(resolve.shader.version_get_shader(resolve.shader_version, i)); + for (int i = 0; i < sss_modes.size(); i++) { + sss.pipelines[i] = RD::get_singleton()->compute_pipeline_create(sss.shader.version_get_shader(sss.shader_version, i)); + } + } + + { + Vector resolve_modes; + resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n"); + resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n#define VOXEL_GI_RESOLVE\n"); + resolve_modes.push_back("\n#define MODE_RESOLVE_DEPTH\n"); + + resolve.shader.initialize(resolve_modes); + + resolve.shader_version = resolve.shader.version_create(); + + for (int i = 0; i < RESOLVE_MODE_MAX; i++) { + resolve.pipelines[i] = RD::get_singleton()->compute_pipeline_create(resolve.shader.version_get_shader(resolve.shader_version, i)); + } } } @@ -2522,10 +2524,6 @@ EffectsRD::~EffectsRD() { RD::get_singleton()->free(index_buffer); //array gets freed as dependency RD::get_singleton()->free(filter.coefficient_buffer); - RD::get_singleton()->free(ssao.mirror_sampler); - RD::get_singleton()->free(ssao.gather_constants_buffer); - RD::get_singleton()->free(ssao.importance_map_load_counter); - if (prefer_raster_effects) { blur_raster.shader.version_free(blur_raster.shader_version); bokeh.raster_shader.version_free(blur_raster.shader_version); @@ -2540,21 +2538,27 @@ EffectsRD::~EffectsRD() { cubemap_downsampler.compute_shader.version_free(cubemap_downsampler.shader_version); filter.compute_shader.version_free(filter.shader_version); } - copy.shader.version_free(copy.shader_version); + if (!prefer_raster_effects) { + copy.shader.version_free(copy.shader_version); + resolve.shader.version_free(resolve.shader_version); + specular_merge.shader.version_free(specular_merge.shader_version); + ssao.blur_shader.version_free(ssao.blur_shader_version); + ssao.gather_shader.version_free(ssao.gather_shader_version); + ssao.downsample_shader.version_free(ssao.downsample_shader_version); + ssao.interleave_shader.version_free(ssao.interleave_shader_version); + ssao.importance_map_shader.version_free(ssao.importance_map_shader_version); + roughness_limiter.shader.version_free(roughness_limiter.shader_version); + ssr.shader.version_free(ssr.shader_version); + ssr_filter.shader.version_free(ssr_filter.shader_version); + ssr_scale.shader.version_free(ssr_scale.shader_version); + sss.shader.version_free(sss.shader_version); + + RD::get_singleton()->free(ssao.mirror_sampler); + RD::get_singleton()->free(ssao.gather_constants_buffer); + RD::get_singleton()->free(ssao.importance_map_load_counter); + } copy_to_fb.shader.version_free(copy_to_fb.shader_version); cube_to_dp.shader.version_free(cube_to_dp.shader_version); - resolve.shader.version_free(resolve.shader_version); - roughness_limiter.shader.version_free(roughness_limiter.shader_version); sort.shader.version_free(sort.shader_version); - specular_merge.shader.version_free(specular_merge.shader_version); - ssao.blur_shader.version_free(ssao.blur_shader_version); - ssao.gather_shader.version_free(ssao.gather_shader_version); - ssao.downsample_shader.version_free(ssao.downsample_shader_version); - ssao.interleave_shader.version_free(ssao.interleave_shader_version); - ssao.importance_map_shader.version_free(ssao.importance_map_shader_version); - ssr.shader.version_free(ssr.shader_version); - ssr_filter.shader.version_free(ssr_filter.shader_version); - ssr_scale.shader.version_free(ssr_scale.shader_version); - sss.shader.version_free(sss.shader_version); tonemap.shader.version_free(tonemap.shader_version); } diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 5a0ad97c7ca..611f7c64944 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -3062,7 +3062,7 @@ RenderForwardClustered::RenderForwardClustered(RendererStorageRD *p_storage) : defines += "\n#define USE_RADIANCE_CUBEMAP_ARRAY \n"; } defines += "\n#define SDFGI_OCT_SIZE " + itos(gi.sdfgi_get_lightprobe_octahedron_size()) + "\n"; - defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(get_max_directional_lights()) + "\n"; + defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(MAX_DIRECTIONAL_LIGHTS) + "\n"; { //lightmaps diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 96b3cdadd43..2064d9c5c5c 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -2630,7 +2630,7 @@ RenderForwardMobile::RenderForwardMobile(RendererStorageRD *p_storage) : defines += "\n#define USE_RADIANCE_CUBEMAP_ARRAY \n"; } // defines += "\n#define SDFGI_OCT_SIZE " + itos(gi.sdfgi_get_lightprobe_octahedron_size()) + "\n"; - defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(get_max_directional_lights()) + "\n"; + defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(MAX_DIRECTIONAL_LIGHTS) + "\n"; { //lightmaps diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp index 02d548bf135..62e9386f95a 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp @@ -281,6 +281,8 @@ RendererCompositorRD::RendererCompositorRD() { scene = memnew(RendererSceneRenderImplementation::RenderForwardClustered(storage)); } + scene->init(); + // now we're ready to create our effects, storage->init_effects(!scene->_render_buffers_can_be_storage()); } diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp index 98d08f68e8a..098e2a5c871 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp @@ -2812,8 +2812,6 @@ void RendererSceneGIRD::init(RendererStorageRD *p_storage, RendererSceneSkyRD *p { //kinda complicated to compute the amount of slots, we try to use as many as we can - voxel_gi_max_lights = 32; - voxel_gi_lights = memnew_arr(VoxelGILight, voxel_gi_max_lights); voxel_gi_lights_uniform = RD::get_singleton()->uniform_buffer_create(voxel_gi_max_lights * sizeof(VoxelGILight)); voxel_gi_quality = RS::VoxelGIQuality(CLAMP(int(GLOBAL_GET("rendering/global_illumination/voxel_gi/quality")), 0, 1)); @@ -3009,7 +3007,9 @@ void RendererSceneGIRD::free() { sdfgi_shader.integrate.version_free(sdfgi_shader.integrate_shader); sdfgi_shader.preprocess.version_free(sdfgi_shader.preprocess_shader); - memdelete_arr(voxel_gi_lights); + if (voxel_gi_lights) { + memdelete_arr(voxel_gi_lights); + } } RendererSceneGIRD::SDFGI *RendererSceneGIRD::create_sdfgi(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size) { diff --git a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h index 128bf09063b..0b4622646f9 100644 --- a/servers/rendering/renderer_rd/renderer_scene_gi_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_gi_rd.h @@ -110,8 +110,8 @@ private: float pad[3]; }; - VoxelGILight *voxel_gi_lights; - uint32_t voxel_gi_max_lights; + VoxelGILight *voxel_gi_lights = nullptr; + uint32_t voxel_gi_max_lights = 32; RID voxel_gi_lights_uniform; enum { diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 5016c99a1e5..d81c216f379 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -4066,7 +4066,7 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData render_state.voxel_gi_count = 0; - if (rb != nullptr) { + if (rb != nullptr && is_dynamic_gi_supported()) { if (rb->sdfgi) { rb->sdfgi->update_cascades(); rb->sdfgi->pre_process_gi(render_data.cam_transform, &render_data, this); @@ -4587,10 +4587,12 @@ uint32_t RendererSceneRenderRD::get_max_elements() const { } RendererSceneRenderRD::RendererSceneRenderRD(RendererStorageRD *p_storage) { - max_cluster_elements = get_max_elements(); - storage = p_storage; singleton = this; +} + +void RendererSceneRenderRD::init() { + max_cluster_elements = get_max_elements(); directional_shadow.size = GLOBAL_GET("rendering/shadows/directional_shadow/size"); directional_shadow.use_16_bits = GLOBAL_GET("rendering/shadows/directional_shadow/16_bits"); diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.h b/servers/rendering/renderer_rd/renderer_scene_render_rd.h index 5306df36f09..a7cc27be4a8 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.h @@ -1290,6 +1290,8 @@ public: virtual bool is_volumetric_supported() const; virtual uint32_t get_max_elements() const; + void init(); + RendererSceneRenderRD(RendererStorageRD *p_storage); ~RendererSceneRenderRD(); }; diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp index 7d438345f1b..8cc20618fcc 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp @@ -9310,15 +9310,6 @@ RendererStorageRD::RendererStorageRD() { } } - { - Vector sdf_versions; - sdf_versions.push_back(""); //one only - voxel_gi_sdf_shader.initialize(sdf_versions); - voxel_gi_sdf_shader_version = voxel_gi_sdf_shader.version_create(); - voxel_gi_sdf_shader_version_shader = voxel_gi_sdf_shader.version_get_shader(voxel_gi_sdf_shader_version, 0); - voxel_gi_sdf_shader_pipeline = RD::get_singleton()->compute_pipeline_create(voxel_gi_sdf_shader_version_shader); - } - 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); @@ -9538,7 +9529,6 @@ RendererStorageRD::~RendererStorageRD() { RD::get_singleton()->free(mesh_default_rd_buffers[i]); } - voxel_gi_sdf_shader.version_free(voxel_gi_sdf_shader_version); particles_shader.copy_shader.version_free(particles_shader.copy_shader_version); rt_sdf.shader.version_free(rt_sdf.shader_version); diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.h b/servers/rendering/renderer_rd/renderer_storage_rd.h index b7adef6c602..02395a884f4 100644 --- a/servers/rendering/renderer_rd/renderer_storage_rd.h +++ b/servers/rendering/renderer_rd/renderer_storage_rd.h @@ -1100,11 +1100,6 @@ private: Dependency dependency; }; - VoxelGiSdfShaderRD voxel_gi_sdf_shader; - RID voxel_gi_sdf_shader_version; - RID voxel_gi_sdf_shader_version_shader; - RID voxel_gi_sdf_shader_pipeline; - mutable RID_Owner voxel_gi_owner; /* REFLECTION PROBE */ diff --git a/servers/rendering/renderer_rd/shader_rd.cpp b/servers/rendering/renderer_rd/shader_rd.cpp index 5bb12fc168d..82efa1318c2 100644 --- a/servers/rendering/renderer_rd/shader_rd.cpp +++ b/servers/rendering/renderer_rd/shader_rd.cpp @@ -279,7 +279,7 @@ void ShaderRD::_compile_variant(uint32_t p_variant, Version *p_version) { return; } - Vector shader_data = RD::get_singleton()->shader_compile_binary_from_spirv(stages); + Vector shader_data = RD::get_singleton()->shader_compile_binary_from_spirv(stages, name + ":" + itos(p_variant)); ERR_FAIL_COND(shader_data.size() == 0); diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index bb9ffffe8aa..b302c6b7931 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -74,8 +74,8 @@ String RenderingDevice::shader_get_spirv_cache_key() const { return String(); } -RID RenderingDevice::shader_create_from_spirv(const Vector &p_spirv) { - Vector bytecode = shader_compile_binary_from_spirv(p_spirv); +RID RenderingDevice::shader_create_from_spirv(const Vector &p_spirv, const String &p_shader_name) { + Vector bytecode = shader_compile_binary_from_spirv(p_spirv, p_shader_name); ERR_FAIL_COND_V(bytecode.size() == 0, RID()); return shader_create_from_bytecode(bytecode); } @@ -192,7 +192,7 @@ Ref RenderingDevice::_shader_compile_spirv_from_source(const Ref< return bytecode; } -Vector RenderingDevice::_shader_compile_binary_from_spirv(const Ref &p_spirv) { +Vector RenderingDevice::_shader_compile_binary_from_spirv(const Ref &p_spirv, const String &p_shader_name) { ERR_FAIL_COND_V(p_spirv.is_null(), Vector()); Vector stage_data; @@ -209,10 +209,10 @@ Vector RenderingDevice::_shader_compile_binary_from_spirv(const Ref &p_spirv) { +RID RenderingDevice::_shader_create_from_spirv(const Ref &p_spirv, const String &p_shader_name) { ERR_FAIL_COND_V(p_spirv.is_null(), RID()); Vector stage_data; @@ -392,8 +392,8 @@ void RenderingDevice::_bind_methods() { ClassDB::bind_method(D_METHOD("index_array_create", "index_buffer", "index_offset", "index_count"), &RenderingDevice::index_array_create); ClassDB::bind_method(D_METHOD("shader_compile_spirv_from_source", "shader_source", "allow_cache"), &RenderingDevice::_shader_compile_spirv_from_source, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("shader_compile_binary_from_spirv", "spirv_data"), &RenderingDevice::_shader_compile_binary_from_spirv); - ClassDB::bind_method(D_METHOD("shader_create_from_spirv", "spirv_data"), &RenderingDevice::_shader_compile_binary_from_spirv); + ClassDB::bind_method(D_METHOD("shader_compile_binary_from_spirv", "spirv_data", "name"), &RenderingDevice::_shader_compile_binary_from_spirv, DEFVAL("")); + ClassDB::bind_method(D_METHOD("shader_create_from_spirv", "spirv_data", "name"), &RenderingDevice::_shader_create_from_spirv, DEFVAL("")); ClassDB::bind_method(D_METHOD("shader_create_from_bytecode", "binary_data"), &RenderingDevice::shader_create_from_bytecode); ClassDB::bind_method(D_METHOD("shader_get_vertex_input_attribute_mask", "shader"), &RenderingDevice::shader_get_vertex_input_attribute_mask); diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index bb028cb84cd..e2d207dab26 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -668,9 +668,9 @@ public: }; virtual String shader_get_binary_cache_key() const = 0; - virtual Vector shader_compile_binary_from_spirv(const Vector &p_spirv) = 0; + virtual Vector shader_compile_binary_from_spirv(const Vector &p_spirv, const String &p_shader_name = "") = 0; - virtual RID shader_create_from_spirv(const Vector &p_spirv); + virtual RID shader_create_from_spirv(const Vector &p_spirv, const String &p_shader_name = ""); virtual RID shader_create_from_bytecode(const Vector &p_shader_binary) = 0; virtual uint32_t shader_get_vertex_input_attribute_mask(RID p_shader) = 0; @@ -1200,8 +1200,8 @@ protected: RID _vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const TypedArray &p_src_buffers); Ref _shader_compile_spirv_from_source(const Ref &p_source, bool p_allow_cache = true); - Vector _shader_compile_binary_from_spirv(const Ref &p_bytecode); - RID _shader_create_from_spirv(const Ref &p_spirv); + Vector _shader_compile_binary_from_spirv(const Ref &p_bytecode, const String &p_shader_name = ""); + RID _shader_create_from_spirv(const Ref &p_spirv, const String &p_shader_name = ""); RID _uniform_set_create(const Array &p_uniforms, RID p_shader, uint32_t p_shader_set);