diff --git a/src/main/java/com/jozufozu/flywheel/api/layout/Layout.java b/src/main/java/com/jozufozu/flywheel/api/layout/Layout.java index 249f59202..10d6b9a10 100644 --- a/src/main/java/com/jozufozu/flywheel/api/layout/Layout.java +++ b/src/main/java/com/jozufozu/flywheel/api/layout/Layout.java @@ -24,7 +24,5 @@ public interface Layout { ElementType type(); int offset(); - - int byteSize(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/CompilationHarness.java b/src/main/java/com/jozufozu/flywheel/backend/compile/CompilationHarness.java index 4ee8adb4a..f46703981 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/CompilationHarness.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/CompilationHarness.java @@ -1,11 +1,11 @@ package com.jozufozu.flywheel.backend.compile; +import java.util.Collection; import java.util.HashMap; import java.util.Map; 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; @@ -18,12 +18,9 @@ public class CompilationHarness { private final SourceLoader sourceLoader; private final ShaderCompiler shaderCompiler; private final ProgramLinker programLinker; - private final ImmutableList keys; private final CompilerStats stats = new CompilerStats(); - public CompilationHarness(ShaderSources sources, ImmutableList keys, KeyCompiler compiler) { - this.keys = keys; - + public CompilationHarness(ShaderSources sources, KeyCompiler compiler) { this.compiler = compiler; sourceLoader = new SourceLoader(sources, stats); shaderCompiler = new ShaderCompiler(stats); @@ -31,7 +28,7 @@ public class CompilationHarness { } @Nullable - public Map compileAndReportErrors() { + public Map compileAndReportErrors(Collection keys) { stats.start(); Map out = new HashMap<>(); for (var key : keys) { @@ -59,28 +56,4 @@ public class CompilationHarness { public interface KeyCompiler { @Nullable GlProgram compile(K key, SourceLoader loader, ShaderCompiler shaderCompiler, ProgramLinker programLinker); } - - public static class Builder { - private final ShaderSources sources; - private ImmutableList keys; - private KeyCompiler compiler; - - public Builder(ShaderSources sources) { - this.sources = sources; - } - - public Builder keys(ImmutableList keys) { - this.keys = keys; - return this; - } - - public Builder compiler(KeyCompiler compiler) { - this.compiler = compiler; - return this; - } - - public CompilationHarness build() { - return new CompilationHarness<>(sources, keys, compiler); - } - } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/Compile.java b/src/main/java/com/jozufozu/flywheel/backend/compile/Compile.java index 59200a0a8..46b7460f2 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/Compile.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/Compile.java @@ -44,15 +44,15 @@ public class Compile { return new ProgramLinkBuilder<>(); } - public CompilationHarness.Builder harness(ShaderSources sources) { - return new CompilationHarness.Builder<>(sources); - } - public static class ProgramLinkBuilder implements CompilationHarness.KeyCompiler { private final Map> compilers = new EnumMap<>(ShaderType.class); private BiConsumer onLink = (k, p) -> { }; + public CompilationHarness harness(ShaderSources sources) { + return new CompilationHarness<>(sources, this); + } + public ProgramLinkBuilder link(ShaderCompilerBuilder compilerBuilder) { if (compilers.containsKey(compilerBuilder.shaderType)) { throw new IllegalArgumentException("Duplicate shader type: " + compilerBuilder.shaderType); 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 29358404f..40e4daf44 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/IndirectPrograms.java @@ -17,7 +17,6 @@ import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.glsl.GlslVersion; import com.jozufozu.flywheel.backend.glsl.ShaderSources; import com.jozufozu.flywheel.backend.glsl.SourceComponent; -import com.jozufozu.flywheel.lib.util.Unit; import net.minecraft.resources.ResourceLocation; @@ -28,7 +27,7 @@ public class IndirectPrograms { public static IndirectPrograms instance; private static final Compile> CULL = new Compile<>(); - private static final Compile UNIT = new Compile<>(); + private static final Compile UTIL = new Compile<>(); private final Map pipeline; private final Map, GlProgram> culling; private final GlProgram apply; @@ -43,19 +42,17 @@ public class IndirectPrograms { static void reload(ShaderSources sources, ImmutableList pipelineKeys, UniformComponent uniformComponent, List vertexComponents, List fragmentComponents) { _delete(); - var pipelineCompiler = PipelineCompiler.create(sources, Pipelines.INDIRECT, pipelineKeys, uniformComponent, vertexComponents, fragmentComponents); + var pipelineCompiler = PipelineCompiler.create(sources, Pipelines.INDIRECT, uniformComponent, vertexComponents, fragmentComponents); var cullingCompiler = createCullingCompiler(uniformComponent, sources); - var applyCompiler = createApplyCompiler(sources); - var scatterCompiler = createScatterCompiler(sources); + var applyCompiler = createUtilCompiler(sources); try { - var pipelineResult = pipelineCompiler.compileAndReportErrors(); - var cullingResult = cullingCompiler.compileAndReportErrors(); - var applyResult = applyCompiler.compileAndReportErrors(); - var scatterResult = scatterCompiler.compileAndReportErrors(); + var pipelineResult = pipelineCompiler.compileAndReportErrors(pipelineKeys); + var cullingResult = cullingCompiler.compileAndReportErrors(createCullingKeys()); + var utils = applyCompiler.compileAndReportErrors(List.of(APPLY_SHADER_MAIN, SCATTER_SHADER_MAIN)); - if (pipelineResult != null && cullingResult != null && applyResult != null && scatterResult != null) { - instance = new IndirectPrograms(pipelineResult, cullingResult, applyResult.get(Unit.INSTANCE), scatterResult.get(Unit.INSTANCE)); + if (pipelineResult != null && cullingResult != null && utils != null) { + instance = new IndirectPrograms(pipelineResult, cullingResult, utils.get(APPLY_SHADER_MAIN), utils.get(SCATTER_SHADER_MAIN)); } } catch (Throwable e) { Flywheel.LOGGER.error("Failed to compile indirect programs", e); @@ -90,37 +87,23 @@ public class IndirectPrograms { } private static CompilationHarness> createCullingCompiler(UniformComponent uniformComponent, ShaderSources sources) { - return CULL.harness(sources) - .keys(createCullingKeys()) - .compiler(CULL.program() - .link(CULL.shader(GlslVersion.V460, ShaderType.COMPUTE) - .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) - .withComponent(uniformComponent) - .withComponent(IndirectComponent::create) - .withResource(InstanceType::cullShader) - .withResource(CULL_SHADER_MAIN)) - .then((key, program) -> program.setUniformBlockBinding("FlwUniforms", 0))) - .build(); + return CULL.program() + .link(CULL.shader(GlslVersion.V460, ShaderType.COMPUTE) + .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) + .withComponent(uniformComponent) + .withComponent(IndirectComponent::create) + .withResource(InstanceType::cullShader) + .withResource(CULL_SHADER_MAIN)) + .then((key, program) -> program.setUniformBlockBinding("FlwUniforms", 0)) + .harness(sources); } - private static CompilationHarness createApplyCompiler(ShaderSources sources) { - return UNIT.harness(sources) - .keys(ImmutableList.of(Unit.INSTANCE)) - .compiler(UNIT.program() - .link(UNIT.shader(GlslVersion.V460, ShaderType.COMPUTE) - .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) - .withResource(APPLY_SHADER_MAIN))) - .build(); - } - - private static CompilationHarness createScatterCompiler(ShaderSources sources) { - return UNIT.harness(sources) - .keys(ImmutableList.of(Unit.INSTANCE)) - .compiler(UNIT.program() - .link(UNIT.shader(GlslVersion.V460, ShaderType.COMPUTE) - .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) - .withResource(SCATTER_SHADER_MAIN))) - .build(); + private static CompilationHarness createUtilCompiler(ShaderSources sources) { + return UTIL.program() + .link(UTIL.shader(GlslVersion.V460, ShaderType.COMPUTE) + .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) + .withResource(s -> s)) + .harness(sources); } public GlProgram getIndirectProgram(InstanceType instanceType, Context contextShader) { 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 8f440cc17..333aaac4e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/InstancingPrograms.java @@ -24,10 +24,10 @@ public class InstancingPrograms { static void reload(ShaderSources sources, ImmutableList pipelineKeys, UniformComponent uniformComponent, List vertexComponents, List fragmentComponents) { _delete(); - var instancingCompiler = PipelineCompiler.create(sources, Pipelines.INSTANCED_ARRAYS, pipelineKeys, uniformComponent, vertexComponents, fragmentComponents); + var instancingCompiler = PipelineCompiler.create(sources, Pipelines.INSTANCED_ARRAYS, uniformComponent, vertexComponents, fragmentComponents); try { - var result = instancingCompiler.compileAndReportErrors(); + var result = instancingCompiler.compileAndReportErrors(pipelineKeys); if (result != null) { instance = new InstancingPrograms(result); 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 6236bed23..9d67f6575 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/PipelineCompiler.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.backend.compile; import java.util.List; -import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.backend.InternalVertex; import com.jozufozu.flywheel.backend.compile.component.UniformComponent; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; @@ -12,35 +11,33 @@ import com.jozufozu.flywheel.backend.glsl.SourceComponent; public class PipelineCompiler { private static final Compile PIPELINE = new Compile<>(); - static CompilationHarness create(ShaderSources sources, Pipeline pipeline, ImmutableList pipelineKeys, UniformComponent uniformComponent, List vertexComponents, List fragmentComponents) { - return PIPELINE.harness(sources) - .keys(pipelineKeys) - .compiler(PIPELINE.program() - .link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX) - .withComponent(uniformComponent) - .withResource(pipeline.vertexApiImpl()) - .withResource(InternalVertex.LAYOUT_SHADER) - .withComponent(key -> pipeline.assembler() - .assemble(new Pipeline.InstanceAssemblerContext(InternalVertex.ATTRIBUTE_COUNT, key.instanceType()))) - .withComponents(vertexComponents) - .withResource(key -> key.instanceType() - .vertexShader()) - .withResource(key -> key.contextShader() - .vertexShader()) - .withResource(pipeline.vertexMain())) - .link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.FRAGMENT) - .enableExtension("GL_ARB_conservative_depth") - .withComponent(uniformComponent) - .withResource(pipeline.fragmentApiImpl()) - .withComponents(fragmentComponents) - .withResource(key -> key.contextShader() - .fragmentShader()) - .withResource(pipeline.fragmentMain())) - .then((key, program) -> { - key.contextShader() - .onProgramLink(program); - program.setUniformBlockBinding("FlwUniforms", 0); - })) - .build(); + static CompilationHarness create(ShaderSources sources, Pipeline pipeline, UniformComponent uniformComponent, List vertexComponents, List fragmentComponents) { + return PIPELINE.program() + .link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.VERTEX) + .withComponent(uniformComponent) + .withResource(pipeline.vertexApiImpl()) + .withResource(InternalVertex.LAYOUT_SHADER) + .withComponent(key -> pipeline.assembler() + .assemble(new Pipeline.InstanceAssemblerContext(InternalVertex.ATTRIBUTE_COUNT, key.instanceType()))) + .withComponents(vertexComponents) + .withResource(key -> key.instanceType() + .vertexShader()) + .withResource(key -> key.contextShader() + .vertexShader()) + .withResource(pipeline.vertexMain())) + .link(PIPELINE.shader(pipeline.glslVersion(), ShaderType.FRAGMENT) + .enableExtension("GL_ARB_conservative_depth") + .withComponent(uniformComponent) + .withResource(pipeline.fragmentApiImpl()) + .withComponents(fragmentComponents) + .withResource(key -> key.contextShader() + .fragmentShader()) + .withResource(pipeline.fragmentMain())) + .then((key, program) -> { + key.contextShader() + .onProgramLink(program); + program.setUniformBlockBinding("FlwUniforms", 0); + }) + .harness(sources); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java index 464d48a23..8cc4b090a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/IndirectComponent.java @@ -113,7 +113,7 @@ public class IndirectComponent implements SourceComponent { // FIXME: I don't think we're unpacking signed byte/short values correctly // FIXME: we definitely don't consider endianness. this all assumes little endian which works on my machine. var type = element.type(); - var name = "_" + element.name(); + var name = element.name(); if (type instanceof ScalarElementType scalar) { return unpackScalar(name, packed, scalar); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractInstancer.java index c4d7b3e66..7ea5b263e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractInstancer.java @@ -150,9 +150,6 @@ public abstract class AbstractInstancer implements Instancer deleted.clear(); } - public void delete() { - } - @Override public String toString() { return "AbstractInstancer[" + getInstanceCount() + ']'; diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java b/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java index 085bab90a..99c2f1346 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/InstancerStorage.java @@ -20,25 +20,18 @@ public abstract class InstancerStorage> { *
* See {@link #getInstancer} for insertion details. */ - private final Map, N> instancers = new HashMap<>(); + protected final Map, N> instancers = new HashMap<>(); /** * A list of instancers that have not yet been initialized. *
* All new instancers land here before having resources allocated in {@link #flush}. * Write access to this list must be synchronized on {@link #creationLock}. */ - private final List> uninitializedInstancers = new ArrayList<>(); + protected final List> uninitializedInstancers = new ArrayList<>(); /** * Mutex for {@link #instancers} and {@link #uninitializedInstancers}. */ - private final Object creationLock = new Object(); - - /** - * A list of initialized instancers. - *
- * These are instancers that may need to be cleared or deleted. - */ - private final List initializedInstancers = new ArrayList<>(); + protected final Object creationLock = new Object(); @SuppressWarnings("unchecked") public Instancer getInstancer(InstanceType type, Model model, RenderStage stage) { @@ -69,21 +62,18 @@ public abstract class InstancerStorage> { public void delete() { instancers.clear(); uninitializedInstancers.clear(); - - initializedInstancers.forEach(AbstractInstancer::delete); - initializedInstancers.clear(); } public void flush() { for (var instancer : uninitializedInstancers) { add(instancer.key(), instancer.instancer(), instancer.model(), instancer.stage()); - initializedInstancers.add(instancer.instancer()); } uninitializedInstancers.clear(); } public void onRenderOriginChanged() { - initializedInstancers.forEach(AbstractInstancer::clear); + instancers.values() + .forEach(AbstractInstancer::clear); } protected abstract N create(InstanceType type); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java index be6f6e724..af2810ff9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedDrawManager.java @@ -40,6 +40,9 @@ public class InstancedDrawManager extends InstancerStorage } public void delete() { + instancers.values() + .forEach(InstancedInstancer::delete); + super.delete(); meshPool.delete(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedInstancer.java index d8f29bca1..ab9498400 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/instancing/InstancedInstancer.java @@ -119,7 +119,6 @@ public class InstancedInstancer extends AbstractInstancer vao.bindAttributes(1, startAttrib, instanceAttributes); } - @Override public void delete() { vbo.delete(); vbo = null; diff --git a/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutBuilderImpl.java b/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutBuilderImpl.java index 8ebfe6138..3f9a5049b 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutBuilderImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutBuilderImpl.java @@ -14,7 +14,6 @@ import com.jozufozu.flywheel.api.layout.Layout.Element; import com.jozufozu.flywheel.api.layout.LayoutBuilder; import com.jozufozu.flywheel.api.layout.ValueRepr; import com.jozufozu.flywheel.impl.layout.LayoutImpl.ElementImpl; -import com.jozufozu.flywheel.lib.math.MoreMath; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; @@ -126,9 +125,9 @@ public class LayoutBuilderImpl implements LayoutBuilder { } private LayoutBuilder element(String name, ElementType type) { - elements.add(new ElementImpl(name, type, offset, MoreMath.align4(type.byteSize()))); + elements.add(new ElementImpl(name, type, offset)); + // type.byteSize() is guaranteed to be 4-aligned. offset += type.byteSize(); - offset = MoreMath.align4(offset); return this; } diff --git a/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutImpl.java b/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutImpl.java index 86f85315c..d6f4f9b34 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/layout/LayoutImpl.java @@ -71,6 +71,6 @@ final class LayoutImpl implements Layout { return elements.equals(other.elements); } - record ElementImpl(String name, ElementType type, int offset, int byteSize) implements Element { + record ElementImpl(String name, ElementType type, int offset) implements Element { } } diff --git a/src/main/java/com/jozufozu/flywheel/impl/layout/MatrixElementTypeImpl.java b/src/main/java/com/jozufozu/flywheel/impl/layout/MatrixElementTypeImpl.java index d65491478..e293dbf77 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/layout/MatrixElementTypeImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/layout/MatrixElementTypeImpl.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Range; import com.jozufozu.flywheel.api.layout.FloatRepr; import com.jozufozu.flywheel.api.layout.MatrixElementType; +import com.jozufozu.flywheel.lib.math.MoreMath; record MatrixElementTypeImpl(FloatRepr repr, @Range(from = 2, to = 4) int rows, @Range(from = 2, to = 4) int columns, int byteSize) implements MatrixElementType { @@ -14,7 +15,7 @@ record MatrixElementTypeImpl(FloatRepr repr, @Range(from = 2, to = 4) int rows, if (columns < 2 || columns > 4) { throw new IllegalArgumentException("Matrix element column count must be in range [2, 4]!"); } - int byteSize = repr.byteSize() * rows * columns; + int byteSize = MoreMath.align4(repr.byteSize() * rows * columns); return new MatrixElementTypeImpl(repr, rows, columns, byteSize); } } diff --git a/src/main/java/com/jozufozu/flywheel/impl/layout/ScalarElementTypeImpl.java b/src/main/java/com/jozufozu/flywheel/impl/layout/ScalarElementTypeImpl.java index f2d9cfcf0..c2e901724 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/layout/ScalarElementTypeImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/layout/ScalarElementTypeImpl.java @@ -2,9 +2,10 @@ package com.jozufozu.flywheel.impl.layout; import com.jozufozu.flywheel.api.layout.ScalarElementType; import com.jozufozu.flywheel.api.layout.ValueRepr; +import com.jozufozu.flywheel.lib.math.MoreMath; record ScalarElementTypeImpl(ValueRepr repr, int byteSize) implements ScalarElementType { static ScalarElementTypeImpl create(ValueRepr repr) { - return new ScalarElementTypeImpl(repr, repr.byteSize()); + return new ScalarElementTypeImpl(repr, MoreMath.align4(repr.byteSize())); } } diff --git a/src/main/java/com/jozufozu/flywheel/impl/layout/VectorElementTypeImpl.java b/src/main/java/com/jozufozu/flywheel/impl/layout/VectorElementTypeImpl.java index cdb5712f7..70b1c67ca 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/layout/VectorElementTypeImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/layout/VectorElementTypeImpl.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Range; import com.jozufozu.flywheel.api.layout.ValueRepr; import com.jozufozu.flywheel.api.layout.VectorElementType; +import com.jozufozu.flywheel.lib.math.MoreMath; record VectorElementTypeImpl(ValueRepr repr, @Range(from = 2, to = 4) int size, int byteSize) implements VectorElementType { @@ -13,7 +14,7 @@ record VectorElementTypeImpl(ValueRepr repr, @Range(from = 2, to = 4) int size, throw new IllegalArgumentException("Vector element size must be in range [2, 4]!"); } - int byteSize = repr.byteSize() * size; + int byteSize = MoreMath.align4(repr.byteSize() * size); return new VectorElementTypeImpl(repr, size, byteSize); } } diff --git a/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java b/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java index e6b382a4f..220c1f2ea 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java +++ b/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java @@ -9,12 +9,12 @@ public final class MoreMath { */ public static final float SQRT_3_OVER_2 = (float) (Math.sqrt(3.0) / 2.0); - public static int align16(int numToRound) { - return (numToRound + 15) & ~15; + public static int align16(int size) { + return (size + 15) & ~15; } - public static int align4(int offset1) { - return (offset1 + 3) & ~3; + public static int align4(int size) { + return (size + 3) & ~3; } public static int ceilingDiv(int numerator, int denominator) {