internal IBorrowedUavTexture PostProcess(IDepthArrayTexture cascadeArray) { IBorrowedUavTexture postProcessed = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascades.PostProcess", Format.R8_UNorm); m_cascadePostProcessor.GatherArray(postProcessed, cascadeArray, m_cascadeInfo, m_csmConstants); return(postProcessed); }
internal static IBorrowedUavTexture Skip() { IBorrowedUavTexture borrowedUav = MyManagers.RwTexturesPool.BorrowUav("MyLuminanceAverage.Skip", Format.R32G32_Float); RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.ComputeShader.SetUav(0, borrowedUav); RC.ComputeShader.Set(m_skipShader); RC.Dispatch(1, 1, 1); RC.ComputeShader.SetUav(0, null); //luminance_reduction_skip return(borrowedUav); }
public IBorrowedUavTexture Evaluate() { MyRenderProxy.Assert(m_mainCsm.SlicesCount == m_settings.NewData.CascadesCount, "Cascades count incostistency"); if (m_settings.NewData.DrawVolumes) { ShadowCore.DrawVolumes(); } ShadowCore.MarkAllCascades(MyGBuffer.Main.DepthStencil, MyRender11.Environment.Matrices.ViewProjectionAt0, m_mainCsm); if (m_settings.NewData.DisplayCascadeCoverage) { IBorrowedRtvTexture target = MyManagers.RwTexturesPool.BorrowRtv("MyShadows.Evaluate.CascadeCoverage", Format.R8G8B8A8_SNorm); ShadowCore.DrawCoverage(target, MyGBuffer.Main.DepthStencil); MyDebugTextureDisplay.Select(target); target.Release(); } if (m_settings.NewData.DisplayHardShadows) { IBorrowedUavTexture hardShadowed = MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.HardShadowed", Format.R8_UNorm); ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.HARD, hardShadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings); MyDebugTextureDisplay.Select(hardShadowed); hardShadowed.Release(); } if (m_settings.NewData.DisplaySimpleShadows) { IBorrowedUavTexture simpleShadowed = MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.SimpleShadowed", Format.R8_UNorm); ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.SIMPLE, simpleShadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings); MyDebugTextureDisplay.Select(simpleShadowed); simpleShadowed.Release(); } IBorrowedUavTexture shadowed = MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.Shadowed", Format.R8_UNorm); ShadowCore.ApplyPostprocess(MyPostprocessShadows.Type.SIMPLE, shadowed, MyGBuffer.Main.DepthStencil, m_mainCsm, ref m_settings); if (m_settings.NewData.EnableFXAAOnShadows) { IBorrowedUavTexture inputForFXAA = MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.InputForFXAA", Format.R8G8B8A8_UNorm); ShadowCore.CopyRedToAll(inputForFXAA, shadowed); IBorrowedUavTexture shadowedWithFXAA = MyManagers.RwTexturesPool.BorrowUav("MyShadows.Evaluate.ShadowedWithFXAA", Format.R8G8B8A8_UNorm); MyFXAA.Run(shadowedWithFXAA, inputForFXAA); shadowed.Release(); inputForFXAA.Release(); shadowed = shadowedWithFXAA; } return(shadowed); }
public static void Deselect() { m_selRtvTexture = null; m_selUavTexture = null; if (m_selBorrowedRtvTexture != null) { m_selBorrowedRtvTexture.Release(); m_selBorrowedRtvTexture = null; } if (m_selBorrowedUavTexture != null) { m_selBorrowedUavTexture.Release(); m_selBorrowedUavTexture = null; } }
public static IBorrowedUavTexture CreateHistogram(ISrvBindable texture, int samples) { Vector2I resolution = texture.Size; IBorrowedUavTexture histogram = MyManagers.RwTexturesPool.BorrowUav("MyHdrDebugTools.Histogram", 513, 1, SharpDX.DXGI.Format.R32_UInt); RC.ClearUav(histogram, Int4.Zero); RC.ComputeShader.Set(m_buildHistogram); RC.ComputeShader.SetSrv(0, texture); RC.ComputeShader.SetUav(0, histogram); var buffer = MyCommon.GetObjectCB(16); var mapping = MyMapping.MapDiscard(buffer); mapping.WriteAndPosition(ref resolution.X); mapping.WriteAndPosition(ref resolution.Y); mapping.Unmap(); RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16)); RC.Dispatch((resolution.X + m_numthreads - 1) / m_numthreads, (resolution.Y + m_numthreads - 1) / m_numthreads, 1); RC.ComputeShader.Set(null); return(histogram); }
internal static IBorrowedUavTexture Run(ISrvBindable src) { IBorrowedUavTexture uav0 = MyManagers.RwTexturesPool.BorrowUav("MyLuminanceAverage.Uav0", Format.R32G32_Float); IBorrowedUavTexture uav1 = MyManagers.RwTexturesPool.BorrowUav("MyLuminanceAverage.Uav1", Format.R32G32_Float); Vector2I size = src.Size; int texelsNum = size.X * size.Y; uint sizeX = (uint)size.X; uint sizeY = (uint)size.Y; var buffer = MyCommon.GetObjectCB(16); var mapping = MyMapping.MapDiscard(buffer); mapping.WriteAndPosition(ref sizeX); mapping.WriteAndPosition(ref sizeY); mapping.WriteAndPosition(ref texelsNum); mapping.Unmap(); RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16)); RC.ComputeShader.Set(m_initialShader); IBorrowedUavTexture output = uav0; ISrvBindable inputSrc = src; RC.ComputeShader.SetUav(0, output); RC.ComputeShader.SetSrv(0, inputSrc); int threadGroupCountX = ComputeGroupCount(size.X); int threadGroupCountY = ComputeGroupCount(size.Y); RC.Dispatch(threadGroupCountX, threadGroupCountY, 1); RC.ComputeShader.Set(m_sumShader); IBorrowedUavTexture input; int i = 0; while (true) { size.X = threadGroupCountX; size.Y = threadGroupCountY; if (size.X <= NUM_THREADS && size.Y <= NUM_THREADS) { break; } output = (i % 2 == 0) ? uav1 : uav0; input = (i % 2 == 0) ? uav0 : uav1; RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetUav(0, output); RC.ComputeShader.SetSrv(0, input); threadGroupCountX = ComputeGroupCount(size.X); threadGroupCountY = ComputeGroupCount(size.Y); RC.Dispatch(threadGroupCountX, threadGroupCountY, 1); i++; } RC.ComputeShader.Set(m_finalShader); output = (i % 2 == 0) ? uav1 : uav0; input = (i % 2 == 0) ? uav0 : uav1; RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetUav(0, output); RC.ComputeShader.SetSrvs(0, input, m_prevLum); threadGroupCountX = ComputeGroupCount(size.X); threadGroupCountY = ComputeGroupCount(size.Y); RC.Dispatch(threadGroupCountX, threadGroupCountY, 1); RC.ComputeShader.Set(null); RC.ComputeShader.SetUav(0, null); // Backup the result for later process RC.CopySubresourceRegion(output.Resource, 0, new ResourceRegion(0, 0, 0, 1, 1, 1), m_prevLum.Resource, 0); input.Release(); return(output); }
internal static void Render() { IBorrowedUavTexture accumTarget = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.AccumTarget", Format.R16G16B16A16_Float); IBorrowedUavTexture coverageTarget = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.CoverageTarget", Format.R16_UNorm); ProfilerShort.Begin("Atmosphere"); MyGpuProfiler.IC_BeginBlock("Atmosphere"); if (MyRender11.DebugOverrides.Atmosphere) { MyAtmosphereRenderer.Render(); } ProfilerShort.BeginNextBlock("Clouds"); MyGpuProfiler.IC_BeginNextBlock("Clouds"); if (MyRender11.DebugOverrides.Clouds) { MyCloudRenderer.Render(); } MyGpuProfiler.IC_EndBlock(); // setup weighted blended OIT targets + blend states SetupTargets(accumTarget, coverageTarget, true); IDepthStencil depthResource; if (MyRender11.MultisamplingEnabled) { depthResource = MyScreenDependants.m_resolvedDepth; } else { depthResource = MyGBuffer.Main.DepthStencil; } m_windowsWithDecals.Clear(); ProfilerShort.BeginNextBlock("Billboards"); MyGpuProfiler.IC_BeginBlock("Billboards"); bool resetBindings = MyBillboardRenderer.Gather(HandleWindow); if (resetBindings) { SetupTargets(accumTarget, coverageTarget, false); } MyBillboardRenderer.Render(depthResource.SrvDepth); ProfilerShort.BeginNextBlock("GPU Particles"); MyGpuProfiler.IC_BeginNextBlock("GPU Particles"); if (MyRender11.DebugOverrides.GPUParticles) { MyGPUParticleRenderer.Run(depthResource.SrvDepth); } MyGpuProfiler.IC_EndBlock(); // Render decals on transparent surfaces in 2 steps: first far, second proximity float intervalMax = MyScreenDecals.VISIBLE_DECALS_SQ_TH; for (int it = 0; it < m_distances.Length; it++) { float intervalMin = m_distances[it]; ProfilerShort.BeginNextBlock("Billboards - Depth Only"); MyGpuProfiler.IC_BeginBlock("Billboards - Depth Only"); bool windowsFound = MyBillboardRenderer.RenderWindowsDepthOnly(depthResource, MyGlobalResources.Gbuffer1Copy, intervalMin, intervalMax); MyGpuProfiler.IC_EndBlock(); if (windowsFound) { SetupTargets(accumTarget, coverageTarget, false); ProfilerShort.BeginNextBlock("Render decals - Transparent"); MyGpuProfiler.IC_BeginBlock("Render decals - Transparent"); MyScreenDecals.Draw(true, m_windowsWithDecals); MyGpuProfiler.IC_EndBlock(); } intervalMax = intervalMin; } if (IsUsedOverlappingHeatMap()) { DisplayOverlappingHeatMap(accumTarget, coverageTarget, MyRender11.Settings.DisplayTransparencyHeatMapInGrayscale); } MyGpuProfiler.IC_BeginBlock("OIT Resolve"); // resolve weighted blended OIT in accum / coverage to LBuffer if (MyRender11.DebugOverrides.OIT) { ResolveOIT(accumTarget, coverageTarget); } else { RC.SetRtv(null); } MyGpuProfiler.IC_EndBlock(); coverageTarget.Release(); accumTarget.Release(); ProfilerShort.End(); }
// Returns the final image and copies it to renderTarget if non-null private static IRtvTexture DrawGameScene(IRtvBindable renderTarget) { MyGpuProfiler.IC_BeginBlockAlways("ClearAndGeometryRender"); PrepareGameScene(); // todo: shouldn't be necessary if (true) { ProfilerShort.Begin("Clear"); MyRender11.RC.ClearState(); ProfilerShort.End(); } if (MyStereoRender.Enable && MyStereoRender.EnableUsingStencilMask) { ProfilerShort.Begin("MyStereoStencilMask.Draw"); MyGpuProfiler.IC_BeginBlock("MyStereoStencilMask.Draw"); MyStereoStencilMask.Draw(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); } MyGpuProfiler.IC_BeginBlock("MyGeometryRenderer.Render"); Debug.Assert(m_commandLists.Count == 0, "Not all command lists executed last frame!"); ProfilerShort.Begin("DynamicGeometryRenderer"); DynamicGeometryRenderer.Render(m_commandLists, true); ProfilerShort.End(); // End function block if (MyScene.SeparateGeometry) { ProfilerShort.Begin("StaticGeometryRenderer"); StaticGeometryRenderer.Render(m_commandLists, false); ProfilerShort.End(); // End function block } SendGlobalOutputMessages(); ExecuteCommandLists(m_commandLists); MyGpuProfiler.IC_EndBlock(); #if !UNSHARPER_TMP MyManagers.EnvironmentProbe.FinalizeEnvProbes(); #endif // cleanup context atfer deferred lists if (true) { ProfilerShort.Begin("Clear3"); MyRender11.RC.ClearState(); ProfilerShort.End(); } MyGpuProfiler.IC_EndBlockAlways(); ProfilerShort.Begin("Render decals - Opaque"); MyGpuProfiler.IC_BeginBlock("Render decals - Opaque"); MyImmediateRC.RC.CopyResource(MyGBuffer.Main.GBuffer1.Resource, MyGlobalResources.Gbuffer1Copy.Resource); // copy gbuffer1 MyScreenDecals.Draw(false); MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Render foliage"); MyGpuProfiler.IC_BeginBlockAlways("RenderFoliage"); m_foliageRenderer.Render(); MyGpuProfiler.IC_EndBlockAlways(); MyGpuProfiler.IC_BeginBlock("GBuffer Resolve"); ProfilerShort.BeginNextBlock("MySceneMaterials.MoveToGPU"); MySceneMaterials.MoveToGPU(); MyRender11.RC.ResetTargets(); int nPasses = MyStereoRender.Enable ? 2 : 1; for (int i = 0; i < nPasses; i++) { if (MyStereoRender.Enable) { MyStereoRender.RenderRegion = i == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT; } if (MultisamplingEnabled) { MyRender11.RC.ClearDsv(MyScreenDependants.m_resolvedDepth, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0); MyGpuProfiler.IC_BeginBlock("MarkAAEdges"); MyAAEdgeMarking.Run(); MyGpuProfiler.IC_EndBlock(); MyDepthResolve.Run(MyScreenDependants.m_resolvedDepth, MyGBuffer.Main.DepthStencil); } ProfilerShort.BeginNextBlock("Shadows"); MyGpuProfiler.IC_BeginBlockAlways("Shadows"); IBorrowedUavTexture postProcessedShadows; if (MyScene.SeparateGeometry) { MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades); postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray); //MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, // DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades); //postProcessedShadows = // DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray); } else { postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(DynamicShadows.ShadowCascades.CascadeShadowmapArray); //postProcessedShadows = MyManagers.Shadow.Evaluate(); } MyGpuProfiler.IC_EndBlockAlways(); if (MySSAO.Params.Enabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO) { ProfilerShort.BeginNextBlock("SSAO"); MyGpuProfiler.IC_BeginBlockAlways("SSAO"); MySSAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth); if (MySSAO.Params.UseBlur) { MyBlur.Run(MyScreenDependants.m_ambientOcclusion, MyScreenDependants.m_ambientOcclusionHelper, MyScreenDependants.m_ambientOcclusion, clearColor: Color4.White); } MyGpuProfiler.IC_EndBlockAlways(); } else if (MyHBAO.Params.Enabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO) { ProfilerShort.BeginNextBlock("HBAO"); MyGpuProfiler.IC_BeginBlock("HBAO"); MyHBAO.Run(MyScreenDependants.m_ambientOcclusion, MyGBuffer.Main, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth); MyGpuProfiler.IC_EndBlock(); } else { MyRender11.RC.ClearRtv(MyScreenDependants.m_ambientOcclusion, Color4.White); } ProfilerShort.BeginNextBlock("Lights"); MyGpuProfiler.IC_BeginBlockAlways("Lights"); if (m_debugOverrides.Lighting) { MyLightRendering.Render(postProcessedShadows); } MyGpuProfiler.IC_EndBlockAlways(); postProcessedShadows.Release(); if (MyRender11.DebugOverrides.Flares) { MyLightRendering.DrawFlares(); } } MyStereoRender.RenderRegion = MyStereoRegion.FULLSCREEN; MyGpuProfiler.IC_EndBlock(); // Rendering for VR is solved inside of Transparent rendering ProfilerShort.BeginNextBlock("Transparent Pass"); MyGpuProfiler.IC_BeginBlockAlways("TransparentPass"); if (m_debugOverrides.Transparent) { MyTransparentRendering.Render(); } MyGpuProfiler.IC_EndBlockAlways(); ProfilerShort.BeginNextBlock("PostProcess"); MyGpuProfiler.IC_BeginBlockAlways("PostProcess"); MyGpuProfiler.IC_BeginBlock("Luminance reduction"); IBorrowedUavTexture avgLum = null; if (MyRender11.Postprocess.EnableEyeAdaptation) { if (m_resetEyeAdaptation) { MyLuminanceAverage.Reset(); m_resetEyeAdaptation = false; } avgLum = MyLuminanceAverage.Run(MyGBuffer.Main.LBuffer); } else { avgLum = MyLuminanceAverage.Skip(); } MyGpuProfiler.IC_EndBlock(); IBorrowedUavTexture histogram = null; if (MyRender11.Settings.DisplayHistogram) { histogram = MyHdrDebugTools.CreateHistogram(MyGBuffer.Main.LBuffer, MyGBuffer.Main.SamplesCount); } if (MyRender11.Settings.DisplayHdrIntensity) { MyHdrDebugTools.DisplayHdrIntensity(MyGBuffer.Main.LBuffer); } MyGpuProfiler.IC_BeginBlock("Bloom"); IBorrowedUavTexture bloom; if (m_debugOverrides.Postprocessing && m_debugOverrides.Bloom) { bloom = MyBloom.Run(MyGBuffer.Main.LBuffer, MyGBuffer.Main.GBuffer2, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth); } else { bloom = MyManagers.RwTexturesPool.BorrowUav("bloom_EightScreenUavHDR", MyRender11.ResolutionI.X / 8, MyRender11.ResolutionI.Y / 8, MyGBuffer.LBufferFormat); MyRender11.RC.ClearRtv(bloom, Color4.Black); } MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Tone mapping"); IBorrowedUavTexture tonemapped = MyToneMapping.Run(MyGBuffer.Main.LBuffer, avgLum, bloom, Postprocess.EnableTonemapping && m_debugOverrides.Postprocessing && m_debugOverrides.Tonemapping); bloom.Release(); MyGpuProfiler.IC_EndBlock(); IRtvTexture renderedImage; IBorrowedCustomTexture rgba8_0 = null; bool fxaa = MyRender11.FxaaEnabled; if (fxaa) { rgba8_0 = MyManagers.RwTexturesPool.BorrowCustom("MyRender11.Rgb8_0"); MyGpuProfiler.IC_BeginBlock("FXAA"); MyFXAA.Run(rgba8_0.Linear, tonemapped); MyGpuProfiler.IC_EndBlock(); renderedImage = rgba8_0.SRgb; } else { renderedImage = tonemapped; } ProfilerShort.Begin("Outline"); if (MyOutline.AnyOutline()) { IBorrowedRtvTexture outlined = MyOutline.Run(); MyGpuProfiler.IC_BeginBlock("Outline Blending"); ProfilerShort.Begin("Outline Blending"); if (fxaa) { MyBlendTargets.RunWithStencil( rgba8_0.SRgb, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestOutlineMeshStencil, 0x40); MyBlendTargets.RunWithStencil( rgba8_0.SRgb, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightMeshStencil, 0x40); } else { if (MyRender11.MultisamplingEnabled) { MyBlendTargets.RunWithPixelStencilTest(tonemapped, outlined, MyBlendStateManager.BlendAdditive); MyBlendTargets.RunWithPixelStencilTest(tonemapped, outlined, MyBlendStateManager.BlendTransparent, true); } else { MyBlendTargets.RunWithStencil(tonemapped, outlined, MyBlendStateManager.BlendAdditive, MyDepthStencilStateManager.TestOutlineMeshStencil, 0x40); MyBlendTargets.RunWithStencil(tonemapped, outlined, MyBlendStateManager.BlendTransparent, MyDepthStencilStateManager.TestHighlightMeshStencil, 0x40); } } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); outlined.Release(); } ProfilerShort.End(); if (renderTarget != null) { MyCopyToRT.Run(renderTarget, renderedImage); } if (MyRender11.Settings.DisplayHistogram) { if (renderTarget != null && avgLum != null) { MyHdrDebugTools.DisplayHistogram(renderTarget, avgLum, histogram); } } MyGpuProfiler.IC_EndBlockAlways(); ProfilerShort.End(); if (rgba8_0 != null) { rgba8_0.Release(); } if (histogram != null) { histogram.Release(); } avgLum.Release(); tonemapped.Release(); // HOTFIX: MyDebugTextureDisplay uses borrowed textures. If we place MyDebugTextureDisplay to the different location, we will have problem with borrowed textures (comment by Michal) ProfilerShort.Begin("MyDebugTextureDisplay.Draw"); MyGpuProfiler.IC_BeginBlock("MyDebugTextureDisplay.Draw"); MyDebugTextureDisplay.Draw(MyRender11.Backbuffer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); return(renderedImage); }
internal static void Render(IRtvTexture gbuffer1Copy) { IBorrowedUavTexture accumTarget = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.AccumTarget", Format.R16G16B16A16_Float); IBorrowedUavTexture coverageTarget = MyManagers.RwTexturesPool.BorrowUav("MyTransparentRendering.CoverageTarget", Format.R16_UNorm); ProfilerShort.Begin("Atmosphere"); MyGpuProfiler.IC_BeginBlock("Atmosphere"); if (MyRender11.DebugOverrides.Atmosphere) { MyAtmosphereRenderer.RenderGBuffer(); } ProfilerShort.BeginNextBlock("Clouds"); MyGpuProfiler.IC_BeginNextBlock("Clouds"); if (MyRender11.DebugOverrides.Clouds) { MyCloudRenderer.Render(); } var depthResource = MyGBuffer.Main.ResolvedDepthStencil; // setup weighted blended OIT targets + blend states if (MyRender11.Settings.DrawBillboards) { ProfilerShort.BeginNextBlock("Billboards"); MyGpuProfiler.IC_BeginNextBlock("Billboards"); MyBillboardRenderer.Gather(); MyBillboardRenderer.RenderAdditveBottom(depthResource.SrvDepth); SetupTargets(accumTarget, coverageTarget, true); MyBillboardRenderer.RenderStandard(depthResource.SrvDepth); } else { SetupTargets(accumTarget, coverageTarget, true); } ProfilerShort.BeginNextBlock("GPU Particles"); MyGpuProfiler.IC_BeginNextBlock("GPU Particles"); if (MyRender11.DebugOverrides.GPUParticles) { MyGPUParticleRenderer.Run(depthResource.SrvDepth, MyGBuffer.Main.GBuffer1); } // Render decals on transparent surfaces in 2 steps: first far, second proximity if (MyRender11.Settings.DrawGlass) { ProfilerShort.BeginNextBlock("Static glass"); MyGpuProfiler.IC_BeginNextBlock("Static glass"); m_glassWithDecals.Clear(); MyStaticGlassRenderer.Render(HandleGlass); float intervalMax = MyScreenDecals.VISIBLE_DECALS_SQ_TH; for (int it = 0; it < m_distances.Length; it++) { float intervalMin = m_distances[it]; ProfilerShort.BeginNextBlock("Glass - Depth Only"); MyGpuProfiler.IC_BeginNextBlock("Glass - Depth Only"); //TODO: This code should properly render glass decals, that they are visible when looking through window on another window // Anyway, it is italian code and it doesnt work. Solve after Beta bool glassFound = MyStaticGlassRenderer.RenderGlassDepthOnly(depthResource, gbuffer1Copy, intervalMin, intervalMax); // if (glassFound) { SetupTargets(accumTarget, coverageTarget, false); ProfilerShort.BeginNextBlock("Render decals - Transparent"); MyGpuProfiler.IC_BeginNextBlock("Render decals - Transparent"); MyScreenDecals.Draw(gbuffer1Copy, true /*, m_glassWithDecals*/); } intervalMax = intervalMin; } } if (IsUsedOverlappingHeatMap()) { DisplayOverlappingHeatMap(accumTarget, coverageTarget, MyRender11.Settings.DisplayTransparencyHeatMapInGrayscale); } MyGpuProfiler.IC_BeginNextBlock("OIT Resolve"); // resolve weighted blended OIT in accum / coverage to LBuffer if (MyRender11.DebugOverrides.OIT) { ResolveOIT(accumTarget, coverageTarget); } ProfilerShort.BeginNextBlock("Billboards"); MyGpuProfiler.IC_BeginNextBlock("Billboards"); if (MyRender11.Settings.DrawBillboards) { MyBillboardRenderer.RenderAdditveTop(depthResource.SrvDepth); } RC.SetRtv(null); MyGpuProfiler.IC_EndBlock(); coverageTarget.Release(); accumTarget.Release(); ProfilerShort.End(); }
// IMPORTANT: The returned object needs to be returned to MyManagers.RwTexturePool after the usage internal static IBorrowedUavTexture Run(ISrvBindable src, ISrvBindable srcGBuffer2, ISrvBindable srcDepth) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.ComputeShader.SetSampler(0, MySamplerStateManager.Default); int screenX = MyRender11.ResolutionI.X; int screenY = MyRender11.ResolutionI.Y; Format formatLBuffer = MyGBuffer.LBufferFormat; MyBorrowedRwTextureManager rwTexturePool = MyManagers.RwTexturesPool; IBorrowedUavTexture uavHalfScreen = rwTexturePool.BorrowUav("MyBloom.UavHalfScreen", screenX / 2, screenY / 2, formatLBuffer); IBorrowedUavTexture uavBlurScreen = rwTexturePool.BorrowUav("MyBloom.UavBlurScreen", screenX / BLOOM_TARGET_SIZE_DIVIDER, screenY / BLOOM_TARGET_SIZE_DIVIDER, formatLBuffer); IBorrowedUavTexture uavBlurScreenHelper = rwTexturePool.BorrowUav("MyBloom.UavBlurScreenHelper", screenX / BLOOM_TARGET_SIZE_DIVIDER, screenY / BLOOM_TARGET_SIZE_DIVIDER, formatLBuffer); RC.ComputeShader.SetUav(0, uavHalfScreen); RC.ComputeShader.SetSrv(0, src); RC.ComputeShader.SetSrv(1, srcGBuffer2); RC.ComputeShader.SetSrv(2, srcDepth); RC.ComputeShader.Set(m_bloomShader); var size = uavHalfScreen.Size; VRageMath.Vector2I threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); bool skipDownScale = false; switch (BLOOM_TARGET_SIZE_DIVIDER) { case 2: skipDownScale = true; break; case 4: RC.ComputeShader.Set(m_downscale2Shader); break; case 8: RC.ComputeShader.Set(m_downscale4Shader); break; default: MyRenderProxy.Assert(false, "Invalid bloom target size divider"); break; } size = uavBlurScreen.Size; threadGroups = new VRageMath.Vector2I((size.X + m_numthreads - 1) / m_numthreads, (size.Y + m_numthreads - 1) / m_numthreads); if (!skipDownScale) { RC.ComputeShader.SetConstantBuffer(1, GetCBSize(uavHalfScreen.Size.X, uavHalfScreen.Size.Y)); RC.ComputeShader.SetUav(0, uavBlurScreen); RC.ComputeShader.SetSrv(0, uavHalfScreen); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); } RC.ComputeShader.SetConstantBuffer(1, GetCB_blur(MyStereoRegion.FULLSCREEN, size)); RC.ComputeShader.Set(m_blurV[MyRender11.Postprocess.BloomSize]); RC.ComputeShader.SetUav(0, uavBlurScreenHelper); RC.ComputeShader.SetSrv(0, uavBlurScreen); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetUav(0, null); RC.ComputeShader.Set(m_blurH[MyRender11.Postprocess.BloomSize]); RC.ComputeShader.SetUav(0, uavBlurScreen); RC.ComputeShader.SetSrv(0, uavBlurScreenHelper); int nPasses = 1; if (MyStereoRender.Enable) { threadGroups.X /= 2; nPasses = 2; } for (int nPass = 0; nPass < nPasses; nPass++) { MyStereoRegion region = MyStereoRegion.FULLSCREEN; if (MyStereoRender.Enable) { region = nPass == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT; } RC.ComputeShader.SetConstantBuffer(1, GetCB_blur(region, size)); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); } if (MyRender11.Settings.DisplayBloomFilter) { MyDebugTextureDisplay.Select(uavHalfScreen); } else if (MyRender11.Settings.DisplayBloomMin) { MyDebugTextureDisplay.Select(uavBlurScreen); } RC.ComputeShader.SetUav(0, null); RC.ComputeShader.SetSrv(0, null); uavHalfScreen.Release(); uavBlurScreenHelper.Release(); return(uavBlurScreen); }
internal void GatherArray(IUavTexture postprocessTarget, ISrvBindable cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer) { MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality(); if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED) { RC.ClearUav(postprocessTarget, new RawInt4()); return; } MarkCascadesInStencil(cascadeInfo); MyGpuProfiler.IC_BeginBlock("Cascades postprocess"); if (shadowsQuality == MyShadowsQuality.LOW) { RC.ComputeShader.Set(m_gatherCS_LD); } else if (shadowsQuality == MyShadowsQuality.MEDIUM) { RC.ComputeShader.Set(m_gatherCS_MD); } else if (shadowsQuality == MyShadowsQuality.HIGH) { RC.ComputeShader.Set(m_gatherCS_HD); } RC.ComputeShader.SetUav(0, postprocessTarget); RC.ComputeShader.SetSrv(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth); RC.ComputeShader.SetSrv(1, MyGBuffer.Main.DepthStencil.SrvStencil); RC.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); } //RC.ComputeShader.SetConstantBuffer(4, MyManagers.Shadows.GetCsmConstantBufferOldOne()); RC.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer); RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, cascadeArray); //RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyManagers.Shadow.GetCsmForGbuffer()); Vector2I threadGroups = GetThreadGroupCount(); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); RC.ComputeShader.SetUav(0, null); RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetSrv(1, null); if (shadowsQuality == MyShadowsQuality.HIGH && MyShadowCascades.Settings.Data.EnableShadowBlur) { IBorrowedUavTexture helper = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascadesPostProcess.Helper", Format.R8_UNorm); MyBlur.Run(postprocessTarget, helper, postprocessTarget, depthStencilState: MyDepthStencilStateManager.IgnoreDepthStencil, depthDiscardThreshold: 0.2f, clearColor: Color4.White); helper.Release(); } MyGpuProfiler.IC_EndBlock(); }
// Returns the final image and copies it to renderTarget if non-null private static IRtvTexture DrawGameScene(IRtvBindable renderTarget, out IBorrowedRtvTexture debugAmbientOcclusion) { MyGpuProfiler.IC_BeginBlockAlways("ClearAndGeometryRender"); PrepareGameScene(); // todo: shouldn't be necessary if (true) { ProfilerShort.Begin("Clear"); MyRender11.RC.ClearState(); ProfilerShort.End(); } if (MyStereoRender.Enable && MyStereoRender.EnableUsingStencilMask) { ProfilerShort.Begin("MyStereoStencilMask.Draw"); MyGpuProfiler.IC_BeginBlock("MyStereoStencilMask.Draw"); MyStereoStencilMask.Draw(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); } ProfilerShort.Begin("MyLights.Update"); MyLights.Update(); ProfilerShort.End(); ProfilerShort.Begin("DynamicGeometryRenderer"); MyCullQuery cullQuery = m_dynamicGeometryRenderer.PrepareCullQuery(true); // it is used to share rendering settings between the old and the new pipeline ProfilerShort.End(); MyGpuProfiler.IC_BeginBlock("NewGeometryRenderer"); ProfilerShort.Begin("NewGeometryRenderer"); IGeometrySrvStrategy geometrySrvStrategy = MyManagers.GeometrySrvResolver.GetGeometrySrvStrategy(); if (MyDebugGeometryStage2.EnableNewGeometryPipeline) { MyManagers.GeometryRenderer.Render(cullQuery, geometrySrvStrategy); } ProfilerShort.End(); MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("MyGeometryRenderer.Render"); Debug.Assert(m_commandLists.Count == 0, "Not all command lists executed last frame!"); ProfilerShort.Begin("DynamicGeometryRenderer"); m_dynamicGeometryRenderer.Render(m_commandLists); ProfilerShort.End(); // End function block if (MyScene.SeparateGeometry) { ProfilerShort.Begin("StaticGeometryRenderer"); m_staticGeometryRenderer.Render(m_commandLists); // , false); ProfilerShort.End(); // End function block } SendGlobalOutputMessages(); ExecuteCommandLists(m_commandLists); MyGpuProfiler.IC_EndBlock(); #if !UNSHARPER_TMP MyManagers.EnvironmentProbe.FinalizeEnvProbes(); #endif // cleanup context atfer deferred lists if (true) { ProfilerShort.Begin("Clear3"); MyRender11.RC.ClearState(); ProfilerShort.End(); } MyGpuProfiler.IC_EndBlockAlways(); IBorrowedRtvTexture gbuffer1Copy = MyGBuffer.Main.GetGbuffer1CopyRtv(); ProfilerShort.Begin("Render decals - Opaque"); MyGpuProfiler.IC_BeginBlock("Render decals - Opaque"); MyScreenDecals.Draw(gbuffer1Copy, false); MyGpuProfiler.IC_EndBlock(); IBorrowedDepthStencilTexture depthStencilCopy = null; // Highlights need the depth state before foliage if (MyHighlight.HasHighlights) { depthStencilCopy = MyGBuffer.Main.GetDepthStencilCopyRtv(); } ProfilerShort.BeginNextBlock("Render foliage"); MyGpuProfiler.IC_BeginBlockAlways("RenderFoliage"); m_foliageRenderer.Render(); MyGpuProfiler.IC_EndBlockAlways(); MyGpuProfiler.IC_BeginBlock("GBuffer Resolve"); ProfilerShort.BeginNextBlock("MySceneMaterials.MoveToGPU"); MySceneMaterials.MoveToGPU(); MyRender11.RC.ResetTargets(); IBorrowedRtvTexture ambientOcclusionRtv = MyManagers.RwTexturesPool.BorrowRtv("MyScreenDependants.AmbientOcclusion", ResolutionI.X, ResolutionI.Y, SharpDX.DXGI.Format.R8_UNorm); debugAmbientOcclusion = ambientOcclusionRtv; // Pass the texture to the outside int nPasses = MyStereoRender.Enable ? 2 : 1; for (int i = 0; i < nPasses; i++) { if (MyStereoRender.Enable) { MyStereoRender.RenderRegion = i == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT; } MyGBuffer.Main.ResolveMultisample(); ProfilerShort.BeginNextBlock("Shadows"); MyGpuProfiler.IC_BeginBlockAlways("Shadows"); IBorrowedUavTexture postProcessedShadows; if (MyScene.SeparateGeometry) { MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades); postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray); //MyShadowCascadesPostProcess.Combine(MyShadowCascades.CombineShadowmapArray, // DynamicShadows.ShadowCascades, StaticShadows.ShadowCascades); //postProcessedShadows = // DynamicShadows.ShadowCascades.PostProcess(MyShadowCascades.CombineShadowmapArray); } else { postProcessedShadows = DynamicShadows.ShadowCascades.PostProcess(DynamicShadows.ShadowCascades.CascadeShadowmapArray); //postProcessedShadows = MyManagers.Shadow.Evaluate(); } MyGpuProfiler.IC_EndBlockAlways(); if (MySSAO.Params.Enabled && Settings.User.AmbientOcclusionEnabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO) { ProfilerShort.BeginNextBlock("SSAO"); MyGpuProfiler.IC_BeginBlockAlways("SSAO"); MySSAO.Run(ambientOcclusionRtv, MyGBuffer.Main); if (MySSAO.Params.UseBlur) { IBorrowedRtvTexture ambientOcclusionHelper = MyManagers.RwTexturesPool.BorrowRtv("MyScreenDependants.AmbientOcclusionHelper", ResolutionI.X, ResolutionI.Y, SharpDX.DXGI.Format.R8_UNorm); MyBlur.Run(ambientOcclusionRtv, ambientOcclusionHelper, ambientOcclusionRtv, clearColor: Color4.White); ambientOcclusionHelper.Release(); } MyGpuProfiler.IC_EndBlockAlways(); } else if (MyHBAO.Params.Enabled && Settings.User.AmbientOcclusionEnabled && m_debugOverrides.Postprocessing && m_debugOverrides.SSAO) { ProfilerShort.BeginNextBlock("HBAO"); MyGpuProfiler.IC_BeginBlock("HBAO"); MyHBAO.Run(ambientOcclusionRtv, MyGBuffer.Main); MyGpuProfiler.IC_EndBlock(); } else { MyRender11.RC.ClearRtv(ambientOcclusionRtv, Color4.White); } ProfilerShort.BeginNextBlock("Lights"); MyGpuProfiler.IC_BeginBlockAlways("Lights"); if (m_debugOverrides.Lighting) { MyLightsRendering.Render(postProcessedShadows, ambientOcclusionRtv); } MyGpuProfiler.IC_EndBlockAlways(); postProcessedShadows.Release(); if (MyRender11.DebugOverrides.Flares) { MyLightsRendering.DrawFlares(); } } MyStereoRender.RenderRegion = MyStereoRegion.FULLSCREEN; MyGpuProfiler.IC_EndBlock(); ProfilerShort.BeginNextBlock("Occlusion Queries"); MyGpuProfiler.IC_BeginBlock("Occlusion Queries"); MyOcclusionQueryRenderer.Render(RC, MyGBuffer.Main.ResolvedDepthStencil, MyGBuffer.Main.LBuffer); MyGpuProfiler.IC_EndBlock(); // Rendering for VR is solved inside of Transparent rendering ProfilerShort.BeginNextBlock("Transparent Pass"); MyGpuProfiler.IC_BeginBlockAlways("TransparentPass"); if (m_debugOverrides.Transparent) { MyTransparentRendering.Render(gbuffer1Copy); } MyGpuProfiler.IC_EndBlockAlways(); gbuffer1Copy.Release(); ProfilerShort.BeginNextBlock("PostProcess"); MyGpuProfiler.IC_BeginBlockAlways("PostProcess"); MyGpuProfiler.IC_BeginBlock("Luminance reduction"); IBorrowedUavTexture avgLum = null; if (MyRender11.Postprocess.EnableEyeAdaptation) { if (m_resetEyeAdaptation) { MyLuminanceAverage.Reset(); m_resetEyeAdaptation = false; } avgLum = MyLuminanceAverage.Run(MyGBuffer.Main.LBuffer); } else { avgLum = MyLuminanceAverage.Skip(); } MyGpuProfiler.IC_EndBlock(); IBorrowedUavTexture histogram = null; if (MyRender11.Settings.DisplayHistogram) { histogram = MyHdrDebugTools.CreateHistogram(MyGBuffer.Main.LBuffer, MyGBuffer.Main.SamplesCount); } if (MyRender11.Settings.DisplayHdrIntensity) { MyHdrDebugTools.DisplayHdrIntensity(MyGBuffer.Main.LBuffer); } MyGpuProfiler.IC_BeginBlock("Bloom"); IBorrowedUavTexture bloom; if (m_debugOverrides.Postprocessing && m_debugOverrides.Bloom) { bloom = MyBloom.Run(MyGBuffer.Main.LBuffer, MyGBuffer.Main.GBuffer2, MyGBuffer.Main.ResolvedDepthStencil.SrvDepth); } else { bloom = MyManagers.RwTexturesPool.BorrowUav("bloom_EightScreenUavHDR", MyRender11.ResolutionI.X / 8, MyRender11.ResolutionI.Y / 8, MyGBuffer.LBufferFormat); MyRender11.RC.ClearRtv(bloom, Color4.Black); } MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Tone mapping"); IBorrowedUavTexture tonemapped = MyToneMapping.Run(MyGBuffer.Main.LBuffer, avgLum, bloom, Postprocess.EnableTonemapping && m_debugOverrides.Postprocessing && m_debugOverrides.Tonemapping); bloom.Release(); MyGpuProfiler.IC_EndBlock(); IRtvTexture renderedImage; IBorrowedCustomTexture fxaaTarget = null; bool fxaa = MyRender11.FxaaEnabled; if (fxaa) { fxaaTarget = MyManagers.RwTexturesPool.BorrowCustom("MyRender11.FXAA.Rgb8"); MyGpuProfiler.IC_BeginBlock("FXAA"); MyFXAA.Run(fxaaTarget.Linear, tonemapped); MyGpuProfiler.IC_EndBlock(); renderedImage = fxaaTarget.SRgb; } else { renderedImage = tonemapped; } ProfilerShort.Begin("MyHighlight.Run"); MyHighlight.Run(renderedImage, fxaaTarget, depthStencilCopy); ProfilerShort.End(); if (depthStencilCopy != null) { depthStencilCopy.Release(); } if (renderTarget != null) { MyCopyToRT.Run(renderTarget, renderedImage); } if (MyRender11.Settings.DisplayHistogram) { if (renderTarget != null && avgLum != null) { MyHdrDebugTools.DisplayHistogram(renderTarget, avgLum, histogram); } } MyGpuProfiler.IC_EndBlockAlways(); ProfilerShort.End(); if (fxaaTarget != null) { fxaaTarget.Release(); } if (histogram != null) { histogram.Release(); } avgLum.Release(); tonemapped.Release(); // HOTFIX: MyDebugTextureDisplay uses borrowed textures. If we place MyDebugTextureDisplay to the different location, we will have problem with borrowed textures (comment by Michal) ProfilerShort.Begin("MyDebugTextureDisplay.Draw"); MyGpuProfiler.IC_BeginBlock("MyDebugTextureDisplay.Draw"); MyDebugTextureDisplay.Draw(MyRender11.Backbuffer); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); return(renderedImage); }
public static void Select(IBorrowedUavTexture tex) { Deselect(); tex.AddRef(); m_selBorrowedUavTexture = tex; }