Skip to content

Commit

Permalink
Merge branch '1.20.x' into vk12Bindless3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thr3343 committed Jul 25, 2024
2 parents 9e9dd90 + 10d52c2 commit 90d17e7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public ChunkArea getChunkArea(RenderSection section, int x, int y, int z) {
return chunkArea;
}

public ChunkArea getChunkArea(int idx) {
return idx >= 0 && idx < chunkAreasArr.length ? this.chunkAreasArr[idx] : null;
}

public void updateFrustumVisibility(VFrustum frustum) {
FrustumOctree.updateFrustumVisibility(frustum, this.chunkAreasArr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AreaBuffer(Usage usage, int elementCount, int elementSize) {
this.size = elementCount * elementSize;
this.buffer = this.allocateBuffer();

Segment s = new Segment(0, elementCount);
Segment s = new Segment(0, this.size);

segments++;
last = first = s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ private AreaBuffer getAreaBufferOrAlloc(TerrainRenderType renderType) {
this.allocated = true;

int initialSize = switch (renderType) {
case SOLID -> 30000;
case CUTOUT -> 100000;
case CUTOUT_MIPPED -> 300000;
case SOLID, CUTOUT -> 100000;
case CUTOUT_MIPPED -> 250000;
case TRANSLUCENT, TRIPWIRE -> 60000;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.google.common.collect.Queues;
import net.vulkanmod.render.chunk.ChunkArea;
import net.vulkanmod.render.chunk.ChunkAreaManager;
import net.vulkanmod.render.chunk.RenderSection;
import net.vulkanmod.render.chunk.buffer.UploadManager;
import net.vulkanmod.render.chunk.WorldRenderer;
import net.vulkanmod.render.chunk.buffer.DrawBuffers;
import net.vulkanmod.render.chunk.build.task.ChunkTask;
import net.vulkanmod.render.chunk.build.task.CompileResult;
Expand All @@ -12,8 +13,7 @@
import net.vulkanmod.render.vertex.TerrainRenderType;

import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.EnumMap;

import java.util.Queue;

public class TaskDispatcher {
Expand Down Expand Up @@ -153,6 +153,11 @@ private void doSectionUpdate(CompileResult compileResult) {
ChunkArea renderArea = section.getChunkArea();
DrawBuffers drawBuffers = renderArea.getDrawBuffers();

// Check if area has been dismissed before uploading
ChunkAreaManager chunkAreaManager = WorldRenderer.getInstance().getChunkAreaManager();
if (chunkAreaManager.getChunkArea(renderArea.index) != renderArea)
return;

if(compileResult.fullUpdate) {
var renderLayers = compileResult.renderedLayers;
for(TerrainRenderType renderType : TerrainRenderType.VALUES) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/vulkanmod/vulkan/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.vulkanmod.vulkan.texture.SamplerManager;
import net.vulkanmod.vulkan.texture.VTextureSelector;
import net.vulkanmod.vulkan.util.VUtil;
import net.vulkanmod.vulkan.util.VkResult;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.*;
Expand Down Expand Up @@ -356,7 +357,6 @@ private void submitFrame() {
return;

try (MemoryStack stack = stackPush()) {

int vkResult;

VkSubmitInfo submitInfo = VkSubmitInfo.calloc(stack);
Expand All @@ -375,7 +375,8 @@ private void submitFrame() {
Synchronization.INSTANCE.waitFences();

if ((vkResult = vkQueueSubmit(DeviceManager.getGraphicsQueue().queue(), submitInfo, inFlightFences.get(currentFrame))) != VK_SUCCESS) {
throw new RuntimeException("Failed to submit draw command buffer: " + vkResult);
vkResetFences(device, stack.longs(inFlightFences.get(currentFrame)));
throw new RuntimeException("Failed to submit draw command buffer: %s".formatted(VkResult.decode(vkResult)));
}

VkPresentInfoKHR presentInfo = VkPresentInfoKHR.calloc(stack);
Expand Down Expand Up @@ -455,7 +456,6 @@ public void preInitFrame() {

WorldRenderer.getInstance().uploadSections();
UploadManager.INSTANCE.submitUploads();
UploadManager.INSTANCE.syncUploads();
}

public void addUsedPipeline(Pipeline pipeline) {
Expand Down Expand Up @@ -510,7 +510,6 @@ private void recreateSwapChain() {

if (framesNum != newFramesNum) {
UploadManager.INSTANCE.submitUploads();
UploadManager.INSTANCE.syncUploads();

framesNum = newFramesNum;
MemoryManager.createInstance(newFramesNum);
Expand Down

0 comments on commit 90d17e7

Please sign in to comment.