Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _GFX_D3D12_COMMAND_LIST_HPP_
- #define _GFX_D3D12_COMMAND_LIST_HPP_
- #include "d3d12_command_allocator.hpp"
- #include "d3d12_pipeline_state_object.hpp"
- #include "d3d12_index_buffer.hpp"
- #include "d3d12_vertex_buffer.hpp"
- #include "d3d12_root_signature.hpp"
- #include "d3d12_descriptor_heap.hpp"
- class GFXCommandListInterfaceD3D12 {
- public:
- ID3D12GraphicsCommandList* GetInterface() { return pCommandList.Raw(); }
- protected:
- UniqueCOM<ID3D12GraphicsCommandList> pCommandList;
- };
- using GFXCommandListInterface = GFXCommandListInterfaceD3D12;
- template<GFXCommandListType type>
- class GFXCommandListCommonCommandsD3D12 : public virtual GFXCommandListInterfaceD3D12 {
- public:
- bool Init (GFXCommandAllocatorD3D12<type>& cmdAllocator, GFXPipelineStateObjectD3D12* pso = nullptr)
- {
- ID3D12PipelineState* d3dPso = pso != nullptr ? pso->GetInterface() : nullptr;
- HRESULT hr = S_OK;
- if (FAILED(hr = pGfxD3DDevice->GetInterface()->CreateCommandList(0, static_cast<D3D12_COMMAND_LIST_TYPE>(type), cmdAllocator.GetInterface(), d3dPso, IID_PPV_ARGS(&pCommandList)))) {
- AppLogError(D3D12_SUBSYSTEM, SPrintf("Failed to create command list. HRESULT: %d", hr).c_str());
- }
- return true;
- }
- void Term (void)
- {
- pCommandList.Reset();
- }
- void Close (void)
- {
- if (HRESULT hr; FAILED(hr = pCommandList->Close())) {
- AppLogError(D3D12_SUBSYSTEM, SPrintf("Failed to close command list. HRESULT: %d", hr).c_str());
- }
- }
- void Reset (GFXCommandAllocatorD3D12<type>& cmdAllocator, GFXPipelineStateObjectD3D12* pso = nullptr)
- {
- ID3D12PipelineState* d3dPso = pso != nullptr ? static_cast<GFXPipelineStateObjectD3D12*>(pso)->GetInterface() : nullptr;
- if (HRESULT hr; FAILED(hr = pCommandList->Reset(cmdAllocator.GetInterface(), d3dPso))) {
- AppLogError(D3D12_SUBSYSTEM, "Failed to reset command list");
- }
- }
- };
- class GFXCommandListCopyComputeGraphicsCommonD3D12 : public virtual GFXCommandListInterfaceD3D12 {
- public:
- void ResourceBarrier(U32 numBarriers, const GFXResourceBarrier* pBarriers)
- {
- static_assert(SizeOf<D3D12_RESOURCE_BARRIER>() == SizeOf<GFXResourceBarrier>(), "GFXResourceBarrier don't match d312 interface");
- const D3D12_RESOURCE_BARRIER* pD3DBarriers = reinterpret_cast<const D3D12_RESOURCE_BARRIER*>(pBarriers);
- pCommandList->ResourceBarrier(numBarriers, pD3DBarriers);
- }
- };
- class GFXCommandListCopyCommandsD3D12 : public virtual GFXCommandListCopyComputeGraphicsCommonD3D12 {
- public:
- void CopyBufferRegion();
- void CopyResource();
- void CopyTextureRegion();
- void CopyTiles();
- };
- class GFXCommandListComputeGraphicsCommonD3D12 : public virtual GFXCommandListInterfaceD3D12 {
- public:
- void ClearState(void);
- void DiscardResource(void);
- void SetDescriptorHeaps(GFXDescriptorHeapD3D12* pDescriptorHeaps, U32 numHeaps)
- {
- ID3D12DescriptorHeap* pD3DDescHeaps[8];
- ASSERT(numHeaps <= 8);
- for (U32 i = 0; i < numHeaps; ++i) {
- pD3DDescHeaps[i] = pDescriptorHeaps[i].GetInterface();
- }
- pCommandList->SetDescriptorHeaps(numHeaps, pD3DDescHeaps);
- }
- void SetPipelineState(void);
- void SetPredication(void);
- };
- class GFXCommandListComputeCommandsD3D12 : public virtual GFXCommandListComputeGraphicsCommonD3D12 {
- public:
- void ClearUnorderedAccessViewFloat();
- void ClearUnorderedAccessViewUint();
- void Dispatch();
- void ExecuteIndirect();
- void SetComputeRoot32BitConstant();
- void SetComputeRoot32BitConstants();
- void SetComputeRootConstantBufferView();
- void SetComputeRootDescriptorTable();
- void SetComputeRootShaderResourceView();
- void SetComputeRootSignature();
- void SetComputeRootUnorderedAccessView();
- };
- using GFXCommandListComputeCommands = GFXCommandListComputeCommandsD3D12;
- class GFXCommandListGraphicsCommandsD3D12 : public virtual GFXCommandListComputeGraphicsCommonD3D12 {
- public:
- void BeginEvent(void);
- void BeginQuery(void);
- void ClearDepthStencilView(const GFXDescriptorCPUHandle& descriptor, Float depth, U8 stencil, U32 numRects, const GFXRect* pRects)
- {
- const D3D12_CPU_DESCRIPTOR_HANDLE& pD3DDescriptor = reinterpret_cast<const D3D12_CPU_DESCRIPTOR_HANDLE&>(descriptor);
- const D3D12_RECT* pD3DRects = reinterpret_cast<const D3D12_RECT*>(pRects);
- pCommandList->ClearDepthStencilView(pD3DDescriptor, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, depth, stencil, numRects, pD3DRects);
- }
- void ClearRenderTargetView(const GFXDescriptorCPUHandle& descriptor, const Float4& color, U32 numRects, const GFXRect* pRects)
- {
- const D3D12_CPU_DESCRIPTOR_HANDLE& pD3DDescriptor = reinterpret_cast<const D3D12_CPU_DESCRIPTOR_HANDLE&>(descriptor);
- const D3D12_RECT* pD3DRects = reinterpret_cast<const D3D12_RECT*>(pRects);
- pCommandList->ClearRenderTargetView(pD3DDescriptor, color.elements, numRects, pD3DRects);
- }
- void DrawIndexedInstanced(U32 indexCountPerInstance, U32 instanceCount, U32 startIndexLocation, I32 baseVertexOffset, U32 startInstanceLocation)
- {
- pCommandList->DrawIndexedInstanced(indexCountPerInstance, instanceCount, startIndexLocation, baseVertexOffset, startInstanceLocation);
- }
- void DrawInstanced(U32 vertexCountPerInstance, U32 instanceCount, U32 startVertexLocation, U32 startInstanceLocation)
- {
- pCommandList->DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation);
- }
- void EndEvent(void);
- void EndQuery(void);
- void ExecuteBundle(void);
- void IASetIndexBuffer(const GFXIndexBufferD3D12& indexBuffer)
- {
- auto view = indexBuffer.GetView();
- pCommandList->IASetIndexBuffer(&view);
- }
- void IASetPrimitiveTopology(GFXPrimitiveTopology topology)
- {
- pCommandList->IASetPrimitiveTopology(static_cast<D3D12_PRIMITIVE_TOPOLOGY>(topology));
- }
- void IASetVertexBuffer(const GFXVertexBufferD3D12& vertexBuffer)
- {
- auto view = vertexBuffer.GetView();
- pCommandList->IASetVertexBuffers(0, 1, &view);
- }
- void OMSetBlendFactor(void);
- void OMSetRenderTargets(U32 numRTs, const GFXDescriptorCPUHandle* pRTDescriptors, bool signleHandleToDescriptorRange, const GFXDescriptorCPUHandle* pDSDescriptor)
- {
- const D3D12_CPU_DESCRIPTOR_HANDLE* pD3DDescriptorsRT = reinterpret_cast<const D3D12_CPU_DESCRIPTOR_HANDLE*>(pRTDescriptors);
- const D3D12_CPU_DESCRIPTOR_HANDLE* pD3DDectiptorDS = reinterpret_cast<const D3D12_CPU_DESCRIPTOR_HANDLE*>(pDSDescriptor);
- pCommandList->OMSetRenderTargets(numRTs, pD3DDescriptorsRT, signleHandleToDescriptorRange, pD3DDectiptorDS);
- }
- void OMSetStencilRef(void);
- void ResolveQueryData(void);
- void ResolveSubresource(void);
- void RSSetScissorRects(U32 numRects, const GFXRect* pRects)
- {
- static_assert(SizeOf<D3D12_RECT>() == SizeOf<GFXRect>(), "GFXRect don't match d3d12 interface");
- const D3D12_RECT* pD3D12Rects = reinterpret_cast<const D3D12_RECT*>(pRects);
- pCommandList->RSSetScissorRects(numRects, pD3D12Rects);
- }
- void RSSetViewports(U32 numViewports, const GFXViewport* pViewports)
- {
- static_assert(SizeOf<D3D12_VIEWPORT>() == SizeOf<GFXViewport>(), "GFXViewport don't match d3d12 interface");
- const D3D12_VIEWPORT* pD3DViewports = reinterpret_cast<const D3D12_VIEWPORT*>(pViewports);
- pCommandList->RSSetViewports(numViewports, pD3DViewports);
- }
- void SetGraphicsRoot32BitConstant(void);
- void SetGraphicsRoot32BitConstants(void);
- void SetGraphicsRootConstantBufferView(U32 rootParameterIndex, GFXGPUVirutalAddress gpuVirtualAddress)
- {
- pCommandList->SetGraphicsRootConstantBufferView(rootParameterIndex, gpuVirtualAddress);
- }
- void SetGraphicsRootDescriptorTable(U32 rootParameterIndex, GFXDescriptorGPUHandle handle)
- {
- D3D12_GPU_DESCRIPTOR_HANDLE d3dHandle;
- d3dHandle.ptr = handle.ptr;
- pCommandList->SetGraphicsRootDescriptorTable(rootParameterIndex, d3dHandle);
- }
- void SetGraphicsRootShaderResourceView(void);
- void SetGraphicsRootSignature(GFXRootSignatureD3D12& rootSignature)
- {
- pCommandList->SetGraphicsRootSignature(rootSignature.GetInterface());
- }
- void SetGraphicsRootUnorderedAccessView(void);
- void SetMarker(void);
- void SOSetTargets(void);
- };
- using GFXCommandListGraphicsCommands = GFXCommandListGraphicsCommandsD3D12;
- template<GFXCommandListType type>
- class GFXCommandListD3D12;
- template<>
- class GFXCommandListD3D12<GFXCommandListType::Direct> : public virtual GFXCommandListCommonCommandsD3D12<GFXCommandListType::Direct>,
- public virtual GFXCommandListComputeCommandsD3D12,
- public virtual GFXCommandListGraphicsCommandsD3D12,
- public virtual GFXCommandListCopyCommandsD3D12
- {};
- using GFXDirectCommandList = GFXCommandListD3D12<GFXCommandListType::Direct>;
- template<>
- class GFXCommandListD3D12<GFXCommandListType::Compute> : public virtual GFXCommandListCommonCommandsD3D12<GFXCommandListType::Compute>,
- public virtual GFXCommandListComputeCommandsD3D12,
- public virtual GFXCommandListCopyCommandsD3D12
- {};
- using GFXComputeCommandList = GFXCommandListD3D12<GFXCommandListType::Compute>;
- template<>
- class GFXCommandListD3D12<GFXCommandListType::Copy> : public virtual GFXCommandListCommonCommandsD3D12<GFXCommandListType::Copy>,
- public virtual GFXCommandListCopyCommandsD3D12
- {};
- using GFXCopyCommandList = GFXCommandListD3D12<GFXCommandListType::Copy>;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement