public void EvaluateClusterDebugView(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthStencilBuffer, TextureHandle depthPyramid)
        {
            TextureHandle debugTexture;

            using (var builder = renderGraph.AddRenderPass <LightClusterDebugPassData>("Debug Texture for the Light Cluster", out var passData, ProfilingSampler.Get(HDProfileId.RaytracingDebugCluster)))
            {
                builder.EnableAsyncCompute(false);

                passData.parameters         = PrepareLightClusterDebugParameters(hdCamera);
                passData.depthStencilBuffer = builder.UseDepthBuffer(depthStencilBuffer, DepthAccess.Read);
                passData.depthPyramid       = builder.ReadTexture(depthStencilBuffer);
                passData.outputBuffer       = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
                {
                    colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Light Cluster Debug Texture"
                }));

                builder.SetRenderFunc(
                    (LightClusterDebugPassData data, RenderGraphContext ctx) =>
                {
                    // We need to fill the structure that holds the various resources
                    LightClusterDebugResources resources = new LightClusterDebugResources();
                    resources.depthStencilBuffer         = data.depthStencilBuffer;
                    resources.depthTexture             = data.depthPyramid;
                    resources.debugLightClusterTexture = data.outputBuffer;
                    ExecuteLightClusterDebug(ctx.cmd, data.parameters, resources);
                });

                debugTexture = passData.outputBuffer;
            }

            m_RenderPipeline.PushFullScreenDebugTexture(renderGraph, debugTexture, FullScreenDebugMode.LightCluster);
        }
        LightClusterDebugResources PrepareLightClusterDebugResources(RTHandle outputDebugLightBuffer)
        {
            LightClusterDebugResources resources = new LightClusterDebugResources();

            resources.debugLightClusterTexture = outputDebugLightBuffer;
            resources.depthTexture             = m_RenderPipeline.sharedRTManager.GetDepthTexture();
            resources.depthStencilBuffer       = m_RenderPipeline.sharedRTManager.GetDepthStencilBuffer();
            return(resources);
        }
        public void EvaluateClusterDebugView(CommandBuffer cmd, HDCamera hdCamera)
        {
            LightClusterDebugParameters parameters = PrepareLightClusterDebugParameters(hdCamera);
            LightClusterDebugResources  resources  = PrepareLightClusterDebugResources(m_DebugLightClusterTexture);

            ExecuteLightClusterDebug(cmd, parameters, resources);

            // Bind the result
            m_RenderPipeline.PushFullScreenDebugTexture(hdCamera, cmd, m_DebugLightClusterTexture, FullScreenDebugMode.LightCluster);
        }
        static public void ExecuteLightClusterDebug(CommandBuffer cmd, LightClusterDebugParameters parameters, LightClusterDebugResources resources)
        {
            // Bind the output texture
            CoreUtils.SetRenderTarget(cmd, resources.debugLightClusterTexture, resources.depthStencilBuffer, clearFlag: ClearFlag.Color, clearColor: Color.black);

            // Inject all the parameters to the debug compute
            cmd.SetComputeBufferParam(parameters.lightClusterDebugCS, parameters.lightClusterDebugKernel, HDShaderIDs._RaytracingLightCluster, parameters.lightCluster);
            cmd.SetComputeVectorParam(parameters.lightClusterDebugCS, _ClusterCellSize, parameters.clusterCellSize);
            cmd.SetComputeTextureParam(parameters.lightClusterDebugCS, parameters.lightClusterDebugKernel, HDShaderIDs._CameraDepthTexture, resources.depthStencilBuffer);

            // Target output texture
            cmd.SetComputeTextureParam(parameters.lightClusterDebugCS, parameters.lightClusterDebugKernel, _DebutLightClusterTexture, resources.debugLightClusterTexture);

            // Dispatch the compute
            int lightVolumesTileSize = 8;
            int numTilesX            = (parameters.texWidth + (lightVolumesTileSize - 1)) / lightVolumesTileSize;
            int numTilesY            = (parameters.texHeight + (lightVolumesTileSize - 1)) / lightVolumesTileSize;

            cmd.DispatchCompute(parameters.lightClusterDebugCS, parameters.lightClusterDebugKernel, numTilesX, numTilesY, 1);

            // Bind the parameters
            parameters.debugMaterialProperties.SetBuffer(HDShaderIDs._RaytracingLightCluster, parameters.lightCluster);
            parameters.debugMaterialProperties.SetVector(_ClusterCellSize, parameters.clusterCellSize);
            parameters.debugMaterialProperties.SetTexture(HDShaderIDs._CameraDepthTexture, resources.depthTexture);

            // Draw the faces
            cmd.DrawProcedural(Matrix4x4.identity, parameters.debugMaterial, 1, MeshTopology.Lines, 48, 64 * 64 * 32, parameters.debugMaterialProperties);
            cmd.DrawProcedural(Matrix4x4.identity, parameters.debugMaterial, 0, MeshTopology.Triangles, 36, 64 * 64 * 32, parameters.debugMaterialProperties);
        }