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>
This commit is contained in:
Jiawei Shao 2022-07-28 01:48:38 +00:00 committed by Dawn LUCI CQ
parent 71cf45763e
commit c44a577cd8
6 changed files with 40 additions and 26 deletions

View File

@ -279,6 +279,12 @@ static constexpr ToggleEnumAndInfoList kToggleNameAndInfoList = {{
"Don't set D3D12_CLEAR_VALUE when creating depth textures with CreatePlacedResource() or " "Don't set D3D12_CLEAR_VALUE when creating depth textures with CreatePlacedResource() or "
"CreateCommittedResource() as a workaround on Intel Gen12 D3D12 drivers.", "CreateCommittedResource() as a workaround on Intel Gen12 D3D12 drivers.",
"https://crbug.com/dawn/1487"}}, "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. // Comment to separate the }} so it is clearer what to copy-paste to add a toggle.
}}; }};
} // anonymous namespace } // anonymous namespace

View File

@ -74,6 +74,7 @@ enum class Toggle {
EnableBlobCache, EnableBlobCache,
D3D12ForceInitializeCopyableDepthStencilTextureOnCreation, D3D12ForceInitializeCopyableDepthStencilTextureOnCreation,
D3D12DontSetClearValueOnDepthTextureCreation, D3D12DontSetClearValueOnDepthTextureCreation,
D3D12AlwaysUseTypelessFormatsForCastableTexture,
EnumCount, EnumCount,
InvalidEnum = EnumCount, InvalidEnum = EnumCount,

View File

@ -38,12 +38,31 @@ ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter) {
info.isUMA = arch.UMA; info.isUMA = arch.UMA;
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {}; D3D12_FEATURE_DATA_D3D12_OPTIONS featureOptions = {};
DAWN_TRY(CheckHRESULT(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, DAWN_TRY(CheckHRESULT(adapter.GetDevice()->CheckFeatureSupport(
&options, sizeof(options)), D3D12_FEATURE_D3D12_OPTIONS, &featureOptions, sizeof(featureOptions)),
"ID3D12Device::CheckFeatureSupport")); "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 // 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 // CheckFeatureSupport for D3D12_FEATURE_D3D12_OPTIONS5 successfully, then we can use
@ -61,20 +80,6 @@ ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter) {
} }
} }
// 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[] = { 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_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}}; {D3D_SHADER_MODEL_6_1}, {D3D_SHADER_MODEL_6_0}, {D3D_SHADER_MODEL_5_1}};
@ -110,12 +115,8 @@ ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter) {
info.shaderProfiles[SingleShaderStage::Fragment] = L"p" + profileSuffix; info.shaderProfiles[SingleShaderStage::Fragment] = L"p" + profileSuffix;
info.shaderProfiles[SingleShaderStage::Compute] = L"c" + profileSuffix; info.shaderProfiles[SingleShaderStage::Compute] = L"c" + profileSuffix;
D3D12_FEATURE_DATA_D3D12_OPTIONS4 featureData4 = {}; info.supportsShaderFloat16 =
if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS4, driverShaderModel >= D3D_SHADER_MODEL_6_2 && featureOptions4.Native16BitShaderOpsSupported;
&featureData4, sizeof(featureData4)))) {
info.supportsShaderFloat16 =
driverShaderModel >= D3D_SHADER_MODEL_6_2 && featureData4.Native16BitShaderOpsSupported;
}
info.supportsDP4a = driverShaderModel >= D3D_SHADER_MODEL_6_4; info.supportsDP4a = driverShaderModel >= D3D_SHADER_MODEL_6_4;

View File

@ -34,6 +34,7 @@ struct D3D12DeviceInfo {
PerStage<std::wstring> shaderProfiles; PerStage<std::wstring> shaderProfiles;
bool supportsSharedResourceCapabilityTier1; bool supportsSharedResourceCapabilityTier1;
bool supportsDP4a; bool supportsDP4a;
bool supportsCastingFullyTypedFormat;
}; };
ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter); ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter);

View File

@ -637,6 +637,8 @@ void Device::InitTogglesFromDriver() {
SetToggle(Toggle::UseD3D12RenderPass, GetDeviceInfo().supportsRenderPass); SetToggle(Toggle::UseD3D12RenderPass, GetDeviceInfo().supportsRenderPass);
SetToggle(Toggle::UseD3D12ResidencyManagement, true); SetToggle(Toggle::UseD3D12ResidencyManagement, true);
SetToggle(Toggle::UseDXC, false); SetToggle(Toggle::UseDXC, false);
SetToggle(Toggle::D3D12AlwaysUseTypelessFormatsForCastableTexture,
!GetDeviceInfo().supportsCastingFullyTypedFormat);
// Disable optimizations when using FXC // Disable optimizations when using FXC
// See https://crbug.com/dawn/1203 // See https://crbug.com/dawn/1203

View File

@ -583,8 +583,11 @@ MaybeError Texture::InitializeAsInternalTexture() {
// This will need to be much more nuanced when WebGPU has // This will need to be much more nuanced when WebGPU has
// texture view compatibility rules. // texture view compatibility rules.
const bool needsTypelessFormat = GetFormat().HasDepthOrStencil() && const bool needsTypelessFormat =
(GetInternalUsage() & wgpu::TextureUsage::TextureBinding) != 0; (GetDevice()->IsToggleEnabled(Toggle::D3D12AlwaysUseTypelessFormatsForCastableTexture) &&
GetViewFormats().any()) ||
(GetFormat().HasDepthOrStencil() &&
(GetInternalUsage() & wgpu::TextureUsage::TextureBinding) != 0);
DXGI_FORMAT dxgiFormat = needsTypelessFormat ? D3D12TypelessTextureFormat(GetFormat().format) DXGI_FORMAT dxgiFormat = needsTypelessFormat ? D3D12TypelessTextureFormat(GetFormat().format)
: D3D12TextureFormat(GetFormat().format); : D3D12TextureFormat(GetFormat().format);