Reland "Making D3D12 accept InternalUsageDescriptors"
This is a reland of 365d40b93a
Original change's description:
> 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>
Bug: dawn:1027, dawn:1052
Change-Id: I0d35cbf4dc1c6dc80e1a5dfb4770a5383ef543fa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/61840
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Juanmi Huertas <juanmihd@chromium.org>
This commit is contained in:
parent
0d6da1072c
commit
633bb68c6b
|
@ -62,7 +62,13 @@ namespace dawn_native { namespace d3d12 {
|
|||
mFormat(descriptor->format),
|
||||
mMipLevelCount(descriptor->mipLevelCount),
|
||||
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(
|
||||
|
@ -84,6 +90,13 @@ namespace dawn_native { namespace d3d12 {
|
|||
textureDescriptor.mipLevelCount = mMipLevelCount;
|
||||
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(
|
||||
&textureDescriptor, mD3D12Resource, ExternalMutexSerial(descriptor->acquireMutexKey),
|
||||
ExternalMutexSerial(descriptor->releaseMutexKey), descriptor->isSwapChainTexture,
|
||||
|
|
|
@ -79,6 +79,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
// Contents of WGPUTextureDescriptor are stored individually since the descriptor
|
||||
// could outlive this image.
|
||||
WGPUTextureUsageFlags mUsage;
|
||||
WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None;
|
||||
WGPUTextureDimension mDimension;
|
||||
WGPUExtent3D mSize;
|
||||
WGPUTextureFormat mFormat;
|
||||
|
|
|
@ -28,6 +28,11 @@ using Microsoft::WRL::ComPtr;
|
|||
namespace {
|
||||
|
||||
class D3D12ResourceTestBase : public DawnTest {
|
||||
protected:
|
||||
std::vector<const char*> GetRequiredExtensions() override {
|
||||
return {"dawn-internal-usages"};
|
||||
}
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
DawnTest::SetUp();
|
||||
|
@ -161,11 +166,28 @@ TEST_P(D3D12SharedHandleValidation, Success) {
|
|||
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) {
|
||||
DAWN_TEST_UNSUPPORTED_IF(UsesWire());
|
||||
|
||||
wgpu::ChainedStruct chainedDescriptor;
|
||||
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
|
||||
baseDawnDescriptor.nextInChain = &chainedDescriptor;
|
||||
|
||||
wgpu::Texture texture;
|
||||
|
|
|
@ -114,6 +114,11 @@ namespace {
|
|||
} // anonymous namespace
|
||||
|
||||
class EGLImageTestBase : public DawnTest {
|
||||
protected:
|
||||
std::vector<const char*> GetRequiredExtensions() override {
|
||||
return {"dawn-internal-usages"};
|
||||
}
|
||||
|
||||
public:
|
||||
ScopedEGLImage CreateEGLImage(uint32_t width,
|
||||
uint32_t height,
|
||||
|
@ -177,15 +182,30 @@ TEST_P(EGLImageValidationTests, Success) {
|
|||
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) {
|
||||
DAWN_TEST_UNSUPPORTED_IF(UsesWire());
|
||||
|
||||
wgpu::ChainedStruct chainedDescriptor;
|
||||
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
|
||||
descriptor.nextInChain = &chainedDescriptor;
|
||||
|
||||
ScopedEGLImage image = CreateDefaultEGLImage();
|
||||
ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapEGLImage(&descriptor, image.getImage()));
|
||||
|
||||
ASSERT_EQ(texture.Get(), nullptr);
|
||||
}
|
||||
|
||||
|
@ -291,6 +311,12 @@ class EGLImageUsageTests : public EGLImageTestBase {
|
|||
textureDescriptor.sampleCount = 1;
|
||||
textureDescriptor.mipLevelCount = 1;
|
||||
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);
|
||||
ASSERT_NE(eglImageTexture, nullptr);
|
||||
|
||||
|
|
|
@ -33,6 +33,11 @@ namespace dawn_native { namespace vulkan {
|
|||
namespace {
|
||||
|
||||
class VulkanImageWrappingTestBase : public DawnTest {
|
||||
protected:
|
||||
std::vector<const char*> GetRequiredExtensions() override {
|
||||
return {"dawn-internal-usages"};
|
||||
}
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
DAWN_TEST_UNSUPPORTED_IF(UsesWire());
|
||||
|
@ -180,9 +185,23 @@ namespace dawn_native { namespace vulkan {
|
|||
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) {
|
||||
wgpu::ChainedStruct chainedDescriptor;
|
||||
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
|
||||
defaultDescriptor.nextInChain = &chainedDescriptor;
|
||||
|
||||
ASSERT_DEVICE_ERROR(wgpu::Texture texture =
|
||||
|
|
|
@ -30,6 +30,11 @@ namespace dawn_native { namespace vulkan {
|
|||
namespace {
|
||||
|
||||
class VulkanImageWrappingTestBase : public DawnTest {
|
||||
protected:
|
||||
std::vector<const char*> GetRequiredExtensions() override {
|
||||
return {"dawn-internal-usages"};
|
||||
}
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
DawnTest::SetUp();
|
||||
|
@ -265,9 +270,24 @@ namespace dawn_native { namespace vulkan {
|
|||
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) {
|
||||
wgpu::ChainedStruct chainedDescriptor;
|
||||
chainedDescriptor.sType = wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel;
|
||||
defaultDescriptor.nextInChain = &chainedDescriptor;
|
||||
|
||||
ASSERT_DEVICE_ERROR(wgpu::Texture texture = WrapVulkanImage(
|
||||
|
|
Loading…
Reference in New Issue