Implement 3D textures and views creation on D3D12 backend

This change also adds a very simple end2end test to verify that
we can create 3D textures and views. But we can't do anything
with them (like copy, sampling, rendering, etc) currently.

I will implement 3d textures and views creation on other backend
in one patch if the simple end2end test is OK.

Bug: dawn:547
Change-Id: I1662458de563cc4b47040a8bc3e94d7a8e0109e5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/39843
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
Yunchao He 2021-02-02 18:45:50 +00:00 committed by Commit Bot service account
parent dd988bca84
commit 04242a063e
2 changed files with 33 additions and 2 deletions

View File

@ -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();
}

View File

@ -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());