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 <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2020-09-28 17:10:24 +00:00 committed by Commit Bot service account
parent cac14e0067
commit ad4a66ec8f
6 changed files with 14 additions and 10 deletions

View File

@ -64,7 +64,7 @@ namespace dawn_native { namespace d3d12 {
const ExternalImageDescriptorDXGISharedHandle* descriptor) { const ExternalImageDescriptorDXGISharedHandle* descriptor) {
Device* backendDevice = reinterpret_cast<Device*>(device); Device* backendDevice = reinterpret_cast<Device*>(device);
Ref<TextureBase> texture = backendDevice->WrapSharedHandle( Ref<TextureBase> texture = backendDevice->WrapSharedHandle(
descriptor, descriptor->sharedHandle, descriptor->acquireMutexKey, descriptor, descriptor->sharedHandle, ExternalMutexSerial(descriptor->acquireMutexKey),
descriptor->isSwapChainTexture); descriptor->isSwapChainTexture);
return reinterpret_cast<WGPUTexture>(texture.Detach()); return reinterpret_cast<WGPUTexture>(texture.Detach());
} }

View File

@ -407,7 +407,7 @@ namespace dawn_native { namespace d3d12 {
Ref<TextureBase> Device::WrapSharedHandle(const ExternalImageDescriptor* descriptor, Ref<TextureBase> Device::WrapSharedHandle(const ExternalImageDescriptor* descriptor,
HANDLE sharedHandle, HANDLE sharedHandle,
uint64_t acquireMutexKey, ExternalMutexSerial acquireMutexKey,
bool isSwapChainTexture) { bool isSwapChainTexture) {
Ref<TextureBase> dawnTexture; Ref<TextureBase> dawnTexture;
if (ConsumedError(Texture::Create(this, descriptor, sharedHandle, acquireMutexKey, if (ConsumedError(Texture::Create(this, descriptor, sharedHandle, acquireMutexKey,

View File

@ -130,7 +130,7 @@ namespace dawn_native { namespace d3d12 {
Ref<TextureBase> WrapSharedHandle(const ExternalImageDescriptor* descriptor, Ref<TextureBase> WrapSharedHandle(const ExternalImageDescriptor* descriptor,
HANDLE sharedHandle, HANDLE sharedHandle,
uint64_t acquireMutexKey, ExternalMutexSerial acquireMutexKey,
bool isSwapChainTexture); bool isSwapChainTexture);
ResultOrError<ComPtr<IDXGIKeyedMutex>> CreateKeyedMutexForTexture( ResultOrError<ComPtr<IDXGIKeyedMutex>> CreateKeyedMutexForTexture(
ID3D12Resource* d3d12Resource); ID3D12Resource* d3d12Resource);

View File

@ -26,6 +26,9 @@ namespace dawn_native { namespace d3d12 {
// BindGroup allocations. // BindGroup allocations.
using HeapVersionID = TypedInteger<struct HeapVersionIDT, uint64_t>; using HeapVersionID = TypedInteger<struct HeapVersionIDT, uint64_t>;
// The monotonically increasing serial for external D3D12 mutexes imported in Dawn.
using ExternalMutexSerial = TypedInteger<struct ExternalMutexSerialT, uint64_t>;
}} // namespace dawn_native::d3d12 }} // namespace dawn_native::d3d12
#endif // DAWNNATIVE_D3D12_INTEGERTYPES_H_ #endif // DAWNNATIVE_D3D12_INTEGERTYPES_H_

View File

@ -389,7 +389,7 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<Ref<TextureBase>> Texture::Create(Device* device, ResultOrError<Ref<TextureBase>> Texture::Create(Device* device,
const ExternalImageDescriptor* descriptor, const ExternalImageDescriptor* descriptor,
HANDLE sharedHandle, HANDLE sharedHandle,
uint64_t acquireMutexKey, ExternalMutexSerial acquireMutexKey,
bool isSwapChainTexture) { bool isSwapChainTexture) {
const TextureDescriptor* textureDescriptor = const TextureDescriptor* textureDescriptor =
reinterpret_cast<const TextureDescriptor*>(descriptor->cTextureDescriptor); reinterpret_cast<const TextureDescriptor*>(descriptor->cTextureDescriptor);
@ -405,7 +405,7 @@ namespace dawn_native { namespace d3d12 {
MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor, MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor,
HANDLE sharedHandle, HANDLE sharedHandle,
uint64_t acquireMutexKey, ExternalMutexSerial acquireMutexKey,
bool isSwapChainTexture) { bool isSwapChainTexture) {
Device* dawnDevice = ToBackend(GetDevice()); Device* dawnDevice = ToBackend(GetDevice());
DAWN_TRY(ValidateTextureDescriptor(dawnDevice, descriptor)); DAWN_TRY(ValidateTextureDescriptor(dawnDevice, descriptor));
@ -422,7 +422,7 @@ namespace dawn_native { namespace d3d12 {
DAWN_TRY_ASSIGN(dxgiKeyedMutex, DAWN_TRY_ASSIGN(dxgiKeyedMutex,
dawnDevice->CreateKeyedMutexForTexture(d3d12Resource.Get())); dawnDevice->CreateKeyedMutexForTexture(d3d12Resource.Get()));
DAWN_TRY(CheckHRESULT(dxgiKeyedMutex->AcquireSync(acquireMutexKey, INFINITE), DAWN_TRY(CheckHRESULT(dxgiKeyedMutex->AcquireSync(uint64_t(acquireMutexKey), INFINITE),
"D3D12 acquiring shared mutex")); "D3D12 acquiring shared mutex"));
mAcquireMutexKey = acquireMutexKey; mAcquireMutexKey = acquireMutexKey;
@ -529,7 +529,7 @@ namespace dawn_native { namespace d3d12 {
device->DeallocateMemory(mResourceAllocation); device->DeallocateMemory(mResourceAllocation);
if (mDxgiKeyedMutex != nullptr) { if (mDxgiKeyedMutex != nullptr) {
mDxgiKeyedMutex->ReleaseSync(mAcquireMutexKey + 1); mDxgiKeyedMutex->ReleaseSync(uint64_t(mAcquireMutexKey) + 1);
device->ReleaseKeyedMutexForTexture(std::move(mDxgiKeyedMutex)); device->ReleaseKeyedMutexForTexture(std::move(mDxgiKeyedMutex));
} }
} }

View File

@ -20,6 +20,7 @@
#include "dawn_native/DawnNative.h" #include "dawn_native/DawnNative.h"
#include "dawn_native/PassResourceUsage.h" #include "dawn_native/PassResourceUsage.h"
#include "dawn_native/d3d12/IntegerTypes.h"
#include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h" #include "dawn_native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn_native/d3d12/d3d12_platform.h" #include "dawn_native/d3d12/d3d12_platform.h"
@ -40,7 +41,7 @@ namespace dawn_native { namespace d3d12 {
static ResultOrError<Ref<TextureBase>> Create(Device* device, static ResultOrError<Ref<TextureBase>> Create(Device* device,
const ExternalImageDescriptor* descriptor, const ExternalImageDescriptor* descriptor,
HANDLE sharedHandle, HANDLE sharedHandle,
uint64_t acquireMutexKey, ExternalMutexSerial acquireMutexKey,
bool isSwapChainTexture); bool isSwapChainTexture);
Texture(Device* device, Texture(Device* device,
const TextureDescriptor* descriptor, const TextureDescriptor* descriptor,
@ -85,7 +86,7 @@ namespace dawn_native { namespace d3d12 {
MaybeError InitializeAsInternalTexture(); MaybeError InitializeAsInternalTexture();
MaybeError InitializeAsExternalTexture(const TextureDescriptor* descriptor, MaybeError InitializeAsExternalTexture(const TextureDescriptor* descriptor,
HANDLE sharedHandle, HANDLE sharedHandle,
uint64_t acquireMutexKey, ExternalMutexSerial acquireMutexKey,
bool isSwapChainTexture); bool isSwapChainTexture);
// Dawn API // Dawn API
@ -118,7 +119,7 @@ namespace dawn_native { namespace d3d12 {
ResourceHeapAllocation mResourceAllocation; ResourceHeapAllocation mResourceAllocation;
bool mSwapChainTexture = false; bool mSwapChainTexture = false;
Serial mAcquireMutexKey = 0; ExternalMutexSerial mAcquireMutexKey = ExternalMutexSerial(0);
ComPtr<IDXGIKeyedMutex> mDxgiKeyedMutex; ComPtr<IDXGIKeyedMutex> mDxgiKeyedMutex;
}; };