yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// d3d12-command-buffer.cpp 2#include "d3d12-command-buffer.h" 3 4#include "d3d12-transient-heap.h" 5 6namespace gfx 7{ 8namespace d3d12 9{ 10 11using namespace Slang ; 12 13// There are a pair of cyclic references between a `TransientResourceHeap` and 14// a `CommandBuffer` created from the heap. We need to break the cycle upon 15// the public reference count of a command buffer dropping to 0. 16 17ICommandBufferD3D12 * CommandBufferImpl ::getInterface (const Guid & guid ) 18{ 19if (guid == GfxGUID ::IID_ISlangUnknown || guid == GfxGUID ::IID_ICommandBuffer || 20guid == GfxGUID ::IID_ICommandBufferD3D12 ) 21return static_cast < ICommandBufferD3D12 *> (this ); 22return nullptr ; 23} 24 25Result CommandBufferImpl ::getNativeHandle (InteropHandle * handle ) 26{ 27handle -> api = InteropHandleAPI ::D3D12 ; 28handle -> handleValue = (uint64_t )m_cmdList .get (); 29return SLANG_OK ; 30} 31 32void CommandBufferImpl ::bindDescriptorHeaps () 33{ 34if (!m_descriptorHeapsBound ) 35 { 36ID3D12DescriptorHeap * heaps []= { 37m_transientHeap -> getCurrentViewHeap ().getHeap (), 38m_transientHeap -> getCurrentSamplerHeap ().getHeap (), 39 }; 40m_cmdList -> SetDescriptorHeaps (SLANG_COUNT_OF (heaps ),heaps ); 41m_descriptorHeapsBound = true; 42 } 43} 44 45void CommandBufferImpl ::reinit () 46{ 47invalidateDescriptorHeapBinding (); 48m_rootShaderObject .init (m_renderer ); 49} 50 51void CommandBufferImpl ::init ( 52DeviceImpl * renderer , 53ID3D12GraphicsCommandList * d3dCommandList , 54TransientResourceHeapImpl * transientHeap ) 55{ 56m_transientHeap = transientHeap ; 57m_renderer = renderer ; 58m_cmdList = d3dCommandList ; 59 60reinit (); 61 62m_cmdList -> QueryInterface < ID3D12GraphicsCommandList6 > (m_cmdList6 .writeRef ()); 63if (m_cmdList6 ) 64 { 65m_cmdList4 = m_cmdList6 ; 66m_cmdList1 = m_cmdList6 ; 67return ; 68 } 69#if SLANG_GFX_HAS_DXR_SUPPORT 70m_cmdList -> QueryInterface < ID3D12GraphicsCommandList4 > (m_cmdList4 .writeRef ()); 71if (m_cmdList4 ) 72 { 73m_cmdList1 = m_cmdList4 ; 74return ; 75 } 76#endif 77m_cmdList -> QueryInterface < ID3D12GraphicsCommandList1 > (m_cmdList1 .writeRef ()); 78} 79 80void CommandBufferImpl ::encodeResourceCommands (IResourceCommandEncoder ** outEncoder ) 81{ 82m_resourceCommandEncoder .init (this ); 83* outEncoder = & m_resourceCommandEncoder ; 84} 85 86void CommandBufferImpl ::encodeRenderCommands ( 87IRenderPassLayout * renderPass , 88IFramebuffer * framebuffer , 89IRenderCommandEncoder ** outEncoder ) 90{ 91m_renderCommandEncoder .init ( 92m_renderer , 93m_transientHeap , 94this , 95static_cast < RenderPassLayoutImpl *> (renderPass ), 96static_cast < FramebufferImpl *> (framebuffer )); 97* outEncoder = & m_renderCommandEncoder ; 98} 99 100void CommandBufferImpl ::encodeComputeCommands (IComputeCommandEncoder ** outEncoder ) 101{ 102m_computeCommandEncoder .init (m_renderer ,m_transientHeap ,this ); 103* outEncoder = & m_computeCommandEncoder ; 104} 105 106void CommandBufferImpl ::encodeRayTracingCommands (IRayTracingCommandEncoder ** outEncoder ) 107{ 108#if SLANG_GFX_HAS_DXR_SUPPORT 109m_rayTracingCommandEncoder .init (this ); 110* outEncoder = & m_rayTracingCommandEncoder ; 111#else 112* outEncoder = nullptr ; 113#endif 114} 115 116void CommandBufferImpl ::close () 117{ 118m_cmdList -> Close (); 119} 120 121}// namespace d3d12 122}// namespace gfx