Uploading groups of shader attributes in DX12 (Buffer and view questions) #210
-
I accidentally posted this question in the samples section. Please remove that other post if possible. Thanks! What would be the most efficient method to upload dynamic shader properties for 30-60 game elements while using the DX12 backend? I've been trying to plan this out for a while, but don't have enough experience with newer APIs yet to know what would work best. I may support Vulkan in the future, but currently dealing exclusively with DX12. I would have asked these questions in a general forum, but I"m noticing Diligent Engine requires some variations on techniques, compared to the base DX12 API. For example, the way that dynamic buffers are fully uploaded when they are unmapped. I started off mapping small sections of a dynamic buffer and drawing just those small sections, but then realized my entire buffer would be copied to the GPU every time it was unmapped. Anyway, I would really appreciate some advice on some of these details. In my game engine, concerning just the properties that will be used in shaders, game entities would have two types of attributes: those that rarely change, and those that change every frame. Some examples would be world transform, colors, ambience factors, roughness factors, etc. If each of my rendered elements has a set of all of these types of properties, what would be the most efficient method to get them all to the shader? I'm hoping to store all of the data into as few buffers as possible, and upload everything at the beginning of each frame, if that makes the most sense. And possibly to separate the less frequently updated attributes into another buffer that is only uploaded when those specific things change.
As far as dynamic buffers go, I've looked at most of the tutorials and samples, but still not clear on the following..
And last questions..
Sorry for so many questions! Really appreciate any advice! Feel free to answer as many or as few as you want. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Hi there! The answers to your question depend on how much data you need to upload to buffer (few bytes vs few KBs vs MBs) and how many updates you need to do (100s vs 1000s vs millions). If you do 100s of updates, then any method will work really. If you do 1000s of updates, then you may need to think more carefully. 100s of thousands of updates definitely require some careful implementation.
Generally, yes. If you have some data that does not change, it is better to separate it. On the other hand, if it is only few bytes, you may also upload it to dynamic buffer every time
I don't know if you mean vertex buffers or uniform buffers. For vertex buffers it is better to only have what you need in the buffer for your model. However, if you have different varitations that require creating multiple copies of the same data, then it is better to have everythin in the same buffer.
No, this is not necessary.
Maybe - hard to tell what exactly will work best for your application. You can take a look at tutorial 10 that uses similar strategy.
You will need IShaderResourceVariable::SetBufferOffset
It may be a good idea. If you can update your buffer only once and then use offset to access its regions - that should work OK.
Do you mean, update every second element, for instance? You can write a compute shader that does that, but I am not sure this is the best approach. You can update contiguous parts of the buffer with This may be helpful. |
Beta Was this translation helpful? Give feedback.
-
It seems to me that you are overengineering at this point. If you need to render 500 different objects with less than 256 bytes of data per object, you can just use dynamic buffers. Mapping dynamic buffers in D3D12 backend is virtually free. I suggest you make it work first and then find the performance bottleneck, if any.
You can update continuous parts for the buffer using
You can update any region of a
It may not be expensive either, depending on how much data you need to update. Uploading 100s of MBs per frame will definitely be a problem, but uploading 100 Kbs is not a issue at all.
No, only the part of the buffer is updated. |
Beta Was this translation helpful? Give feedback.
Hi there! The answers to your question depend on how much data you need to upload to buffer (few bytes vs few KBs vs MBs) and how many updates you need to do (100s vs 1000s vs millions). If you do 100s of updates, then any method will work really. If you do 1000s of updates, then you may need to think more carefully. 100s of thousands of updates definitely require some careful implementation.
Generally, yes. If you have some data that does not change, it is better to separate it. On the other hand, if it is only few bytes, you may also upload it to dynamic buffer every time