Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.20.3' into 1.20.5
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/resources/fabric.mod.json
  • Loading branch information
IMS212 committed May 9, 2024
2 parents 0291687 + c3c199e commit cd449b3
Show file tree
Hide file tree
Showing 27 changed files with 700 additions and 56 deletions.
7 changes: 1 addition & 6 deletions LICENSE-DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
Incompatible licenses:

glsl-transformer is licensed under the glsl-transformer Noncommercial License 1.0.0. Details on this can be found in https://github.com/IrisShaders/glsl-transformer/blob/main/LICENSE.
The license text is short and easy to understand, but the gist is that you may distribute unmodified editions of this library and them in new works, under the condition that you qualify as a noncommercial entity. If you need to modify it, you may only do so in private or by contributing the changes back to the IrisShaders/glsl-transformer repository under the Contributor License Agreement. Using and distributing this library as part of a noncommercial, meaning access to it is not conditioned on payment or other compensation, Minecraft mod or related software falls under the allowed purposes. You are required to obtain a commercial license for using this library for any purpose other than a noncommercial one.

This license is not applicable if linking with a program (Iris) containing glsl-transformer, unless the linker interacts with the library's API directly.

tl;dr: If you intend to just depend on Iris and need to depend on the transformer due to that, you're fine. If you intend to use the transformer in any way, you must follow the license as followed above.
glsl-transformer is licensed under the GNU Affero General Public License version 3. This may affect your ability to distribute Iris.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ So, if you want to distribute a Forge port of Iris, we'd prefer if you let us kn

All code in this (Iris) repository is completely free and open source, and you are free to read, distribute, and modify the code as long as you abide by the (fairly reasonable) terms of the [GNU LGPLv3 license](https://github.com/IrisShaders/Iris/blob/master/LICENSE).

Dependencies may not be under an applicable license: See the [Incompatible Dependencies](https://github.com/IrisShaders/Iris/blob/master/LICENSE-DEPENDENCIES) page for more information.

You are not allowed to redistribute Iris commerically or behind a paywall, unless you get a commercial license for GLSL Transformer. See above for more information.
glsl-transformer is licensed under the GNU Affero General Public License version 3. This may affect your ability to distribute Iris.

Though it's not legally required, I'd appreciate it if you could ask before hosting your own public downloads for compiled versions of Iris. Though if you want to add the mod to a site like MCBBS, that's fine, no need to ask me.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ dependencies {
mappings(loom.officialMojangMappings())
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = Constants.FABRIC_LOADER_VERSION)

include("org.antlr:antlr4-runtime:4.11.1")
modImplementation("org.antlr:antlr4-runtime:4.11.1")
include("io.github.douira:glsl-transformer:2.0.0-pre13")
modImplementation("io.github.douira:glsl-transformer:2.0.0-pre13")
include("org.antlr:antlr4-runtime:4.13.1")
modImplementation("org.antlr:antlr4-runtime:4.13.1")
include("io.github.douira:glsl-transformer:2.0.1")
modImplementation("io.github.douira:glsl-transformer:2.0.1")
include("org.anarres:jcpp:1.4.14")
modImplementation("org.anarres:jcpp:1.4.14")

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.irisshaders.iris.compat.dh.DHCompat;
import net.irisshaders.iris.config.IrisConfig;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.buffer.ShaderStorageBufferHolder;
import net.irisshaders.iris.gl.shader.ShaderCompileException;
import net.irisshaders.iris.gl.shader.StandardMacros;
import net.irisshaders.iris.gui.debug.DebugLoadFailedGridScreen;
Expand Down Expand Up @@ -588,6 +589,8 @@ private static WorldRenderingPipeline createPipeline(NamespacedId dimensionId) {
storedError = Optional.of(e);
}
}

ShaderStorageBufferHolder.forceDeleteBuffers();
logger.error("Failed to create shader rendering pipeline, disabling shaders!", e);
// TODO: This should be reverted if a dimension change causes shaders to compile again
fallback = true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/irisshaders/iris/compat/dh/DHCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void run() {
if (e instanceof ExceptionInInitializerError eiie) {
throw new RuntimeException("Failure loading DH compat.", eiie.getCause());
} else {
throw new RuntimeException("DH 2.0 not found, yet Fabric claims it's there. Curious.", e);
throw new RuntimeException("DH found, but one or more API methods are missing. Iris requires DH [2.0.4] or DH API version [1.1.0] or newer. Please make sure you are on the latest version of DH and Iris.", e);
}
} else {
Iris.logger.info("DH not found, and classes not found.");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/irisshaders/iris/gl/GLDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ public static void nameObject(int id, int object, String name) {
}

public static void pushGroup(int id, String name) {
debugState.pushGroup(id, name);
//debugState.pushGroup(id, name);
}

public static void popGroup() {
debugState.popGroup();
//debugState.popGroup();
}

private interface DebugState {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/irisshaders/iris/gl/IrisLimits.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class IrisLimits {
* is implemented.
*/
public static final int MAX_COLOR_BUFFERS = 16;
public static final boolean VK_CONFORMANCE = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public void resizeIfRelative(int width, int height) {
GlStateManager._glBindBuffer(GL43C.GL_SHADER_STORAGE_BUFFER, newId);

// Calculation time
int newWidth = (int) (width * info.scaleX());
int newHeight = (int) (height * info.scaleY());
int finalSize = (newHeight * newWidth) * info.size();
long newWidth = (long) (width * info.scaleX());
long newHeight = (long) (height * info.scaleY());
long finalSize = (newHeight * newWidth) * info.size();
IrisRenderSystem.bufferStorage(GL43C.GL_SHADER_STORAGE_BUFFER, finalSize, 0);
IrisRenderSystem.clearBufferSubData(GL43C.GL_SHADER_STORAGE_BUFFER, GL43C.GL_R8, 0, finalSize, GL43C.GL_RED, GL43C.GL_BYTE, new int[]{0});
IrisRenderSystem.bindBufferBase(GL43C.GL_SHADER_STORAGE_BUFFER, index, newId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

import com.mojang.blaze3d.platform.GlStateManager;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.sampler.SamplerLimits;
import org.lwjgl.opengl.GL43C;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class ShaderStorageBufferHolder {
private int cachedWidth;
private int cachedHeight;
private ShaderStorageBuffer[] buffers;
private boolean destroyed;

private static List<ShaderStorageBuffer> ACTIVE_BUFFERS = new ArrayList<>();


public ShaderStorageBufferHolder(Int2ObjectArrayMap<ShaderStorageInfo> overrides, int width, int height) {
destroyed = false;
cachedWidth = width;
Expand All @@ -29,6 +36,7 @@ public ShaderStorageBufferHolder(Int2ObjectArrayMap<ShaderStorageInfo> overrides
}

buffers[index] = new ShaderStorageBuffer(index, bufferInfo);
ACTIVE_BUFFERS.add(buffers[index]);
int buffer = buffers[index].getId();

if (bufferInfo.relative()) {
Expand Down Expand Up @@ -59,6 +67,14 @@ public void hasResizedScreen(int width, int height) {
}
}

public static void forceDeleteBuffers() {
if (!ACTIVE_BUFFERS.isEmpty()) {
Iris.logger.warn("Found " + ACTIVE_BUFFERS.size() + " stored buffers with a total size of " + ACTIVE_BUFFERS.stream().map(ShaderStorageBuffer::getSize).reduce(0L, Long::sum) + ", forcing them to be deleted.");
ACTIVE_BUFFERS.forEach(ShaderStorageBuffer::destroy);
ACTIVE_BUFFERS.clear();
}
}

public void setupBuffers() {
if (destroyed) {
throw new IllegalStateException("Tried to use destroyed buffer objects");
Expand All @@ -81,6 +97,7 @@ public int getBufferIndex(int index) {
public void destroyBuffers() {
for (ShaderStorageBuffer buffer : buffers) {
if (buffer != null) {
ACTIVE_BUFFERS.remove(buffer);
buffer.destroy();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.irisshaders.iris.gl.buffer;

public record ShaderStorageInfo(int size, boolean relative, float scaleX, float scaleY) {
public record ShaderStorageInfo(long size, boolean relative, float scaleX, float scaleY) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
define(standardDefines, getVendor());
define(standardDefines, getRenderer());
define(standardDefines, "IS_IRIS");
define(standardDefines, "IRIS_TAG_SUPPORT");


if (FabricLoader.getInstance().isModLoaded("distanthorizons") && DHCompat.hasRenderingEnabled()) {
define(standardDefines, "DISTANT_HORIZONS");
}

if (FabricLoader.getInstance().isModLoaded("continuity")) {
define(standardDefines, "IRIS_HAS_CONNECTED_TEXTURES");
}

define(standardDefines, "DH_BLOCK_UNKNOWN", String.valueOf(0));
define(standardDefines, "DH_BLOCK_LEAVES", String.valueOf(1));
define(standardDefines, "DH_BLOCK_STONE", String.valueOf(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public interface GameRendererAccessor {

@Invoker
double invokeGetFov(Camera camera, float tickDelta, boolean b);

@Invoker("shouldRenderBlockOutline")
boolean shouldRenderBlockOutlineA();
}
2 changes: 1 addition & 1 deletion src/main/java/net/irisshaders/iris/mixin/MixinProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MixinProgram {
return includeHandler.process(shaderSource);
}

@Inject(method = "compileShaderInternal", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;glGetShaderInfoLog(II)Ljava/lang/String;"), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "compileShaderInternal", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;glGetShaderInfoLog(II)Ljava/lang/String;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private static void iris$causeException(Program.Type arg, String string, InputStream inputStream, String string2, GlslPreprocessor arg2, CallbackInfoReturnable<Integer> cir, String string3, int i) {
cir.cancel();
throw new ShaderCompileException(string + arg.getExtension(), GlStateManager.glGetShaderInfoLog(i, 32768));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.irisshaders.iris.mixin.entity_render_context;

import com.mojang.blaze3d.vertex.PoseStack;
import net.irisshaders.iris.shaderpack.materialmap.NamespacedId;
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EnderDragonRenderer;
import net.minecraft.client.renderer.entity.layers.CapeLayer;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(EnderDragonRenderer.class)
public class MixinEnderDragonRenderer {
private static final NamespacedId END_BEAM = new NamespacedId("minecraft", "end_crystal_beam");
private static int previousE;

@Inject(method = "renderCrystalBeams", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V"))
private static void changeId(float f, float g, float h, float i, int j, PoseStack poseStack, MultiBufferSource multiBufferSource, int k, CallbackInfo ci) {
if (WorldRenderingSettings.INSTANCE.getEntityIds() == null) return;

previousE = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
CapturedRenderingState.INSTANCE.setCurrentEntity(WorldRenderingSettings.INSTANCE.getEntityIds().applyAsInt(END_BEAM));
}

@Inject(method = "renderCrystalBeams", at = @At(value = "RETURN"))
private static void changeId2(CallbackInfo ci) {
if (previousE != 0) {
CapturedRenderingState.INSTANCE.setCurrentEntity(previousE);
previousE = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class IrisRenderingPipeline implements WorldRenderingPipeline, ShaderRend
private final PackShadowDirectives shadowDirectives;
private final DHCompat dhCompat;
private final int stackSize = 0;
private boolean initializedBlockIds;
public boolean isBeforeTranslucent;
private ShaderStorageBufferHolder shaderStorageBufferHolder;
private ShadowRenderTargets shadowRenderTargets;
Expand Down Expand Up @@ -285,6 +286,10 @@ public IrisRenderingPipeline(ProgramSet programSet) {
return shadowRenderTargets;
};

if (shadowDirectives.isShadowEnabled() == OptionalBoolean.TRUE) {
shadowTargetsSupplier.get();
}

this.shadowComputes = createShadowComputes(programSet.getShadowCompute(), programSet);

this.beginRenderer = new CompositeRenderer(this, programSet.getPackDirectives(), programSet.getBegin(), programSet.getBeginCompute(), renderTargets, shaderStorageBufferHolder,
Expand Down Expand Up @@ -433,9 +438,7 @@ public IrisRenderingPipeline(ProgramSet programSet) {
}
});

WorldRenderingSettings.INSTANCE.setBlockStateIds(
BlockMaterialMapping.createBlockStateIdMap(programSet.getPack().getIdMap().getBlockProperties()));
WorldRenderingSettings.INSTANCE.setBlockTypeIds(BlockMaterialMapping.createBlockTypeMap(programSet.getPack().getIdMap().getBlockRenderTypeMap()));
initializedBlockIds = false;

WorldRenderingSettings.INSTANCE.setEntityIds(programSet.getPack().getIdMap().getEntityIdMap());
WorldRenderingSettings.INSTANCE.setItemIds(programSet.getPack().getIdMap().getItemIdMap());
Expand All @@ -446,10 +449,6 @@ public IrisRenderingPipeline(ProgramSet programSet) {
WorldRenderingSettings.INSTANCE.setSeparateEntityDraws(programSet.getPackDirectives().shouldUseSeparateEntityDraws());
WorldRenderingSettings.INSTANCE.setUseExtendedVertexFormat(true);

if (shadowRenderTargets == null && shadowDirectives.isShadowEnabled() == OptionalBoolean.TRUE) {
shadowRenderTargets = new ShadowRenderTargets(this, shadowMapResolution, shadowDirectives);
}

if (shadowRenderTargets != null) {
ShaderInstance shader = shaderMap.getShader(ShaderKey.SHADOW_TERRAIN_CUTOUT);
boolean shadowUsesImages = false;
Expand Down Expand Up @@ -846,6 +845,14 @@ public void onSetShaderTexture(int id) {
public void beginLevelRendering() {
isRenderingWorld = true;

if (!initializedBlockIds) {
WorldRenderingSettings.INSTANCE.setBlockStateIds(
BlockMaterialMapping.createBlockStateIdMap(pack.getIdMap().getBlockProperties()));
WorldRenderingSettings.INSTANCE.setBlockTypeIds(BlockMaterialMapping.createBlockTypeMap(pack.getIdMap().getBlockRenderTypeMap()));
Minecraft.getInstance().levelRenderer.allChanged();
initializedBlockIds = true;
}

// Make sure we're using texture unit 0 for this.
RenderSystem.activeTexture(GL15C.GL_TEXTURE0);
Vector4f emptyClearColor = new Vector4f(1.0F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.github.douira.glsl_transformer.util.LRUCache;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.IrisLimits;
import net.irisshaders.iris.gl.blending.AlphaTest;
import net.irisshaders.iris.gl.shader.ShaderCompileException;
import net.irisshaders.iris.gl.state.ShaderAttributeInputs;
Expand All @@ -31,6 +32,7 @@
import net.irisshaders.iris.pipeline.transform.transformer.CompositeCoreTransformer;
import net.irisshaders.iris.pipeline.transform.transformer.CompositeTransformer;
import net.irisshaders.iris.pipeline.transform.transformer.DHTransformer;
import net.irisshaders.iris.pipeline.transform.transformer.LayoutTransformer;
import net.irisshaders.iris.pipeline.transform.transformer.SodiumCoreTransformer;
import net.irisshaders.iris.pipeline.transform.transformer.SodiumTransformer;
import net.irisshaders.iris.pipeline.transform.transformer.TextureTransformer;
Expand Down Expand Up @@ -140,8 +142,8 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) {

if (profile == Profile.CORE || version.number >= 150 && profile == null || isLine) {
// patch the version number to at least 330
if (version.number < 330) {
versionStatement.version = Version.GLSL33;
if (version.number < 410) {
versionStatement.version = Version.GLSL41;
}

switch (parameters.patch) {
Expand All @@ -164,8 +166,8 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) {
}
} else {
// patch the version number to at least 330
if (version.number < 330) {
versionStatement.version = Version.GLSL33;
if (version.number < 410) {
versionStatement.version = Version.GLSL41;
}
versionStatement.profile = Profile.CORE;

Expand Down Expand Up @@ -196,6 +198,10 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) {

// the compatibility transformer does a grouped transformation
CompatibilityTransformer.transformGrouped(transformer, trees, parameters);

if (IrisLimits.VK_CONFORMANCE) {
LayoutTransformer.transformGrouped(transformer, trees, parameters);
}
});
transformer.setTokenFilter(parseTokenFilter);
}
Expand Down
Loading

0 comments on commit cd449b3

Please sign in to comment.