Add GPUExternalTexture Types

Adds GPUExternalTexture-related types, as well as
Device::ImportExternalTexture. Adds a basic unit and end2end test.

Bug: dawn:728
Change-Id: Iee9533eb872c493a089cccd500748f1a61457407
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/46060
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Brandon Jones <brandon1.jones@intel.com>
This commit is contained in:
Brandon Jones
2021-04-01 20:46:42 +00:00
committed by Commit Bot service account
parent a223e1f0c8
commit 0e92e9bf3c
12 changed files with 389 additions and 4 deletions

View File

@@ -192,6 +192,7 @@ test("dawn_unittests") {
"unittests/validation/DrawIndirectValidationTests.cpp",
"unittests/validation/DynamicStateCommandValidationTests.cpp",
"unittests/validation/ErrorScopeValidationTests.cpp",
"unittests/validation/ExternalTextureTests.cpp",
"unittests/validation/FenceValidationTests.cpp",
"unittests/validation/GetBindGroupLayoutValidationTests.cpp",
"unittests/validation/IndexBufferValidationTests.cpp",
@@ -308,6 +309,7 @@ source_set("dawn_end2end_tests_sources") {
"end2end/DrawTests.cpp",
"end2end/DynamicBufferOffsetTests.cpp",
"end2end/EntryPointTests.cpp",
"end2end/ExternalTextureTests.cpp",
"end2end/FenceTests.cpp",
"end2end/FirstIndexOffsetTests.cpp",
"end2end/GpuMemorySynchronizationTests.cpp",

View File

@@ -0,0 +1,69 @@
// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "tests/DawnTest.h"
namespace {
wgpu::Texture Create2DTexture(wgpu::Device device,
uint32_t width,
uint32_t height,
wgpu::TextureFormat format,
wgpu::TextureUsage usage) {
wgpu::TextureDescriptor descriptor;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.size.width = width;
descriptor.size.height = height;
descriptor.size.depthOrArrayLayers = 1;
descriptor.sampleCount = 1;
descriptor.format = format;
descriptor.mipLevelCount = 1;
descriptor.usage = usage;
return device.CreateTexture(&descriptor);
}
class ExternalTextureTests : public DawnTest {
protected:
static constexpr uint32_t kWidth = 4;
static constexpr uint32_t kHeight = 4;
static constexpr wgpu::TextureFormat kFormat = wgpu::TextureFormat::RGBA8Unorm;
static constexpr wgpu::TextureUsage kSampledUsage = wgpu::TextureUsage::Sampled;
};
} // anonymous namespace
TEST_P(ExternalTextureTests, CreateExternalTextureSuccess) {
DAWN_SKIP_TEST_IF(UsesWire());
wgpu::Texture texture = Create2DTexture(device, kWidth, kHeight, kFormat, kSampledUsage);
// Create a texture view for the external texture
wgpu::TextureView view = texture.CreateView();
// Create an ExternalTextureDescriptor from the texture view
wgpu::ExternalTextureDescriptor externalDesc;
externalDesc.plane0 = view;
externalDesc.format = kFormat;
// Import the external texture
wgpu::ExternalTexture externalTexture = device.CreateExternalTexture(&externalDesc);
ASSERT_NE(externalTexture.Get(), nullptr);
}
DAWN_INSTANTIATE_TEST(ExternalTextureTests,
D3D12Backend(),
MetalBackend(),
OpenGLBackend(),
OpenGLESBackend(),
VulkanBackend());

View File

@@ -0,0 +1,99 @@
// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "tests/unittests/validation/ValidationTest.h"
namespace {
class ExternalTextureTest : public ValidationTest {
public:
wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
wgpu::TextureDescriptor descriptor;
descriptor.size.width = kWidth;
descriptor.size.height = kHeight;
descriptor.size.depth = kDefaultDepth;
descriptor.mipLevelCount = kDefaultMipLevels;
descriptor.sampleCount = kDefaultSampleCount;
descriptor.dimension = wgpu::TextureDimension::e2D;
descriptor.format = kDefaultTextureFormat;
descriptor.usage = wgpu::TextureUsage::Sampled;
return descriptor;
}
protected:
static constexpr uint32_t kWidth = 32;
static constexpr uint32_t kHeight = 32;
static constexpr uint32_t kDefaultDepth = 1;
static constexpr uint32_t kDefaultMipLevels = 1;
static constexpr uint32_t kDefaultSampleCount = 1;
static constexpr wgpu::TextureFormat kDefaultTextureFormat =
wgpu::TextureFormat::RGBA8Unorm;
};
TEST_F(ExternalTextureTest, CreateExternalTextureValidation) {
wgpu::TextureDescriptor textureDescriptor = CreateDefaultTextureDescriptor();
wgpu::ExternalTextureDescriptor externalDesc;
externalDesc.format = kDefaultTextureFormat;
// Creating an external texture from a 2D, single-subresource texture should succeed.
{
wgpu::Texture texture = device.CreateTexture(&textureDescriptor);
externalDesc.plane0 = texture.CreateView();
device.CreateExternalTexture(&externalDesc);
}
// Creating an external texture with a mismatched texture view format should fail.
{
textureDescriptor.format = wgpu::TextureFormat::RGBA8Uint;
wgpu::Texture texture = device.CreateTexture(&textureDescriptor);
externalDesc.plane0 = texture.CreateView();
ASSERT_DEVICE_ERROR(device.CreateExternalTexture(&externalDesc));
}
// Creating an external texture from a non-2D texture should fail.
{
textureDescriptor.dimension = wgpu::TextureDimension::e3D;
wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor);
externalDesc.plane0 = internalTexture.CreateView();
ASSERT_DEVICE_ERROR(device.CreateExternalTexture(&externalDesc));
}
// Creating an external texture from a texture with mip count > 1 should fail.
{
textureDescriptor.mipLevelCount = 2;
wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor);
externalDesc.plane0 = internalTexture.CreateView();
ASSERT_DEVICE_ERROR(device.CreateExternalTexture(&externalDesc));
}
// Creating an external texture from a texture without TextureUsage::Sampled should fail.
{
textureDescriptor.mipLevelCount = 2;
wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor);
externalDesc.plane0 = internalTexture.CreateView();
ASSERT_DEVICE_ERROR(device.CreateExternalTexture(&externalDesc));
}
// Creating an external texture with an unsupported format should fail.
{
constexpr wgpu::TextureFormat kUnsupportedFormat = wgpu::TextureFormat::R8Uint;
textureDescriptor.format = kUnsupportedFormat;
wgpu::Texture internalTexture = device.CreateTexture(&textureDescriptor);
externalDesc.plane0 = internalTexture.CreateView();
externalDesc.format = kUnsupportedFormat;
ASSERT_DEVICE_ERROR(device.CreateExternalTexture(&externalDesc));
}
}
} // namespace