summaryrefslogtreecommitdiffstats
path: root/tools/gfx/d3d12/render-d3d12.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-03-11 11:57:53 -0800
committerGitHub <noreply@github.com>2022-03-11 11:57:53 -0800
commit0890fd8f2e485bfdd93ff6227be08ff4142e55d1 (patch)
treebe8d2381d0f0e96b267428046dcad815fcafd245 /tools/gfx/d3d12/render-d3d12.cpp
parentf6c2a0f81340a0efd10e286a3cbe33e1b564a11b (diff)
gfx: Add `ITransientResourceHeap::finish()` to avoid `Signal` after every queue submit. (#2158)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx/d3d12/render-d3d12.cpp')
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index 67c31158b..de3081f40 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -2378,6 +2378,7 @@ void DeviceImpl::submitResourceCommandsAndWait(const DeviceImpl::ResourceCommand
{
info.commandBuffer->close();
m_resourceCommandQueue->executeCommandBuffer(info.commandBuffer);
+ m_resourceCommandTransientHeap->finish();
m_resourceCommandTransientHeap->synchronizeAndReset();
}
@@ -2785,18 +2786,9 @@ Result AccelerationStructureImpl::getNativeHandle(InteropHandle* outHandle)
Result TransientResourceHeapImpl::synchronizeAndReset()
{
- Array<HANDLE, 16> waitHandles;
- for (auto& waitInfo : m_waitInfos)
- {
- if (waitInfo.waitValue == 0)
- continue;
- if (waitInfo.fence)
- {
- waitInfo.fence->SetEventOnCompletion(waitInfo.waitValue, waitInfo.fenceEvent);
- waitHandles.add(waitInfo.fenceEvent);
- }
- }
- WaitForMultipleObjects((DWORD)waitHandles.getCount(), waitHandles.getBuffer(), TRUE, INFINITE);
+ WaitForMultipleObjects(
+ (DWORD)m_waitHandles.getCount(), m_waitHandles.getBuffer(), TRUE, INFINITE);
+ m_waitHandles.clear();
m_currentViewHeapIndex = -1;
m_currentSamplerHeapIndex = -1;
allocateNewViewDescriptorHeap(m_device);
@@ -2809,6 +2801,22 @@ Result TransientResourceHeapImpl::synchronizeAndReset()
return SLANG_OK;
}
+Result TransientResourceHeapImpl::finish()
+{
+ for (auto& waitInfo : m_waitInfos)
+ {
+ if (waitInfo.waitValue == 0)
+ continue;
+ if (waitInfo.fence)
+ {
+ waitInfo.queue->Signal(waitInfo.fence, waitInfo.waitValue);
+ waitInfo.fence->SetEventOnCompletion(waitInfo.waitValue, waitInfo.fenceEvent);
+ m_waitHandles.add(waitInfo.fenceEvent);
+ }
+ }
+ return SLANG_OK;
+}
+
TransientResourceHeapImpl::QueueWaitInfo& TransientResourceHeapImpl::getQueueWaitInfo(
uint32_t queueIndex)
{
@@ -3462,10 +3470,8 @@ void RayTracingCommandEncoderImpl::dispatchRays(
auto shaderTableImpl = static_cast<ShaderTableImpl*>(shaderTable);
- ResourceCommandEncoderImpl resourceCopyEncoder;
- resourceCopyEncoder.init(m_commandBuffer);
auto shaderTableBuffer =
- shaderTableImpl->getOrCreateBuffer(pipelineImpl, m_transientHeap, &resourceCopyEncoder);
+ shaderTableImpl->getOrCreateBuffer(pipelineImpl, m_transientHeap, static_cast<ResourceCommandEncoderImpl*>(this));
auto shaderTableAddr = shaderTableBuffer->getDeviceAddress();
D3D12_DISPATCH_RAYS_DESC dispatchDesc = {};
@@ -5015,8 +5021,8 @@ void CommandQueueImpl::executeCommandBuffers(
auto& waitInfo = transientHeap->getQueueWaitInfo(m_queueIndex);
waitInfo.waitValue = m_fenceValue;
waitInfo.fence = m_fence;
+ waitInfo.queue = m_d3dQueue;
}
- m_d3dQueue->Signal(m_fence, m_fenceValue);
}
if (fence)
@@ -6556,10 +6562,7 @@ void ResourceCommandEncoderImpl::textureBarrier(
void ResourceCommandEncoderImpl::bufferBarrier(
size_t count, IBufferResource* const* buffers, ResourceState src, ResourceState dst)
{
-
- List<D3D12_RESOURCE_BARRIER> barriers;
- barriers.reserve(count);
-
+ ShortList<D3D12_RESOURCE_BARRIER, 16> barriers;
for (size_t i = 0; i < count; i++)
{
auto bufferImpl = static_cast<BufferResourceImpl*>(buffers[i]);