This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commandQueue->Signal(fence, fenceValue); | |
WaitFenceValue(fence, fenceValue++); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FrameResources { | |
public: | |
~FrameResources(); | |
ComPtr<ID3D12Resource> renderTarget; | |
ComPtr<ID3D12CommandAllocator> commandAllocator; | |
ComPtr<ID3D12Resource> constantBuffer; | |
ComPtr<ID3D12DescriptorHeap> srvHeap; | |
struct { char buf[256]; } *mappedConstantBuffer = nullptr; | |
UINT64 fenceValueToGuard = 0; | |
} frameResources[2]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void WaitFenceValue(ComPtr<ID3D12Fence> fence, UINT64 value) | |
{ | |
if (fence->GetCompletedValue() >= value) { | |
return; | |
} | |
HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); | |
fence->SetEventOnCompletion(value, fenceEvent); | |
WaitForSingleObject(fenceEvent, INFINITE); | |
CloseHandle(fenceEvent); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commandQueue->ExecuteCommandLists(1, &A); | |
commandQueue->Signal(fence, 1); | |
commandQueue->ExecuteCommandLists(1, &B); | |
commandQueue->Signal(fence, 2); | |
commandQueue->ExecuteCommandLists(1, &C); | |
commandQueue->Signal(fence, 3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void WaitFenceValue(ComPtr<ID3D12Fence> fence, UINT64 value) | |
{ | |
HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); | |
fence->SetEventOnCompletion(value, fenceEvent); | |
WaitForSingleObject(fenceEvent, INFINITE); | |
CloseHandle(fenceEvent); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
afSetPipeline(pipelineState, rootSignature); | |
Mat invVP = inv(matV * matP); | |
int descriptorHeapIndex = deviceMan.AssignDescriptorHeap(2); | |
deviceMan.AssignConstantBuffer(descriptorHeapIndex, &invVP, sizeof(invVP)); | |
deviceMan.AssignSRV(descriptorHeapIndex + 1, texId); | |
deviceMan.SetAssignedDescriptorHeap(descriptorHeapIndex); | |
afDraw(PT_TRIANGLESTRIP, 4); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DeviceManDX12::AssignConstantBuffer(int descriptorHeapIndex, const void* buf, int size) | |
{ | |
int sizeAligned = (size + 0xff) & ~0xff; | |
int numRequired = sizeAligned / 0x100; | |
if (numAssignedConstantBufferBlocks + numRequired > maxConstantBufferBlocks) { | |
assert(0); | |
return; | |
} | |
int top = numAssignedConstantBufferBlocks; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int DeviceManDX12::AssignDescriptorHeap(int numRequired) | |
{ | |
if (numAssignedSrvs + numRequired > maxSrvs) { | |
assert(0); | |
return -1; | |
} | |
int head = numAssignedSrvs; | |
numAssignedSrvs = numAssignedSrvs + numRequired; | |
return head; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const UINT maxSrvs = 1024; | |
ComPtr<ID3D12DescriptorHeap> srvHeap; | |
const D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, maxSrvs, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE }; | |
device->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(&srvHeap)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConstantBuffer cb; | |
for (obj : objs) { | |
void *p; | |
cb.Map(&p); | |
memcpy(p, obj.data, sizeof()); | |
cb.Unmap(); | |
Draw() | |
} |