From 00fcab636a055c78036ee20bb1a89339b0a28bad Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 7 Jan 2021 17:33:44 +0000 Subject: [PATCH] Fix default viewDimension in deprecated BGLEntry path. The handling of the default view dimension in the deprecated bind group layout entry path was checking the viewDimension of the new sub-descriptor instead of the deprecated viewDimension member. This meant that viewDimension was always defaulted and "2D". This commit fixes the issue by looking at the correct viewDimension member and adds a regression deprecation test. Bug: dawn:620 Change-Id: Icc133b6d80ba3d88bae30dc9138f1d74e14d12c7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36841 Auto-Submit: Corentin Wallez Commit-Queue: Austin Eng Reviewed-by: Brandon Jones Reviewed-by: Austin Eng --- src/dawn_native/BindGroupLayout.cpp | 9 ++--- src/tests/end2end/DeprecatedAPITests.cpp | 45 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index 3d95e3bef4..0ae9b83872 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -443,8 +443,7 @@ namespace dawn_native { case wgpu::BindingType::SampledTexture: bindingInfo.bindingType = BindingInfoType::Texture; bindingInfo.texture.viewDimension = binding.viewDimension; - if (binding.texture.viewDimension == - wgpu::TextureViewDimension::Undefined) { + if (binding.viewDimension == wgpu::TextureViewDimension::Undefined) { bindingInfo.texture.viewDimension = wgpu::TextureViewDimension::e2D; } @@ -469,8 +468,7 @@ namespace dawn_native { bindingInfo.storageTexture.access = wgpu::StorageTextureAccess::ReadOnly; bindingInfo.storageTexture.format = binding.storageTextureFormat; bindingInfo.storageTexture.viewDimension = binding.viewDimension; - if (binding.storageTexture.viewDimension == - wgpu::TextureViewDimension::Undefined) { + if (binding.viewDimension == wgpu::TextureViewDimension::Undefined) { bindingInfo.storageTexture.viewDimension = wgpu::TextureViewDimension::e2D; } @@ -480,8 +478,7 @@ namespace dawn_native { bindingInfo.storageTexture.access = wgpu::StorageTextureAccess::WriteOnly; bindingInfo.storageTexture.format = binding.storageTextureFormat; bindingInfo.storageTexture.viewDimension = binding.viewDimension; - if (binding.storageTexture.viewDimension == - wgpu::TextureViewDimension::Undefined) { + if (binding.viewDimension == wgpu::TextureViewDimension::Undefined) { bindingInfo.storageTexture.viewDimension = wgpu::TextureViewDimension::e2D; } diff --git a/src/tests/end2end/DeprecatedAPITests.cpp b/src/tests/end2end/DeprecatedAPITests.cpp index 9855619106..5cd4240b6f 100644 --- a/src/tests/end2end/DeprecatedAPITests.cpp +++ b/src/tests/end2end/DeprecatedAPITests.cpp @@ -105,6 +105,51 @@ TEST_P(DeprecationTests, BindGroupLayoutEntryTypeConflict) { ASSERT_DEVICE_ERROR(device.CreateBindGroupLayout(&descriptor)); } +// Test that the deprecated BGLEntry path correctly handles the defaulting of viewDimension. +// This is a regression test for crbug.com/dawn/620 +TEST_P(DeprecationTests, BindGroupLayoutEntryViewDimensionDefaulting) { + wgpu::BindGroupLayoutEntry binding; + binding.binding = 0; + binding.visibility = wgpu::ShaderStage::Vertex; + binding.type = wgpu::BindingType::SampledTexture; + + wgpu::BindGroupLayoutDescriptor bglDesc; + bglDesc.entryCount = 1; + bglDesc.entries = &binding; + + // Check that the default viewDimension is 2D. + { + binding.viewDimension = wgpu::TextureViewDimension::Undefined; + wgpu::BindGroupLayout bgl = device.CreateBindGroupLayout(&bglDesc); + + wgpu::TextureDescriptor desc; + desc.usage = wgpu::TextureUsage::Sampled; + desc.size = {1, 1, 1}; + desc.format = wgpu::TextureFormat::RGBA8Unorm; + desc.dimension = wgpu::TextureDimension::e2D; + wgpu::Texture texture = device.CreateTexture(&desc); + + // Success, the default is 2D and we give it a 2D view. + utils::MakeBindGroup(device, bgl, {{0, texture.CreateView()}}); + } + + // Check that setting a non-default viewDimension works. + { + binding.viewDimension = wgpu::TextureViewDimension::e2DArray; + wgpu::BindGroupLayout bgl = device.CreateBindGroupLayout(&bglDesc); + + wgpu::TextureDescriptor desc; + desc.usage = wgpu::TextureUsage::Sampled; + desc.size = {1, 1, 4}; + desc.format = wgpu::TextureFormat::RGBA8Unorm; + desc.dimension = wgpu::TextureDimension::e2D; + wgpu::Texture texture = device.CreateTexture(&desc); + + // Success, the view will be 2DArray and the BGL expects a 2DArray. + utils::MakeBindGroup(device, bgl, {{0, texture.CreateView()}}); + } +} + DAWN_INSTANTIATE_TEST(DeprecationTests, D3D12Backend(), MetalBackend(),