From 9df2bcf646995b90484570e01692c48cc32ff390 Mon Sep 17 00:00:00 2001 From: KamFretoZ <14798312+kamfretoz@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:12:09 +0700 Subject: [PATCH 1/3] CI: Ensure dependency cache key reflects all state --- .github/workflows/linux_build_flatpak.yml | 2 +- .github/workflows/linux_build_qt.yml | 2 +- .github/workflows/macos_build.yml | 2 +- .github/workflows/windows_build_qt.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux_build_flatpak.yml b/.github/workflows/linux_build_flatpak.yml index 7a8d579587c6f..51aacbd4b35f3 100644 --- a/.github/workflows/linux_build_flatpak.yml +++ b/.github/workflows/linux_build_flatpak.yml @@ -111,7 +111,7 @@ jobs: branch: ${{ inputs.branch }} cache: true restore-cache: true - cache-key: ${{ inputs.os }} ${{ inputs.platform }} ${{ inputs.compiler }} flatpak ${{ hashFiles('.github/workflows/scripts/linux/flatpak/**/*.json') }} + cache-key: ${{ inputs.os }} ${{ inputs.platform }} ${{ inputs.compiler }} flatpak ${{ hashFiles('.github/workflows/scripts/linux/flatpak/**/*.json', '.github/workflows/scripts/common/*.patch') }} #- name: Validate build # run: | diff --git a/.github/workflows/linux_build_qt.yml b/.github/workflows/linux_build_qt.yml index d78d924fb8dbb..80ae3d52e5fd9 100644 --- a/.github/workflows/linux_build_qt.yml +++ b/.github/workflows/linux_build_qt.yml @@ -117,7 +117,7 @@ jobs: uses: actions/cache@v4 with: path: ~/deps - key: ${{ inputs.os }} ${{ inputs.platform }} deps ${{ hashFiles('.github/workflows/scripts/linux/build-dependencies-qt.sh') }} + key: ${{ inputs.os }} ${{ inputs.platform }} deps ${{ hashFiles('.github/workflows/scripts/linux/build-dependencies-qt.sh', '.github/workflows/scripts/common/*.patch') }} - name: Build Dependencies if: steps.cache-deps.outputs.cache-hit != 'true' diff --git a/.github/workflows/macos_build.yml b/.github/workflows/macos_build.yml index e05d6ac6c4790..59811d477a4ff 100644 --- a/.github/workflows/macos_build.yml +++ b/.github/workflows/macos_build.yml @@ -85,7 +85,7 @@ jobs: uses: actions/cache@v4 with: path: ~/deps - key: ${{ inputs.os }} deps ${{ hashFiles('.github/workflows/scripts/macos/build-dependencies.sh') }} + key: ${{ inputs.os }} deps ${{ hashFiles('.github/workflows/scripts/macos/build-dependencies.sh', '.github/workflows/scripts/common/*.patch') }} - name: Build Dependencies if: steps.cache-deps.outputs.cache-hit != 'true' diff --git a/.github/workflows/windows_build_qt.yml b/.github/workflows/windows_build_qt.yml index 5666942ed7a72..4f54294c11c32 100644 --- a/.github/workflows/windows_build_qt.yml +++ b/.github/workflows/windows_build_qt.yml @@ -100,7 +100,7 @@ jobs: uses: actions/cache@v4 with: path: deps - key: ${{ inputs.os }} ${{ inputs.platform }} deps ${{ hashFiles('.github/workflows/scripts/windows/build-dependencies.bat') }} + key: ${{ inputs.os }} ${{ inputs.platform }} deps ${{ hashFiles('.github/workflows/scripts/windows/build-dependencies.bat', '.github/workflows/scripts/common/*.patch') }} - name: Build Dependencies if: steps.cache-deps.outputs.cache-hit != 'true' From c8ce45502655eb3973778d44227820fc88247ec8 Mon Sep 17 00:00:00 2001 From: KamFretoZ <14798312+kamfretoz@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:18:52 +0700 Subject: [PATCH 2/3] Shaderc: Make non-semantic debug optional Don't you hate it when you come up with more ideas just minutes AFTER the PR has been merged? --- .../scripts/common/shaderc-changes.patch | 325 +----------------- pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp | 20 +- 2 files changed, 21 insertions(+), 324 deletions(-) diff --git a/.github/workflows/scripts/common/shaderc-changes.patch b/.github/workflows/scripts/common/shaderc-changes.patch index 4524d53e642d4..2ed5ac2952bc8 100644 --- a/.github/workflows/scripts/common/shaderc-changes.patch +++ b/.github/workflows/scripts/common/shaderc-changes.patch @@ -114,6 +114,15 @@ diff --git a/libshaderc/include/shaderc/shaderc.h b/libshaderc/include/shaderc/s index 3a3e97d..65d5b77 100644 --- a/libshaderc/include/shaderc/shaderc.h +++ b/libshaderc/include/shaderc/shaderc.h +@@ -15,6 +15,8 @@ + #ifndef SHADERC_SHADERC_H_ + #define SHADERC_SHADERC_H_ + ++#define SHADERC_PCSX2_CUSTOM 1 ++ + #ifdef __cplusplus + extern "C" { + #endif @@ -317,7 +317,7 @@ SHADERC_EXPORT void shaderc_compile_options_set_source_language( // Sets the compiler mode to generate debug information in the output. @@ -123,69 +132,6 @@ index 3a3e97d..65d5b77 100644 // Sets the compiler optimization level to the given level. Only the last one // takes effect if multiple calls of this function exist. -@@ -506,6 +506,10 @@ SHADERC_EXPORT void shaderc_compile_options_set_invert_y( - SHADERC_EXPORT void shaderc_compile_options_set_nan_clamp( - shaderc_compile_options_t options, bool enable); - -+// Returns a string representation of the specified compilation status. -+SHADERC_EXPORT const char* shaderc_compilation_status_to_string( -+ shaderc_compilation_status status); -+ - // An opaque handle to the results of a call to any shaderc_compile_into_*() - // function. - typedef struct shaderc_compilation_result* shaderc_compilation_result_t; -@@ -529,28 +533,31 @@ typedef struct shaderc_compilation_result* shaderc_compilation_result_t; - // present. May be safely called from multiple threads without explicit - // synchronization. If there was failure in allocating the compiler object, - // null will be returned. --SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_spv( -+SHADERC_EXPORT shaderc_compilation_status shaderc_compile_into_spv( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -- const shaderc_compile_options_t additional_options); -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result); - - // Like shaderc_compile_into_spv, but the result contains SPIR-V assembly text - // instead of a SPIR-V binary module. The SPIR-V assembly syntax is as defined - // by the SPIRV-Tools open source project. --SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_spv_assembly( -+SHADERC_EXPORT shaderc_compilation_status shaderc_compile_into_spv_assembly( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -- const shaderc_compile_options_t additional_options); -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result); - - // Like shaderc_compile_into_spv, but the result contains preprocessed source - // code instead of a SPIR-V binary module --SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_preprocessed_text( -+SHADERC_EXPORT shaderc_compilation_status shaderc_compile_into_preprocessed_text( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -- const shaderc_compile_options_t additional_options); -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result); - - // Takes an assembly string of the format defined in the SPIRV-Tools project - // (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md), -@@ -561,10 +568,11 @@ SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_preprocessed_te - // May be safely called from multiple threads without explicit synchronization. - // If there was failure in allocating the compiler object, null will be - // returned. --SHADERC_EXPORT shaderc_compilation_result_t shaderc_assemble_into_spv( -+SHADERC_EXPORT shaderc_compilation_status shaderc_assemble_into_spv( - const shaderc_compiler_t compiler, const char* source_assembly, - size_t source_assembly_size, -- const shaderc_compile_options_t additional_options); -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result); - - // The following functions, operating on shaderc_compilation_result_t objects, - // offer only the basic thread-safety guarantee. diff --git a/libshaderc/include/shaderc/shaderc.hpp b/libshaderc/include/shaderc/shaderc.hpp index 3817af8..5592b49 100644 --- a/libshaderc/include/shaderc/shaderc.hpp @@ -202,119 +148,6 @@ index 3817af8..5592b49 100644 } // Sets the compiler optimization level to the given level. Only the last one -@@ -425,9 +426,10 @@ class Compiler { - const char* input_file_name, - const char* entry_point_name, - const CompileOptions& options) const { -- shaderc_compilation_result_t compilation_result = shaderc_compile_into_spv( -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_compile_into_spv( - compiler_, source_text, source_text_size, shader_kind, input_file_name, -- entry_point_name, options.options_); -+ entry_point_name, options.options_, &compilation_result); - return SpvCompilationResult(compilation_result); - } - -@@ -451,9 +453,10 @@ class Compiler { - size_t source_text_size, - shaderc_shader_kind shader_kind, - const char* input_file_name) const { -- shaderc_compilation_result_t compilation_result = -- shaderc_compile_into_spv(compiler_, source_text, source_text_size, -- shader_kind, input_file_name, "main", nullptr); -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_compile_into_spv(compiler_, source_text, source_text_size, -+ shader_kind, input_file_name, "main", nullptr, -+ &compilation_result); - return SpvCompilationResult(compilation_result); - } - -@@ -504,8 +507,11 @@ class Compiler { - SpvCompilationResult AssembleToSpv(const char* source_assembly, - size_t source_assembly_size, - const CompileOptions& options) const { -- return SpvCompilationResult(shaderc_assemble_into_spv( -- compiler_, source_assembly, source_assembly_size, options.options_)); -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_assemble_into_spv( -+ compiler_, source_assembly, source_assembly_size, options.options_, -+ &compilation_result); -+ return SpvCompilationResult(compilation_result); - } - - // Assembles the given SPIR-V assembly and returns a SPIR-V binary module -@@ -513,8 +519,11 @@ class Compiler { - // Like the first AssembleToSpv method but uses the default compiler options. - SpvCompilationResult AssembleToSpv(const char* source_assembly, - size_t source_assembly_size) const { -- return SpvCompilationResult(shaderc_assemble_into_spv( -- compiler_, source_assembly, source_assembly_size, nullptr)); -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_assemble_into_spv( -+ compiler_, source_assembly, source_assembly_size, nullptr, -+ &compilation_result); -+ return SpvCompilationResult(compilation_result); - } - - // Assembles the given SPIR-V assembly and returns a SPIR-V binary module -@@ -523,9 +532,11 @@ class Compiler { - // std::string. - SpvCompilationResult AssembleToSpv(const std::string& source_assembly, - const CompileOptions& options) const { -- return SpvCompilationResult( -- shaderc_assemble_into_spv(compiler_, source_assembly.data(), -- source_assembly.size(), options.options_)); -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_assemble_into_spv( -+ compiler_, source_assembly.data(), source_assembly.size(), -+ options.options_, &compilation_result); -+ return SpvCompilationResult(compilation_result); - } - - // Assembles the given SPIR-V assembly and returns a SPIR-V binary module -@@ -533,8 +544,10 @@ class Compiler { - // Like the first AssembleToSpv method but the source is provided as a - // std::string and also uses default compiler options. - SpvCompilationResult AssembleToSpv(const std::string& source_assembly) const { -- return SpvCompilationResult(shaderc_assemble_into_spv( -- compiler_, source_assembly.data(), source_assembly.size(), nullptr)); -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_assemble_into_spv(compiler_, source_assembly.data(), -+ source_assembly.size(), nullptr, &compilation_result); -+ return SpvCompilationResult(compilation_result); - } - - // Compiles the given source GLSL and returns the SPIR-V assembly text -@@ -544,10 +557,11 @@ class Compiler { - const char* source_text, size_t source_text_size, - shaderc_shader_kind shader_kind, const char* input_file_name, - const char* entry_point_name, const CompileOptions& options) const { -- shaderc_compilation_result_t compilation_result = -- shaderc_compile_into_spv_assembly( -- compiler_, source_text, source_text_size, shader_kind, -- input_file_name, entry_point_name, options.options_); -+ shaderc_compilation_result_t compilation_result = nullptr; -+ shaderc_compile_into_spv_assembly( -+ compiler_, source_text, source_text_size, shader_kind, -+ input_file_name, entry_point_name, options.options_, -+ &compilation_result); - return AssemblyCompilationResult(compilation_result); - } - -@@ -592,10 +606,10 @@ class Compiler { - const char* source_text, size_t source_text_size, - shaderc_shader_kind shader_kind, const char* input_file_name, - const CompileOptions& options) const { -- shaderc_compilation_result_t compilation_result = -- shaderc_compile_into_preprocessed_text( -+ shaderc_compilation_result_t compilation_result; -+ shaderc_compile_into_preprocessed_text( - compiler_, source_text, source_text_size, shader_kind, -- input_file_name, "main", options.options_); -+ input_file_name, "main", options.options_, &compilation_result); - return PreprocessedSourceCompilationResult(compilation_result); - } - diff --git a/libshaderc/src/shaderc.cc b/libshaderc/src/shaderc.cc index 63f1bbc..c1a9b12 100644 --- a/libshaderc/src/shaderc.cc @@ -334,146 +167,6 @@ index 63f1bbc..c1a9b12 100644 } void shaderc_compile_options_set_optimization_level( -@@ -591,8 +595,31 @@ void shaderc_compiler_release(shaderc_compiler_t compiler) { - delete compiler; - } - -+const char* shaderc_compilation_status_to_string(shaderc_compilation_status status) -+{ -+ static constexpr const std::pair status_names[] = { -+ {shaderc_compilation_status_success, "shaderc_compilation_status_success"}, -+ {shaderc_compilation_status_invalid_stage, "shaderc_compilation_status_invalid_stage"}, -+ {shaderc_compilation_status_compilation_error, "shaderc_compilation_status_compilation_error"}, -+ {shaderc_compilation_status_internal_error, "shaderc_compilation_status_internal_error"}, -+ {shaderc_compilation_status_null_result_object, "shaderc_compilation_status_null_result_object"}, -+ {shaderc_compilation_status_invalid_assembly, "shaderc_compilation_status_invalid_assembly"}, -+ {shaderc_compilation_status_validation_error, "shaderc_compilation_status_validation_error"}, -+ {shaderc_compilation_status_transformation_error, "shaderc_compilation_status_transformation_error"}, -+ {shaderc_compilation_status_configuration_error, "shaderc_compilation_status_configuration_error"}, -+ }; -+ -+ for (const auto& it : status_names) -+ { -+ if (status == it.first) -+ return it.second; -+ } -+ -+ return "shaderc_compilation_status_unknown"; -+} -+ - namespace { --shaderc_compilation_result_t CompileToSpecifiedOutputType( -+shaderc_compilation_result_vector* CompileToSpecifiedOutputType( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -@@ -669,48 +696,59 @@ shaderc_compilation_result_t CompileToSpecifiedOutputType( - } - } // anonymous namespace - --shaderc_compilation_result_t shaderc_compile_into_spv( -+shaderc_compilation_status shaderc_compile_into_spv( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -- const shaderc_compile_options_t additional_options) { -- return CompileToSpecifiedOutputType( -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result) { -+ shaderc_compilation_result_vector* resultv = CompileToSpecifiedOutputType( - compiler, source_text, source_text_size, shader_kind, input_file_name, - entry_point_name, additional_options, - shaderc_util::Compiler::OutputType::SpirvBinary); -+ *result = resultv; -+ return resultv ? resultv->compilation_status : shaderc_compilation_status_internal_error; - } - --shaderc_compilation_result_t shaderc_compile_into_spv_assembly( -+shaderc_compilation_status shaderc_compile_into_spv_assembly( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -- const shaderc_compile_options_t additional_options) { -- return CompileToSpecifiedOutputType( -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result) { -+ shaderc_compilation_result_vector* resultv = CompileToSpecifiedOutputType( - compiler, source_text, source_text_size, shader_kind, input_file_name, - entry_point_name, additional_options, - shaderc_util::Compiler::OutputType::SpirvAssemblyText); -+ *result = resultv; -+ return resultv ? resultv->compilation_status : shaderc_compilation_status_internal_error; - } - --shaderc_compilation_result_t shaderc_compile_into_preprocessed_text( -+shaderc_compilation_status shaderc_compile_into_preprocessed_text( - const shaderc_compiler_t compiler, const char* source_text, - size_t source_text_size, shaderc_shader_kind shader_kind, - const char* input_file_name, const char* entry_point_name, -- const shaderc_compile_options_t additional_options) { -- return CompileToSpecifiedOutputType( -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result) { -+ shaderc_compilation_result_vector* resultv = CompileToSpecifiedOutputType( - compiler, source_text, source_text_size, shader_kind, input_file_name, - entry_point_name, additional_options, - shaderc_util::Compiler::OutputType::PreprocessedText); -+ *result = resultv; -+ return resultv ? resultv->compilation_status : shaderc_compilation_status_internal_error; - } - --shaderc_compilation_result_t shaderc_assemble_into_spv( -+shaderc_compilation_status shaderc_assemble_into_spv( - const shaderc_compiler_t compiler, const char* source_assembly, - size_t source_assembly_size, -- const shaderc_compile_options_t additional_options) { -- auto* result = new (std::nothrow) shaderc_compilation_result_spv_binary; -- if (!result) return nullptr; -- result->compilation_status = shaderc_compilation_status_invalid_assembly; -- if (!compiler->initializer) return result; -- if (source_assembly == nullptr) return result; -+ const shaderc_compile_options_t additional_options, -+ shaderc_compilation_result_t* result) { -+ auto* bresult = new (std::nothrow) shaderc_compilation_result_spv_binary; -+ if (!bresult) return shaderc_compilation_status_internal_error; -+ bresult->compilation_status = shaderc_compilation_status_invalid_assembly; -+ *result = bresult; -+ if (!compiler->initializer) return bresult->compilation_status; -+ if (source_assembly == nullptr) return bresult->compilation_status; - - TRY_IF_EXCEPTIONS_ENABLED { - spv_binary assembling_output_data = nullptr; -@@ -724,22 +762,22 @@ shaderc_compilation_result_t shaderc_assemble_into_spv( - GetCompilerTargetEnvVersion(target_env_version), - {source_assembly, source_assembly + source_assembly_size}, - &assembling_output_data, &errors); -- result->num_errors = !assembling_succeeded; -+ bresult->num_errors = !assembling_succeeded; - if (assembling_succeeded) { -- result->SetOutputData(assembling_output_data); -- result->output_data_size = -+ bresult->SetOutputData(assembling_output_data); -+ bresult->output_data_size = - assembling_output_data->wordCount * sizeof(uint32_t); -- result->compilation_status = shaderc_compilation_status_success; -+ bresult->compilation_status = shaderc_compilation_status_success; - } else { -- result->messages = std::move(errors); -- result->compilation_status = shaderc_compilation_status_invalid_assembly; -+ bresult->messages = std::move(errors); -+ bresult->compilation_status = shaderc_compilation_status_invalid_assembly; - } - } - CATCH_IF_EXCEPTIONS_ENABLED(...) { -- result->compilation_status = shaderc_compilation_status_internal_error; -+ bresult->compilation_status = shaderc_compilation_status_internal_error; - } - -- return result; -+ return bresult->compilation_status; - } - - size_t shaderc_result_get_length(const shaderc_compilation_result_t result) { diff --git a/libshaderc_util/include/libshaderc_util/compiler.h b/libshaderc_util/include/libshaderc_util/compiler.h index d9d02b9..b076ec8 100644 --- a/libshaderc_util/include/libshaderc_util/compiler.h 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 From 2cac643e24b2a8ba4e1930c5a20ec61d40ec9cd9 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Fri, 22 Nov 2024 20:46:20 -0600 Subject: [PATCH 3/3] 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 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