Support sampling depth and stencil of combined d/s formats

This CL adds sampling of depth-only and stencil-only texture
views on all backends. However, Metal on macOS <= 10.11 will
need a workaround to use separate depth/stencil textures for
each aspect since it is impossible to sample the stencil
aspect of a combined depth/stencil texture.

Also fixes sampling of depth24plus on D3D12 which had an
incomplete check for determining if a TYPELESS format is
necessary.

Bug: dawn:439, dawn:553
Change-Id: Id4991c565f822add200054296714e2dcd330119a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30725
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Austin Eng
2020-11-04 15:27:11 +00:00
committed by Commit Bot service account
parent 9d6265bc07
commit a0f1725c4f
9 changed files with 633 additions and 153 deletions

View File

@@ -15,9 +15,23 @@
#include <gtest/gtest.h>
#include "common/Math.h"
#include "dawn/EnumClassBitmasks.h"
#include <cmath>
namespace wgpu {
enum class TestEnum {
A = 0x1,
B = 0x2,
C = 0x4,
};
} // namespace wgpu
template <>
struct wgpu::IsDawnBitmask<wgpu::TestEnum> {
static constexpr bool enable = true;
};
// Tests for ScanForward
TEST(Math, ScanForward) {
// Test extrema
@@ -260,3 +274,32 @@ TEST(Math, RoundUp) {
ASSERT_EQ(RoundUp(0x7FFFFFFFFFFFFFFFull, 0x8000000000000000ull), 0x8000000000000000ull);
ASSERT_EQ(RoundUp(1, 1), 1u);
}
// Tests for IsSubset
TEST(Math, IsSubset) {
// single value is a subset
ASSERT_TRUE(IsSubset(0b100, 0b101));
ASSERT_FALSE(IsSubset(0b010, 0b101));
ASSERT_TRUE(IsSubset(0b001, 0b101));
// empty set is a subset
ASSERT_TRUE(IsSubset(0b000, 0b101));
// equal-to is a subset
ASSERT_TRUE(IsSubset(0b101, 0b101));
// superset is not a subset
ASSERT_FALSE(IsSubset(0b111, 0b101));
// only empty is a subset of empty
ASSERT_FALSE(IsSubset(0b100, 0b000));
ASSERT_FALSE(IsSubset(0b010, 0b000));
ASSERT_FALSE(IsSubset(0b001, 0b000));
ASSERT_TRUE(IsSubset(0b000, 0b000));
// Test with enums
ASSERT_TRUE(IsSubset(wgpu::TestEnum::A, wgpu::TestEnum::A));
ASSERT_TRUE(IsSubset(wgpu::TestEnum::A, wgpu::TestEnum::A | wgpu::TestEnum::B));
ASSERT_FALSE(IsSubset(wgpu::TestEnum::C, wgpu::TestEnum::A | wgpu::TestEnum::B));
ASSERT_FALSE(IsSubset(wgpu::TestEnum::A | wgpu::TestEnum::C, wgpu::TestEnum::A));
}

View File

@@ -311,10 +311,8 @@ TEST_F(BindGroupValidationTest, TextureComponentType) {
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, uintTextureView}}));
}
// Test which depth-stencil formats are allowed to be sampled.
// This is a regression test for a change in dawn_native mistakenly allowing the depth24plus formats
// to be sampled without proper backend support.
TEST_F(BindGroupValidationTest, SamplingDepthTexture) {
// Test which depth-stencil formats are allowed to be sampled (all).
TEST_F(BindGroupValidationTest, SamplingDepthStencilTexture) {
wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture}});
@@ -330,20 +328,30 @@ TEST_F(BindGroupValidationTest, SamplingDepthTexture) {
utils::MakeBindGroup(device, layout, {{0, texture.CreateView()}});
}
// Depth24Plus is not allowed to be sampled.
// Depth24Plus is allowed to be sampled.
{
desc.format = wgpu::TextureFormat::Depth24Plus;
wgpu::Texture texture = device.CreateTexture(&desc);
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, texture.CreateView()}}));
utils::MakeBindGroup(device, layout, {{0, texture.CreateView()}});
}
// Depth24PlusStencil8 is not allowed to be sampled.
// Depth24PlusStencil8 is allowed to be sampled, if the depth or stencil aspect is selected.
{
desc.format = wgpu::TextureFormat::Depth24PlusStencil8;
wgpu::Texture texture = device.CreateTexture(&desc);
wgpu::TextureViewDescriptor viewDesc = {};
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, texture.CreateView()}}));
viewDesc.aspect = wgpu::TextureAspect::DepthOnly;
utils::MakeBindGroup(device, layout, {{0, texture.CreateView(&viewDesc)}});
wgpu::BindGroupLayoutEntry entry = {0, wgpu::ShaderStage::Fragment,
wgpu::BindingType::SampledTexture};
entry.textureComponentType = wgpu::TextureComponentType::Uint;
layout = utils::MakeBindGroupLayout(device, {entry});
viewDesc.aspect = wgpu::TextureAspect::StencilOnly;
utils::MakeBindGroup(device, layout, {{0, texture.CreateView(&viewDesc)}});
}
}