Queue: Don't allocate dedicate presentation queue (use graphics queue for it)

This commit is contained in:
Florian RICHER 2025-05-24 16:55:03 +02:00
parent d26695607b
commit fe685a377f
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
5 changed files with 9 additions and 43 deletions

View file

@ -21,7 +21,6 @@ public class Device {
private final PhysicalDevice physicalDevice; private final PhysicalDevice physicalDevice;
private final VkDevice vkDevice; private final VkDevice vkDevice;
private final Optional<Queue> presentQueue;
private final Optional<Queue> graphicsQueue; private final Optional<Queue> graphicsQueue;
private final Optional<Queue> computeQueue; private final Optional<Queue> computeQueue;
private final Optional<Queue> transferQueue; private final Optional<Queue> transferQueue;
@ -58,8 +57,6 @@ public class Device {
graphicsQueue = queueFamilyIndices.getGraphicsQueueFamilyIndex() graphicsQueue = queueFamilyIndices.getGraphicsQueueFamilyIndex()
.flatMap(queueFamilyIndex -> Optional.of(queuesCreator.createQueue(this, queueFamilyIndex))); .flatMap(queueFamilyIndex -> Optional.of(queuesCreator.createQueue(this, queueFamilyIndex)));
presentQueue = queueFamilyIndices.getPresentQueueFamilyIndex()
.flatMap(queueFamilyIndex -> Optional.of(queuesCreator.createQueue(this, queueFamilyIndex)));
computeQueue = queueFamilyIndices.getComputeQueueFamilyIndex() computeQueue = queueFamilyIndices.getComputeQueueFamilyIndex()
.flatMap(queueFamilyIndex -> Optional.of(queuesCreator.createQueue(this, queueFamilyIndex))); .flatMap(queueFamilyIndex -> Optional.of(queuesCreator.createQueue(this, queueFamilyIndex)));
transferQueue = queueFamilyIndices.getTransferQueueFamilyIndex() transferQueue = queueFamilyIndices.getTransferQueueFamilyIndex()
@ -86,10 +83,6 @@ public class Device {
vkDeviceWaitIdle(vkDevice); vkDeviceWaitIdle(vkDevice);
} }
public Optional<Queue> getPresentQueue() {
return presentQueue;
}
public Optional<Queue> getGraphicsQueue() { public Optional<Queue> getGraphicsQueue() {
return graphicsQueue; return graphicsQueue;
} }

View file

@ -1,20 +1,17 @@
package fr.mrdev023.vulkan_java.vk; package fr.mrdev023.vulkan_java.vk;
import java.util.HashMap;
import java.util.Optional; import java.util.Optional;
public class QueueFamilyIndices { public class QueueFamilyIndices {
private final Optional<Integer> graphicsQueueFamilyIndex; private final Optional<Integer> graphicsQueueFamilyIndex;
private final Optional<Integer> computeQueueFamilyIndex; private final Optional<Integer> computeQueueFamilyIndex;
private final Optional<Integer> transferQueueFamilyIndex; private final Optional<Integer> transferQueueFamilyIndex;
private final Optional<Integer> presentQueueFamilyIndex;
public QueueFamilyIndices(Optional<Integer> graphicsQueueFamilyIndex, Optional<Integer> computeQueueFamilyIndex, public QueueFamilyIndices(Optional<Integer> graphicsQueueFamilyIndex, Optional<Integer> computeQueueFamilyIndex,
Optional<Integer> transferQueueFamilyIndex, Optional<Integer> presentQueueFamilyIndex) { Optional<Integer> transferQueueFamilyIndex) {
this.graphicsQueueFamilyIndex = graphicsQueueFamilyIndex; this.graphicsQueueFamilyIndex = graphicsQueueFamilyIndex;
this.computeQueueFamilyIndex = computeQueueFamilyIndex; this.computeQueueFamilyIndex = computeQueueFamilyIndex;
this.transferQueueFamilyIndex = transferQueueFamilyIndex; this.transferQueueFamilyIndex = transferQueueFamilyIndex;
this.presentQueueFamilyIndex = presentQueueFamilyIndex;
} }
public Optional<Integer> getGraphicsQueueFamilyIndex() { public Optional<Integer> getGraphicsQueueFamilyIndex() {
@ -29,15 +26,10 @@ public class QueueFamilyIndices {
return transferQueueFamilyIndex; return transferQueueFamilyIndex;
} }
public Optional<Integer> getPresentQueueFamilyIndex() {
return presentQueueFamilyIndex;
}
public static class Builder { public static class Builder {
private Optional<Integer> graphicsQueueFamilyIndex; private Optional<Integer> graphicsQueueFamilyIndex;
private Optional<Integer> computeQueueFamilyIndex; private Optional<Integer> computeQueueFamilyIndex;
private Optional<Integer> transferQueueFamilyIndex; private Optional<Integer> transferQueueFamilyIndex;
private Optional<Integer> presentQueueFamilyIndex;
public Builder withGraphicsQueueFamilyIndex(int graphicsQueueFamilyIndex) { public Builder withGraphicsQueueFamilyIndex(int graphicsQueueFamilyIndex) {
this.graphicsQueueFamilyIndex = Optional.of(graphicsQueueFamilyIndex); this.graphicsQueueFamilyIndex = Optional.of(graphicsQueueFamilyIndex);
@ -54,14 +46,8 @@ public class QueueFamilyIndices {
return this; return this;
} }
public Builder withPresentQueueFamilyIndex(int presentQueueFamilyIndex) {
this.presentQueueFamilyIndex = Optional.of(presentQueueFamilyIndex);
return this;
}
public QueueFamilyIndices build() { public QueueFamilyIndices build() {
return new QueueFamilyIndices(graphicsQueueFamilyIndex, computeQueueFamilyIndex, transferQueueFamilyIndex, return new QueueFamilyIndices(graphicsQueueFamilyIndex, computeQueueFamilyIndex, transferQueueFamilyIndex);
presentQueueFamilyIndex);
} }
} }
} }

View file

@ -67,10 +67,6 @@ public class QueuesCreator {
var familyIndex = queueFamilyIndices.getTransferQueueFamilyIndex().get(); var familyIndex = queueFamilyIndices.getTransferQueueFamilyIndex().get();
families.put(familyIndex, families.getOrDefault(familyIndex, 0) + 1); families.put(familyIndex, families.getOrDefault(familyIndex, 0) + 1);
} }
if (queueFamilyIndices.getPresentQueueFamilyIndex().isPresent()) {
var familyIndex = queueFamilyIndices.getPresentQueueFamilyIndex().get();
families.put(familyIndex, families.getOrDefault(familyIndex, 0) + 1);
}
return families; return families;
} }
} }

View file

@ -13,8 +13,6 @@ public class QueueFamilyRequirementResultLogger {
queueFamilyIndices.flatMap(QueueFamilyIndices::getComputeQueueFamilyIndex)); queueFamilyIndices.flatMap(QueueFamilyIndices::getComputeQueueFamilyIndex));
logQueueFamilyResult("Transfer Queue", logQueueFamilyResult("Transfer Queue",
queueFamilyIndices.flatMap(QueueFamilyIndices::getTransferQueueFamilyIndex)); queueFamilyIndices.flatMap(QueueFamilyIndices::getTransferQueueFamilyIndex));
logQueueFamilyResult("Present Queue",
queueFamilyIndices.flatMap(QueueFamilyIndices::getPresentQueueFamilyIndex));
ScopedLogger.popScope(); ScopedLogger.popScope();
} }

View file

@ -30,7 +30,6 @@ public class QueueFamilyRequirementsValidator {
*/ */
public Optional<QueueFamilyIndices> validate(PhysicalDevice physicalDevice) { public Optional<QueueFamilyIndices> validate(PhysicalDevice physicalDevice) {
var vkQueueFamilyProps = physicalDevice.getVkQueueFamilyProps(); var vkQueueFamilyProps = physicalDevice.getVkQueueFamilyProps();
var queueFamilyIndicesBuilder = new QueueFamilyIndices.Builder(); var queueFamilyIndicesBuilder = new QueueFamilyIndices.Builder();
for (int i = 0; i < vkQueueFamilyProps.capacity(); i++) { for (int i = 0; i < vkQueueFamilyProps.capacity(); i++) {
@ -39,9 +38,11 @@ public class QueueFamilyRequirementsValidator {
if (hasRequiredFlag(VK10.VK_QUEUE_GRAPHICS_BIT) && queueFlagIsSupported(vkQueueFamilyProp) if (hasRequiredFlag(VK10.VK_QUEUE_GRAPHICS_BIT) && queueFlagIsSupported(vkQueueFamilyProp)
&& availableQueue > 0) { && availableQueue > 0) {
queueFamilyIndicesBuilder.withGraphicsQueueFamilyIndex(i); if (surface.isEmpty() || isSurfaceSupported(surface.get(), physicalDevice, i)) {
requiredQueueFlags &= ~VK10.VK_QUEUE_GRAPHICS_BIT; // Consume the flag queueFamilyIndicesBuilder.withGraphicsQueueFamilyIndex(i);
availableQueue--; requiredQueueFlags &= ~VK10.VK_QUEUE_GRAPHICS_BIT; // Consume the flag
availableQueue--;
}
} }
if (hasRequiredFlag(VK10.VK_QUEUE_COMPUTE_BIT) && queueFlagIsSupported(vkQueueFamilyProp) if (hasRequiredFlag(VK10.VK_QUEUE_COMPUTE_BIT) && queueFlagIsSupported(vkQueueFamilyProp)
@ -55,22 +56,14 @@ public class QueueFamilyRequirementsValidator {
&& availableQueue > 0) { && availableQueue > 0) {
queueFamilyIndicesBuilder.withTransferQueueFamilyIndex(i); queueFamilyIndicesBuilder.withTransferQueueFamilyIndex(i);
requiredQueueFlags &= ~VK10.VK_QUEUE_TRANSFER_BIT; // Consume the flag requiredQueueFlags &= ~VK10.VK_QUEUE_TRANSFER_BIT; // Consume the flag
availableQueue--;
} }
if (surface.isPresent() && isSurfaceSupported(surface.get(), physicalDevice, i) if (requiredQueueFlags == 0) {
&& availableQueue > 0) {
queueFamilyIndicesBuilder.withPresentQueueFamilyIndex(i);
surface = Optional.empty(); // Consume the surface
availableQueue--;
}
if (requiredQueueFlags == 0 && surface.isEmpty()) {
break; break;
} }
} }
if (requiredQueueFlags == 0 && surface.isEmpty()) { if (requiredQueueFlags == 0) {
return Optional.of(queueFamilyIndicesBuilder.build()); return Optional.of(queueFamilyIndicesBuilder.build());
} }