Beispiel #1
0
        public void InitBuffers(out Buffer Points, out Buffer Regions)
        {
            // get the number of the points
            int SizeOfPoint = ComputeShader.SizeOfFloat2;

            // allocate the 2 buffers
            g_pBuffer1 = ComputeShader.CreateBuffer(MaxNumElements, SizeOfPoint, AccessViewType.SRV | AccessViewType.UAV);
            g_pBuffer1.DebugName = "g_pBuffer1";
            g_pBuffer2 = ComputeShader.CreateBuffer(MaxNumElements, SizeOfPoint, AccessViewType.UAV);
            g_pBuffer2.DebugName = "g_pBuffer2";
            g_pBuffer3 = ComputeShader.CreateBuffer(MaxNumElements, SizeOfPoint, AccessViewType.UAV);
            g_pBuffer3.DebugName = "g_pBuffer3";

            g_pBuffer_HRegions = ComputeShader.CreateBuffer(20000, RegionInfo.GetStructSize(), AccessViewType.UAV);
            g_pBuffer_HRegions.DebugName = "g_pBuffer_HRegions";
            g_pBuffer_VRegions = ComputeShader.CreateBuffer(20000, RegionInfo.GetStructSize(), AccessViewType.UAV);
            g_pBuffer_VRegions.DebugName = "g_pBuffer_VRegions";

            // create the UAVs
            uavBuffer1 = FXResourceVariable.InitUAVResource(this.dev, g_pBuffer1);
            uavBuffer2 = FXResourceVariable.InitUAVResource(this.dev, g_pBuffer2);
            uavBuffer3 = FXResourceVariable.InitUAVResource(this.dev, g_pBuffer3);
            uavHRegions = FXResourceVariable.InitUAVResource(this.dev, g_pBuffer_HRegions);
            uavVRegions = FXResourceVariable.InitUAVResource(this.dev, g_pBuffer_VRegions);

            rvData = new FxResourceVariableList();
            rvInput = new FxResourceVariableList();
            rvRegionsInput = new FxResourceVariableList();
            rvRegionsOutput = new FxResourceVariableList();

            // link the buffers with shaders
            rvData.AddResourceFromShader(CSBitonicSort.m_effect,"Data");

            rvData.AddResourceFromShader(CSMatrixTranspose.m_effect, "Data");
            rvData.AddResourceFromShader(CSCopyRegion.m_effect, "Data");
            rvData.AddResourceFromShader(CSCopySubBuffer.m_effect, "Data");

            rvInput.AddResourceFromShader(CSMatrixTranspose.m_effect, "Input");
            rvInput.AddResourceFromShader(CSFindSplitIndexH.m_effect, "Input");
            rvInput.AddResourceFromShader(CSFindSplitIndexV.m_effect, "Input");
            rvInput.AddResourceFromShader(CSCopyRegion.m_effect, "Input");
            rvInput.AddResourceFromShader(CSCopySubBuffer.m_effect, "Input");

            //rvRegionsInput.AddResourceFromShader(CSFindSplitIndexH.m_effect, "RegionInfoInput");
            rvRegionsInput.AddResourceFromShader(CSFindSplitIndexV.m_effect, "RegionInfoInput");
            rvRegionsInput.AddResourceFromShader(CSCopyRegion.m_effect, "RegionInfoInput");
            rvRegionsInput.AddResourceFromShader(CSFillRegionInfo.m_effect, "RegionInfoInput");

            rvRegionsOutput.AddResourceFromShader(CSFindSplitIndexH.m_effect, "RegionInfoOutput");
            rvRegionsOutput.AddResourceFromShader(CSFindSplitIndexV.m_effect, "RegionInfoOutput");
            //rvRegionsOutput.AddResourceFromShader(CSCopyRegion.m_effect, "RegionInfoOutput");
            rvRegionsOutput.AddResourceFromShader(CSFillRegionInfo.m_effect, "RegionInfoOutput");

            // Bind the CB
            CBBitonic = CSBitonicSort.m_effect.GetConstantBufferByName<cbBitonic>("CB");
            CBTranspose = CSMatrixTranspose.m_effect.GetConstantBufferByName<cbBitonic>("CB");

            CBFindSplitIndexH = CSFindSplitIndexH.m_effect.GetConstantBufferByName<CB_Split>("CB_Split");
            CBFindSplitIndexV = CSFindSplitIndexV.m_effect.GetConstantBufferByName<CB_Split>("CB_Split");
            CBFillRegionInfo = CSFillRegionInfo.m_effect.GetConstantBufferByName<CB_Split>("CB_Split");
            CBCopyRegion =CSCopyRegion.m_effect.GetConstantBufferByName<CB_Split>("CB_Split");
            CBCopySubBuffer = CSCopySubBuffer.m_effect.GetConstantBufferByName<CB_Split>("CB_Split");

            // create a staging buffer
            stagingResult = ComputeShader.CreateStagingBuffer(g_pBuffer1);

            // set the output
            Points = g_pBuffer3;
            Regions = g_pBuffer_HRegions; // this is complex :P
        }
Beispiel #2
0
        public void InitShaders(Device device)
        {
            WriteLine("MaxPointsPerRegion : " + MaxPointsPerRegion.ToString());
            NumVertex = listAllVertex.Count;

            // select the spliting numbers
            // find the split points
            PointsPerRegion = MaxPointsPerRegion;
            NumRegions = (int)Math.Ceiling((float)NumVertex / (float)PointsPerRegion);

            HorizontalRegions = (int)Math.Floor(Math.Sqrt(NumRegions));
            VerticalRegions = (int)Math.Floor((float)NumRegions / (float)HorizontalRegions);

            // recalc the region number
            NumRegions = HorizontalRegions * VerticalRegions;

            // inc the max vertex per region
            maxVertexPerRegion = (int)((float)MaxPointsPerRegion * 1.3f);

            // calc the threads
            mergeVYthreadNum = HorizontalRegions;
            mergeVXthreadNum = VerticalRegions - 1;
            mergeVthreadNum = mergeVXthreadNum * mergeVYthreadNum;
            mergeVXkernelNum = (int)Math.Ceiling(mergeVXthreadNum / MergeVXThread);
            mergeVYkernelNum = (int)Math.Ceiling(mergeVYthreadNum / MergeVYThread);

            mergeHthreadNum = HorizontalRegions - 1;
            mergeHkernelNum = (int)Math.Ceiling(mergeHthreadNum / MergeThread);

            TimeStatistics.StartClock();

            // compile the shader
            if (false)
            {
                CSSubRegions = new ComputeShader(@"Delaunay\Shaders\Triangulation.hlsl", "main", @"Delaunay\Shaders\");
                CSVMerging = new ComputeShader(@"Delaunay\Shaders\MergeVertical.hlsl", "main", @"Delaunay\Shaders\");
                CSHMerging = new ComputeShader(@"Delaunay\Shaders\MergeHorizontal.hlsl", "main", @"Delaunay\Shaders\");
            }
            else
            {
                CSSubRegions = new ComputeShader(@"Delaunay\Shaders_Prebuild\Triangulation.main.fxo");
                CSVMerging = new ComputeShader(@"Delaunay\Shaders_Prebuild\MergeVertical.main.fxo");
                CSHMerging = new ComputeShader(@"Delaunay\Shaders_Prebuild\MergeHorizontal.main.fxo");
            }

            bitonicSort = new BitonicSort(NumVertex, device);

            float time = TimeStatistics.ClockLap("Load Shaders");
            WriteLine("Load Shaders:" + time.ToString());

            TimeStatistics.StartClock();

            // init variables list
            rvlInputPoints = new FxResourceVariableList();
            rvlRegionInfo = new FxResourceVariableList();
            rvlFaceListBuffer = new FxResourceVariableList();
            rvlHalfEdgeListBuffer = new FxResourceVariableList();
            rvlBoundaryListBuffer = new FxResourceVariableList();
            rvlThreadInfoListBuffer = new FxResourceVariableList();
            rvlDelaunayStackBuffer = new FxResourceVariableList();
            rvlUintStackBuffer = new FxResourceVariableList();

            // init the data
            InitDataForCS();

            // init the data
            bitonicSort.InitBuffers(out InputPoints, out RegionInfo);

            // set the data
            bitonicSort.FillData(listAllVertex);

            srvInputPoints = FXResourceVariable.InitSRVResource(device, InputPoints);
            srvRegionInfo = FXResourceVariable.InitSRVResource(device, RegionInfo); // this is complex :P
            stagingInputPointsBuffer = ComputeShader.CreateStagingBuffer(InputPoints);

            // link the resource with buffers
            rvlInputPoints.SetViewsToResources(srvInputPoints);
            rvlRegionInfo.SetViewsToResources(srvRegionInfo);
            rvlFaceListBuffer.SetViewsToResources(uavFaceListBuffer);
            rvlHalfEdgeListBuffer.SetViewsToResources(uavHalfEdgeListBuffer);
            rvlBoundaryListBuffer.SetViewsToResources(uavBoundaryListBuffer);
            rvlThreadInfoListBuffer.SetViewsToResources(uavThreadInfoListBuffer);
            rvlDelaunayStackBuffer.SetViewsToResources(uavDelaunayStackBuffer);
            rvlUintStackBuffer.SetViewsToResources(uavUintStackBuffer);

            time = TimeStatistics.ClockLap("Load Data");
            WriteLine("Load Data:" + time.ToString());

            WriteLine("===================================== Size in bytes:");
            WriteLine("InputPoints Size = " + InputPoints.Description.SizeInBytes.ToString());
            WriteLine("RegionInfo Size = " + RegionInfo.Description.SizeInBytes.ToString());
            WriteLine("FaceListBuffer Size = " + FaceListBuffer.Description.SizeInBytes.ToString());
            WriteLine("HalfEdgeListBuffer Size = " + HalfEdgeListBuffer.Description.SizeInBytes.ToString());
            WriteLine("BoundaryListBuffer Size = " + BoundaryListBuffer.Description.SizeInBytes.ToString());
            WriteLine("ThreadInfoListBuffer Size = " + ThreadInfoListBuffer.Description.SizeInBytes.ToString());
            WriteLine("DelaunayStackBuffer Size = " + DelaunayStackBuffer.Description.SizeInBytes.ToString());
            WriteLine("UintStackBuffer Size = " + UintStackBuffer.Description.SizeInBytes.ToString());
            float sum = InputPoints.Description.SizeInBytes
                        + RegionInfo.Description.SizeInBytes
                        + FaceListBuffer.Description.SizeInBytes
                        + HalfEdgeListBuffer.Description.SizeInBytes
                        + BoundaryListBuffer.Description.SizeInBytes
                        + ThreadInfoListBuffer.Description.SizeInBytes
                        + DelaunayStackBuffer.Description.SizeInBytes
                        + UintStackBuffer.Description.SizeInBytes;

            WriteLine("===================================== Overall size in bytes:" + sum.ToString());
            WriteLine("===================================== Overall size in Mbytes:" + (sum / (1024 * 1024)).ToString());
        }