Validate creating bind group layout with storage textures

This patch adds the validation on the creation of the bind group
layout with read-only storage texture, write-only storage texture
and read-write storage texture. Currently read-write storage textures
are not supported in any shader stages.

This patch also fixes chromium:1061156.

BUG=chromium:1061156, dawn:267
TEST=dawn_unittests, dawn_end2end_tests

Change-Id: Ib42678719df48565a46e39f21c34ec640960dcdc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16920
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Jiawei Shao
2020-03-16 10:53:36 +00:00
committed by Commit Bot service account
parent 463c394905
commit 1a56ce54e0
5 changed files with 116 additions and 44 deletions

View File

@@ -0,0 +1,50 @@
// Copyright 2020 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "tests/DawnTest.h"
class StorageTextureTests : public DawnTest {};
// Test that using read-only storage texture and write-only storage texture in BindGroupLayout is
// valid on all backends. This test is a regression test for chromium:1061156 and passes by not
// asserting or crashing.
TEST_P(StorageTextureTests, BindGroupLayoutWithStorageTextureBindingType) {
// wgpu::BindingType::ReadonlyStorageTexture is a valid binding type to create a bind group
// layout.
{
wgpu::BindGroupLayoutBinding binding = {0, wgpu::ShaderStage::Compute,
wgpu::BindingType::ReadonlyStorageTexture};
wgpu::BindGroupLayoutDescriptor descriptor;
descriptor.bindingCount = 1;
descriptor.bindings = &binding;
device.CreateBindGroupLayout(&descriptor);
}
// wgpu::BindingType::WriteonlyStorageTexture is a valid binding type to create a bind group
// layout.
{
wgpu::BindGroupLayoutBinding binding = {0, wgpu::ShaderStage::Compute,
wgpu::BindingType::WriteonlyStorageTexture};
wgpu::BindGroupLayoutDescriptor descriptor;
descriptor.bindingCount = 1;
descriptor.bindings = &binding;
device.CreateBindGroupLayout(&descriptor);
}
}
DAWN_INSTANTIATE_TEST(StorageTextureTests,
D3D12Backend(),
MetalBackend(),
OpenGLBackend(),
VulkanBackend());

View File

@@ -205,3 +205,36 @@ TEST_F(StorageTextureValidationTests, ReadWriteStorageTexture) {
ASSERT_DEVICE_ERROR(device.CreateComputePipeline(&descriptor));
}
}
// Test that using read-only storage texture and write-only storage texture in
// BindGroupLayout is valid, while using read-write storage texture is not allowed now.
TEST_F(StorageTextureValidationTests, BindGroupLayoutWithStorageTextureBindingType) {
struct TestSpec {
wgpu::ShaderStage stage;
wgpu::BindingType type;
bool valid;
};
constexpr std::array<TestSpec, 9> kTestSpecs = {
{{wgpu::ShaderStage::Vertex, wgpu::BindingType::ReadonlyStorageTexture, true},
{wgpu::ShaderStage::Vertex, wgpu::BindingType::WriteonlyStorageTexture, false},
{wgpu::ShaderStage::Vertex, wgpu::BindingType::StorageTexture, false},
{wgpu::ShaderStage::Fragment, wgpu::BindingType::ReadonlyStorageTexture, true},
{wgpu::ShaderStage::Fragment, wgpu::BindingType::WriteonlyStorageTexture, false},
{wgpu::ShaderStage::Fragment, wgpu::BindingType::StorageTexture, false},
{wgpu::ShaderStage::Compute, wgpu::BindingType::ReadonlyStorageTexture, true},
{wgpu::ShaderStage::Compute, wgpu::BindingType::WriteonlyStorageTexture, true},
{wgpu::ShaderStage::Compute, wgpu::BindingType::StorageTexture, false}}};
for (const auto& testSpec : kTestSpecs) {
wgpu::BindGroupLayoutBinding binding = {0, testSpec.stage, testSpec.type};
wgpu::BindGroupLayoutDescriptor descriptor;
descriptor.bindingCount = 1;
descriptor.bindings = &binding;
if (testSpec.valid) {
device.CreateBindGroupLayout(&descriptor);
} else {
ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&descriptor));
}
}
}