| 24 | }); |
| 25 | |
| 26 | GPUBuffer* HistogramPass::Render(RenderContext& renderContext, GPUTexture* colorBuffer) |
| 27 | { |
| 28 | auto device = GPUDevice::Instance; |
| 29 | auto context = device->GetMainContext(); |
| 30 | if (checkIfSkipPass() || !_isSupported) |
| 31 | return nullptr; |
| 32 | PROFILE_GPU_CPU("Histogram"); |
| 33 | |
| 34 | // Setup constants |
| 35 | HistogramData data; |
| 36 | const uint32 colorBufferX = colorBuffer->Width(); |
| 37 | const uint32 colorBufferY = colorBuffer->Height(); |
| 38 | data.InputSizeX = colorBufferX; |
| 39 | data.InputSizeY = colorBufferY; |
| 40 | GetHistogramMad(data.HistogramMul, data.HistogramAdd); |
| 41 | |
| 42 | // Update constants |
| 43 | const auto shader = _shader->GetShader(); |
| 44 | const auto cb0 = shader->GetCB(0); |
| 45 | context->UpdateCB(cb0, &data); |
| 46 | context->BindCB(0, cb0); |
| 47 | |
| 48 | // Clear the histogram buffer |
| 49 | context->BindUA(0, _histogramBuffer->View()); |
| 50 | context->Dispatch(_csClearHistogram, (HISTOGRAM_SIZE + THREADGROUP_SIZE_X - 1) / THREADGROUP_SIZE_X, 1, 1); |
| 51 | |
| 52 | // Generate the histogram |
| 53 | context->BindSR(0, colorBuffer); |
| 54 | context->BindUA(0, _histogramBuffer->View()); |
| 55 | context->Dispatch(_csGenerateHistogram, (colorBufferX + THREADGROUP_SIZE_X - 1) / THREADGROUP_SIZE_X, (colorBufferY + THREADGROUP_SIZE_Y - 1) / THREADGROUP_SIZE_Y, 1); |
| 56 | |
| 57 | // Cleanup |
| 58 | context->ResetUA(); |
| 59 | context->ResetSR(); |
| 60 | |
| 61 | return _histogramBuffer; |
| 62 | } |
| 63 | |
| 64 | void HistogramPass::GetHistogramMad(float& multiply, float& add) |
| 65 | { |