D3D12: use typeless format when CastingFullyTypedFormatSupported is false
This patch adds a check in the creation of D3D12 texture that we should
always use typeless formats for castable textures on the platforms where
CastingFullyTypedFormatSupported is false.
With this patch the test TextureViewSamplingTest.SRGBReinterpretation will
pass on Intel HD530 GPUs.
Bug: dawn:1276
Test: dawn_end2end_tests
Change-Id: I3f49b1c5aac9a0b881469968e22a5228aac9f35f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97184
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/native/Toggles.cpp b/src/dawn/native/Toggles.cpp
index 5f03891..17d676d 100644
--- a/src/dawn/native/Toggles.cpp
+++ b/src/dawn/native/Toggles.cpp
@@ -279,6 +279,12 @@
"Don't set D3D12_CLEAR_VALUE when creating depth textures with CreatePlacedResource() or "
"CreateCommittedResource() as a workaround on Intel Gen12 D3D12 drivers.",
"https://crbug.com/dawn/1487"}},
+ {Toggle::D3D12AlwaysUseTypelessFormatsForCastableTexture,
+ {"d3d12_always_use_typeless_formats_for_castable_texture",
+ "Always use the typeless DXGI format when we create a texture with valid viewFormat. This "
+ "Toggle is enabled by default on the D3D12 platforms where CastingFullyTypedFormatSupported "
+ "is false.",
+ "https://crbug.com/dawn/1276"}},
// Comment to separate the }} so it is clearer what to copy-paste to add a toggle.
}};
} // anonymous namespace
diff --git a/src/dawn/native/Toggles.h b/src/dawn/native/Toggles.h
index d6c3664..22c1198 100644
--- a/src/dawn/native/Toggles.h
+++ b/src/dawn/native/Toggles.h
@@ -74,6 +74,7 @@
EnableBlobCache,
D3D12ForceInitializeCopyableDepthStencilTextureOnCreation,
D3D12DontSetClearValueOnDepthTextureCreation,
+ D3D12AlwaysUseTypelessFormatsForCastableTexture,
EnumCount,
InvalidEnum = EnumCount,
diff --git a/src/dawn/native/d3d12/D3D12Info.cpp b/src/dawn/native/d3d12/D3D12Info.cpp
index 6a4c435..6bbb865 100644
--- a/src/dawn/native/d3d12/D3D12Info.cpp
+++ b/src/dawn/native/d3d12/D3D12Info.cpp
@@ -38,12 +38,31 @@
info.isUMA = arch.UMA;
- D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
- DAWN_TRY(CheckHRESULT(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,
- &options, sizeof(options)),
+ D3D12_FEATURE_DATA_D3D12_OPTIONS featureOptions = {};
+ DAWN_TRY(CheckHRESULT(adapter.GetDevice()->CheckFeatureSupport(
+ D3D12_FEATURE_D3D12_OPTIONS, &featureOptions, sizeof(featureOptions)),
"ID3D12Device::CheckFeatureSupport"));
+ info.resourceHeapTier = featureOptions.ResourceHeapTier;
- info.resourceHeapTier = options.ResourceHeapTier;
+ D3D12_FEATURE_DATA_D3D12_OPTIONS3 featureOptions3 = {};
+ if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport(
+ D3D12_FEATURE_D3D12_OPTIONS3, &featureOptions3, sizeof(featureOptions3)))) {
+ info.supportsCastingFullyTypedFormat = featureOptions3.CastingFullyTypedFormatSupported;
+ }
+
+ // Used to share resources cross-API. If we query CheckFeatureSupport for
+ // D3D12_FEATURE_D3D12_OPTIONS4 successfully, then we can use cross-API sharing.
+ info.supportsSharedResourceCapabilityTier1 = false;
+ D3D12_FEATURE_DATA_D3D12_OPTIONS4 featureOptions4 = {};
+ if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport(
+ D3D12_FEATURE_D3D12_OPTIONS4, &featureOptions4, sizeof(featureOptions4)))) {
+ // Tier 1 support additionally enables the NV12 format. Since only the NV12 format
+ // is used by Dawn, check for Tier 1.
+ if (featureOptions4.SharedResourceCompatibilityTier >=
+ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1) {
+ info.supportsSharedResourceCapabilityTier1 = true;
+ }
+ }
// Windows builds 1809 and above can use the D3D12 render pass API. If we query
// CheckFeatureSupport for D3D12_FEATURE_D3D12_OPTIONS5 successfully, then we can use
@@ -61,20 +80,6 @@
}
}
- // Used to share resources cross-API. If we query CheckFeatureSupport for
- // D3D12_FEATURE_D3D12_OPTIONS4 successfully, then we can use cross-API sharing.
- info.supportsSharedResourceCapabilityTier1 = false;
- D3D12_FEATURE_DATA_D3D12_OPTIONS4 featureOptions4 = {};
- if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS4, &featureOptions4, sizeof(featureOptions4)))) {
- // Tier 1 support additionally enables the NV12 format. Since only the NV12 format
- // is used by Dawn, check for Tier 1.
- if (featureOptions4.SharedResourceCompatibilityTier >=
- D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1) {
- info.supportsSharedResourceCapabilityTier1 = true;
- }
- }
-
D3D12_FEATURE_DATA_SHADER_MODEL knownShaderModels[] = {
{D3D_SHADER_MODEL_6_4}, {D3D_SHADER_MODEL_6_3}, {D3D_SHADER_MODEL_6_2},
{D3D_SHADER_MODEL_6_1}, {D3D_SHADER_MODEL_6_0}, {D3D_SHADER_MODEL_5_1}};
@@ -110,12 +115,8 @@
info.shaderProfiles[SingleShaderStage::Fragment] = L"p" + profileSuffix;
info.shaderProfiles[SingleShaderStage::Compute] = L"c" + profileSuffix;
- D3D12_FEATURE_DATA_D3D12_OPTIONS4 featureData4 = {};
- if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS4,
- &featureData4, sizeof(featureData4)))) {
- info.supportsShaderFloat16 =
- driverShaderModel >= D3D_SHADER_MODEL_6_2 && featureData4.Native16BitShaderOpsSupported;
- }
+ info.supportsShaderFloat16 =
+ driverShaderModel >= D3D_SHADER_MODEL_6_2 && featureOptions4.Native16BitShaderOpsSupported;
info.supportsDP4a = driverShaderModel >= D3D_SHADER_MODEL_6_4;
diff --git a/src/dawn/native/d3d12/D3D12Info.h b/src/dawn/native/d3d12/D3D12Info.h
index e0f2a66..d985f55 100644
--- a/src/dawn/native/d3d12/D3D12Info.h
+++ b/src/dawn/native/d3d12/D3D12Info.h
@@ -34,6 +34,7 @@
PerStage<std::wstring> shaderProfiles;
bool supportsSharedResourceCapabilityTier1;
bool supportsDP4a;
+ bool supportsCastingFullyTypedFormat;
};
ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter);
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index 7b67035..1a43169 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -637,6 +637,8 @@
SetToggle(Toggle::UseD3D12RenderPass, GetDeviceInfo().supportsRenderPass);
SetToggle(Toggle::UseD3D12ResidencyManagement, true);
SetToggle(Toggle::UseDXC, false);
+ SetToggle(Toggle::D3D12AlwaysUseTypelessFormatsForCastableTexture,
+ !GetDeviceInfo().supportsCastingFullyTypedFormat);
// Disable optimizations when using FXC
// See https://crbug.com/dawn/1203
diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp
index cd17ada1..041a498 100644
--- a/src/dawn/native/d3d12/TextureD3D12.cpp
+++ b/src/dawn/native/d3d12/TextureD3D12.cpp
@@ -583,8 +583,11 @@
// This will need to be much more nuanced when WebGPU has
// texture view compatibility rules.
- const bool needsTypelessFormat = GetFormat().HasDepthOrStencil() &&
- (GetInternalUsage() & wgpu::TextureUsage::TextureBinding) != 0;
+ const bool needsTypelessFormat =
+ (GetDevice()->IsToggleEnabled(Toggle::D3D12AlwaysUseTypelessFormatsForCastableTexture) &&
+ GetViewFormats().any()) ||
+ (GetFormat().HasDepthOrStencil() &&
+ (GetInternalUsage() & wgpu::TextureUsage::TextureBinding) != 0);
DXGI_FORMAT dxgiFormat = needsTypelessFormat ? D3D12TypelessTextureFormat(GetFormat().format)
: D3D12TextureFormat(GetFormat().format);