Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Implement workaround for PowerVR Rogue shader compiler crashes.

Skyth659c43dd5d78
diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp
index 19e9072329a..b9e56ab5f55 100644
--- a/drivers/vulkan/rendering_device_driver_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp
@@ -78,6 +78,16 @@
#define RECORD_PIPELINE_STATISTICS_PATH "./pipelines.csv"
#endif
+#define POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_LOCK \
+ if (powervr_rogue_shader_crash_workaround_mutex) { \
+ powervr_rogue_shader_crash_workaround_mutex->lock(); \
+ }
+
+#define POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_UNLOCK \
+ if (powervr_rogue_shader_crash_workaround_mutex) { \
+ powervr_rogue_shader_crash_workaround_mutex->unlock(); \
+ }
+
/*****************/
/**** GENERIC ****/
/*****************/
@@ -747,6 +757,11 @@ void RenderingDeviceDriverVulkan::_check_driver_workarounds(const VkPhysicalDevi
// Workaround for a bug in NVIDIA drivers where submitting a render pass with no bound pipeline and an attachment using the "Don't Care" store operation causes a crash.
driver_workarounds.avoid_store_op_dont_care_in_draw_list_with_no_bound_pipeline = (p_device_properties.vendorID == RenderingContextDriver::Vendor::VENDOR_NVIDIA);
+
+ // Workaround for shader compilers ("libufwriter.so") in PowerVR Rogue GPUs (and some B-Series BXM-8-256) where creating shader modules or pipelines concurrently causes a crash.
+ if (p_device_properties.vendorID == RenderingContextDriver::Vendor::VENDOR_IMGTEC && (strstr(p_device_properties.deviceName, "Rogue") != nullptr || strstr(p_device_properties.deviceName, "BXM-8-256") != nullptr)) {
+ powervr_rogue_shader_crash_workaround_mutex = memnew(BinaryMutex); // Non-null mutex pointer enables the workaround.
+ }
}
void RenderingDeviceDriverVulkan::_get_device_properties() {
@@ -4464,7 +4479,10 @@ RDD::ShaderID RenderingDeviceDriverVulkan::shader_create_from_container(const Re
shader_module_create_info.codeSize = decoded_spirv.size();
shader_module_create_info.pCode = (const uint32_t *)(decoded_spirv.ptr());
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_LOCK
res = vkCreateShaderModule(vk_device, &shader_module_create_info, VKC::get_allocation_callbacks(VK_OBJECT_TYPE_SHADER_MODULE), &vk_module);
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_UNLOCK
+
if (res != VK_SUCCESS) {
error_text = vformat("Error (%d) creating module for shader stage %s.", res, String(SHADER_STAGE_NAMES[shader_refl.stages_vector[i]]));
break;
@@ -6213,7 +6231,11 @@ RDD::PipelineID RenderingDeviceDriverVulkan::render_pipeline_create(
shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
shader_module_create_info.pCode = (const uint32_t *)(respv_optimized_data.data());
shader_module_create_info.codeSize = respv_optimized_data.size();
+
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_LOCK
VkResult err = vkCreateShaderModule(vk_device, &shader_module_create_info, VKC::get_allocation_callbacks(VK_OBJECT_TYPE_SHADER_MODULE), &shader_module);
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_UNLOCK
+
if (err == VK_SUCCESS) {
// Replace the module used in the creation info.
vk_pipeline_stages[i].module = shader_module;
@@ -6276,7 +6298,10 @@ RDD::PipelineID RenderingDeviceDriverVulkan::render_pipeline_create(
#endif
VkPipeline vk_pipeline = VK_NULL_HANDLE;
+
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_LOCK
VkResult err = vkCreateGraphicsPipelines(vk_device, pipelines_cache.vk_cache, 1, &pipeline_create_info, VKC::get_allocation_callbacks(VK_OBJECT_TYPE_PIPELINE), &vk_pipeline);
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_UNLOCK
// Don't print error for VK_ERROR_UNKNOWN on Adreno 660.
if (unlikely(err == VK_ERROR_UNKNOWN && driver_workarounds.dont_print_on_render_pipeline_creation_failure)) {
@@ -6792,7 +6817,11 @@ RDD::PipelineID RenderingDeviceDriverVulkan::compute_pipeline_create(ShaderID p_
}
VkPipeline vk_pipeline = VK_NULL_HANDLE;
+
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_LOCK
VkResult err = vkCreateComputePipelines(vk_device, pipelines_cache.vk_cache, 1, &pipeline_create_info, VKC::get_allocation_callbacks(VK_OBJECT_TYPE_PIPELINE), &vk_pipeline);
+ POWERVR_ROGUE_SHADER_CRASH_WORKAROUND_MUTEX_UNLOCK
+
ERR_FAIL_COND_V_MSG(err, PipelineID(), vformat("Couldn't create Vulkan compute pipelines (VkResult error %d).", err));
return PipelineID(vk_pipeline);
@@ -7542,6 +7571,8 @@ RenderingDeviceDriverVulkan::~RenderingDeviceDriverVulkan() {
}
#endif
+ memdelete(powervr_rogue_shader_crash_workaround_mutex);
+
while (small_allocs_pools.size()) {
HashMap<uint32_t, VmaPool>::Iterator E = small_allocs_pools.begin();
vmaDestroyPool(allocator, E->value);
diff --git a/drivers/vulkan/rendering_device_driver_vulkan.h b/drivers/vulkan/rendering_device_driver_vulkan.h
index 0e2726a593e..e7c129c744b 100644
--- a/drivers/vulkan/rendering_device_driver_vulkan.h
+++ b/drivers/vulkan/rendering_device_driver_vulkan.h
@@ -194,6 +194,7 @@ class RenderingDeviceDriverVulkan : public RenderingDeviceDriver {
PipelineStatistics pipeline_statistics;
DriverWorkarounds driver_workarounds;
+ BinaryMutex *powervr_rogue_shader_crash_workaround_mutex = nullptr;
void _register_requested_device_extension(const CharString &p_extension_name, bool p_required);
Error _initialize_device_extensions();