Exemplo n.º 1
0
        //[/GLdescription]

        //[LockPositions]
        void LockPos(Del f)
        {
            CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsResourceSetMapFlags(_resources[0],
                                                                             (uint)CUDAInterop.CUgraphicsMapResourceFlags_enum.CU_GRAPHICS_MAP_RESOURCE_FLAGS_READ_ONLY));
            CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsResourceSetMapFlags(_resources[1],
                                                                             (uint)CUDAInterop.CUgraphicsMapResourceFlags_enum.CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD));
            CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsMapResourcesEx(2u, _resources, IntPtr.Zero));

            var bytes   = IntPtr.Zero;
            var handle0 = IntPtr.Zero;
            var handle1 = IntPtr.Zero;

            unsafe
            {
                CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsResourceGetMappedPointer(&handle0, &bytes,
                                                                                      _resources[0]));
                CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsResourceGetMappedPointer(&handle1, &bytes,
                                                                                      _resources[1]));
            }
            var pos0 = new deviceptr <float4>(handle0);
            var pos1 = new deviceptr <float4>(handle1);

            try
            {
                f(pos0, pos1);
            }
            finally
            {
                CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsUnmapResourcesEx(2u, _resources, IntPtr.Zero));
            }
        }
Exemplo n.º 2
0
        unsafe public void Update(IntPtr vbRes, float time)
        {
            // 1. map resource to cuda space, means lock to cuda space
            var vbRes1 = vbRes;

            CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsMapResources(1, &vbRes1, IntPtr.Zero));

            // 2. get memory pointer from mapped resource
            var vbPtr  = IntPtr.Zero;
            var vbSize = IntPtr.Zero;

            CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsResourceGetMappedPointer(&vbPtr, &vbSize, vbRes1));

            // 3. create device pointer, and run the kernel
            var pos = new deviceptr <float4>(vbPtr);

            GPULaunch(Kernel, LaunchParam, pos, time);

            // 4. unmap resource, means unlock, so that DirectX can then use it again
            CUDAInterop.cuSafeCall(CUDAInterop.cuGraphicsUnmapResources(1u, &vbRes1, IntPtr.Zero));
        }