Skip to content

Commit

Permalink
Fix Segfault on Wayland when closing the client
Browse files Browse the repository at this point in the history
(i.e. Wayland is fussy about the order, and Window handle must be destroyed after the Swapchain and vkInstance, and not before)

Rebase

This reverts commit 7eb7a5f.

Refactor Chunk rendering + Improve Draw Direct Performance

Make PushConstants per ChunkArea instead of per RenderSection;  Reduces PushConstant CPU usage by over 100x in DrawCall heavy scenarios

Use compile time length for ChunkArea SectionQueues to improve JIT Optimisations

Merge Direct/Indirect Shaders:
Use same shader for both Direct and Draw Indirect + remove Indirect Pipeline

Skip 0 index (i.e. empty draw calls) checks + reduce DescriptorSet binding Frequency

Faster Gaussian Sky Blending

[GPU Optimisation]: Separate VertexBuffers per RenderType

Use Queue Enum + Split CommandPools based on Queue/Operation Type

Dedicated Transfer Queue specific fixes

Enable VK12 VMA Features

Bizarrely Improves Performance by at least 15/20% according to initial testing

Optimise Chunk Shader

(May either have no performance improvement and/or have possible Shader/Visual artefacts)

Early-Z Optimisations + Reduce AreaBuffer Fragmentation + Final Cleanup

(Quick Summary)

* Align Sizes to power of 2
* Reduce Pipeline Binding Frequency
* Refactor ChunkTask to use RenderType enums to reduce CPU +
* improve JIT optimisations
* Try to use Early-Z on Translucent RenderType

Fix Segfault on Wayland when closing the client

(i.e. Wayland is fussy about the order, and Window handle must be destroyed after the Swapchain and vkInstance, and not before)

Revert "Rebase"

This reverts commit f0382e3.
  • Loading branch information
thr3343 committed Nov 17, 2023
1 parent 6aef636 commit 66bcb0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/main/java/net/vulkanmod/mixin/render/MinecraftMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ public void close(CallbackInfo ci) {
Vulkan.waitIdle();

}
@Inject(method = "close", at = @At(value = "RETURN"))
/**
* @author
* @reason On Wayland the window (apparently) can only be safely destroyed after both SwapChain and VkInstance are Destroyed, and not before (Hence injecting at HEAD and not RETURN)
*/
@Inject(method = "close", at = @At(value = "HEAD"))
public void close2(CallbackInfo ci) {

Vulkan.cleanUp();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/vulkanmod/vulkan/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ public void cleanUpResources() {

TerrainShaderManager.destroyPipelines();
VTextureSelector.getWhiteTexture().free();
VTextureSelector.freeAll();
}

private void destroySyncObjects() {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/net/vulkanmod/vulkan/Vulkan.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.vulkanmod.vulkan.queue.Queue;
import net.vulkanmod.vulkan.queue.TransferQueue;
import net.vulkanmod.vulkan.shader.Pipeline;
import net.vulkanmod.vulkan.texture.VTextureSelector;
import net.vulkanmod.vulkan.texture.VulkanImage;
import net.vulkanmod.vulkan.util.VUtil;
import org.lwjgl.PointerBuffer;
Expand Down Expand Up @@ -194,11 +195,13 @@ public static void cleanUp() {
vkDestroyFence(Device.device, immediateFence, null);

Pipeline.destroyPipelineCache();
// WorldRenderer.getInstance().cleanUp();
Renderer.getInstance().cleanUpResources();
swapChain.getRenderPass().cleanUp();
swapChain.cleanUp();

Renderer.getInstance().cleanUpResources();
freeStagingBuffers();

// VTextureSelector.freeAll();
try {
MemoryManager.getInstance().freeAllBuffers();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ public long getId() {
public static class AttachmentInfo {
final Type type;
final int format;
VulkanImage attachment;
int initialLayout;
int loadOp;
int storeOp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ public static VulkanImage getOverlayTexture() {
public static VulkanImage getBoundTexture() { return boundTexture; }

public static VulkanImage getWhiteTexture() { return whiteTexture; }

public static void freeAll()
{
framebufferTexture.doFree();
framebufferTexture2.doFree();
}
}

0 comments on commit 66bcb0a

Please sign in to comment.