mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
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.
This commit is contained in:
parent
c13b7637c5
commit
0e2a31ccbf
@ -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() {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ResourceLocation> 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<InstanceType<?>> createCullingKeys() {
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,6 @@ public class PipelineCompiler {
|
||||
program.setUniformBlockBinding("_FlwFrameUniforms", 0);
|
||||
program.setUniformBlockBinding("_FlwFogUniforms", 1);
|
||||
})
|
||||
.harness(sources);
|
||||
.harness(pipeline.compilerMarker(), sources);
|
||||
}
|
||||
}
|
||||
|
@ -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"))
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<K> {
|
||||
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<K> compiler) {
|
||||
public CompilationHarness(String marker, ShaderSources sources, KeyCompiler<K> 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<K> {
|
||||
stats.finish();
|
||||
|
||||
if (stats.errored()) {
|
||||
Flywheel.LOGGER.error(stats.generateErrorLog());
|
||||
stats.emitErrorLog();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ public class Compile<K> {
|
||||
private BiConsumer<K, GlProgram> onLink = (k, p) -> {
|
||||
};
|
||||
|
||||
public CompilationHarness<K> harness(ShaderSources sources) {
|
||||
return new CompilationHarness<>(sources, this);
|
||||
public CompilationHarness<K> harness(String marker, ShaderSources sources) {
|
||||
return new CompilationHarness<>(marker, sources, this);
|
||||
}
|
||||
|
||||
public ProgramLinkBuilder<K> link(ShaderCompilerBuilder<K> compilerBuilder) {
|
||||
|
@ -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<LoadError> 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() {
|
||||
|
Loading…
Reference in New Issue
Block a user