mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-17 11:05:04 +00:00
Tweaks (#1329)
This commit is contained in:
1 parent
1968914582
commit
48d032e654
8 files changed
+126
-69
No files matched your search
@@ -390,6 +390,9 @@ public class Iris {
|
||||
// Warm up the threadpool so shader transformations are faster when we need them
|
||||
ShaderTransformExecutor.warmup();
|
||||
|
||||
// Initialize version hoisting pattern based on GL capabilities
|
||||
ShaderTransformer.init();
|
||||
|
||||
PBRTextureManager.INSTANCE.init();
|
||||
|
||||
// Only load the shader pack when we can access OpenGL
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.Locale;
|
||||
* A compiled OpenGL shader object.
|
||||
*/
|
||||
public class GlShader extends GlResource {
|
||||
private static final Logger LOGGER = LogManager.getLogger(GlShader.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger("GlShader");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public enum PixelType {
|
||||
UNSIGNED_SHORT_4_4_4_4_REV(GL12.GL_UNSIGNED_SHORT_4_4_4_4_REV, GlVersion.GL_12),
|
||||
UNSIGNED_SHORT_5_5_5_1(GL12.GL_UNSIGNED_SHORT_5_5_5_1, GlVersion.GL_12),
|
||||
UNSIGNED_SHORT_1_5_5_5_REV(GL12.GL_UNSIGNED_SHORT_1_5_5_5_REV, GlVersion.GL_12),
|
||||
UNSIGNED_INT(GL11.GL_UNSIGNED_BYTE, GlVersion.GL_11),
|
||||
UNSIGNED_INT(GL11.GL_UNSIGNED_INT, GlVersion.GL_11),
|
||||
UNSIGNED_INT_8_8_8_8(GL12.GL_UNSIGNED_INT_8_8_8_8, GlVersion.GL_12),
|
||||
UNSIGNED_INT_8_8_8_8_REV(GL12.GL_UNSIGNED_INT_8_8_8_8_REV, GlVersion.GL_12),
|
||||
UNSIGNED_INT_10_10_10_2(GL12.GL_UNSIGNED_INT_10_10_10_2, GlVersion.GL_12),
|
||||
|
||||
@@ -754,6 +754,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
IrisSamplers.addNoiseSampler(customTextureSamplerInterceptor, customTextureManager.getNoiseTexture());
|
||||
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, customImages);
|
||||
IrisSamplers.addCustomTextures(customTextureSamplerInterceptor, customTextureManager.getIrisCustomTextures());
|
||||
IrisImages.addCustomImages(builder, customImages);
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
if (!shadow) {
|
||||
shadowTargetsSupplier.get();
|
||||
@@ -1130,6 +1134,9 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
IrisSamplers.addNoiseSampler(customTextureSamplerInterceptor, customTextureManager.getNoiseTexture());
|
||||
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, customImages);
|
||||
IrisSamplers.addCustomTextures(customTextureSamplerInterceptor, customTextureManager.getIrisCustomTextures());
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
if (shadowRenderTargets != null) {
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowRenderTargets, null, true);
|
||||
@@ -1137,6 +1144,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
}
|
||||
|
||||
IrisImages.addCustomImages(builder, customImages);
|
||||
|
||||
programs[i] = builder.buildCompute();
|
||||
|
||||
this.customUniforms.mapholderToPass(builder, programs[i]);
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.iris.IrisExtendedChunkVertexType;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
@@ -15,13 +17,15 @@ import org.taumc.glsl.ShaderParser;
|
||||
import org.taumc.glsl.Transformer;
|
||||
import org.taumc.glsl.grammar.GLSLLexer;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -58,7 +62,63 @@ public class ShaderTransformer {
|
||||
fullReservedWords.add("texture");
|
||||
|
||||
// sample was added as a keyword in GLSL 400, many shaders use it
|
||||
versionedReservedWords.put(400, Arrays.asList("sample"));
|
||||
versionedReservedWords.put(400, List.of("sample"));
|
||||
}
|
||||
|
||||
private record VersionRequirement(String keyword, int minVersion, BooleanSupplier supported) {}
|
||||
|
||||
// Sorted descending by minVersion for early exit in getRequiredVersion
|
||||
private static final VersionRequirement[] VERSION_REQUIREMENTS = {
|
||||
new VersionRequirement("std430", 430, RenderSystem::supportsSSBO),
|
||||
new VersionRequirement("iimage", 420, RenderSystem::supportsImageLoadStore),
|
||||
new VersionRequirement("uimage", 420, RenderSystem::supportsImageLoadStore),
|
||||
new VersionRequirement("imageLoad", 420, RenderSystem::supportsImageLoadStore),
|
||||
new VersionRequirement("imageStore", 420, RenderSystem::supportsImageLoadStore)
|
||||
};
|
||||
|
||||
private static Pattern hoistPattern;
|
||||
private static Object2IntMap<String> keywordToVersion;
|
||||
private static int maxSupportedHoistVersion;
|
||||
|
||||
public static void init() {
|
||||
final StringBuilder patternBuilder = new StringBuilder();
|
||||
final Object2IntOpenHashMap<String> versionMap = new Object2IntOpenHashMap<>();
|
||||
int maxVersion = 0;
|
||||
|
||||
for (VersionRequirement req : VERSION_REQUIREMENTS) {
|
||||
if (req.supported.getAsBoolean()) {
|
||||
if (!patternBuilder.isEmpty()) patternBuilder.append('|');
|
||||
|
||||
patternBuilder.append(Pattern.quote(req.keyword));
|
||||
versionMap.put(req.keyword, req.minVersion);
|
||||
maxVersion = Math.max(maxVersion, req.minVersion);
|
||||
}
|
||||
}
|
||||
|
||||
if (!patternBuilder.isEmpty()) {
|
||||
hoistPattern = Pattern.compile(patternBuilder.toString());
|
||||
keywordToVersion = versionMap;
|
||||
}
|
||||
maxSupportedHoistVersion = maxVersion;
|
||||
|
||||
Iris.logger.info("Shader version hoisting: {} feature(s) GLSL {}", versionMap.size(), maxVersion > 0 ? maxVersion : "N/A");
|
||||
}
|
||||
|
||||
private static int getRequiredVersion(String shaderSource, int declaredVersion) {
|
||||
if (hoistPattern == null || declaredVersion >= maxSupportedHoistVersion) {
|
||||
return declaredVersion;
|
||||
}
|
||||
|
||||
final Matcher m = hoistPattern.matcher(shaderSource);
|
||||
int required = declaredVersion;
|
||||
while (m.find()) {
|
||||
final int ver = keywordToVersion.getInt(m.group());
|
||||
if (ver > required) {
|
||||
required = ver;
|
||||
if (required >= maxSupportedHoistVersion) break;
|
||||
}
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
private static final class TransformKey<P extends Parameters> {
|
||||
@@ -164,10 +224,19 @@ public class ShaderTransformer {
|
||||
|
||||
String profile = "";
|
||||
int versionInt = Integer.parseInt(versionString);
|
||||
|
||||
// Check if shader uses features requiring a higher GLSL version
|
||||
int requiredVersion = getRequiredVersion(input, versionInt);
|
||||
if (requiredVersion > versionInt) {
|
||||
Iris.logger.debug("Shader requires GLSL {} for detected features, hoisting from {}", requiredVersion, versionInt);
|
||||
versionInt = requiredVersion;
|
||||
versionString = String.valueOf(versionInt);
|
||||
}
|
||||
|
||||
if (versionInt >= 150) {
|
||||
profile = matcher.group(2);
|
||||
if (profile == null) {
|
||||
profile = "core";
|
||||
profile = "compatibility";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ public class ShaderPack {
|
||||
IncludeProcessor includeProcessor = new IncludeProcessor(graph);
|
||||
|
||||
// Set up our source provider for creating ProgramSets
|
||||
Iterable<StringPair> finalEnvironmentDefines1 = environmentDefines;
|
||||
Iterable<StringPair> finalEnvironmentDefines1 = finalEnvironmentDefines;
|
||||
this.sourceProvider = (path) -> {
|
||||
String pathString = path.getPathString();
|
||||
// Removes the first "/" in the path if present, and the file
|
||||
|
||||
Reference in new issue
Block a user