From 52feb1a37d6b743dc307079237eb379a996d7d5c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 5 Dec 2024 23:51:25 +1000 Subject: [PATCH] PostProcessing: Improve compile error reporting --- src/util/postprocessing.cpp | 7 ++++--- src/util/postprocessing_shader.h | 5 +++-- src/util/postprocessing_shader_fx.cpp | 28 ++++++++++++------------- src/util/postprocessing_shader_fx.h | 5 +++-- src/util/postprocessing_shader_glsl.cpp | 16 +++++++------- src/util/postprocessing_shader_glsl.h | 5 +++-- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index 030a77f40..79717708e 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -583,16 +583,17 @@ bool PostProcessing::Chain::CheckTargets(GPUTexture::Format target_format, u32 t m_wants_depth_buffer = false; + Error error; for (size_t i = 0; i < m_stages.size(); i++) { Shader* const shader = m_stages[i].get(); progress->FormatStatusText("Compiling {}...", shader->GetName()); - if (!shader->CompilePipeline(target_format, target_width, target_height, progress) || - !shader->ResizeOutput(target_format, target_width, target_height)) + if (!shader->CompilePipeline(target_format, target_width, target_height, &error, progress) || + !shader->ResizeOutput(target_format, target_width, target_height, &error)) { - ERROR_LOG("Failed to compile one or more post-processing shaders, disabling."); + ERROR_LOG("Failed to compile post-processing shader '{}':\n{}", shader->GetName(), error.GetDescription()); Host::AddIconOSDMessage( "PostProcessLoadFail", ICON_FA_EXCLAMATION_TRIANGLE, fmt::format("Failed to compile post-processing shader '{}'. Disabling post-processing.", shader->GetName())); diff --git a/src/util/postprocessing_shader.h b/src/util/postprocessing_shader.h index 8d2c73f5d..b9137b71a 100644 --- a/src/util/postprocessing_shader.h +++ b/src/util/postprocessing_shader.h @@ -44,9 +44,10 @@ public: const ShaderOption* GetOptionByName(std::string_view name) const; ShaderOption* GetOptionByName(std::string_view name); - virtual bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) = 0; + virtual bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height, Error* error) = 0; - virtual bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) = 0; + virtual bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, Error* error, + ProgressCallback* progress) = 0; virtual GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index 301170e69..1abe6ad47 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -1321,7 +1321,7 @@ GPUTexture* PostProcessing::ReShadeFXShader::GetTextureByID(TextureID id, GPUTex return m_textures[static_cast(id)].texture.get(); } -bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format, u32 width, u32 height, +bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format, u32 width, u32 height, Error* error, ProgressCallback* progress) { m_valid = false; @@ -1342,31 +1342,29 @@ bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format, const auto& [cg, cg_language] = CreateRFXCodegen(false); - Error error; - if (!CreateModule(width, height, cg.get(), cg_language, std::move(fxcode), &error)) + if (!CreateModule(width, height, cg.get(), cg_language, std::move(fxcode), error)) { - ERROR_LOG("Failed to create module for '{}': {}", m_name, error.GetDescription()); + Error::AddPrefix(error, "Failed to create module: "); return false; } const reshadefx::effect_module& mod = cg->module(); DebugAssert(!mod.techniques.empty()); - if (!CreatePasses(format, mod, &error)) + if (!CreatePasses(format, mod, error)) { - ERROR_LOG("Failed to create passes for '{}': {}", m_name, error.GetDescription()); + Error::AddPrefix(error, "Failed to create passes: "); return false; } - auto get_shader = [cg_language, &cg](const std::string& name, const std::span samplers, - GPUShaderStage stage) { + auto get_shader = [cg_language, &cg, error](const std::string& name, const std::span samplers, + GPUShaderStage stage) { const std::string real_code = cg->finalize_code_for_entry_point(name); const char* entry_point = (cg_language == GPUShaderLanguage::HLSL) ? name.c_str() : "main"; - Error error; - std::unique_ptr sshader = g_gpu_device->CreateShader(stage, cg_language, real_code, &error, entry_point); + std::unique_ptr sshader = g_gpu_device->CreateShader(stage, cg_language, real_code, error, entry_point); if (!sshader) - ERROR_LOG("Failed to compile function '{}': {}", name, error.GetDescription()); + Error::AddPrefixFmt(error, "Failed to compile function '{}': ", name); return sshader; }; @@ -1426,10 +1424,10 @@ bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format, return false; } - pass.pipeline = g_gpu_device->CreatePipeline(plconfig, &error); + pass.pipeline = g_gpu_device->CreatePipeline(plconfig, error); if (!pass.pipeline) { - ERROR_LOG("Failed to create pipeline for pass '{}': {}", info.name, error.GetDescription()); + Error::AddPrefixFmt(error, "Failed to create pipeline for pass '{}': ", info.name); progress->PopState(); return false; } @@ -1444,7 +1442,7 @@ bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format, return true; } -bool PostProcessing::ReShadeFXShader::ResizeOutput(GPUTexture::Format format, u32 width, u32 height) +bool PostProcessing::ReShadeFXShader::ResizeOutput(GPUTexture::Format format, u32 width, u32 height, Error* error) { m_valid = false; @@ -1458,7 +1456,7 @@ bool PostProcessing::ReShadeFXShader::ResizeOutput(GPUTexture::Format format, u3 const u32 t_width = std::max(static_cast(static_cast(width) * tex.rt_scale), 1u); const u32 t_height = std::max(static_cast(static_cast(height) * tex.rt_scale), 1u); tex.texture = g_gpu_device->FetchTexture(t_width, t_height, 1, 1, 1, GPUTexture::Type::RenderTarget, tex.format, - GPUTexture::Flags::None); + GPUTexture::Flags::None, nullptr, 0, error); if (!tex.texture) return {}; } diff --git a/src/util/postprocessing_shader_fx.h b/src/util/postprocessing_shader_fx.h index 286026d14..2f20e2147 100644 --- a/src/util/postprocessing_shader_fx.h +++ b/src/util/postprocessing_shader_fx.h @@ -33,8 +33,9 @@ public: bool LoadFromFile(std::string name, std::string filename, bool only_config, Error* error); bool LoadFromString(std::string name, std::string filename, std::string code, bool only_config, Error* error); - bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) override; - bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) override; + bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height, Error* error) override; + bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, Error* error, + ProgressCallback* progress) override; GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, s32 native_height, u32 target_width, u32 target_height) override; diff --git a/src/util/postprocessing_shader_glsl.cpp b/src/util/postprocessing_shader_glsl.cpp index 95ecb5423..c699b51a5 100644 --- a/src/util/postprocessing_shader_glsl.cpp +++ b/src/util/postprocessing_shader_glsl.cpp @@ -121,7 +121,7 @@ void PostProcessing::GLSLShader::FillUniformBuffer(void* buffer, s32 viewport_x, } } -bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32 width, u32 height, +bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32 width, u32 height, Error* error, ProgressCallback* progress) { if (m_pipeline) @@ -130,10 +130,10 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32 PostProcessingGLSLShaderGen shadergen(g_gpu_device->GetRenderAPI(), g_gpu_device->GetFeatures().dual_source_blend, g_gpu_device->GetFeatures().framebuffer_fetch); - std::unique_ptr vs = g_gpu_device->CreateShader(GPUShaderStage::Vertex, shadergen.GetLanguage(), - shadergen.GeneratePostProcessingVertexShader(*this)); - std::unique_ptr fs = g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(), - shadergen.GeneratePostProcessingFragmentShader(*this)); + std::unique_ptr vs = g_gpu_device->CreateShader( + GPUShaderStage::Vertex, shadergen.GetLanguage(), shadergen.GeneratePostProcessingVertexShader(*this), error); + std::unique_ptr fs = g_gpu_device->CreateShader( + GPUShaderStage::Fragment, shadergen.GetLanguage(), shadergen.GeneratePostProcessingFragmentShader(*this), error); if (!vs || !fs) return false; @@ -151,7 +151,7 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32 plconfig.fragment_shader = fs.get(); plconfig.geometry_shader = nullptr; - if (!(m_pipeline = g_gpu_device->CreatePipeline(plconfig))) + if (!(m_pipeline = g_gpu_device->CreatePipeline(plconfig, error))) return false; if (!m_sampler) @@ -160,7 +160,7 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32 config.address_u = GPUSampler::AddressMode::ClampToBorder; config.address_v = GPUSampler::AddressMode::ClampToBorder; config.border_color = 0xFF000000u; - if (!(m_sampler = g_gpu_device->CreateSampler(config))) + if (!(m_sampler = g_gpu_device->CreateSampler(config, error))) return false; } @@ -201,7 +201,7 @@ GPUDevice::PresentResult PostProcessing::GLSLShader::Apply(GPUTexture* input_col return GPUDevice::PresentResult::OK; } -bool PostProcessing::GLSLShader::ResizeOutput(GPUTexture::Format format, u32 width, u32 height) +bool PostProcessing::GLSLShader::ResizeOutput(GPUTexture::Format format, u32 width, u32 height, Error* error) { return true; } diff --git a/src/util/postprocessing_shader_glsl.h b/src/util/postprocessing_shader_glsl.h index 7fc617dad..c983ffdfb 100644 --- a/src/util/postprocessing_shader_glsl.h +++ b/src/util/postprocessing_shader_glsl.h @@ -22,8 +22,9 @@ public: bool LoadFromFile(std::string name, const char* filename, Error* error); bool LoadFromString(std::string name, std::string code, Error* error); - bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) override; - bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) override; + bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height, Error* error) override; + bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, Error* error, + ProgressCallback* progress) override; GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, s32 native_height, u32 target_width, u32 target_height) override;