🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

D3D12 Structured Buffers

Started by
1 comment, last by __MONTE2020 3 years, 2 months ago

I am porting my D3D11 Tiled Deferred pass to my D3D12 engine and I ran into a problem. In D3D11 I passed my Lights as StructuredBuffer. I would create buffer with D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED. Since lights are dynamic I would map, memcpy and unmap when I update lights. In D3D12 my approach was the same as an approach to transient constant buffers: I would allocate memory from upload buffer allocator, do a memcpy and then pass allocated buffer gpu address to SetComputeRootShaderResourceView. Usually debug layer is enough for me to debug and find the cause of the problem but this causes my laptop to freeze and forces me to reset it. Can anyone give some advice on how to set structured buffer in d3d12 or what could be the cause for freeze? thanks

Advertisement

I managed to get it working. I moved from unsafe SetComputeRootShaderResourceView to Descriptor Tables, i.e. one descriptor table with one SRV range of one descriptor. That, as you would expect, still didnt work but it didnt freeze my laptop so I was able to inspect values in PIX. I found that I was passing junk because I memcpy'ed address of std::vector instead of calling std::vector<T>::data(). Another problem was my Align function was working only for power of two aligns and I had to align my memory with sizeof(Light) so I can calculate FirstElement in D3D12_BUFFER_SRV. The options were either padd the struct to power of two size or write another align functions, both of which work. I didn't test SetComputeRootShaderResourceView after I found the solution though.

This topic is closed to new replies.

Advertisement