Skip to content

Commit

Permalink
DX12: mesh-indirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Feb 4, 2024
1 parent 4405df2 commit c9ef615
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
12 changes: 11 additions & 1 deletion Engine/gapi/directx12/dxcommandbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void DxCommandBuffer::beginRendering(const AttachmentDesc* desc, size_t descSize
impl->RSSetScissorRects(1, &sr);
}

void Tempest::Detail::DxCommandBuffer::endRendering() {
void DxCommandBuffer::endRendering() {
impl->EndRenderPass();
}

Expand Down Expand Up @@ -683,6 +683,16 @@ void DxCommandBuffer::dispatchMesh(size_t x, size_t y, size_t z) {
impl->DispatchMesh(UINT(x),UINT(y),UINT(z));
}

void DxCommandBuffer::dispatchMeshIndirect(const AbstractGraphicsApi::Buffer& indirect, size_t offset) {
const DxBuffer& ind = reinterpret_cast<const DxBuffer&>(indirect);
auto& sign = dev.drawMeshIndirectSgn.get();

// block future writers
resState.onUavUsage(ind.nonUniqId, NonUniqResId::I_None, PipelineStage::S_Graphics);

impl->ExecuteIndirect(sign, 1, ind.impl.get(), UINT64(offset), nullptr, 0);
}

void DxCommandBuffer::copy(AbstractGraphicsApi::Buffer& dstBuf, size_t offsetDest, const AbstractGraphicsApi::Buffer& srcBuf, size_t offsetSrc, size_t size) {
auto& dst = reinterpret_cast<DxBuffer&>(dstBuf);
auto& src = reinterpret_cast<const DxBuffer&>(srcBuf);
Expand Down
2 changes: 2 additions & 0 deletions Engine/gapi/directx12/dxcommandbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class DxCommandBuffer:public AbstractGraphicsApi::CommandBuffer {
void drawIndirect(const AbstractGraphicsApi::Buffer& indirect, size_t offset) override;

void dispatchMesh(size_t x, size_t y, size_t z) override;
void dispatchMeshIndirect(const AbstractGraphicsApi::Buffer& indirect, size_t offset) override;

void dispatch (size_t x, size_t y, size_t z) override;

void barrier (const AbstractGraphicsApi::BarrierDesc* desc, size_t cnt) override;
Expand Down
16 changes: 9 additions & 7 deletions Engine/gapi/directx12/dxdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ DxDevice::DxDevice(IDXGIAdapter1& adapter, const ApiEntry& dllApi)
dxAssert(device->CreateCommandQueue(&queueDesc, uuid<ID3D12CommandQueue>(), reinterpret_cast<void**>(&cmdQueue)));

{
D3D12_INDIRECT_ARGUMENT_DESC args[1] = {};
args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DRAW;
D3D12_INDIRECT_ARGUMENT_DESC arg = {};
D3D12_COMMAND_SIGNATURE_DESC desc = {};
desc.ByteStride = sizeof(D3D12_DRAW_ARGUMENTS);
desc.NumArgumentDescs = 1;
desc.pArgumentDescs = &arg;

D3D12_COMMAND_SIGNATURE_DESC desc = {};
desc.ByteStride = sizeof(D3D12_DRAW_ARGUMENTS);
desc.NumArgumentDescs = 1;
desc.pArgumentDescs = args;
arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DRAW;
dxAssert(device->CreateCommandSignature(&desc, nullptr, uuid<ID3D12CommandSignature>(), reinterpret_cast<void**>(&drawIndirectSgn)));

dxAssert(device->CreateCommandSignature(&desc, nullptr, uuid<ID3D12CommandSignature>(), reinterpret_cast<void**>(&drawIndirectSgn)));
arg.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH;
dxAssert(device->CreateCommandSignature(&desc, nullptr, uuid<ID3D12CommandSignature>(), reinterpret_cast<void**>(&drawMeshIndirectSgn)));
}

allocator.setDevice(*this);
Expand Down
1 change: 1 addition & 0 deletions Engine/gapi/directx12/dxdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class DxDevice : public AbstractGraphicsApi::Device {
ComPtr<ID3D12CommandQueue> cmdQueue;

ComPtr<ID3D12CommandSignature> drawIndirectSgn;
ComPtr<ID3D12CommandSignature> drawMeshIndirectSgn;

DxAllocator allocator;
DxDescriptorAllocator descAlloc;
Expand Down
5 changes: 5 additions & 0 deletions Engine/gapi/directx12/guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ inline GUID uuid<ID3D12GraphicsCommandList6>(){
return GUID{0xC3827890, 0xE548, 0x4CFA, {0x96,0xcf,0x56,0x89,0xa9,0x37,0x0f,0x80}};
}

template<>
inline GUID uuid<ID3D12GraphicsCommandList7>(){
return GUID{0xDD171223, 0x8B61, 0x4769, {0x90,0xe3,0x16,0x0c,0xcd,0xe4,0xe2,0xc1}};
}

template<>
inline GUID uuid<ID3D12DescriptorHeap>(){
return GUID{0x8EFB471D, 0x616C, 0x4F49, {0x90,0xf7,0x12,0x7b,0xb7,0x63,0xfa,0x51}};
Expand Down

0 comments on commit c9ef615

Please sign in to comment.