yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// debug-command-buffer.cpp 2#include "debug-command-buffer.h" 3 4#include "debug-framebuffer.h" 5#include "debug-helper-functions.h" 6#include "debug-render-pass.h" 7 8namespace gfx 9{ 10using namespace Slang ; 11 12namespace debug 13{ 14 15DebugCommandBuffer ::DebugCommandBuffer () 16{ 17SLANG_GFX_API_FUNC ; 18m_renderCommandEncoder .commandBuffer = this ; 19m_computeCommandEncoder .commandBuffer = this ; 20m_resourceCommandEncoder .commandBuffer = this ; 21m_rayTracingCommandEncoder .commandBuffer = this ; 22} 23 24ICommandBuffer * DebugCommandBuffer ::getInterface (const Slang ::Guid & guid ) 25{ 26if (guid == GfxGUID ::IID_ICommandBuffer || guid == GfxGUID ::IID_ISlangUnknown ) 27return (DebugObject < ICommandBuffer >* )this ; 28if (guid == GfxGUID ::IID_ICommandBufferD3D12 ) 29return static_cast < ICommandBufferD3D12 *> (this ); 30return nullptr ; 31} 32 33void DebugCommandBuffer ::encodeRenderCommands ( 34IRenderPassLayout * renderPass , 35IFramebuffer * framebuffer , 36IRenderCommandEncoder ** outEncoder ) 37{ 38SLANG_GFX_API_FUNC ; 39checkCommandBufferOpenWhenCreatingEncoder (); 40checkEncodersClosedBeforeNewEncoder (); 41auto innerRenderPass = getInnerObj (renderPass ); 42auto innerFramebuffer = getInnerObj (framebuffer ); 43m_renderCommandEncoder .isOpen = true; 44baseObject -> encodeRenderCommands ( 45innerRenderPass , 46innerFramebuffer , 47& m_renderCommandEncoder .baseObject ); 48if (m_renderCommandEncoder .baseObject ) 49* outEncoder = & m_renderCommandEncoder ; 50else 51* outEncoder = nullptr ; 52} 53 54void DebugCommandBuffer ::encodeComputeCommands (IComputeCommandEncoder ** outEncoder ) 55{ 56SLANG_GFX_API_FUNC ; 57checkCommandBufferOpenWhenCreatingEncoder (); 58checkEncodersClosedBeforeNewEncoder (); 59m_computeCommandEncoder .isOpen = true; 60baseObject -> encodeComputeCommands (& m_computeCommandEncoder .baseObject ); 61if (m_computeCommandEncoder .baseObject ) 62 { 63* outEncoder = & m_computeCommandEncoder ; 64 } 65else 66 { 67* outEncoder = nullptr ; 68 } 69} 70 71void DebugCommandBuffer ::encodeResourceCommands (IResourceCommandEncoder ** outEncoder ) 72{ 73SLANG_GFX_API_FUNC ; 74checkCommandBufferOpenWhenCreatingEncoder (); 75checkEncodersClosedBeforeNewEncoder (); 76m_resourceCommandEncoder .isOpen = true; 77baseObject -> encodeResourceCommands (& m_resourceCommandEncoder .baseObject ); 78if (m_resourceCommandEncoder .baseObject ) 79 { 80* outEncoder = & m_resourceCommandEncoder ; 81 } 82else 83 { 84* outEncoder = nullptr ; 85 } 86} 87 88void DebugCommandBuffer ::encodeRayTracingCommands (IRayTracingCommandEncoder ** outEncoder ) 89{ 90SLANG_GFX_API_FUNC ; 91checkCommandBufferOpenWhenCreatingEncoder (); 92checkEncodersClosedBeforeNewEncoder (); 93m_rayTracingCommandEncoder .isOpen = true; 94baseObject -> encodeRayTracingCommands (& m_rayTracingCommandEncoder .baseObject ); 95if (m_rayTracingCommandEncoder .baseObject ) 96 { 97* outEncoder = & m_rayTracingCommandEncoder ; 98 } 99else 100 { 101* outEncoder = nullptr ; 102 } 103} 104 105void DebugCommandBuffer ::close () 106{ 107SLANG_GFX_API_FUNC ; 108if (!isOpen ) 109 { 110GFX_DIAGNOSE_ERROR ("command buffer is already closed." ); 111 } 112if (m_renderCommandEncoder .isOpen ) 113 { 114GFX_DIAGNOSE_ERROR ( 115"A render command encoder on this command buffer is still open. " 116"IRenderCommandEncoder::endEncoding() must be called before closing a command buffer." ); 117 } 118if (m_computeCommandEncoder .isOpen ) 119 { 120GFX_DIAGNOSE_ERROR ("A compute command encoder on this command buffer is still open. " 121"IComputeCommandEncoder::endEncoding() must be called before closing a " 122"command buffer." ); 123 } 124if (m_resourceCommandEncoder .isOpen ) 125 { 126GFX_DIAGNOSE_ERROR ("A resource command encoder on this command buffer is still open. " 127"IResourceCommandEncoder::endEncoding() must be called before closing a " 128"command buffer." ); 129 } 130isOpen = false; 131baseObject -> close (); 132} 133 134Result DebugCommandBuffer ::getNativeHandle (InteropHandle * outHandle ) 135{ 136SLANG_GFX_API_FUNC ; 137return baseObject -> getNativeHandle (outHandle ); 138} 139 140void DebugCommandBuffer ::invalidateDescriptorHeapBinding () 141{ 142SLANG_GFX_API_FUNC ; 143ComPtr < ICommandBufferD3D12 > cmdBuf ; 144if (SLANG_FAILED (baseObject -> queryInterface ( 145SlangUUID SLANG_UUID_ICommandBufferD3D12 , 146 (void ** )cmdBuf .writeRef ()))) 147 { 148GFX_DIAGNOSE_ERROR ("The current command buffer implementation does not provide " 149"ICommandBufferD3D12 interface." ); 150return ; 151 } 152return cmdBuf -> invalidateDescriptorHeapBinding (); 153} 154 155void DebugCommandBuffer ::ensureInternalDescriptorHeapsBound () 156{ 157SLANG_GFX_API_FUNC ; 158ComPtr < ICommandBufferD3D12 > cmdBuf ; 159if (SLANG_FAILED (baseObject -> queryInterface ( 160SlangUUID SLANG_UUID_ICommandBufferD3D12 , 161 (void ** )cmdBuf .writeRef ()))) 162 { 163GFX_DIAGNOSE_ERROR ("The current command buffer implementation does not provide " 164"ICommandBufferD3D12 interface." ); 165return ; 166 } 167return cmdBuf -> ensureInternalDescriptorHeapsBound (); 168} 169 170void DebugCommandBuffer ::checkEncodersClosedBeforeNewEncoder () 171{ 172if (m_renderCommandEncoder .isOpen || m_resourceCommandEncoder .isOpen || 173m_computeCommandEncoder .isOpen ) 174 { 175GFX_DIAGNOSE_ERROR ( 176"A previouse command encoder created on this command buffer is still open. " 177"endEncoding() must be called on the encoder before creating an encoder." ); 178 } 179} 180 181void DebugCommandBuffer ::checkCommandBufferOpenWhenCreatingEncoder () 182{ 183if (!isOpen ) 184 { 185GFX_DIAGNOSE_ERROR ("The command buffer is already closed. Encoders can only be retrieved " 186"while the command buffer is open." ); 187 } 188} 189 190}// namespace debug 191}// namespace gfx