示例#1
0
        internal static void Run(ISrvBindable depthRead, ISrvBindable gbufferNormalsRead)
        {
            // The maximum number of supported GPU particles
            ISrvBindable textureArraySrv;
            int          emitterCount = MyGPUEmitters.Gather(m_emitterData, out textureArraySrv);

            if (emitterCount == 0)
            {
                return;
            }

            // Unbind current targets while we run the compute stages of the system
            //RC.DeviceContext.OutputMerger.SetTargets(null);
            // global GPU particles setup
            RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState);
            RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState);
            RC.SetInputLayout(null);
            RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.ComputeShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);
            RC.AllShaderStages.SetConstantBuffer(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer);
            RC.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap);
            RC.VertexShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray);
            RC.VertexShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            // If we are resetting the particle system, then initialize the dead list
            if (m_resetSystem)
            {
                ResetInternal();
                m_resetSystem = false;
            }

            MyGpuProfiler.IC_BeginBlock("Emit");
            // Emit particles into the system
            Emit(emitterCount, m_emitterData, depthRead);
            MyGpuProfiler.IC_EndBlock();

            // Run the simulation for this frame
            MyGpuProfiler.IC_BeginBlock("Simulate");
            Simulate(depthRead, gbufferNormalsRead);
            MyGpuProfiler.IC_EndBlock();

            // Copy the atomic counter in the alive list UAV into a constant buffer for access by subsequent passes
            RC.CopyStructureCount(m_activeListConstantBuffer, 0, m_aliveIndexBuffer);

            // Only read number of alive and dead particle back to the CPU in debug as we don't want to stall the GPU in release code

            ProfilerShort.Begin("Debug - ReadCounter");
            MyGpuProfiler.IC_BeginBlock("Debug - ReadCounter");
            int numActiveParticlesAfterSimulation = ReadCounter(m_aliveIndexBuffer);

            MyGpuProfiler.IC_EndBlock();
            ProfilerShort.End();

            MyGpuProfiler.IC_BeginBlock("Render");
            Render(textureArraySrv, depthRead);
            MyGpuProfiler.IC_EndBlock();

            RC.ComputeShader.SetSamplers(0, MySamplerStateManager.StandardSamplers);

            MyStatsDisplay.Write("GPU particles", "Live #", numActiveParticlesAfterSimulation);
        }
示例#2
0
        internal static void Run(MyBindableResource depthRead)
        {
            // The maximum number of supported GPU particles
            SharpDX.Direct3D11.ShaderResourceView textureArraySRV;
            int emitterCount = MyGPUEmitters.Gather(m_emitterData, out textureArraySRV);

            if (emitterCount == 0)
            {
                return;
            }

            // Unbind current targets while we run the compute stages of the system
            //RC.DeviceContext.OutputMerger.SetTargets(null);
            // global GPU particles setup
            RC.SetDS(MyDepthStencilState.DefaultDepthState);
            RC.SetRS(MyRender11.m_nocullRasterizerState);
            RC.SetIL(null);
            RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);
            RC.DeviceContext.ComputeShader.SetSamplers(0, SamplerStates.StandardSamplers);
            RC.DeviceContext.PixelShader.SetSamplers(0, SamplerStates.StandardSamplers);
            RC.SetCB(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer);
            RC.DeviceContext.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap);
            RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray.SRV);
            RC.DeviceContext.VertexShader.SetSamplers(0, SamplerStates.StandardSamplers);

            // If we are resetting the particle system, then initialize the dead list
            if (m_resetSystem)
            {
                ResetInternal();
                m_resetSystem = false;
            }

            MyGpuProfiler.IC_BeginBlock("Emit");
            // Emit particles into the system
            Emit(emitterCount, m_emitterData);
            MyGpuProfiler.IC_EndBlock();

            // Run the simulation for this frame
            MyGpuProfiler.IC_BeginBlock("Simulate");
            Simulate(depthRead);
            MyGpuProfiler.IC_EndBlock();

            // Copy the atomic counter in the alive list UAV into a constant buffer for access by subsequent passes
            RC.DeviceContext.CopyStructureCount(m_activeListConstantBuffer, 0, m_aliveIndexBuffer.m_UAV);

            // Only read number of alive and dead particle back to the CPU in debug as we don't want to stall the GPU in release code
#if DEBUG
            m_numDeadParticlesAfterSimulation   = ReadCounter(m_deadListBuffer);
            m_numActiveParticlesAfterSimulation = ReadCounter(m_aliveIndexBuffer);
#endif

            MyGpuProfiler.IC_BeginBlock("Render");
            Render(textureArraySRV, depthRead);
            MyGpuProfiler.IC_EndBlock();

            RC.DeviceContext.ComputeShader.SetSamplers(0, SamplerStates.StandardSamplers);

            /*Debug.WriteLine(string.Format("dead particles @ start {0} dead after emit {1} dead after sim {2} active after sim {3}",
             *  m_numDeadParticlesOnInit, m_numDeadParticlesAfterEmit,
             *  m_numDeadParticlesAfterSimulation, m_numActiveParticlesAfterSimulation));*/
        }