D3D12: Pass usage to ProduceTexture
Allow external images to specify all allowed texture usages which will be checked by ProduceTexture. This avoids needing to assume the usage between multiple calls to ProduceTexture is always the same. Bug=dawn:625 Change-Id: I9fdb59af23e6c160e939ab1c51de03542248c0c8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/44260 Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
0702b70469
commit
2f72aeda4f
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include "dawn_native/D3D12Backend.h"
|
||||
|
||||
#include "common/Log.h"
|
||||
#include "common/Math.h"
|
||||
#include "common/SwapChainUtils.h"
|
||||
#include "dawn_native/d3d12/DeviceD3D12.h"
|
||||
#include "dawn_native/d3d12/NativeSwapChainImplD3D12.h"
|
||||
|
@ -68,8 +70,14 @@ namespace dawn_native { namespace d3d12 {
|
|||
const ExternalImageAccessDescriptorDXGIKeyedMutex* descriptor) {
|
||||
Device* backendDevice = reinterpret_cast<Device*>(device);
|
||||
|
||||
// Ensure the texture usage is allowed
|
||||
if (!IsSubset(descriptor->usage, mUsage)) {
|
||||
dawn::ErrorLog() << "Texture usage is not valid for external image";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TextureDescriptor textureDescriptor = {};
|
||||
textureDescriptor.usage = static_cast<wgpu::TextureUsage>(mUsage);
|
||||
textureDescriptor.usage = static_cast<wgpu::TextureUsage>(descriptor->usage);
|
||||
textureDescriptor.dimension = static_cast<wgpu::TextureDimension>(mDimension);
|
||||
textureDescriptor.size = {mSize.width, mSize.height, mSize.depth};
|
||||
textureDescriptor.format = static_cast<wgpu::TextureFormat>(mFormat);
|
||||
|
@ -149,6 +157,7 @@ namespace dawn_native { namespace d3d12 {
|
|||
externalAccessDesc.isInitialized = descriptor->isInitialized;
|
||||
externalAccessDesc.isSwapChainTexture = descriptor->isSwapChainTexture;
|
||||
externalAccessDesc.acquireMutexKey = descriptor->acquireMutexKey;
|
||||
externalAccessDesc.usage = descriptor->cTextureDescriptor->usage;
|
||||
|
||||
return externalImage->ProduceTexture(device, &externalAccessDesc);
|
||||
}
|
||||
|
|
|
@ -231,6 +231,7 @@ namespace dawn_native {
|
|||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptor {
|
||||
public:
|
||||
bool isInitialized; // Whether the texture is initialized on import
|
||||
WGPUTextureUsageFlags usage;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfo {
|
||||
|
|
|
@ -122,6 +122,7 @@ namespace {
|
|||
|
||||
dawn_native::d3d12::ExternalImageAccessDescriptorDXGIKeyedMutex externalAccessDesc;
|
||||
externalAccessDesc.acquireMutexKey = 0;
|
||||
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(dawnDesc->usage);
|
||||
|
||||
*dawnTexture = wgpu::Texture::Acquire(
|
||||
externalImage->ProduceTexture(device.Get(), &externalAccessDesc));
|
||||
|
@ -361,6 +362,7 @@ class D3D12SharedHandleUsageTests : public D3D12ResourceTestBase {
|
|||
dawn_native::d3d12::ExternalImageAccessDescriptorDXGIKeyedMutex externalAccessDesc;
|
||||
externalAccessDesc.acquireMutexKey = 1;
|
||||
externalAccessDesc.isInitialized = isInitialized;
|
||||
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(dawnDescriptor->usage);
|
||||
|
||||
*dawnTextureOut = wgpu::Texture::Acquire(
|
||||
externalImage->ProduceTexture(device.Get(), &externalAccessDesc));
|
||||
|
@ -573,6 +575,7 @@ TEST_P(D3D12SharedHandleUsageTests, ReuseExternalImage) {
|
|||
dawn_native::d3d12::ExternalImageAccessDescriptorDXGIKeyedMutex externalAccessDesc;
|
||||
externalAccessDesc.acquireMutexKey = 1;
|
||||
externalAccessDesc.isInitialized = true;
|
||||
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(baseDawnDescriptor.usage);
|
||||
|
||||
texture =
|
||||
wgpu::Texture::Acquire(externalImage->ProduceTexture(device.Get(), &externalAccessDesc));
|
||||
|
@ -590,5 +593,31 @@ TEST_P(D3D12SharedHandleUsageTests, ReuseExternalImage) {
|
|||
}
|
||||
}
|
||||
|
||||
// Produce a new texture with a usage not specified in the external image.
|
||||
TEST_P(D3D12SharedHandleUsageTests, ExternalImageUsage) {
|
||||
DAWN_SKIP_TEST_IF(UsesWire());
|
||||
|
||||
dawn_native::d3d12::ExternalImageAccessDescriptorDXGIKeyedMutex externalAccessDesc;
|
||||
externalAccessDesc.acquireMutexKey = 1;
|
||||
externalAccessDesc.isInitialized = true;
|
||||
|
||||
wgpu::Texture texture;
|
||||
ComPtr<ID3D11Texture2D> d3d11Texture;
|
||||
std::unique_ptr<dawn_native::d3d12::ExternalImageDXGI> externalImage;
|
||||
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
|
||||
&externalImage);
|
||||
ASSERT_NE(texture.Get(), nullptr);
|
||||
|
||||
externalAccessDesc.usage = WGPUTextureUsage_Storage;
|
||||
texture =
|
||||
wgpu::Texture::Acquire(externalImage->ProduceTexture(device.Get(), &externalAccessDesc));
|
||||
ASSERT_EQ(texture.Get(), nullptr);
|
||||
|
||||
externalAccessDesc.usage = WGPUTextureUsage_Sampled;
|
||||
texture =
|
||||
wgpu::Texture::Acquire(externalImage->ProduceTexture(device.Get(), &externalAccessDesc));
|
||||
ASSERT_NE(texture.Get(), nullptr);
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(D3D12SharedHandleValidation, D3D12Backend());
|
||||
DAWN_INSTANTIATE_TEST(D3D12SharedHandleUsageTests, D3D12Backend());
|
||||
|
|
|
@ -213,6 +213,7 @@ namespace {
|
|||
dawn_native::d3d12::ExternalImageAccessDescriptorDXGIKeyedMutex externalAccessDesc;
|
||||
externalAccessDesc.acquireMutexKey = 1;
|
||||
externalAccessDesc.isInitialized = true;
|
||||
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(textureDesc.usage);
|
||||
|
||||
*dawnTextureOut = wgpu::Texture::Acquire(
|
||||
externalImage->ProduceTexture(device.Get(), &externalAccessDesc));
|
||||
|
|
Loading…
Reference in New Issue