Skip to content

Commit

Permalink
WIP, trying to figure out what's tanking perf & fixing host memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcao3 committed Feb 13, 2024
1 parent 5664035 commit 7795ab1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private static VRef<VAccelerationStructure> executeBlasBuild(VContext ctx, VCmdB
.srcAccessMask(VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR)
.dstAccessMask(VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR), null, null);

cmd.addAccelerationStructureRef(structure);
cmd.addBufferRef(scratch);
return structure;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ private void buildEntities() {
public void renderPostShadows(List<VRef<VGImage>> vgOutImgs, Camera camera, ShaderStorageBuffer[] ssbos, MixinCelestialUniforms celestialUniforms) {
ctx.cmd.newFrame();

// System.gc();

buildEntities();

PBRTextureManager.notifyPBRTexturesChanged();
Expand Down Expand Up @@ -412,7 +410,7 @@ public void renderPostShadows(List<VRef<VGImage>> vgOutImgs, Camera camera, Shad
}
}

ctx.cmd.submit(0, cmdRef, Arrays.asList(new VRef<>(in.get())), new int[]{VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT}, Arrays.asList(new VRef<>(out.get())), null);
ctx.cmd.submit(0, cmdRef, Arrays.asList(new VRef<>(in.get())), Arrays.asList(new VRef<>(out.get())), null);
}

out.get().glWait(new int[0], outImgsGlIds, outImgsGlLayouts);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/me/cortex/vulkanite/lib/cmd/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.cortex.vulkanite.lib.other.sync.VSemaphore;
import org.lwjgl.vulkan.*;

import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -35,8 +36,6 @@ protected VRef<VCommandPool> initialValue() {
}
};

private static final int[] waitAll = {VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT};

public CommandManager(VkDevice device, int queues) {
this.device = device;
this.queues = new Queue[queues];
Expand Down Expand Up @@ -103,14 +102,14 @@ public void hostWaitForExecution(int waitQueueId, long execution) {
}

public long submit(int queueId, final VRef<VCmdBuff> cmdBuff) {
return submit(queueId, cmdBuff, null, waitAll, null, null);
return submit(queueId, cmdBuff, null, null, null);
}

public long submit(int queueId, final VRef<VCmdBuff> cmdBuff, List<VRef<VSemaphore>> waits, int[] waitStages, List<VRef<VSemaphore>> triggers, VFence fence) {
public long submit(int queueId, final VRef<VCmdBuff> cmdBuff, List<VRef<VSemaphore>> waits, List<VRef<VSemaphore>> triggers, VFence fence) {
if (queueId == 0) {
RenderSystem.assertOnRenderThread();
}
return queues[queueId].submit(cmdBuff, queues, waits, waitStages, triggers, fence);
return queues[queueId].submit(cmdBuff, queues, waits, triggers, fence);
}

public void waitQueueIdle(int queue) {
Expand Down Expand Up @@ -191,7 +190,7 @@ public void waitForExecution(int execQueue, long execution) {
}
}

public long submit(final VRef<VCmdBuff> cmdBuff, Queue[] queues, List<VRef<VSemaphore>> waits, int[] waitStages, List<VRef<VSemaphore>> triggers, VFence fence) {
public long submit(final VRef<VCmdBuff> cmdBuff, Queue[] queues, List<VRef<VSemaphore>> waits, List<VRef<VSemaphore>> triggers, VFence fence) {
long t = timeline.getAndIncrement();

synchronized (this) {
Expand All @@ -206,11 +205,13 @@ public long submit(final VRef<VCmdBuff> cmdBuff, Queue[] queues, List<VRef<VSema
LongBuffer signalSemaphores = stack.mallocLong(triggerCount);
LongBuffer waitTimelineValues = stack.mallocLong(waitCount);
LongBuffer signalTimelineValues = stack.mallocLong(triggerCount);
IntBuffer waitStages = stack.mallocInt(waitCount);
// Traditional binary semaphores
if (waits != null) {
for (var wait : waits) {
waitSemaphores.put(wait.get().address());
waitTimelineValues.put(0);
waitStages.put(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
cmdBuff.get().addSemaphoreRef(wait);
}
}
Expand All @@ -226,6 +227,7 @@ public long submit(final VRef<VCmdBuff> cmdBuff, Queue[] queues, List<VRef<VSema
var sema = queues[entry.getKey()].timelineSema;
waitSemaphores.put(sema.get().address());
waitTimelineValues.put(entry.getValue());
waitStages.put(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
cmdBuff.get().addSemaphoreRef(sema);
}
signalSemaphores.put(timelineSema.get().address());
Expand All @@ -236,6 +238,7 @@ public long submit(final VRef<VCmdBuff> cmdBuff, Queue[] queues, List<VRef<VSema
signalSemaphores.rewind();
waitTimelineValues.rewind();
signalTimelineValues.rewind();
waitStages.rewind();

var timelineSubmitInfo = VkTimelineSemaphoreSubmitInfo.calloc(stack)
.sType$Default()
Expand All @@ -248,7 +251,7 @@ public long submit(final VRef<VCmdBuff> cmdBuff, Queue[] queues, List<VRef<VSema
.pCommandBuffers(stack.pointers(cmdBuff.get().seal()))
.pWaitSemaphores(waitSemaphores)
.waitSemaphoreCount(waitCount)
.pWaitDstStageMask(stack.ints(waitStages))
.pWaitDstStageMask(waitStages)
.pSignalSemaphores(signalSemaphores)
.pNext(timelineSubmitInfo.address());
_CHECK_(vkQueueSubmit(queue, submit, fence == null ? 0 : fence.address()));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/cortex/vulkanite/lib/cmd/VCmdBuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.cortex.vulkanite.lib.base.VRef;
import me.cortex.vulkanite.lib.descriptors.VDescriptorSet;
import me.cortex.vulkanite.lib.memory.MemoryManager;
import me.cortex.vulkanite.lib.memory.VAccelerationStructure;
import me.cortex.vulkanite.lib.memory.VBuffer;
import me.cortex.vulkanite.lib.memory.VImage;

Expand Down Expand Up @@ -48,6 +49,9 @@ public void addSemaphoreRef(final VRef<VSemaphore> semaphore) {
public void addVGSemaphoreRef(final VRef<VGSemaphore> semaphore) {
refs.add(semaphore.addRefGeneric());
}
public void addAccelerationStructureRef(final VRef<VAccelerationStructure> accelerationStructure) {
refs.add(accelerationStructure.addRefGeneric());
}

protected VCmdBuff(VCommandPool pool, VkCommandBuffer buff, int flags) {
this.pool = pool;
Expand Down

0 comments on commit 7795ab1

Please sign in to comment.