From 012840b75229c32924ed1dfcd643be4104fae155 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Wed, 2 Feb 2022 21:11:42 +0000 Subject: [PATCH] Create 1x1 Dummy Texture For Single-Plane External Textures Creates a 1x1x1 dummy texture that will be bound, but unused to shaders that use external textures. It is expected that a special texture type will be introduced and used in the future to optimize backends that allow null bindings. Bug: dawn:1082 Change-Id: I0c49f58f6a725290ec9b73b09578c0f85e5b38d7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/78940 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Brandon1 Jones --- src/dawn_native/ExternalTexture.cpp | 26 +++++++++++++++++++- src/dawn_native/ExternalTexture.h | 1 + src/dawn_native/PassResourceUsageTracker.cpp | 6 ----- src/dawn_native/d3d12/BindGroupD3D12.cpp | 3 --- src/dawn_native/metal/CommandBufferMTL.mm | 3 --- src/dawn_native/opengl/CommandBufferGL.cpp | 3 --- src/dawn_native/vulkan/BindGroupVk.cpp | 3 --- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/dawn_native/ExternalTexture.cpp b/src/dawn_native/ExternalTexture.cpp index db211045fe..c3126d834f 100644 --- a/src/dawn_native/ExternalTexture.cpp +++ b/src/dawn_native/ExternalTexture.cpp @@ -125,7 +125,31 @@ namespace dawn::native { const ExternalTextureDescriptor* descriptor) { // Store any passed in TextureViews associated with individual planes. mTextureViews[0] = descriptor->plane0; - mTextureViews[1] = descriptor->plane1; + + if (descriptor->plane1) { + mTextureViews[1] = descriptor->plane1; + } else { + TextureDescriptor textureDesc; + textureDesc.dimension = wgpu::TextureDimension::e2D; + textureDesc.format = wgpu::TextureFormat::RGBA8Unorm; + textureDesc.label = "Dawn_External_Texture_Dummy_Texture"; + textureDesc.size = {1, 1, 1}; + textureDesc.usage = wgpu::TextureUsage::TextureBinding; + + DAWN_TRY_ASSIGN(mDummyTexture, device->CreateTexture(&textureDesc)); + + TextureViewDescriptor textureViewDesc; + textureViewDesc.arrayLayerCount = 1; + textureViewDesc.aspect = wgpu::TextureAspect::All; + textureViewDesc.baseArrayLayer = 0; + textureViewDesc.dimension = wgpu::TextureViewDimension::e2D; + textureViewDesc.format = wgpu::TextureFormat::RGBA8Unorm; + textureViewDesc.label = "Dawn_External_Texture_Dummy_Texture_View"; + textureViewDesc.mipLevelCount = 1; + + DAWN_TRY_ASSIGN(mTextureViews[1], + device->CreateTextureView(mDummyTexture.Get(), &textureViewDesc)); + } // We must create a buffer to store parameters needed by a shader that operates on this // external texture. diff --git a/src/dawn_native/ExternalTexture.h b/src/dawn_native/ExternalTexture.h index 6a2476af1f..27df552827 100644 --- a/src/dawn_native/ExternalTexture.h +++ b/src/dawn_native/ExternalTexture.h @@ -65,6 +65,7 @@ namespace dawn::native { ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor); ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag); + Ref mDummyTexture; Ref mParamsBuffer; std::array, kMaxPlanesPerFormat> mTextureViews; diff --git a/src/dawn_native/PassResourceUsageTracker.cpp b/src/dawn_native/PassResourceUsageTracker.cpp index 2acb20794c..5fa4717587 100644 --- a/src/dawn_native/PassResourceUsageTracker.cpp +++ b/src/dawn_native/PassResourceUsageTracker.cpp @@ -131,9 +131,6 @@ namespace dawn::native { const std::array, kMaxPlanesPerFormat>& textureViews = externalTexture->GetTextureViews(); - // Only single-plane formats are supported right now, so assert only one - // view exists. - ASSERT(textureViews[1].Get() == nullptr); ASSERT(textureViews[2].Get() == nullptr); mExternalTextureUsages.insert(externalTexture); @@ -205,9 +202,6 @@ namespace dawn::native { const std::array, kMaxPlanesPerFormat>& textureViews = externalTexture->GetTextureViews(); - // Only single-plane formats are supported right now, so assert only one - // view exists. - ASSERT(textureViews[1].Get() == nullptr); ASSERT(textureViews[2].Get() == nullptr); mUsage.referencedExternalTextures.insert(externalTexture); diff --git a/src/dawn_native/d3d12/BindGroupD3D12.cpp b/src/dawn_native/d3d12/BindGroupD3D12.cpp index 7957bd5763..9e7522c1d0 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupD3D12.cpp @@ -180,9 +180,6 @@ namespace dawn::native::d3d12 { const std::array, kMaxPlanesPerFormat>& views = GetBindingAsExternalTexture(bindingIndex)->GetTextureViews(); - // Only single-plane formats are supported right now, so assert only one view - // exists. - ASSERT(views[1].Get() == nullptr); ASSERT(views[2].Get() == nullptr); auto& srv = ToBackend(views[0])->GetSRVDescriptor(); diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 55c85e8c26..59716b729c 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -495,9 +495,6 @@ namespace dawn::native::metal { const std::array, kMaxPlanesPerFormat>& views = group->GetBindingAsExternalTexture(bindingIndex)->GetTextureViews(); - // Only single-plane formats are supported right now, so assert only one - // view exists. - ASSERT(views[1].Get() == nullptr); ASSERT(views[2].Get() == nullptr); TextureView* textureView = ToBackend(views[0].Get()); diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index 2601d613dd..12f31c958d 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -370,9 +370,6 @@ namespace dawn::native::opengl { ->GetBindingAsExternalTexture(bindingIndex) ->GetTextureViews(); - // Only single-plane formats are supported right now, so assert only one - // view exists. - ASSERT(textureViews[1].Get() == nullptr); ASSERT(textureViews[2].Get() == nullptr); TextureView* view = ToBackend(textureViews[0].Get()); diff --git a/src/dawn_native/vulkan/BindGroupVk.cpp b/src/dawn_native/vulkan/BindGroupVk.cpp index fca8d88869..f94fa2dce9 100644 --- a/src/dawn_native/vulkan/BindGroupVk.cpp +++ b/src/dawn_native/vulkan/BindGroupVk.cpp @@ -134,9 +134,6 @@ namespace dawn::native::vulkan { const std::array, kMaxPlanesPerFormat>& textureViews = GetBindingAsExternalTexture(bindingIndex)->GetTextureViews(); - // Only single-plane formats are supported right now, so ensure only one view - // exists. - ASSERT(textureViews[1].Get() == nullptr); ASSERT(textureViews[2].Get() == nullptr); TextureView* view = ToBackend(textureViews[0].Get());