- Include a marker for each compilation harness in its logs.
- Use a separate instance of logger for compilation stuffs.
- Change CompilerStats info format to log programs before shaders.
This commit is contained in:
Jozufozu 2024-01-19 12:29:35 -08:00
parent 4aa833e027
commit a6ee564784
11 changed files with 45 additions and 24 deletions

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent;
import com.jozufozu.flywheel.api.visualization.VisualizationManager; import com.jozufozu.flywheel.api.visualization.VisualizationManager;
@ -32,7 +33,6 @@ import com.jozufozu.flywheel.lib.util.LevelAttached;
import com.jozufozu.flywheel.lib.util.ShadersModHandler; import com.jozufozu.flywheel.lib.util.ShadersModHandler;
import com.jozufozu.flywheel.lib.util.StringUtil; import com.jozufozu.flywheel.lib.util.StringUtil;
import com.jozufozu.flywheel.vanilla.VanillaVisuals; import com.jozufozu.flywheel.vanilla.VanillaVisuals;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.commands.synchronization.ArgumentTypeInfos; import net.minecraft.commands.synchronization.ArgumentTypeInfos;
@ -56,7 +56,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod(Flywheel.ID) @Mod(Flywheel.ID)
public class Flywheel { public class Flywheel {
public static final String ID = "flywheel"; public static final String ID = "flywheel";
public static final Logger LOGGER = LogUtils.getLogger(); public static final Logger LOGGER = LoggerFactory.getLogger(ID);
private static ArtifactVersion version; private static ArtifactVersion version;
public Flywheel() { public Flywheel() {

View File

@ -2,6 +2,9 @@ package com.jozufozu.flywheel.backend.compile;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.context.Context;
@ -19,12 +22,14 @@ import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener; import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
public final class FlwPrograms { public final class FlwPrograms {
public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/compile");
private FlwPrograms() { private FlwPrograms() {
} }
private static void reload(ResourceManager resourceManager) { private static void reload(ResourceManager resourceManager) {
var sources = new ShaderSources(resourceManager); var sources = new ShaderSources(resourceManager);
var preLoadStats = new CompilerStats(); var preLoadStats = new CompilerStats("Preload");
var loadChecker = new SourceLoader(sources, preLoadStats); var loadChecker = new SourceLoader(sources, preLoadStats);
var pipelineKeys = createPipelineKeys(); var pipelineKeys = createPipelineKeys();
@ -35,7 +40,7 @@ public final class FlwPrograms {
IndirectPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents); IndirectPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents);
if (preLoadStats.errored()) { if (preLoadStats.errored()) {
Flywheel.LOGGER.error(preLoadStats.generateErrorLog()); preLoadStats.emitErrorLog();
} }
} }

View File

@ -61,7 +61,7 @@ public class IndirectPrograms extends AbstractPrograms {
newInstance = new IndirectPrograms(pipelineResult, cullingResult, utils.get(APPLY_SHADER_MAIN), utils.get(SCATTER_SHADER_MAIN)); newInstance = new IndirectPrograms(pipelineResult, cullingResult, utils.get(APPLY_SHADER_MAIN), utils.get(SCATTER_SHADER_MAIN));
} }
} catch (Throwable t) { } catch (Throwable t) {
Flywheel.LOGGER.error("Failed to compile indirect programs", t); FlwPrograms.LOGGER.error("Failed to compile indirect programs", t);
} }
pipelineCompiler.delete(); pipelineCompiler.delete();
@ -80,7 +80,7 @@ public class IndirectPrograms extends AbstractPrograms {
.withResource(InstanceType::cullShader) .withResource(InstanceType::cullShader)
.withResource(CULL_SHADER_MAIN)) .withResource(CULL_SHADER_MAIN))
.then((key, program) -> program.setUniformBlockBinding("_FlwFrameUniforms", 0)) .then((key, program) -> program.setUniformBlockBinding("_FlwFrameUniforms", 0))
.harness(sources); .harness("culling", sources);
} }
private static CompilationHarness<ResourceLocation> createUtilCompiler(ShaderSources sources) { private static CompilationHarness<ResourceLocation> createUtilCompiler(ShaderSources sources) {
@ -88,7 +88,7 @@ public class IndirectPrograms extends AbstractPrograms {
.link(UTIL.shader(GlslVersion.V460, ShaderType.COMPUTE) .link(UTIL.shader(GlslVersion.V460, ShaderType.COMPUTE)
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
.withResource(s -> s)) .withResource(s -> s))
.harness(sources); .harness("utilities", sources);
} }
private static ImmutableList<InstanceType<?>> createCullingKeys() { private static ImmutableList<InstanceType<?>> createCullingKeys() {

View File

@ -6,7 +6,6 @@ import java.util.Map;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.context.Context;
import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.instance.InstanceType;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
@ -35,7 +34,7 @@ public class InstancingPrograms extends AbstractPrograms {
newInstance = new InstancingPrograms(pipelineResult); newInstance = new InstancingPrograms(pipelineResult);
} }
} catch (Throwable t) { } catch (Throwable t) {
Flywheel.LOGGER.error("Failed to compile instancing programs", t); FlwPrograms.LOGGER.error("Failed to compile instancing programs", t);
} }
pipelineCompiler.delete(); pipelineCompiler.delete();

View File

@ -9,7 +9,8 @@ import com.jozufozu.flywheel.backend.glsl.SourceComponent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, ResourceLocation fragmentMain, public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, ResourceLocation fragmentMain,
ResourceLocation vertexApiImpl, ResourceLocation fragmentApiImpl, InstanceAssembler assembler) { ResourceLocation vertexApiImpl, ResourceLocation fragmentApiImpl, InstanceAssembler assembler,
String compilerMarker) {
@FunctionalInterface @FunctionalInterface
public interface InstanceAssembler { public interface InstanceAssembler {
/** /**
@ -34,6 +35,7 @@ public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, Res
private ResourceLocation vertexApiImpl; private ResourceLocation vertexApiImpl;
private ResourceLocation fragmentApiImpl; private ResourceLocation fragmentApiImpl;
private InstanceAssembler assembler; private InstanceAssembler assembler;
private String compilerMarker;
public Builder glslVersion(GlslVersion glslVersion) { public Builder glslVersion(GlslVersion glslVersion) {
this.glslVersion = glslVersion; this.glslVersion = glslVersion;
@ -65,6 +67,11 @@ public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, Res
return this; return this;
} }
public Builder compilerMarker(String compilerMarker) {
this.compilerMarker = compilerMarker;
return this;
}
public Pipeline build() { public Pipeline build() {
Objects.requireNonNull(glslVersion); Objects.requireNonNull(glslVersion);
Objects.requireNonNull(vertexMain); Objects.requireNonNull(vertexMain);
@ -72,7 +79,8 @@ public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, Res
Objects.requireNonNull(vertexApiImpl); Objects.requireNonNull(vertexApiImpl);
Objects.requireNonNull(fragmentApiImpl); Objects.requireNonNull(fragmentApiImpl);
Objects.requireNonNull(assembler); Objects.requireNonNull(assembler);
return new Pipeline(glslVersion, vertexMain, fragmentMain, vertexApiImpl, fragmentApiImpl, assembler); Objects.requireNonNull(compilerMarker);
return new Pipeline(glslVersion, vertexMain, fragmentMain, vertexApiImpl, fragmentApiImpl, assembler, compilerMarker);
} }
} }
} }

View File

@ -38,6 +38,6 @@ public class PipelineCompiler {
program.setUniformBlockBinding("_FlwFrameUniforms", 0); program.setUniformBlockBinding("_FlwFrameUniforms", 0);
program.setUniformBlockBinding("_FlwFogUniforms", 1); program.setUniformBlockBinding("_FlwFogUniforms", 1);
}) })
.harness(sources); .harness(pipeline.compilerMarker(), sources);
} }
} }

View File

@ -7,6 +7,7 @@ import com.jozufozu.flywheel.backend.glsl.GlslVersion;
public final class Pipelines { public final class Pipelines {
public static final Pipeline INSTANCED_ARRAYS = Pipeline.builder() public static final Pipeline INSTANCED_ARRAYS = Pipeline.builder()
.compilerMarker("instancing")
.glslVersion(GlslVersion.V330) .glslVersion(GlslVersion.V330)
.vertexMain(Flywheel.rl("internal/instancing/main.vert")) .vertexMain(Flywheel.rl("internal/instancing/main.vert"))
.fragmentMain(Flywheel.rl("internal/instancing/main.frag")) .fragmentMain(Flywheel.rl("internal/instancing/main.frag"))
@ -15,6 +16,7 @@ public final class Pipelines {
.assembler(InstancedArraysComponent::new) .assembler(InstancedArraysComponent::new)
.build(); .build();
public static final Pipeline INDIRECT = Pipeline.builder() public static final Pipeline INDIRECT = Pipeline.builder()
.compilerMarker("indirect")
.glslVersion(GlslVersion.V460) .glslVersion(GlslVersion.V460)
.vertexMain(Flywheel.rl("internal/indirect/main.vert")) .vertexMain(Flywheel.rl("internal/indirect/main.vert"))
.fragmentMain(Flywheel.rl("internal/indirect/main.frag")) .fragmentMain(Flywheel.rl("internal/indirect/main.frag"))

View File

@ -8,7 +8,7 @@ import java.util.List;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.compile.FlwPrograms;
import com.jozufozu.flywheel.backend.gl.GlCompat; import com.jozufozu.flywheel.backend.gl.GlCompat;
import com.jozufozu.flywheel.backend.gl.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.GlShader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
@ -123,7 +123,7 @@ public class Compilation {
try (FileWriter writer = new FileWriter(file)) { try (FileWriter writer = new FileWriter(file)) {
writer.write(source); writer.write(source);
} catch (Exception e) { } catch (Exception e) {
Flywheel.LOGGER.error("Could not dump source.", e); FlwPrograms.LOGGER.error("Could not dump source.", e);
} }
} }

View File

@ -6,7 +6,6 @@ import java.util.Map;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.glsl.ShaderSources; import com.jozufozu.flywheel.backend.glsl.ShaderSources;
@ -15,10 +14,11 @@ public class CompilationHarness<K> {
private final SourceLoader sourceLoader; private final SourceLoader sourceLoader;
private final ShaderCompiler shaderCompiler; private final ShaderCompiler shaderCompiler;
private final ProgramLinker programLinker; private final ProgramLinker programLinker;
private final CompilerStats stats = new CompilerStats(); private final CompilerStats stats;
public CompilationHarness(ShaderSources sources, KeyCompiler<K> compiler) { public CompilationHarness(String marker, ShaderSources sources, KeyCompiler<K> compiler) {
this.compiler = compiler; this.compiler = compiler;
stats = new CompilerStats(marker);
sourceLoader = new SourceLoader(sources, stats); sourceLoader = new SourceLoader(sources, stats);
shaderCompiler = new ShaderCompiler(stats); shaderCompiler = new ShaderCompiler(stats);
programLinker = new ProgramLinker(stats); programLinker = new ProgramLinker(stats);
@ -39,7 +39,7 @@ public class CompilationHarness<K> {
stats.finish(); stats.finish();
if (stats.errored()) { if (stats.errored()) {
Flywheel.LOGGER.error(stats.generateErrorLog()); stats.emitErrorLog();
return null; return null;
} }

View File

@ -46,8 +46,8 @@ public class Compile<K> {
private BiConsumer<K, GlProgram> onLink = (k, p) -> { private BiConsumer<K, GlProgram> onLink = (k, p) -> {
}; };
public CompilationHarness<K> harness(ShaderSources sources) { public CompilationHarness<K> harness(String marker, ShaderSources sources) {
return new CompilationHarness<>(sources, this); return new CompilationHarness<>(marker, sources, this);
} }
public ProgramLinkBuilder<K> link(ShaderCompilerBuilder<K> compilerBuilder) { public ProgramLinkBuilder<K> link(ShaderCompilerBuilder<K> compilerBuilder) {

View File

@ -7,14 +7,17 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.compile.FlwPrograms;
import com.jozufozu.flywheel.backend.glsl.LoadError; import com.jozufozu.flywheel.backend.glsl.LoadError;
import com.jozufozu.flywheel.backend.glsl.LoadResult; import com.jozufozu.flywheel.backend.glsl.LoadResult;
import com.jozufozu.flywheel.backend.glsl.error.ErrorBuilder; import com.jozufozu.flywheel.backend.glsl.error.ErrorBuilder;
import com.jozufozu.flywheel.lib.util.StringUtil; import com.jozufozu.flywheel.lib.util.StringUtil;
public class CompilerStats { public class CompilerStats {
private final Marker marker;
private long compileStart; private long compileStart;
private final Set<LoadError> loadErrors = new HashSet<>(); private final Set<LoadError> loadErrors = new HashSet<>();
@ -25,6 +28,10 @@ public class CompilerStats {
private int shaderCount = 0; private int shaderCount = 0;
private int programCount = 0; private int programCount = 0;
public CompilerStats(String marker) {
this.marker = MarkerFactory.getMarker(marker);
}
public void start() { public void start() {
compileStart = System.nanoTime(); compileStart = System.nanoTime();
} }
@ -33,14 +40,14 @@ public class CompilerStats {
long compileEnd = System.nanoTime(); long compileEnd = System.nanoTime();
var elapsed = StringUtil.formatTime(compileEnd - compileStart); var elapsed = StringUtil.formatTime(compileEnd - compileStart);
Flywheel.LOGGER.info("Compiled " + shaderCount + " shaders (with " + shaderErrors.size() + " compile errors) " + "and " + programCount + " programs (with " + programErrors.size() + " link errors) in " + elapsed); FlwPrograms.LOGGER.info(marker, "Compiled %d programs (with %d link errors) and %d shaders (with %d compile errors) in %s".formatted(programCount, programErrors.size(), shaderCount, shaderErrors.size(), elapsed));
} }
public boolean errored() { public boolean errored() {
return errored; return errored;
} }
public String generateErrorLog() { public void emitErrorLog() {
String out = ""; String out = "";
if (!loadErrors.isEmpty()) { if (!loadErrors.isEmpty()) {
@ -55,7 +62,7 @@ public class CompilerStats {
out += "\nProgram link errors:\n" + linkErrors(); out += "\nProgram link errors:\n" + linkErrors();
} }
return out; FlwPrograms.LOGGER.error(marker, out);
} }
private String compileErrors() { private String compileErrors() {