Skip to content

Commit 2e66e66

Browse files
committed
More robust transfer queue fallback system
1 parent a04c526 commit 2e66e66

File tree

1 file changed

+20
-30
lines changed
  • src/main/java/net/vulkanmod/vulkan/queue

1 file changed

+20
-30
lines changed

src/main/java/net/vulkanmod/vulkan/queue/Queue.java

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public static QueueFamilyIndices getQueueFamilies() {
8686
return queueFamilyIndices;
8787
}
8888

89+
private static int findFirstQueueIndex(VkQueueFamilyProperties.Buffer queueFamilies, int flags) {
90+
for (int i = 0; i < queueFamilies.capacity(); i++) {
91+
int queueFlags = queueFamilies.get(i).queueFlags();
92+
if((queueFlags & flags) != 0) return i;
93+
}
94+
return -1;
95+
}
96+
8997
public static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) {
9098
QueueFamilyIndices indices = new QueueFamilyIndices();
9199

@@ -141,40 +149,22 @@ public static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) {
141149
}
142150

143151
if (indices.transferFamily == -1) {
144-
145-
int fallback = -1;
146-
for (int i = 0; i < queueFamilies.capacity(); i++) {
147-
int queueFlags = queueFamilies.get(i).queueFlags();
148-
149-
if ((queueFlags & VK_QUEUE_TRANSFER_BIT) != 0) {
150-
if (fallback == -1)
151-
fallback = i;
152-
153-
if ((queueFlags & (VK_QUEUE_GRAPHICS_BIT)) == 0) {
154-
indices.transferFamily = i;
155-
156-
if (i != indices.computeFamily)
157-
break;
158-
fallback = i;
159-
}
160-
}
161-
162-
if (fallback == -1)
163-
throw new RuntimeException("Failed to find queue family with transfer support");
164-
165-
indices.transferFamily = fallback;
152+
// Some driversmay not have a transfer-only queue (for example iGPUs, when there's usually no need for DMA)
153+
int fallback = findFirstQueueIndex(queueFamilies, VK_QUEUE_TRANSFER_BIT);
154+
if(fallback == -1) {
155+
// the Adreno driver takes this further: it straight up has no queues with the transfer bit.
156+
// Rely on a compute or graphics queue in this case.
157+
Initializer.LOGGER.warn("No transfer queues found, will try compute-graphics queue");
158+
fallback = findFirstQueueIndex(queueFamilies, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT);
166159
}
160+
if(fallback == -1)
161+
throw new RuntimeException("Failed to a suitable transfer queue fallback");
162+
else
163+
indices.transferFamily = fallback;
167164
}
168165

169166
if (indices.computeFamily == -1) {
170-
for (int i = 0; i < queueFamilies.capacity(); i++) {
171-
int queueFlags = queueFamilies.get(i).queueFlags();
172-
173-
if ((queueFlags & VK_QUEUE_COMPUTE_BIT) != 0) {
174-
indices.computeFamily = i;
175-
break;
176-
}
177-
}
167+
indices.computeFamily = findFirstQueueIndex(queueFamilies, VK_QUEUE_COMPUTE_BIT);
178168
}
179169

180170
if (indices.graphicsFamily == VK_QUEUE_FAMILY_IGNORED)

0 commit comments

Comments
 (0)