diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index d189bf662..1b1638a59 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -5,7 +5,7 @@ import org.slf4j.Logger; import com.jozufozu.flywheel.backend.Backends; import com.jozufozu.flywheel.backend.Loader; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipelines; +import com.jozufozu.flywheel.backend.compile.Pipelines; import com.jozufozu.flywheel.backend.engine.UniformBuffer; import com.jozufozu.flywheel.backend.engine.batching.DrawBuffer; import com.jozufozu.flywheel.config.BackendArgument; diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java b/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java index 50b0042ae..d8778c867 100644 --- a/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java +++ b/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java @@ -1,14 +1,11 @@ package com.jozufozu.flywheel.api.backend; -import org.jetbrains.annotations.Nullable; - import com.jozufozu.flywheel.impl.BackendManagerImpl; public final class BackendManager { /** * Get the current backend. */ - @Nullable public static Backend getBackend() { return BackendManagerImpl.getBackend(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/AbstractCompiler.java b/src/main/java/com/jozufozu/flywheel/backend/compile/AbstractCompiler.java index a37002d2d..922921fa4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/AbstractCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/AbstractCompiler.java @@ -7,6 +7,9 @@ import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; +import com.jozufozu.flywheel.backend.compile.core.CompilerStats; +import com.jozufozu.flywheel.backend.compile.core.ProgramLinker; +import com.jozufozu.flywheel.backend.compile.core.ShaderCompiler; import com.jozufozu.flywheel.gl.shader.GlProgram; import com.jozufozu.flywheel.glsl.ShaderSources; @@ -21,8 +24,7 @@ public abstract class AbstractCompiler { this.sources = sources; this.keys = keys; - shaderCompiler = ShaderCompiler.builder() - .build(stats); + shaderCompiler = new ShaderCompiler(stats); programLinker = new ProgramLinker(stats); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/CompileUtil.java b/src/main/java/com/jozufozu/flywheel/backend/compile/CompileUtil.java deleted file mode 100644 index 053de2709..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/CompileUtil.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.jozufozu.flywheel.backend.compile; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.jetbrains.annotations.NotNull; - -import com.jozufozu.flywheel.gl.GLSLVersion; -import com.jozufozu.flywheel.gl.shader.ShaderType; -import com.jozufozu.flywheel.glsl.SourceFile; - -public class CompileUtil { - - public static final Pattern vecType = Pattern.compile("^[biud]?vec([234])$"); - public static final Pattern matType = Pattern.compile("^mat([234])(?:x([234]))?$"); - - public static String generateHeader(GLSLVersion version, ShaderType type) { - return version.getVersionLine() + type.getDefineStatement(); - } - - public static int getElementCount(String type) { - Matcher vec = vecType.matcher(type); - if (vec.find()) { - return Integer.parseInt(vec.group(1)); - } - - Matcher mat = matType.matcher(type); - if (mat.find()) { - int n = Integer.parseInt(mat.group(1)); - - String m = mat.group(2); - - if (m != null) { - return Integer.parseInt(m) * n; - } - - return n; - } - - return 1; - } - - public static int getAttributeCount(CharSequence type) { - Matcher mat = matType.matcher(type); - if (mat.find()) { - return Integer.parseInt(mat.group(1)); - } - - return 1; - } - - @NotNull - public static String generateDebugName(SourceFile... stages) { - return Stream.of(stages) - .map(SourceFile::toString) - .collect(Collectors.joining(" -> ")); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/CullingCompiler.java b/src/main/java/com/jozufozu/flywheel/backend/compile/CullingCompiler.java index b0ba8cc2d..480da512c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/CullingCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/CullingCompiler.java @@ -5,10 +5,11 @@ import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; -import com.jozufozu.flywheel.backend.engine.indirect.IndirectComponent; -import com.jozufozu.flywheel.gl.GLSLVersion; +import com.jozufozu.flywheel.backend.compile.component.IndirectComponent; +import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.shader.GlProgram; import com.jozufozu.flywheel.gl.shader.ShaderType; +import com.jozufozu.flywheel.glsl.GLSLVersion; import com.jozufozu.flywheel.glsl.ShaderSources; import com.jozufozu.flywheel.glsl.SourceComponent; import com.jozufozu.flywheel.glsl.SourceFile; 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 791976f88..e69dc803c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/FlwPrograms.java @@ -5,8 +5,8 @@ import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.uniform.ShaderUniforms; import com.jozufozu.flywheel.api.vertex.VertexType; +import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.glsl.ShaderSources; -import com.jozufozu.flywheel.glsl.error.ErrorReporter; import com.jozufozu.flywheel.lib.context.Contexts; import net.minecraft.server.packs.resources.ResourceManager; @@ -16,9 +16,7 @@ public class FlwPrograms { } public static void reload(ResourceManager resourceManager) { - var errorReporter = new ErrorReporter(); - - var sources = new ShaderSources(errorReporter, resourceManager); + var sources = new ShaderSources(resourceManager); var pipelineKeys = createPipelineKeys(); var uniformComponent = UniformComponent.builder(Flywheel.rl("uniforms")) .sources(ShaderUniforms.REGISTRY.getAll() diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/Includer.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Includer.java deleted file mode 100644 index 3d562663e..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/Includer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.jozufozu.flywheel.backend.compile; - -import java.util.function.Consumer; - -import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.glsl.SourceComponent; - -/** - * A component of a ShaderCompiler, responsible for expanding root sources into the complete set of included sources. - */ -public interface Includer { - - /** - * Expand the given root sources into the complete set of included sources. - *

Each unique source will be seen exactly once. - * - * @param rootSources The root sources to expand. - * @param out A consumer to which all sources should be passed in the order they should be included. - */ - void expand(ImmutableList rootSources, Consumer out); -} 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 560e1b488..9030238cf 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java @@ -8,7 +8,7 @@ import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.vertex.VertexType; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipelines; +import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.shader.GlProgram; import com.jozufozu.flywheel.glsl.ShaderSources; 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 e13de2885..544a031ec 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java @@ -8,7 +8,7 @@ import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.api.context.Context; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.vertex.VertexType; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipelines; +import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.shader.GlProgram; import com.jozufozu.flywheel.glsl.ShaderSources; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/pipeline/Pipeline.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java similarity index 94% rename from src/main/java/com/jozufozu/flywheel/backend/compile/pipeline/Pipeline.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java index b29aada8f..cce3188ef 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/pipeline/Pipeline.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipeline.java @@ -1,8 +1,8 @@ -package com.jozufozu.flywheel.backend.compile.pipeline; +package com.jozufozu.flywheel.backend.compile; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.vertex.VertexType; -import com.jozufozu.flywheel.gl.GLSLVersion; +import com.jozufozu.flywheel.glsl.GLSLVersion; import com.jozufozu.flywheel.glsl.ShaderSources; import com.jozufozu.flywheel.glsl.SourceComponent; 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 6958bd238..bd9bb5c34 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java @@ -4,7 +4,8 @@ import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipeline; +import com.jozufozu.flywheel.backend.compile.component.MaterialAdapterComponent; +import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.gl.shader.GlProgram; import com.jozufozu.flywheel.gl.shader.ShaderType; import com.jozufozu.flywheel.glsl.ShaderSources; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/pipeline/Pipelines.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java similarity index 75% rename from src/main/java/com/jozufozu/flywheel/backend/compile/pipeline/Pipelines.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java index 4cd1c9b11..b3dde931d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/pipeline/Pipelines.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/Pipelines.java @@ -1,11 +1,9 @@ -package com.jozufozu.flywheel.backend.compile.pipeline; - -import java.util.List; +package com.jozufozu.flywheel.backend.compile; import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.backend.engine.indirect.IndirectComponent; -import com.jozufozu.flywheel.backend.engine.instancing.InstancedArraysComponent; -import com.jozufozu.flywheel.gl.GLSLVersion; +import com.jozufozu.flywheel.backend.compile.component.IndirectComponent; +import com.jozufozu.flywheel.backend.compile.component.InstancedArraysComponent; +import com.jozufozu.flywheel.glsl.GLSLVersion; import net.minecraft.resources.ResourceLocation; @@ -23,8 +21,6 @@ public final class Pipelines { .assembler(IndirectComponent::new) .build(); - public static final List ALL = List.of(INSTANCED_ARRAYS, INDIRECT); - public static void init() { } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/RecursiveIncluder.java b/src/main/java/com/jozufozu/flywheel/backend/compile/RecursiveIncluder.java deleted file mode 100644 index bbf9258d9..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/RecursiveIncluder.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.jozufozu.flywheel.backend.compile; - -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.function.Consumer; - -import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.glsl.SourceComponent; - -public class RecursiveIncluder implements Includer { - - public static final RecursiveIncluder INSTANCE = new RecursiveIncluder(); - - private RecursiveIncluder() { - } - - @Override - public void expand(ImmutableList rootSources, Consumer out) { - var included = new LinkedHashSet(); // use hash set to deduplicate. linked to preserve order - for (var component : rootSources) { - recursiveDepthFirstInclude(included, component); - included.add(component); - } - included.forEach(out); - } - - private static void recursiveDepthFirstInclude(Set included, SourceComponent component) { - for (var include : component.included()) { - recursiveDepthFirstInclude(included, include); - } - included.addAll(component.included()); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/glsl/SourceChecks.java b/src/main/java/com/jozufozu/flywheel/backend/compile/SourceChecks.java similarity index 94% rename from src/main/java/com/jozufozu/flywheel/glsl/SourceChecks.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/SourceChecks.java index e84843a38..7d526fb01 100644 --- a/src/main/java/com/jozufozu/flywheel/glsl/SourceChecks.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/SourceChecks.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.glsl; +package com.jozufozu.flywheel.backend.compile; import java.util.Optional; import java.util.function.BiConsumer; @@ -6,14 +6,13 @@ import java.util.function.BiConsumer; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; +import com.jozufozu.flywheel.glsl.SourceFile; import com.jozufozu.flywheel.glsl.error.ErrorReporter; import com.jozufozu.flywheel.glsl.parse.ShaderFunction; import com.jozufozu.flywheel.glsl.parse.ShaderVariable; +// TODO: recycle to be invoked by the shader compiler public class SourceChecks { - - // TODO: recycle to be invoked by the shader compiler - public static final BiConsumer LAYOUT_VERTEX = checkFunctionArity("flw_layoutVertex", 0); public static final BiConsumer INSTANCE_VERTEX = checkFunctionParameterTypeExists("flw_instanceVertex", 1, 0); public static final BiConsumer MATERIAL_VERTEX = checkFunctionArity("flw_materialVertex", 0); @@ -22,7 +21,6 @@ public class SourceChecks { public static final BiConsumer CONTEXT_FRAGMENT = checkFunctionArity("flw_contextFragment", 0).andThen(checkFunctionArity("flw_initFragment", 0)); public static final BiConsumer PIPELINE = checkFunctionArity("main", 0); - public static BiConsumer checkFunctionArity(String name, int arity) { return (errorReporter, file) -> checkFunctionArity(errorReporter, file, name, arity); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/UniformComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/UniformComponent.java deleted file mode 100644 index ba88a6bda..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/UniformComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.jozufozu.flywheel.backend.compile; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.glsl.ShaderSources; -import com.jozufozu.flywheel.glsl.SourceComponent; -import com.jozufozu.flywheel.glsl.SourceFile; -import com.jozufozu.flywheel.glsl.generate.GlslBuilder; - -import net.minecraft.resources.ResourceLocation; - -public class UniformComponent implements SourceComponent { - - private final ResourceLocation name; - private final ImmutableList uniformShaders; - - public static Builder builder(ResourceLocation uniforms) { - return new Builder(uniforms); - } - - private UniformComponent(ResourceLocation name, ImmutableList uniformShaders) { - this.name = name; - this.uniformShaders = uniformShaders; - } - - @Override - public Collection included() { - return uniformShaders; - } - - @Override - public String source() { - var builder = new GlslBuilder(); - - builder.uniformBlock() - .layout("std140") - .binding(0) - .name("FLWUniforms") - .member("flywheel_uniforms", "flywheel"); - - builder.blankLine(); - - return builder.build(); - } - - @Override - public ResourceLocation name() { - return name; - } - - public static class Builder { - - private final ResourceLocation name; - private final List uniformShaders = new ArrayList<>(); - - public Builder(ResourceLocation name) { - this.name = name; - } - - public Builder sources(List sources) { - this.uniformShaders.addAll(sources); - return this; - } - - public UniformComponent build(ShaderSources sources) { - var out = ImmutableList.builder(); - - for (var fileResolution : uniformShaders) { - out.add(sources.find(fileResolution)); - } - - return new UniformComponent(name, out.build()); - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java similarity index 83% rename from src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectComponent.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java index 446c6702e..ffa8cf829 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.engine.indirect; +package com.jozufozu.flywheel.backend.compile.component; import java.util.Collection; import java.util.List; @@ -7,8 +7,8 @@ import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.layout.LayoutItem; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipeline; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipelines; +import com.jozufozu.flywheel.backend.compile.Pipeline; +import com.jozufozu.flywheel.backend.compile.Pipelines; import com.jozufozu.flywheel.glsl.ShaderSources; import com.jozufozu.flywheel.glsl.SourceComponent; import com.jozufozu.flywheel.glsl.SourceFile; @@ -20,11 +20,11 @@ import com.jozufozu.flywheel.glsl.generate.GlslExpr; import net.minecraft.resources.ResourceLocation; public class IndirectComponent implements SourceComponent { - private static final String UNPACK_ARG = "p"; private static final GlslExpr.Variable UNPACKING_VARIABLE = GlslExpr.variable(UNPACK_ARG); - private static final String STRUCT_NAME = "IndirectStruct"; - private static final String PACKED_STRUCT_NAME = STRUCT_NAME + "_packed"; + private static final String STRUCT_NAME = "FlwInstance"; + private static final String PACKED_STRUCT_NAME = "FlwPackedInstance"; + private static final String UNPACK_FN_NAME = "_flw_unpackInstance"; private final List layoutItems; private final ImmutableList included; @@ -55,15 +55,12 @@ public class IndirectComponent implements SourceComponent { public String generateIndirect() { var builder = new GlslBuilder(); - builder.define("FlwInstance", STRUCT_NAME); - builder.define("FlwPackedInstance", PACKED_STRUCT_NAME); - builder.blankLine(); - var packed = builder.struct(); - builder.blankLine(); var instance = builder.struct(); - packed.setName(PACKED_STRUCT_NAME); instance.setName(STRUCT_NAME); + builder.blankLine(); + var packed = builder.struct(); + packed.setName(PACKED_STRUCT_NAME); for (var field : layoutItems) { field.addPackedToStruct(packed); @@ -75,7 +72,7 @@ public class IndirectComponent implements SourceComponent { builder.function() .signature(FnSignature.create() .returnType(STRUCT_NAME) - .name("_flw_unpackInstance") + .name(UNPACK_FN_NAME) .arg(PACKED_STRUCT_NAME, UNPACK_ARG) .build()) .body(this::generateUnpackingBody); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedArraysComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java similarity index 86% rename from src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedArraysComponent.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java index a56ee964f..efc1af804 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedArraysComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/InstancedArraysComponent.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.engine.instancing; +package com.jozufozu.flywheel.backend.compile.component; import java.util.Collection; import java.util.Collections; @@ -6,7 +6,7 @@ import java.util.List; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.layout.LayoutItem; -import com.jozufozu.flywheel.backend.compile.pipeline.Pipeline; +import com.jozufozu.flywheel.backend.compile.Pipeline; import com.jozufozu.flywheel.glsl.SourceComponent; import com.jozufozu.flywheel.glsl.generate.FnSignature; import com.jozufozu.flywheel.glsl.generate.GlslBlock; @@ -17,7 +17,8 @@ import net.minecraft.resources.ResourceLocation; public class InstancedArraysComponent implements SourceComponent { private static final String ATTRIBUTE_PREFIX = "_flw_i_"; - private static final String STRUCT_NAME = "Instance"; + private static final String STRUCT_NAME = "FlwInstance"; + private static final String UNPACK_FN_NAME = "_flw_unpackInstance"; private final List layoutItems; private final int baseIndex; @@ -43,9 +44,6 @@ public class InstancedArraysComponent implements SourceComponent { @Override public String source() { var builder = new GlslBuilder(); - builder.define("FlwInstance", STRUCT_NAME); - - builder.blankLine(); int i = baseIndex; for (var field : layoutItems) { @@ -72,7 +70,7 @@ public class InstancedArraysComponent implements SourceComponent { // unpacking function builder.function() - .signature(FnSignature.of(STRUCT_NAME, "_flw_unpackInstance")) + .signature(FnSignature.of(STRUCT_NAME, UNPACK_FN_NAME)) .body(this::generateUnpackingBody); builder.blankLine(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/MaterialAdapterComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java similarity index 87% rename from src/main/java/com/jozufozu/flywheel/backend/compile/MaterialAdapterComponent.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java index 1e7ea6745..e1ff329b0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/MaterialAdapterComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java @@ -1,16 +1,16 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.component; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; +import java.util.function.UnaryOperator; import javax.annotation.Nonnull; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.jozufozu.flywheel.glsl.ShaderSources; import com.jozufozu.flywheel.glsl.SourceComponent; import com.jozufozu.flywheel.glsl.generate.FnSignature; @@ -18,12 +18,10 @@ import com.jozufozu.flywheel.glsl.generate.GlslBlock; import com.jozufozu.flywheel.glsl.generate.GlslBuilder; import com.jozufozu.flywheel.glsl.generate.GlslExpr; import com.jozufozu.flywheel.glsl.generate.GlslSwitch; -import com.jozufozu.flywheel.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; public class MaterialAdapterComponent implements SourceComponent { - // TODO: material id handling in pipeline shader private final ResourceLocation name; private final GlslExpr switchArg; @@ -59,9 +57,9 @@ public class MaterialAdapterComponent implements SourceComponent { builder.function() .signature(adaptedFunction.signature()) .body(body -> generateAdapter(body, adaptedFunction)); - } - builder.blankLine(); + builder.blankLine(); + } return builder.build(); } @@ -145,31 +143,28 @@ public class MaterialAdapterComponent implements SourceComponent { var transformed = ImmutableList.builder(); + int index = 0; for (var rl : materialSources) { var sourceFile = sources.find(rl); - var adapterMap = createAdapterMap(adaptedFunctions, getSuffix(rl)); + final int finalIndex = index; + var adapterMap = createAdapterMap(adaptedFunctions, fnName -> "_" + fnName + "_" + finalIndex); transformed.add(new StringSubstitutionSourceComponent(sourceFile, adapterMap)); + index++; } return new MaterialAdapterComponent(name, switchArg, adaptedFunctions, transformed.build()); } } - @NotNull - private static HashMap createAdapterMap(List adaptedFunctions, String suffix) { - HashMap out = new HashMap<>(); + private static ImmutableMap createAdapterMap(List adaptedFunctions, UnaryOperator nameAdapter) { + ImmutableMap.Builder builder = ImmutableMap.builder(); for (var adapted : adaptedFunctions) { var fnName = adapted.signature() .name(); - out.put(fnName, fnName + suffix); + builder.put(fnName, nameAdapter.apply(fnName)); } - return out; - } - - @NotNull - private static String getSuffix(ResourceLocation rl) { - return '_' + ResourceUtil.toSafeString(rl); + return builder.build(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/StringSubstitutionSourceComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionSourceComponent.java similarity index 96% rename from src/main/java/com/jozufozu/flywheel/backend/compile/StringSubstitutionSourceComponent.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionSourceComponent.java index 375696bba..66eb668f9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/StringSubstitutionSourceComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/StringSubstitutionSourceComponent.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.component; import java.util.Collection; import java.util.Map; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/component/UniformComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/UniformComponent.java new file mode 100644 index 000000000..af945263e --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/UniformComponent.java @@ -0,0 +1,76 @@ +package com.jozufozu.flywheel.backend.compile.component; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.ImmutableList; +import com.jozufozu.flywheel.glsl.ShaderSources; +import com.jozufozu.flywheel.glsl.SourceComponent; +import com.jozufozu.flywheel.glsl.SourceFile; +import com.jozufozu.flywheel.glsl.generate.GlslBuilder; + +import net.minecraft.resources.ResourceLocation; + +public class UniformComponent implements SourceComponent { + private final ResourceLocation name; + private final ImmutableList uniformShaders; + + public static Builder builder(ResourceLocation uniforms) { + return new Builder(uniforms); + } + + private UniformComponent(ResourceLocation name, ImmutableList uniformShaders) { + this.name = name; + this.uniformShaders = uniformShaders; + } + + @Override + public Collection included() { + return uniformShaders; + } + + @Override + public String source() { + var builder = new GlslBuilder(); + + builder.uniformBlock() + .layout("std140") + .binding(0) + .name("FLWUniforms") + .member("flywheel_uniforms", "flywheel"); + + builder.blankLine(); + + return builder.build(); + } + + @Override + public ResourceLocation name() { + return name; + } + + public static class Builder { + private final ResourceLocation name; + private final List uniformShaders = new ArrayList<>(); + + public Builder(ResourceLocation name) { + this.name = name; + } + + public Builder sources(List sources) { + this.uniformShaders.addAll(sources); + return this; + } + + public UniformComponent build(ShaderSources sources) { + var out = ImmutableList.builder(); + + for (var fileResolution : uniformShaders) { + out.add(sources.find(fileResolution)); + } + + return new UniformComponent(name, out.build()); + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/Compilation.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java similarity index 94% rename from src/main/java/com/jozufozu/flywheel/backend/compile/Compilation.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java index d925fd3be..dc252043c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/Compilation.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/Compilation.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import java.io.File; import java.io.FileWriter; @@ -10,10 +10,10 @@ import org.jetbrains.annotations.NotNull; import org.lwjgl.opengl.GL20; import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.gl.GLSLVersion; import com.jozufozu.flywheel.gl.shader.GlShader; import com.jozufozu.flywheel.gl.shader.ShaderType; import com.jozufozu.flywheel.gl.versioned.GlCompat; +import com.jozufozu.flywheel.glsl.GLSLVersion; import com.jozufozu.flywheel.glsl.SourceComponent; import com.jozufozu.flywheel.glsl.SourceFile; import com.jozufozu.flywheel.util.StringUtil; @@ -39,10 +39,11 @@ public class Compilation { private int generatedLines = 0; public Compilation(GLSLVersion glslVersion, ShaderType shaderType) { - this.generatedSource = new StringBuilder(); - this.fullSource = new StringBuilder(CompileUtil.generateHeader(glslVersion, shaderType)).append('\n'); this.glslVersion = glslVersion; this.shaderType = shaderType; + + generatedSource = new StringBuilder(); + fullSource = new StringBuilder(glslVersion.getVersionLine()).append(shaderType.getDefineStatement()).append('\n'); } @NotNull diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/CompilerStats.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java similarity index 96% rename from src/main/java/com/jozufozu/flywheel/backend/compile/CompilerStats.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java index 3e8b3d752..168c4d6ce 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/CompilerStats.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/CompilerStats.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/FailedCompilation.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java similarity index 97% rename from src/main/java/com/jozufozu/flywheel/backend/compile/FailedCompilation.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java index ca3f97c36..0c42a1c9a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/FailedCompilation.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/FailedCompilation.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import java.util.List; import java.util.regex.Matcher; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/LinkResult.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/LinkResult.java similarity index 92% rename from src/main/java/com/jozufozu/flywheel/backend/compile/LinkResult.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/LinkResult.java index 0c77d6b2c..bc496c3c3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/LinkResult.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/LinkResult.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -6,7 +6,6 @@ import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.gl.shader.GlProgram; public sealed interface LinkResult { - @Nullable default GlProgram unwrap() { return null; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/ProgramLinker.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/ProgramLinker.java similarity index 96% rename from src/main/java/com/jozufozu/flywheel/backend/compile/ProgramLinker.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/ProgramLinker.java index 63394441a..b04065fb7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/ProgramLinker.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/ProgramLinker.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import static org.lwjgl.opengl.GL11.GL_TRUE; import static org.lwjgl.opengl.GL20.GL_LINK_STATUS; diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/ShaderCompiler.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/ShaderCompiler.java similarity index 57% rename from src/main/java/com/jozufozu/flywheel/backend/compile/ShaderCompiler.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/ShaderCompiler.java index ec4aa00e8..505f00a75 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/ShaderCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/ShaderCompiler.java @@ -1,28 +1,27 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.function.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.google.common.collect.ImmutableList; -import com.jozufozu.flywheel.gl.GLSLVersion; import com.jozufozu.flywheel.gl.shader.GlShader; import com.jozufozu.flywheel.gl.shader.ShaderType; +import com.jozufozu.flywheel.glsl.GLSLVersion; import com.jozufozu.flywheel.glsl.SourceComponent; public class ShaderCompiler { private final Map shaderCache = new HashMap<>(); private final CompilerStats stats; - private final CompilationFactory factory; - private final Includer includer; - public ShaderCompiler(CompilerStats stats, CompilationFactory factory, Includer includer) { + public ShaderCompiler(CompilerStats stats) { this.stats = stats; - this.factory = factory; - this.includer = includer; } public int shaderCount() { @@ -37,7 +36,7 @@ public class ShaderCompiler { return cached.unwrap(); } - ShaderResult out = compileUncached(factory.create(glslVersion, shaderType), sourceComponents); + ShaderResult out = compileUncached(new Compilation(glslVersion, shaderType), sourceComponents); shaderCache.put(key, out); stats.shaderResult(out); return out.unwrap(); @@ -56,41 +55,28 @@ public class ShaderCompiler { ctx.enableExtension("GL_ARB_explicit_attrib_location"); ctx.enableExtension("GL_ARB_conservative_depth"); - includer.expand(sourceComponents, ctx::appendComponent); + expand(sourceComponents, ctx::appendComponent); return ctx.compile(); } + private static void expand(ImmutableList rootSources, Consumer out) { + var included = new LinkedHashSet(); // use hash set to deduplicate. linked to preserve order + for (var component : rootSources) { + recursiveDepthFirstInclude(included, component); + included.add(component); + } + included.forEach(out); + } + + private static void recursiveDepthFirstInclude(Set included, SourceComponent component) { + for (var include : component.included()) { + recursiveDepthFirstInclude(included, include); + } + included.addAll(component.included()); + } + private record ShaderKey(GLSLVersion glslVersion, ShaderType shaderType, ImmutableList sourceComponents) { - - } - - public static Builder builder() { - return new Builder(); - } - - @FunctionalInterface - public interface CompilationFactory { - Compilation create(GLSLVersion version, ShaderType shaderType); - } - - public static class Builder { - private CompilationFactory factory = Compilation::new; - private Includer includer = RecursiveIncluder.INSTANCE; - - public Builder compilationFactory(CompilationFactory factory) { - this.factory = factory; - return this; - } - - public Builder includer(Includer includer) { - this.includer = includer; - return this; - } - - public ShaderCompiler build(CompilerStats stats) { - return new ShaderCompiler(stats, factory, includer); - } } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/ShaderResult.java b/src/main/java/com/jozufozu/flywheel/backend/compile/core/ShaderResult.java similarity index 92% rename from src/main/java/com/jozufozu/flywheel/backend/compile/ShaderResult.java rename to src/main/java/com/jozufozu/flywheel/backend/compile/core/ShaderResult.java index 174fa8f9f..480d4ef14 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/ShaderResult.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/core/ShaderResult.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.compile; +package com.jozufozu.flywheel.backend.compile.core; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java index 803308a41..c166a3649 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -70,16 +70,12 @@ public class FlwCommands { Minecraft.getInstance().levelRenderer.allChanged(); var actualBackend = BackendManager.getBackend(); - if (actualBackend == null) { - player.displayClientMessage(new TextComponent("Error switching backends, flywheel disabled"), false); - } else if (actualBackend != requestedBackend) { + if (actualBackend != requestedBackend) { player.displayClientMessage(new TextComponent("'" + requestedId + "' not available").withStyle(ChatFormatting.RED), false); - var component = actualBackend.engineMessage(); - player.displayClientMessage(component, false); - } else { - Component message = requestedBackend.engineMessage(); - player.displayClientMessage(message, false); } + + Component message = actualBackend.engineMessage(); + player.displayClientMessage(message, false); } return Command.SINGLE_SUCCESS; }))); diff --git a/src/main/java/com/jozufozu/flywheel/gl/GLSLVersion.java b/src/main/java/com/jozufozu/flywheel/glsl/GLSLVersion.java similarity index 92% rename from src/main/java/com/jozufozu/flywheel/gl/GLSLVersion.java rename to src/main/java/com/jozufozu/flywheel/glsl/GLSLVersion.java index 6b1576438..60b1feecb 100644 --- a/src/main/java/com/jozufozu/flywheel/gl/GLSLVersion.java +++ b/src/main/java/com/jozufozu/flywheel/glsl/GLSLVersion.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.gl; +package com.jozufozu.flywheel.glsl; public enum GLSLVersion { V110(110), diff --git a/src/main/java/com/jozufozu/flywheel/glsl/Index.java b/src/main/java/com/jozufozu/flywheel/glsl/Index.java deleted file mode 100644 index 0b84ae039..000000000 --- a/src/main/java/com/jozufozu/flywheel/glsl/Index.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.jozufozu.flywheel.glsl; - -import java.util.Collection; -import java.util.Map; - -import com.google.common.collect.Multimap; -import com.google.common.collect.MultimapBuilder; -import com.jozufozu.flywheel.glsl.parse.ShaderFunction; -import com.jozufozu.flywheel.glsl.parse.ShaderStruct; - -import net.minecraft.resources.ResourceLocation; - -/** - * Indexes many shader source definitions to allow for error fix suggestions. - */ -public class Index { - - private final Multimap knownStructs = MultimapBuilder.hashKeys() - .hashSetValues() - .build(); - - private final Multimap knownFunctions = MultimapBuilder.hashKeys() - .hashSetValues() - .build(); - - public Index(Map sources) { - Collection files = sources.values(); - - for (SourceFile file : files) { - file.structs.forEach(knownStructs::put); - file.functions.forEach(knownFunctions::put); - } - } - - public Collection getStructDefinitionsMatching(CharSequence name) { - return knownStructs.get(name.toString()); - } - - public Collection getFunctionDefinitionsMatching(CharSequence name) { - return knownFunctions.get(name.toString()); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java index b0577aadd..70ac5d2ac 100644 --- a/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java +++ b/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.glsl; import java.io.IOException; import java.util.ArrayDeque; -import java.util.ArrayList; import java.util.Deque; import java.util.HashMap; import java.util.Map; @@ -10,8 +9,6 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; -import com.google.common.collect.Lists; -import com.jozufozu.flywheel.glsl.error.ErrorReporter; import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.StringUtil; @@ -23,7 +20,8 @@ import net.minecraft.server.packs.resources.ResourceManager; */ public class ShaderSources { public static final String SHADER_DIR = "flywheel/"; - public static final ArrayList EXTENSIONS = Lists.newArrayList(".vert", ".vsh", ".frag", ".fsh", ".glsl"); + + private final ResourceManager manager; private final Map cache = new HashMap<>(); @@ -32,11 +30,7 @@ public class ShaderSources { */ private final Deque findStack = new ArrayDeque<>(); - private final ResourceManager manager; - private final ErrorReporter errorReporter; - - public ShaderSources(ErrorReporter errorReporter, ResourceManager manager) { - this.errorReporter = errorReporter; + public ShaderSources(ResourceManager manager) { this.manager = manager; } diff --git a/src/main/java/com/jozufozu/flywheel/glsl/SourceFile.java b/src/main/java/com/jozufozu/flywheel/glsl/SourceFile.java index 5337f7e79..02a6fa537 100644 --- a/src/main/java/com/jozufozu/flywheel/glsl/SourceFile.java +++ b/src/main/java/com/jozufozu/flywheel/glsl/SourceFile.java @@ -27,7 +27,6 @@ import net.minecraft.resources.ResourceLocation; *

*/ public class SourceFile implements SourceComponent { - public final ResourceLocation name; public final ShaderSources parent; diff --git a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java index 9ec6761ec..2a438211b 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java @@ -30,15 +30,14 @@ public final class BackendManagerImpl { private static final Backend DEFAULT_BACKEND = findDefaultBackend(); - private static Backend backend; + private static Backend backend = OFF_BACKEND; - @Nullable public static Backend getBackend() { return backend; } public static boolean isOn() { - return backend != null && backend != OFF_BACKEND; + return backend != OFF_BACKEND; } public static Backend getOffBackend() { @@ -80,9 +79,6 @@ public final class BackendManagerImpl { public static void init() { CrashReportCallables.registerCrashCallable("Flywheel Backend", () -> { - if (backend == null) { - return "Uninitialized"; - } var backendId = Backend.REGISTRY.getId(backend); if (backendId == null) { return "Unregistered"; diff --git a/src/main/java/com/jozufozu/flywheel/util/StringUtil.java b/src/main/java/com/jozufozu/flywheel/util/StringUtil.java index 44cedf96b..59f3296e7 100644 --- a/src/main/java/com/jozufozu/flywheel/util/StringUtil.java +++ b/src/main/java/com/jozufozu/flywheel/util/StringUtil.java @@ -21,13 +21,23 @@ import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.lib.memory.FlwMemoryTracker; public class StringUtil { - private static final NumberFormat THREE_DECIMAL_PLACES = new DecimalFormat("#0.000"); - // FIXME: this method should count trailing newlines public static int countLines(String s) { - return (int) s.lines() - .count(); + int lines = 1; + int length = s.length(); + for (int i = 0; i < length; i++) { + char c = s.charAt(i); + if (c == '\n') { + lines++; + } else if (c == '\r') { + lines++; + if (i + 1 < length && s.charAt(i + 1) == '\n') { + i++; + } + } + } + return lines; } public static String formatBytes(long bytes) { diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instanced_arrays_draw.vert b/src/main/resources/assets/flywheel/flywheel/internal/instanced_arrays_draw.vert index a3680d8d4..f8716ca1c 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instanced_arrays_draw.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/instanced_arrays_draw.vert @@ -3,12 +3,12 @@ uniform uvec2 _flw_materialID_instancing; void main() { - flw_layoutVertex(); - _flw_materialVertexID = _flw_materialID_instancing.x; _flw_materialFragmentID = _flw_materialID_instancing.y; FlwInstance i = _flw_unpackInstance(); + + flw_layoutVertex(); flw_instanceVertex(i); flw_materialVertex(); flw_contextVertex();