Making D3D12 accept InternalUsageDescriptors

This is a follow up from two previous CLs,
https://dawn-review.googlesource.com/c/dawn/+/58440
and
https://dawn-review.googlesource.com/c/dawn/+/58140

This CL adds in the D3D12Backend the possibility to use Dawn Texture
Internal Usage Descriptor, and adds a series of tests to validate it.

Change-Id: I94f6b39153b60ec8af61bda22d41a865898da613
Bug: dawn:1027, dawn:1052
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/61520
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Juanmi 2021-08-12 15:35:48 +00:00 committed by Dawn LUCI CQ
parent 1935043d35
commit 365d40b93a
6 changed files with 107 additions and 6 deletions

View File

@ -62,7 +62,13 @@ namespace dawn_native { namespace d3d12 {
mFormat(descriptor->format), mFormat(descriptor->format),
mMipLevelCount(descriptor->mipLevelCount), mMipLevelCount(descriptor->mipLevelCount),
mSampleCount(descriptor->sampleCount) { mSampleCount(descriptor->sampleCount) {
ASSERT(descriptor->nextInChain == nullptr); ASSERT(!descriptor->nextInChain ||
descriptor->nextInChain->sType == WGPUSType_DawnTextureInternalUsageDescriptor);
if (descriptor->nextInChain) {
mUsageInternal = reinterpret_cast<const WGPUDawnTextureInternalUsageDescriptor*>(
descriptor->nextInChain)
->internalUsage;
}
} }
WGPUTexture ExternalImageDXGI::ProduceTexture( WGPUTexture ExternalImageDXGI::ProduceTexture(
@ -84,6 +90,13 @@ namespace dawn_native { namespace d3d12 {
textureDescriptor.mipLevelCount = mMipLevelCount; textureDescriptor.mipLevelCount = mMipLevelCount;
textureDescriptor.sampleCount = mSampleCount; textureDescriptor.sampleCount = mSampleCount;
DawnTextureInternalUsageDescriptor internalDesc = {};
if (mUsageInternal) {
textureDescriptor.nextInChain = &internalDesc;
internalDesc.internalUsage = static_cast<wgpu::TextureUsage>(mUsageInternal);
internalDesc.sType = wgpu::SType::DawnTextureInternalUsageDescriptor;
}
Ref<TextureBase> texture = backendDevice->CreateExternalTexture( Ref<TextureBase> texture = backendDevice->CreateExternalTexture(
&textureDescriptor, mD3D12Resource, ExternalMutexSerial(descriptor->acquireMutexKey), &textureDescriptor, mD3D12Resource, ExternalMutexSerial(descriptor->acquireMutexKey),
ExternalMutexSerial(descriptor->releaseMutexKey), descriptor->isSwapChainTexture, ExternalMutexSerial(descriptor->releaseMutexKey), descriptor->isSwapChainTexture,

View File

@ -79,6 +79,7 @@ namespace dawn_native { namespace d3d12 {
// Contents of WGPUTextureDescriptor are stored individually since the descriptor // Contents of WGPUTextureDescriptor are stored individually since the descriptor
// could outlive this image. // could outlive this image.
WGPUTextureUsageFlags mUsage; WGPUTextureUsageFlags mUsage;
WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None;
WGPUTextureDimension mDimension; WGPUTextureDimension mDimension;
WGPUExtent3D mSize; WGPUExtent3D mSize;
WGPUTextureFormat mFormat; WGPUTextureFormat mFormat;

View File

@ -28,6 +28,11 @@ using Microsoft::WRL::ComPtr;
namespace { namespace {
class D3D12ResourceTestBase : public DawnTest { class D3D12ResourceTestBase : public DawnTest {
protected:
std::vector<const char*> GetRequiredExtensions() override {
return {"dawn-internal-usages"};
}
public: public:
void SetUp() override { void SetUp() override {
DawnTest::SetUp(); DawnTest::SetUp();
@ -161,11 +166,28 @@ TEST_P(D3D12SharedHandleValidation, Success) {
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
} }
// Test an error occurs if the texture descriptor is invalid // Test a successful wrapping of an D3D12Resource with DawnTextureInternalUsageDescriptor
TEST_P(D3D12SharedHandleValidation, SuccessWithInternalUsageDescriptor) {
DAWN_TEST_UNSUPPORTED_IF(UsesWire());
wgpu::DawnTextureInternalUsageDescriptor internalDesc = {};
baseDawnDescriptor.nextInChain = &internalDesc;
internalDesc.internalUsage = wgpu::TextureUsage::CopySrc;
internalDesc.sType = wgpu::SType::DawnTextureInternalUsageDescriptor;
wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture);
ASSERT_NE(texture.Get(), nullptr);
}
// Test an error occurs if an invalid sType is the nextInChain
TEST_P(D3D12SharedHandleValidation, InvalidTextureDescriptor) { TEST_P(D3D12SharedHandleValidation, InvalidTextureDescriptor) {
DAWN_TEST_UNSUPPORTED_IF(UsesWire()); DAWN_TEST_UNSUPPORTED_IF(UsesWire());
wgpu::ChainedStruct chainedDescriptor; wgpu::ChainedStruct chainedDescriptor;
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
baseDawnDescriptor.nextInChain = &chainedDescriptor; baseDawnDescriptor.nextInChain = &chainedDescriptor;
wgpu::Texture texture; wgpu::Texture texture;

View File

@ -114,6 +114,11 @@ namespace {
} // anonymous namespace } // anonymous namespace
class EGLImageTestBase : public DawnTest { class EGLImageTestBase : public DawnTest {
protected:
std::vector<const char*> GetRequiredExtensions() override {
return {"dawn-internal-usages"};
}
public: public:
ScopedEGLImage CreateEGLImage(uint32_t width, ScopedEGLImage CreateEGLImage(uint32_t width,
uint32_t height, uint32_t height,
@ -177,15 +182,30 @@ TEST_P(EGLImageValidationTests, Success) {
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
} }
// Test an error occurs if the texture descriptor is invalid // Test a successful wrapping of an EGLImage in a texture with DawnTextureInternalUsageDescriptor
TEST_P(EGLImageValidationTests, SuccessWithInternalUsageDescriptor) {
DAWN_TEST_UNSUPPORTED_IF(UsesWire());
wgpu::DawnTextureInternalUsageDescriptor internalDesc = {};
descriptor.nextInChain = &internalDesc;
internalDesc.internalUsage = wgpu::TextureUsage::CopySrc;
internalDesc.sType = wgpu::SType::DawnTextureInternalUsageDescriptor;
ScopedEGLImage image = CreateDefaultEGLImage();
wgpu::Texture texture = WrapEGLImage(&descriptor, image.getImage());
ASSERT_NE(texture.Get(), nullptr);
}
// Test an error occurs if an invalid sType is the nextInChain
TEST_P(EGLImageValidationTests, InvalidTextureDescriptor) { TEST_P(EGLImageValidationTests, InvalidTextureDescriptor) {
DAWN_TEST_UNSUPPORTED_IF(UsesWire()); DAWN_TEST_UNSUPPORTED_IF(UsesWire());
wgpu::ChainedStruct chainedDescriptor; wgpu::ChainedStruct chainedDescriptor;
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
descriptor.nextInChain = &chainedDescriptor; descriptor.nextInChain = &chainedDescriptor;
ScopedEGLImage image = CreateDefaultEGLImage(); ScopedEGLImage image = CreateDefaultEGLImage();
ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapEGLImage(&descriptor, image.getImage())); ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapEGLImage(&descriptor, image.getImage()));
ASSERT_EQ(texture.Get(), nullptr); ASSERT_EQ(texture.Get(), nullptr);
} }
@ -291,6 +311,12 @@ class EGLImageUsageTests : public EGLImageTestBase {
textureDescriptor.sampleCount = 1; textureDescriptor.sampleCount = 1;
textureDescriptor.mipLevelCount = 1; textureDescriptor.mipLevelCount = 1;
textureDescriptor.usage = wgpu::TextureUsage::RenderAttachment; textureDescriptor.usage = wgpu::TextureUsage::RenderAttachment;
wgpu::DawnTextureInternalUsageDescriptor internalDesc = {};
textureDescriptor.nextInChain = &internalDesc;
internalDesc.internalUsage = wgpu::TextureUsage::CopySrc;
internalDesc.sType = wgpu::SType::DawnTextureInternalUsageDescriptor;
wgpu::Texture eglImageTexture = WrapEGLImage(&textureDescriptor, eglImage); wgpu::Texture eglImageTexture = WrapEGLImage(&textureDescriptor, eglImage);
ASSERT_NE(eglImageTexture, nullptr); ASSERT_NE(eglImageTexture, nullptr);

View File

@ -33,6 +33,11 @@ namespace dawn_native { namespace vulkan {
namespace { namespace {
class VulkanImageWrappingTestBase : public DawnTest { class VulkanImageWrappingTestBase : public DawnTest {
protected:
std::vector<const char*> GetRequiredExtensions() override {
return {"dawn-internal-usages"};
}
public: public:
void SetUp() override { void SetUp() override {
DAWN_TEST_UNSUPPORTED_IF(UsesWire()); DAWN_TEST_UNSUPPORTED_IF(UsesWire());
@ -180,10 +185,24 @@ namespace dawn_native { namespace vulkan {
IgnoreSignalSemaphore(texture); IgnoreSignalSemaphore(texture);
} }
// Test an error occurs if the texture descriptor is invalid // Test no error occurs if the import is valid with DawnTextureInternalUsageDescriptor
TEST_P(VulkanImageWrappingValidationTests, SuccessfulImportWithInternalUsageDescriptor) {
wgpu::DawnTextureInternalUsageDescriptor internalDesc = {};
defaultDescriptor.nextInChain = &internalDesc;
internalDesc.internalUsage = wgpu::TextureUsage::CopySrc;
internalDesc.sType = wgpu::SType::DawnTextureInternalUsageDescriptor;
wgpu::Texture texture = WrapVulkanImage(device, &defaultDescriptor, defaultFd,
defaultStride, defaultModifier, {}, true, true);
EXPECT_NE(texture.Get(), nullptr);
IgnoreSignalSemaphore(texture);
}
// Test an error occurs if an invalid sType is the nextInChain
TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) { TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) {
wgpu::ChainedStruct chainedDescriptor; wgpu::ChainedStruct chainedDescriptor;
defaultDescriptor.nextInChain = &chainedDescriptor; chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
descriptor.nextInChain = &chainedDescriptor;
ASSERT_DEVICE_ERROR(wgpu::Texture texture = ASSERT_DEVICE_ERROR(wgpu::Texture texture =
WrapVulkanImage(device, &defaultDescriptor, defaultFd, WrapVulkanImage(device, &defaultDescriptor, defaultFd,

View File

@ -30,6 +30,11 @@ namespace dawn_native { namespace vulkan {
namespace { namespace {
class VulkanImageWrappingTestBase : public DawnTest { class VulkanImageWrappingTestBase : public DawnTest {
protected:
std::vector<const char*> GetRequiredExtensions() override {
return {"dawn-internal-usages"};
}
public: public:
void SetUp() override { void SetUp() override {
DawnTest::SetUp(); DawnTest::SetUp();
@ -265,9 +270,24 @@ namespace dawn_native { namespace vulkan {
IgnoreSignalSemaphore(texture); IgnoreSignalSemaphore(texture);
} }
// Test an error occurs if the texture descriptor is invalid // Test no error occurs if the import is valid with DawnTextureInternalUsageDescriptor
TEST_P(VulkanImageWrappingValidationTests, SuccessfulImportWithInternalUsageDescriptor) {
wgpu::DawnTextureInternalUsageDescriptor internalDesc = {};
defaultDescriptor.nextInChain = &internalDesc;
internalDesc.internalUsage = wgpu::TextureUsage::CopySrc;
internalDesc.sType = wgpu::SType::DawnTextureInternalUsageDescriptor;
wgpu::Texture texture =
WrapVulkanImage(device, &defaultDescriptor, defaultFd, defaultAllocationSize,
defaultMemoryTypeIndex, {}, true, true);
EXPECT_NE(texture.Get(), nullptr);
IgnoreSignalSemaphore(texture);
}
// Test an error occurs if an invalid sType is the nextInChain
TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) { TEST_P(VulkanImageWrappingValidationTests, InvalidTextureDescriptor) {
wgpu::ChainedStruct chainedDescriptor; wgpu::ChainedStruct chainedDescriptor;
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
defaultDescriptor.nextInChain = &chainedDescriptor; defaultDescriptor.nextInChain = &chainedDescriptor;
ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage( ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(