private void button1_Click(object sender, EventArgs e) { triangulation = cuda.LoadPTX("Triangulation", "PTX", "Triangulation"); merge_vertical = cuda.LoadPTX("MergeVertical", "PTX", "merge"); regionSplitH = cuda.LoadPTX("RegionSplit", "PTX", "splitRegionH"); regionSplitV_Phase1 = cuda.LoadPTX("RegionSplit", "PTX", "splitRegionV_phase1"); regionSplitV_Phase2 = cuda.LoadPTX("RegionSplit", "PTX", "splitRegionV_phase2"); // add a random points TODO: add external source (ex. file) CreateRandomPoints(1024 * 8, new FxVector2f(0, 0), new FxVector2f(5000, 5000)); #region Set the max face/he/ve/boundary NumVertex = listAllVertex.Count; // select the spliting numbers // find the split points NumRegions = (int)Math.Ceiling((float)NumVertex / (float)maxVertexPerRegion); HorizontalRegions = (int)Math.Floor(Math.Sqrt(NumRegions)); VerticalRegions = (int)Math.Floor((float)NumRegions / (float)HorizontalRegions); NumRegions = HorizontalRegions * VerticalRegions; // init the array sizes // max faces per thread maxFacesPerThread = maxVertexPerRegion * 5; maxFacesPerThread += maxFacesPerThread % 32; // max Half edge per thread maxHalfEdgePerThread = maxFacesPerThread * 5; maxHalfEdgePerThread += maxHalfEdgePerThread % 32; // max vertex per thread maxBoundaryNodesPerThread = maxVertexPerRegion * 5; maxBoundaryNodesPerThread += maxBoundaryNodesPerThread % 32; WriteLine("maxFacesPerThread:" + maxFacesPerThread.ToString()); WriteLine("maxHalfEdgePerThread:" + maxHalfEdgePerThread.ToString()); WriteLine("maxBoundaryNodesPerThread:" + maxBoundaryNodesPerThread.ToString()); #endregion // init the array on cpu side threadInfo = new csThreadInfo[NumRegions]; regionInfo = new RegionInfo[NumRegions]; threadParam = new cbThreadParam(); #region init the thread param // init the thread param threadParam.maxFacesPerThread = (uint)maxFacesPerThread; threadParam.maxHalfEdgePerThread = (uint)maxHalfEdgePerThread; threadParam.maxBoundaryNodesPerThread = (uint)maxBoundaryNodesPerThread; threadParam.RegionsNum = (uint)NumRegions; MV_threadParam.ThreadNumPerRow = (uint)(VerticalRegions-1); MV_threadParam.HorizontalThreadNum = (uint)(HorizontalRegions); MV_threadParam.ThreadNum = MV_threadParam.HorizontalThreadNum * MV_threadParam.ThreadNumPerRow; MV_threadParam.stackMaxSize = stackMaxSize; MV_threadParam.depth = 0; #endregion // copy the data to the hardware d_threadInfo = threadInfo; d_regionInfo = regionInfo; d_threadParam = threadParam; d_FaceList = new CudaDeviceVariable<csFace>(maxFacesPerThread * NumRegions); d_BoundaryList = new CudaDeviceVariable<csBoundaryNode>(maxBoundaryNodesPerThread * NumRegions); d_HalfEdgeList = new CudaDeviceVariable<csHalfEdge>(maxHalfEdgePerThread * NumRegions); d_Stack = new CudaDeviceVariable<csStack>(stackMaxSize * NumRegions); d_UintStack = new CudaDeviceVariable<uint>(2 * stackMaxSize * NumRegions); // Update the region info by sort the vertex // try to sort the list GPUSort = new BitonicSort<FxVector2f>(cuda); }
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()); }