Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcao3 committed Feb 13, 2024
1 parent 7795ab1 commit c9637b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Pair<VRef<VAccelerationStructure>, VRef<VBuffer>> buildBlas(List<Pair<RenderLaye
}
geometryBuffer.get().unmap();

VRef<VAccelerationStructure> blas = null;
VRef<VAccelerationStructure> blas;
try (var stack = MemoryStack.stackPush()) {
int[] primitiveCounts = new int[infos.size()];
var buildInfo = populateBuildStructs(ctx, stack, cmd, infos, primitiveCounts);
Expand Down Expand Up @@ -156,7 +156,7 @@ private static VRef<VAccelerationStructure> executeBlasBuild(VContext ctx, VCmdB

vkCmdBuildAccelerationStructuresKHR(cmd.buffer(), buildInfos, stack.pointers(buildRanges));

vkCmdPipelineBarrier(cmd.buffer(), VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, 0, VkMemoryBarrier.calloc(1)
vkCmdPipelineBarrier(cmd.buffer(), VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR, 0, VkMemoryBarrier.calloc(1, stack)
.sType$Default()
.srcAccessMask(VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR)
.dstAccessMask(VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR), null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class VulkanPipeline {
private final AccelerationManager accelerationManager;

private record RtPipeline(VRef<VRaytracePipeline> pipeline, int commonSet, int geomSet, int customTexSet, int ssboSet) {}
private ArrayList<RtPipeline> raytracePipelines = new ArrayList<>();
private final ArrayList<RtPipeline> raytracePipelines = new ArrayList<>();

private final VRef<VSampler> sampler;
private final VRef<VSampler> ctexSampler;
Expand All @@ -71,8 +71,6 @@ private record RtPipeline(VRef<VRaytracePipeline> pipeline, int commonSet, int g
private final VRef<VImage> placeholderNormals;
private final VRef<VImageView> placeholderNormalsView;

private int fidx;

private final int maxIrisRenderTargets = 16;

private final boolean supportsEntities;
Expand Down Expand Up @@ -229,9 +227,6 @@ public VulkanPipeline(VContext ctx, AccelerationManager accelerationManager, Ray
}
}

private VSemaphore previousSemaphore;


private final EntityCapture capture = new EntityCapture();
private void buildEntities() {
accelerationManager.setEntityData(supportsEntities?capture.capture(CapturedRenderingState.INSTANCE.getTickDelta(), MinecraftClient.getInstance().world):null);
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/me/cortex/vulkanite/lib/cmd/CommandManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.cortex.vulkanite.lib.cmd;

import static me.cortex.vulkanite.lib.other.VUtil._CHECK_;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
Expand All @@ -18,6 +16,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

import static me.cortex.vulkanite.lib.other.VUtil._CHECK_;
import static org.lwjgl.system.MemoryStack.stackPush;
import static org.lwjgl.vulkan.VK10.*;
import static org.lwjgl.vulkan.VK12.vkWaitSemaphores;
Expand All @@ -27,14 +26,11 @@ public class CommandManager {
private final VkDevice device;
private final Queue[] queues;
private final ThreadLocal<VRef<VCommandPool>> threadLocalPool =
new ThreadLocal<>() {
@Override
protected VRef<VCommandPool> initialValue() {
var pool = createSingleUsePool();
pool.get().setDebugUtilsObjectName("Thread-local single use pool");
return pool;
}
};
ThreadLocal.withInitial(() -> {
var pool = createSingleUsePool();
pool.get().setDebugUtilsObjectName("Thread-local single use pool");
return pool;
});

public CommandManager(VkDevice device, int queues) {
this.device = device;
Expand Down Expand Up @@ -69,6 +65,7 @@ public void executeWait(Consumer<VCmdBuff> cmdbuf) {

/**
* Enqueues a wait for a timeline value on a queue
*
* @param waitQueueId The queue that will wait
* @param executionQueueId The queue whose timeline value will be waited for
* @param execution The timeline value to wait for
Expand All @@ -79,6 +76,7 @@ public void queueWaitForExeuction(int waitQueueId, int executionQueueId, long ex

/**
* Wait on the host for a timeline value on a queue
*
* @param waitQueueId The queue whose timeline value will be waited for
* @param execution The timeline value to wait for
*/
Expand Down Expand Up @@ -125,12 +123,12 @@ public synchronized void newFrame() {

private static class Queue {
public final VkQueue queue;
public final Multimap<Integer, Long> waitingFor = Multimaps.synchronizedMultimap(HashMultimap.<Integer, Long>create());
public final Multimap<Integer, Long> waitingFor = Multimaps.synchronizedMultimap(HashMultimap.create());
public final ConcurrentHashMap<Long, VRef<VCmdBuff>> submitted = new ConcurrentHashMap<>();
public AtomicLong timeline = new AtomicLong(1);
public long completedTimestamp = 0;
public final VRef<VSemaphore> timelineSema;
public final Deque<Long> frameTimestamps = new ArrayDeque<>(3);
public AtomicLong timeline = new AtomicLong(1);
public long completedTimestamp = 0;

public Queue(int queueId, VkDevice device) {
try (var stack = stackPush()) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/me/cortex/vulkanite/lib/cmd/VCmdBuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import me.cortex.vulkanite.lib.other.sync.VSemaphore;
import me.cortex.vulkanite.lib.pipeline.VComputePipeline;
import me.cortex.vulkanite.lib.pipeline.VRaytracePipeline;
import org.lwjgl.system.Pointer;
import org.lwjgl.vulkan.*;
import org.lwjgl.system.MemoryUtil;

Expand All @@ -34,7 +33,7 @@ public class VCmdBuff extends VObject {
private final VCommandPool pool;
private VkCommandBuffer buffer;

private final List<VRef<VQueryPool>> queryPoolRefs = new ArrayList<>();
@SuppressWarnings("FieldCanBeLocal")
private final List<VRef<VObject>> refs = new ArrayList<>();

public void addBufferRef(final VRef<VBuffer> buffer) {
Expand Down Expand Up @@ -138,7 +137,7 @@ public void dispatch(int x, int y, int z) {

public void resetQueryPool(final VRef<VQueryPool> queryPool, int first, int size) {
vkCmdResetQueryPool(buffer, queryPool.get().pool, first, size);
queryPoolRefs.add(queryPool.addRef());
refs.add(queryPool.addRefGeneric());
}

public void encodeDataUpload(MemoryManager manager, long src, final VRef<VBuffer> dest, long destOffset, long size) {
Expand Down

0 comments on commit c9637b4

Please sign in to comment.