Skip to content

Commit

Permalink
Minor Cleanup + Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thr3343 committed Oct 6, 2024
1 parent 1b2e1cc commit b2da2b7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 53 deletions.
5 changes: 0 additions & 5 deletions src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public class WorldRenderer {
private SectionGraph sectionGraph;
private boolean graphNeedsUpdate;

private final Set<BlockEntity> globalBlockEntities = Sets.newHashSet();

private final TaskDispatcher taskDispatcher;

private double xTransparentOld;
Expand Down Expand Up @@ -249,9 +247,6 @@ public void allChanged() {
}

this.taskDispatcher.clearBatchQueue();
synchronized (this.globalBlockEntities) {
this.globalBlockEntities.clear();
}

this.sectionGrid = new SectionGrid(this.level, this.renderDistance);
this.sectionGraph = new SectionGraph(this.level, this.sectionGrid, this.taskDispatcher);
Expand Down
58 changes: 19 additions & 39 deletions src/main/java/net/vulkanmod/render/chunk/buffer/UploadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.vulkanmod.vulkan.Synchronization;
import net.vulkanmod.vulkan.Vulkan;
import net.vulkanmod.vulkan.device.DeviceManager;
import net.vulkanmod.vulkan.memory.Buffer;
import net.vulkanmod.vulkan.memory.StagingBuffer;
import net.vulkanmod.vulkan.queue.CommandPool;
import net.vulkanmod.vulkan.queue.Queue;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.VkBufferMemoryBarrier;
import org.lwjgl.vulkan.VkCommandBuffer;
Expand All @@ -25,16 +23,15 @@ public static void createInstance() {
INSTANCE = new UploadManager();
}

Queue queue = DeviceManager.getTransferQueue();
CommandPool.CommandBuffer commandBuffer;
private CommandPool.CommandBuffer commandBuffer;

LongOpenHashSet dstBuffers = new LongOpenHashSet();
private final LongOpenHashSet dstBuffers = new LongOpenHashSet();

public void submitUploads() {
if (this.commandBuffer == null)
return;

this.queue.submitCommands(this.commandBuffer);
TransferQueue.submitCommands(this.commandBuffer);

Synchronization.INSTANCE.addCommandBuffer(this.commandBuffer);

Expand All @@ -51,19 +48,14 @@ public void recordUpload(Buffer buffer, long dstOffset, long bufferSize, ByteBuf
stagingBuffer.copyBuffer((int) bufferSize, src);

if (!this.dstBuffers.add(buffer.getId())) {
try (MemoryStack stack = MemoryStack.stackPush()) {
VkMemoryBarrier.Buffer barrier = VkMemoryBarrier.calloc(1, stack);
barrier.sType$Default();
barrier.srcAccessMask(VK_ACCESS_TRANSFER_WRITE_BIT);
barrier.dstAccessMask(VK_ACCESS_TRANSFER_WRITE_BIT);

vkCmdPipelineBarrier(commandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
barrier,
null,
null);
}
//Use BufferBarrier + granular QueueFamilyIndex
TransferQueue.BufferBarrier(commandBuffer,
buffer.getId(),
bufferSize,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);

this.dstBuffers.clear();
}
Expand All @@ -80,25 +72,13 @@ public void copyBuffer(Buffer src, int srcOffset, Buffer dst, int dstOffset, int

VkCommandBuffer commandBuffer = this.commandBuffer.getHandle();

try (MemoryStack stack = MemoryStack.stackPush()) {
VkMemoryBarrier.Buffer barrier = VkMemoryBarrier.calloc(1, stack);
barrier.sType$Default();

VkBufferMemoryBarrier.Buffer bufferMemoryBarriers = VkBufferMemoryBarrier.calloc(1, stack);
VkBufferMemoryBarrier bufferMemoryBarrier = bufferMemoryBarriers.get(0);
bufferMemoryBarrier.sType$Default();
bufferMemoryBarrier.buffer(src.getId());
bufferMemoryBarrier.srcAccessMask(VK_ACCESS_TRANSFER_WRITE_BIT);
bufferMemoryBarrier.dstAccessMask(VK_ACCESS_TRANSFER_READ_BIT);
bufferMemoryBarrier.size(VK_WHOLE_SIZE);

vkCmdPipelineBarrier(commandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
barrier,
bufferMemoryBarriers,
null);
}
TransferQueue.BufferBarrier(commandBuffer,
src.getId(),
VK_WHOLE_SIZE,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);

this.dstBuffers.add(dst.getId());

Expand All @@ -113,7 +93,7 @@ public void syncUploads() {

private void beginCommands() {
if (this.commandBuffer == null)
this.commandBuffer = queue.beginCommands();
this.commandBuffer = TransferQueue.beginCommands();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import java.util.List;

public class SectionGraph {
Minecraft minecraft;
private final Minecraft minecraft;
private final Level level;

private final SectionGrid sectionGrid;
private final ChunkAreaManager chunkAreaManager;
private final TaskDispatcher taskDispatcher;
private final ResettableQueue<RenderSection> sectionQueue = new ResettableQueue<>();
private AreaSetQueue chunkAreaQueue;
private final AreaSetQueue chunkAreaQueue;
private short lastFrame = 0;

private final ResettableQueue<RenderSection> blockEntitiesSections = new ResettableQueue<>();
Expand All @@ -45,7 +44,6 @@ public class SectionGraph {
public SectionGraph(Level level, SectionGrid sectionGrid, TaskDispatcher taskDispatcher) {
this.level = level;
this.sectionGrid = sectionGrid;
this.chunkAreaManager = sectionGrid.getChunkAreaManager();
this.taskDispatcher = taskDispatcher;

this.chunkAreaQueue = new AreaSetQueue(sectionGrid.getChunkAreaManager().size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ private void createRenderPass() {
.srcStageMask(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)
.dstStageMask(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT)
.srcAccessMask(0)
.dstAccessMask(0);
.dstAccessMask(0)
.dependencyFlags(VK_DEPENDENCY_BY_REGION_BIT); //FrameBuffer local Scope

renderPassInfo.pDependencies(subpassDependencies);
}
Expand All @@ -120,7 +121,8 @@ private void createRenderPass() {
.srcStageMask(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)
.dstStageMask(VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT)
.srcAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT)
.dstAccessMask(VK_ACCESS_SHADER_READ_BIT);
.dstAccessMask(VK_ACCESS_SHADER_READ_BIT)
.dependencyFlags(VK_DEPENDENCY_BY_REGION_BIT); //FrameBuffer local Scope

renderPassInfo.pDependencies(subpassDependencies);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/vulkanmod/vulkan/memory/MemoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.vulkanmod.render.chunk.buffer.AreaBuffer;
import net.vulkanmod.vulkan.Vulkan;
import net.vulkanmod.vulkan.device.DeviceManager;
import net.vulkanmod.vulkan.queue.Queue;
import net.vulkanmod.vulkan.texture.VulkanImage;
import net.vulkanmod.vulkan.util.Pair;
import net.vulkanmod.vulkan.util.VkResult;
Expand Down Expand Up @@ -166,8 +167,7 @@ public static synchronized void createImage(int width, int height, int mipLevels
imageInfo.usage(usage);
imageInfo.samples(VK_SAMPLE_COUNT_1_BIT);
// imageInfo.sharingMode(VK_SHARING_MODE_CONCURRENT);
// TODO hardcoded queue family indices
imageInfo.pQueueFamilyIndices(stack.ints(0, 1));
imageInfo.pQueueFamilyIndices(stack.ints(Queue.GraphicsQueue.familyIndex()));

VmaAllocationCreateInfo allocationInfo = VmaAllocationCreateInfo.calloc(stack);
allocationInfo.requiredFlags(memProperties);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/vulkanmod/vulkan/queue/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public long submitCommands(CommandPool.CommandBuffer commandBuffer) {

public VkQueue queue() { return this.queue; }

public int familyIndex() { return familyIndex; }

public void cleanUp() {
if(commandPool != null)
commandPool.cleanUp();
Expand Down Expand Up @@ -140,7 +142,7 @@ public void fillBuffer(long id, int bufferSize, int qNaN) {
vkCmdFillBuffer(this.getCommandBuffer().getHandle(), id, 0, bufferSize, qNaN);
}

public void BufferBarrier(VkCommandBuffer commandBuffer, long bufferhdle, int size_t, int srcAccess, int dstAccess, int srcStage, int dstStage) {
public void BufferBarrier(VkCommandBuffer commandBuffer, long bufferhdle, long size_t, int srcAccess, int dstAccess, int srcStage, int dstStage) {

try(MemoryStack stack = MemoryStack.stackPush()) {
VkBufferMemoryBarrier.Buffer memBarrier = VkBufferMemoryBarrier.calloc(1, stack)
Expand Down

0 comments on commit b2da2b7

Please sign in to comment.