Skip to content

Commit 2992891

Browse files
committed
Fix uniform upload bug when loading new dimension
1 parent b6fe3ae commit 2992891

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

src/main/java/net/vulkanmod/vulkan/Renderer.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public void preInitFrame() {
220220
// runTick might be called recursively,
221221
// this check forces sync to avoid upload corruption
222222
if (lastReset == currentFrame) {
223+
submitUploads();
223224
waitFences();
224225
}
225226
lastReset = currentFrame;
@@ -345,7 +346,7 @@ private void submitFrame() {
345346

346347
vkResetFences(device, inFlightFences.get(currentFrame));
347348

348-
if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().queue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) {
349+
if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().vkQueue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) {
349350
vkResetFences(device, inFlightFences.get(currentFrame));
350351
throw new RuntimeException("Failed to submit draw command buffer: %s".formatted(VkResult.decode(vkResult)));
351352
}
@@ -360,7 +361,7 @@ private void submitFrame() {
360361

361362
presentInfo.pImageIndices(stack.ints(imageIndex));
362363

363-
vkResult = vkQueuePresentKHR(DeviceManager.getPresentQueue().queue(), presentInfo);
364+
vkResult = vkQueuePresentKHR(DeviceManager.getPresentQueue().vkQueue(), presentInfo);
364365

365366
if (vkResult == VK_ERROR_OUT_OF_DATE_KHR || vkResult == VK_SUBOPTIMAL_KHR || swapChainUpdate) {
366367
swapChainUpdate = true;
@@ -396,7 +397,7 @@ public void flushCmds() {
396397
submitUploads();
397398
waitFences();
398399

399-
if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().queue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) {
400+
if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().vkQueue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) {
400401
vkResetFences(device, inFlightFences.get(currentFrame));
401402
throw new RuntimeException("Failed to submit draw command buffer: %s".formatted(VkResult.decode(vkResult)));
402403
}
@@ -411,19 +412,17 @@ public void submitUploads() {
411412
var transferCb = transferCbs.get(currentFrame);
412413

413414
if (transferCb.isRecording()) {
414-
415+
final var transferQueue = DeviceManager.getTransferQueue();
415416
try (MemoryStack stack = MemoryStack.stackPush()) {
416-
transferCb.submitCommands(stack,
417-
DeviceManager.getTransferQueue().queue(),
418-
false);
417+
transferCb.submitCommands(stack, transferQueue.vkQueue(), false);
419418
}
420419

421420
Synchronization.INSTANCE.addCommandBuffer(transferCb);
422421

423-
transferCbs.set(currentFrame, DeviceManager.getTransferQueue()
424-
.getCommandPool()
425-
.getCommandBuffer());
422+
transferCbs.set(currentFrame, transferQueue.getCommandPool().getCommandBuffer());
426423
}
424+
425+
ImageUploadHelper.INSTANCE.submitCommands();
427426
}
428427

429428
public void endRenderPass() {
@@ -468,7 +467,6 @@ public void removeUsedPipeline(Pipeline pipeline) {
468467

469468
private void waitFences() {
470469
// Make sure there are no uploads/transitions scheduled
471-
ImageUploadHelper.INSTANCE.submitCommands();
472470
Synchronization.INSTANCE.waitFences();
473471
Vulkan.getStagingBuffer().reset();
474472
}
@@ -494,7 +492,7 @@ void waitForSwapChain() {
494492
.pWaitSemaphores(stack.longs(imageAvailableSemaphores.get(currentFrame)))
495493
.pWaitDstStageMask(stack.ints(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT));
496494

497-
vkQueueSubmit(DeviceManager.getGraphicsQueue().queue(), info, inFlightFences.get(currentFrame));
495+
vkQueueSubmit(DeviceManager.getGraphicsQueue().vkQueue(), info, inFlightFences.get(currentFrame));
498496
vkWaitForFences(device, inFlightFences.get(currentFrame), true, -1);
499497
}
500498
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public abstract class Queue {
2121
private static VkDevice device;
2222
private static QueueFamilyIndices queueFamilyIndices;
2323

24-
private final VkQueue queue;
24+
private final VkQueue vkQueue;
2525

2626
protected CommandPool commandPool;
2727

@@ -41,20 +41,20 @@ public synchronized CommandPool.CommandBuffer beginCommands() {
4141
Queue(MemoryStack stack, int familyIndex, boolean initCommandPool) {
4242
PointerBuffer pQueue = stack.mallocPointer(1);
4343
vkGetDeviceQueue(DeviceManager.vkDevice, familyIndex, 0, pQueue);
44-
this.queue = new VkQueue(pQueue.get(0), DeviceManager.vkDevice);
44+
this.vkQueue = new VkQueue(pQueue.get(0), DeviceManager.vkDevice);
4545

4646
if (initCommandPool)
4747
this.commandPool = new CommandPool(familyIndex);
4848
}
4949

5050
public synchronized long submitCommands(CommandPool.CommandBuffer commandBuffer) {
5151
try (MemoryStack stack = stackPush()) {
52-
return commandBuffer.submitCommands(stack, queue, false);
52+
return commandBuffer.submitCommands(stack, vkQueue, false);
5353
}
5454
}
5555

56-
public VkQueue queue() {
57-
return this.queue;
56+
public VkQueue vkQueue() {
57+
return this.vkQueue;
5858
}
5959

6060
public void cleanUp() {
@@ -63,7 +63,7 @@ public void cleanUp() {
6363
}
6464

6565
public void waitIdle() {
66-
vkQueueWaitIdle(queue);
66+
vkQueueWaitIdle(vkQueue);
6767
}
6868

6969
public CommandPool getCommandPool() {

0 commit comments

Comments
 (0)