mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-16 20:31:20 +00:00
Add releaseMutexKey to ExternalImageAccessDescriptorDXGIKeyedMutex
This allows the client to specify a different release key for the keyed mutex than the default of acquire key + 1. If the release key is the sentinel value of UINT64_MAX, it's set to acquire key + 1. Once Chromium transitions to always specifying the release key, it will be made a required parameter and the default behavior will be removed. Bug: chromium:1213977 Change-Id: I327f7157bb7ff23cf216e43043568ce7c6f38a60 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/53880 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Sunny Sachanandani <sunnyps@chromium.org>
This commit is contained in:
parent
85acca3e09
commit
cabd60d991
@ -84,9 +84,16 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
textureDescriptor.mipLevelCount = mMipLevelCount;
|
textureDescriptor.mipLevelCount = mMipLevelCount;
|
||||||
textureDescriptor.sampleCount = mSampleCount;
|
textureDescriptor.sampleCount = mSampleCount;
|
||||||
|
|
||||||
|
// Set the release key to acquire key + 1 if not set. This allows supporting the old keyed
|
||||||
|
// mutex protocol during the transition to making this a required parameter.
|
||||||
|
ExternalMutexSerial releaseMutexKey =
|
||||||
|
(descriptor->releaseMutexKey != UINT64_MAX)
|
||||||
|
? ExternalMutexSerial(descriptor->releaseMutexKey)
|
||||||
|
: ExternalMutexSerial(descriptor->acquireMutexKey + 1);
|
||||||
|
|
||||||
Ref<TextureBase> texture = backendDevice->CreateExternalTexture(
|
Ref<TextureBase> texture = backendDevice->CreateExternalTexture(
|
||||||
&textureDescriptor, mD3D12Resource, ExternalMutexSerial(descriptor->acquireMutexKey),
|
&textureDescriptor, mD3D12Resource, ExternalMutexSerial(descriptor->acquireMutexKey),
|
||||||
descriptor->isSwapChainTexture, descriptor->isInitialized);
|
releaseMutexKey, descriptor->isSwapChainTexture, descriptor->isInitialized);
|
||||||
return reinterpret_cast<WGPUTexture>(texture.Detach());
|
return reinterpret_cast<WGPUTexture>(texture.Detach());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,12 +453,13 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
Ref<TextureBase> Device::CreateExternalTexture(const TextureDescriptor* descriptor,
|
Ref<TextureBase> Device::CreateExternalTexture(const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture,
|
ComPtr<ID3D12Resource> d3d12Texture,
|
||||||
ExternalMutexSerial acquireMutexKey,
|
ExternalMutexSerial acquireMutexKey,
|
||||||
|
ExternalMutexSerial releaseMutexKey,
|
||||||
bool isSwapChainTexture,
|
bool isSwapChainTexture,
|
||||||
bool isInitialized) {
|
bool isInitialized) {
|
||||||
Ref<Texture> dawnTexture;
|
Ref<Texture> dawnTexture;
|
||||||
if (ConsumedError(
|
if (ConsumedError(Texture::CreateExternalImage(this, descriptor, std::move(d3d12Texture),
|
||||||
Texture::CreateExternalImage(this, descriptor, std::move(d3d12Texture),
|
acquireMutexKey, releaseMutexKey,
|
||||||
acquireMutexKey, isSwapChainTexture, isInitialized),
|
isSwapChainTexture, isInitialized),
|
||||||
&dawnTexture)) {
|
&dawnTexture)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
Ref<TextureBase> CreateExternalTexture(const TextureDescriptor* descriptor,
|
Ref<TextureBase> CreateExternalTexture(const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture,
|
ComPtr<ID3D12Resource> d3d12Texture,
|
||||||
ExternalMutexSerial acquireMutexKey,
|
ExternalMutexSerial acquireMutexKey,
|
||||||
|
ExternalMutexSerial releaseMutexKey,
|
||||||
bool isSwapChainTexture,
|
bool isSwapChainTexture,
|
||||||
bool isInitialized);
|
bool isInitialized);
|
||||||
ResultOrError<ComPtr<IDXGIKeyedMutex>> CreateKeyedMutexForTexture(
|
ResultOrError<ComPtr<IDXGIKeyedMutex>> CreateKeyedMutexForTexture(
|
||||||
|
@ -422,12 +422,14 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
const TextureDescriptor* descriptor,
|
const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture,
|
ComPtr<ID3D12Resource> d3d12Texture,
|
||||||
ExternalMutexSerial acquireMutexKey,
|
ExternalMutexSerial acquireMutexKey,
|
||||||
|
ExternalMutexSerial releaseMutexKey,
|
||||||
bool isSwapChainTexture,
|
bool isSwapChainTexture,
|
||||||
bool isInitialized) {
|
bool isInitialized) {
|
||||||
Ref<Texture> dawnTexture =
|
Ref<Texture> dawnTexture =
|
||||||
AcquireRef(new Texture(device, descriptor, TextureState::OwnedExternal));
|
AcquireRef(new Texture(device, descriptor, TextureState::OwnedExternal));
|
||||||
DAWN_TRY(dawnTexture->InitializeAsExternalTexture(descriptor, std::move(d3d12Texture),
|
DAWN_TRY(dawnTexture->InitializeAsExternalTexture(descriptor, std::move(d3d12Texture),
|
||||||
acquireMutexKey, isSwapChainTexture));
|
acquireMutexKey, releaseMutexKey,
|
||||||
|
isSwapChainTexture));
|
||||||
|
|
||||||
// Importing a multi-planar format must be initialized. This is required because
|
// Importing a multi-planar format must be initialized. This is required because
|
||||||
// a shared multi-planar format cannot be initialized by Dawn.
|
// a shared multi-planar format cannot be initialized by Dawn.
|
||||||
@ -454,6 +456,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor,
|
MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture,
|
ComPtr<ID3D12Resource> d3d12Texture,
|
||||||
ExternalMutexSerial acquireMutexKey,
|
ExternalMutexSerial acquireMutexKey,
|
||||||
|
ExternalMutexSerial releaseMutexKey,
|
||||||
bool isSwapChainTexture) {
|
bool isSwapChainTexture) {
|
||||||
Device* dawnDevice = ToBackend(GetDevice());
|
Device* dawnDevice = ToBackend(GetDevice());
|
||||||
|
|
||||||
@ -464,6 +467,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
"D3D12 acquiring shared mutex"));
|
"D3D12 acquiring shared mutex"));
|
||||||
|
|
||||||
mAcquireMutexKey = acquireMutexKey;
|
mAcquireMutexKey = acquireMutexKey;
|
||||||
|
mReleaseMutexKey = releaseMutexKey;
|
||||||
mDxgiKeyedMutex = std::move(dxgiKeyedMutex);
|
mDxgiKeyedMutex = std::move(dxgiKeyedMutex);
|
||||||
mSwapChainTexture = isSwapChainTexture;
|
mSwapChainTexture = isSwapChainTexture;
|
||||||
|
|
||||||
@ -528,7 +532,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
// When creating the ResourceHeapAllocation, the resource heap is set to nullptr because the
|
// When creating the ResourceHeapAllocation, the resource heap is set to nullptr because the
|
||||||
// texture is owned externally. The texture's owning entity must remain responsible for
|
// texture is owned externally. The texture's owning entity must remain responsible for
|
||||||
// memory management.
|
// memory management.
|
||||||
mResourceAllocation = { info, 0, std::move(d3d12Texture), nullptr };
|
mResourceAllocation = {info, 0, std::move(d3d12Texture), nullptr};
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +573,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
mSwapChainTexture = false;
|
mSwapChainTexture = false;
|
||||||
|
|
||||||
if (mDxgiKeyedMutex != nullptr) {
|
if (mDxgiKeyedMutex != nullptr) {
|
||||||
mDxgiKeyedMutex->ReleaseSync(uint64_t(mAcquireMutexKey) + 1);
|
mDxgiKeyedMutex->ReleaseSync(uint64_t(mReleaseMutexKey));
|
||||||
device->ReleaseKeyedMutexForTexture(std::move(mDxgiKeyedMutex));
|
device->ReleaseKeyedMutexForTexture(std::move(mDxgiKeyedMutex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -788,8 +792,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
// This transitions assume it is a 2D texture
|
// This transitions assume it is a 2D texture
|
||||||
ASSERT(GetDimension() == wgpu::TextureDimension::e2D);
|
ASSERT(GetDimension() == wgpu::TextureDimension::e2D);
|
||||||
|
|
||||||
mSubresourceStateAndDecay.Merge(
|
mSubresourceStateAndDecay.Merge(textureUsages, [&](const SubresourceRange& mergeRange,
|
||||||
textureUsages, [&](const SubresourceRange& mergeRange, StateAndDecay* state,
|
StateAndDecay* state,
|
||||||
wgpu::TextureUsage usage) {
|
wgpu::TextureUsage usage) {
|
||||||
// Skip if this subresource is not used during the current pass
|
// Skip if this subresource is not used during the current pass
|
||||||
if (usage == wgpu::TextureUsage::None) {
|
if (usage == wgpu::TextureUsage::None) {
|
||||||
@ -797,8 +801,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
D3D12_RESOURCE_STATES newState = D3D12TextureUsage(usage, GetFormat());
|
D3D12_RESOURCE_STATES newState = D3D12TextureUsage(usage, GetFormat());
|
||||||
TransitionSubresourceRange(barriers, mergeRange, state, newState,
|
TransitionSubresourceRange(barriers, mergeRange, state, newState, pendingCommandSerial);
|
||||||
pendingCommandSerial);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -869,7 +872,6 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
|
MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
|
||||||
const SubresourceRange& range,
|
const SubresourceRange& range,
|
||||||
TextureBase::ClearValue clearValue) {
|
TextureBase::ClearValue clearValue) {
|
||||||
|
|
||||||
ID3D12GraphicsCommandList* commandList = commandContext->GetCommandList();
|
ID3D12GraphicsCommandList* commandList = commandContext->GetCommandList();
|
||||||
|
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
@ -43,6 +43,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
const TextureDescriptor* descriptor,
|
const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture,
|
ComPtr<ID3D12Resource> d3d12Texture,
|
||||||
ExternalMutexSerial acquireMutexKey,
|
ExternalMutexSerial acquireMutexKey,
|
||||||
|
ExternalMutexSerial releaseMutexKey,
|
||||||
bool isSwapChainTexture,
|
bool isSwapChainTexture,
|
||||||
bool isInitialized);
|
bool isInitialized);
|
||||||
static ResultOrError<Ref<Texture>> Create(Device* device,
|
static ResultOrError<Ref<Texture>> Create(Device* device,
|
||||||
@ -89,6 +90,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
MaybeError InitializeAsExternalTexture(const TextureDescriptor* descriptor,
|
MaybeError InitializeAsExternalTexture(const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture,
|
ComPtr<ID3D12Resource> d3d12Texture,
|
||||||
ExternalMutexSerial acquireMutexKey,
|
ExternalMutexSerial acquireMutexKey,
|
||||||
|
ExternalMutexSerial releaseMutexKey,
|
||||||
bool isSwapChainTexture);
|
bool isSwapChainTexture);
|
||||||
MaybeError InitializeAsSwapChainTexture(ComPtr<ID3D12Resource> d3d12Texture);
|
MaybeError InitializeAsSwapChainTexture(ComPtr<ID3D12Resource> d3d12Texture);
|
||||||
|
|
||||||
@ -123,6 +125,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
bool mSwapChainTexture = false;
|
bool mSwapChainTexture = false;
|
||||||
|
|
||||||
ExternalMutexSerial mAcquireMutexKey = ExternalMutexSerial(0);
|
ExternalMutexSerial mAcquireMutexKey = ExternalMutexSerial(0);
|
||||||
|
ExternalMutexSerial mReleaseMutexKey = ExternalMutexSerial(0);
|
||||||
ComPtr<IDXGIKeyedMutex> mDxgiKeyedMutex;
|
ComPtr<IDXGIKeyedMutex> mDxgiKeyedMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
: ExternalImageAccessDescriptor {
|
: ExternalImageAccessDescriptor {
|
||||||
public:
|
public:
|
||||||
uint64_t acquireMutexKey;
|
uint64_t acquireMutexKey;
|
||||||
|
// Release key will be set to acquireMutexKey + 1 if set to sentinel value UINT64_MAX.
|
||||||
|
uint64_t releaseMutexKey = UINT64_MAX;
|
||||||
bool isSwapChainTexture = false;
|
bool isSwapChainTexture = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user