From 5a1d786754ad865c1b72c46e4f9c0d3dcc19aa72 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Fri, 30 Oct 2020 17:54:46 +0000 Subject: [PATCH] Check for deprecation warnings in ValidationTests And adds EXPECT_DEPRECATION_WARNING where necessary in validation tests. Bug: dawn:520, dawn:527 Change-Id: Ic8e103e4b7b5784a2009519e0a18ed16088632b1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/31300 Reviewed-by: Corentin Wallez Commit-Queue: Kai Ninomiya --- .../validation/BindGroupValidationTests.cpp | 27 ++++++++++--------- .../GetBindGroupLayoutValidationTests.cpp | 19 +++++++++++-- .../RenderPipelineValidationTests.cpp | 2 +- .../unittests/validation/ValidationTest.cpp | 5 ++++ .../unittests/validation/ValidationTest.h | 11 ++++++++ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 8b9994d802..d6abcb80b4 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -950,18 +950,11 @@ TEST_F(BindGroupLayoutValidationTest, MultisampledTextureViewDimension) { 0, false, wgpu::TextureViewDimension::Undefined}, }); - // Multisampled 2D storage texture is invalid. - ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout( - device, { - {0, wgpu::ShaderStage::Compute, wgpu::BindingType::ReadonlyStorageTexture, - false, 0, true, wgpu::TextureViewDimension::e2D}, - })); - // Multisampled 2D array texture is invalid. ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout( device, { - {0, wgpu::ShaderStage::Compute, wgpu::BindingType::SampledTexture, false, 0, - true, wgpu::TextureViewDimension::e2DArray}, + {0, wgpu::ShaderStage::Compute, wgpu::BindingType::MultisampledTexture, false, + 0, false, wgpu::TextureViewDimension::e2DArray}, })); // Multisampled cube texture is invalid. @@ -1032,14 +1025,15 @@ TEST_F(BindGroupLayoutValidationTest, MultisampledTextureComponentType) { })); } -// Test that it is an error to pass multisampled=true for non-texture bindings -TEST_F(BindGroupLayoutValidationTest, MultisampledMustBeTexture) { +// Test that it is an error to pass multisampled=true for non-texture bindings. +// TODO(crbug.com/dawn/527): Remove this test when multisampled=true is removed. +TEST_F(BindGroupLayoutValidationTest, MultisampledMustBeSampledTexture) { // Base: Multisampled 2D texture works. - utils::MakeBindGroupLayout( + EXPECT_DEPRECATION_WARNING(utils::MakeBindGroupLayout( device, { {0, wgpu::ShaderStage::Compute, wgpu::BindingType::SampledTexture, false, 0, true, wgpu::TextureViewDimension::e2D}, - }); + })); // Multisampled uniform buffer binding is invalid ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout( @@ -1060,6 +1054,13 @@ TEST_F(BindGroupLayoutValidationTest, MultisampledMustBeTexture) { device, { {0, wgpu::ShaderStage::Compute, wgpu::BindingType::Sampler, false, 0, true}, })); + + // Multisampled 2D storage texture is invalid. + ASSERT_DEVICE_ERROR(utils::MakeBindGroupLayout( + device, { + {0, wgpu::ShaderStage::Compute, wgpu::BindingType::ReadonlyStorageTexture, + false, 0, true, wgpu::TextureViewDimension::e2D}, + })); } constexpr uint64_t kBufferSize = 3 * kMinDynamicBufferOffsetAlignment + 8; diff --git a/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp b/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp index f73a2277b8..704091465e 100644 --- a/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp +++ b/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp @@ -247,7 +247,6 @@ TEST_F(GetBindGroupLayoutTests, BindingType) { TEST_F(GetBindGroupLayoutTests, Multisampled) { wgpu::BindGroupLayoutEntry binding = {}; binding.binding = 0; - binding.type = wgpu::BindingType::SampledTexture; binding.visibility = wgpu::ShaderStage::Fragment; binding.hasDynamicOffset = false; @@ -256,6 +255,7 @@ TEST_F(GetBindGroupLayoutTests, Multisampled) { desc.entries = &binding; { + binding.type = wgpu::BindingType::SampledTexture; binding.multisampled = false; wgpu::RenderPipeline pipeline = RenderPipelineFromFragmentShader(R"( #version 450 @@ -266,7 +266,8 @@ TEST_F(GetBindGroupLayoutTests, Multisampled) { } { - binding.multisampled = true; + binding.type = wgpu::BindingType::MultisampledTexture; + binding.multisampled = false; wgpu::RenderPipeline pipeline = RenderPipelineFromFragmentShader(R"( #version 450 layout(set = 0, binding = 0) uniform texture2DMS tex; @@ -274,6 +275,20 @@ TEST_F(GetBindGroupLayoutTests, Multisampled) { void main() {})"); EXPECT_EQ(device.CreateBindGroupLayout(&desc).Get(), pipeline.GetBindGroupLayout(0).Get()); } + + // TODO(crbug.com/dawn/527): Remove this block when multisampled=true is removed. + { + binding.type = wgpu::BindingType::SampledTexture; + binding.multisampled = true; + wgpu::RenderPipeline pipeline = RenderPipelineFromFragmentShader(R"( + #version 450 + layout(set = 0, binding = 0) uniform texture2DMS tex; + + void main() {})"); + wgpu::BindGroupLayout bgl; + EXPECT_DEPRECATION_WARNING(bgl = device.CreateBindGroupLayout(&desc)); + EXPECT_EQ(bgl.Get(), pipeline.GetBindGroupLayout(0).Get()); + } } // Test that texture view dimension matches the shader. diff --git a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp index 8c81f5bd57..bb6fc81a74 100644 --- a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp @@ -585,7 +585,7 @@ TEST_F(RenderPipelineValidationTest, StripIndexFormatRequired) { // TODO(crbug.com/dawn/502): Once setIndexBuffer requires an // indexFormat. this should fail. For now it succeeds to allow // backwards compatibility during the deprecation period. - device.CreateRenderPipeline(&descriptor); + EXPECT_DEPRECATION_WARNING(device.CreateRenderPipeline(&descriptor)); } } } diff --git a/src/tests/unittests/validation/ValidationTest.cpp b/src/tests/unittests/validation/ValidationTest.cpp index 5993096c57..298529d390 100644 --- a/src/tests/unittests/validation/ValidationTest.cpp +++ b/src/tests/unittests/validation/ValidationTest.cpp @@ -72,6 +72,11 @@ ValidationTest::~ValidationTest() { void ValidationTest::TearDown() { ASSERT_FALSE(mExpectError); + + if (device) { + EXPECT_EQ(mLastWarningCount, + dawn_native::GetDeprecationWarningCountForTesting(device.Get())); + } } void ValidationTest::StartExpectDeviceError() { diff --git a/src/tests/unittests/validation/ValidationTest.h b/src/tests/unittests/validation/ValidationTest.h index 8468aa7afb..aaff4e14cc 100644 --- a/src/tests/unittests/validation/ValidationTest.h +++ b/src/tests/unittests/validation/ValidationTest.h @@ -39,6 +39,15 @@ } \ } while (0) +#define EXPECT_DEPRECATION_WARNING(statement) \ + do { \ + size_t warningsBefore = dawn_native::GetDeprecationWarningCountForTesting(device.Get()); \ + statement; \ + size_t warningsAfter = dawn_native::GetDeprecationWarningCountForTesting(device.Get()); \ + EXPECT_EQ(mLastWarningCount, warningsBefore); \ + mLastWarningCount = warningsAfter; \ + } while (0) + class ValidationTest : public testing::Test { public: ValidationTest(); @@ -76,6 +85,8 @@ class ValidationTest : public testing::Test { dawn_native::Adapter adapter; std::unique_ptr instance; + size_t mLastWarningCount = 0; + private: static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata); std::string mDeviceErrorMessage;