Add SetResourceState and ForceRebindDescriptors to GPUContext for integration with external rendering libraries

This commit is contained in:
Wojciech Figat
2022-12-14 16:16:02 +01:00
parent c38eda5799
commit 713aa3e0f9
4 changed files with 40 additions and 9 deletions

View File

@@ -63,3 +63,11 @@ void GPUContext::Draw(GPUTextureView* rt)
SetState(_device->GetCopyLinearPS());
DrawFullscreenTriangle();
}
void GPUContext::SetResourceState(GPUResource* resource, uint64 state, int32 subresource)
{
}
void GPUContext::ForceRebindDescriptors()
{
}

View File

@@ -596,4 +596,14 @@ public:
/// Flushes the command buffer (calls GPU execution).
/// </summary>
API_FUNCTION() virtual void Flush() = 0;
/// <summary>
/// Sets the state of the resource (or subresource).
/// </summary>
virtual void SetResourceState(GPUResource* resource, uint64 state, int32 subresource = -1);
/// <summary>
/// Forces graphics backend to rebind descriptors after command list was used by external graphics library.
/// </summary>
virtual void ForceRebindDescriptors();
};

View File

@@ -236,13 +236,7 @@ void GPUContextDX12::Reset()
Platform::MemoryClear(&_samplers, sizeof(_samplers));
_swapChainsUsed = 0;
// Bind Root Signature
_commandList->SetGraphicsRootSignature(_device->GetRootSignature());
_commandList->SetComputeRootSignature(_device->GetRootSignature());
// Bind heaps
ID3D12DescriptorHeap* ppHeaps[] = { _device->RingHeap_CBV_SRV_UAV.GetHeap(), _device->RingHeap_Sampler.GetHeap() };
_commandList->SetDescriptorHeaps(ARRAY_COUNT(ppHeaps), ppHeaps);
ForceRebindDescriptors();
}
uint64 GPUContextDX12::Execute(bool waitForCompletion)
@@ -1392,11 +1386,11 @@ void GPUContextDX12::CopySubresource(GPUResource* dstResource, uint32 dstSubreso
auto srcBufferDX12 = dynamic_cast<GPUBufferDX12*>(srcResource);
auto dstTextureDX12 = dynamic_cast<GPUTextureDX12*>(dstResource);
auto srcTextureDX12 = dynamic_cast<GPUTextureDX12*>(srcResource);
SetResourceState(dstResourceDX12, D3D12_RESOURCE_STATE_COPY_DEST);
SetResourceState(srcResourceDX12, D3D12_RESOURCE_STATE_COPY_SOURCE);
flushRBs();
// Buffer -> Buffer
if (srcBufferDX12 && dstBufferDX12)
{
@@ -1430,4 +1424,21 @@ void GPUContextDX12::CopySubresource(GPUResource* dstResource, uint32 dstSubreso
}
}
void GPUContextDX12::SetResourceState(GPUResource* resource, uint64 state, int32 subresource)
{
auto resourceDX12 = dynamic_cast<ResourceOwnerDX12*>(resource);
SetResourceState(resourceDX12, (D3D12_RESOURCE_STATES)state, subresource);
}
void GPUContextDX12::ForceRebindDescriptors()
{
// Bind Root Signature
_commandList->SetGraphicsRootSignature(_device->GetRootSignature());
_commandList->SetComputeRootSignature(_device->GetRootSignature());
// Bind heaps
ID3D12DescriptorHeap* ppHeaps[] = {_device->RingHeap_CBV_SRV_UAV.GetHeap(), _device->RingHeap_Sampler.GetHeap()};
_commandList->SetDescriptorHeaps(ARRAY_COUNT(ppHeaps), ppHeaps);
}
#endif

View File

@@ -198,6 +198,8 @@ public:
void CopyCounter(GPUBuffer* dstBuffer, uint32 dstOffset, GPUBuffer* srcBuffer) override;
void CopyResource(GPUResource* dstResource, GPUResource* srcResource) override;
void CopySubresource(GPUResource* dstResource, uint32 dstSubresource, GPUResource* srcResource, uint32 srcSubresource) override;
void SetResourceState(GPUResource* resource, uint64 state, int32 subresource) override;
void ForceRebindDescriptors() override;
};
#endif