| 182 | } |
| 183 | |
| 184 | void MeshRenderer::ReduceDepth(ID3D11DeviceContext* context, DepthStencilBuffer& depthBuffer, |
| 185 | const Camera& camera) |
| 186 | { |
| 187 | PIXEvent event(L"Depth Reduction"); |
| 188 | |
| 189 | reductionConstants.Data.Projection = Float4x4::Transpose(camera.ProjectionMatrix()); |
| 190 | reductionConstants.Data.NearClip = camera.NearClip(); |
| 191 | reductionConstants.Data.FarClip = camera.FarClip(); |
| 192 | reductionConstants.Data.TextureSize.x = depthBuffer.Width; |
| 193 | reductionConstants.Data.TextureSize.y = depthBuffer.Height; |
| 194 | reductionConstants.Data.NumSamples = depthBuffer.MultiSamples; |
| 195 | reductionConstants.ApplyChanges(context); |
| 196 | reductionConstants.SetCS(context, 0); |
| 197 | |
| 198 | ID3D11RenderTargetView* rtvs[1] = { NULL }; |
| 199 | context->OMSetRenderTargets(1, rtvs, NULL); |
| 200 | |
| 201 | ID3D11UnorderedAccessView* uavs[1] = { depthReductionTargets[0].UAView }; |
| 202 | context->CSSetUnorderedAccessViews(0, 1, uavs, NULL); |
| 203 | |
| 204 | ID3D11ShaderResourceView* srvs[1] = { depthBuffer.SRView }; |
| 205 | context->CSSetShaderResources(0, 1, srvs); |
| 206 | |
| 207 | const bool msaa = depthBuffer.MultiSamples > 1; |
| 208 | |
| 209 | ID3D11ComputeShader* shader = depthReductionInitialCS[msaa ? 1 : 0]; |
| 210 | context->CSSetShader(shader, NULL, 0); |
| 211 | |
| 212 | uint32 dispatchX = depthReductionTargets[0].Width; |
| 213 | uint32 dispatchY = depthReductionTargets[0].Height; |
| 214 | context->Dispatch(dispatchX, dispatchY, 1); |
| 215 | |
| 216 | uavs[0] = NULL; |
| 217 | context->CSSetUnorderedAccessViews(0, 1, uavs, NULL); |
| 218 | |
| 219 | srvs[0] = NULL; |
| 220 | context->CSSetShaderResources(0, 1, srvs); |
| 221 | |
| 222 | context->CSSetShader(depthReductionCS, NULL, 0); |
| 223 | |
| 224 | for(uint32 i = 1; i < depthReductionTargets.size(); ++i) |
| 225 | { |
| 226 | RenderTarget2D& srcTexture = depthReductionTargets[i - 1]; |
| 227 | reductionConstants.Data.TextureSize.x = srcTexture.Width; |
| 228 | reductionConstants.Data.TextureSize.y = srcTexture.Height; |
| 229 | reductionConstants.Data.NumSamples = srcTexture.MultiSamples; |
| 230 | reductionConstants.ApplyChanges(context); |
| 231 | |
| 232 | uavs[0] = depthReductionTargets[i].UAView; |
| 233 | context->CSSetUnorderedAccessViews(0, 1, uavs, NULL); |
| 234 | |
| 235 | srvs[0] = srcTexture.SRView; |
| 236 | context->CSSetShaderResources(0, 1, srvs); |
| 237 | |
| 238 | dispatchX = depthReductionTargets[i].Width; |
| 239 | dispatchY = depthReductionTargets[i].Height; |
| 240 | context->Dispatch(dispatchX, dispatchY, 1); |
| 241 |
no test coverage detected