mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-23 23:13:46 +00:00
Call ID3D12SharingContract::Present on WebGPU swap buffer destroy
In PIX's D3D12-only mode, there is no way to determine frame boundaries for WebGPU since Dawn does not manage DXGI swap chains. Without assistance, PIX will wait forever for a present that never happens. If we know we're dealing with a swapbuffer texture, inform PIX we've "presented" the texture so it can determine frame boundaries and use the texture's contents for the UI. Bug: dawn:364 Change-Id: I7eb628c460e1e7c446ad91b29b03dd7b54545afb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/18060 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
This commit is contained in:
parent
4da46462d7
commit
c602c86907
@ -62,7 +62,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
const ExternalImageDescriptorDXGISharedHandle* descriptor) {
|
const ExternalImageDescriptorDXGISharedHandle* descriptor) {
|
||||||
Device* backendDevice = reinterpret_cast<Device*>(device);
|
Device* backendDevice = reinterpret_cast<Device*>(device);
|
||||||
TextureBase* texture = backendDevice->WrapSharedHandle(descriptor, descriptor->sharedHandle,
|
TextureBase* texture = backendDevice->WrapSharedHandle(descriptor, descriptor->sharedHandle,
|
||||||
descriptor->acquireMutexKey);
|
descriptor->acquireMutexKey,
|
||||||
|
descriptor->isSwapChainTexture);
|
||||||
return reinterpret_cast<WGPUTexture>(texture);
|
return reinterpret_cast<WGPUTexture>(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,10 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
CheckHRESULT(mD3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)),
|
CheckHRESULT(mD3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)),
|
||||||
"D3D12 create command queue"));
|
"D3D12 create command queue"));
|
||||||
|
|
||||||
|
// If PIX is not attached, the QueryInterface fails. Hence, no need to check the return
|
||||||
|
// value.
|
||||||
|
mCommandQueue.As(&mD3d12SharingContract);
|
||||||
|
|
||||||
DAWN_TRY(CheckHRESULT(mD3d12Device->CreateFence(mLastSubmittedSerial, D3D12_FENCE_FLAG_NONE,
|
DAWN_TRY(CheckHRESULT(mD3d12Device->CreateFence(mLastSubmittedSerial, D3D12_FENCE_FLAG_NONE,
|
||||||
IID_PPV_ARGS(&mFence)),
|
IID_PPV_ARGS(&mFence)),
|
||||||
"D3D12 create fence"));
|
"D3D12 create fence"));
|
||||||
@ -124,6 +128,10 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
return mCommandQueue;
|
return mCommandQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ID3D12SharingContract* Device::GetSharingContract() const {
|
||||||
|
return mD3d12SharingContract.Get();
|
||||||
|
}
|
||||||
|
|
||||||
ComPtr<ID3D12CommandSignature> Device::GetDispatchIndirectSignature() const {
|
ComPtr<ID3D12CommandSignature> Device::GetDispatchIndirectSignature() const {
|
||||||
return mDispatchIndirectSignature;
|
return mDispatchIndirectSignature;
|
||||||
}
|
}
|
||||||
@ -322,9 +330,11 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
TextureBase* Device::WrapSharedHandle(const ExternalImageDescriptor* descriptor,
|
TextureBase* Device::WrapSharedHandle(const ExternalImageDescriptor* descriptor,
|
||||||
HANDLE sharedHandle,
|
HANDLE sharedHandle,
|
||||||
uint64_t acquireMutexKey) {
|
uint64_t acquireMutexKey,
|
||||||
|
bool isSwapChainTexture) {
|
||||||
TextureBase* dawnTexture;
|
TextureBase* dawnTexture;
|
||||||
if (ConsumedError(Texture::Create(this, descriptor, sharedHandle, acquireMutexKey),
|
if (ConsumedError(Texture::Create(this, descriptor, sharedHandle, acquireMutexKey,
|
||||||
|
isSwapChainTexture),
|
||||||
&dawnTexture))
|
&dawnTexture))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
ComPtr<ID3D12Device> GetD3D12Device() const;
|
ComPtr<ID3D12Device> GetD3D12Device() const;
|
||||||
ComPtr<ID3D12CommandQueue> GetCommandQueue() const;
|
ComPtr<ID3D12CommandQueue> GetCommandQueue() const;
|
||||||
|
ID3D12SharingContract* GetSharingContract() const;
|
||||||
|
|
||||||
ComPtr<ID3D12CommandSignature> GetDispatchIndirectSignature() const;
|
ComPtr<ID3D12CommandSignature> GetDispatchIndirectSignature() const;
|
||||||
ComPtr<ID3D12CommandSignature> GetDrawIndirectSignature() const;
|
ComPtr<ID3D12CommandSignature> GetDrawIndirectSignature() const;
|
||||||
@ -102,7 +103,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
TextureBase* WrapSharedHandle(const ExternalImageDescriptor* descriptor,
|
TextureBase* WrapSharedHandle(const ExternalImageDescriptor* descriptor,
|
||||||
HANDLE sharedHandle,
|
HANDLE sharedHandle,
|
||||||
uint64_t acquireMutexKey);
|
uint64_t acquireMutexKey,
|
||||||
|
bool isSwapChainTexture);
|
||||||
ResultOrError<ComPtr<IDXGIKeyedMutex>> CreateKeyedMutexForTexture(
|
ResultOrError<ComPtr<IDXGIKeyedMutex>> CreateKeyedMutexForTexture(
|
||||||
ID3D12Resource* d3d12Resource);
|
ID3D12Resource* d3d12Resource);
|
||||||
void ReleaseKeyedMutexForTexture(ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex);
|
void ReleaseKeyedMutexForTexture(ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex);
|
||||||
@ -146,6 +148,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
ComPtr<ID3D12Device> mD3d12Device; // Device is owned by adapter and will not be outlived.
|
ComPtr<ID3D12Device> mD3d12Device; // Device is owned by adapter and will not be outlived.
|
||||||
ComPtr<ID3D12CommandQueue> mCommandQueue;
|
ComPtr<ID3D12CommandQueue> mCommandQueue;
|
||||||
|
ComPtr<ID3D12SharingContract> mD3d12SharingContract;
|
||||||
|
|
||||||
// 11on12 device and device context corresponding to mCommandQueue
|
// 11on12 device and device context corresponding to mCommandQueue
|
||||||
ComPtr<ID3D11On12Device> mD3d11On12Device;
|
ComPtr<ID3D11On12Device> mD3d11On12Device;
|
||||||
|
@ -284,14 +284,15 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
ResultOrError<TextureBase*> Texture::Create(Device* device,
|
ResultOrError<TextureBase*> Texture::Create(Device* device,
|
||||||
const ExternalImageDescriptor* descriptor,
|
const ExternalImageDescriptor* descriptor,
|
||||||
HANDLE sharedHandle,
|
HANDLE sharedHandle,
|
||||||
uint64_t acquireMutexKey) {
|
uint64_t acquireMutexKey,
|
||||||
|
bool isSwapChainTexture) {
|
||||||
const TextureDescriptor* textureDescriptor =
|
const TextureDescriptor* textureDescriptor =
|
||||||
reinterpret_cast<const TextureDescriptor*>(descriptor->cTextureDescriptor);
|
reinterpret_cast<const TextureDescriptor*>(descriptor->cTextureDescriptor);
|
||||||
|
|
||||||
Ref<Texture> dawnTexture =
|
Ref<Texture> dawnTexture =
|
||||||
AcquireRef(new Texture(device, textureDescriptor, TextureState::OwnedExternal));
|
AcquireRef(new Texture(device, textureDescriptor, TextureState::OwnedExternal));
|
||||||
DAWN_TRY(dawnTexture->InitializeAsExternalTexture(textureDescriptor, sharedHandle,
|
DAWN_TRY(dawnTexture->InitializeAsExternalTexture(textureDescriptor, sharedHandle,
|
||||||
acquireMutexKey));
|
acquireMutexKey, isSwapChainTexture));
|
||||||
|
|
||||||
dawnTexture->SetIsSubresourceContentInitialized(descriptor->isCleared, 0,
|
dawnTexture->SetIsSubresourceContentInitialized(descriptor->isCleared, 0,
|
||||||
textureDescriptor->mipLevelCount, 0,
|
textureDescriptor->mipLevelCount, 0,
|
||||||
@ -301,7 +302,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor,
|
MaybeError Texture::InitializeAsExternalTexture(const TextureDescriptor* descriptor,
|
||||||
HANDLE sharedHandle,
|
HANDLE sharedHandle,
|
||||||
uint64_t acquireMutexKey) {
|
uint64_t acquireMutexKey,
|
||||||
|
bool isSwapChainTexture) {
|
||||||
Device* dawnDevice = ToBackend(GetDevice());
|
Device* dawnDevice = ToBackend(GetDevice());
|
||||||
DAWN_TRY(ValidateTextureDescriptor(dawnDevice, descriptor));
|
DAWN_TRY(ValidateTextureDescriptor(dawnDevice, descriptor));
|
||||||
DAWN_TRY(ValidateTextureDescriptorCanBeWrapped(descriptor));
|
DAWN_TRY(ValidateTextureDescriptorCanBeWrapped(descriptor));
|
||||||
@ -322,6 +324,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
mAcquireMutexKey = acquireMutexKey;
|
mAcquireMutexKey = acquireMutexKey;
|
||||||
mDxgiKeyedMutex = std::move(dxgiKeyedMutex);
|
mDxgiKeyedMutex = std::move(dxgiKeyedMutex);
|
||||||
|
mSwapChainTexture = isSwapChainTexture;
|
||||||
|
|
||||||
AllocationInfo info;
|
AllocationInfo info;
|
||||||
info.mMethod = AllocationMethod::kExternal;
|
info.mMethod = AllocationMethod::kExternal;
|
||||||
@ -391,6 +394,20 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
void Texture::DestroyImpl() {
|
void Texture::DestroyImpl() {
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
|
||||||
|
// In PIX's D3D12-only mode, there is no way to determine frame boundaries
|
||||||
|
// for WebGPU since Dawn does not manage DXGI swap chains. Without assistance,
|
||||||
|
// PIX will wait forever for a present that never happens.
|
||||||
|
// If we know we're dealing with a swapbuffer texture, inform PIX we've
|
||||||
|
// "presented" the texture so it can determine frame boundaries and use its
|
||||||
|
// contents for the UI.
|
||||||
|
if (mSwapChainTexture) {
|
||||||
|
ID3D12SharingContract* d3dSharingContract = device->GetSharingContract();
|
||||||
|
if (d3dSharingContract != nullptr) {
|
||||||
|
d3dSharingContract->Present(mResourceAllocation.GetD3D12Resource().Get(), 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
device->DeallocateMemory(mResourceAllocation);
|
device->DeallocateMemory(mResourceAllocation);
|
||||||
|
|
||||||
if (mDxgiKeyedMutex != nullptr) {
|
if (mDxgiKeyedMutex != nullptr) {
|
||||||
|
@ -39,7 +39,8 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
static ResultOrError<TextureBase*> Create(Device* device,
|
static ResultOrError<TextureBase*> Create(Device* device,
|
||||||
const ExternalImageDescriptor* descriptor,
|
const ExternalImageDescriptor* descriptor,
|
||||||
HANDLE sharedHandle,
|
HANDLE sharedHandle,
|
||||||
uint64_t acquireMutexKey);
|
uint64_t acquireMutexKey,
|
||||||
|
bool isSwapChainTexture);
|
||||||
Texture(Device* device,
|
Texture(Device* device,
|
||||||
const TextureDescriptor* descriptor,
|
const TextureDescriptor* descriptor,
|
||||||
ComPtr<ID3D12Resource> d3d12Texture);
|
ComPtr<ID3D12Resource> d3d12Texture);
|
||||||
@ -75,7 +76,8 @@ 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);
|
uint64_t acquireMutexKey,
|
||||||
|
bool isSwapChainTexture);
|
||||||
|
|
||||||
// Dawn API
|
// Dawn API
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
@ -100,6 +102,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
Serial mLastUsedSerial = UINT64_MAX;
|
Serial mLastUsedSerial = UINT64_MAX;
|
||||||
bool mValidToDecay = false;
|
bool mValidToDecay = false;
|
||||||
|
bool mSwapChainTexture = false;
|
||||||
|
|
||||||
Serial mAcquireMutexKey = 0;
|
Serial mAcquireMutexKey = 0;
|
||||||
ComPtr<IDXGIKeyedMutex> mDxgiKeyedMutex;
|
ComPtr<IDXGIKeyedMutex> mDxgiKeyedMutex;
|
||||||
|
@ -36,6 +36,7 @@ namespace dawn_native { namespace d3d12 {
|
|||||||
|
|
||||||
HANDLE sharedHandle;
|
HANDLE sharedHandle;
|
||||||
uint64_t acquireMutexKey;
|
uint64_t acquireMutexKey;
|
||||||
|
bool isSwapChainTexture = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
|
DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user