Skip to content

Commit

Permalink
(fix:) Fix VKShaderCache.cpp as it was causing XBSX2 to no longer build.
Browse files Browse the repository at this point in the history
  • Loading branch information
SternXD committed Dec 3, 2024
1 parent 72516bb commit 6666e66
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -205,6 +205,27 @@ 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::SPIRVCodeVector> VKShaderCache::CompileShaderToSPV(u32 stage, std::string_view source, bool debug)
{
std::optional<VKShaderCache::SPIRVCodeVector> ret;
Expand All @@ -216,21 +237,25 @@ std::optional<VKShaderCache::SPIRVCodeVector> 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<shaderc_shader_kind>(stage), "source",
"main", options, &result);
if (status != shaderc_compilation_status_success)
"main", options);

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: {}\n{}",
dyn_shaderc::shaderc_compilation_status_to_string(status), 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
Expand Down Expand Up @@ -682,4 +707,4 @@ std::optional<VKShaderCache::SPIRVCodeVector> VKShaderCache::CompileAndAddShader

m_index.emplace(key, data);
return spv;
}
}

0 comments on commit 6666e66

Please sign in to comment.