Compat: Require viewFormat to equal format
In non compat, you can view an rgba8unorm texture
as an rgba8unorm-srgb texture and visa-versa.
In compat you can not.
Bug: dawn:1360
Change-Id: I9697ea74e2e6d36dca0b25079e2b16dc5c265849
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/163224
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Gregg Tavares <gman@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp
index 87c2893..11eda40 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -58,6 +58,10 @@
"The texture view format (%s) is not texture view format compatible "
"with the texture format (%s).",
viewFormatEnum, format.format);
+
+ DAWN_INVALID_IF(device->IsCompatibilityMode() && viewFormat->format != format.format,
+ "viewFormat (%s) must match format (%s) in compatibility mode.",
+ viewFormat->format, format.format);
return {};
}
diff --git a/src/dawn/tests/unittests/validation/CompatValidationTests.cpp b/src/dawn/tests/unittests/validation/CompatValidationTests.cpp
index ac91331..522b327 100644
--- a/src/dawn/tests/unittests/validation/CompatValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/CompatValidationTests.cpp
@@ -70,6 +70,38 @@
cubeTexture.Destroy();
}
+TEST_F(CompatValidationTest, CanNotSpecifyAlternateCompatibleViewFormatRGBA8Unorm) {
+ constexpr wgpu::TextureFormat viewFormat = wgpu::TextureFormat::RGBA8UnormSrgb;
+
+ wgpu::TextureDescriptor descriptor;
+ descriptor.size = {1, 1, 1};
+ descriptor.dimension = wgpu::TextureDimension::e2D;
+ descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
+ descriptor.usage = wgpu::TextureUsage::TextureBinding;
+ descriptor.viewFormatCount = 1;
+ descriptor.viewFormats = &viewFormat;
+ wgpu::Texture texture;
+ ASSERT_DEVICE_ERROR(texture = device.CreateTexture(&descriptor),
+ testing::HasSubstr("must match format"));
+ texture.Destroy();
+}
+
+TEST_F(CompatValidationTest, CanNotSpecifyAlternateCompatibleViewFormatRGBA8UnormSrgb) {
+ constexpr wgpu::TextureFormat viewFormat = wgpu::TextureFormat::RGBA8Unorm;
+
+ wgpu::TextureDescriptor descriptor;
+ descriptor.size = {1, 1, 1};
+ descriptor.dimension = wgpu::TextureDimension::e2D;
+ descriptor.format = wgpu::TextureFormat::RGBA8UnormSrgb;
+ descriptor.usage = wgpu::TextureUsage::TextureBinding;
+ descriptor.viewFormatCount = 1;
+ descriptor.viewFormats = &viewFormat;
+ wgpu::Texture texture;
+ ASSERT_DEVICE_ERROR(texture = device.CreateTexture(&descriptor),
+ testing::HasSubstr("must match format"));
+ texture.Destroy();
+}
+
TEST_F(CompatValidationTest, CanNotCreatePipelineWithDifferentPerTargetBlendStateOrWriteMask) {
wgpu::ShaderModule module = utils::CreateShaderModule(device, R"(
@vertex fn vs() -> @builtin(position) vec4f {