diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp index e366cf14b0..a0fb5ffcc9 100644 --- a/src/dawn_native/Toggles.cpp +++ b/src/dawn_native/Toggles.cpp @@ -126,7 +126,9 @@ namespace dawn_native { "default. This setting is used to test bindgroup encoding.", "https://crbug.com/dawn/155"}}, {Toggle::UseDXC, - {"use_dxc", "Use DXC instead of FXC for compiling HLSL", + {"use_dxc", + "Use DXC instead of FXC for compiling HLSL when both dxcompiler.dll and dxil.dll " + "is available.", "https://crbug.com/dawn/402"}}, {Toggle::DisableRobustness, {"disable_robustness", "Disable robust buffer access", "https://crbug.com/dawn/480"}}, diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 753d5779dd..a261143d25 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -153,6 +153,10 @@ namespace dawn_native { namespace d3d12 { // Device shouldn't be used until after DeviceBase::Initialize so we must wait until after // device initialization to call NextSerial DAWN_TRY(NextSerial()); + + // The environment can only use DXC when it's available. Override the decision if it is not + // applicable. + ApplyUseDxcToggle(); return {}; } @@ -188,6 +192,12 @@ namespace dawn_native { namespace d3d12 { return ToBackend(GetAdapter())->GetBackend()->GetFactory(); } + void Device::ApplyUseDxcToggle() { + if (!ToBackend(GetAdapter())->GetBackend()->GetFunctions()->IsDXCAvailable()) { + ForceSetToggle(Toggle::UseDXC, false); + } + } + ResultOrError Device::GetOrCreateDxcLibrary() const { return ToBackend(GetAdapter())->GetBackend()->GetOrCreateDxcLibrary(); } diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index f7737af116..5d54a3ea1d 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -178,6 +178,8 @@ namespace dawn_native { namespace d3d12 { MaybeError CheckDebugLayerAndGenerateErrors(); + void ApplyUseDxcToggle(); + ComPtr mFence; HANDLE mFenceEvent = nullptr; ExecutionSerial CheckAndUpdateCompletedSerials() override; diff --git a/src/tests/end2end/ShaderFloat16Tests.cpp b/src/tests/end2end/ShaderFloat16Tests.cpp index fa0fd4784c..1f4f445ef5 100644 --- a/src/tests/end2end/ShaderFloat16Tests.cpp +++ b/src/tests/end2end/ShaderFloat16Tests.cpp @@ -108,4 +108,4 @@ TEST_P(ShaderFloat16Tests, Basic16BitFloatFeaturesTest) { EXPECT_BUFFER_U16_RANGE_EQ(expected, bufferOut, 0, 2); } -DAWN_INSTANTIATE_TEST(ShaderFloat16Tests, MetalBackend(), VulkanBackend()); +DAWN_INSTANTIATE_TEST(ShaderFloat16Tests, D3D12Backend(), MetalBackend(), VulkanBackend());