Created
July 9, 2016 10:14
-
-
Save yorung/e039764cf6021b0228a350e07f48025d to your computer and use it in GitHub Desktop.
[DX12] Assign constant buffer and write its GPU address into descriptor heap
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; | |
| numAssignedConstantBufferBlocks += numRequired; | |
| memcpy(mappedConstantBuffer + top, buf, size); | |
| D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {}; | |
| cbvDesc.BufferLocation = constantBuffer->GetGPUVirtualAddress() + top * 0x100; | |
| cbvDesc.SizeInBytes = sizeAligned; | |
| assert((cbvDesc.SizeInBytes & 0xff) == 0); | |
| D3D12_CPU_DESCRIPTOR_HANDLE ptr = srvHeap->GetCPUDescriptorHandleForHeapStart(); | |
| ptr.ptr += deviceMan.GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * descriptorHeapIndex; | |
| deviceMan.GetDevice()->CreateConstantBufferView(&cbvDesc, ptr); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment