public void TickLogic() { if (mUpdateSelf == false || mEnabled == false) { return; } var RHICtx = EngineNS.CEngine.Instance.RenderContext; if (RHICtx == null || mHitProxyView == null) { return; } ScopeTickLogic.Begin(); //int CurrDPNumber = 0; //CEngine.Instance.HitProxyManager.HitProxyIsNewest = false; //opaque render pass; mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_Opaque, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy); //custom opaque pass; mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_CustomOpaque, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy); //custom translucent render pass; mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_CustomTranslucent, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy); //translucent render pass; mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_Translucent, mCamera, mHitProxySE, PrebuildPassIndex.PPI_HitProxy); //gizmos pass;the coordinary should be rendered in this pass; mHitProxyView.CookSpecRenderLayerDataToPass(RHICtx, ERenderLayer.RL_Gizmos, mCamera, mHitProxyAxisSE, PrebuildPassIndex.PPI_HitProxy); var CmdList = mCLDB_HitProxy[0]; CmdList.BeginCommand(); CmdList.BeginRenderPass(mRenderPassDesc_HitProxy, mHitProxyView.FrameBuffer); mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_Opaque); mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_CustomOpaque); mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_CustomTranslucent); mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_Translucent); mHitProxyView.PushSpecRenderLayerDataToRHI(CmdList, ERenderLayer.RL_Gizmos); CmdList.BuildRenderPass(); CmdList.EndRenderPass(); CmdList.CreateReadableTexture2D(ref HitProxyTex2D, mHitProxyView.FrameBuffer.GetSRV_RenderTarget(0), mHitProxyView.FrameBuffer); EngineNS.CEngine.Instance.GpuFetchManager.RegFetchTexture2D(HitProxyTex2D, (InSrv) => { if (mHitProxyCPUTexture == null) { mHitProxyCPUTexture = new CBlobObject(); } if (CEngine.Instance.Desc.RHIType == ERHIType.RHT_OGL) { var t1 = EngineNS.Support.Time.HighPrecision_GetTickCount(); unsafe { void *pData; uint rowPitch; uint depthPitch; if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch)) { lock (mHitProxyCPUTexture) { InSrv.BuildImageBlob(mHitProxyCPUTexture, pData, rowPitch); } InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0); } var t2 = EngineNS.Support.Time.HighPrecision_GetTickCount(); //System.Diagnostics.Debug.WriteLine($"Fetch hitproxy time : {t2 - t1}"); } } else { CEngine.Instance.EventPoster.RunOn(() => { var t1 = EngineNS.Support.Time.HighPrecision_GetTickCount(); unsafe { void *pData; uint rowPitch; uint depthPitch; if (InSrv.Map(CEngine.Instance.RenderContext.ImmCommandList, 0, &pData, &rowPitch, &depthPitch)) { lock (mHitProxyCPUTexture) { InSrv.BuildImageBlob(mHitProxyCPUTexture, pData, rowPitch); } InSrv.Unmap(CEngine.Instance.RenderContext.ImmCommandList, 0); } var t2 = EngineNS.Support.Time.HighPrecision_GetTickCount(); //System.Diagnostics.Debug.WriteLine($"Fetch hitproxy time : {t2 - t1}"); } return(null); }, Thread.Async.EAsyncTarget.AsyncEditor); } }); CmdList.EndCommand(); ScopeTickLogic.End(); }
public bool Init(UInt32 width, UInt32 height, CGfxCamera camera) { var RHICtx = EngineNS.CEngine.Instance.RenderContext; mViewportSizeX = width; mViewportSizeY = height; //hit proxy view; CGfxSceneViewInfo HitProxyViewInfo = new CGfxSceneViewInfo(); HitProxyViewInfo.mUseDSV = true; HitProxyViewInfo.Width = width; HitProxyViewInfo.Height = height; HitProxyViewInfo.mDSVDesc.Init(); HitProxyViewInfo.mDSVDesc.Format = EngineNS.EPixelFormat.PXF_D24_UNORM_S8_UINT; HitProxyViewInfo.mDSVDesc.Width = width; HitProxyViewInfo.mDSVDesc.Height = height; CRenderTargetViewDesc rtDesc0 = new CRenderTargetViewDesc(); rtDesc0.Init(); rtDesc0.Format = EPixelFormat.PXF_R8G8B8A8_UNORM; rtDesc0.Width = width; rtDesc0.Height = height; HitProxyViewInfo.mRTVDescArray.Add(rtDesc0); mHitProxyView = new CGfxSceneView(); if (false == mHitProxyView.Init(RHICtx, null, HitProxyViewInfo)) { Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError!!!", ""); return(false); } mCamera = camera; mRenderPassDesc_HitProxy = new CRenderPassDesc(); FrameBufferClearColor TempClearColor = new FrameBufferClearColor(); TempClearColor.r = 0.0f; TempClearColor.g = 0.0f; TempClearColor.b = 0.0f; TempClearColor.a = 0.0f; mRenderPassDesc_HitProxy.mFBLoadAction_Color = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_HitProxy.mFBStoreAction_Color = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_HitProxy.mFBClearColorRT0 = TempClearColor; mRenderPassDesc_HitProxy.mFBLoadAction_Depth = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_HitProxy.mFBStoreAction_Depth = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_HitProxy.mDepthClearValue = 1.0f; mRenderPassDesc_HitProxy.mFBLoadAction_Stencil = FrameBufferLoadAction.LoadActionClear; mRenderPassDesc_HitProxy.mFBStoreAction_Stencil = FrameBufferStoreAction.StoreActionStore; mRenderPassDesc_HitProxy.mStencilClearValue = 0u; if (mHitProxySE == null) { mHitProxySE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxHitProxySE>(); } if (mHitProxySE == null) { Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError!!!", ""); return(false); } if (mHitProxyAxisSE == null) { mHitProxyAxisSE = CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxHitProxyAxisSE>(); } if (mHitProxyAxisSE == null) { Profiler.Log.WriteLine(Profiler.ELogTag.Error, "@Graphic", $"HitProxyError!!!", ""); return(false); } mHitProxyCPUTexture = new CBlobObject(); return(true); }