Hello,
I'm currently trying to mipmap 3D textures in D3D12. So the basic idea was to build 2 miplevels at once as I'm running 4x4x4 threads in group. Also using groupshared memory to do some optimizations. What is sad (on mipmap generation) - that for 1st mip calculation just 8 threads will do some work and just single thread for the 2nd mip calculation. All of them are occupied only when filling data into groupshared memory. If you're curious, the compute shader is here: https://pastebin.com/4DYWbsDZ (it was too long to dump it here)
To generate complete mipchain, I use a loop like:
// Initial setup int todo = mMiplevels - 1; int base = 0; int dimension = mDimensions; // As long as there are some mip-levels to generate while (todo != 0) { // Always generate 2 miplevels at once (as long as we can) int mipLevels = 2; if (todo == 1) { todo++; base--; dimension *= 2; } // Record what we need to do into cmd list context->SetConstants(0, Engine::DWParam(base), Engine::DWParam(mipLevels), Engine::DWParam(1.0f / (float)dimension)); context->SetDescriptorTable(1, mColorTexture->GetSRV()); context->SetDescriptorTable(2, mColorTexture->GetUAV(base + 1)); context->SetDescriptorTable(3, mColorTexture->GetUAV(base + 2)); context->Dispatch(dimension / 4, dimension / 4, dimension / 4); base += mipLevels; dimension /= pow(2, mipLevels); }
After this for loop there is a 'Finish' call which executes command lists, and of course a barrier as the volume is going to be used. Note that the volume is generated and used within single frame.
The question here is (to others who most likely already tried similar thing), can this be done in better way?