From ad4a66ec8f18c54a77f82e31310b877968e8a621 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 28 Sep 2020 17:10:24 +0000 Subject: [PATCH] D3D12: Use typed integers for the ExternalMutexSerial This will prevent mixing it up with other serial types in the future. Bug: dawn:442 Change-Id: Ia1ec00572fa268e48349f7d9e39234ec8f5d3953 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28961 Commit-Queue: Corentin Wallez Reviewed-by: Jiawei Shao Reviewed-by: Austin Eng --- src/dawn_native/d3d12/D3D12Backend.cpp | 2 +- src/dawn_native/d3d12/DeviceD3D12.cpp | 2 +- src/dawn_native/d3d12/DeviceD3D12.h | 2 +- src/dawn_native/d3d12/IntegerTypes.h | 3 +++ src/dawn_native/d3d12/TextureD3D12.cpp | 8 ++++---- src/dawn_native/d3d12/TextureD3D12.h | 7 ++++--- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/dawn_native/d3d12/D3D12Backend.cpp b/src/dawn_native/d3d12/D3D12Backend.cpp index 73175faaee..aac8968c31 100644 --- a/src/dawn_native/d3d12/D3D12Backend.cpp +++ b/src/dawn_native/d3d12/D3D12Backend.cpp @@ -64,7 +64,7 @@ namespace dawn_native { namespace d3d12 { const ExternalImageDescriptorDXGISharedHandle* descriptor) { Device* backendDevice = reinterpret_cast(device); Ref texture = backendDevice->WrapSharedHandle( - descriptor, descriptor->sharedHandle, descriptor->acquireMutexKey, + descriptor, descriptor->sharedHandle, ExternalMutexSerial(descriptor->acquireMutexKey), descriptor->isSwapChainTexture); return reinterpret_cast(texture.Detach()); } diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index a26cbb8a0c..5a1f94ef61 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -407,7 +407,7 @@ namespace dawn_native { namespace d3d12 { Ref Device::WrapSharedHandle(const ExternalImageDescriptor* descriptor, HANDLE sharedHandle, - uint64_t acquireMutexKey, + ExternalMutexSerial acquireMutexKey, bool isSwapChainTexture) { Ref dawnTexture; if (ConsumedError(Texture::Create(this, descriptor, sharedHandle, acquireMutexKey, diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index a82dbfe75e..467113226c 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -130,7 +130,7 @@ namespace dawn_native { namespace d3d12 { Ref WrapSharedHandle(const ExternalImageDescriptor* descriptor, HANDLE sharedHandle, - uint64_t acquireMutexKey, + ExternalMutexSerial acquireMutexKey, bool isSwapChainTexture); ResultOrError> CreateKeyedMutexForTexture( ID3D12Resource* d3d12Resource); diff --git a/src/dawn_native/d3d12/IntegerTypes.h b/src/dawn_native/d3d12/IntegerTypes.h index 1c16cfd47a..219f392a19 100644 --- a/src/dawn_native/d3d12/IntegerTypes.h +++ b/src/dawn_native/d3d12/IntegerTypes.h @@ -26,6 +26,9 @@ namespace dawn_native { namespace d3d12 { // BindGroup allocations. using HeapVersionID = TypedInteger; + // The monotonically increasing serial for external D3D12 mutexes imported in Dawn. + using ExternalMutexSerial = TypedInteger; + }} // namespace dawn_native::d3d12 #endif // DAWNNATIVE_D3D12_INTEGERTYPES_H_ diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index 959155cbe7..60f8ef450c 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -389,7 +389,7 @@ namespace dawn_native { namespace d3d12 { ResultOrError> Texture::Create(Device* device, const ExternalImageDescriptor* descriptor, HANDLE sharedHandle, - uint64_t acquireMutexKey, + ExternalMutexSerial acquireMutexKey, bool isSwapChainTexture) { const TextureDescriptor* textureDescriptor = reinterpret_cast(descriptor->cTextureDescriptor); @@ -405,7 +405,7 @@ namespace dawn_native { namespace d3d12 { MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor, HANDLE sharedHandle, - uint64_t acquireMutexKey, + ExternalMutexSerial acquireMutexKey, bool isSwapChainTexture) { Device* dawnDevice = ToBackend(GetDevice()); DAWN_TRY(ValidateTextureDescriptor(dawnDevice, descriptor)); @@ -422,7 +422,7 @@ namespace dawn_native { namespace d3d12 { DAWN_TRY_ASSIGN(dxgiKeyedMutex, dawnDevice->CreateKeyedMutexForTexture(d3d12Resource.Get())); - DAWN_TRY(CheckHRESULT(dxgiKeyedMutex->AcquireSync(acquireMutexKey, INFINITE), + DAWN_TRY(CheckHRESULT(dxgiKeyedMutex->AcquireSync(uint64_t(acquireMutexKey), INFINITE), "D3D12 acquiring shared mutex")); mAcquireMutexKey = acquireMutexKey; @@ -529,7 +529,7 @@ namespace dawn_native { namespace d3d12 { device->DeallocateMemory(mResourceAllocation); if (mDxgiKeyedMutex != nullptr) { - mDxgiKeyedMutex->ReleaseSync(mAcquireMutexKey + 1); + mDxgiKeyedMutex->ReleaseSync(uint64_t(mAcquireMutexKey) + 1); device->ReleaseKeyedMutexForTexture(std::move(mDxgiKeyedMutex)); } } diff --git a/src/dawn_native/d3d12/TextureD3D12.h b/src/dawn_native/d3d12/TextureD3D12.h index 0bebb93ced..728915c336 100644 --- a/src/dawn_native/d3d12/TextureD3D12.h +++ b/src/dawn_native/d3d12/TextureD3D12.h @@ -20,6 +20,7 @@ #include "dawn_native/DawnNative.h" #include "dawn_native/PassResourceUsage.h" +#include "dawn_native/d3d12/IntegerTypes.h" #include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn_native/d3d12/d3d12_platform.h" @@ -40,7 +41,7 @@ namespace dawn_native { namespace d3d12 { static ResultOrError> Create(Device* device, const ExternalImageDescriptor* descriptor, HANDLE sharedHandle, - uint64_t acquireMutexKey, + ExternalMutexSerial acquireMutexKey, bool isSwapChainTexture); Texture(Device* device, const TextureDescriptor* descriptor, @@ -85,7 +86,7 @@ namespace dawn_native { namespace d3d12 { MaybeError InitializeAsInternalTexture(); MaybeError InitializeAsExternalTexture(const TextureDescriptor* descriptor, HANDLE sharedHandle, - uint64_t acquireMutexKey, + ExternalMutexSerial acquireMutexKey, bool isSwapChainTexture); // Dawn API @@ -118,7 +119,7 @@ namespace dawn_native { namespace d3d12 { ResourceHeapAllocation mResourceAllocation; bool mSwapChainTexture = false; - Serial mAcquireMutexKey = 0; + ExternalMutexSerial mAcquireMutexKey = ExternalMutexSerial(0); ComPtr mDxgiKeyedMutex; };