Queue: Add support of pritority + Fix bad Queue index by family

This commit is contained in:
Florian RICHER 2025-05-24 17:14:50 +02:00
parent fe685a377f
commit 4ce051b0f5
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77

View file

@ -1,14 +1,16 @@
package fr.mrdev023.vulkan_java.vk;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.VK10;
import org.lwjgl.vulkan.VkDeviceQueueCreateInfo;
public class QueuesCreator {
private final HashMap<Integer, Integer> families;
private final HashMap<Integer, List<Float>> families;
private HashMap<Integer, Integer> counters;
public QueuesCreator(QueueFamilyIndices queueFamilyIndices) {
@ -26,7 +28,11 @@ public class QueuesCreator {
stack);
int i = 0;
for (var familyIndex : families.keySet()) {
FloatBuffer priorities = stack.callocFloat(families.get(familyIndex));
FloatBuffer priorities = stack.callocFloat(families.get(familyIndex).size());
for (var priority : families.get(familyIndex)) {
priorities.put(priority);
}
priorities.flip();
queueCreationInfoBuf.get(i)
.sType(VK10.VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO)
.queueFamilyIndex(familyIndex)
@ -43,29 +49,35 @@ public class QueuesCreator {
}
private int getNextAvailableQueueIndexForFamilyIndex(int queueFamilyIndex) {
var max = families.getOrDefault(queueFamilyIndex, 0);
var max = families.get(queueFamilyIndex).size();
var current = counters.getOrDefault(queueFamilyIndex, 0);
if (current >= max) {
throw new RuntimeException("No more queues available for family " + queueFamilyIndex);
}
counters.put(queueFamilyIndex, current + 1);
return current + 1;
return current;
}
private HashMap<Integer, Integer> createFamilies(QueueFamilyIndices queueFamilyIndices) {
var families = new HashMap<Integer, Integer>();
private HashMap<Integer, List<Float>> createFamilies(QueueFamilyIndices queueFamilyIndices) {
var families = new HashMap<Integer, List<Float>>();
if (queueFamilyIndices.getGraphicsQueueFamilyIndex().isPresent()) {
var familyIndex = queueFamilyIndices.getGraphicsQueueFamilyIndex().get();
families.put(familyIndex, families.getOrDefault(familyIndex, 0) + 1);
var familyPriorities = families.getOrDefault(familyIndex, new ArrayList<Float>());
familyPriorities.add(1.0f);
families.put(familyIndex, familyPriorities);
}
if (queueFamilyIndices.getComputeQueueFamilyIndex().isPresent()) {
var familyIndex = queueFamilyIndices.getComputeQueueFamilyIndex().get();
families.put(familyIndex, families.getOrDefault(familyIndex, 0) + 1);
var familyPriorities = families.getOrDefault(familyIndex, new ArrayList<Float>());
familyPriorities.add(0.5f);
families.put(familyIndex, familyPriorities);
}
if (queueFamilyIndices.getTransferQueueFamilyIndex().isPresent()) {
var familyIndex = queueFamilyIndices.getTransferQueueFamilyIndex().get();
families.put(familyIndex, families.getOrDefault(familyIndex, 0) + 1);
var familyPriorities = families.getOrDefault(familyIndex, new ArrayList<Float>());
familyPriorities.add(0.5f);
families.put(familyIndex, familyPriorities);
}
return families;
}