This commit is contained in:
mcrcortex
2025-09-14 22:07:38 +10:00
parent 8c49b42aa6
commit 0b5183e196
17 changed files with 169 additions and 28 deletions

View File

@@ -69,6 +69,11 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
this.sectionRenderer = sectionRenderer;
}
//Called before the pipeline starts running, used to update uniforms etc
public void preSetup(Viewport<?> viewport) {
}
protected abstract int setup(Viewport<?> viewport, int sourceFramebuffer, int srcWidth, int srcHeight);
protected abstract void postOpaquePreTranslucent(Viewport<?> viewport);
protected void finish(Viewport<?> viewport, int sourceFrameBuffer, int srcWidth, int srcHeight) {
@@ -200,8 +205,19 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
public abstract void setupAndBindTranslucent(Viewport<?> viewport);
public void bindUniforms() {
this.bindUniforms(-1);
}
public void bindUniforms(int index) {
}
//null means no function, otherwise return the taa injection function
public String taaFunction(AbstractSectionRenderer<?,?> renderer, String functionName) {
public String taaFunction(String functionName) {
return this.taaFunction(-1, functionName);
}
public String taaFunction(int uboBindingPoint, String functionName) {
return null;
}

View File

@@ -90,14 +90,18 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
}
@Override
protected int setup(Viewport<?> viewport, int sourceFramebuffer, int srcWidth, int srcHeight) {
public void preSetup(Viewport<?> viewport) {
super.preSetup(viewport);
if (this.shaderUniforms != null) {
//Update the uniforms
long ptr = UploadStream.INSTANCE.uploadTo(this.shaderUniforms);
this.data.getUniforms().updater().accept(ptr);
UploadStream.INSTANCE.commit();
}
}
@Override
protected int setup(Viewport<?> viewport, int sourceFramebuffer, int srcWidth, int srcHeight) {
this.fb.resize(viewport.width, viewport.height);
this.fbTranslucent.resize(viewport.width, viewport.height);
@@ -144,10 +148,20 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
}
private void doBindings() {
@Override
public void bindUniforms() {
this.bindUniforms(UNIFORM_BINDING_POINT);
}
@Override
public void bindUniforms(int bindingPoint) {
if (this.shaderUniforms != null) {
GL30.glBindBufferBase(GL_UNIFORM_BUFFER, 5, this.shaderUniforms.id);// todo: dont randomly select this to 5
GL30.glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, this.shaderUniforms.id);// todo: dont randomly select this to 5
}
}
private void doBindings() {
this.bindUniforms();
if (this.data.getSsboSet() != null) {
this.data.getSsboSet().bindingFunction().accept(10);
}
@@ -221,11 +235,16 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
}
@Override
public String taaFunction(AbstractSectionRenderer<?, ?> renderer, String functionName) {
public String taaFunction(String functionName) {
return this.taaFunction(UNIFORM_BINDING_POINT, functionName);
}
@Override
public String taaFunction(int uboBindingPoint, String functionName) {
var builder = new StringBuilder();
if (this.data.getUniforms() != null) {
builder.append("layout(binding = "+UNIFORM_BINDING_POINT+", std140) uniform ShaderUniformBindings ")
builder.append("layout(binding = "+uboBindingPoint+", std140) uniform ShaderUniformBindings ")
.append(this.data.getUniforms().layout())
.append(";\n\n");
}

View File

@@ -7,6 +7,7 @@ import me.cortex.voxy.client.core.util.IrisUtil;
import me.cortex.voxy.client.iris.IGetIrisVoxyPipelineData;
import me.cortex.voxy.common.Logger;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import java.util.function.BooleanSupplier;
@@ -34,7 +35,13 @@ public class RenderPipelineFactory {
return null;
}
Logger.info("Creating voxy iris render pipeline");
return new IrisVoxyRenderPipeline(pipeData, nodeManager, nodeCleaner, traversal, frexSupplier);
try {
return new IrisVoxyRenderPipeline(pipeData, nodeManager, nodeCleaner, traversal, frexSupplier);
} catch (Exception e) {
Logger.error("Failed to create iris render pipeline", e);
IrisUtil.disableIrisShaders();
return null;
}
}
return null;
}

View File

@@ -139,7 +139,7 @@ public class VoxyRenderSystem {
this.renderDistanceTracker.setRenderDistance(VoxyConfig.CONFIG.sectionRenderDistance);
}
this.chunkBoundRenderer = new ChunkBoundRenderer();
this.chunkBoundRenderer = new ChunkBoundRenderer(this.pipeline);
Logger.info("Voxy render system created with " + geometryCapacity + " geometry capacity, using pipeline '" + this.pipeline.getClass().getSimpleName() + "' with renderer '" + sectionRenderer.getClass().getSimpleName() + "'");
} catch (RuntimeException e) {
@@ -233,6 +233,7 @@ public class VoxyRenderSystem {
//this.autoBalanceSubDivSize();
this.pipeline.preSetup(viewport);
TimingStatistics.E.start();
if (!IrisUtil.irisShadowActive()) {

View File

@@ -2,10 +2,12 @@ package me.cortex.voxy.client.core.rendering;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import me.cortex.voxy.client.core.AbstractRenderPipeline;
import me.cortex.voxy.client.core.gl.GlBuffer;
import me.cortex.voxy.client.core.gl.GlVertexArray;
import me.cortex.voxy.client.core.gl.shader.AutoBindingShader;
import me.cortex.voxy.client.core.gl.shader.Shader;
import me.cortex.voxy.client.core.gl.shader.ShaderLoader;
import me.cortex.voxy.client.core.gl.shader.ShaderType;
import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer;
import me.cortex.voxy.client.core.rendering.util.UploadStream;
@@ -35,18 +37,28 @@ public class ChunkBoundRenderer {
private final GlBuffer uniformBuffer = new GlBuffer(128);
private final Long2IntOpenHashMap chunk2idx = new Long2IntOpenHashMap(INIT_MAX_CHUNK_COUNT);
private long[] idx2chunk = new long[INIT_MAX_CHUNK_COUNT];
private final Shader rasterShader = Shader.makeAuto()
.add(ShaderType.VERTEX, "voxy:chunkoutline/outline.vsh")
.add(ShaderType.FRAGMENT, "voxy:chunkoutline/outline.fsh")
.compile()
.ubo(0, this.uniformBuffer)
.ssbo(1, this.chunkPosBuffer);
private final Shader rasterShader;
private final LongOpenHashSet addQueue = new LongOpenHashSet();
private final LongOpenHashSet remQueue = new LongOpenHashSet();
public ChunkBoundRenderer() {
private final AbstractRenderPipeline pipeline;
public ChunkBoundRenderer(AbstractRenderPipeline pipeline) {
this.chunk2idx.defaultReturnValue(-1);
this.pipeline = pipeline;
String vert = ShaderLoader.parse("voxy:chunkoutline/outline.vsh");
String taa = pipeline.taaFunction("getTAA");
if (taa != null) {
vert = vert+"\n\n\n"+taa;
}
this.rasterShader = Shader.makeAuto()
.addSource(ShaderType.VERTEX, vert)
.defineIf("TAA", taa != null)
.add(ShaderType.FRAGMENT, "voxy:chunkoutline/outline.fsh")
.compile()
.ubo(0, this.uniformBuffer)
.ssbo(1, this.chunkPosBuffer);
}
public void addSection(long pos) {
@@ -115,6 +127,7 @@ public class ChunkBoundRenderer {
viewport.depthBoundingBuffer.bind();
this.rasterShader.bind();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BB_BYTE.id());
this.pipeline.bindUniforms();
//Batch the draws into groups of size 32
int count = this.chunk2idx.size();

View File

@@ -95,7 +95,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
//The pipeline can be used to transform the renderer in abstract ways
String vertex = ShaderLoader.parse("voxy:lod/gl46/quads2.vert");
String taa = pipeline.taaFunction(this, "taaShift");
String taa = pipeline.taaFunction("taaShift");
if (taa != null) {
vertex += "\n"+taa;//inject it at the end
}

View File

@@ -107,12 +107,14 @@ public class BasicAsyncGeometryManager implements IGeometryManager {
private SectionMeta createMeta(BuiltSection section) {
if ((section.geometryBuffer.size%GEOMETRY_ELEMENT_SIZE)!=0) throw new IllegalStateException();
int size = (int) (section.geometryBuffer.size/GEOMETRY_ELEMENT_SIZE);
//clamp size upwards
int upsized = (size+1023)&~1023;
//Address
int addr = (int)this.allocationHeap.alloc(size);
int addr = (int)this.allocationHeap.alloc(upsized);
if (addr == -1) {
throw new IllegalStateException("Geometry OOM");
throw new IllegalStateException("Geometry OOM. requested allocation size (in elements): " + size + ", Heap size at top remaining: " + (this.allocationHeap.getLimit()-this.allocationHeap.getSize()) + ", used elements: " + this.usedCapacity);
}
this.usedCapacity += size;
this.usedCapacity += upsized;
//Create upload
if (this.heapUploads.put(addr, section.geometryBuffer) != null) {
throw new IllegalStateException("Addr: " + addr);

View File

@@ -6,6 +6,7 @@ import net.caffeinemc.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import net.caffeinemc.mods.sodium.client.util.FogParameters;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.shadows.ShadowRenderer;
@@ -19,7 +20,7 @@ public class IrisUtil {
public static CapturedViewportParameters CAPTURED_VIEWPORT_PARAMETERS;
public static final boolean IRIS_INSTALLED = FabricLoader.getInstance().isModLoaded("iris");
public static final boolean SHADER_SUPPORT = System.getProperty("voxy.enableExperimentalIrisPipeline", "false").equalsIgnoreCase("true");
public static final boolean SHADER_SUPPORT = true;//System.getProperty("voxy.enableExperimentalIrisPipeline", "false").equalsIgnoreCase("true");
private static boolean irisShadowActive0() {
@@ -47,4 +48,10 @@ public class IrisUtil {
public static boolean irisShaderPackEnabled() {
return IRIS_INSTALLED && irisShaderPackEnabled0();
}
public static void disableIrisShaders() {
if(IRIS_INSTALLED) disableIrisShaders0();
}
private static void disableIrisShaders0() {
IrisApi.getInstance().getConfig().setShadersEnabledAndApply(false);//Disable shaders
}
}

View File

@@ -7,7 +7,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import me.cortex.voxy.client.core.util.IrisUtil;
import me.cortex.voxy.common.Logger;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.shaderpack.ShaderPack;
import net.irisshaders.iris.shaderpack.include.AbsolutePackPath;
@@ -314,13 +316,14 @@ public class IrisShaderPatch {
} catch (Exception e) {
patchData = null;
Logger.error("Failed to parse patch data gson",e);
throw new ShaderLoadError("Failed to parse patch data gson",e);
}
if (patchData == null) {
return null;
}
if (patchData.version != VERSION) {
Logger.error("Shader has voxy patch data, but patch version is incorrect. expected " + VERSION + " got "+patchData.version);
return null;
throw new IllegalStateException("Shader version mismatch expected " + VERSION + " got "+patchData.version);
}
return new IrisShaderPatch(patchData, ipack);
}

View File

@@ -0,0 +1,11 @@
package me.cortex.voxy.client.iris;
public class ShaderLoadError extends RuntimeException {
public ShaderLoadError(String reason) {
super(reason);
}
public ShaderLoadError(String reason, Exception cause) {
super(reason, cause);
}
}

View File

@@ -0,0 +1,25 @@
package me.cortex.voxy.client.mixin.iris;
import me.cortex.voxy.client.iris.ShaderLoadError;
import me.cortex.voxy.common.Logger;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shaderpack.ShaderPack;
import net.irisshaders.iris.shaderpack.materialmap.NamespacedId;
import net.irisshaders.iris.shaderpack.programs.ProgramSet;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(value = Iris.class, remap = false)
public class MixinIris {
@Redirect(method = "createPipeline", at = @At(value = "INVOKE", target = "Lnet/irisshaders/iris/shaderpack/ShaderPack;getProgramSet(Lnet/irisshaders/iris/shaderpack/materialmap/NamespacedId;)Lnet/irisshaders/iris/shaderpack/programs/ProgramSet;"))
private static ProgramSet voxy$redirectProgramSet(ShaderPack shaderPack, NamespacedId dim) {
try {
return shaderPack.getProgramSet(dim);
} catch (ShaderLoadError e) {
Logger.error(e);
return null;
}
}
}

View File

@@ -4,6 +4,7 @@ import me.cortex.voxy.client.VoxyClientInstance;
import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.client.core.IGetVoxyRenderSystem;
import me.cortex.voxy.client.core.VoxyRenderSystem;
import me.cortex.voxy.client.core.util.IrisUtil;
import me.cortex.voxy.common.Logger;
import me.cortex.voxy.common.world.WorldEngine;
import me.cortex.voxy.commonImpl.VoxyCommon;
@@ -79,6 +80,14 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
Logger.error("Null world selected");
return;
}
this.renderer = new VoxyRenderSystem(world, instance.getThreadPool());
try {
this.renderer = new VoxyRenderSystem(world, instance.getThreadPool());
} catch (RuntimeException e) {
if (IrisUtil.irisShaderPackEnabled()) {
IrisUtil.disableIrisShaders();
} else {
throw e;
}
}
}
}

View File

@@ -15,8 +15,8 @@ public class AllocationArena {
private static final int SIZE_BITS = 64 - ADDR_BITS;
private static final long SIZE_MSK = (1L<<SIZE_BITS)-1;
private static final long ADDR_MSK = (1L<<ADDR_BITS)-1;
private final LongRBTreeSet FREE = new LongRBTreeSet();//Size Address
private final LongRBTreeSet TAKEN = new LongRBTreeSet();//Address Size
private final LongRBTreeSet FREE = new LongRBTreeSet(Long::compareUnsigned);//Size Address
private final LongRBTreeSet TAKEN = new LongRBTreeSet(Long::compareUnsigned);//Address Size
private long sizeLimit = Long.MAX_VALUE;
private long totalSize;
@@ -41,6 +41,19 @@ public class AllocationArena {
public long getSize() {
return this.totalSize;
}
public int numFreeBlocks() {
return this.FREE.size();
}
public int getLargestFreeBlockSize(int index) {
var iter = this.FREE.tailSet(-1).iterator();
for (;index>0&&iter.hasPrevious();index--){iter.previousLong();}
long slot = iter.previousLong();
return (int) (slot>>ADDR_BITS);
}
/*
public long allocFromLargest(int size) {//Allocates from the largest avalible block, this is useful for expanding later on
@@ -190,4 +203,8 @@ public class AllocationArena {
throw new IllegalStateException("Size set smaller than current size");
}
}
public long getLimit() {
return this.sizeLimit;
}
}

View File

@@ -21,6 +21,10 @@ bool shouldRender(ivec3 icorner) {
return (corner.x*corner.x + corner.z*corner.z < negInnerSec.w*negInnerSec.w) && abs(corner.y) < negInnerSec.w;
}
#ifdef TAA
vec2 getTAA();
#endif
void main() {
uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3);
@@ -38,4 +42,8 @@ void main() {
//cubeCornerI.y = cubeCornerI.y*1024-512;
gl_Position = MVP * vec4(vec3(cubeCornerI+origin)*16, 1);
gl_Position.z -= 0.0005f;
#ifdef TAA
gl_Position.xy += getTAA()*gl_Position.w;//Apply TAA if we have it
#endif
}

View File

@@ -1,8 +1,9 @@
#version 460 core
#extension GL_ARB_gpu_shader_int64 : enable
#define VISIBILITY_ACCESS
#define VISIBILITY_BUFFER_BINDING 2
#import <voxy:lod/gl46/bindings.glsl>
layout(binding = VISIBILITY_BUFFER_BINDING, std430) restrict buffer VisibilityBuffer {
uint visibilityData[];
};
layout(early_fragment_tests) in;
flat in uint id;
@@ -11,5 +12,5 @@ flat in uint value;
void main() {
visibilityData[id] = value;
//colour = vec4(float(id&7u)/7, float((id>>3)&7u)/7, float((id>>6)&7u)/7, 1);
//colour = vec4(float(id&7u)/7, float((id>>3)&7u)/7, float((id>>6)&7u)/7, 0);
}

View File

@@ -105,6 +105,7 @@ vec4 computeColour(vec2 texturePos, vec4 colour) {
void main() {
//vec2 uv = vec2(0);
//Tile is the tile we are in
vec2 tile;
vec2 uv2 = modf(uv, tile)*(1.0/(vec2(3.0,2.0)*256.0));

View File

@@ -9,6 +9,7 @@
"iris.MixinPackRenderTargetDirectives",
"iris.CustomUniformsAccessor",
"iris.IrisRenderingPipelineAccessor",
"iris.MixinIris",
"iris.MixinIrisRenderingPipeline",
"iris.MixinIrisSamplers",
"iris.MixinMatrixUniforms",