Skip to content

Commit d7e6def

Browse files
kainino0xdawn-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[dawn][native] Disallow viewFormats with TRANSIENT_ATTACHMENT
Without this, we hit "Failed to create MTLTexture view" in the Metal backend when trying to create a view with a different format on a transient texture. (This happens even without Metal validation layers so it's not a vulnerability, it just loses the device.) Bug: gpuweb/gpuweb#6263 Test: gpuweb/cts#4647 Change-Id: Ia4b33594b0d47822af34fc5d8294d22f996fdc38 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/310035 Reviewed-by: Fr <beaufort.francois@gmail.com> Commit-Queue: Fr <beaufort.francois@gmail.com> Auto-Submit: Kai Ninomiya <kainino@chromium.org>
1 parent 6d3df85 commit d7e6def

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/dawn/native/Texture.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,14 @@ MaybeError ValidateTextureDescriptor(
798798
DAWN_TRY(ValidateTextureUsageConstraints(device, descriptor->dimension, usage, format,
799799
std::move(allowedSharedTextureMemoryUsage)));
800800

801-
DAWN_INVALID_IF(
802-
usage & wgpu::TextureUsage::TransientAttachment &&
801+
if (usage & wgpu::TextureUsage::TransientAttachment) {
802+
DAWN_INVALID_IF(
803803
(descriptor->size.depthOrArrayLayers != 1 || descriptor->mipLevelCount != 1),
804-
"The texture size depthOrArrayLayers (%u) and mipLevelCount (%u) must be 1.",
805-
descriptor->size.depthOrArrayLayers, descriptor->mipLevelCount);
804+
"Transient textures must have depthOrArrayLayers (%u) = 1 and mipLevelCount (%u) = 1.",
805+
descriptor->size.depthOrArrayLayers, descriptor->mipLevelCount);
806+
DAWN_INVALID_IF(descriptor->viewFormatCount > 0,
807+
"Transient textures must not have any viewFormats");
808+
}
806809

807810
DAWN_TRY(ValidateTextureDimension(descriptor->dimension));
808811
if (!device->HasFlexibleTextureViews()) {

src/dawn/tests/unittests/native/MemoryInstrumentationTests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ TEST_F(MemoryInstrumentationTest, DumpMemoryStatistics) {
193193
.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::TransientAttachment,
194194
.size = {.width = 30, .height = 20},
195195
.format = kRGBA8UnormTextureFormat,
196-
.viewFormatCount = 1,
197-
.viewFormats = &kRGBA8UnormTextureFormat,
198196
};
199197
wgpu::Texture transientAttachmentTexture =
200198
device.CreateTexture(&kTransientAttachmentTextureDesc);

0 commit comments

Comments
 (0)