public async System.Threading.Tasks.Task InitPass(CRenderContext rc, Graphics.CGfxMaterialInstance MtlInst = null, bool isSM3 = false) { if (rc == null) { rc = CEngine.Instance.RenderContext; } if (CRenderContext.ShaderModel >= 4) { UseComputeShader = true; Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: SM = {CRenderContext.ShaderModel},Use ComputeShader"); } else { UseComputeShader = false; Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: SM = {CRenderContext.ShaderModel},CPU Culling"); } if (rc.ContextCaps.MaxVertexShaderStorageBlocks == 0) { UseVTF = true; Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: No SSBO in VertexShader,Use VTF"); } else { UseVTF = false; Profiler.Log.WriteLine(Profiler.ELogTag.Info, "Graphics", $"GpuDriven: Use SSBO in VertexShader"); } if (mMergeInstanceSE == null) { mMergeInstanceSE = mMergeInstanceSE = EngineNS.CEngine.Instance.ShadingEnvManager.GetGfxShadingEnv <CGfxMergeInstanceSE>(); if (UseVTF) { mMergeInstanceSE.SetMacroDefineValue("ENV_USEVTF", "1"); } else { mMergeInstanceSE.SetMacroDefineValue("ENV_USEVTF", "0"); } } if (MtlInst == null) { MtlInst = await CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("Material/defaultmaterial.instmtl")); } if (mPass == null) { var pass = rc.CreatePass(); var meshpri = CEngine.Instance.MeshPrimitivesManager.CreateMeshPrimitives(rc, 1); EngineNS.Graphics.Mesh.CGfxMeshCooker.MakeRect3D(rc, meshpri); //var meshpri = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(rc, CEngineDesc.ScreenAlignedTriangleName, true); var ViewportMesh = CEngine.Instance.MeshManager.CreateMesh(rc, meshpri); ViewportMesh.SetMaterialInstance(rc, 0, MtlInst, CEngine.Instance.PrebuildPassData.DefaultShadingEnvs); var affectLights = new List <GamePlay.SceneGraph.GSceneGraph.AffectLight>(); ViewportMesh.mMeshVars.SetPointLights(affectLights); await pass.InitPassForViewportView(rc, mMergeInstanceSE, MtlInst, ViewportMesh); mPass = pass; var vsDesc = mPass.Effect.ShaderProgram.VertexShader.Desc; var tbInfo = new CTextureBindInfo(); if (vsDesc.GetSRVDesc(vsDesc.FindSRVDesc("AllVertexArray"), ref tbInfo)) { } if (vsDesc.GetSRVDesc(vsDesc.FindSRVDesc("MeshInstanceArray"), ref tbInfo)) { } } //const string CSVersion = "cs_5_0"; var macros = new CShaderDefinitions(); var shaderFile = RName.GetRName("Shaders/Compute/GpuDriven/Cluster.compute", RName.enRNameType.Engine); mCS_MeshBatchDesc = rc.CreateShaderDesc(shaderFile, "CSMain_MeshBatch", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType); mCS_MeshBatch = rc.CreateComputeShader(mCS_MeshBatchDesc); mCS_ClearBatchArgsDesc = rc.CreateShaderDesc(shaderFile, "CSMain_ClearBatchArgs", EShaderType.EST_ComputeShader, macros, CIPlatform.Instance.PlatformType); mCS_ClearBatchArgs = rc.CreateComputeShader(mCS_ClearBatchArgsDesc); var cbIndex = mCS_MeshBatchDesc.FindCBufferDesc("cbMeshBatch"); if (cbIndex != uint.MaxValue) { mCBMeshBatch = rc.CreateConstantBuffer(mCS_MeshBatchDesc, cbIndex); } }