Skip to content

Commit fa40733

Browse files
authored
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
1 parent 34d4dc5 commit fa40733

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/cascadia/TerminalControl/Resources/en-US/Resources.resw

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ Please either install the missing font or choose another one.</value>
207207
<comment>{0} is a file name</comment>
208208
</data>
209209
<data name="PixelShaderCompileFailed" xml:space="preserve">
210-
<value>Unable to compile the specified pixel shader.</value>
210+
<value>Pixel shader failed to compile: {0}</value>
211+
<comment>{0} is the error message generated by the compiler</comment>
211212
</data>
212213
<data name="UnexpectedRendererError" xml:space="preserve">
213214
<value>Renderer encountered an unexpected error: {0}</value>
@@ -223,7 +224,7 @@ Please either install the missing font or choose another one.</value>
223224
</data>
224225
<data name="RendererErrorOther" xml:space="preserve">
225226
<value>Renderer encountered an unexpected error: {0:#010x} {1}</value>
226-
<comment>{Locked="{0:#010x}","{1}"} {0:#010x} is a placeholder for a Windows error code (e.g. 0x88985002). {1} is the corresponding message.</comment>
227+
<comment>{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.</comment>
227228
</data>
228229
<data name="TermControlReadOnly" xml:space="preserve">
229230
<value>Read-only mode is enabled.</value>
@@ -320,4 +321,4 @@ Please either install the missing font or choose another one.</value>
320321
<value>Suggested input: {0}</value>
321322
<comment>{Locked="{0}"} {0} will be replaced with a string of input that is suggested for the user to input</comment>
322323
</data>
323-
</root>
324+
</root>

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
11621162
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"PixelShaderNotFound") }, parameter) };
11631163
break;
11641164
case D2DERR_SHADER_COMPILE_FAILED:
1165-
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"PixelShaderCompileFailed") }) };
1165+
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"PixelShaderCompileFailed") }, parameter) };
11661166
break;
11671167
case DWRITE_E_NOFONT:
11681168
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"RendererErrorFontNotFound") }, parameter) };
@@ -1175,7 +1175,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
11751175
wchar_t buf[512];
11761176
const auto len = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &buf[0], ARRAYSIZE(buf), nullptr);
11771177
const std::wstring_view msg{ &buf[0], len };
1178-
message = winrt::hstring{ fmt::format(std::wstring_view{ RS_(L"RendererErrorOther") }, hr, msg) };
1178+
std::wstring resourceString = RS_(L"RendererErrorOther").c_str();
1179+
//conditional message construction
1180+
std::wstring partialMessage = fmt::format(std::wstring_view{ resourceString }, hr, msg);
1181+
if (!parameter.empty())
1182+
{
1183+
fmt::format_to(std::back_inserter(partialMessage), LR"( "{0}")", parameter);
1184+
}
1185+
message = winrt::hstring{ partialMessage };
11791186
break;
11801187
}
11811188
}

src/renderer/atlas/BackendD3D.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "dwrite.h"
1616
#include "wic.h"
1717
#include "../../types/inc/ColorFix.hpp"
18+
#include "../../types/inc/convert.hpp"
1819

1920
#if ATLAS_DEBUG_SHOW_DIRTY || ATLAS_DEBUG_COLORIZE_GLYPH_ATLAS
2021
#include <til/colorbrewer.h>
@@ -451,15 +452,21 @@ void BackendD3D::_recreateCustomShader(const RenderingPayload& p)
451452
{
452453
if (error)
453454
{
454-
LOG_HR_MSG(hr, "%.*hs", static_cast<int>(error->GetBufferSize()), static_cast<char*>(error->GetBufferPointer()));
455+
if (p.warningCallback)
456+
{
457+
//to handle compile time errors
458+
const std::string_view errMsgStrView{ static_cast<const char*>(error->GetBufferPointer()), error->GetBufferSize() };
459+
const auto errMsgWstring = ConvertToW(CP_ACP, errMsgStrView);
460+
p.warningCallback(D2DERR_SHADER_COMPILE_FAILED, errMsgWstring);
461+
}
455462
}
456463
else
457464
{
458-
LOG_HR(hr);
459-
}
460-
if (p.warningCallback)
461-
{
462-
p.warningCallback(D2DERR_SHADER_COMPILE_FAILED, p.s->misc->customPixelShaderPath);
465+
if (p.warningCallback)
466+
{
467+
//to handle errors such as file not found, path not found, access denied
468+
p.warningCallback(hr, p.s->misc->customPixelShaderPath);
469+
}
463470
}
464471
}
465472

0 commit comments

Comments
 (0)