Add unsafe API tests for 3D textures
This change also marks 3D view creation as Unsafe API.
BUG: dawn:547
Change-Id: Icdb7b48f19054d70258363f6d58ded957be72b70
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/46723
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp
index 91c905f..0b91e83 100644
--- a/src/dawn_native/Device.cpp
+++ b/src/dawn_native/Device.cpp
@@ -1303,7 +1303,7 @@
DAWN_TRY(ValidateObject(texture));
TextureViewDescriptor desc = GetTextureViewDescriptorWithDefaults(texture, descriptor);
if (IsValidationEnabled()) {
- DAWN_TRY(ValidateTextureViewDescriptor(texture, &desc));
+ DAWN_TRY(ValidateTextureViewDescriptor(this, texture, &desc));
}
return CreateTextureViewImpl(texture, &desc);
}
diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp
index 55eb68f..a56e4a8 100644
--- a/src/dawn_native/Texture.cpp
+++ b/src/dawn_native/Texture.cpp
@@ -306,7 +306,8 @@
return {};
}
- MaybeError ValidateTextureViewDescriptor(const TextureBase* texture,
+ MaybeError ValidateTextureViewDescriptor(const DeviceBase* device,
+ const TextureBase* texture,
const TextureViewDescriptor* descriptor) {
if (descriptor->nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
@@ -324,6 +325,13 @@
return DAWN_VALIDATION_ERROR("1D texture views aren't supported (yet).");
}
+ // Disallow 3D views as unsafe until they are fully implemented.
+ if (descriptor->dimension == wgpu::TextureViewDimension::e3D &&
+ device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
+ return DAWN_VALIDATION_ERROR(
+ "3D views are disallowed because they are not fully implemented");
+ }
+
DAWN_TRY(ValidateTextureFormat(descriptor->format));
DAWN_TRY(ValidateTextureAspect(descriptor->aspect));
diff --git a/src/dawn_native/Texture.h b/src/dawn_native/Texture.h
index 7ae3946..2e39580 100644
--- a/src/dawn_native/Texture.h
+++ b/src/dawn_native/Texture.h
@@ -30,7 +30,8 @@
MaybeError ValidateTextureDescriptor(const DeviceBase* device,
const TextureDescriptor* descriptor);
- MaybeError ValidateTextureViewDescriptor(const TextureBase* texture,
+ MaybeError ValidateTextureViewDescriptor(const DeviceBase* device,
+ const TextureBase* texture,
const TextureViewDescriptor* descriptor);
TextureViewDescriptor GetTextureViewDescriptorWithDefaults(
const TextureBase* texture,
diff --git a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp
index 0b4371a..f4f66f8 100644
--- a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp
+++ b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp
@@ -28,6 +28,22 @@
}
};
+// Check that 3D Texture creation is disallowed as part of unsafe APIs.
+TEST_F(UnsafeAPIValidationTest, 3DTextureCreationDisallowed) {
+ wgpu::TextureDescriptor baseDesc;
+ baseDesc.size = {32, 32, 6};
+ baseDesc.format = wgpu::TextureFormat::RGBA8Unorm;
+ baseDesc.usage = wgpu::TextureUsage::Sampled;
+
+ // Control case: 2D (array) texture creation is allowed.
+ device.CreateTexture(&baseDesc);
+
+ // 3D texture creation is disallowed.
+ wgpu::TextureDescriptor texture3DDesc = baseDesc;
+ texture3DDesc.dimension = wgpu::TextureDimension::e3D;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&texture3DDesc));
+}
+
// Check that DrawIndexedIndirect is disallowed as part of unsafe APIs.
TEST_F(UnsafeAPIValidationTest, DrawIndexedIndirectDisallowed) {
// Create the index and indirect buffers.