diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 91c905f5f7..0b91e83c5a 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -1303,7 +1303,7 @@ namespace dawn_native { 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 55eb68fb1f..a56e4a8891 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -306,7 +306,8 @@ namespace dawn_native { 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 @@ namespace dawn_native { 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 7ae39463f6..2e39580793 100644 --- a/src/dawn_native/Texture.h +++ b/src/dawn_native/Texture.h @@ -30,7 +30,8 @@ namespace dawn_native { 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 0b4371a229..f4f66f8654 100644 --- a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp +++ b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp @@ -28,6 +28,22 @@ class UnsafeAPIValidationTest : public ValidationTest { } }; +// 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.