Skip to content

Commit

Permalink
[Vulkan] requesting all queues
Browse files Browse the repository at this point in the history
  • Loading branch information
krauthaufen committed Jul 20, 2022
1 parent d76e9d2 commit 9436e67
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 43 deletions.
80 changes: 37 additions & 43 deletions src/Aardvark.Rendering.Vulkan/Core/Device.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,15 @@ type Device internal(dev : PhysicalDevice, wantedExtensions : list<string>) as t
ptr

let queueInfos =
let counts = Dictionary.empty
for (fam, cnt) in List.concat [Option.toList graphicsQueues; Option.toList computeQueues; Option.toList transferQueues] do
match counts.TryGetValue fam.index with
| (true, o) -> counts.[fam.index] <- o + cnt
| _ -> counts.[fam.index] <- cnt

counts
|> Dictionary.toArray
|> Array.map (fun (familyIndex, count) ->
VkDeviceQueueCreateInfo(
VkDeviceQueueCreateFlags.None,
uint32 familyIndex,
uint32 count,
queuePriorities
)
physical.QueueFamilies |> Array.map (fun fam ->
VkDeviceQueueCreateInfo(
VkDeviceQueueCreateFlags.None,
uint32 fam.index,
uint32 fam.count,
queuePriorities
)
)


native {
let! ptr = queueInfos
Expand Down Expand Up @@ -239,44 +232,45 @@ type Device internal(dev : PhysicalDevice, wantedExtensions : list<string>) as t
return !!pDevice
}

let graphicsFamily, computeFamily, transferFamily =
let usedFamilies =
let offsets = Array.zeroCreate physical.QueueFamilies.Length

let toFamily (fam : QueueFamilyInfo, count : int) =
physical.QueueFamilies |> Array.map (fun fam ->
let offset = offsets.[fam.index]
offsets.[fam.index] <- offset + count
offsets.[fam.index] <- offset + fam.count

let queues =
List.init count (fun i ->
List.init fam.count (fun i ->
DeviceQueue(this, device, fam, offset + i)
)

let family = new DeviceQueueFamily(this, physical, fam, queues)
family

)

let graphicsFamily =
match graphicsQueues with
| Some (info,_) ->
usedFamilies |> Array.tryFind (fun f -> f.Index = info.index)
| None ->
None

let computeFamily =
match computeQueues with
| Some (info,_) ->
usedFamilies |> Array.tryFind (fun f -> f.Index = info.index)
| None ->
None
let transferFamily =
match transferQueues with
| Some (info,_) ->
usedFamilies |> Array.tryFind (fun f -> f.Index = info.index)
| None ->
None

let queueFamilies = usedFamilies

let graphicsFamily = graphicsQueues |> Option.map toFamily
let computeFamily = computeQueues |> Option.map toFamily
let transferFamily = transferQueues |> Option.map toFamily

let computeFamily =
match computeFamily with
| Some c -> Some c
| None -> graphicsFamily

graphicsFamily, computeFamily, transferFamily

let queueFamilies =
Array.concat [
Option.toArray graphicsFamily
Option.toArray computeFamily
Option.toArray transferFamily
]

let usedFamilies =
List.concat [ Option.toList graphicsQueues; Option.toList computeQueues; Option.toList transferQueues ]
|> List.map (fun (f,_) -> f.index)
|> Set.ofList
|> Set.toArray
let usedFamilies = usedFamilies |> Array.map (fun f -> f.Index) |> Set.ofArray |> Set.toArray

let pAllFamilies =
if usedFamilies.Length <= 1 then
Expand Down
3 changes: 3 additions & 0 deletions src/Aardvark.Rendering.Vulkan/Core/Info.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ type QueueFlags =
| Compute = 0x00000002
| Transfer = 0x00000004
| SparseBinding = 0x00000008
| Protected = 0x00000010
| VideoDecode = 0x00000020
| VideoEncode = 0x00000040
| All = 0x00000007


Expand Down
2 changes: 2 additions & 0 deletions src/Aardvark.Rendering.Vulkan/Core/Platform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ type Instance(apiVersion : Version, layers : list<string>, extensions : list<str
QueueFlags.Graphics, "graphics"
QueueFlags.Transfer, "transfer"
QueueFlags.SparseBinding, "sparsebinding"
QueueFlags.VideoDecode, "video-decode"
QueueFlags.VideoEncode, "video-encode"
]

let capString (c : QueueFlags) =
Expand Down
8 changes: 8 additions & 0 deletions src/Aardvark.Rendering.Vulkan/Runtime/Headless.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ type HeadlessVulkanApplication(debug : DebugLevel, instanceExtensions : list<str

yield! Instance.Extensions.Raytracing

yield KHRVideoQueue.Name
yield KHRVideoDecodeQueue.Name
yield KHRVideoEncodeQueue.Name
yield EXTVideoDecodeH264.Name
yield EXTVideoEncodeH264.Name
yield EXTVideoDecodeH265.Name
yield EXTVideoEncodeH265.Name

if debug > DebugLevel.None then
yield Instance.Extensions.DebugReport
yield Instance.Extensions.DebugUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ type VulkanApplication(debug : DebugLevel, chooseDevice : list<PhysicalDevice> -
yield Instance.Extensions.GetPhysicalDeviceProperties2

yield! Instance.Extensions.Raytracing

yield KHRVideoQueue.Name
yield KHRVideoDecodeQueue.Name
yield KHRVideoEncodeQueue.Name
yield EXTVideoDecodeH264.Name
yield EXTVideoEncodeH264.Name
yield EXTVideoDecodeH265.Name
yield EXTVideoEncodeH265.Name

if debug > DebugLevel.None then
yield Instance.Extensions.DebugReport
Expand Down

0 comments on commit 9436e67

Please sign in to comment.