Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with Asynchronous Render List Generation in Sodium #2539

Draft
wants to merge 9 commits into
base: 1.21.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions .github/workflows/build-release.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/build.yml

This file was deleted.

5 changes: 4 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ dependencies {

modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-api-v1:3.2.9+1172e897d7")

modImplementation("maven.modrinth", "sodium", "mc1.21.3-0.6.0-fabric")
// modImplementation("maven.modrinth", "sodium", "mc1.21-0.6.0-beta.2-fabric")
modImplementation("net.caffeinemc", "fabric", "0.6.0-snapshot+mc1.21.3-local") {
isChanging = true
}
modCompileOnly("org.antlr:antlr4-runtime:4.13.1")
modCompileOnly("io.github.douira:glsl-transformer:2.0.1")
modCompileOnly("org.anarres:jcpp:1.4.14")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MixinAdvancedShadowCullingFrustum(Matrix4f matrix4f, Matrix4f matrix4f2)
}

@Shadow(remap = false)
protected int isVisible(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
protected boolean isVisibleBool(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
throw new IllegalStateException();
}

Expand All @@ -33,6 +33,6 @@ public void update(int worldMinBlockY, int worldMaxBlockY, DhApiMat4f worldViewP

@Override
public boolean intersects(int lodBlockPosMinX, int lodBlockPosMinZ, int lodBlockWidth, int lodDetailLevel) {
return this.isVisible(lodBlockPosMinX, this.worldMinYDH, lodBlockPosMinZ, lodBlockPosMinX + lodBlockWidth, this.worldMaxYDH, lodBlockPosMinZ + lodBlockWidth) != 0;
return this.isVisibleBool(lodBlockPosMinX, this.worldMinYDH, lodBlockPosMinZ, lodBlockPosMinX + lodBlockWidth, this.worldMaxYDH, lodBlockPosMinZ + lodBlockWidth);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.irisshaders.iris.compat.sodium.mixin;

import net.caffeinemc.mods.sodium.client.render.immediate.CloudRenderer;
import net.minecraft.client.renderer.ShaderProgram;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(CloudRenderer.class)
public interface CloudRendererAccessor {
@Accessor
static ShaderProgram getCLOUDS_SHADER() {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package net.irisshaders.iris.compat.sodium.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.caffeinemc.mods.sodium.api.util.NormI8;
import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter;
import net.caffeinemc.mods.sodium.api.vertex.format.common.ColorVertex;
import net.caffeinemc.mods.sodium.client.render.immediate.CloudRenderer;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.pipeline.ShaderRenderingPipeline;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.pipeline.programs.ShaderKey;
import net.irisshaders.iris.vertices.IrisVertexFormats;
import net.irisshaders.iris.vertices.sodium.CloudVertex;
import org.jetbrains.annotations.Nullable;
Expand All @@ -20,7 +18,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand All @@ -41,10 +38,18 @@ public abstract class MixinCloudRenderer {

@Shadow(remap = false)
@Nullable
private CloudRenderer.@Nullable CloudGeometry cachedGeometry;
private CloudRenderer.@Nullable CloudGeometry builtGeometry;

@Unique
private @Nullable CloudRenderer.CloudGeometry cachedGeometryIris;
private static boolean hadShadersOn = false;

// Bitmasks for each cloud face
private static final int FACE_MASK_NEG_Y = 1 << 0;
private static final int FACE_MASK_POS_Y = 1 << 1;
private static final int FACE_MASK_NEG_X = 1 << 2;
private static final int FACE_MASK_POS_X = 1 << 3;
private static final int FACE_MASK_NEG_Z = 1 << 4;
private static final int FACE_MASK_POS_Z = 1 << 5;

@Inject(method = "writeVertex", at = @At("HEAD"), cancellable = true, remap = false)
private static void writeIrisVertex(long buffer, float x, float y, float z, int color, CallbackInfoReturnable<Long> cir) {
Expand All @@ -54,27 +59,57 @@ private static void writeIrisVertex(long buffer, float x, float y, float z, int
}
}

@Inject(method = "emitCellGeometry2D", at = @At("HEAD"), remap = false)
private static void computeNormal2D(VertexBufferWriter writer, int faces, int color, float x, float z, CallbackInfo ci) {
@Inject(method = "emitCellGeometryFlat", at = @At("HEAD"), remap = false)
private static void computeNormal2D(VertexBufferWriter writer, int texel, int x, int z, CallbackInfo ci) {
computedNormal = NORMALS[0];
}

@Inject(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/util/ColorABGR;mulRGB(II)I", ordinal = 0), remap = false)
private static void computeNormal3D(VertexBufferWriter writer, int cellFaces, int cellColor, int cellX, int cellZ, CallbackInfo ci) {
computedNormal = NORMALS[0];
}

@Inject(method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudFace;ordinal()I"), remap = false)
private static void computeNormal3D(VertexBufferWriter writer, int visibleFaces, int baseColor, float posX, float posZ, boolean interior, CallbackInfo ci, @Local(ordinal = 4) int face) {
computedNormal = NORMALS[face];
@Inject(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/util/ColorABGR;mulRGB(II)I", ordinal = 1), remap = false)
private static void computeNormal3DUp(VertexBufferWriter writer, int cellFaces, int cellColor, int cellX, int cellZ, CallbackInfo ci) {
computedNormal = NORMALS[1];
}

@Inject(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;writeVertex(JFFFI)J", ordinal = 8, remap = false), remap = false)
private static void computeNormal3DNegX(VertexBufferWriter writer, int cellFaces, int cellColor, int cellX, int cellZ, CallbackInfo ci) {
computedNormal = NORMALS[2];
}

@Inject(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;writeVertex(JFFFI)J", ordinal = 12, remap = false))
private static void computeNormal3DPosX(VertexBufferWriter writer, int cellFaces, int cellColor, int cellX, int cellZ, CallbackInfo ci) {
computedNormal = NORMALS[3];
}

@ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
@Inject(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;writeVertex(JFFFI)J", ordinal = 16, remap = false))
private static void computeNormal3DNegZ(VertexBufferWriter writer, int cellFaces, int cellColor, int cellX, int cellZ, CallbackInfo ci) {
computedNormal = NORMALS[4];
}

@Inject(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;writeVertex(JFFFI)J", ordinal = 20, remap = false))
private static void computeNormal3DPosZ(VertexBufferWriter writer, int cellFaces, int cellColor, int cellX, int cellZ, CallbackInfo ci) {
computedNormal = NORMALS[5];
}

@ModifyArg(remap = false, method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
private static int allocateNewSize(int size) {
return IrisApi.getInstance().isShaderPackInUse() ? 480 : size;
}

@ModifyArg(remap = false, method = "emitCellGeometryInterior", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
private static int allocateNewSizeInt(int size) {
return IrisApi.getInstance().isShaderPackInUse() ? 480 : size;
}

@ModifyArg(method = "rebuildGeometry", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/Tesselator;begin(Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;Lcom/mojang/blaze3d/vertex/VertexFormat;)Lcom/mojang/blaze3d/vertex/BufferBuilder;"), index = 1)
private static VertexFormat rebuild(VertexFormat p_350837_) {
return IrisApi.getInstance().isShaderPackInUse() ? IrisVertexFormats.CLOUDS : p_350837_;
}

@ModifyArg(method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
@ModifyArg(method = "emitCellGeometryExterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
private static VertexFormat modifyArgIris(VertexFormat vertexFormatDescription) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return IrisVertexFormats.CLOUDS;
Expand All @@ -83,12 +118,21 @@ private static VertexFormat modifyArgIris(VertexFormat vertexFormatDescription)
}
}

@ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
@ModifyArg(method = "emitCellGeometryInterior", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
private static VertexFormat modifyArgIrisInt(VertexFormat vertexFormatDescription) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return IrisVertexFormats.CLOUDS;
} else {
return ColorVertex.FORMAT;
}
}

@ModifyArg(remap = false, method = "emitCellGeometryFlat", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
private static int allocateNewSize2D(int size) {
return IrisApi.getInstance().isShaderPackInUse() ? 80 : size;
}

@ModifyArg(method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
@ModifyArg(method = "emitCellGeometryFlat", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
private static VertexFormat modifyArgIris2D(VertexFormat vertexFormatDescription) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return IrisVertexFormats.CLOUDS;
Expand All @@ -97,21 +141,15 @@ private static VertexFormat modifyArgIris2D(VertexFormat vertexFormatDescription
}
}

@Redirect(method = "render", at = @At(remap = false, value = "FIELD", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;cachedGeometry:Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudGeometry;", ordinal = 0))
private CloudRenderer.@Nullable CloudGeometry changeGeometry(CloudRenderer instance) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return cachedGeometryIris;
} else {
return cachedGeometry;
}
@WrapOperation(method = "render", at = @At(remap = false, value = "INVOKE", target = "Ljava/util/Objects;equals(Ljava/lang/Object;Ljava/lang/Object;)Z"))
private boolean changeGeometry(Object a, Object b, Operation<Boolean> original) {
return hadShadersOn == Iris.isPackInUseQuick() && original.call(a, b);
}

@Redirect(method = "render", at = @At(remap = false, value = "FIELD", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;cachedGeometry:Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudGeometry;", ordinal = 1))
private void changeGeometry2(CloudRenderer instance, CloudRenderer.CloudGeometry value) {
if (IrisApi.getInstance().isShaderPackInUse()) {
cachedGeometryIris = value;
} else {
cachedGeometry = value;
}
@Inject(method = "rebuildGeometry", at = @At(remap = false, value = "HEAD"))
private static void changeGeometry2(CallbackInfoReturnable<CloudRenderer.CloudGeometry> cir) {
hadShadersOn = IrisApi.getInstance().isShaderPackInUse();
}

// TODO interiors
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.irisshaders.iris.compat.sodium.mixin;

import net.caffeinemc.mods.sodium.client.render.chunk.lists.ChunkRenderList;
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegion;
import net.irisshaders.iris.compat.sodium.mixinterface.ShadowRenderRegion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

@Mixin(RenderRegion.class)
public class MixinRenderRegion implements ShadowRenderRegion {
@Final
@Shadow
@Mutable
private ChunkRenderList renderList;

@Unique
ChunkRenderList regularRenderList;

@Unique
ChunkRenderList shadowRenderList;

@Unique
@Override
public void swapToShadowRenderList() {
this.regularRenderList = this.renderList;
this.renderList = this.shadowRenderList;
this.ensureRenderList();
}

@Unique
@Override
public void swapToRegularRenderList() {
this.shadowRenderList = this.renderList;
this.renderList = this.regularRenderList;
this.ensureRenderList();
}

@Unique
private void ensureRenderList() {
if (this.renderList == null) {
this.renderList = new ChunkRenderList((RenderRegion) (Object) this);
}
}
}
Loading