diff --git a/src/Aardvark.Rendering.GL/Resources/Buffers/Buffer.fs b/src/Aardvark.Rendering.GL/Resources/Buffers/Buffer.fs index 50d3495d3..aa8718a11 100644 --- a/src/Aardvark.Rendering.GL/Resources/Buffers/Buffer.fs +++ b/src/Aardvark.Rendering.GL/Resources/Buffers/Buffer.fs @@ -124,7 +124,7 @@ module BufferExtensions = member x.CreateBuffer(data : Array, [] storage : BufferStorage) = let size = nativeint (data.GetType().GetElementType().GLSize) * nativeint data.Length - pinned data (fun src -> + data |> NativeInt.pin (fun src -> x.CreateBuffer(src, size, storage) ) diff --git a/src/Aardvark.Rendering.GL/Resources/Pointers.fs b/src/Aardvark.Rendering.GL/Resources/Pointers.fs index db7f4d9df..d4ddae60d 100644 --- a/src/Aardvark.Rendering.GL/Resources/Pointers.fs +++ b/src/Aardvark.Rendering.GL/Resources/Pointers.fs @@ -185,7 +185,7 @@ module PointerContextExtensions = | :? C4b as c -> c.ToArray() | _ -> value - pinned value (fun pValue -> + value |> NativeInt.pin (fun pValue -> let mutable pSrc = pValue for r = 0 to dim.Y - 1 do diff --git a/src/Aardvark.Rendering.GL/Resources/Textures/TextureDownload.fs b/src/Aardvark.Rendering.GL/Resources/Textures/TextureDownload.fs index ae025e45d..b9148699c 100644 --- a/src/Aardvark.Rendering.GL/Resources/Textures/TextureDownload.fs +++ b/src/Aardvark.Rendering.GL/Resources/Textures/TextureDownload.fs @@ -171,7 +171,7 @@ module internal TextureDownloadImplementation = let pixelType = PixelType.ofType image.PixFormat.Type let pixelFormat = PixelFormat.ofColFormat texture.Format.IsIntegerFormat image.Format - pinned image.Array (fun dst -> + image.Array |> NativeInt.pin (fun dst -> let dstInfo = image.VolumeInfo.ToXYWTensor4'().AsBytes(elementSize) downloadNative texture level slice offset size 0 elementSize pixelFormat pixelType dst dstInfo ) @@ -182,7 +182,7 @@ module internal TextureDownloadImplementation = let pixelType = PixelType.ofType volume.PixFormat.Type let pixelFormat = PixelFormat.ofColFormat texture.Format.IsIntegerFormat volume.Format - pinned volume.Array (fun dst -> + volume.Array |> NativeInt.pin (fun dst -> let dstInfo = volume.Tensor4Info.AsBytes(elementSize) downloadNative texture level 0 offset volume.Size 0 elementSize pixelFormat pixelType dst dstInfo ) @@ -190,14 +190,14 @@ module internal TextureDownloadImplementation = let inline private copyUnsignedNormalizedDepth (matrix : Matrix) (shift : int) (maxValue : ^T) (channels : int) (elementSize : int) (alignedLineSize : nativeint) (src : nativeint) = - pinned matrix.Array (fun dst -> + matrix.Data |> NativePtr.pinArr (fun dst -> let src = let info = Tensor4Info.deviceLayout true elementSize alignedLineSize channels matrix.Size.XYI src |> NativeTensor4.ofNativeInt info let dst = let info = matrix.AsVolume().Info.ToXYWTensor4'().AsBytes() - dst |> NativeTensor4.ofNativeInt info + dst.Address |> NativeTensor4.ofNativeInt info (src, dst) ||> NativeTensor4.iterPtr2 (fun _ src dst -> let src : nativeptr<'T> = NativePtr.cast src @@ -246,9 +246,9 @@ module internal TextureDownloadImplementation = downloadGeneralPixelData texture level slice offset size format typ copy | FloatingPointDepth (format, typ) -> - pinned matrix.Array (fun dst -> + matrix.Data |> NativePtr.pinArr (fun dst -> let dstInfo = matrix.AsVolume().Info.ToXYWTensor4'().AsBytes() - downloadNative texture level slice offset.XYO size 0 sizeof format typ dst dstInfo + downloadNative texture level slice offset.XYO size 0 sizeof format typ dst.Address dstInfo ) | fmt -> failwithf "[GL] %A is not a supported depth format" fmt @@ -265,9 +265,9 @@ module internal TextureDownloadImplementation = match texture.Format with | Stencil(format, typ, byteOffset) -> - pinned matrix.Array (fun dst -> + matrix.Data |> NativePtr.pinArr (fun dst -> let dstInfo = matrix.AsVolume().Info.ToXYWTensor4'().AsBytes() - downloadNative texture level slice offset.XYO size byteOffset sizeof format typ dst dstInfo + downloadNative texture level slice offset.XYO size byteOffset sizeof format typ dst.Address dstInfo ) | fmt -> failwithf "[GL] %A is not a supported stencil format" fmt diff --git a/src/Aardvark.Rendering.Vulkan/Core/Device.fs b/src/Aardvark.Rendering.Vulkan/Core/Device.fs index f9f89ac4d..5ab603287 100644 --- a/src/Aardvark.Rendering.Vulkan/Core/Device.fs +++ b/src/Aardvark.Rendering.Vulkan/Core/Device.fs @@ -768,14 +768,14 @@ and CopyEngine(family : DeviceQueueFamily) = stream.Run cmd.Handle cmd.End() - cmd.Handle |> pin (fun pCmd -> + cmd.Handle |> NativePtr.pin (fun pCmd -> let submit = VkSubmitInfo( 0u, NativePtr.zero, NativePtr.zero, 1u, pCmd, 0u, NativePtr.zero ) - submit |> pin (fun pSubmit -> + submit |> NativePtr.pin (fun pSubmit -> VkRaw.vkQueueSubmit(queue.Handle, 1u, pSubmit, fence.Handle) |> ignore ) ) @@ -1004,7 +1004,7 @@ and [] Resource<'T when 'T : unmanaged and 'T : equality> = base.IsValid && x.handle <> Unchecked.defaultof<_> new(device : Device, handle : 'T, refCount : int) = - handle |> pin device.Instance.RegisterDebugTrace + handle |> NativePtr.pin device.Instance.RegisterDebugTrace { inherit Resource(device, refCount); handle = handle } new(device : Device, handle : 'T) = @@ -1109,7 +1109,7 @@ and DeviceQueue internal(device : Device, deviceHandle : VkDevice, familyInfo : uint32 cmds.Length, pCmdMasks, signalCount, pSignalIndices ) - ext |> pin (fun pExt -> + ext |> NativePtr.pin (fun pExt -> let submit = VkSubmitInfo( @@ -1118,7 +1118,7 @@ and DeviceQueue internal(device : Device, deviceHandle : VkDevice, familyInfo : uint32 cmds.Length, pCmds, uint32 signal.Length, pSignal ) - submit |> pin (fun pSubmit -> + submit |> NativePtr.pin (fun pSubmit -> VkRaw.vkQueueSubmit(handle, 1u, pSubmit, fence) |> check "could not submit command buffer" ) @@ -1132,7 +1132,7 @@ and DeviceQueue internal(device : Device, deviceHandle : VkDevice, familyInfo : uint32 signal.Length, pSignal ) - submit |> pin (fun pSubmit -> + submit |> NativePtr.pin (fun pSubmit -> VkRaw.vkQueueSubmit(handle, 1u, pSubmit, fence) |> check "could not submit command buffer" ) @@ -1400,7 +1400,7 @@ and DeviceCommandPool internal(device : Device, index : int, queueFamily : Devic uint32 index ) let handle = - createInfo |> pin (fun pCreate -> + createInfo |> NativePtr.pin (fun pCreate -> temporary (fun pHandle -> VkRaw.vkCreateCommandPool(device.Handle, pCreate, NativePtr.zero, pHandle) |> check "could not create command pool" @@ -1453,7 +1453,7 @@ and CommandPool internal(device : Device, familyIndex : int, queueFamily : Devic flags |> int |> unbox, uint32 familyIndex ) - createInfo |> pin (fun pCreate -> + createInfo |> NativePtr.pin (fun pCreate -> temporary (fun pHandle -> VkRaw.vkCreateCommandPool(device.Handle, pCreate, NativePtr.zero, pHandle) |> check "could not create command pool" @@ -1685,7 +1685,7 @@ and CommandBuffer internal(device : Device, pool : VkCommandPool, queueFamily : if handle <> 0n && device.Handle <> 0n then releaseResources() - handle |> pin (fun pHandle -> VkRaw.vkFreeCommandBuffers(device.Handle, pool, 1u, pHandle)) + handle |> NativePtr.pin (fun pHandle -> VkRaw.vkFreeCommandBuffers(device.Handle, pool, 1u, pHandle)) handle <- 0n interface IDisposable with @@ -1794,7 +1794,7 @@ and Semaphore internal(device : Device) = let mutable handle = let info = VkSemaphoreCreateInfo.Empty - info |> pin (fun pInfo -> + info |> NativePtr.pin (fun pInfo -> temporary (fun pHandle -> VkRaw.vkCreateSemaphore(device.Handle, pInfo, NativePtr.zero, pHandle) |> check "could not create semaphore" @@ -1826,7 +1826,7 @@ and Event internal(device : Device) = let mutable handle = let info = VkEventCreateInfo.Empty - info |> pin (fun pInfo -> + info |> NativePtr.pin (fun pInfo -> temporary (fun pHandle -> VkRaw.vkCreateEvent(device.Handle, pInfo, NativePtr.zero, pHandle) |> check "could not create event" @@ -1880,7 +1880,7 @@ and DeviceHeap internal(device : Device, physical : PhysicalDevice, memory : Mem ) let mem = - info |> pin (fun pInfo -> + info |> NativePtr.pin (fun pInfo -> temporary (fun pHandle -> VkRaw.vkAllocateMemory(device.Handle, pInfo, NativePtr.zero, pHandle) |> check "could not 'allocate' null pointer for device heap" @@ -2360,7 +2360,7 @@ and [] DevicePtr internal(memory : DeviceMemory, offset : int6 finally if not memory.Heap.IsHostCoherent then let range = VkMappedMemoryRange(memory.Handle, uint64 x.Offset, uint64 x.Size) - range |> pin (fun pRange -> + range |> NativePtr.pin (fun pRange -> VkRaw.vkFlushMappedMemoryRanges(device.Handle, 1u, pRange) |> check "could not flush memory range" ) @@ -2725,7 +2725,7 @@ and DeviceQueueThread(family : DeviceQueueFamily) = uint32 imageBinds.Length, pImageBindInfos, 0u, NativePtr.zero ) - bindInfo |> pin (fun pInfo -> + bindInfo |> NativePtr.pin (fun pInfo -> VkRaw.vkQueueBindSparse(queue.Handle, 1u, pInfo, fence.Handle) |> check "could not bind sparse memory" ) diff --git a/src/Aardvark.Rendering.Vulkan/Core/Platform.fs b/src/Aardvark.Rendering.Vulkan/Core/Platform.fs index 3505587d7..b2176a75f 100644 --- a/src/Aardvark.Rendering.Vulkan/Core/Platform.fs +++ b/src/Aardvark.Rendering.Vulkan/Core/Platform.fs @@ -542,13 +542,13 @@ and PhysicalDevice internal(instance : Instance, handle : VkPhysicalDevice) = if apiVersion >= Version(1,1,0) || hasExtension KHRMaintenance3.Name then let main3 = VkPhysicalDeviceMaintenance3Properties(10u, 10UL) - main3 |> pin (fun pMain3 -> + main3 |> NativePtr.pin (fun pMain3 -> let props = VkPhysicalDeviceProperties2( NativePtr.toNativeInt pMain3, VkPhysicalDeviceProperties() ) - props |> pin (fun pProps -> + props |> NativePtr.pin (fun pProps -> VkRaw.vkGetPhysicalDeviceProperties2(handle, pProps) let props = NativePtr.read pProps let main3 = NativePtr.read pMain3 @@ -572,13 +572,13 @@ and PhysicalDevice internal(instance : Instance, handle : VkPhysicalDevice) = 0u, 0u ) - id |> pin (fun pId -> + id |> NativePtr.pin (fun pId -> let khrProps = VkPhysicalDeviceProperties2KHR( NativePtr.toNativeInt pId, VkPhysicalDeviceProperties() ) - khrProps |> pin (fun pProps -> + khrProps |> NativePtr.pin (fun pProps -> VkRaw.vkGetPhysicalDeviceProperties2(handle, pProps) let id = NativePtr.read pId let uid = sprintf "{ GUID = %A; Mask = %d }" id.deviceUUID id.deviceNodeMask diff --git a/src/Aardvark.Rendering.Vulkan/Core/Utilities.fs b/src/Aardvark.Rendering.Vulkan/Core/Utilities.fs index 5c7892abf..40f34c480 100644 --- a/src/Aardvark.Rendering.Vulkan/Core/Utilities.fs +++ b/src/Aardvark.Rendering.Vulkan/Core/Utilities.fs @@ -127,16 +127,9 @@ module private Utilities = let inline () (v : 'a) = NativePtr.write ptr v let temporary<'a, 'r when 'a : unmanaged> (f : nativeptr<'a> -> 'r) = - native { - let! ptr = Unchecked.defaultof<'a> - return f ptr - } - - let pin (f : nativeptr<'a> -> 'r) (v : 'a) = - native { - let! ptr = v - return f ptr - } + let value = Unchecked.defaultof<'a> + use ptr = fixed &value + f ptr let check (str : string) (err : VkResult) = if err <> VkResult.Success then diff --git a/src/Aardvark.Rendering.Vulkan/Resources/Buffers/IndirectBuffer.fs b/src/Aardvark.Rendering.Vulkan/Resources/Buffers/IndirectBuffer.fs index 1150f8924..ab16f747c 100644 --- a/src/Aardvark.Rendering.Vulkan/Resources/Buffers/IndirectBuffer.fs +++ b/src/Aardvark.Rendering.Vulkan/Resources/Buffers/IndirectBuffer.fs @@ -64,7 +64,7 @@ module IndirectBuffer = let size = nativeint ab.Data.LongLength * nativeint sizeof - pinned ab.Data (fun src -> + ab.Data |> NativeInt.pin (fun src -> device.DeviceMemory |> Buffer.ofWriter false flags size (fun dst -> copy swap src dst ab.Data.Length ) diff --git a/src/Aardvark.Rendering.Vulkan/Resources/Image/Image.fs b/src/Aardvark.Rendering.Vulkan/Resources/Image/Image.fs index 87538cbfb..67409b258 100644 --- a/src/Aardvark.Rendering.Vulkan/Resources/Image/Image.fs +++ b/src/Aardvark.Rendering.Vulkan/Resources/Image/Image.fs @@ -413,7 +413,7 @@ module ``Image Command Extensions`` = img.VkImageSubresourceRange ) - imageMemoryBarrier |> pin (fun pBarrier -> + imageMemoryBarrier |> NativePtr.pin (fun pBarrier -> VkRaw.vkCmdPipelineBarrier( cmd.Handle, srcStage, dstStage, @@ -488,7 +488,7 @@ module ``Image Command Extensions`` = ) cmd.AppendCommand() - copy |> pin (fun pCopy -> + copy |> NativePtr.pin (fun pCopy -> VkRaw.vkCmdCopyImage(cmd.Handle, src.Image.Handle, src.Image.Layout, dst.Image.Handle, dst.Image.Layout, 1u, pCopy) ) @@ -535,7 +535,7 @@ module ``Image Command Extensions`` = ) cmd.AppendCommand() - copy |> pin (fun pCopy -> + copy |> NativePtr.pin (fun pCopy -> VkRaw.vkCmdCopyBufferToImage(cmd.Handle, src.Handle, dst.Image.Handle, dst.Image.Layout, 1u, pCopy) ) @@ -557,7 +557,7 @@ module ``Image Command Extensions`` = ) cmd.AppendCommand() - copy |> pin (fun pCopy -> + copy |> NativePtr.pin (fun pCopy -> VkRaw.vkCmdCopyImageToBuffer(cmd.Handle, src.Image.Handle, src.Image.Layout, dst.Handle, 1u, pCopy) ) @@ -587,7 +587,7 @@ module ``Image Command Extensions`` = ) cmd.AppendCommand() - resolve |> pin (fun pResolve -> + resolve |> NativePtr.pin (fun pResolve -> VkRaw.vkCmdResolveImage(cmd.Handle, src.Image.Handle, srcLayout, dst.Image.Handle, dstLayout, 1u, pResolve) ) @@ -668,7 +668,7 @@ module ``Image Command Extensions`` = ) cmd.AppendCommand() - blit |> pin (fun pBlit -> + blit |> NativePtr.pin (fun pBlit -> VkRaw.vkCmdBlitImage(cmd.Handle, src.Image.Handle, srcLayout, dst.Image.Handle, dstLayout, 1u, pBlit, filter) ) @@ -804,7 +804,7 @@ module ``Image Command Extensions`` = let imgSize = int64 copy.extent.width * int64 copy.extent.height * int64 copy.extent.depth * 4L totalSize <- totalSize + imgSize * int64 copy.srcSubresource.layerCount - copy |> pin (fun pCopy -> + copy |> NativePtr.pin (fun pCopy -> VkRaw.vkCmdCopyImage( cmd.Handle, baseImage.Handle, VkImageLayout.TransferSrcOptimal, @@ -820,7 +820,7 @@ module ``Image Command Extensions`` = VkAccessFlags.TransferWriteBit, VkAccessFlags.TransferReadBit ||| VkAccessFlags.TransferWriteBit ) - mem |> pin (fun pMem -> + mem |> NativePtr.pin (fun pMem -> VkRaw.vkCmdPipelineBarrier( cmd.Handle, VkPipelineStageFlags.TransferBit, @@ -893,8 +893,8 @@ module ``Image Command Extensions`` = VkClearColorValue(float32 = color.Float) let range = img.VkImageSubresourceRange - clearValue |> pin (fun pClear -> - range |> pin (fun pRange -> + clearValue |> NativePtr.pin (fun pClear -> + range |> NativePtr.pin (fun pRange -> cmd.AppendCommand() VkRaw.vkCmdClearColorImage(cmd.Handle, img.Image.Handle, VkImageLayout.TransferDstOptimal, pClear, 1u, pRange) ) @@ -919,8 +919,8 @@ module ``Image Command Extensions`` = let mutable clearValue = VkClearDepthStencilValue(depth, stencil) let mutable range = img.VkImageSubresourceRange - clearValue |> pin (fun pClear -> - range |> pin (fun pRange -> + clearValue |> NativePtr.pin (fun pClear -> + range |> NativePtr.pin (fun pRange -> cmd.AppendCommand() VkRaw.vkCmdClearDepthStencilImage(cmd.Handle, img.Image.Handle, VkImageLayout.TransferDstOptimal, pClear, 1u, pRange) ) @@ -988,7 +988,7 @@ module Image = let mutable handle = temporary (fun pHandle -> - info |> pin (fun pInfo -> + info |> NativePtr.pin (fun pInfo -> VkRaw.vkCreateImage(device.Handle, pInfo, NativePtr.zero, pHandle) |> check "could not create image" NativePtr.read pHandle diff --git a/src/Aardvark.Rendering.Vulkan/Resources/Image/TensorImage.fs b/src/Aardvark.Rendering.Vulkan/Resources/Image/TensorImage.fs index e01c21ff9..a4d43637e 100644 --- a/src/Aardvark.Rendering.Vulkan/Resources/Image/TensorImage.fs +++ b/src/Aardvark.Rendering.Vulkan/Resources/Image/TensorImage.fs @@ -425,7 +425,7 @@ module TensorImageCommandExtensions = ) cmd.AppendCommand() - copy |> pin (fun pCopy -> + copy |> NativePtr.pin (fun pCopy -> VkRaw.vkCmdCopyBufferToImage(cmd.Handle, src.Buffer.Handle, dst.Image.Handle, dst.Image.Layout, 1u, pCopy) ) @@ -471,7 +471,7 @@ module TensorImageCommandExtensions = ) cmd.AppendCommand() - copy |> pin (fun pCopy -> + copy |> NativePtr.pin (fun pCopy -> VkRaw.vkCmdCopyImageToBuffer(cmd.Handle, src.Image.Handle, src.Image.Layout, dst.Buffer.Handle, 1u, pCopy) ) diff --git a/src/Aardvark.Rendering.Vulkan/Resources/Raytracing/ShaderBindingTable.fs b/src/Aardvark.Rendering.Vulkan/Resources/Raytracing/ShaderBindingTable.fs index 61ec64add..1ad039f51 100644 --- a/src/Aardvark.Rendering.Vulkan/Resources/Raytracing/ShaderBindingTable.fs +++ b/src/Aardvark.Rendering.Vulkan/Resources/Raytracing/ShaderBindingTable.fs @@ -140,9 +140,9 @@ module private ShaderBindingTableUtilities = let shaderHandles : uint8[] = Array.zeroCreate <| groupCount * (int size) - pinned shaderHandles (fun ptr -> + shaderHandles |> NativePtr.pinArr (fun ptr -> VkRaw.vkGetRayTracingShaderGroupHandlesKHR( - pipeline.Device.Handle, pipeline.Handle, 0u, uint32 groupCount, uint64 shaderHandles.Length, ptr + pipeline.Device.Handle, pipeline.Handle, 0u, uint32 groupCount, uint64 shaderHandles.Length, ptr.Address ) |> check "[Raytracing] Failed to get shader group handles" ) diff --git a/src/Aardvark.Rendering.Vulkan/Runtime/ComputeTask.fs b/src/Aardvark.Rendering.Vulkan/Runtime/ComputeTask.fs index d7b00d489..8e23f8d13 100644 --- a/src/Aardvark.Rendering.Vulkan/Runtime/ComputeTask.fs +++ b/src/Aardvark.Rendering.Vulkan/Runtime/ComputeTask.fs @@ -79,7 +79,7 @@ module internal ComputeTaskInternals = let length = arr.Length - index min sizeInBytes (nativeint length * elementSize) - pinned arr (fun ptr -> f (ptr + offset) sizeInBytes) + arr |> NativeInt.pin (fun ptr -> f (ptr + offset) sizeInBytes) [] module private Compiler = diff --git a/src/Aardvark.Rendering/Resources/Adaptive/AdaptiveBuffer.fs b/src/Aardvark.Rendering/Resources/Adaptive/AdaptiveBuffer.fs index ad65f198a..0c10d6ec0 100644 --- a/src/Aardvark.Rendering/Resources/Adaptive/AdaptiveBuffer.fs +++ b/src/Aardvark.Rendering/Resources/Adaptive/AdaptiveBuffer.fs @@ -42,7 +42,7 @@ type AdaptiveBufferExtensions private() = /// The number of bytes to write to the buffer. [] static member Write(this : IAdaptiveBuffer, data : Array, offset : nativeint, sizeInBytes : nativeint) = - pinned data (fun src -> + data |> NativeInt.pin (fun src -> this.Write(src, offset, sizeInBytes) ) @@ -59,10 +59,9 @@ type AdaptiveBufferExtensions private() = assert (start >= 0 && start < data.Length) assert (start + length <= data.Length) - pinned data (fun src -> - let src = src + nativeint (start * sizeof<'T>) + (start, data) ||> NativePtr.pinArri (fun src -> let size = nativeint (length * sizeof<'T>) - this.Write(src, offset, size) + this.Write(src.Address, offset, size) ) /// @@ -83,8 +82,8 @@ type AdaptiveBufferExtensions private() = /// The offset (in bytes) into the buffer. [] static member Write<'T when 'T : unmanaged>(this : IAdaptiveBuffer, data : 'T, offset : nativeint) = - pinned data (fun src -> - this.Write(src, offset, nativeint sizeof<'T>) + data |> NativePtr.pin (fun src -> + this.Write(src.Address, offset, nativeint sizeof<'T>) ) /// diff --git a/src/Aardvark.Rendering/Resources/Adaptive/ManagedBuffer.fs b/src/Aardvark.Rendering/Resources/Adaptive/ManagedBuffer.fs index 5355418bb..7b9182fbe 100644 --- a/src/Aardvark.Rendering/Resources/Adaptive/ManagedBuffer.fs +++ b/src/Aardvark.Rendering/Resources/Adaptive/ManagedBuffer.fs @@ -68,8 +68,8 @@ type ManagedBufferExtensions private() = /// The range (i.e. min and max offsets) in the buffer to write to. [] static member Set(this : IManagedBuffer, data : byte[], range : Range1l) = - pinned data (fun src -> - this.Set(src, nativeint data.Length, range) + data |> NativePtr.pinArr (fun src -> + this.Set(src.Address, nativeint data.Length, range) ) /// @@ -80,8 +80,8 @@ type ManagedBufferExtensions private() = /// The index in the buffer to write to. [] static member Set<'T when 'T : unmanaged>(this : IManagedBuffer, value : 'T, index : int64) = - pinned value (fun src -> - this.Set(src, nativeint sizeof<'T>, Range1l(index, index)) + value |> NativePtr.pin (fun src -> + this.Set(src.Address, nativeint sizeof<'T>, Range1l(index, index)) ) /// @@ -103,8 +103,8 @@ type ManagedBufferExtensions private() = /// The range (i.e. min and max offsets) in the buffer to write to. [] static member Set<'T when 'T : unmanaged>(this : IManagedBuffer, values : 'T[], range : Range1l) = - pinned values (fun src -> - this.Set(src, nativeint values.Length * nativeint sizeof<'T>, range) + values |> NativePtr.pinArr (fun src -> + this.Set(src.Address, nativeint values.Length * nativeint sizeof<'T>, range) ) /// @@ -119,7 +119,7 @@ type ManagedBufferExtensions private() = let elementSize = values.GetType().GetElementType().GetCLRSize() let sizeInBytes = nativeint values.Length * nativeint elementSize - pinned values (fun src -> + values |> NativeInt.pin (fun src -> this.Set(src, sizeInBytes, range) ) diff --git a/src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs b/src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs index a5ed466fa..c95092996 100644 --- a/src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs +++ b/src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs @@ -113,8 +113,8 @@ type IBufferRangeExtensions private() = srcIndex |> checkNonNegative "srcIndex" (srcIndex, count) ||> checkArrayBounds src - pinned src (fun pSrc -> - dst.Buffer.Upload(dst.Offset + byteSize<'T> dstIndex, pSrc + byteSize<'T> srcIndex, byteSize<'T> count) + (srcIndex, src) ||> NativePtr.pinArri (fun pSrc -> + dst.Buffer.Upload(dst.Offset + byteSize<'T> dstIndex, pSrc.Address, byteSize<'T> count) ) ///Copies elements from an array to a buffer range. @@ -186,8 +186,8 @@ type IBufferRangeExtensions private() = dstIndex |> checkNonNegative "dstIndex" (dstIndex, count) ||> checkArrayBounds dst - pinned dst (fun pDst -> - src.Buffer.Download(src.Offset + byteSize<'T> srcIndex, pDst + byteSize<'T> dstIndex, byteSize<'T> count) + (dstIndex, dst) ||> NativePtr.pinArri (fun pDst -> + src.Buffer.Download(src.Offset + byteSize<'T> srcIndex, pDst.Address, byteSize<'T> count) ) ///Copies elements from a buffer range to an array. @@ -249,8 +249,8 @@ type IBufferRangeExtensions private() = dstIndex |> checkNonNegative "dstIndex" (dstIndex, count) ||> checkArrayBounds dst - pinned dst (fun pDst -> - src.Buffer.DownloadAsync(src.Offset + byteSize<'T> srcIndex, pDst + byteSize<'T> dstIndex, byteSize<'T> count) + (dstIndex, dst) ||> NativePtr.pinArri (fun pDst -> + src.Buffer.DownloadAsync(src.Offset + byteSize<'T> srcIndex, pDst.Address, byteSize<'T> count) ) ///Asynchronously copies elements from a buffer range to an array. diff --git a/src/Aardvark.Rendering/Resources/Textures/DdsTexture.fs b/src/Aardvark.Rendering/Resources/Textures/DdsTexture.fs index e6c267c0f..0acb6a2ec 100644 --- a/src/Aardvark.Rendering/Resources/Textures/DdsTexture.fs +++ b/src/Aardvark.Rendering/Resources/Textures/DdsTexture.fs @@ -387,7 +387,7 @@ module DdsTexture = { new INativeTextureData with member x.Size = size member x.SizeInBytes = int64 sizeInBytes - member x.Use(f) = pinned data (fun ptr -> f (ptr + offset)) } + member x.Use(f) = data |> NativePtr.pinArr (fun ptr -> f (ptr.Address + offset)) } ) ) diff --git a/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Download.fs b/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Download.fs index 0b50c56f9..c1362e337 100644 --- a/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Download.fs +++ b/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Download.fs @@ -33,7 +33,7 @@ module BufferDownload = let private testNativeDownload (totalCount : int) (rangeStart : int) (rangeCount : int) = let download (buffer : IBackendBuffer) (dst : uint8[]) = - pinned dst (fun dst -> + dst |> NativeInt.pin (fun dst -> buffer.Download(nativeint rangeStart, dst, nativeint rangeCount) ) diff --git a/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Upload.fs b/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Upload.fs index fa79f43c1..c4dea8816 100644 --- a/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Upload.fs +++ b/src/Tests/Aardvark.Rendering.Tests/Tests/Buffer/Upload.fs @@ -46,7 +46,7 @@ module BufferUpload = let initialValue = 127uy let upload (buffer : IBackendBuffer) = - pinned rangeData (fun src -> + rangeData |> NativeInt.pin (fun src -> buffer.Upload(nativeint rangeStart, src, nativeint rangeCount) ) diff --git a/src/Tests/Aardvark.Rendering.Tests/Tests/Texture/Upload.fs b/src/Tests/Aardvark.Rendering.Tests/Tests/Texture/Upload.fs index 021335d8f..3d91fc270 100644 --- a/src/Tests/Aardvark.Rendering.Tests/Tests/Texture/Upload.fs +++ b/src/Tests/Aardvark.Rendering.Tests/Tests/Texture/Upload.fs @@ -54,7 +54,7 @@ module TextureUpload = { new INativeTextureData with member x.Size = V3i(pi.Size, 1) member x.SizeInBytes = int64 <| pi.Array.Length * sizeof<'T> - member x.Use (f : nativeint -> 'U) = pinned pi.Array f } + member x.Use (f : nativeint -> 'U) = NativeInt.pin f pi.Array } )) { new INativeTexture with