Skip to content

Commit

Permalink
Minor shader loading improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 2, 2024
1 parent 2ac2141 commit 8606dde
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 40 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/net/irisshaders/iris/helpers/Tri.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ public boolean equals(Object obj) {
return tri.first == this.first && tri.second == this.second && tri.third == this.third;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((first == null) ? 0 : first.hashCode());
result = prime * result + ((second == null) ? 0 : second.hashCode());
result = prime * result + ((third == null) ? 0 : third.hashCode());
return result;
}

@Override
public String toString() {
return "First: " + first.toString() + " Second: " + second.toString() + " Third: " + third.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Mixin(value = Window.class, priority = 1010)
public class MixinWindow {
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwCreateWindow(IILjava/lang/CharSequence;JJ)J"))
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwDefaultWindowHints()V", shift = At.Shift.AFTER))
private void iris$enableDebugContext(WindowEventHandler arg, ScreenManager arg2, DisplayData arg3, String string, String string2, CallbackInfo ci) {
if (Iris.getIrisConfig().areDebugOptionsEnabled()) {
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_DEBUG_CONTEXT, GLFW.GLFW_TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public MixinHumanoidArmorLayer(RenderLayerParent<T, M> pRenderLayer0) {
super(pRenderLayer0);
}

@Group(name = "armorPieceForge", min = 1, max = 1)
@Inject(method = "renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;copyPropertiesTo(Lnet/minecraft/client/model/HumanoidModel;)V"))
@Inject(method = "Lnet/minecraft/client/renderer/entity/layers/HumanoidArmorLayer;renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;)V", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;copyPropertiesTo(Lnet/minecraft/client/model/HumanoidModel;)V"))
private void changeId(PoseStack pHumanoidArmorLayer0, MultiBufferSource pMultiBufferSource1, T pLivingEntity2, EquipmentSlot pEquipmentSlot3, int pInt4, A pHumanoidModel5, CallbackInfo ci, @Local ArmorItem lvArmorItem8) {
if (WorldRenderingSettings.INSTANCE.getItemIds() == null) return;

Expand All @@ -43,16 +42,6 @@ private void changeId(PoseStack pHumanoidArmorLayer0, MultiBufferSource pMultiBu
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(WorldRenderingSettings.INSTANCE.getItemIds().applyAsInt(new NamespacedId(location.getNamespace(), location.getPath())));
}

@Group(name = "armorPieceForge", min = 1, max = 1)
@Inject(method = "Lnet/minecraft/client/renderer/entity/layers/HumanoidArmorLayer;renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;copyPropertiesTo(Lnet/minecraft/client/model/HumanoidModel;)V"))
private void changeIdF(PoseStack pHumanoidArmorLayer0, MultiBufferSource pMultiBufferSource1, T pLivingEntity2, EquipmentSlot pEquipmentSlot3, int pInt4, A pHumanoidModel5, float limbSwing, float limbSwingAmount, float partialTick, float ageInTicks, float netHeadYaw, float headPitch, CallbackInfo ci, @Local ArmorItem lvArmorItem8) {
if (WorldRenderingSettings.INSTANCE.getItemIds() == null) return;

ResourceLocation location = BuiltInRegistries.ITEM.getKey(lvArmorItem8);

CapturedRenderingState.INSTANCE.setCurrentRenderedItem(WorldRenderingSettings.INSTANCE.getItemIds().applyAsInt(new NamespacedId(location.getNamespace(), location.getPath())));
}

@Inject(method = "renderTrim(Lnet/minecraft/core/Holder;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/item/armortrim/ArmorTrim;Lnet/minecraft/client/model/HumanoidModel;Z)V", at = @At(value = "HEAD"))
private void changeTrimTemp(Holder<ArmorMaterial> holder, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, ArmorTrim armorTrim, A humanoidModel, boolean bl, CallbackInfo ci) {
if (WorldRenderingSettings.INSTANCE.getItemIds() == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.irisshaders.iris.gl.texture.TextureType;
import net.irisshaders.iris.helpers.Tri;
import net.irisshaders.iris.pipeline.transform.parameter.ComputeParameters;
import net.irisshaders.iris.pipeline.transform.parameter.DHParameters;
import net.irisshaders.iris.pipeline.transform.parameter.Parameters;
import net.irisshaders.iris.pipeline.transform.parameter.SodiumParameters;
import net.irisshaders.iris.pipeline.transform.parameter.TextureStageParameters;
Expand Down Expand Up @@ -83,7 +84,7 @@ public boolean isTokenAllowed(Token token) {
private static final boolean useCache = true;
private static final Map<CacheKey, Map<PatchShaderType, String>> cache = new LRUCache<>(400);
private static final List<String> internalPrefixes = List.of("iris_", "irisMain", "moj_import");
private static final Pattern versionPattern = Pattern.compile("^.*#version\\s+(\\d+)", Pattern.DOTALL);
private static final Pattern versionPattern = Pattern.compile("#version\\s+(\\d+)", Pattern.DOTALL);
private static final EnumASTTransformer<Parameters, PatchShaderType> transformer;
static Logger LOGGER = LogManager.getLogger(TransformPatcher.class);

Expand Down Expand Up @@ -305,25 +306,16 @@ public static Map<PatchShaderType, String> patchDHTerrain(
String name, String vertex, String tessControl, String tessEval, String geometry, String fragment,
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
return transform(name, vertex, geometry, tessControl, tessEval, fragment,
new Parameters(Patch.DH_TERRAIN, textureMap) {
@Override
public TextureStage getTextureStage() {
return TextureStage.GBUFFERS_AND_SHADOW;
}
});
new DHParameters(Patch.DH_TERRAIN, textureMap));
}


public static Map<PatchShaderType, String> patchDHGeneric(
String name, String vertex, String tessControl, String tessEval, String geometry, String fragment,
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
return transform(name, vertex, geometry, tessControl, tessEval, fragment,
new Parameters(Patch.DH_GENERIC, textureMap) {
@Override
public TextureStage getTextureStage() {
return TextureStage.GBUFFERS_AND_SHADOW;
}
});
new DHParameters(Patch.DH_GENERIC, textureMap));

}

public static Map<PatchShaderType, String> patchSodium(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.irisshaders.iris.pipeline.transform.parameter;

import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.irisshaders.iris.gl.texture.TextureType;
import net.irisshaders.iris.helpers.Tri;
import net.irisshaders.iris.pipeline.transform.Patch;
import net.irisshaders.iris.shaderpack.texture.TextureStage;

public class DHParameters extends Parameters {
public DHParameters(Patch patch, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
super(patch, textureMap);
}

@Override
public TextureStage getTextureStage() {
return TextureStage.GBUFFERS_AND_SHADOW;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((patch == null) ? 0 : patch.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((textureMap == null) ? 0 : textureMap.hashCode());
return result;
}
Expand All @@ -54,8 +53,6 @@ public boolean equals(Object obj) {
Parameters other = (Parameters) obj;
if (patch != other.patch)
return false;
if (type != other.type)
return false;
if (textureMap == null) {
return other.textureMap == null;
} else return textureMap.equals(other.textureMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Function;

public class ProgramSet implements ProgramSetInterface {
Expand Down Expand Up @@ -56,18 +60,28 @@ public ProgramSet(AbsolutePackPath directory, Function<AbsolutePackPath, String>
this.shadowCompute = readComputeArray(directory, sourceProvider, "shadow", shaderProperties);
this.setup = readProgramArray(directory, sourceProvider, "setup", shaderProperties);

for (ProgramArrayId id : ProgramArrayId.values()) {
ProgramSource[] sources = readProgramArray(directory, sourceProvider, id.getSourcePrefix(), shaderProperties, readTesselation);
compositePrograms.put(id, sources);
ComputeSource[][] computes = new ComputeSource[id.getNumPrograms()][];
for (int i = 0; i < id.getNumPrograms(); i++) {
computes[i] = readComputeArray(directory, sourceProvider, id.getSourcePrefix() + (i == 0 ? "" : i), shaderProperties);
try (ExecutorService service = Executors.newFixedThreadPool(10)) {
for (ProgramArrayId id : ProgramArrayId.values()) {
ProgramSource[] sources = readProgramArray(directory, sourceProvider, id.getSourcePrefix(), shaderProperties, readTesselation);
compositePrograms.put(id, sources);
ComputeSource[][] computes = new ComputeSource[id.getNumPrograms()][];
for (int i = 0; i < id.getNumPrograms(); i++) {
computes[i] = readComputeArray(directory, sourceProvider, id.getSourcePrefix() + (i == 0 ? "" : i), shaderProperties);
}
computePrograms.put(id, computes);
}
computePrograms.put(id, computes);
}

for (ProgramId programId : ProgramId.values()) {
gbufferPrograms.put(programId, readProgramSource(directory, sourceProvider, programId.getSourceName(), this, shaderProperties, programId.getBlendModeOverride(), readTesselation));
Future[] sources = new Future[ProgramId.values().length];

for (ProgramId programId : ProgramId.values()) {
sources[programId.ordinal()] = service.submit(() -> readProgramSource(directory, sourceProvider, programId.getSourceName(), this, shaderProperties, programId.getBlendModeOverride(), readTesselation));
}

for (ProgramId id : ProgramId.values()) {
gbufferPrograms.put(id, (ProgramSource) sources[id.ordinal()].get());
}
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}

this.finalCompute = readComputeArray(directory, sourceProvider, "final", shaderProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package net.irisshaders.iris.mixin.forge;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.vertex.PoseStack;
import net.irisshaders.iris.helpers.EntityState;
import net.irisshaders.iris.shaderpack.materialmap.NamespacedId;
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.armortrim.ArmorTrim;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -24,6 +32,15 @@ private void changeTrimTempForge(Holder<ArmorMaterial> holder, PoseStack poseSta
EntityState.interposeItemId(WorldRenderingSettings.INSTANCE.getItemIds().applyAsInt(new NamespacedId("minecraft", "trim_" + armorTrim.material().value().assetName())));
}

@Inject(method = "Lnet/minecraft/client/renderer/entity/layers/HumanoidArmorLayer;renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;copyPropertiesTo(Lnet/minecraft/client/model/HumanoidModel;)V"), require = 0)
private void changeIdF(PoseStack poseStack, MultiBufferSource bufferSource, LivingEntity livingEntity, EquipmentSlot slot, int packedLight, HumanoidModel p_model, float limbSwing, float limbSwingAmount, float partialTick, float ageInTicks, float netHeadYaw, float headPitch, CallbackInfo ci, @Local ArmorItem lvArmorItem8) {
if (WorldRenderingSettings.INSTANCE.getItemIds() == null) return;

ResourceLocation location = BuiltInRegistries.ITEM.getKey(lvArmorItem8);

CapturedRenderingState.INSTANCE.setCurrentRenderedItem(WorldRenderingSettings.INSTANCE.getItemIds().applyAsInt(new NamespacedId(location.getNamespace(), location.getPath())));
}

@Inject(method = "renderTrim(Lnet/minecraft/core/Holder;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/item/armortrim/ArmorTrim;Lnet/minecraft/client/model/Model;Z)V", at = @At(value = "TAIL"))
private void changeTrimTemp2Forge(Holder<ArmorMaterial> holder, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, ArmorTrim armorTrim, Model humanoidModel, boolean bl, CallbackInfo ci) {
EntityState.restoreItemId();
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pluginManagement {
}
}

include("common", "fabric")
include("common", "fabric", "neoforge")

0 comments on commit 8606dde

Please sign in to comment.