[d3d] Move some texture format convert methods to d3d folder

Bug: dawn:1705
Change-Id: I08a348666785ab25110b179e37b6a2869313d998
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125241
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/d3d/UtilsD3D.cpp b/src/dawn/native/d3d/UtilsD3D.cpp
index 057e730..4aaaa31 100644
--- a/src/dawn/native/d3d/UtilsD3D.cpp
+++ b/src/dawn/native/d3d/UtilsD3D.cpp
@@ -74,4 +74,322 @@
     return (majorVersion << 32) + minorVersion;
 }
 
+DXGI_FORMAT DXGITypelessTextureFormat(wgpu::TextureFormat format) {
+    switch (format) {
+        case wgpu::TextureFormat::R8Unorm:
+        case wgpu::TextureFormat::R8Snorm:
+        case wgpu::TextureFormat::R8Uint:
+        case wgpu::TextureFormat::R8Sint:
+            return DXGI_FORMAT_R8_TYPELESS;
+
+        case wgpu::TextureFormat::R16Uint:
+        case wgpu::TextureFormat::R16Sint:
+        case wgpu::TextureFormat::R16Float:
+        case wgpu::TextureFormat::Depth16Unorm:
+            return DXGI_FORMAT_R16_TYPELESS;
+
+        case wgpu::TextureFormat::RG8Unorm:
+        case wgpu::TextureFormat::RG8Snorm:
+        case wgpu::TextureFormat::RG8Uint:
+        case wgpu::TextureFormat::RG8Sint:
+            return DXGI_FORMAT_R8G8_TYPELESS;
+
+        case wgpu::TextureFormat::R32Uint:
+        case wgpu::TextureFormat::R32Sint:
+        case wgpu::TextureFormat::R32Float:
+            return DXGI_FORMAT_R32_TYPELESS;
+
+        case wgpu::TextureFormat::RG16Uint:
+        case wgpu::TextureFormat::RG16Sint:
+        case wgpu::TextureFormat::RG16Float:
+            return DXGI_FORMAT_R16G16_TYPELESS;
+
+        case wgpu::TextureFormat::RGBA8Unorm:
+        case wgpu::TextureFormat::RGBA8UnormSrgb:
+        case wgpu::TextureFormat::RGBA8Snorm:
+        case wgpu::TextureFormat::RGBA8Uint:
+        case wgpu::TextureFormat::RGBA8Sint:
+            return DXGI_FORMAT_R8G8B8A8_TYPELESS;
+
+        case wgpu::TextureFormat::BGRA8Unorm:
+        case wgpu::TextureFormat::BGRA8UnormSrgb:
+            return DXGI_FORMAT_B8G8R8A8_TYPELESS;
+
+        case wgpu::TextureFormat::RGB10A2Unorm:
+            return DXGI_FORMAT_R10G10B10A2_TYPELESS;
+
+        case wgpu::TextureFormat::RG11B10Ufloat:
+            return DXGI_FORMAT_R11G11B10_FLOAT;
+        case wgpu::TextureFormat::RGB9E5Ufloat:
+            return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
+
+        case wgpu::TextureFormat::RG32Uint:
+        case wgpu::TextureFormat::RG32Sint:
+        case wgpu::TextureFormat::RG32Float:
+            return DXGI_FORMAT_R32G32_TYPELESS;
+
+        case wgpu::TextureFormat::RGBA16Uint:
+        case wgpu::TextureFormat::RGBA16Sint:
+        case wgpu::TextureFormat::RGBA16Float:
+            return DXGI_FORMAT_R16G16B16A16_TYPELESS;
+
+        case wgpu::TextureFormat::RGBA32Uint:
+        case wgpu::TextureFormat::RGBA32Sint:
+        case wgpu::TextureFormat::RGBA32Float:
+            return DXGI_FORMAT_R32G32B32A32_TYPELESS;
+
+        case wgpu::TextureFormat::Depth32Float:
+        case wgpu::TextureFormat::Depth24Plus:
+            return DXGI_FORMAT_R32_TYPELESS;
+
+        // DXGI_FORMAT_D24_UNORM_S8_UINT is the smallest format supported on D3D12 that has stencil,
+        // for which the typeless equivalent is DXGI_FORMAT_R24G8_TYPELESS.
+        case wgpu::TextureFormat::Stencil8:
+            return DXGI_FORMAT_R24G8_TYPELESS;
+        case wgpu::TextureFormat::Depth24PlusStencil8:
+        case wgpu::TextureFormat::Depth32FloatStencil8:
+            return DXGI_FORMAT_R32G8X24_TYPELESS;
+
+        case wgpu::TextureFormat::BC1RGBAUnorm:
+        case wgpu::TextureFormat::BC1RGBAUnormSrgb:
+            return DXGI_FORMAT_BC1_TYPELESS;
+
+        case wgpu::TextureFormat::BC2RGBAUnorm:
+        case wgpu::TextureFormat::BC2RGBAUnormSrgb:
+            return DXGI_FORMAT_BC2_TYPELESS;
+
+        case wgpu::TextureFormat::BC3RGBAUnorm:
+        case wgpu::TextureFormat::BC3RGBAUnormSrgb:
+            return DXGI_FORMAT_BC3_TYPELESS;
+
+        case wgpu::TextureFormat::BC4RSnorm:
+        case wgpu::TextureFormat::BC4RUnorm:
+            return DXGI_FORMAT_BC4_TYPELESS;
+
+        case wgpu::TextureFormat::BC5RGSnorm:
+        case wgpu::TextureFormat::BC5RGUnorm:
+            return DXGI_FORMAT_BC5_TYPELESS;
+
+        case wgpu::TextureFormat::BC6HRGBFloat:
+        case wgpu::TextureFormat::BC6HRGBUfloat:
+            return DXGI_FORMAT_BC6H_TYPELESS;
+
+        case wgpu::TextureFormat::BC7RGBAUnorm:
+        case wgpu::TextureFormat::BC7RGBAUnormSrgb:
+            return DXGI_FORMAT_BC7_TYPELESS;
+
+        case wgpu::TextureFormat::ETC2RGB8Unorm:
+        case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
+        case wgpu::TextureFormat::ETC2RGB8A1Unorm:
+        case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
+        case wgpu::TextureFormat::ETC2RGBA8Unorm:
+        case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
+        case wgpu::TextureFormat::EACR11Unorm:
+        case wgpu::TextureFormat::EACR11Snorm:
+        case wgpu::TextureFormat::EACRG11Unorm:
+        case wgpu::TextureFormat::EACRG11Snorm:
+
+        case wgpu::TextureFormat::ASTC4x4Unorm:
+        case wgpu::TextureFormat::ASTC4x4UnormSrgb:
+        case wgpu::TextureFormat::ASTC5x4Unorm:
+        case wgpu::TextureFormat::ASTC5x4UnormSrgb:
+        case wgpu::TextureFormat::ASTC5x5Unorm:
+        case wgpu::TextureFormat::ASTC5x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC6x5Unorm:
+        case wgpu::TextureFormat::ASTC6x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC6x6Unorm:
+        case wgpu::TextureFormat::ASTC6x6UnormSrgb:
+        case wgpu::TextureFormat::ASTC8x5Unorm:
+        case wgpu::TextureFormat::ASTC8x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC8x6Unorm:
+        case wgpu::TextureFormat::ASTC8x6UnormSrgb:
+        case wgpu::TextureFormat::ASTC8x8Unorm:
+        case wgpu::TextureFormat::ASTC8x8UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x5Unorm:
+        case wgpu::TextureFormat::ASTC10x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x6Unorm:
+        case wgpu::TextureFormat::ASTC10x6UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x8Unorm:
+        case wgpu::TextureFormat::ASTC10x8UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x10Unorm:
+        case wgpu::TextureFormat::ASTC10x10UnormSrgb:
+        case wgpu::TextureFormat::ASTC12x10Unorm:
+        case wgpu::TextureFormat::ASTC12x10UnormSrgb:
+        case wgpu::TextureFormat::ASTC12x12Unorm:
+        case wgpu::TextureFormat::ASTC12x12UnormSrgb:
+
+        case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
+        case wgpu::TextureFormat::Undefined:
+            UNREACHABLE();
+    }
+}
+
+DXGI_FORMAT DXGITextureFormat(wgpu::TextureFormat format) {
+    switch (format) {
+        case wgpu::TextureFormat::R8Unorm:
+            return DXGI_FORMAT_R8_UNORM;
+        case wgpu::TextureFormat::R8Snorm:
+            return DXGI_FORMAT_R8_SNORM;
+        case wgpu::TextureFormat::R8Uint:
+            return DXGI_FORMAT_R8_UINT;
+        case wgpu::TextureFormat::R8Sint:
+            return DXGI_FORMAT_R8_SINT;
+
+        case wgpu::TextureFormat::R16Uint:
+            return DXGI_FORMAT_R16_UINT;
+        case wgpu::TextureFormat::R16Sint:
+            return DXGI_FORMAT_R16_SINT;
+        case wgpu::TextureFormat::R16Float:
+            return DXGI_FORMAT_R16_FLOAT;
+        case wgpu::TextureFormat::RG8Unorm:
+            return DXGI_FORMAT_R8G8_UNORM;
+        case wgpu::TextureFormat::RG8Snorm:
+            return DXGI_FORMAT_R8G8_SNORM;
+        case wgpu::TextureFormat::RG8Uint:
+            return DXGI_FORMAT_R8G8_UINT;
+        case wgpu::TextureFormat::RG8Sint:
+            return DXGI_FORMAT_R8G8_SINT;
+
+        case wgpu::TextureFormat::R32Uint:
+            return DXGI_FORMAT_R32_UINT;
+        case wgpu::TextureFormat::R32Sint:
+            return DXGI_FORMAT_R32_SINT;
+        case wgpu::TextureFormat::R32Float:
+            return DXGI_FORMAT_R32_FLOAT;
+        case wgpu::TextureFormat::RG16Uint:
+            return DXGI_FORMAT_R16G16_UINT;
+        case wgpu::TextureFormat::RG16Sint:
+            return DXGI_FORMAT_R16G16_SINT;
+        case wgpu::TextureFormat::RG16Float:
+            return DXGI_FORMAT_R16G16_FLOAT;
+        case wgpu::TextureFormat::RGBA8Unorm:
+            return DXGI_FORMAT_R8G8B8A8_UNORM;
+        case wgpu::TextureFormat::RGBA8UnormSrgb:
+            return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
+        case wgpu::TextureFormat::RGBA8Snorm:
+            return DXGI_FORMAT_R8G8B8A8_SNORM;
+        case wgpu::TextureFormat::RGBA8Uint:
+            return DXGI_FORMAT_R8G8B8A8_UINT;
+        case wgpu::TextureFormat::RGBA8Sint:
+            return DXGI_FORMAT_R8G8B8A8_SINT;
+        case wgpu::TextureFormat::BGRA8Unorm:
+            return DXGI_FORMAT_B8G8R8A8_UNORM;
+        case wgpu::TextureFormat::BGRA8UnormSrgb:
+            return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
+        case wgpu::TextureFormat::RGB10A2Unorm:
+            return DXGI_FORMAT_R10G10B10A2_UNORM;
+        case wgpu::TextureFormat::RG11B10Ufloat:
+            return DXGI_FORMAT_R11G11B10_FLOAT;
+        case wgpu::TextureFormat::RGB9E5Ufloat:
+            return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
+
+        case wgpu::TextureFormat::RG32Uint:
+            return DXGI_FORMAT_R32G32_UINT;
+        case wgpu::TextureFormat::RG32Sint:
+            return DXGI_FORMAT_R32G32_SINT;
+        case wgpu::TextureFormat::RG32Float:
+            return DXGI_FORMAT_R32G32_FLOAT;
+        case wgpu::TextureFormat::RGBA16Uint:
+            return DXGI_FORMAT_R16G16B16A16_UINT;
+        case wgpu::TextureFormat::RGBA16Sint:
+            return DXGI_FORMAT_R16G16B16A16_SINT;
+        case wgpu::TextureFormat::RGBA16Float:
+            return DXGI_FORMAT_R16G16B16A16_FLOAT;
+
+        case wgpu::TextureFormat::RGBA32Uint:
+            return DXGI_FORMAT_R32G32B32A32_UINT;
+        case wgpu::TextureFormat::RGBA32Sint:
+            return DXGI_FORMAT_R32G32B32A32_SINT;
+        case wgpu::TextureFormat::RGBA32Float:
+            return DXGI_FORMAT_R32G32B32A32_FLOAT;
+
+        case wgpu::TextureFormat::Depth16Unorm:
+            return DXGI_FORMAT_D16_UNORM;
+        case wgpu::TextureFormat::Depth32Float:
+        case wgpu::TextureFormat::Depth24Plus:
+            return DXGI_FORMAT_D32_FLOAT;
+        // DXGI_FORMAT_D24_UNORM_S8_UINT is the smallest format supported on D3D12 that has stencil.
+        case wgpu::TextureFormat::Stencil8:
+            return DXGI_FORMAT_D24_UNORM_S8_UINT;
+        case wgpu::TextureFormat::Depth24PlusStencil8:
+        case wgpu::TextureFormat::Depth32FloatStencil8:
+            return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+
+        case wgpu::TextureFormat::BC1RGBAUnorm:
+            return DXGI_FORMAT_BC1_UNORM;
+        case wgpu::TextureFormat::BC1RGBAUnormSrgb:
+            return DXGI_FORMAT_BC1_UNORM_SRGB;
+        case wgpu::TextureFormat::BC2RGBAUnorm:
+            return DXGI_FORMAT_BC2_UNORM;
+        case wgpu::TextureFormat::BC2RGBAUnormSrgb:
+            return DXGI_FORMAT_BC2_UNORM_SRGB;
+        case wgpu::TextureFormat::BC3RGBAUnorm:
+            return DXGI_FORMAT_BC3_UNORM;
+        case wgpu::TextureFormat::BC3RGBAUnormSrgb:
+            return DXGI_FORMAT_BC3_UNORM_SRGB;
+        case wgpu::TextureFormat::BC4RSnorm:
+            return DXGI_FORMAT_BC4_SNORM;
+        case wgpu::TextureFormat::BC4RUnorm:
+            return DXGI_FORMAT_BC4_UNORM;
+        case wgpu::TextureFormat::BC5RGSnorm:
+            return DXGI_FORMAT_BC5_SNORM;
+        case wgpu::TextureFormat::BC5RGUnorm:
+            return DXGI_FORMAT_BC5_UNORM;
+        case wgpu::TextureFormat::BC6HRGBFloat:
+            return DXGI_FORMAT_BC6H_SF16;
+        case wgpu::TextureFormat::BC6HRGBUfloat:
+            return DXGI_FORMAT_BC6H_UF16;
+        case wgpu::TextureFormat::BC7RGBAUnorm:
+            return DXGI_FORMAT_BC7_UNORM;
+        case wgpu::TextureFormat::BC7RGBAUnormSrgb:
+            return DXGI_FORMAT_BC7_UNORM_SRGB;
+
+        case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
+            return DXGI_FORMAT_NV12;
+
+        case wgpu::TextureFormat::ETC2RGB8Unorm:
+        case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
+        case wgpu::TextureFormat::ETC2RGB8A1Unorm:
+        case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
+        case wgpu::TextureFormat::ETC2RGBA8Unorm:
+        case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
+        case wgpu::TextureFormat::EACR11Unorm:
+        case wgpu::TextureFormat::EACR11Snorm:
+        case wgpu::TextureFormat::EACRG11Unorm:
+        case wgpu::TextureFormat::EACRG11Snorm:
+
+        case wgpu::TextureFormat::ASTC4x4Unorm:
+        case wgpu::TextureFormat::ASTC4x4UnormSrgb:
+        case wgpu::TextureFormat::ASTC5x4Unorm:
+        case wgpu::TextureFormat::ASTC5x4UnormSrgb:
+        case wgpu::TextureFormat::ASTC5x5Unorm:
+        case wgpu::TextureFormat::ASTC5x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC6x5Unorm:
+        case wgpu::TextureFormat::ASTC6x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC6x6Unorm:
+        case wgpu::TextureFormat::ASTC6x6UnormSrgb:
+        case wgpu::TextureFormat::ASTC8x5Unorm:
+        case wgpu::TextureFormat::ASTC8x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC8x6Unorm:
+        case wgpu::TextureFormat::ASTC8x6UnormSrgb:
+        case wgpu::TextureFormat::ASTC8x8Unorm:
+        case wgpu::TextureFormat::ASTC8x8UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x5Unorm:
+        case wgpu::TextureFormat::ASTC10x5UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x6Unorm:
+        case wgpu::TextureFormat::ASTC10x6UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x8Unorm:
+        case wgpu::TextureFormat::ASTC10x8UnormSrgb:
+        case wgpu::TextureFormat::ASTC10x10Unorm:
+        case wgpu::TextureFormat::ASTC10x10UnormSrgb:
+        case wgpu::TextureFormat::ASTC12x10Unorm:
+        case wgpu::TextureFormat::ASTC12x10UnormSrgb:
+        case wgpu::TextureFormat::ASTC12x12Unorm:
+        case wgpu::TextureFormat::ASTC12x12UnormSrgb:
+
+        case wgpu::TextureFormat::Undefined:
+            UNREACHABLE();
+    }
+}
+
 }  // namespace dawn::native::d3d
diff --git a/src/dawn/native/d3d/UtilsD3D.h b/src/dawn/native/d3d/UtilsD3D.h
index f820279..6f0ea19 100644
--- a/src/dawn/native/d3d/UtilsD3D.h
+++ b/src/dawn/native/d3d/UtilsD3D.h
@@ -28,6 +28,10 @@
 
 uint64_t MakeDXCVersion(uint64_t majorVersion, uint64_t minorVersion);
 
+DXGI_FORMAT DXGITypelessTextureFormat(wgpu::TextureFormat format);
+
+DXGI_FORMAT DXGITextureFormat(wgpu::TextureFormat format);
+
 }  // namespace dawn::native::d3d
 
 #endif  // SRC_DAWN_NATIVE_D3D_UTILSD3D_H_
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index 892af59..8c6051a 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -584,7 +584,7 @@
     const Format* format = GetInternalFormat(textureDescriptor->format).AcquireSuccess();
     if (format->IsMultiPlanar()) {
         if (ConsumedError(ValidateD3D12VideoTextureCanBeShared(
-                this, D3D12TextureFormat(textureDescriptor->format)))) {
+                this, d3d::DXGITextureFormat(textureDescriptor->format)))) {
             return nullptr;
         }
     }
diff --git a/src/dawn/native/d3d12/NativeSwapChainImplD3D12.cpp b/src/dawn/native/d3d12/NativeSwapChainImplD3D12.cpp
index de70081..91b9687 100644
--- a/src/dawn/native/d3d12/NativeSwapChainImplD3D12.cpp
+++ b/src/dawn/native/d3d12/NativeSwapChainImplD3D12.cpp
@@ -15,6 +15,7 @@
 #include "dawn/native/d3d12/NativeSwapChainImplD3D12.h"
 
 #include "dawn/common/Assert.h"
+#include "dawn/native/d3d/UtilsD3D.h"
 #include "dawn/native/d3d12/DeviceD3D12.h"
 #include "dawn/native/d3d12/TextureD3D12.h"
 
@@ -62,7 +63,7 @@
     DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
     swapChainDesc.Width = width;
     swapChainDesc.Height = height;
-    swapChainDesc.Format = D3D12TextureFormat(GetPreferredFormat());
+    swapChainDesc.Format = d3d::DXGITextureFormat(GetPreferredFormat());
     swapChainDesc.BufferUsage = D3D12SwapChainBufferUsage(usage);
     swapChainDesc.BufferCount = kFrameCount;
     swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
diff --git a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp
index e6988e4..ab9cbb1 100644
--- a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp
+++ b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp
@@ -431,7 +431,7 @@
     descriptorD3D12.RasterizerState.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
 
     if (HasDepthStencilAttachment()) {
-        descriptorD3D12.DSVFormat = D3D12TextureFormat(GetDepthStencilFormat());
+        descriptorD3D12.DSVFormat = d3d::DXGITextureFormat(GetDepthStencilFormat());
     }
 
     static_assert(kMaxColorAttachments == 8);
@@ -443,7 +443,7 @@
         GetHighestBitIndexPlusOne(GetColorAttachmentsMask());
     for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) {
         descriptorD3D12.RTVFormats[static_cast<uint8_t>(i)] =
-            D3D12TextureFormat(GetColorAttachmentFormat(i));
+            d3d::DXGITextureFormat(GetColorAttachmentFormat(i));
         descriptorD3D12.BlendState.RenderTarget[static_cast<uint8_t>(i)] =
             ComputeColorDesc(device, GetColorTargetState(i));
     }
diff --git a/src/dawn/native/d3d12/SwapChainD3D12.cpp b/src/dawn/native/d3d12/SwapChainD3D12.cpp
index 7e814f8..ae65319 100644
--- a/src/dawn/native/d3d12/SwapChainD3D12.cpp
+++ b/src/dawn/native/d3d12/SwapChainD3D12.cpp
@@ -21,6 +21,7 @@
 #include "dawn/dawn_wsi.h"
 #include "dawn/native/Surface.h"
 #include "dawn/native/d3d/D3DError.h"
+#include "dawn/native/d3d/UtilsD3D.h"
 #include "dawn/native/d3d12/DeviceD3D12.h"
 #include "dawn/native/d3d12/TextureD3D12.h"
 
@@ -156,7 +157,7 @@
 
     // Precompute the configuration parameters we want for the DXGI swapchain.
     mConfig.bufferCount = PresentModeToBufferCount(GetPresentMode());
-    mConfig.format = D3D12TextureFormat(GetFormat());
+    mConfig.format = d3d::DXGITextureFormat(GetFormat());
     mConfig.swapChainFlags = PresentModeToSwapChainFlags(GetPresentMode());
     mConfig.usage = ToDXGIUsage(GetUsage());
 
diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp
index f87078a..bcfaf8a 100644
--- a/src/dawn/native/d3d12/TextureD3D12.cpp
+++ b/src/dawn/native/d3d12/TextureD3D12.cpp
@@ -111,326 +111,8 @@
     }
 }
 
-DXGI_FORMAT D3D12TypelessTextureFormat(wgpu::TextureFormat format) {
-    switch (format) {
-        case wgpu::TextureFormat::R8Unorm:
-        case wgpu::TextureFormat::R8Snorm:
-        case wgpu::TextureFormat::R8Uint:
-        case wgpu::TextureFormat::R8Sint:
-            return DXGI_FORMAT_R8_TYPELESS;
-
-        case wgpu::TextureFormat::R16Uint:
-        case wgpu::TextureFormat::R16Sint:
-        case wgpu::TextureFormat::R16Float:
-        case wgpu::TextureFormat::Depth16Unorm:
-            return DXGI_FORMAT_R16_TYPELESS;
-
-        case wgpu::TextureFormat::RG8Unorm:
-        case wgpu::TextureFormat::RG8Snorm:
-        case wgpu::TextureFormat::RG8Uint:
-        case wgpu::TextureFormat::RG8Sint:
-            return DXGI_FORMAT_R8G8_TYPELESS;
-
-        case wgpu::TextureFormat::R32Uint:
-        case wgpu::TextureFormat::R32Sint:
-        case wgpu::TextureFormat::R32Float:
-            return DXGI_FORMAT_R32_TYPELESS;
-
-        case wgpu::TextureFormat::RG16Uint:
-        case wgpu::TextureFormat::RG16Sint:
-        case wgpu::TextureFormat::RG16Float:
-            return DXGI_FORMAT_R16G16_TYPELESS;
-
-        case wgpu::TextureFormat::RGBA8Unorm:
-        case wgpu::TextureFormat::RGBA8UnormSrgb:
-        case wgpu::TextureFormat::RGBA8Snorm:
-        case wgpu::TextureFormat::RGBA8Uint:
-        case wgpu::TextureFormat::RGBA8Sint:
-            return DXGI_FORMAT_R8G8B8A8_TYPELESS;
-
-        case wgpu::TextureFormat::BGRA8Unorm:
-        case wgpu::TextureFormat::BGRA8UnormSrgb:
-            return DXGI_FORMAT_B8G8R8A8_TYPELESS;
-
-        case wgpu::TextureFormat::RGB10A2Unorm:
-            return DXGI_FORMAT_R10G10B10A2_TYPELESS;
-
-        case wgpu::TextureFormat::RG11B10Ufloat:
-            return DXGI_FORMAT_R11G11B10_FLOAT;
-        case wgpu::TextureFormat::RGB9E5Ufloat:
-            return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
-
-        case wgpu::TextureFormat::RG32Uint:
-        case wgpu::TextureFormat::RG32Sint:
-        case wgpu::TextureFormat::RG32Float:
-            return DXGI_FORMAT_R32G32_TYPELESS;
-
-        case wgpu::TextureFormat::RGBA16Uint:
-        case wgpu::TextureFormat::RGBA16Sint:
-        case wgpu::TextureFormat::RGBA16Float:
-            return DXGI_FORMAT_R16G16B16A16_TYPELESS;
-
-        case wgpu::TextureFormat::RGBA32Uint:
-        case wgpu::TextureFormat::RGBA32Sint:
-        case wgpu::TextureFormat::RGBA32Float:
-            return DXGI_FORMAT_R32G32B32A32_TYPELESS;
-
-        case wgpu::TextureFormat::Depth32Float:
-        case wgpu::TextureFormat::Depth24Plus:
-            return DXGI_FORMAT_R32_TYPELESS;
-
-        // DXGI_FORMAT_D24_UNORM_S8_UINT is the smallest format supported on D3D12 that has stencil,
-        // for which the typeless equivalent is DXGI_FORMAT_R24G8_TYPELESS.
-        case wgpu::TextureFormat::Stencil8:
-            return DXGI_FORMAT_R24G8_TYPELESS;
-        case wgpu::TextureFormat::Depth24PlusStencil8:
-        case wgpu::TextureFormat::Depth32FloatStencil8:
-            return DXGI_FORMAT_R32G8X24_TYPELESS;
-
-        case wgpu::TextureFormat::BC1RGBAUnorm:
-        case wgpu::TextureFormat::BC1RGBAUnormSrgb:
-            return DXGI_FORMAT_BC1_TYPELESS;
-
-        case wgpu::TextureFormat::BC2RGBAUnorm:
-        case wgpu::TextureFormat::BC2RGBAUnormSrgb:
-            return DXGI_FORMAT_BC2_TYPELESS;
-
-        case wgpu::TextureFormat::BC3RGBAUnorm:
-        case wgpu::TextureFormat::BC3RGBAUnormSrgb:
-            return DXGI_FORMAT_BC3_TYPELESS;
-
-        case wgpu::TextureFormat::BC4RSnorm:
-        case wgpu::TextureFormat::BC4RUnorm:
-            return DXGI_FORMAT_BC4_TYPELESS;
-
-        case wgpu::TextureFormat::BC5RGSnorm:
-        case wgpu::TextureFormat::BC5RGUnorm:
-            return DXGI_FORMAT_BC5_TYPELESS;
-
-        case wgpu::TextureFormat::BC6HRGBFloat:
-        case wgpu::TextureFormat::BC6HRGBUfloat:
-            return DXGI_FORMAT_BC6H_TYPELESS;
-
-        case wgpu::TextureFormat::BC7RGBAUnorm:
-        case wgpu::TextureFormat::BC7RGBAUnormSrgb:
-            return DXGI_FORMAT_BC7_TYPELESS;
-
-        case wgpu::TextureFormat::ETC2RGB8Unorm:
-        case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
-        case wgpu::TextureFormat::ETC2RGB8A1Unorm:
-        case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
-        case wgpu::TextureFormat::ETC2RGBA8Unorm:
-        case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
-        case wgpu::TextureFormat::EACR11Unorm:
-        case wgpu::TextureFormat::EACR11Snorm:
-        case wgpu::TextureFormat::EACRG11Unorm:
-        case wgpu::TextureFormat::EACRG11Snorm:
-
-        case wgpu::TextureFormat::ASTC4x4Unorm:
-        case wgpu::TextureFormat::ASTC4x4UnormSrgb:
-        case wgpu::TextureFormat::ASTC5x4Unorm:
-        case wgpu::TextureFormat::ASTC5x4UnormSrgb:
-        case wgpu::TextureFormat::ASTC5x5Unorm:
-        case wgpu::TextureFormat::ASTC5x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC6x5Unorm:
-        case wgpu::TextureFormat::ASTC6x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC6x6Unorm:
-        case wgpu::TextureFormat::ASTC6x6UnormSrgb:
-        case wgpu::TextureFormat::ASTC8x5Unorm:
-        case wgpu::TextureFormat::ASTC8x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC8x6Unorm:
-        case wgpu::TextureFormat::ASTC8x6UnormSrgb:
-        case wgpu::TextureFormat::ASTC8x8Unorm:
-        case wgpu::TextureFormat::ASTC8x8UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x5Unorm:
-        case wgpu::TextureFormat::ASTC10x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x6Unorm:
-        case wgpu::TextureFormat::ASTC10x6UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x8Unorm:
-        case wgpu::TextureFormat::ASTC10x8UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x10Unorm:
-        case wgpu::TextureFormat::ASTC10x10UnormSrgb:
-        case wgpu::TextureFormat::ASTC12x10Unorm:
-        case wgpu::TextureFormat::ASTC12x10UnormSrgb:
-        case wgpu::TextureFormat::ASTC12x12Unorm:
-        case wgpu::TextureFormat::ASTC12x12UnormSrgb:
-
-        case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
-        case wgpu::TextureFormat::Undefined:
-            UNREACHABLE();
-    }
-}
-
 }  // namespace
 
-DXGI_FORMAT D3D12TextureFormat(wgpu::TextureFormat format) {
-    switch (format) {
-        case wgpu::TextureFormat::R8Unorm:
-            return DXGI_FORMAT_R8_UNORM;
-        case wgpu::TextureFormat::R8Snorm:
-            return DXGI_FORMAT_R8_SNORM;
-        case wgpu::TextureFormat::R8Uint:
-            return DXGI_FORMAT_R8_UINT;
-        case wgpu::TextureFormat::R8Sint:
-            return DXGI_FORMAT_R8_SINT;
-
-        case wgpu::TextureFormat::R16Uint:
-            return DXGI_FORMAT_R16_UINT;
-        case wgpu::TextureFormat::R16Sint:
-            return DXGI_FORMAT_R16_SINT;
-        case wgpu::TextureFormat::R16Float:
-            return DXGI_FORMAT_R16_FLOAT;
-        case wgpu::TextureFormat::RG8Unorm:
-            return DXGI_FORMAT_R8G8_UNORM;
-        case wgpu::TextureFormat::RG8Snorm:
-            return DXGI_FORMAT_R8G8_SNORM;
-        case wgpu::TextureFormat::RG8Uint:
-            return DXGI_FORMAT_R8G8_UINT;
-        case wgpu::TextureFormat::RG8Sint:
-            return DXGI_FORMAT_R8G8_SINT;
-
-        case wgpu::TextureFormat::R32Uint:
-            return DXGI_FORMAT_R32_UINT;
-        case wgpu::TextureFormat::R32Sint:
-            return DXGI_FORMAT_R32_SINT;
-        case wgpu::TextureFormat::R32Float:
-            return DXGI_FORMAT_R32_FLOAT;
-        case wgpu::TextureFormat::RG16Uint:
-            return DXGI_FORMAT_R16G16_UINT;
-        case wgpu::TextureFormat::RG16Sint:
-            return DXGI_FORMAT_R16G16_SINT;
-        case wgpu::TextureFormat::RG16Float:
-            return DXGI_FORMAT_R16G16_FLOAT;
-        case wgpu::TextureFormat::RGBA8Unorm:
-            return DXGI_FORMAT_R8G8B8A8_UNORM;
-        case wgpu::TextureFormat::RGBA8UnormSrgb:
-            return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
-        case wgpu::TextureFormat::RGBA8Snorm:
-            return DXGI_FORMAT_R8G8B8A8_SNORM;
-        case wgpu::TextureFormat::RGBA8Uint:
-            return DXGI_FORMAT_R8G8B8A8_UINT;
-        case wgpu::TextureFormat::RGBA8Sint:
-            return DXGI_FORMAT_R8G8B8A8_SINT;
-        case wgpu::TextureFormat::BGRA8Unorm:
-            return DXGI_FORMAT_B8G8R8A8_UNORM;
-        case wgpu::TextureFormat::BGRA8UnormSrgb:
-            return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
-        case wgpu::TextureFormat::RGB10A2Unorm:
-            return DXGI_FORMAT_R10G10B10A2_UNORM;
-        case wgpu::TextureFormat::RG11B10Ufloat:
-            return DXGI_FORMAT_R11G11B10_FLOAT;
-        case wgpu::TextureFormat::RGB9E5Ufloat:
-            return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
-
-        case wgpu::TextureFormat::RG32Uint:
-            return DXGI_FORMAT_R32G32_UINT;
-        case wgpu::TextureFormat::RG32Sint:
-            return DXGI_FORMAT_R32G32_SINT;
-        case wgpu::TextureFormat::RG32Float:
-            return DXGI_FORMAT_R32G32_FLOAT;
-        case wgpu::TextureFormat::RGBA16Uint:
-            return DXGI_FORMAT_R16G16B16A16_UINT;
-        case wgpu::TextureFormat::RGBA16Sint:
-            return DXGI_FORMAT_R16G16B16A16_SINT;
-        case wgpu::TextureFormat::RGBA16Float:
-            return DXGI_FORMAT_R16G16B16A16_FLOAT;
-
-        case wgpu::TextureFormat::RGBA32Uint:
-            return DXGI_FORMAT_R32G32B32A32_UINT;
-        case wgpu::TextureFormat::RGBA32Sint:
-            return DXGI_FORMAT_R32G32B32A32_SINT;
-        case wgpu::TextureFormat::RGBA32Float:
-            return DXGI_FORMAT_R32G32B32A32_FLOAT;
-
-        case wgpu::TextureFormat::Depth16Unorm:
-            return DXGI_FORMAT_D16_UNORM;
-        case wgpu::TextureFormat::Depth32Float:
-        case wgpu::TextureFormat::Depth24Plus:
-            return DXGI_FORMAT_D32_FLOAT;
-        // DXGI_FORMAT_D24_UNORM_S8_UINT is the smallest format supported on D3D12 that has stencil.
-        case wgpu::TextureFormat::Stencil8:
-            return DXGI_FORMAT_D24_UNORM_S8_UINT;
-        case wgpu::TextureFormat::Depth24PlusStencil8:
-        case wgpu::TextureFormat::Depth32FloatStencil8:
-            return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
-
-        case wgpu::TextureFormat::BC1RGBAUnorm:
-            return DXGI_FORMAT_BC1_UNORM;
-        case wgpu::TextureFormat::BC1RGBAUnormSrgb:
-            return DXGI_FORMAT_BC1_UNORM_SRGB;
-        case wgpu::TextureFormat::BC2RGBAUnorm:
-            return DXGI_FORMAT_BC2_UNORM;
-        case wgpu::TextureFormat::BC2RGBAUnormSrgb:
-            return DXGI_FORMAT_BC2_UNORM_SRGB;
-        case wgpu::TextureFormat::BC3RGBAUnorm:
-            return DXGI_FORMAT_BC3_UNORM;
-        case wgpu::TextureFormat::BC3RGBAUnormSrgb:
-            return DXGI_FORMAT_BC3_UNORM_SRGB;
-        case wgpu::TextureFormat::BC4RSnorm:
-            return DXGI_FORMAT_BC4_SNORM;
-        case wgpu::TextureFormat::BC4RUnorm:
-            return DXGI_FORMAT_BC4_UNORM;
-        case wgpu::TextureFormat::BC5RGSnorm:
-            return DXGI_FORMAT_BC5_SNORM;
-        case wgpu::TextureFormat::BC5RGUnorm:
-            return DXGI_FORMAT_BC5_UNORM;
-        case wgpu::TextureFormat::BC6HRGBFloat:
-            return DXGI_FORMAT_BC6H_SF16;
-        case wgpu::TextureFormat::BC6HRGBUfloat:
-            return DXGI_FORMAT_BC6H_UF16;
-        case wgpu::TextureFormat::BC7RGBAUnorm:
-            return DXGI_FORMAT_BC7_UNORM;
-        case wgpu::TextureFormat::BC7RGBAUnormSrgb:
-            return DXGI_FORMAT_BC7_UNORM_SRGB;
-
-        case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
-            return DXGI_FORMAT_NV12;
-
-        case wgpu::TextureFormat::ETC2RGB8Unorm:
-        case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
-        case wgpu::TextureFormat::ETC2RGB8A1Unorm:
-        case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
-        case wgpu::TextureFormat::ETC2RGBA8Unorm:
-        case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
-        case wgpu::TextureFormat::EACR11Unorm:
-        case wgpu::TextureFormat::EACR11Snorm:
-        case wgpu::TextureFormat::EACRG11Unorm:
-        case wgpu::TextureFormat::EACRG11Snorm:
-
-        case wgpu::TextureFormat::ASTC4x4Unorm:
-        case wgpu::TextureFormat::ASTC4x4UnormSrgb:
-        case wgpu::TextureFormat::ASTC5x4Unorm:
-        case wgpu::TextureFormat::ASTC5x4UnormSrgb:
-        case wgpu::TextureFormat::ASTC5x5Unorm:
-        case wgpu::TextureFormat::ASTC5x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC6x5Unorm:
-        case wgpu::TextureFormat::ASTC6x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC6x6Unorm:
-        case wgpu::TextureFormat::ASTC6x6UnormSrgb:
-        case wgpu::TextureFormat::ASTC8x5Unorm:
-        case wgpu::TextureFormat::ASTC8x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC8x6Unorm:
-        case wgpu::TextureFormat::ASTC8x6UnormSrgb:
-        case wgpu::TextureFormat::ASTC8x8Unorm:
-        case wgpu::TextureFormat::ASTC8x8UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x5Unorm:
-        case wgpu::TextureFormat::ASTC10x5UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x6Unorm:
-        case wgpu::TextureFormat::ASTC10x6UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x8Unorm:
-        case wgpu::TextureFormat::ASTC10x8UnormSrgb:
-        case wgpu::TextureFormat::ASTC10x10Unorm:
-        case wgpu::TextureFormat::ASTC10x10UnormSrgb:
-        case wgpu::TextureFormat::ASTC12x10Unorm:
-        case wgpu::TextureFormat::ASTC12x10UnormSrgb:
-        case wgpu::TextureFormat::ASTC12x12Unorm:
-        case wgpu::TextureFormat::ASTC12x12UnormSrgb:
-
-        case wgpu::TextureFormat::Undefined:
-            UNREACHABLE();
-    }
-}
-
 MaybeError ValidateTextureDescriptorCanBeWrapped(const TextureDescriptor* descriptor) {
     DAWN_INVALID_IF(descriptor->dimension != wgpu::TextureDimension::e2D,
                     "Texture dimension (%s) is not %s.", descriptor->dimension,
@@ -460,7 +142,7 @@
         d3dDescriptor.Width, d3dDescriptor.Height, dawnDescriptor->size.width,
         dawnDescriptor->size.height, dawnDescriptor->size.depthOrArrayLayers);
 
-    const DXGI_FORMAT dxgiFormatFromDescriptor = D3D12TextureFormat(dawnDescriptor->format);
+    const DXGI_FORMAT dxgiFormatFromDescriptor = d3d::DXGITextureFormat(dawnDescriptor->format);
     DAWN_INVALID_IF(dxgiFormatFromDescriptor != d3dDescriptor.Format,
                     "D3D12 texture format (%x) is not compatible with Dawn descriptor format (%s).",
                     d3dDescriptor.Format, dawnDescriptor->format);
@@ -595,8 +277,9 @@
         (GetFormat().HasDepthOrStencil() &&
          (GetInternalUsage() & wgpu::TextureUsage::TextureBinding) != 0);
 
-    DXGI_FORMAT dxgiFormat = needsTypelessFormat ? D3D12TypelessTextureFormat(GetFormat().format)
-                                                 : D3D12TextureFormat(GetFormat().format);
+    DXGI_FORMAT dxgiFormat = needsTypelessFormat
+                                 ? d3d::DXGITypelessTextureFormat(GetFormat().format)
+                                 : d3d::DXGITextureFormat(GetFormat().format);
 
     resourceDescriptor.MipLevels = static_cast<UINT16>(GetNumMipLevels());
     resourceDescriptor.Format = dxgiFormat;
@@ -702,7 +385,7 @@
 }
 
 DXGI_FORMAT Texture::GetD3D12Format() const {
-    return D3D12TextureFormat(GetFormat().format);
+    return d3d::DXGITextureFormat(GetFormat().format);
 }
 
 ID3D12Resource* Texture::GetD3D12Resource() const {
@@ -983,7 +666,7 @@
                                                         uint32_t baseSlice,
                                                         uint32_t sliceCount) const {
     D3D12_RENDER_TARGET_VIEW_DESC rtvDesc;
-    rtvDesc.Format = D3D12TextureFormat(format.format);
+    rtvDesc.Format = d3d::DXGITextureFormat(format.format);
     if (IsMultisampledTexture()) {
         ASSERT(GetDimension() == wgpu::TextureDimension::e2D);
         ASSERT(GetNumMipLevels() == 1);
@@ -1238,7 +921,7 @@
 
 TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor)
     : TextureViewBase(texture, descriptor) {
-    mSrvDesc.Format = D3D12TextureFormat(descriptor->format);
+    mSrvDesc.Format = d3d::DXGITextureFormat(descriptor->format);
     mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
 
     UINT planeSlice = 0;
@@ -1329,7 +1012,7 @@
         const Aspect planeAspect = ConvertViewAspect(GetFormat(), descriptor->aspect);
         planeSlice = GetAspectIndex(planeAspect);
         mSrvDesc.Format =
-            D3D12TextureFormat(texture->GetFormat().GetAspectInfo(planeAspect).format);
+            d3d::DXGITextureFormat(texture->GetFormat().GetAspectInfo(planeAspect).format);
     }
 
     // Currently we always use D3D12_TEX2D_ARRAY_SRV because we cannot specify base array layer
@@ -1398,7 +1081,7 @@
 }
 
 DXGI_FORMAT TextureView::GetD3D12Format() const {
-    return D3D12TextureFormat(GetFormat().format);
+    return d3d::DXGITextureFormat(GetFormat().format);
 }
 
 const D3D12_SHADER_RESOURCE_VIEW_DESC& TextureView::GetSRVDescriptor() const {
diff --git a/src/dawn/native/d3d12/TextureD3D12.h b/src/dawn/native/d3d12/TextureD3D12.h
index f12121e..a46ca02 100644
--- a/src/dawn/native/d3d12/TextureD3D12.h
+++ b/src/dawn/native/d3d12/TextureD3D12.h
@@ -35,7 +35,6 @@
 class Device;
 class D3D11on12ResourceCacheEntry;
 
-DXGI_FORMAT D3D12TextureFormat(wgpu::TextureFormat format);
 MaybeError ValidateD3D12TextureCanBeWrapped(ID3D12Resource* d3d12Resource,
                                             const TextureDescriptor* descriptor);
 MaybeError ValidateTextureDescriptorCanBeWrapped(const TextureDescriptor* descriptor);