diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index e6730c29ed..f7d5d041b7 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -96,9 +96,10 @@ namespace dawn_native { namespace d3d12 { switch (dimension) { case wgpu::TextureDimension::e2D: return D3D12_RESOURCE_DIMENSION_TEXTURE2D; + case wgpu::TextureDimension::e3D: + return D3D12_RESOURCE_DIMENSION_TEXTURE3D; case wgpu::TextureDimension::e1D: - case wgpu::TextureDimension::e3D: UNREACHABLE(); } } @@ -1091,9 +1092,15 @@ namespace dawn_native { namespace d3d12 { mSrvDesc.TextureCubeArray.MipLevels = descriptor->mipLevelCount; mSrvDesc.TextureCubeArray.ResourceMinLODClamp = 0; break; + case wgpu::TextureViewDimension::e3D: + ASSERT(texture->GetDimension() == wgpu::TextureDimension::e3D); + mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; + mSrvDesc.Texture3D.MostDetailedMip = descriptor->baseMipLevel; + mSrvDesc.Texture3D.MipLevels = descriptor->mipLevelCount; + mSrvDesc.Texture3D.ResourceMinLODClamp = 0; + break; case wgpu::TextureViewDimension::e1D: - case wgpu::TextureViewDimension::e3D: case wgpu::TextureViewDimension::Undefined: UNREACHABLE(); } diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp index e63a0eb2c3..383a600608 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -45,6 +45,20 @@ namespace { return device.CreateTexture(&descriptor); } + wgpu::Texture Create3DTexture(wgpu::Device device, + wgpu::Extent3D size, + uint32_t mipLevelCount, + wgpu::TextureUsage usage) { + wgpu::TextureDescriptor descriptor; + descriptor.dimension = wgpu::TextureDimension::e3D; + descriptor.size = size; + descriptor.sampleCount = 1; + descriptor.format = kDefaultFormat; + descriptor.mipLevelCount = mipLevelCount; + descriptor.usage = usage; + return device.CreateTexture(&descriptor); + } + wgpu::ShaderModule CreateDefaultVertexShaderModule(wgpu::Device device) { return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( #version 450 @@ -678,3 +692,13 @@ DAWN_INSTANTIATE_TEST(TextureViewTest, OpenGLBackend(), OpenGLESBackend(), VulkanBackend()); + +class TextureView3DTest : public DawnTest {}; + +// Test that 3D textures and 3D texture views can be created successfully +TEST_P(TextureView3DTest, BasicTest) { + wgpu::Texture texture = Create3DTexture(device, {4, 4, 4}, 3, wgpu::TextureUsage::Sampled); + wgpu::TextureView view = texture.CreateView(); +} + +DAWN_INSTANTIATE_TEST(TextureView3DTest, D3D12Backend());