Add features of depth24unorm-stencil8 and depth32float-stencil8 texture formats

The depth240unorm-stencil8 and depth32float-stencil8 are optional
features. Enable them and add validation tests for texture creation
and texture view creation.

They are unimplmented on backends, skip their end2end tests.

TODO: add validtion for copy commands.

BUG=dawn:690

Change-Id: I980631d2f3fa6397a6125221a76980a15c8cb2f5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/68220
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Hao Li <hao.x.li@intel.com>
This commit is contained in:
Li Hao
2021-11-25 01:11:57 +00:00
committed by Dawn LUCI CQ
parent 596e07f768
commit a329997e27
16 changed files with 333 additions and 95 deletions

View File

@@ -28,6 +28,11 @@ namespace {
wgpu::TextureFormat::RGBA8Snorm,
};
wgpu::TextureDimension kDimensions[] = {
wgpu::TextureDimension::e1D,
wgpu::TextureDimension::e3D,
};
class TextureValidationTest : public ValidationTest {
protected:
void SetUp() override {
@@ -426,21 +431,13 @@ namespace {
TEST_F(TextureValidationTest, DepthStencilFormatsFor3D) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
wgpu::TextureDimension dimensions[] = {
wgpu::TextureDimension::e1D,
wgpu::TextureDimension::e3D,
};
// TODO(dawn:690): Uncomment these depth/stencil formats after we implement them in Dawn.
wgpu::TextureFormat depthStencilFormats[] = {
wgpu::TextureFormat::Stencil8, wgpu::TextureFormat::Depth16Unorm,
wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureFormat::Depth32Float,
// wgpu::TextureFormat::Depth24UnormStencil8,
// wgpu::TextureFormat::Depth32FloatStencil8,
};
for (wgpu::TextureDimension dimension : dimensions) {
for (wgpu::TextureDimension dimension : kDimensions) {
for (wgpu::TextureFormat format : depthStencilFormats) {
descriptor.format = format;
descriptor.dimension = dimension;
@@ -551,6 +548,22 @@ namespace {
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Test that the creation of a texture with depth24unorm-stencil8 will fail when the feature
// Depth24UnormStencil8 is not enabled.
TEST_F(TextureValidationTest, UseD24S8FormatWithoutEnablingFeature) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = wgpu::TextureFormat::Depth24UnormStencil8;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Test that the creation of a texture with depth32float-stencil8 will fail when the feature
// Depth32FloatStencil8 is not enabled.
TEST_F(TextureValidationTest, UseD32S8FormatWithoutEnablingFeature) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
descriptor.format = wgpu::TextureFormat::Depth32FloatStencil8;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
// Test that the creation of a texture with BC format will fail when the feature
// textureCompressionBC is not enabled.
TEST_F(TextureValidationTest, UseBCFormatWithoutEnablingFeature) {
@@ -581,6 +594,46 @@ namespace {
}
}
class D24S8TextureFormatsValidationTests : public TextureValidationTest {
protected:
WGPUDevice CreateTestDevice() override {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredFeatures = {"depth24unorm-stencil8"};
return adapter.CreateDevice(&descriptor);
}
};
// Test that depth24unorm-stencil8 format is invalid for 3D texture
TEST_F(D24S8TextureFormatsValidationTests, DepthStencilFormatsFor3D) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
for (wgpu::TextureDimension dimension : kDimensions) {
descriptor.format = wgpu::TextureFormat::Depth24UnormStencil8;
descriptor.dimension = dimension;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
class D32S8TextureFormatsValidationTests : public TextureValidationTest {
protected:
WGPUDevice CreateTestDevice() override {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredFeatures = {"depth32float-stencil8"};
return adapter.CreateDevice(&descriptor);
}
};
// Test that depth32float-stencil8 format is invalid for 3D texture
TEST_F(D32S8TextureFormatsValidationTests, DepthStencilFormatsFor3D) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
for (wgpu::TextureDimension dimension : kDimensions) {
descriptor.format = wgpu::TextureFormat::Depth32FloatStencil8;
descriptor.dimension = dimension;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
// TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with
// compressed texture formats.
class CompressedTextureFormatsValidationTests : public TextureValidationTest {

View File

@@ -54,6 +54,16 @@ namespace {
return device.CreateTexture(&descriptor);
}
wgpu::Texture CreateDepthStencilTexture(wgpu::Device& device, wgpu::TextureFormat format) {
wgpu::TextureDescriptor descriptor = {};
descriptor.size = {kWidth, kHeight, kDepth};
descriptor.usage =
wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::RenderAttachment;
descriptor.mipLevelCount = kDefaultMipLevels;
descriptor.format = format;
return device.CreateTexture(&descriptor);
}
wgpu::TextureViewDescriptor CreateDefaultViewDescriptor(wgpu::TextureViewDimension dimension) {
wgpu::TextureViewDescriptor descriptor;
descriptor.format = kDefaultTextureFormat;
@@ -639,4 +649,92 @@ namespace {
}
}
class D24S8TextureViewValidationTests : public ValidationTest {
protected:
WGPUDevice CreateTestDevice() override {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredFeatures = {"depth24unorm-stencil8"};
return adapter.CreateDevice(&descriptor);
}
};
// Test that the selected TextureAspects must exist in the Depth24UnormStencil8 texture format
TEST_F(D24S8TextureViewValidationTests, AspectMustExist) {
wgpu::Texture texture =
CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth24UnormStencil8);
// Can select: All, DepthOnly, and StencilOnly from Depth24UnormStencil8
{
wgpu::TextureViewDescriptor viewDescriptor = {};
viewDescriptor.aspect = wgpu::TextureAspect::All;
texture.CreateView(&viewDescriptor);
viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly;
texture.CreateView(&viewDescriptor);
viewDescriptor.aspect = wgpu::TextureAspect::StencilOnly;
texture.CreateView(&viewDescriptor);
}
}
// Test the format compatibility rules when creating a texture view.
TEST_F(D24S8TextureViewValidationTests, TextureViewFormatCompatibility) {
wgpu::Texture texture =
CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth24UnormStencil8);
wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
// It is an error to create a texture view in color format on a depth-stencil texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
class D32S8TextureViewValidationTests : public ValidationTest {
protected:
WGPUDevice CreateTestDevice() override {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredFeatures = {"depth32float-stencil8"};
return adapter.CreateDevice(&descriptor);
}
};
// Test that the selected TextureAspects must exist in the Depth32FloatStencil8 texture format
TEST_F(D32S8TextureViewValidationTests, AspectMustExist) {
wgpu::Texture texture =
CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth32FloatStencil8);
// Can select: All, DepthOnly, and StencilOnly from Depth32FloatStencil8
{
wgpu::TextureViewDescriptor viewDescriptor = {};
viewDescriptor.aspect = wgpu::TextureAspect::All;
texture.CreateView(&viewDescriptor);
viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly;
texture.CreateView(&viewDescriptor);
viewDescriptor.aspect = wgpu::TextureAspect::StencilOnly;
texture.CreateView(&viewDescriptor);
}
}
// Test the format compatibility rules when creating a texture view.
TEST_F(D32S8TextureViewValidationTests, TextureViewFormatCompatibility) {
wgpu::Texture texture =
CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth32FloatStencil8);
wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
// It is an error to create a texture view in color format on a depth-stencil texture.
{
wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
}
} // anonymous namespace