diff options
author | reduz <reduzio@gmail.com> | 2021-08-16 14:51:29 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-08-17 13:52:06 -0300 |
commit | 6027cd0a1dc0726b039a96c8d1b811158464540b (patch) | |
tree | eecea01b7a54ba385a06b83b599263a0cc6db5bf /drivers | |
parent | 72cb4529375de4e3c7511cb7be4ffe8e0103d8ca (diff) |
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.
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/vulkan/rendering_device_vulkan.cpp | 38 | ||||
-rw-r--r-- | drivers/vulkan/rendering_device_vulkan.h | 3 |
2 files changed, 36 insertions, 5 deletions
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index dbe932f74c..63510d261a 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<Vector<VkDescriptorSetLa } #endif -#define SHADER_BINARY_VERSION 1 +//version 1: initial +//version 2: Added shader name + +#define SHADER_BINARY_VERSION 2 String RenderingDeviceVulkan::shader_get_binary_cache_key() const { return "Vulkan-SV" + itos(SHADER_BINARY_VERSION); @@ -4476,9 +4479,10 @@ struct RenderingDeviceVulkanShaderBinaryData { uint32_t push_constant_size; uint32_t push_constants_vk_stage; uint32_t stage_count; + uint32_t shader_name_len; }; -Vector<uint8_t> RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv) { +Vector<uint8_t> RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &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<uint8_t> 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<uint8_t> 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<uint8_t> &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<Vector<VkDescriptorSetLayoutBinding>> set_bindings; Vector<Vector<UniformInfo>> uniform_info; @@ -5088,6 +5118,7 @@ RID RenderingDeviceVulkan::shader_create_from_bytecode(const Vector<uint8_t> &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 6175369285..5ee2ca07f2 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -639,6 +639,7 @@ class RenderingDeviceVulkan : public RenderingDevice { Vector<VkPipelineShaderStageCreateInfo> pipeline_stages; Vector<SpecializationConstant> 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<uint8_t> shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv); + virtual Vector<uint8_t> shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = ""); virtual RID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary); |