Add "fxc_optimizations" toggle set to false by default

FXC sometimes miscompiles code when optimizing (/O2), and there is no
discernable workaround. This change sets the optimization level to /O0
when compiling shaders with FXC.

Also, no longer default to enabling EmitHLSLDebugSymbols in Debug
builds, which disabled optimizations (/Od). This confused me a few
times, and is not necessary since we can set this toggle via command
line.

Bug: dawn:1203
Bug: tint:1175
Bug: tint:1112
Change-Id: Ide9e6ecd45adeca951b8836dee91a8367eca3769
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/70700
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2021-11-25 13:24:50 +00:00 committed by Dawn LUCI CQ
parent 802292eb52
commit db6aa8a4ad
5 changed files with 20 additions and 4 deletions

View File

@ -225,6 +225,12 @@ namespace dawn_native {
"be enabled for OpenGL ES backend, and serves as a workaround by default enabled on " "be enabled for OpenGL ES backend, and serves as a workaround by default enabled on "
"some Metal devices with Intel GPU to ensure the depth result is correct.", "some Metal devices with Intel GPU to ensure the depth result is correct.",
"https://crbug.com/dawn/136"}}, "https://crbug.com/dawn/136"}},
{Toggle::FxcOptimizations,
{"fxc_optimizations",
"Enable optimizations when compiling with FXC. Disabled by default because FXC "
"miscompiles in many cases when optimizations are enabled.",
"https://crbug.com/dawn/1203"}},
// Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle. // Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle.
}}; }};
} // anonymous namespace } // anonymous namespace

View File

@ -60,6 +60,7 @@ namespace dawn_native {
UseUserDefinedLabelsInBackend, UseUserDefinedLabelsInBackend,
DisableR8RG8Mipmaps, DisableR8RG8Mipmaps,
UseDummyFragmentInVertexOnlyPipeline, UseDummyFragmentInVertexOnlyPipeline,
FxcOptimizations,
EnumCount, EnumCount,
InvalidEnum = EnumCount, InvalidEnum = EnumCount,

View File

@ -34,6 +34,11 @@ namespace dawn_native { namespace d3d12 {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
uint32_t compileFlags = 0; uint32_t compileFlags = 0;
if (!device->IsToggleEnabled(Toggle::UseDXC) &&
!device->IsToggleEnabled(Toggle::FxcOptimizations)) {
compileFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL0;
}
if (device->IsToggleEnabled(Toggle::EmitHLSLDebugSymbols)) { if (device->IsToggleEnabled(Toggle::EmitHLSLDebugSymbols)) {
compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
} }

View File

@ -518,10 +518,9 @@ namespace dawn_native { namespace d3d12 {
SetToggle(Toggle::UseD3D12ResidencyManagement, true); SetToggle(Toggle::UseD3D12ResidencyManagement, true);
SetToggle(Toggle::UseDXC, false); SetToggle(Toggle::UseDXC, false);
#if defined(_DEBUG) // Disable optimizations when using FXC
// Enable better shader debugging with the graphics debugging tools. // See https://crbug.com/dawn/1203
SetToggle(Toggle::EmitHLSLDebugSymbols, true); SetToggle(Toggle::FxcOptimizations, false);
#endif
// By default use the maximum shader-visible heap size allowed. // By default use the maximum shader-visible heap size allowed.
SetToggle(Toggle::UseD3D12SmallShaderVisibleHeapForTesting, false); SetToggle(Toggle::UseD3D12SmallShaderVisibleHeapForTesting, false);

View File

@ -326,6 +326,11 @@ namespace dawn_native { namespace d3d12 {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
uint32_t compileFlags = 0; uint32_t compileFlags = 0;
if (!device->IsToggleEnabled(Toggle::UseDXC) &&
!device->IsToggleEnabled(Toggle::FxcOptimizations)) {
compileFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL0;
}
if (device->IsToggleEnabled(Toggle::EmitHLSLDebugSymbols)) { if (device->IsToggleEnabled(Toggle::EmitHLSLDebugSymbols)) {
compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
} }