diff --git a/paket.dependencies b/paket.dependencies index 8104b406..0bdb8299 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -13,13 +13,13 @@ nuget CSharp.Data.Adaptive ~> 1.2.13 nuget Aardvark.Base.TypeProviders ~> 4.5.15 -nuget Aardvark.Base.FSharp ~> 5.2.23 -nuget Aardvark.Base.IO ~> 5.2.23 -nuget Aardvark.Base.Incremental ~> 5.2.23 -nuget Aardvark.Base.Runtime ~> 5.2.23 -nuget Aardvark.Base.Essentials ~> 5.2.23 -nuget Aardvark.Geometry ~> 5.2.23 -nuget Aardvark.Base.Tensors ~> 5.2.23 +nuget Aardvark.Base.FSharp ~> 5.2.27 +nuget Aardvark.Base.IO ~> 5.2.27 +nuget Aardvark.Base.Incremental ~> 5.2.27 +nuget Aardvark.Base.Runtime ~> 5.2.27 +nuget Aardvark.Base.Essentials ~> 5.2.27 +nuget Aardvark.Geometry ~> 5.2.27 +nuget Aardvark.Base.Tensors ~> 5.2.27 nuget Aardvark.Assembler ~> 0.0.8 diff --git a/paket.lock b/paket.lock index eddbc630..f5b40fb7 100644 --- a/paket.lock +++ b/paket.lock @@ -10,53 +10,53 @@ NUGET Aardvark.Base.Runtime (>= 5.2.7 < 5.3) FSharp.Core (>= 5.0) FSharp.Data.Adaptive (>= 1.2.13 < 1.3) - Aardvark.Base (5.2.25) - Aardvark.Base.Telemetry (5.2.25) + Aardvark.Base (5.2.27) + Aardvark.Base.Telemetry (5.2.27) System.Collections.Immutable (>= 5.0) System.Reflection.Metadata (>= 5.0) - restriction: || (== net471) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0-windows7.0) (< netcoreapp3.1)) (== netstandard2.0) System.Text.Json (>= 4.7.2) - Aardvark.Base.Essentials (5.2.25) - Aardvark.Base (5.2.25) + Aardvark.Base.Essentials (5.2.27) + Aardvark.Base (5.2.27) System.Collections.Immutable (>= 5.0) - Aardvark.Base.FSharp (5.2.25) - Aardvark.Base (5.2.25) + Aardvark.Base.FSharp (5.2.27) + Aardvark.Base (5.2.27) Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6) FSharp.Core (>= 5.0) FSharp.Data.Adaptive (>= 1.2 < 1.3) FsPickler (>= 5.3.2 < 5.4) System.Dynamic.Runtime (>= 4.3 < 4.4) - Aardvark.Base.Incremental (5.2.25) - Aardvark.Base (5.2.25) - Aardvark.Base.FSharp (5.2.25) + Aardvark.Base.Incremental (5.2.27) + Aardvark.Base (5.2.27) + Aardvark.Base.FSharp (5.2.27) Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6) FSharp.Core (>= 5.0) FSharp.Data.Adaptive (>= 1.2 < 1.3) FsPickler (>= 5.3.2 < 5.4) - Aardvark.Base.IO (5.2.25) - Aardvark.Base (5.2.25) - Aardvark.Base.Tensors (5.2.25) + Aardvark.Base.IO (5.2.27) + Aardvark.Base (5.2.27) + Aardvark.Base.Tensors (5.2.27) System.Dynamic.Runtime (>= 4.3 < 4.4) - Aardvark.Base.Runtime (5.2.25) - Aardvark.Base.FSharp (5.2.25) - Aardvark.Base.Incremental (5.2.25) + Aardvark.Base.Runtime (5.2.27) + Aardvark.Base.FSharp (5.2.27) + Aardvark.Base.Incremental (5.2.27) Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6) FSharp.Core (>= 5.0) FSharp.Data.Adaptive (>= 1.2 < 1.3) FsPickler (>= 5.3.2 < 5.4) - Aardvark.Base.Telemetry (5.2.25) - Aardvark.Base.Tensors (5.2.25) - Aardvark.Base (5.2.25) - Aardvark.Base.FSharp (5.2.25) + Aardvark.Base.Telemetry (5.2.27) + Aardvark.Base.Tensors (5.2.27) + Aardvark.Base (5.2.27) + Aardvark.Base.FSharp (5.2.27) FSharp.Core (>= 5.0) SixLabors.ImageSharp (>= 2.1.3 < 2.2) Aardvark.Base.TypeProviders (4.5.15) FSharp.Core (>= 3.1.2.5) - restriction: || (== net471) (&& (== net6.0) (>= net45)) (&& (== net6.0-windows7.0) (>= net45)) (&& (== netstandard2.0) (>= net45)) FSharp.Core (>= 4.2.3) - restriction: || (&& (== net471) (< net45)) (== net6.0) (== net6.0-windows7.0) (== netstandard2.0) Aardvark.Build (1.0.19) - Aardvark.Geometry (5.2.25) - Aardvark.Base (5.2.25) - Aardvark.Base.FSharp (5.2.25) - Aardvark.Base.Tensors (5.2.25) + Aardvark.Geometry (5.2.27) + Aardvark.Base (5.2.27) + Aardvark.Base.FSharp (5.2.27) + Aardvark.Base.Tensors (5.2.27) Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6) FSharp.Core (>= 5.0) FSharp.Data.Adaptive (>= 1.2 < 1.3) diff --git a/src/Aardvark.Rendering.Vulkan/Resources/Buffer.fs b/src/Aardvark.Rendering.Vulkan/Resources/Buffer.fs index cd0c781f..67e82f7b 100644 --- a/src/Aardvark.Rendering.Vulkan/Resources/Buffer.fs +++ b/src/Aardvark.Rendering.Vulkan/Resources/Buffer.fs @@ -14,6 +14,7 @@ open KHRBufferDeviceAddress open KHRAccelerationStructure #nowarn "9" +#nowarn "44" // RangeSet // #nowarn "51" // ======================================================================= @@ -442,6 +443,7 @@ module Buffer = let internal updateWriter (writer : nativeint -> unit) (buffer : Buffer) = updateRangeWriter 0L buffer.Size writer buffer + [] let uploadRanges (ptr : nativeint) (ranges : RangeSet) (buffer : Buffer) = let baseOffset = int64 ranges.Min let totalSize = int64 (ranges.Max - ranges.Min) @@ -453,6 +455,18 @@ module Buffer = Marshal.Copy(ptr + srcOffset, dst + dstOffset, r.Size + 1) ) + // TODO: Rename back to uploadRanges with next major update + let uploadRangeSet (ptr : nativeint) (ranges : RangeSet1i) (buffer : Buffer) = + let baseOffset = int64 ranges.Min + let totalSize = int64 (ranges.Max - ranges.Min + 1) + + buffer |> updateRangeWriter baseOffset totalSize (fun dst -> + for r in ranges do + let srcOffset = nativeint r.Min + let dstOffset = nativeint (r.Min - ranges.Min) + Marshal.Copy(ptr + srcOffset, dst + dstOffset, r.Size + 1) + ) + let rec tryUpdate (data : IBuffer) (buffer : Buffer) = match data with | :? Buffer as b -> @@ -640,10 +654,15 @@ type ContextBufferExtensions private() = use token = memory.Device.Token token |> Buffer.ofBufferWithMemory export flags data memory + [] [] static member inline UploadRanges(buffer : Buffer, ptr : nativeint, ranges : RangeSet) = buffer |> Buffer.uploadRanges ptr ranges + [] + static member inline UploadRanges(buffer : Buffer, ptr : nativeint, ranges : RangeSet1i) = + buffer |> Buffer.uploadRangeSet ptr ranges + [] static member inline TryUpdate(buffer : Buffer, b : IBuffer) = buffer |> Buffer.tryUpdate b diff --git a/src/Aardvark.Rendering.Vulkan/Resources/GeometryPool.fs b/src/Aardvark.Rendering.Vulkan/Resources/GeometryPool.fs index ae366125..57026ea9 100644 --- a/src/Aardvark.Rendering.Vulkan/Resources/GeometryPool.fs +++ b/src/Aardvark.Rendering.Vulkan/Resources/GeometryPool.fs @@ -17,262 +17,6 @@ open Microsoft.FSharp.NativeInterop module GeometryPoolUtilities = - type HalfRangeKind = - | Left = 0 - | Right = 1 - - [] - type RangeSet(store : MapExt) = - static let empty = RangeSet(MapExt.empty) - - static member Empty = empty - - member private x.store = store - - static member OfSeq(s : seq) = - let arr = s |> Seq.toArray - if arr.Length = 0 then - empty - elif arr.Length = 1 then - let r = arr.[0] - RangeSet(MapExt.ofList [r.Min, HalfRangeKind.Left; r.Max + 1L, HalfRangeKind.Right ]) - else - // TODO: better impl possible (sort array and traverse) - arr |> Array.fold (fun s r -> s.Add r) empty - - member x.Add(r : Range1l) = - - if r.Max < r.Min then - x - else - let min = r.Min - let max = r.Max + 1L - - let lm, _, inner = MapExt.split min store - let inner, _, rm = MapExt.split max inner - - let before = MapExt.tryMax lm |> Option.map (fun mk -> mk, lm.[mk]) - let after = MapExt.tryMin rm |> Option.map (fun mk -> mk, rm.[mk]) - - let newStore = - match before, after with - | None, None -> - MapExt.ofList [ min, HalfRangeKind.Left; max, HalfRangeKind.Right] - - | Some(bk, HalfRangeKind.Right), None -> - lm - |> MapExt.add min HalfRangeKind.Left - |> MapExt.add max HalfRangeKind.Right - - | Some(bk, HalfRangeKind.Left), None -> - lm - |> MapExt.add max HalfRangeKind.Right - - | None, Some(ak, HalfRangeKind.Left) -> - rm - |> MapExt.add min HalfRangeKind.Left - |> MapExt.add max HalfRangeKind.Right - - | None, Some(ak, HalfRangeKind.Right) -> - rm - |> MapExt.add min HalfRangeKind.Left - - | Some(bk, HalfRangeKind.Right), Some(ak, HalfRangeKind.Left) -> - let self = MapExt.ofList [ min, HalfRangeKind.Left; max, HalfRangeKind.Right] - MapExt.union (MapExt.union lm self) rm - - | Some(bk, HalfRangeKind.Left), Some(ak, HalfRangeKind.Left) -> - let self = MapExt.ofList [ max, HalfRangeKind.Right] - MapExt.union (MapExt.union lm self) rm - - | Some(bk, HalfRangeKind.Right), Some(ak, HalfRangeKind.Right) -> - let self = MapExt.ofList [ min, HalfRangeKind.Left ] - MapExt.union (MapExt.union lm self) rm - - | Some(bk, HalfRangeKind.Left), Some(ak, HalfRangeKind.Right) -> - MapExt.union lm rm - - | _ -> - failwithf "impossible" - assert (newStore.Count % 2 = 0) - RangeSet(newStore) - - member x.Remove(r : Range1l) = - if r.Max < r.Min then - x - else - let min = r.Min - let max = r.Max + 1L - - let lm, _, inner = MapExt.split min store - let inner, _, rm = MapExt.split max inner - - let before = MapExt.tryMax lm |> Option.map (fun mk -> mk, lm.[mk]) - let after = MapExt.tryMin rm |> Option.map (fun mk -> mk, rm.[mk]) - - let newStore = - match before, after with - | None, None -> - MapExt.empty - - | Some(bk, HalfRangeKind.Right), None -> - lm - - | Some(bk, HalfRangeKind.Left), None -> - lm - |> MapExt.add min HalfRangeKind.Right - - | None, Some(ak, HalfRangeKind.Left) -> - rm - - | None, Some(ak, HalfRangeKind.Right) -> - rm - |> MapExt.add max HalfRangeKind.Left - - | Some(bk, HalfRangeKind.Right), Some(ak, HalfRangeKind.Left) -> - MapExt.union lm rm - - | Some(bk, HalfRangeKind.Left), Some(ak, HalfRangeKind.Left) -> - let self = MapExt.ofList [ min, HalfRangeKind.Right] - MapExt.union (MapExt.union lm self) rm - - | Some(bk, HalfRangeKind.Right), Some(ak, HalfRangeKind.Right) -> - let self = MapExt.ofList [ max, HalfRangeKind.Left ] - MapExt.union (MapExt.union lm self) rm - - | Some(bk, HalfRangeKind.Left), Some(ak, HalfRangeKind.Right) -> - let self = MapExt.ofList [ min, HalfRangeKind.Right; max, HalfRangeKind.Left] - MapExt.union (MapExt.union lm self) rm - - | _ -> - failwithf "impossible" - - RangeSet(newStore) - - member x.Contains(v : int64) = - let l, s, _ = MapExt.neighbours v store - match s with - | Some(_,k) -> - k = HalfRangeKind.Left - | _ -> - match l with - | Some(_,HalfRangeKind.Left) -> true - | _ -> false - - member x.Count = - assert (store.Count &&& 1 = 0) - store.Count / 2 - - member private x.AsString = x.ToString() - - member x.ToArray() = - let arr = Array.zeroCreate (store.Count / 2) - let rec write (i : int) (l : list) = - match l with - | (lKey,lValue) :: (rKey, rValue) :: rest -> - arr.[i] <- Range1l(lKey, rKey - 1L) - write (i + 1) rest - - | [_] -> failwith "bad RangeSet" - - | [] -> () - - store |> MapExt.toList |> write 0 - arr - - member x.ToList() = - let rec build (l : list) = - match l with - | (lKey,lValue) :: (rKey, rValue) :: rest -> - Range1l(lKey, rKey - 1L) :: - build rest - - | [_] -> failwith "bad RangeSet" - - | [] -> [] - - store |> MapExt.toList |> build - - member x.ToSeq() = - x :> seq<_> - - override x.ToString() = - let rec ranges (l : list) = - match l with - | (kMin, vMin) :: (kMax, vMax) :: rest -> - sprintf "[%d,%d)" kMin kMax :: - ranges rest - - | [(k,v)] -> - [ sprintf "ERROR: %d %A" k v ] - - | [] -> - [] - - store |> MapExt.toList |> ranges |> String.concat ", " |> sprintf "ranges [ %s ]" - - interface System.Collections.IEnumerable with - member x.GetEnumerator() = new RangeSetEnumerator((store :> seq<_>).GetEnumerator()) :> _ - - interface System.Collections.Generic.IEnumerable with - member x.GetEnumerator() = new RangeSetEnumerator((store :> seq<_>).GetEnumerator()) :> _ - - and private RangeSetEnumerator(e : IEnumerator>) = - - let mutable a = Unchecked.defaultof<_> - let mutable b = Unchecked.defaultof<_> - - member x.MoveNext() = - if e.MoveNext() then - a <- e.Current - if e.MoveNext() then - b <- e.Current - true - else - failwithf "impossible" - else - false - - member x.Reset() = - e.Reset() - a <- Unchecked.defaultof<_> - b <- Unchecked.defaultof<_> - - member x.Current = - assert (a.Value = HalfRangeKind.Left && b.Value = HalfRangeKind.Right) - Range1l(a.Key, b.Key - 1L) - - member x.Dispose() = - e.Dispose() - a <- Unchecked.defaultof<_> - b <- Unchecked.defaultof<_> - - interface System.Collections.IEnumerator with - member x.MoveNext() = x.MoveNext() - member x.Current = x.Current :> obj - member x.Reset() = x.Reset() - - interface System.Collections.Generic.IEnumerator with - member x.Dispose() = x.Dispose() - member x.Current = x.Current - - [] - module RangeSet = - let empty = RangeSet.Empty - - let inline ofSeq (s : seq) = RangeSet.OfSeq s - let inline ofList (s : list) = RangeSet.OfSeq s - let inline ofArray (s : Range1l[]) = RangeSet.OfSeq s - - let inline add (r : Range1l) (s : RangeSet) = s.Add r - let inline remove (r : Range1l) (s : RangeSet) = s.Remove r - let inline contains (v : int64) (s : RangeSet) = s.Contains v - let inline count (s : RangeSet) = s.Count - - let inline toSeq (s : RangeSet) = s :> seq<_> - let inline toList (s : RangeSet) = s.ToList() - let inline toArray (s : RangeSet) = s.ToArray() - [] type ResourceLock2() = let lock = ResourceLock() @@ -319,7 +63,7 @@ module GeometryPoolUtilities = } let mutable isEmpty = true - let mutable dirty = RangeSet.empty + let mutable dirty = RangeSet1l.empty member private x.HostBuffer = hostBuffer @@ -330,12 +74,12 @@ module GeometryPoolUtilities = Marshal.Copy(data, ptr + nativeint offset, size) let range = Range1l(offset, offset + size - 1L) - Interlocked.Change(&dirty, RangeSet.add range) |> ignore + Interlocked.Change(&dirty, RangeSet1l.add range) |> ignore ) member x.Flush() = LockedResource.update x (fun () -> - let dirty = Interlocked.Exchange(&dirty, RangeSet.empty) + let dirty = Interlocked.Exchange(&dirty, RangeSet1l.empty) let cnt = dirty.Count if cnt <> 0 then diff --git a/src/Aardvark.Rendering/Pipeline/DrawCalls.fs b/src/Aardvark.Rendering/Pipeline/DrawCalls.fs index 516b8fbc..ade15b10 100644 --- a/src/Aardvark.Rendering/Pipeline/DrawCalls.fs +++ b/src/Aardvark.Rendering/Pipeline/DrawCalls.fs @@ -11,12 +11,12 @@ type DrawCallSet(collapseAdjacent : bool) = inherit AVal.AbstractVal() let all = System.Collections.Generic.HashSet() - let mutable ranges = RangeSet.empty + let mutable ranges = RangeSet1i.empty member x.AddUnsafe(r : Range1i) = lock x (fun () -> if all.Add r then - ranges <- RangeSet.insert r ranges + ranges <- RangeSet1i.add r ranges true else false @@ -25,7 +25,7 @@ type DrawCallSet(collapseAdjacent : bool) = member x.RemoveUnsafe(r : Range1i) = lock x (fun () -> if all.Remove r then - ranges <- RangeSet.remove r ranges + ranges <- RangeSet1i.remove r ranges true else false @@ -35,7 +35,7 @@ type DrawCallSet(collapseAdjacent : bool) = let result = lock x (fun () -> if all.Add r then - ranges <- RangeSet.insert r ranges + ranges <- RangeSet1i.add r ranges true else false @@ -49,7 +49,7 @@ type DrawCallSet(collapseAdjacent : bool) = let result = lock x (fun () -> if all.Remove r then - ranges <- RangeSet.remove r ranges + ranges <- RangeSet1i.remove r ranges true else false diff --git a/src/Aardvark.SceneGraph/PointCloud.fs b/src/Aardvark.SceneGraph/PointCloud.fs index 3d66df18..e1ef4e87 100644 --- a/src/Aardvark.SceneGraph/PointCloud.fs +++ b/src/Aardvark.SceneGraph/PointCloud.fs @@ -593,14 +593,14 @@ module PointCloudRenderObjectSemantics = load rasterize paramse dependencies let drawCallBuffer = - let add (set : RangeSet) (v : LoadedGeometry) = + let add (set : RangeSet1i) (v : LoadedGeometry) = let range = v.Range - if range.IsValid then RangeSet.insert range set + if range.IsValid then RangeSet1i.add range set else set - let sub (set : RangeSet) (v : LoadedGeometry) = + let sub (set : RangeSet1i) (v : LoadedGeometry) = let range = v.Range - if range.IsValid then RangeSet.remove range set + if range.IsValid then RangeSet1i.remove range set else set let call (r : Range1i) = @@ -613,9 +613,9 @@ module PointCloudRenderObjectSemantics = ) loadedGeometries - |> ASet.foldGroup add sub RangeSet.empty + |> ASet.foldGroup add sub RangeSet1i.empty |> AVal.map (fun ranges -> - let calls = ranges |> RangeSet.toSeq |> Seq.map call |> Seq.toArray + let calls = ranges |> Seq.map call |> Seq.toArray IndirectBuffer.ofArray calls )