| 174 | } |
| 175 | |
| 176 | void MipMapGenPass::Dispatch(nvrhi::ICommandList* commandList, int maxLOD) |
| 177 | { |
| 178 | assert(m_Texture); |
| 179 | |
| 180 | commandList->beginMarker("MipMapGen::Dispatch"); |
| 181 | |
| 182 | uint nmipLevels = m_Texture->getDesc().mipLevels; |
| 183 | if (maxLOD > 0 && maxLOD < (int)nmipLevels) |
| 184 | nmipLevels = maxLOD+1; |
| 185 | |
| 186 | uint width = m_Texture->getDesc().width, |
| 187 | height = m_Texture->getDesc().height; |
| 188 | |
| 189 | width = (width + GROUP_SIZE - 1) / GROUP_SIZE; |
| 190 | height = (height + GROUP_SIZE - 1) / GROUP_SIZE; |
| 191 | |
| 192 | for (uint i=0; i < MAX_PASSES; ++i) |
| 193 | { |
| 194 | if (i * NUM_LODS >= nmipLevels) |
| 195 | break; |
| 196 | |
| 197 | MipmmapGenConstants constants = {}; |
| 198 | constants.numLODs = std::min(nmipLevels - i*NUM_LODS -1, (uint32_t)NUM_LODS); |
| 199 | constants.dispatch = i; |
| 200 | commandList->writeBuffer(m_ConstantBuffer, &constants, sizeof(constants)); |
| 201 | |
| 202 | nvrhi::ComputeState state; |
| 203 | state.pipeline = m_Pso; |
| 204 | state.bindings = { m_BindingSets[i] }; |
| 205 | commandList->setComputeState(state); |
| 206 | commandList->dispatch(width, height); |
| 207 | } |
| 208 | |
| 209 | commandList->endMarker(); // "MipMapGen::Dispatch" |
| 210 | } |
| 211 | |
| 212 | |
| 213 | void MipMapGenPass::Display(std::shared_ptr<donut::engine::CommonRenderPasses> commonPasses, nvrhi::ICommandList* commandList, nvrhi::IFramebuffer* target) |