diff --git a/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java b/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java index ace5b4080..875b71b93 100644 --- a/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java +++ b/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java @@ -73,8 +73,6 @@ public class WorldRenderer { private SectionGraph sectionGraph; private boolean graphNeedsUpdate; - private final Set globalBlockEntities = Sets.newHashSet(); - private final TaskDispatcher taskDispatcher; private double xTransparentOld; @@ -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); diff --git a/src/main/java/net/vulkanmod/render/chunk/buffer/UploadManager.java b/src/main/java/net/vulkanmod/render/chunk/buffer/UploadManager.java index 05d45429d..dd064592d 100644 --- a/src/main/java/net/vulkanmod/render/chunk/buffer/UploadManager.java +++ b/src/main/java/net/vulkanmod/render/chunk/buffer/UploadManager.java @@ -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; @@ -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); @@ -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(); } @@ -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()); @@ -113,7 +93,7 @@ public void syncUploads() { private void beginCommands() { if (this.commandBuffer == null) - this.commandBuffer = queue.beginCommands(); + this.commandBuffer = TransferQueue.beginCommands(); } } diff --git a/src/main/java/net/vulkanmod/render/chunk/graph/SectionGraph.java b/src/main/java/net/vulkanmod/render/chunk/graph/SectionGraph.java index ea2a35d30..299b3ddfa 100644 --- a/src/main/java/net/vulkanmod/render/chunk/graph/SectionGraph.java +++ b/src/main/java/net/vulkanmod/render/chunk/graph/SectionGraph.java @@ -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 sectionQueue = new ResettableQueue<>(); - private AreaSetQueue chunkAreaQueue; + private final AreaSetQueue chunkAreaQueue; private short lastFrame = 0; private final ResettableQueue blockEntitiesSections = new ResettableQueue<>(); @@ -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); diff --git a/src/main/java/net/vulkanmod/vulkan/framebuffer/RenderPass.java b/src/main/java/net/vulkanmod/vulkan/framebuffer/RenderPass.java index 24cc8c031..b2ea64541 100644 --- a/src/main/java/net/vulkanmod/vulkan/framebuffer/RenderPass.java +++ b/src/main/java/net/vulkanmod/vulkan/framebuffer/RenderPass.java @@ -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); } @@ -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); } diff --git a/src/main/java/net/vulkanmod/vulkan/memory/MemoryManager.java b/src/main/java/net/vulkanmod/vulkan/memory/MemoryManager.java index a007bb189..167b239c0 100644 --- a/src/main/java/net/vulkanmod/vulkan/memory/MemoryManager.java +++ b/src/main/java/net/vulkanmod/vulkan/memory/MemoryManager.java @@ -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; @@ -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); diff --git a/src/main/java/net/vulkanmod/vulkan/queue/Queue.java b/src/main/java/net/vulkanmod/vulkan/queue/Queue.java index cc44ca8e8..6ae03009f 100644 --- a/src/main/java/net/vulkanmod/vulkan/queue/Queue.java +++ b/src/main/java/net/vulkanmod/vulkan/queue/Queue.java @@ -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(); @@ -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)