Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- compute->SetPipelineState(mMipmapPS);
- compute->SetRootSignature(mMipmapRS);
- compute->SetDescriptorHeap(Engine::DescriptorHeap::CBV_SRV_UAV, heap);
- compute->TransitionResource(mColorBuffer, RESOURCE_STATE_UNORDERED_ACCESS, true);
- int todo = mNumMipmaps - 1;
- int base = 0;
- int dimension[2] = { (int)mWidth, (int)mHeight };
- while (todo != 0)
- {
- int mipLevels = 3;
- int npotflag = 0;
- if (((dimension[0] % 2) == 1) && ((dimension[1] % 2) == 1))
- {
- npotflag = 3;
- }
- else if ((dimension[1] % 2) == 1)
- {
- npotflag = 2;
- }
- else if ((dimension[0] % 2) == 1)
- {
- npotflag = 1;
- }
- if (todo == 1)
- {
- mipLevels = 1;
- }
- else if (todo == 2)
- {
- mipLevels = 2;
- }
- int dispatch[2] = { 0, 0 };
- dispatch[0] = dimension[0] / 8;
- if ((dimension[0] % 8) > 0)
- {
- dispatch[0]++;
- }
- dispatch[1] = dimension[1] / 8;
- if ((dimension[1] % 8) > 0)
- {
- dispatch[1]++;
- }
- if (dispatch[0] == 0 && dispatch[1] > 0)
- {
- dispatch[0] = 1;
- }
- else if (dispatch[0] > 0 && dispatch[1] == 0)
- {
- dispatch[1] = 1;
- }
- else if (dispatch[0] == 0 && dispatch[1] == 0)
- {
- break;
- }
- compute->SetConstants(0, Engine::DWParam(base), Engine::DWParam(npotflag), Engine::DWParam(1.0f / (float)dimension[0]), Engine::DWParam(1.0f / (float)dimension[1]));
- compute->SetConstants(1, Engine::DWParam(mipLevels), Engine::DWParam(mipLevels), Engine::DWParam(mipLevels), Engine::DWParam(mipLevels));
- compute->SetDescriptorTable(2, mColorBuffer->GetSRV());
- compute->SetDescriptorTable(3, mColorBuffer->GetUAV(base + 1));
- if (mipLevels >= 2) { compute->SetDescriptorTable(4, mColorBuffer->GetUAV(base + 2)); }
- if (mipLevels >= 3) { compute->SetDescriptorTable(5, mColorBuffer->GetUAV(base + 3)); }
- compute->Dispatch(dispatch[0], dispatch[1], 1);
- compute->TransitionResource(mColorBuffer, RESOURCE_STATE_UNORDERED_ACCESS, true);
- todo -= mipLevels;
- base += mipLevels;
- dimension[0] /= 2 << (mipLevels - 1);
- dimension[1] /= 2 << (mipLevels - 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement