diff --git a/src/dawn_native/d3d12/SamplerD3D12.cpp b/src/dawn_native/d3d12/SamplerD3D12.cpp index 070b0af6f2..e147a167e3 100644 --- a/src/dawn_native/d3d12/SamplerD3D12.cpp +++ b/src/dawn_native/d3d12/SamplerD3D12.cpp @@ -38,26 +38,38 @@ namespace dawn_native { namespace d3d12 { : SamplerBase(device, descriptor) { // https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx // hex value, decimal value, min linear, mag linear, mip linear - // D3D12_FILTER_MIN_MAG_MIP_POINT = 0 0 0 0 0 - // D3D12_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x1 1 0 0 1 - // D3D12_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x4 4 0 1 0 - // D3D12_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x5 5 0 1 1 - // D3D12_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10 16 1 0 0 - // D3D12_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11 17 1 0 1 - // D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14 20 1 1 0 - // D3D12_FILTER_MIN_MAG_MIP_LINEAR = 0x15 21 1 1 1 + // D3D12_FILTER_MIN_MAG_MIP_POINT = 0 0 0 0 0 + // D3D12_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x1 1 0 0 1 + // D3D12_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x4 4 0 1 0 + // D3D12_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x5 5 0 1 1 + // D3D12_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10 16 1 0 0 + // D3D12_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11 17 1 0 1 + // D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14 20 1 1 0 + // D3D12_FILTER_MIN_MAG_MIP_LINEAR = 0x15 21 1 1 1 + // D3D12_FILTER_COMPARISON_MIN_MAG_MIP_POINT, = 0x80 128 + // D3D12_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, = 0x81 129 + // D3D12_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT, = 0x84 132 + // D3D12_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, = 0x85 133 + // D3D12_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, = 0x90 144 + // D3D12_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,= 0x91 145 + // D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, = 0x94 148 + // D3D12_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, = 0x95 149 - // if mip mode is linear, add 1 - // if mag mode is linear, add 4 - // if min mode is linear, add 16 + // if mip mode is linear, add 0x1 + // if mag mode is linear, add 0x4 + // if min mode is linear, add 0x10 + // if comparison, add 0x80 uint8_t mode = 0; + if (descriptor->compare != wgpu::CompareFunction::Undefined) { + mode += 0x80; + } switch (descriptor->minFilter) { case wgpu::FilterMode::Nearest: break; case wgpu::FilterMode::Linear: - mode += 16; + mode += 0x10; break; } @@ -65,7 +77,7 @@ namespace dawn_native { namespace d3d12 { case wgpu::FilterMode::Nearest: break; case wgpu::FilterMode::Linear: - mode += 4; + mode += 0x4; break; } @@ -73,7 +85,7 @@ namespace dawn_native { namespace d3d12 { case wgpu::FilterMode::Nearest: break; case wgpu::FilterMode::Linear: - mode += 1; + mode += 0x1; break; } diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index bcd4d2606e..2a8b29a706 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -772,6 +772,11 @@ namespace dawn_native { namespace d3d12 { TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor) : TextureViewBase(texture, descriptor) { mSrvDesc.Format = D3D12TextureFormat(descriptor->format); + if (descriptor->format == wgpu::TextureFormat::Depth32Float) { + // TODO(enga): This will need to be much more nuanced when WebGPU has + // texture view compatibility rules. + mSrvDesc.Format = DXGI_FORMAT_R32_FLOAT; + } mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; // Currently we always use D3D12_TEX2D_ARRAY_SRV because we cannot specify base array layer diff --git a/src/tests/end2end/DepthSamplingTests.cpp b/src/tests/end2end/DepthSamplingTests.cpp index 491f7c2c4b..dc19e180fd 100644 --- a/src/tests/end2end/DepthSamplingTests.cpp +++ b/src/tests/end2end/DepthSamplingTests.cpp @@ -505,7 +505,4 @@ TEST_P(DepthSamplingTest, CompareFunctionsNonNormalizedContentsCompute) { } } -// TODO(crbug.com/dawn/367): Does not work on D3D12 because we need to reinterpret the texture view -// as R32Float to sample it. See tables here: -// https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/hardware-support-for-direct3d-12-1-formats -DAWN_INSTANTIATE_TEST(DepthSamplingTest, MetalBackend(), OpenGLBackend(), VulkanBackend()); +DAWN_INSTANTIATE_TEST(DepthSamplingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());