merge-stonecutter #16
No files matched your search
@@ -10,6 +10,7 @@ import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
|
||||
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
|
||||
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -305,11 +306,10 @@ public class CompositeRenderer {
|
||||
private Program createProgram(ProgramSource source, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot,
|
||||
Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
|
||||
// TODO: Properly handle empty shaders
|
||||
Preconditions.checkArgument(source.isValid());
|
||||
Map<ShaderType, String> transformed = TransformPatcherBridge.patchComposite(
|
||||
source.getName(),
|
||||
source.getSource(ShaderType.VERTEX).orElseThrow(NullPointerException::new),
|
||||
source.getSource(ShaderType.GEOM).orElse(null),
|
||||
source.getSource(ShaderType.FRAGMENT).orElseThrow(NullPointerException::new), textureStage, pipeline.getTextureMap());
|
||||
source.getSourcesMap(), textureStage, pipeline.getTextureMap());
|
||||
String vertex = transformed.get(ShaderType.VERTEX);
|
||||
String geometry = transformed.get(ShaderType.GEOMETRY);
|
||||
String fragment = transformed.get(ShaderType.FRAGMENT);
|
||||
|
||||
@@ -9,6 +9,7 @@ import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
|
||||
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
|
||||
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
@@ -317,11 +318,10 @@ public class FinalPassRenderer {
|
||||
private Program createProgram(ProgramSource source, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot,
|
||||
Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
|
||||
// TODO: Properly handle empty shaders
|
||||
Preconditions.checkArgument(source.isValid());
|
||||
Map<ShaderType, String> transformed = TransformPatcherBridge.patchComposite(
|
||||
source.getName(),
|
||||
source.getSource(ShaderType.VERTEX).orElseThrow(NullPointerException::new),
|
||||
source.getSource(ShaderType.GEOM).orElse(null),
|
||||
source.getSource(ShaderType.FRAGMENT).orElseThrow(NullPointerException::new), TextureStage.COMPOSITE_AND_FINAL, pipeline.getTextureMap());
|
||||
source.getSourcesMap(), TextureStage.COMPOSITE_AND_FINAL, pipeline.getTextureMap());
|
||||
String vertex = transformed.get(ShaderType.VERTEX);
|
||||
String geometry = transformed.get(ShaderType.GEOMETRY);
|
||||
String fragment = transformed.get(ShaderType.FRAGMENT);
|
||||
|
||||
+1
-5
@@ -150,11 +150,7 @@ public class SodiumTerrainPipeline {
|
||||
|
||||
Map<ShaderType, String> transformed = TransformPatcherBridge.patchSodium(
|
||||
sources.getName(),
|
||||
sources.getSourceNullable(ShaderType.VERTEX),
|
||||
sources.getSourceNullable(ShaderType.GEOM),
|
||||
sources.getSourceNullable(ShaderType.TESS_CTRL),
|
||||
sources.getSourceNullable(ShaderType.TESS_EVALUATE),
|
||||
sources.getSourceNullable(ShaderType.FRAGMENT),
|
||||
sources.getSourcesMap(),
|
||||
passInfo.alphaTest.orElseThrow(), inputs, parent.getTextureMap());
|
||||
|
||||
for (var type : ShaderType.values()) {
|
||||
|
||||
+6
-13
@@ -28,31 +28,24 @@ public class ShaderTransformer {
|
||||
private static final Object2ObjectLinkedOpenHashMap<TransformKey, Map<ShaderType, String>> shaderTransformationCache = new Object2ObjectLinkedOpenHashMap<>();
|
||||
public static final boolean useCache = true;
|
||||
|
||||
public record TransformKey<P extends Parameters>(Patch patchType, EnumMap<ShaderType, String> inputs, P params) {}
|
||||
public record TransformKey<P extends Parameters>(Patch patchType, Map<ShaderType, String> inputs, P params) {}
|
||||
|
||||
public static <P extends Parameters> Map<ShaderType, String> transform(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, P parameters) {
|
||||
if (vertex == null && geometry == null && tessControl == null && tessEval == null && fragment == null) {
|
||||
public static <P extends Parameters> Map<ShaderType, String> transform(String name, Map<ShaderType, String> sources, P parameters) {
|
||||
if (sources.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
Map<ShaderType, String> result;
|
||||
|
||||
var patchType = parameters.patch;
|
||||
|
||||
EnumMap<ShaderType, String> inputs = new EnumMap<>(ShaderType.class);
|
||||
inputs.put(ShaderType.VERTEX, vertex);
|
||||
inputs.put(ShaderType.GEOMETRY, geometry);
|
||||
inputs.put(ShaderType.TESS_CTRL, tessControl);
|
||||
inputs.put(ShaderType.TESS_EVALUATE, tessEval);
|
||||
inputs.put(ShaderType.FRAGMENT, fragment);
|
||||
|
||||
var key = new TransformKey(patchType, inputs, parameters);
|
||||
var key = new TransformKey(patchType, Map.copyOf(sources), parameters);
|
||||
|
||||
synchronized (shaderTransformationCache) {
|
||||
result = shaderTransformationCache.getAndMoveToFirst(key);
|
||||
}
|
||||
|
||||
if(result == null || !useCache) {
|
||||
result = ShaderTransformationDiskCache.transformIfAbsent(key, () -> transformInternal(name, inputs, patchType, parameters));
|
||||
result = ShaderTransformationDiskCache.transformIfAbsent(key, () -> transformInternal(name, sources, patchType, parameters));
|
||||
// Clear this, we don't want whatever random type was last transformed being considered for the key
|
||||
parameters.type = null;
|
||||
synchronized (shaderTransformationCache) {
|
||||
@@ -122,7 +115,7 @@ public class ShaderTransformer {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static <P extends Parameters> Map<ShaderType, String> transformInternal(String name, EnumMap<ShaderType, String> inputs, Patch patchType, P parameters) {
|
||||
private static <P extends Parameters> Map<ShaderType, String> transformInternal(String name, Map<ShaderType, String> inputs, Patch patchType, P parameters) {
|
||||
EnumMap<ShaderType, String> result = new EnumMap<>(ShaderType.class);
|
||||
EnumMap<ShaderType, Transformer> types = new EnumMap<>(ShaderType.class);
|
||||
EnumMap<ShaderType, String> prepatched = new EnumMap<>(ShaderType.class);
|
||||
|
||||
+13
-13
@@ -21,9 +21,9 @@ import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
|
||||
|
||||
public class TransformPatcherBridge {
|
||||
|
||||
private static Map<ShaderType, String> transform(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment,
|
||||
private static Map<ShaderType, String> transform(String name, Map<ShaderType, String> sources,
|
||||
Parameters parameters) {
|
||||
return ShaderTransformer.transform(name, vertex, geometry, tessControl, tessEval, fragment, parameters);
|
||||
return ShaderTransformer.transform(name, sources, parameters);
|
||||
}
|
||||
|
||||
private static Map<ShaderType, String> transformCompute(String name, String compute,
|
||||
@@ -32,43 +32,43 @@ public class TransformPatcherBridge {
|
||||
}
|
||||
|
||||
public static Map<ShaderType, String> patchVanilla(
|
||||
String name, String vertex, String geometry, String tessControl, String tessEval, String fragment,
|
||||
String name, Map<ShaderType, String> sources,
|
||||
AlphaTest alpha, boolean isLines,
|
||||
boolean hasChunkOffset,
|
||||
ShaderAttributeInputs inputs,
|
||||
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return transform(name, vertex, geometry, tessControl, tessEval, fragment,
|
||||
new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, geometry != null, tessControl != null || tessEval != null));
|
||||
return transform(name,sources,
|
||||
new VanillaParameters(Patch.VANILLA, textureMap, alpha, isLines, hasChunkOffset, inputs, sources.containsKey(ShaderType.GEOM), sources.containsKey(ShaderType.TESS_CTRL) || sources.containsKey(ShaderType.TESS_EVALUATE)));
|
||||
}
|
||||
|
||||
|
||||
public static Map<ShaderType, String> patchDHTerrain(
|
||||
String name, String vertex, String tessControl, String tessEval, String geometry, String fragment,
|
||||
String name, Map<ShaderType, String> sources,
|
||||
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return transform(name, vertex, geometry, tessControl, tessEval, fragment,
|
||||
return transform(name, sources,
|
||||
new DHParameters(Patch.DH_TERRAIN, textureMap));
|
||||
}
|
||||
|
||||
|
||||
public static Map<ShaderType, String> patchDHGeneric(
|
||||
String name, String vertex, String tessControl, String tessEval, String geometry, String fragment,
|
||||
String name, Map<ShaderType, String> sources,
|
||||
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return transform(name, vertex, geometry, tessControl, tessEval, fragment,
|
||||
return transform(name, sources,
|
||||
new DHParameters(Patch.DH_GENERIC, textureMap));
|
||||
}
|
||||
|
||||
public static Map<ShaderType, String> patchSodium(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment,
|
||||
public static Map<ShaderType, String> patchSodium(String name, Map<ShaderType, String> sources,
|
||||
AlphaTest alpha, ShaderAttributeInputs inputs,
|
||||
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return transform(name, vertex, geometry, tessControl, tessEval, fragment,
|
||||
return transform(name, sources,
|
||||
new SodiumParameters(Patch.SODIUM, textureMap, alpha, inputs));
|
||||
}
|
||||
|
||||
public static Map<ShaderType, String> patchComposite(
|
||||
String name, String vertex, String geometry, String fragment,
|
||||
String name, Map<ShaderType, String> sources,
|
||||
TextureStage stage,
|
||||
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return transform(name, vertex, geometry, null, null, fragment, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap));
|
||||
return transform(name, sources, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap));
|
||||
}
|
||||
|
||||
public static String patchCompute(
|
||||
|
||||
+6
@@ -6,6 +6,7 @@ import net.irisshaders.iris.shaderpack.properties.ProgramDirectives;
|
||||
import net.irisshaders.iris.shaderpack.properties.ShaderProperties;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -13,6 +14,7 @@ import java.util.Optional;
|
||||
public class ProgramSource {
|
||||
private final String name;
|
||||
private final Map<ShaderType, String> sources = new EnumMap<>(ShaderType.class);
|
||||
private final Map<ShaderType, String> sourcesView = Collections.unmodifiableMap(sources);
|
||||
private final ProgramDirectives directives;
|
||||
private final ProgramSet parent;
|
||||
|
||||
@@ -41,6 +43,10 @@ public class ProgramSource {
|
||||
return sources.get(type);
|
||||
}
|
||||
|
||||
public Map<ShaderType, String> getSourcesMap() {
|
||||
return sourcesView;
|
||||
}
|
||||
|
||||
public ProgramDirectives getDirectives() {
|
||||
return this.directives;
|
||||
}
|
||||
|
||||
+3
-3
@@ -8,6 +8,7 @@ import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
|
||||
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
|
||||
import static org.embeddedt.embeddium.compat.mc.MinecraftVersionShimService.MINECRAFT_SHIM;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -245,11 +246,10 @@ public class ShadowCompositeRenderer {
|
||||
private Program createProgram(ProgramSource source, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot,
|
||||
ShadowRenderTargets targets) {
|
||||
// TODO: Properly handle empty shaders
|
||||
Preconditions.checkArgument(source.isValid());
|
||||
Map<ShaderType, String> transformed = TransformPatcherBridge.patchComposite(
|
||||
source.getName(),
|
||||
source.getSource(ShaderType.VERTEX).orElseThrow(NullPointerException::new),
|
||||
source.getSourceNullable(ShaderType.GEOM),
|
||||
source.getSource(ShaderType.FRAGMENT).orElseThrow(NullPointerException::new), TextureStage.SHADOWCOMP, pipeline.getTextureMap());
|
||||
source.getSourcesMap(), TextureStage.SHADOWCOMP, pipeline.getTextureMap());
|
||||
String vertex = transformed.get(ShaderType.VERTEX);
|
||||
String geometry = transformed.get(ShaderType.GEOMETRY);
|
||||
String fragment = transformed.get(ShaderType.FRAGMENT);
|
||||
|
||||
+4
-5
@@ -8,6 +8,7 @@ import java.util.Map;
|
||||
import static com.mitchej123.glsm.GLStateManagerService.GL_STATE_MANAGER;
|
||||
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
|
||||
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
|
||||
@@ -29,6 +30,7 @@ import net.irisshaders.iris.gl.shader.GlShader;
|
||||
import net.irisshaders.iris.gl.state.FogMode;
|
||||
import net.irisshaders.iris.gl.texture.TextureType;
|
||||
import net.irisshaders.iris.pipeline.ModernIrisRenderingPipeline;
|
||||
import net.irisshaders.iris.pipeline.foss_transform.ShaderTransformer;
|
||||
import net.irisshaders.iris.pipeline.foss_transform.TransformPatcherBridge;
|
||||
import net.irisshaders.iris.pipeline.transform.ShaderPrinter;
|
||||
import net.irisshaders.iris.samplers.IrisSamplers;
|
||||
@@ -155,13 +157,10 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
|
||||
}
|
||||
|
||||
public static IrisGenericRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, ModernIrisRenderingPipeline pipeline) {
|
||||
Preconditions.checkArgument(source.isValid());
|
||||
Map<ShaderType, String> transformed = TransformPatcherBridge.patchDHGeneric(
|
||||
name,
|
||||
source.getSource(ShaderType.VERTEX).orElseThrow(RuntimeException::new),
|
||||
source.getSource(ShaderType.TESS_CTRL).orElse(null),
|
||||
source.getSource(ShaderType.TESS_EVALUATE).orElse(null),
|
||||
source.getSource(ShaderType.GEOM).orElse(null),
|
||||
source.getSource(ShaderType.FRAGMENT).orElseThrow(RuntimeException::new),
|
||||
source.getSourcesMap(),
|
||||
pipeline.getTextureMap());
|
||||
String vertex = transformed.get(ShaderType.VERTEX);
|
||||
String tessControl = transformed.get(ShaderType.TESS_CTRL);
|
||||
|
||||
+3
-5
@@ -7,6 +7,7 @@ import java.util.Map;
|
||||
|
||||
import static com.mitchej123.glsm.RenderSystemService.RENDER_SYSTEM;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.seibel.distanthorizons.api.DhApi;
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
|
||||
@@ -135,13 +136,10 @@ public class IrisLodRenderProgram {
|
||||
}
|
||||
|
||||
public static IrisLodRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, ModernIrisRenderingPipeline pipeline) {
|
||||
Preconditions.checkArgument(source.isValid());
|
||||
Map<ShaderType, String> transformed = TransformPatcherBridge.patchDHTerrain(
|
||||
name,
|
||||
source.getSource(ShaderType.VERTEX).orElseThrow(RuntimeException::new),
|
||||
source.getSource(ShaderType.TESS_CTRL).orElse(null),
|
||||
source.getSource(ShaderType.TESS_EVALUATE).orElse(null),
|
||||
source.getSource(ShaderType.GEOM).orElse(null),
|
||||
source.getSource(ShaderType.FRAGMENT).orElseThrow(RuntimeException::new),
|
||||
source.getSourcesMap(),
|
||||
pipeline.getTextureMap());
|
||||
String vertex = transformed.get(ShaderType.VERTEX);
|
||||
String tessControl = transformed.get(ShaderType.TESS_CTRL);
|
||||
|
||||
+3
-5
@@ -1,5 +1,6 @@
|
||||
package net.irisshaders.iris.pipeline.programs;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
@@ -64,13 +65,10 @@ public class ShaderCreator {
|
||||
BlendModeOverride blendModeOverride = source.getDirectives().getBlendModeOverride().orElse(programId.getBlendModeOverride());
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Preconditions.checkArgument(source.isValid());
|
||||
return TransformPatcherBridge.patchVanilla(
|
||||
name,
|
||||
source.getSource(ShaderType.VERTEX).orElseThrow(RuntimeException::new),
|
||||
source.getSource(ShaderType.GEOM).orElse(null),
|
||||
source.getSource(ShaderType.TESS_CTRL).orElse(null),
|
||||
source.getSource(ShaderType.TESS_EVALUATE).orElse(null),
|
||||
source.getSource(ShaderType.FRAGMENT).orElseThrow(RuntimeException::new),
|
||||
source.getSourcesMap(),
|
||||
alpha, isLines, true, inputs, pipeline.getTextureMap());
|
||||
}, Util.backgroundExecutor()).thenApplyAsync(transformed -> {
|
||||
|
||||
|
||||
Reference in new issue
Block a user