public static void CaptureGeoBox(EngineNS.Bricks.HollowMaker.Agent.GeoBox geoBox, EngineNS.Bricks.HollowMaker.GeomScene.AgentBoxs agentData, EngineNS.Graphics.CGfxCamera camera, EngineNS.CRenderContext rc, UInt32 numElem, EngineNS.Graphics.RenderPolicy.CGfxRP_SceneCapture rp, EngineNS.CCommandList cmd, UInt32 cbIndex, EngineNS.CConstantBuffer cbuffer, EngineNS.CGpuBuffer buffer_visible, EngineNS.CShaderDesc csMain_visible, EngineNS.CComputeShader cs_visible, EngineNS.CUnorderedAccessView uav_visible, EngineNS.CGpuBuffer buffer_setBit, EngineNS.CShaderDesc csMain_setBit, EngineNS.CComputeShader cs_setBit, EngineNS.CUnorderedAccessView uav_setBit, EngineNS.CComputeShader cs_Clear, List <EngineNS.Support.BitSet> savedBitsets, UInt32 textureIdx, Action <int, EngineNS.Support.CBlobObject, EngineNS.Support.CBlobObject> actionAfterCapturePerDir) { var cornerPos = geoBox.Box.GetCorners(); //for(int posIdx = 0; posIdx < cornerPos.Length; posIdx++) //{ // await CaptureSceneWithPoint(cornerPos[posIdx], world, camera, rc, camDirs, camUps, dataBlobs, picBlobs); //} cmd.SetComputeShader(cs_visible); UInt32[] pUAVInitialCounts = new UInt32[1] { 1, }; cmd.CSSetUnorderedAccessView(0, uav_visible, pUAVInitialCounts); //await CaptureSceneWithPoint(geoBox.Box.GetCenter(), agentData.Mat , camera, rc, camDirs, camUps, numElem/*, dataBlobs, picBlobs*/); for (int camIdx = 0; camIdx < 6; camIdx++) { EngineNS.Support.CBlobObject idBlob = null; EngineNS.Support.CBlobObject picBlob = null; EditorCommon.PVSAssist.CaptureWithPoint(geoBox.Box.GetCenter(), agentData.Mat, camera, rc, camDirs[camIdx], camUps[camIdx], numElem, rp, textureIdx, ref idBlob, ref picBlob); actionAfterCapturePerDir?.Invoke(camIdx, idBlob, picBlob); } // gbuffer0 var blob = new EngineNS.Support.CBlobObject(); buffer_visible.GetBufferData(rc, blob); var idArray = blob.ToUInts(); // fill uav1, clear uav0 cmd.SetComputeShader(cs_setBit); UInt32[] pUAVInitialCounts1 = new UInt32[1] { 1, }; cmd.CSSetUnorderedAccessView(0, uav_visible, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(1, uav_setBit, pUAVInitialCounts); var cbDesc = new EngineNS.CConstantBufferDesc(); if (csMain_setBit.GetCBufferDesc(cbIndex, ref cbDesc)) { if (cbDesc.Type == EngineNS.ECBufferRhiType.SIT_CBUFFER) { cmd.CSSetConstantBuffer(cbDesc.CSBindPoint, cbuffer); } } cmd.CSDispatch(numElem, 1, 1); var blob0 = new EngineNS.Support.CBlobObject(); buffer_visible.GetBufferData(rc, blob0); var visArray = blob0.ToUInts(); // gbuffer1 var blob1 = new EngineNS.Support.CBlobObject(); buffer_setBit.GetBufferData(rc, blob1); var idArray1 = blob1.ToBytes(); var bitSet = new EngineNS.Support.BitSet(); var bitSet1 = new EngineNS.Support.BitSet(); bitSet.Init(numElem * 2, idArray1); bitSet1.Init(numElem); for (UInt32 e = 0; e < numElem; e++) { var bit1 = bitSet.IsBit(e * 2 + 0); var bit2 = bitSet.IsBit(e * 2 + 1); bitSet1.SetBit(e, bit1 || bit2); } savedBitsets.Add(bitSet1); cmd.SetComputeShader(cs_Clear); cmd.CSSetUnorderedAccessView(0, uav_visible, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(1, uav_setBit, pUAVInitialCounts); cmd.CSDispatch(numElem / 16 + 1, 1, 1); }
public void ComputeDispatch(CRenderContext rc, EngineNS.CCommandList cmd, Graphics.CGfxCamera Camera) { if (mCS_ClearBatchArgs == null) { return; } UInt32[] pUAVInitialCounts = new UInt32[1] { 1, }; { cmd.SetComputeShader(mCS_ClearBatchArgs); //if (mCS_ClearBatchArgsDesc.GetCBufferDesc("IndirectDrawArgs", ref cbDesc)) // cmd.CSSetUnorderedAccessView(cbDesc.CSBindPoint, uavIndirectDrawArgs, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(5, uavIndirectDrawArgs, pUAVInitialCounts); cmd.CSDispatch(1, 1, 1); cmd.CSSetUnorderedAccessView(5, null, pUAVInitialCounts); } cmd.SetComputeShader(mCS_MeshBatch); //if (mCS_MeshBatchDesc.GetCBufferDesc("MeshInstanceArray", ref cbDesc)) // cmd.CSSetUnorderedAccessView(cbDesc.CSBindPoint, uavMeshInstanceArray, pUAVInitialCounts); //if (mCS_MeshBatchDesc.GetCBufferDesc("ClusterArray", ref cbDesc)) // cmd.CSSetUnorderedAccessView(cbDesc.CSBindPoint, uavClusterArray, pUAVInitialCounts); //if (mCS_MeshBatchDesc.GetCBufferDesc("StaticSceneAllFaces", ref cbDesc)) // cmd.CSSetUnorderedAccessView(cbDesc.CSBindPoint, uavStaticSceneAllFaces, pUAVInitialCounts); //if (mCS_MeshBatchDesc.GetCBufferDesc("StaticSceneDrawFaces", ref cbDesc)) // cmd.CSSetUnorderedAccessView(cbDesc.CSBindPoint, uavStaticSceneDrawFaces, pUAVInitialCounts); //if (mCS_MeshBatchDesc.GetCBufferDesc("IndirectDrawArgs", ref cbDesc)) // cmd.CSSetUnorderedAccessView(cbDesc.CSBindPoint, uavIndirectDrawArgs, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(1, uavMeshInstanceArray, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(2, uavClusterArray, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(3, uavStaticSceneAllFaces, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(4, uavStaticSceneDrawFaces, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(5, uavIndirectDrawArgs, pUAVInitialCounts); UpdateCBMeshbatch(cmd, Camera); mCBMeshBatch.FlushContent(cmd); var cbIndex = mCS_MeshBatchDesc.FindCBufferDesc("cbMeshBatch"); var tmpDesc = new EngineNS.CConstantBufferDesc(); if (mCS_MeshBatchDesc.GetCBufferDesc(cbIndex, ref tmpDesc)) { if (tmpDesc.Type == EngineNS.ECBufferRhiType.SIT_CBUFFER) { cmd.CSSetConstantBuffer(tmpDesc.CSBindPoint, mCBMeshBatch); } } cmd.CSDispatch((uint)((GpuClusters.Count + 63) / 64), 1, 1); cmd.CSSetUnorderedAccessView(1, null, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(2, null, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(3, null, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(4, null, pUAVInitialCounts); cmd.CSSetUnorderedAccessView(5, null, pUAVInitialCounts); cmd.SetComputeShader(null); //unsafe //{ // CEngine.Instance.EventPoster.RunOn(() => // { // var blobDrawArgs = new EngineNS.Support.CBlobObject(); // bufferIndirectDrawArgs.GetBufferData(rc, blobDrawArgs); // EngineNS.Bricks.GpuDriven.GpuScene.GpuDrawArgs* pArg = (EngineNS.Bricks.GpuDriven.GpuScene.GpuDrawArgs*)blobDrawArgs.Data.ToPointer(); // if (pArg != null) // { // mDrawArgs = *pArg; // } // return null; // }, Thread.Async.EAsyncTarget.Main); //} }