public void UpdateStats()
        {
            string group = "Rtv pooling";

            foreach (var itListRtv in m_dictionaryRtvTextures)
            {
                MyStatsDisplay.Write(group, itListRtv.Key.ToString(), itListRtv.Value.Count);
            }

            group = "Rtv pooling";
            foreach (var itListUav in m_dictionaryUavTextures)
            {
                MyStatsDisplay.Write(group, itListUav.Key.ToString(), itListUav.Value.Count);
            }

            group = "Custom pooling";
            foreach (var itListCustom in m_dictionaryCustomTextures)
            {
                MyStatsDisplay.Write(group, itListCustom.Key.ToString(), itListCustom.Value.Count);
            }

            group = "DepthStencil pooling";
            foreach (var itListDepthStencil in m_dictionaryDepthStencilTextures)
            {
                MyStatsDisplay.Write(group, itListDepthStencil.Key.ToString(), itListDepthStencil.Value.Count);
            }
        }
Ejemplo n.º 2
0
        private static bool ProcessDrawSpritesQueue(string textureName)
        {
            List <MySpriteDrawRenderMessage> messages;

            if (!m_spriteTextureBatches.TryGetValue(textureName, out messages) || messages.Count == 0)
            {
                return(false);
            }

            GetRenderProfiler().StartProfilingBlock("ProcessDrawQueue");

            foreach (var message in messages)
            {
                ProfilerShort.Begin(message.MessageType.ToString());
                ProcessDrawMessage(message);
                ProfilerShort.End();
            }
            messages.Clear();

            if (textureName == DEFAULT_TEXTURE_TARGET && MyRenderProxy.DrawRenderStats >= MyRenderProxy.MyStatsState.Draw)
            {
                // Stats will be drawn one frame later
                ProfilerShort.Begin("MyRenderStatsDraw.Draw");
                MyGpuProfiler.IC_BeginBlock("MyRenderStatsDraw.Draw");

                if (!m_drawStatsSwitch)
                {
                    MyRenderStatsDraw.Draw(MyRenderStats.m_stats, 0.6f, VRageMath.Color.Yellow);
                }
                else
                {
                    MyStatsUpdater.UpdateStats();
                    MyStatsDisplay.Draw();
                }

                if (MyRenderProxy.DrawRenderStats == MyRenderProxy.MyStatsState.MoveNext)
                {
                    MyRenderProxy.DrawRenderStats = MyRenderProxy.MyStatsState.Draw;

                    if (!m_drawStatsSwitch)
                    {
                        m_drawStatsSwitch = !m_drawStatsSwitch;
                        // We finished cycling through the last page -- signal turning off of drawing stats on the next MoveNext
                        MyRenderProxy.DrawRenderStats = MyRenderProxy.MyStatsState.ShouldFinish;
                    }
                    else
                    {
                        m_drawStatsSwitch = MyStatsDisplay.MoveToNextPage(); // After the last page (returns false), switch to old stat display
                    }
                }

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

            GetRenderProfiler().EndProfilingBlock();
            return(true);
        }
Ejemplo n.º 3
0
        void LogStuff(SharpDXException e)
        {
            if (MyRenderProxy.Log == null)
            {
                return;
            }

            MyRenderProxy.Log.WriteLine("Reason: " + e.Message.Trim());

            if (e.Descriptor == SharpDX.DXGI.ResultCode.DeviceRemoved)
            {
                MyRenderProxy.Log.WriteLine("Reason: " + MyRender11.Device.DeviceRemovedReason);
            }

            MyRenderProxy.Log.WriteMemoryUsage("");
            MyRenderProxy.Log.WriteLine("Buffer type name: " + GetType().Name);
            MyRenderProxy.Log.WriteLine("Buffer debug name: " + Name);
            MyRenderProxy.Log.WriteLine("Buffer description:\n" + BufferDescriptionToString());


            MyRenderProxy.Log.WriteLine("Exception stack trace: " + e.StackTrace);


            StringBuilder sb = new StringBuilder();

            System.Threading.Thread.Sleep(1000);

            foreach (var column in MyRenderStats.m_stats.Values)
            {
                foreach (var stats in column)
                {
                    sb.Clear();
                    stats.WriteTo(sb);
                    MyRenderProxy.Log.WriteLine(sb.ToString());
                }
            }

            MyStatsUpdater.UpdateStats();
            MyStatsDisplay.WriteTo(sb);
            MyRenderProxy.Log.WriteLine(sb.ToString());
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        internal static void Present()
        {
            if (m_swapchain != null)
            {
                GetRenderProfiler().StartProfilingBlock("Screenshot");
                if (m_screenshot.HasValue)
                {
                    if (m_screenshot.Value.SizeMult == VRageMath.Vector2.One)
                    {
                        MyCopyToRT.ClearAlpha(Backbuffer);
                        SaveScreenshotFromResource(Backbuffer);
                    }
                    else
                    {
                        TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult);
                    }
                }
                GetRenderProfiler().EndProfilingBlock();

                try
                {
                    MyManagers.OnFrameEnd();
                    MyGpuProfiler.IC_BeginBlock("Waiting for present");
                    GetRenderProfiler().StartProfilingBlock("Waiting for present");
                    m_swapchain.Present(m_settings.VSync ? 1 : 0, 0);
                    GetRenderProfiler().EndProfilingBlock();
                    MyGpuProfiler.IC_EndBlock();

                    MyStatsUpdater.Timestamps.Update(ref MyStatsUpdater.Timestamps.Present, ref MyStatsUpdater.Timestamps.PreviousPresent);

                    MyManagers.OnUpdate();

                    if (VRage.OpenVRWrapper.MyOpenVR.Static != null)
                    {
                        MyGpuProfiler.IC_BeginBlock("OpenVR.FrameDone");
                        GetRenderProfiler().StartProfilingBlock("OpenVR.FrameDone");

                        /*var handle=MyOpenVR.GetOverlay("menu");
                         * MyOpenVR.SetOverlayTexture(handle, MyRender11.Backbuffer.m_resource.NativePointer);
                         */
                        VRage.OpenVRWrapper.MyOpenVR.FrameDone();
                        GetRenderProfiler().EndProfilingBlock();
                        MyGpuProfiler.IC_EndBlock();
                    }
                }
                catch (SharpDXException e)
                {
                    Log.WriteLine("Graphics device error! Reason:\n" + e.Message);

                    if (e.Descriptor == SharpDX.DXGI.ResultCode.DeviceRemoved)
                    {
                        Log.WriteLine("Device removed reason:\n" + Device.DeviceRemovedReason);
                    }

                    Log.WriteLine("Exception stack trace:\n" + e.StackTrace);

                    StringBuilder sb = new StringBuilder();

                    foreach (var column in MyRenderStats.m_stats.Values)
                    {
                        foreach (var stats in column)
                        {
                            sb.Clear();
                            stats.WriteTo(sb);
                            Log.WriteLine(sb.ToString());
                        }
                    }

                    MyStatsUpdater.UpdateStats();
                    MyStatsDisplay.WriteTo(sb);
                    Log.WriteLine(sb.ToString());

                    throw new MyDeviceErrorException("The graphics device encountered a problem.\nSee the log for more details.");
                }

                GetRenderProfiler().StartProfilingBlock("GPU profiler");
                MyGpuProfiler.EndFrame();
                MyGpuProfiler.StartFrame();
                GetRenderProfiler().EndProfilingBlock();

                // waiting for change to fullscreen - window migh overlap or some other dxgi excuse to fail :(
                GetRenderProfiler().StartProfilingBlock("TryChangeToFullscreen");
                TryChangeToFullscreen();
                GetRenderProfiler().EndProfilingBlock();
            }
        }
Ejemplo n.º 6
0
        internal static void Draw(bool draw = true)
        {
            try
            {
                MyGpuProfiler.IC_BeginBlock("Draw");
                GetRenderProfiler().StartProfilingBlock("ProcessMessages");
                MyGpuProfiler.IC_BeginBlock("ProcessMessageQueue");
                TransferLocalMessages();
                ProcessMessageQueue();
                MyGpuProfiler.IC_EndBlock();
                GetRenderProfiler().EndProfilingBlock();

                if (draw)
                {
                    m_drawScene = false;
                    DispatchDrawQueue();

                    if (m_drawScene)
                    {
                        DrawScene();
                    }

                    if (!(MyRender11.Settings.OffscreenSpritesRendering && m_drawScene))
                    {
                        ProcessDrawQueue();
                        DrawSprites(MyRender11.Backbuffer, new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y));
                    }

                    MyFileTextureManager texManager = MyManagers.FileTextures;
                    texManager.LoadAllRequested();

                    if (m_texturesToRender.Count > 0)
                    {
                        VRage.Render11.PostprocessStage.MySaveExportedTextures.RenderColoredTextures(m_texturesToRender);
                    }
                }

                MyLinesRenderer.Clear();
                MySpritesRenderer.Clear();

                m_drawQueue.Clear();
                MyGpuProfiler.IC_EndBlock();
            }
            catch (SharpDXException e)
            {
                MyRender11.Log.IncreaseIndent();
                MyRender11.Log.WriteLine(" " + e);
                if (e.Descriptor == SharpDX.DXGI.ResultCode.DeviceRemoved)
                {
                    MyRender11.Log.WriteLine("Reason: " + Device.DeviceRemovedReason);
                }

                // Include the stats
                m_exceptionBuilder.Clear();
                MyStatsUpdater.UpdateStats();
                MyStatsDisplay.WriteTo(m_exceptionBuilder);
                MyRender11.Log.WriteLine(m_exceptionBuilder.ToString());
                MyRender11.Log.Flush();
                MyRender11.Log.DecreaseIndent();
                throw;
            }
        }