# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/pcsx2/hotfix-shaderc.patch # Copyright (C) 2025 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- From a71ea9917a132c84c98a3e1f72cf50636627275a Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Fri, 22 Nov 2024 20:46:20 -0600 Subject: [PATCH] Vulkan: Re-add shaderc status strings to error messages --- pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp b/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp index f360178beb992..e001aef8bbd0e 100644 --- a/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp +++ b/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp @@ -108,13 +108,13 @@ static void FillPipelineCacheHeader(VK_PIPELINE_CACHE_HEADER* header) X(shaderc_compile_options_set_generate_debug_info) \ X(shaderc_compile_options_set_optimization_level) \ X(shaderc_compile_options_set_target_env) \ - X(shaderc_compilation_status_to_string) \ X(shaderc_compile_into_spv) \ X(shaderc_result_release) \ X(shaderc_result_get_length) \ X(shaderc_result_get_num_warnings) \ X(shaderc_result_get_bytes) \ - X(shaderc_result_get_error_message) + X(shaderc_result_get_error_message) \ + X(shaderc_result_get_compilation_status) // TODO: NOT thread safe, yet. namespace dyn_shaderc @@ -216,21 +216,25 @@ std::optional VKShaderCache::CompileShaderToSPV( dyn_shaderc::shaderc_compile_options_set_source_language(options, shaderc_source_language_glsl); dyn_shaderc::shaderc_compile_options_set_target_env(options, shaderc_target_env_vulkan, 0); +#ifdef SHADERC_PCSX2_CUSTOM dyn_shaderc::shaderc_compile_options_set_generate_debug_info(options, debug, debug && GSDeviceVK::GetInstance()->GetOptionalExtensions().vk_khr_shader_non_semantic_info); +#else + if (debug) + dyn_shaderc::shaderc_compile_options_set_generate_debug_info(options); +#endif dyn_shaderc::shaderc_compile_options_set_optimization_level( options, debug ? shaderc_optimization_level_zero : shaderc_optimization_level_performance); - shaderc_compilation_result_t result; - const shaderc_compilation_status status = dyn_shaderc::shaderc_compile_into_spv( + const shaderc_compilation_result_t result = dyn_shaderc::shaderc_compile_into_spv( dyn_shaderc::s_compiler, source.data(), source.length(), static_cast(stage), "source", - "main", options, &result); - if (status != shaderc_compilation_status_success) + "main", options); + + if (!result || dyn_shaderc::shaderc_result_get_compilation_status(result) != shaderc_compilation_status_success) { const std::string_view errors(result ? dyn_shaderc::shaderc_result_get_error_message(result) : "null result object"); - ERROR_LOG("Failed to compile shader to SPIR-V: {}\n{}", - dyn_shaderc::shaderc_compilation_status_to_string(status), errors); + ERROR_LOG("Failed to compile shader to SPIR-V: {}", errors); DumpBadShader(source, errors); } else index e001aef8bbd0e..6128a8177bd15 100644 --- a/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp +++ b/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp @@ -205,6 +205,25 @@ static void DumpBadShader(std::string_view code, std::string_view errors) } } +static const char* compilation_status_to_string(shaderc_compilation_status status) +{ + switch (status) + { +#define CASE(x) case shaderc_compilation_status_##x: return #x + CASE(success); + CASE(invalid_stage); + CASE(compilation_error); + CASE(internal_error); + CASE(null_result_object); + CASE(invalid_assembly); + CASE(validation_error); + CASE(transformation_error); + CASE(configuration_error); +#undef CASE + } + return "unknown_error"; +} + std::optional VKShaderCache::CompileShaderToSPV(u32 stage, std::string_view source, bool debug) { std::optional ret; @@ -230,11 +249,12 @@ std::optional VKShaderCache::CompileShaderToSPV( dyn_shaderc::s_compiler, source.data(), source.length(), static_cast(stage), "source", "main", options); - if (!result || dyn_shaderc::shaderc_result_get_compilation_status(result) != shaderc_compilation_status_success) + shaderc_compilation_status status = shaderc_compilation_status_null_result_object; + if (!result || (status = dyn_shaderc::shaderc_result_get_compilation_status(result)) != shaderc_compilation_status_success) { - const std::string_view errors(result ? dyn_shaderc::shaderc_result_get_error_message(result) : - "null result object"); - ERROR_LOG("Failed to compile shader to SPIR-V: {}", errors); + const std::string_view errors(result ? dyn_shaderc::shaderc_result_get_error_message(result) + : "null result object"); + ERROR_LOG("Failed to compile shader to SPIR-V: {}\n{}", compilation_status_to_string(status), errors); DumpBadShader(source, errors); } else