rate up
2
rate down
DX12, RootSignature versioning.
Hi! I'm learning DX12 and there is one thing that I can't understand. Right now I'm at :.[http://][https://www.braynzarsoft.net/viewtutorial/q16390-transformations-and-world-view-projection-space-matrices] . This tutorial mentions that RootParameters(Constants and Descriptors) are automagically versioned by the driver. But, when we are updating and rendering, we are actually offsetting our memcpy/set view: memcpy(cbvGPUAddress[frameIndex], &cbPerObject, sizeof(cbPerObject)); memcpy(cbvGPUAddress[frameIndex] + ConstantBufferPerObjectAlignedSize, &cbPerObject, sizeof(cbPerObject)); // ... commandList->SetGraphicsRootConstantBufferView(0, constantBufferUploadHeaps[frameIndex]->GetGPUVirtualAddress()); commandList->SetGraphicsRootConstantBufferView(0, constantBufferUploadHeaps[frameIndex]->GetGPUVirtualAddress() + ConstantBufferPerObjectAlignedSize); It looks pretty much manual, when we update we have to take into account the padding, same when we set it CB. Then, what's actually that versioning doing? Thanks!
Chosen Answer
rate up
2
rate down
The root signature is what is actually being versioned, not the data the root descriptor points to. Every draw call you make, the root signature gets "versioned", or copied, and then a new root signature (copy from the previous one) is filled out for the next draw call. Constants and root descriptors are stored directly in the root signature, So when you call draw, those constants and descriptors will be saved, and the root signature is copied for the next draw call. Descriptors are only pointers to a chunk of memory, so while those will be versioned, the actual data that the descriptor points to will not. this is unlike a root constant, where the data itself is stored in the root signature. SetGraphicsRootConstantBufferView is not setting a root constant, it is setting a root descriptor (a constant buffer view), which points to a chunk of memory that the constant buffer is located in. You will have to change where this constant buffer view is pointing to between draw calls. Say you have two objects, each have their own constant buffers. object1's constant buffer data is at memory address 1 and object2's constant buffer data is at memory address 2. You only need one root descriptor, so what you do is: rootdescriptor = 1; // set the root descriptor to be the address 1, object1's constant buffer data location rootsignature.SetGraphicsRootConstantBufferView(rootdescriptor); object1.draw(); // the root descriptor is copied rootdescriptor = 2; // set root descriptor to be the address 2, object2's constant buffer data location rootsignature.SetGraphicsRootConstantBufferView(rootdescriptor); object2.draw(); obviously thats psuedocode, but basically the idea is there. the constant buffer data is not versioned by the driver, but the root signature is
Comments
Hi, thanks for the answer, it clarifies it a lot!
on Jul 18 `17
piluve
Sign in to answer!