From 5a3aa6159e0ef0241b528812e1d138f0d7055f22 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Tue, 17 May 2022 10:56:14 -0700 Subject: Split render-d3d12.h/cpp into a set of smaller files (#2231) * Split render-d3d12 into numerous smaller files to make the code easier to parse * Added all new D3D12 files created from splitting render-d3d12 * Fixed several uses of attachment still floating around; Changed resource-d3d12 and descriptor-heap-d3d12 to match naming conventions of new d3d12 implementation header files * Readded files with name changes because changing them from inside VS apparently results in them being treated as new files * Merged in externals changes from master * Small cleanup changes * Rerun CI Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com> --- tools/gfx/d3d12/d3d12-command-buffer.cpp | 110 +++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tools/gfx/d3d12/d3d12-command-buffer.cpp (limited to 'tools/gfx/d3d12/d3d12-command-buffer.cpp') diff --git a/tools/gfx/d3d12/d3d12-command-buffer.cpp b/tools/gfx/d3d12/d3d12-command-buffer.cpp new file mode 100644 index 000000000..3a09da037 --- /dev/null +++ b/tools/gfx/d3d12/d3d12-command-buffer.cpp @@ -0,0 +1,110 @@ +// d3d12-command-buffer.cpp +#include "d3d12-command-buffer.h" + +#include "d3d12-transient-heap.h" + +namespace gfx +{ +namespace d3d12 +{ + +using namespace Slang; + +// There are a pair of cyclic references between a `TransientResourceHeap` and +// a `CommandBuffer` created from the heap. We need to break the cycle upon +// the public reference count of a command buffer dropping to 0. + +ICommandBufferD3D12* CommandBufferImpl::getInterface(const Guid& guid) +{ + if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_ICommandBuffer || + guid == GfxGUID::IID_ICommandBufferD3D12) + return static_cast(this); + return nullptr; +} + +Result CommandBufferImpl::getNativeHandle(InteropHandle* handle) +{ + handle->api = InteropHandleAPI::D3D12; + handle->handleValue = (uint64_t)m_cmdList.get(); + return SLANG_OK; +} + +void CommandBufferImpl::bindDescriptorHeaps() +{ + if (!m_descriptorHeapsBound) + { + ID3D12DescriptorHeap* heaps[] = { + m_transientHeap->getCurrentViewHeap().getHeap(), + m_transientHeap->getCurrentSamplerHeap().getHeap(), + }; + m_cmdList->SetDescriptorHeaps(SLANG_COUNT_OF(heaps), heaps); + m_descriptorHeapsBound = true; + } +} + +void CommandBufferImpl::reinit() +{ + invalidateDescriptorHeapBinding(); + m_rootShaderObject.init(m_renderer); +} + +void CommandBufferImpl::init( + DeviceImpl* renderer, + ID3D12GraphicsCommandList* d3dCommandList, + TransientResourceHeapImpl* transientHeap) +{ + m_transientHeap = transientHeap; + m_renderer = renderer; + m_cmdList = d3dCommandList; + + reinit(); + +#if SLANG_GFX_HAS_DXR_SUPPORT + m_cmdList->QueryInterface(m_cmdList4.writeRef()); + if (m_cmdList4) + { + m_cmdList1 = m_cmdList4; + return; + } +#endif + m_cmdList->QueryInterface(m_cmdList1.writeRef()); +} + +void CommandBufferImpl::encodeResourceCommands(IResourceCommandEncoder** outEncoder) +{ + m_resourceCommandEncoder.init(this); + *outEncoder = &m_resourceCommandEncoder; +} + +void CommandBufferImpl::encodeRenderCommands( + IRenderPassLayout* renderPass, IFramebuffer* framebuffer, IRenderCommandEncoder** outEncoder) +{ + m_renderCommandEncoder.init( + m_renderer, + m_transientHeap, + this, + static_cast(renderPass), + static_cast(framebuffer)); + *outEncoder = &m_renderCommandEncoder; +} + +void CommandBufferImpl::encodeComputeCommands(IComputeCommandEncoder** outEncoder) +{ + m_computeCommandEncoder.init(m_renderer, m_transientHeap, this); + *outEncoder = &m_computeCommandEncoder; +} + +void CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) +{ +#if SLANG_GFX_HAS_DXR_SUPPORT + m_rayTracingCommandEncoder.init(this); + *outEncoder = &m_rayTracingCommandEncoder; +#else + * outEncoder = nullptr; +#endif +} + +void CommandBufferImpl::close() { m_cmdList->Close(); } + +} // namespace d3d12 +} // namespace gfx -- cgit v1.2.3