From 06454a713f366f75089d3427eb13443c1f31a922 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Tue, 16 Aug 2022 10:41:35 -0700 Subject: [PATCH] Lazily instantiate DrawBuffers - Iris/Oculus create wrapper RenderTypes whose DrawBuffers are never used. Creating the DrawBuffer on retrieval solves this inefficiency. - Add 1.18.2 as a Minecraft version to the issue template --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + .../com/jozufozu/flywheel/backend/instancing/DrawBuffer.java | 3 +++ .../java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 9e92efbb5..ccdb88cfd 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -90,6 +90,7 @@ body: label: Minecraft Version description: The version of Minecraft you were using when the bug occured options: + - "1.18.2" - "1.18.1" - "1.18" - "1.17.1" diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java index 2725674db..f9c6ab051 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java @@ -2,6 +2,8 @@ package com.jozufozu.flywheel.backend.instancing; import java.nio.ByteBuffer; +import org.jetbrains.annotations.ApiStatus; + import com.jozufozu.flywheel.backend.model.BufferBuilderExtension; import com.jozufozu.flywheel.backend.model.DirectVertexConsumer; import com.mojang.blaze3d.platform.MemoryTracker; @@ -20,6 +22,7 @@ public class DrawBuffer { private ByteBuffer backingBuffer; private int expectedVertices; + @ApiStatus.Internal public DrawBuffer(RenderType parent) { this.parent = parent; } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java index c3a3d7b5d..d31b71899 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderTypeMixin.java @@ -14,11 +14,14 @@ import net.minecraft.client.renderer.RenderType; public class RenderTypeMixin implements RenderTypeExtension { @Unique - private final DrawBuffer flywheel$drawBuffer = new DrawBuffer((RenderType) (Object) this); + private DrawBuffer flywheel$drawBuffer; @Override @Nonnull public DrawBuffer flywheel$getDrawBuffer() { + if (flywheel$drawBuffer == null) { + flywheel$drawBuffer = new DrawBuffer((RenderType) (Object) this); + } return flywheel$drawBuffer; } }