From fa407332a5970164277919dc038f272c04628c9e Mon Sep 17 00:00:00 2001
From: blitzRahul <104504393+blitzRahul@users.noreply.github.com>
Date: Sat, 22 Jun 2024 02:55:49 +0530
Subject: [PATCH] Display useful pixel shader compilation errors (#17436)
More descriptive warnings are triggered when custom pixel shader
compilation fails.
If D3DCompileFromFile fails and the compiler generates an error message-
the message is converted to a wstring and is sent as a parameter when
calling p.warningCallback.
Changes were made to resources.resw and TermControl.cpp to accommodate
this.
## Validation Steps Performed
I tested the following errors that may be encountered while developing a
custom pixel shader:
1. Compile time errors
2. File not found error
3. Path not found error
4. Access denied error
Fixes #17435
TAEF tests passed:
Summary: Total=294, Passed=294, Failed=0, Blocked=0, Not Run=0,
Skipped=0
---
.../Resources/en-US/Resources.resw | 7 ++++---
src/cascadia/TerminalControl/TermControl.cpp | 11 +++++++++--
src/renderer/atlas/BackendD3D.cpp | 19 +++++++++++++------
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/cascadia/TerminalControl/Resources/en-US/Resources.resw b/src/cascadia/TerminalControl/Resources/en-US/Resources.resw
index 54c6a4643b5..d618171e58b 100644
--- a/src/cascadia/TerminalControl/Resources/en-US/Resources.resw
+++ b/src/cascadia/TerminalControl/Resources/en-US/Resources.resw
@@ -207,7 +207,8 @@ Please either install the missing font or choose another one.
{0} is a file name
- Unable to compile the specified pixel shader.
+ Pixel shader failed to compile: {0}
+ {0} is the error message generated by the compiler
Renderer encountered an unexpected error: {0}
@@ -223,7 +224,7 @@ Please either install the missing font or choose another one.
Renderer encountered an unexpected error: {0:#010x} {1}
- {Locked="{0:#010x}","{1}"} {0:#010x} is a placeholder for a Windows error code (e.g. 0x88985002). {1} is the corresponding message.
+ {Locked="{0:#010x}","{1}"} {0:#010x} is a placeholder for a Windows error code (e.g. 0x88985002). {1} is the corresponding message. {2} is the filename.
Read-only mode is enabled.
@@ -320,4 +321,4 @@ Please either install the missing font or choose another one.
Suggested input: {0}
{Locked="{0}"} {0} will be replaced with a string of input that is suggested for the user to input
-
+
\ No newline at end of file
diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp
index 1fffe66dc50..bc045f36381 100644
--- a/src/cascadia/TerminalControl/TermControl.cpp
+++ b/src/cascadia/TerminalControl/TermControl.cpp
@@ -1162,7 +1162,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"PixelShaderNotFound") }, parameter) };
break;
case D2DERR_SHADER_COMPILE_FAILED:
- message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"PixelShaderCompileFailed") }) };
+ message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"PixelShaderCompileFailed") }, parameter) };
break;
case DWRITE_E_NOFONT:
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"RendererErrorFontNotFound") }, parameter) };
@@ -1175,7 +1175,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
wchar_t buf[512];
const auto len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &buf[0], ARRAYSIZE(buf), nullptr);
const std::wstring_view msg{ &buf[0], len };
- message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"RendererErrorOther") }, hr, msg) };
+ std::wstring resourceString = RS_(L"RendererErrorOther").c_str();
+ //conditional message construction
+ std::wstring partialMessage = fmt::format(std::wstring_view{ resourceString }, hr, msg);
+ if (!parameter.empty())
+ {
+ fmt::format_to(std::back_inserter(partialMessage), LR"( "{0}")", parameter);
+ }
+ message = winrt::hstring{ partialMessage };
break;
}
}
diff --git a/src/renderer/atlas/BackendD3D.cpp b/src/renderer/atlas/BackendD3D.cpp
index 562d8ae7905..9a83b75d233 100644
--- a/src/renderer/atlas/BackendD3D.cpp
+++ b/src/renderer/atlas/BackendD3D.cpp
@@ -15,6 +15,7 @@
#include "dwrite.h"
#include "wic.h"
#include "../../types/inc/ColorFix.hpp"
+#include "../../types/inc/convert.hpp"
#if ATLAS_DEBUG_SHOW_DIRTY || ATLAS_DEBUG_COLORIZE_GLYPH_ATLAS
#include
@@ -451,15 +452,21 @@ void BackendD3D::_recreateCustomShader(const RenderingPayload& p)
{
if (error)
{
- LOG_HR_MSG(hr, "%.*hs", static_cast(error->GetBufferSize()), static_cast(error->GetBufferPointer()));
+ if (p.warningCallback)
+ {
+ //to handle compile time errors
+ const std::string_view errMsgStrView{ static_cast(error->GetBufferPointer()), error->GetBufferSize() };
+ const auto errMsgWstring = ConvertToW(CP_ACP, errMsgStrView);
+ p.warningCallback(D2DERR_SHADER_COMPILE_FAILED, errMsgWstring);
+ }
}
else
{
- LOG_HR(hr);
- }
- if (p.warningCallback)
- {
- p.warningCallback(D2DERR_SHADER_COMPILE_FAILED, p.s->misc->customPixelShaderPath);
+ if (p.warningCallback)
+ {
+ //to handle errors such as file not found, path not found, access denied
+ p.warningCallback(hr, p.s->misc->customPixelShaderPath);
+ }
}
}