public void SetRays <T>(T[] rays) where T : struct { if (_query == null) { _query = new PrimeQuery(_context, _model, QueryType.ClosestHit); } if (_rayBuffer == null) { _rayBuffer = _context.CreateBuffer(_bufferType, _rayFormat == RayFormat.OriginDirectionMinMaxInterleaved ? RtpBufferFormat.RTP_BUFFER_FORMAT_RAY_ORIGIN_TMIN_DIRECTION_TMAX : RtpBufferFormat.RTP_BUFFER_FORMAT_RAY_ORIGIN_DIRECTION, rays); _rayBuffer.SetRange(0u, (ulong)rays.Length); _hitBuffer = _context.CreateBuffer(_bufferType, RtpBufferFormat.RTP_BUFFER_FORMAT_HIT_T_TRIID_U_V, Enumerable.Repeat(new Hit { t = 1e-4f }, rays.Length).ToArray()); _hitBuffer.SetRange(0u, (ulong)rays.Length); //_hitBuffer.Lock(); _query.SetRays(_rayBuffer); _query.SetHits(_hitBuffer); } else { _rayBuffer.SetData(rays); } }
public static unsafe PrimeBuffer Create <T>(PrimeContext ctx, PrimeBufferDesc desc, T[] data) where T : struct { var dataToCopy = new Memory <T>(data); var data2Cpy = dataToCopy.Pin(); var dataLength = Unsafe.SizeOf <T>() * data.Length; var dataPtr = IntPtr.Zero; if (desc.Type == RTPBufferType.CudaLinear) { //CudaDriverApi.CudaCall(CudaDriverApi.cuMemAlloc(ref dataPtr, (uint) dataLength)); CudaRunTimeApi.CudaCall(CudaRunTimeApi.cudaMalloc(ref dataPtr, (uint)dataLength)); CudaRunTimeApi.CudaCall(CudaRunTimeApi.cudaMemcpy(dataPtr.ToPointer(), new IntPtr(data2Cpy.Pointer), (uint)dataLength, CudaMemCpyKind.cudaMemcpyHostToDevice)); // CudaDriverApi.CudaCall(CudaDriverApi.cuMemcpyHtoD(ref dataPtr, data2Cpy.Pointer, (uint) dataLength)); } else { dataPtr = Marshal.AllocHGlobal(dataLength); GC.AddMemoryPressure(dataLength); var span = new Span <T>(data); MemoryHelper.CopyFromManaged(ref span, dataPtr, (uint)data.Length); // Unsafe.Copy(dataPtr.ToPointer(), ref data); } data2Cpy.Dispose(); var buffer = new PrimeBuffer(ctx, desc, dataPtr) { size = dataLength }; return(buffer); }
public PrimeBuffer CreateBuffer <T>(RTPBufferType type, RtpBufferFormat format, T[] data) where T : struct { var desc = new PrimeBufferDesc { Type = type, Format = format }; var buffer = PrimeBuffer.Create(this, desc, data); _buffers.Add(buffer); return(buffer); }
public void SetInstances(PrimeBuffer instances, PrimeBuffer transforms) { CheckError(PrimeApi.rtpModelSetInstances(InternalPtr, instances.InternalPtr, transforms.InternalPtr)); }
public void SetTriangles(PrimeBuffer indices, PrimeBuffer vertices) { CheckError(PrimeApi.rtpModelSetTriangles(InternalPtr, indices?.InternalPtr ?? IntPtr.Zero, vertices.InternalPtr)); }
public void SetHits(PrimeBuffer hits) { CheckError(PrimeApi.rtpQuerySetHits(InternalPtr, hits.InternalPtr)); }
public void SetRays(PrimeBuffer rays) { CheckError(PrimeApi.rtpQuerySetRays(InternalPtr, rays.InternalPtr)); }