From a6ee56478463dc344419cc84c2c728703cacfa40 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Fri, 19 Jan 2024 12:29:35 -0800 Subject: [PATCH] Marker? - 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. --- src/main/java/com/jozufozu/flywheel/Flywheel.java | 4 ++-- .../flywheel/backend/compile/FlwPrograms.java | 9 +++++++-- .../backend/compile/IndirectPrograms.java | 6 +++--- .../backend/compile/InstancingPrograms.java | 3 +-- .../flywheel/backend/compile/Pipeline.java | 12 ++++++++++-- .../backend/compile/PipelineCompiler.java | 2 +- .../flywheel/backend/compile/Pipelines.java | 2 ++ .../backend/compile/core/Compilation.java | 4 ++-- .../backend/compile/core/CompilationHarness.java | 8 ++++---- .../flywheel/backend/compile/core/Compile.java | 4 ++-- .../backend/compile/core/CompilerStats.java | 15 +++++++++++---- 11 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index dd8e80fb0..09b8fceb0 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent; 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.StringUtil; import com.jozufozu.flywheel.vanilla.VanillaVisuals; -import com.mojang.logging.LogUtils; import net.minecraft.client.Minecraft; import net.minecraft.commands.synchronization.ArgumentTypeInfos; @@ -56,7 +56,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @Mod(Flywheel.ID) public class 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; public Flywheel() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java b/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java index ad7463e18..ca25d9a84 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java @@ -2,6 +2,9 @@ package com.jozufozu.flywheel.backend.compile; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; 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; public final class FlwPrograms { + public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/compile"); + private FlwPrograms() { } private static void reload(ResourceManager resourceManager) { var sources = new ShaderSources(resourceManager); - var preLoadStats = new CompilerStats(); + var preLoadStats = new CompilerStats("Preload"); var loadChecker = new SourceLoader(sources, preLoadStats); var pipelineKeys = createPipelineKeys(); @@ -35,7 +40,7 @@ public final class FlwPrograms { IndirectPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents); if (preLoadStats.errored()) { - Flywheel.LOGGER.error(preLoadStats.generateErrorLog()); + preLoadStats.emitErrorLog(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java b/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java index 347418515..1956bd86c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java @@ -61,7 +61,7 @@ public class IndirectPrograms extends AbstractPrograms { newInstance = new IndirectPrograms(pipelineResult, cullingResult, utils.get(APPLY_SHADER_MAIN), utils.get(SCATTER_SHADER_MAIN)); } } catch (Throwable t) { - Flywheel.LOGGER.error("Failed to compile indirect programs", t); + FlwPrograms.LOGGER.error("Failed to compile indirect programs", t); } pipelineCompiler.delete(); @@ -80,7 +80,7 @@ public class IndirectPrograms extends AbstractPrograms { .withResource(InstanceType::cullShader) .withResource(CULL_SHADER_MAIN)) .then((key, program) -> program.setUniformBlockBinding("_FlwFrameUniforms", 0)) - .harness(sources); + .harness("culling", sources); } private static CompilationHarness createUtilCompiler(ShaderSources sources) { @@ -88,7 +88,7 @@ public class IndirectPrograms extends AbstractPrograms { .link(UTIL.shader(GlslVersion.V460, ShaderType.COMPUTE) .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) .withResource(s -> s)) - .harness(sources); + .harness("utilities", sources); } private static ImmutableList> createCullingKeys() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java b/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java index 9c9ca9168..06cae2029 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java @@ -6,7 +6,6 @@ import java.util.Map; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; @@ -35,7 +34,7 @@ public class InstancingPrograms extends AbstractPrograms { newInstance = new InstancingPrograms(pipelineResult); } } catch (Throwable t) { - Flywheel.LOGGER.error("Failed to compile instancing programs", t); + FlwPrograms.LOGGER.error("Failed to compile instancing programs", t); } pipelineCompiler.delete(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java index 6537b205f..201e92fd3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java @@ -9,7 +9,8 @@ import com.jozufozu.flywheel.backend.glsl.SourceComponent; import net.minecraft.resources.ResourceLocation; public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, ResourceLocation fragmentMain, - ResourceLocation vertexApiImpl, ResourceLocation fragmentApiImpl, InstanceAssembler assembler) { + ResourceLocation vertexApiImpl, ResourceLocation fragmentApiImpl, InstanceAssembler assembler, + String compilerMarker) { @FunctionalInterface public interface InstanceAssembler { /** @@ -34,6 +35,7 @@ public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, Res private ResourceLocation vertexApiImpl; private ResourceLocation fragmentApiImpl; private InstanceAssembler assembler; + private String compilerMarker; public Builder glslVersion(GlslVersion glslVersion) { this.glslVersion = glslVersion; @@ -65,6 +67,11 @@ public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, Res return this; } + public Builder compilerMarker(String compilerMarker) { + this.compilerMarker = compilerMarker; + return this; + } + public Pipeline build() { Objects.requireNonNull(glslVersion); Objects.requireNonNull(vertexMain); @@ -72,7 +79,8 @@ public record Pipeline(GlslVersion glslVersion, ResourceLocation vertexMain, Res Objects.requireNonNull(vertexApiImpl); Objects.requireNonNull(fragmentApiImpl); 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); } } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java index d7338c6ed..1e7f15fc0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java @@ -38,6 +38,6 @@ public class PipelineCompiler { program.setUniformBlockBinding("_FlwFrameUniforms", 0); program.setUniformBlockBinding("_FlwFogUniforms", 1); }) - .harness(sources); + .harness(pipeline.compilerMarker(), sources); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java index 17411fed3..895fe28f9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java @@ -7,6 +7,7 @@ import com.jozufozu.flywheel.backend.glsl.GlslVersion; public final class Pipelines { public static final Pipeline INSTANCED_ARRAYS = Pipeline.builder() + .compilerMarker("instancing") .glslVersion(GlslVersion.V330) .vertexMain(Flywheel.rl("internal/instancing/main.vert")) .fragmentMain(Flywheel.rl("internal/instancing/main.frag")) @@ -15,6 +16,7 @@ public final class Pipelines { .assembler(InstancedArraysComponent::new) .build(); public static final Pipeline INDIRECT = Pipeline.builder() + .compilerMarker("indirect") .glslVersion(GlslVersion.V460) .vertexMain(Flywheel.rl("internal/indirect/main.vert")) .fragmentMain(Flywheel.rl("internal/indirect/main.frag")) diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java index a9377d229..6c490d1a9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java @@ -8,7 +8,7 @@ import java.util.List; import org.jetbrains.annotations.NotNull; 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.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; @@ -123,7 +123,7 @@ public class Compilation { try (FileWriter writer = new FileWriter(file)) { writer.write(source); } catch (Exception e) { - Flywheel.LOGGER.error("Could not dump source.", e); + FlwPrograms.LOGGER.error("Could not dump source.", e); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilationHarness.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilationHarness.java index 60a401895..611ba08ee 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilationHarness.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilationHarness.java @@ -6,7 +6,6 @@ import java.util.Map; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.glsl.ShaderSources; @@ -15,10 +14,11 @@ public class CompilationHarness { private final SourceLoader sourceLoader; private final ShaderCompiler shaderCompiler; private final ProgramLinker programLinker; - private final CompilerStats stats = new CompilerStats(); + private final CompilerStats stats; - public CompilationHarness(ShaderSources sources, KeyCompiler compiler) { + public CompilationHarness(String marker, ShaderSources sources, KeyCompiler compiler) { this.compiler = compiler; + stats = new CompilerStats(marker); sourceLoader = new SourceLoader(sources, stats); shaderCompiler = new ShaderCompiler(stats); programLinker = new ProgramLinker(stats); @@ -39,7 +39,7 @@ public class CompilationHarness { stats.finish(); if (stats.errored()) { - Flywheel.LOGGER.error(stats.generateErrorLog()); + stats.emitErrorLog(); return null; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java index 1ef355a83..02286ceb1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compile.java @@ -46,8 +46,8 @@ public class Compile { private BiConsumer onLink = (k, p) -> { }; - public CompilationHarness harness(ShaderSources sources) { - return new CompilationHarness<>(sources, this); + public CompilationHarness harness(String marker, ShaderSources sources) { + return new CompilationHarness<>(marker, sources, this); } public ProgramLinkBuilder link(ShaderCompilerBuilder compilerBuilder) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java index afaedd55b..1e71b3973 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java @@ -7,14 +7,17 @@ import java.util.Set; import java.util.stream.Collectors; 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.LoadResult; import com.jozufozu.flywheel.backend.glsl.error.ErrorBuilder; import com.jozufozu.flywheel.lib.util.StringUtil; public class CompilerStats { + private final Marker marker; private long compileStart; private final Set loadErrors = new HashSet<>(); @@ -25,6 +28,10 @@ public class CompilerStats { private int shaderCount = 0; private int programCount = 0; + public CompilerStats(String marker) { + this.marker = MarkerFactory.getMarker(marker); + } + public void start() { compileStart = System.nanoTime(); } @@ -33,14 +40,14 @@ public class CompilerStats { long compileEnd = System.nanoTime(); 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() { return errored; } - public String generateErrorLog() { + public void emitErrorLog() { String out = ""; if (!loadErrors.isEmpty()) { @@ -55,7 +62,7 @@ public class CompilerStats { out += "\nProgram link errors:\n" + linkErrors(); } - return out; + FlwPrograms.LOGGER.error(marker, out); } private String compileErrors() {