diff --git a/src/dawn/native/Toggles.cpp b/src/dawn/native/Toggles.cpp index 5f03891372..17d676dc32 100644 --- a/src/dawn/native/Toggles.cpp +++ b/src/dawn/native/Toggles.cpp @@ -279,6 +279,12 @@ static constexpr ToggleEnumAndInfoList kToggleNameAndInfoList = {{ "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 d6c3664052..22c119890f 100644 --- a/src/dawn/native/Toggles.h +++ b/src/dawn/native/Toggles.h @@ -74,6 +74,7 @@ enum class Toggle { EnableBlobCache, D3D12ForceInitializeCopyableDepthStencilTextureOnCreation, D3D12DontSetClearValueOnDepthTextureCreation, + D3D12AlwaysUseTypelessFormatsForCastableTexture, EnumCount, InvalidEnum = EnumCount, diff --git a/src/dawn/native/d3d12/D3D12Info.cpp b/src/dawn/native/d3d12/D3D12Info.cpp index 6a4c435648..6bbb865956 100644 --- a/src/dawn/native/d3d12/D3D12Info.cpp +++ b/src/dawn/native/d3d12/D3D12Info.cpp @@ -38,12 +38,31 @@ ResultOrError GatherDeviceInfo(const Adapter& adapter) { 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 @@ ResultOrError 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[] = { {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 @@ ResultOrError GatherDeviceInfo(const Adapter& adapter) { 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 e0f2a669ec..d985f55411 100644 --- a/src/dawn/native/d3d12/D3D12Info.h +++ b/src/dawn/native/d3d12/D3D12Info.h @@ -34,6 +34,7 @@ struct D3D12DeviceInfo { PerStage shaderProfiles; bool supportsSharedResourceCapabilityTier1; bool supportsDP4a; + bool supportsCastingFullyTypedFormat; }; ResultOrError GatherDeviceInfo(const Adapter& adapter); diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index 7b67035a56..1a43169739 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -637,6 +637,8 @@ void Device::InitTogglesFromDriver() { 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 cd17ada197..041a498d60 100644 --- a/src/dawn/native/d3d12/TextureD3D12.cpp +++ b/src/dawn/native/d3d12/TextureD3D12.cpp @@ -583,8 +583,11 @@ MaybeError Texture::InitializeAsInternalTexture() { // 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);