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 <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Brandon1 Jones <brandon1.jones@intel.com>
This commit is contained in:
Brandon Jones 2022-02-02 21:11:42 +00:00 committed by Dawn LUCI CQ
parent 2fbc170827
commit 012840b752
7 changed files with 26 additions and 19 deletions

View File

@ -125,7 +125,31 @@ namespace dawn::native {
const ExternalTextureDescriptor* descriptor) { const ExternalTextureDescriptor* descriptor) {
// Store any passed in TextureViews associated with individual planes. // Store any passed in TextureViews associated with individual planes.
mTextureViews[0] = descriptor->plane0; 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 // We must create a buffer to store parameters needed by a shader that operates on this
// external texture. // external texture.

View File

@ -65,6 +65,7 @@ namespace dawn::native {
ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor); ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor);
ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag); ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag);
Ref<TextureBase> mDummyTexture;
Ref<BufferBase> mParamsBuffer; Ref<BufferBase> mParamsBuffer;
std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat> mTextureViews; std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat> mTextureViews;

View File

@ -131,9 +131,6 @@ namespace dawn::native {
const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& textureViews = const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& textureViews =
externalTexture->GetTextureViews(); 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); ASSERT(textureViews[2].Get() == nullptr);
mExternalTextureUsages.insert(externalTexture); mExternalTextureUsages.insert(externalTexture);
@ -205,9 +202,6 @@ namespace dawn::native {
const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& textureViews = const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& textureViews =
externalTexture->GetTextureViews(); 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); ASSERT(textureViews[2].Get() == nullptr);
mUsage.referencedExternalTextures.insert(externalTexture); mUsage.referencedExternalTextures.insert(externalTexture);

View File

@ -180,9 +180,6 @@ namespace dawn::native::d3d12 {
const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& views = const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& views =
GetBindingAsExternalTexture(bindingIndex)->GetTextureViews(); 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); ASSERT(views[2].Get() == nullptr);
auto& srv = ToBackend(views[0])->GetSRVDescriptor(); auto& srv = ToBackend(views[0])->GetSRVDescriptor();

View File

@ -495,9 +495,6 @@ namespace dawn::native::metal {
const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& views = const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& views =
group->GetBindingAsExternalTexture(bindingIndex)->GetTextureViews(); 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); ASSERT(views[2].Get() == nullptr);
TextureView* textureView = ToBackend(views[0].Get()); TextureView* textureView = ToBackend(views[0].Get());

View File

@ -370,9 +370,6 @@ namespace dawn::native::opengl {
->GetBindingAsExternalTexture(bindingIndex) ->GetBindingAsExternalTexture(bindingIndex)
->GetTextureViews(); ->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); ASSERT(textureViews[2].Get() == nullptr);
TextureView* view = ToBackend(textureViews[0].Get()); TextureView* view = ToBackend(textureViews[0].Get());

View File

@ -134,9 +134,6 @@ namespace dawn::native::vulkan {
const std::array<Ref<dawn::native::TextureViewBase>, kMaxPlanesPerFormat>& const std::array<Ref<dawn::native::TextureViewBase>, kMaxPlanesPerFormat>&
textureViews = GetBindingAsExternalTexture(bindingIndex)->GetTextureViews(); 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); ASSERT(textureViews[2].Get() == nullptr);
TextureView* view = ToBackend(textureViews[0].Get()); TextureView* view = ToBackend(textureViews[0].Get());