Common and version specific shader packages #10

Merged
embeddedt merged 24 commits from mitchej123/celeritas:common-shaders-and-enhancements into stonecutter 2025-03-31 19:52:28 -04:00
67 changed files with 112 additions and 36 deletions
Showing only changes of commit ef7eb8faf2 - Show all commits

No files matched your search

+3
View File
@@ -45,6 +45,9 @@ dependencies {
} }
// TODO: Make this depend also on :common
evaluationDependsOn(":common")
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
@@ -76,10 +76,13 @@ public interface GLStateManagerService {
void bindTexture(int texture); // Non-standard signature void bindTexture(int texture); // Non-standard signature
int getActiveTexture(); // Mojang Addition int getActiveTexture(); // Mojang Addition
int getBoundTexture(int internalUnit); // Mojang Addition
int getActiveBoundTexture(); // Mojang Addition
boolean getDepthStateMask(); boolean getDepthStateMask();
boolean isBlendEnabled(); boolean isBlendEnabled();
BlendMode getBlendMode(); BlendMode getBlendMode();
ColorMask getColorMask(); ColorMask getColorMask();
void setBoundTexture(int unit, int texture);
} }
@@ -0,0 +1,19 @@
package com.mitchej123.glsm;
import java.util.ServiceLoader;
public interface MinecraftVersionShimService {
MinecraftVersionShimService MINECRAFT_SHIM = ServiceLoader.load(MinecraftVersionShimService.class).findFirst().orElseThrow();
default boolean getSmartCull() {
return false;
}
default void setSmartCull(boolean smartCull) {
// Do nothing
}
default long getCurrentTiick() {
return 0L;
}
}
@@ -15,6 +15,7 @@ public interface RenderSystemService {
void enableBlend(); void enableBlend();
void disableBlend(); void disableBlend();
void setUnknownBlendState(); // Mojang Addition
void enableDepthTest(); void enableDepthTest();
void disableDepthTest(); void disableDepthTest();
@@ -49,6 +50,8 @@ public interface RenderSystemService {
float getShaderFogEnd(); float getShaderFogEnd();
Matrix4f getProjectionMatrix(); Matrix4f getProjectionMatrix();
void setProjectionMatrixOrth(Matrix4f projectionMatrix);
void setProjectionMatrixOrigin(Matrix4f projectionMatrix);
// TODO: Figure out VertexSorting type // TODO: Figure out VertexSorting type
// void setProjectionMatrix(Matrix4f projectionMatrix, VertexSorting vertexSorting) // void setProjectionMatrix(Matrix4f projectionMatrix, VertexSorting vertexSorting)
@@ -5,13 +5,11 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.MinecraftVersionShimService.MINECRAFT_SHIM;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM; import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.sampler.SamplerLimits; import net.irisshaders.iris.gl.sampler.SamplerLimits;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import net.minecraft.client.Minecraft;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Vector3i; import org.joml.Vector3i;
@@ -35,13 +33,13 @@ public class IrisRenderSystem {
public static void initRenderer() { public static void initRenderer() {
if (GL.getCapabilities().OpenGL45) { if (GL.getCapabilities().OpenGL45) {
dsaState = new DSACore(); dsaState = new DSACore();
Iris.logger.info("OpenGL 4.5 detected, enabling DSA."); IRIS_LOGGER.info("OpenGL 4.5 detected, enabling DSA.");
} else if (GL.getCapabilities().GL_ARB_direct_state_access) { } else if (GL.getCapabilities().GL_ARB_direct_state_access) {
dsaState = new DSAARB(); dsaState = new DSAARB();
Iris.logger.info("ARB_direct_state_access detected, enabling DSA."); IRIS_LOGGER.info("ARB_direct_state_access detected, enabling DSA.");
} else { } else {
dsaState = new DSAUnsupported(); dsaState = new DSAUnsupported();
Iris.logger.info("DSA support not detected."); IRIS_LOGGER.info("DSA support not detected.");
} }
hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind; hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind;
@@ -294,13 +292,13 @@ public class IrisRenderSystem {
public static void disableBufferBlend(int buffer) { public static void disableBufferBlend(int buffer) {
RENDER_SYSTEM.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glDisablei(GL32C.GL_BLEND, buffer); GL32C.glDisablei(GL32C.GL_BLEND, buffer);
((BooleanStateExtended) GlStateManagerAccessor.getBLEND().mode).setUnknownState(); RENDER_SYSTEM.setUnknownBlendState();
} }
public static void enableBufferBlend(int buffer) { public static void enableBufferBlend(int buffer) {
RENDER_SYSTEM.assertOnRenderThreadOrInit(); RENDER_SYSTEM.assertOnRenderThreadOrInit();
GL32C.glEnablei(GL32C.GL_BLEND, buffer); GL32C.glEnablei(GL32C.GL_BLEND, buffer);
((BooleanStateExtended) GlStateManagerAccessor.getBLEND().mode).setUnknownState(); RENDER_SYSTEM.setUnknownBlendState();
} }
public static void blendFuncSeparatei(int buffer, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) { public static void blendFuncSeparatei(int buffer, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
@@ -326,11 +324,11 @@ public class IrisRenderSystem {
public static void setShadowProjection(Matrix4f shadowProjection) { public static void setShadowProjection(Matrix4f shadowProjection) {
backupProjection = RENDER_SYSTEM.getProjectionMatrix(); backupProjection = RENDER_SYSTEM.getProjectionMatrix();
RenderSystem.setProjectionMatrix(shadowProjection/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.ORTHOGRAPHIC_Z/*?}*/); RENDER_SYSTEM.setProjectionMatrixOrth(shadowProjection);
} }
public static void restorePlayerProjection() { public static void restorePlayerProjection() {
RenderSystem.setProjectionMatrix(backupProjection/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.DISTANCE_TO_ORIGIN/*?}*/); RENDER_SYSTEM.setProjectionMatrixOrigin(backupProjection);
backupProjection = null; backupProjection = null;
} }
@@ -448,12 +446,12 @@ public class IrisRenderSystem {
private static boolean cullingState; private static boolean cullingState;
public static void backupAndDisableCullingState(boolean b) { public static void backupAndDisableCullingState(boolean b) {
cullingState = Minecraft.getInstance().smartCull; cullingState = MINECRAFT_SHIM.getSmartCull();
Minecraft.getInstance().smartCull = Minecraft.getInstance().smartCull && !b; MINECRAFT_SHIM.setSmartCull(cullingState && !b);
} }
public static void restoreCullingState() { public static void restoreCullingState() {
Minecraft.getInstance().smartCull = cullingState; MINECRAFT_SHIM.setSmartCull(cullingState);
cullingState = true; cullingState = true;
} }
@@ -537,14 +535,14 @@ public class IrisRenderSystem {
@Override @Override
public void bindTextureToUnit(int target, int unit, int texture) { public void bindTextureToUnit(int target, int unit, int texture) {
if (GlStateManagerAccessor.getTEXTURES()[unit].binding == texture) { if (GL_STATE_MANAGER.getBoundTexture(unit) == texture) {
return; return;
} }
ARBDirectStateAccess.glBindTextureUnit(unit, texture); ARBDirectStateAccess.glBindTextureUnit(unit, texture);
// Manually fix GLStateManager bindings... // Manually fix GLStateManager bindings...
GlStateManagerAccessor.getTEXTURES()[unit].binding = texture; GL_STATE_MANAGER.setBoundTexture(unit, texture);
} }
@Override @Override
@@ -625,7 +623,7 @@ public class IrisRenderSystem {
@Override @Override
public void copyTexSubImage2D(int destTexture, int target, int i, int i1, int i2, int i3, int i4, int width, int height) { public void copyTexSubImage2D(int destTexture, int target, int i, int i1, int i2, int i3, int i4, int width, int height) {
int previous = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding; int previous = GL_STATE_MANAGER.getActiveBoundTexture();
GL_STATE_MANAGER.bindTexture(destTexture); GL_STATE_MANAGER.bindTexture(destTexture);
GL32C.glCopyTexSubImage2D(target, i, i1, i2, i3, i4, width, height); GL32C.glCopyTexSubImage2D(target, i, i1, i2, i3, i4, width, height);
GL_STATE_MANAGER.bindTexture(previous); GL_STATE_MANAGER.bindTexture(previous);
@@ -3,7 +3,6 @@ package net.irisshaders.iris.gl.buffer;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.lwjgl.opengl.GL43C; import org.lwjgl.opengl.GL43C;
// Do not extend GlResource, this is immutable. // Do not extend GlResource, this is immutable.
@@ -14,7 +13,7 @@ public class ShaderStorageBuffer {
public ShaderStorageBuffer(int index, ShaderStorageInfo info) { public ShaderStorageBuffer(int index, ShaderStorageInfo info) {
this.id = IrisRenderSystem.createBuffers(); this.id = IrisRenderSystem.createBuffers();
GLDebug.nameObject(GL43C.GL_BUFFER, id, "SSBO " + index); // GLDebug.nameObject(GL43C.GL_BUFFER, id, "SSBO " + index);
this.index = index; this.index = index;
this.info = info; this.info = info;
} }
@@ -8,7 +8,6 @@ import net.irisshaders.iris.gl.texture.InternalTextureFormat;
import net.irisshaders.iris.gl.texture.PixelFormat; import net.irisshaders.iris.gl.texture.PixelFormat;
import net.irisshaders.iris.gl.texture.PixelType; import net.irisshaders.iris.gl.texture.PixelType;
import net.irisshaders.iris.gl.texture.TextureType; import net.irisshaders.iris.gl.texture.TextureType;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.lwjgl.opengl.*; import org.lwjgl.opengl.*;
public class GlImage extends GlResource { public class GlImage extends GlResource {
@@ -31,7 +30,7 @@ public class GlImage extends GlResource {
this.pixelType = pixelType; this.pixelType = pixelType;
this.clear = clear; this.clear = clear;
GLDebug.nameObject(GL43C.GL_TEXTURE, getGlId(), name); // GLDebug.nameObject(GL43C.GL_TEXTURE, getGlId(), name);
IrisRenderSystem.bindTextureForSetup(target.getGlType(), getGlId()); IrisRenderSystem.bindTextureForSetup(target.getGlType(), getGlId());
target.apply(getGlId(), width, height, depth, internalFormat.getGlFormat(), format.getGlFormat(), pixelType.getGlFormat(), null); target.apply(getGlId(), width, height, depth, internalFormat.getGlFormat(), format.getGlFormat(), pixelType.getGlFormat(), null);
@@ -1,10 +1,11 @@
package net.irisshaders.iris.gl.texture; package net.irisshaders.iris.gl.texture;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM; import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.framebuffer.GlFramebuffer; import net.irisshaders.iris.gl.framebuffer.GlFramebuffer;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C; import org.lwjgl.opengl.GL30C;
@@ -57,7 +58,7 @@ public interface DepthCopyStrategy {
public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb, int destTexture, int width, int height) { public void copy(GlFramebuffer sourceFb, int sourceTexture, GlFramebuffer destFb, int destTexture, int width, int height) {
sourceFb.bindAsReadBuffer(); sourceFb.bindAsReadBuffer();
int previousTexture = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding; int previousTexture = GL_STATE_MANAGER.getActiveBoundTexture();
IrisRenderSystem.copyTexSubImage2D( IrisRenderSystem.copyTexSubImage2D(
destTexture, destTexture,
@@ -6,7 +6,6 @@ import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
@@ -30,7 +29,7 @@ public class TextureInfoCache {
public void onTexImage2D(int target, int level, int internalformat, int width, int height, int border, public void onTexImage2D(int target, int level, int internalformat, int width, int height, int border,
int format, int type, @Nullable IntBuffer pixels) { int format, int type, @Nullable IntBuffer pixels) {
if (level == 0) { if (level == 0) {
int id = GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding; int id = GL_STATE_MANAGER.getActiveBoundTexture();
TextureInfo info = getInfo(id); TextureInfo info = getInfo(id);
info.internalFormat = internalformat; info.internalFormat = internalformat;
info.width = width; info.width = width;
@@ -4,6 +4,7 @@ import java.nio.IntBuffer;
import java.util.*; import java.util.*;
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER; import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
import static com.mitchej123.glsm.MinecraftVersionShimService.MINECRAFT_SHIM;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import net.irisshaders.iris.Iris; import net.irisshaders.iris.Iris;
@@ -15,7 +16,6 @@ import net.irisshaders.iris.gl.uniform.UniformHolder;
import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency; import net.irisshaders.iris.gl.uniform.UniformUpdateFrequency;
import net.irisshaders.iris.parsing.UniformType; import net.irisshaders.iris.parsing.UniformType;
import net.irisshaders.iris.uniforms.SystemTimeUniforms; import net.irisshaders.iris.uniforms.SystemTimeUniforms;
import net.minecraft.client.Minecraft;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBShaderImageLoadStore; import org.lwjgl.opengl.ARBShaderImageLoadStore;
import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL20C;
@@ -41,11 +41,7 @@ public class ProgramUniforms {
} }
private static long getCurrentTick() { private static long getCurrentTick() {
if (Minecraft.getInstance().level == null) { return MINECRAFT_SHIM.getCurrentTiick();
return 0L;
} else {
return Minecraft.getInstance().level.getGameTime();
}
} }
public static void clearActiveUniforms() { public static void clearActiveUniforms() {
@@ -1,7 +1,7 @@
package net.irisshaders.iris.mixin; package net.irisshaders.iris.mixin;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.BooleanStateExtended; import org.embeddedt.embeddium.compat.BooleanStateExtended;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -31,7 +31,6 @@ import net.irisshaders.iris.shaderpack.option.ShaderPackOptions;
import net.irisshaders.iris.shaderpack.preprocessor.PropertiesPreprocessor; import net.irisshaders.iris.shaderpack.preprocessor.PropertiesPreprocessor;
import net.irisshaders.iris.shaderpack.texture.TextureStage; import net.irisshaders.iris.shaderpack.texture.TextureStage;
import net.irisshaders.iris.uniforms.custom.CustomUniforms; import net.irisshaders.iris.uniforms.custom.CustomUniforms;
import org.embeddedt.embeddium.impl.loader.common.LoaderServices;
import org.embeddedt.embeddium.impl.util.PlatformUtil; import org.embeddedt.embeddium.impl.util.PlatformUtil;
import java.io.IOException; import java.io.IOException;
@@ -1,4 +1,4 @@
package net.irisshaders.iris.gl; package org.embeddedt.embeddium.compat;
public interface BooleanStateExtended { public interface BooleanStateExtended {
void setUnknownState(); void setUnknownState();
@@ -0,0 +1,25 @@
package org.embeddedt.embeddium.impl;
import com.mitchej123.glsm.MinecraftVersionShimService;
import net.minecraft.client.Minecraft;
public class MinecraftModernVersionShim implements MinecraftVersionShimService {
@Override
public boolean getSmartCull() {
return Minecraft.getInstance().smartCull;
}
@Override
public void setSmartCull(boolean smartCull) {
Minecraft.getInstance().smartCull = smartCull;
}
@Override
public long getCurrentTiick() {
if (Minecraft.getInstance().level == null) {
return 0L;
} else {
return Minecraft.getInstance().level.getGameTime();
}
}
}
@@ -218,6 +218,21 @@ public class GLStateManagerImpl implements GLStateManagerService {
return GlStateManager._getActiveTexture(); return GlStateManager._getActiveTexture();
} }
@Override
public int getBoundTexture(int internalUnit) {
return GlStateManagerAccessor.getTEXTURES()[internalUnit].binding;
}
@Override
public int getActiveBoundTexture() {
return GlStateManagerAccessor.getTEXTURES()[GlStateManagerAccessor.getActiveTexture()].binding;
}
@Override
public void setBoundTexture(int unit, int texture) {
GlStateManagerAccessor.getTEXTURES()[unit].binding = texture;
}
@Override @Override
public void glDeleteTextures(int texture) { public void glDeleteTextures(int texture) {
GlStateManager._deleteTexture(texture); GlStateManager._deleteTexture(texture);
@@ -248,8 +263,6 @@ public class GLStateManagerImpl implements GLStateManagerService {
GlStateManager._pixelStore(pname, param); GlStateManager._pixelStore(pname, param);
} }
@Override @Override
public boolean getDepthStateMask() { public boolean getDepthStateMask() {
return GlStateManagerAccessor.getDEPTH().mask; return GlStateManagerAccessor.getDEPTH().mask;
@@ -274,4 +287,5 @@ public class GLStateManagerImpl implements GLStateManagerService {
return new ColorMask(colorMask.red, colorMask.green, colorMask.blue, colorMask.alpha); return new ColorMask(colorMask.red, colorMask.green, colorMask.blue, colorMask.alpha);
} }
} }
@@ -4,6 +4,8 @@ import java.nio.FloatBuffer;
import com.mitchej123.glsm.RenderSystemService; import com.mitchej123.glsm.RenderSystemService;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.mixin.GlStateManagerAccessor;
import org.embeddedt.embeddium.compat.BooleanStateExtended;
import org.joml.Matrix4f; import org.joml.Matrix4f;
public class RenderSystemImpl implements RenderSystemService { public class RenderSystemImpl implements RenderSystemService {
@@ -32,6 +34,11 @@ public class RenderSystemImpl implements RenderSystemService {
RenderSystem.disableBlend(); RenderSystem.disableBlend();
} }
@Override
public void setUnknownBlendState() {
((BooleanStateExtended) GlStateManagerAccessor.getBLEND().mode).setUnknownState();
}
@Override @Override
public void enableDepthTest() { public void enableDepthTest() {
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
@@ -131,4 +138,14 @@ public class RenderSystemImpl implements RenderSystemService {
public Matrix4f getProjectionMatrix() { public Matrix4f getProjectionMatrix() {
return RenderSystem.getProjectionMatrix(); return RenderSystem.getProjectionMatrix();
} }
@Override
public void setProjectionMatrixOrth(Matrix4f projectionMatrix) {
RenderSystem.setProjectionMatrix(projectionMatrix/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.ORTHOGRAPHIC_Z/*?}*/);
}
@Override
public void setProjectionMatrixOrigin(Matrix4f projectionMatrix) {
RenderSystem.setProjectionMatrix(projectionMatrix/*? if >=1.20 {*/, com.mojang.blaze3d.vertex.VertexSorting.DISTANCE_TO_ORIGIN/*?}*/);
}
} }
@@ -0,0 +1 @@
org.embeddedt.embeddium.impl.MinecraftModernVersionShim