diff --git a/mod/docs/optimize-layer-design.md b/mod/docs/optimize-layer-design.md
index 735715aa..dea968df 100644
--- a/mod/docs/optimize-layer-design.md
+++ b/mod/docs/optimize-layer-design.md
@@ -1,11 +1,6 @@
# Слой оптимизации (Optimize): перенос референсных оптимизаций, улучшения и Vulkan
-Статус: Этап 1 готов (2026-10-10), Этап 2 + начало Этапа 3 готовы (2026-10-10). Цель MC: 26.2.
-
-## История изменений
-- **2026-10-10**: Этап 1 завершён — 11 портированных файлов (`core/LruMap`, `entity/{EntityLod,CachedName,StateEntity,CachedStack}`, `particle/{ParticleLod,Workers}`, `hud/HudWorth`, `block/{TickCached,CachedLight,CachedValidity,SpawnerCache}`, `text/StableText`) + `OptimizeToggles` + `mod/NOTICE`. 53 теста. Патчи: `0001-feat-mod-...patch`, `0002-test-mod-...patch`.
-- **2026-10-10**: Этап 2 завершён — `FrameBudget` (mode + target FPS + per-subsystem caps), `FrameProfiler` (5 секций EMA-таймингов), `OptimizePropertyBridge` (`-Dlovisual.opt.*` overrides), `OptimizeDebugHudMixin` (F3 overlay). 22 новых теста. `Optimize.java` расширен тумблерами `budget_mode` / `target_fps` / `show_profiler`.
-- **2026-10-10**: Этап 3 (частично) — `RenderBackendOps` интерфейс + `GlRenderBackendOps` реализация (lazy clear, TBO cache, RenderTypes cache). Три mixin'а зарегистрированы в `lovisual.mixins.json`: `RenderTypesMixin`, `GlCommandEncoderClearMixin`, `GlCommandEncoderTexBufferMixin`. SkinAtlas/AnimFreeze/HudCache/FrameFence оставлены на поздний Этап 3.
+Статус: черновик на согласование (2026-10-09). Цель MC: 26.2.
## Решение
Все оптимизации из референса (слои `common`, `26.x`, `26.2`) переносятся в наш модуль `Optimize`, а не живут отдельным
@@ -111,15 +106,11 @@ optimize/
Существующие Vulkan-миксины LoVisual (`VulkanDeviceMixin` и др.) не переписываем, новый код подключается рядом.
## Этапы
-1. ✅ `core/` + helpers + adapter interfaces + `OptimizeToggles` (бэкенд-независимые части). Тесты, сборка. **Завершён 2026-10-10** — 11 портированных .java, 53 теста, 0 падений, `checkFolderLimit` OK.
-2. ✅ Бюджет кадра, профилировщик, `-Dlovisual.opt.*`. **Завершён 2026-10-10** — `FrameBudget` (3 режима: OFF/SOFT/AGGRESSIVE, target FPS, per-subsystem caps для entities/particles/HUD/effects/text/trails), `FrameProfiler` (5 секций, EMA, decay через 2 с idle), `OptimizePropertyBridge` (10 системных свойств + `all=false` отключает всё), `OptimizeDebugHudMixin` (F3 overlay показывает тумблеры + бюджет + тайминги секций + override'ы). 22 новых теста.
-3. 🔄 `gl/`: shared FBO, FrameFence, lazy clear, TBO cache, SkinAtlas через GL; затем новые GL-идеи из раздела ниже. **Частично готово 2026-10-10**: `RenderBackendOps` интерфейс (GL/Vulkan стратегия), `GlRenderBackendOps` реализация, 3 mixin'а (`RenderTypesMixin`, `GlCommandEncoderClearMixin`, `GlCommandEncoderTexBufferMixin`), зарегистрированы в `lovisual.mixins.json`. **Осталось**: FrameFence/RealFence (shared GPU fence на кадр), SharedDepthFbos (DSA depth clear через cached FBO), SkinAtlas (glCopyImageSubData), AnimFreeze, ItemLod, LivingEntityLodMixin, ParticleMixin, SpawnerRendererMixin, BubbleColumnUpParticleMixin, VertexConsumerUtilsMixin, SodiumEntityRendererMixin, BlockEntity* mixins, HUD cache mixins, LevelRendererOutlineMixin, MinecraftFrameMixin.
-4. ❌ `vulkan/`: `vkCmdCopyImage`, затем `VkPipelineCache`, затем остальное по замерам. **Не начат** — дизайн готов, ждёт профилирования GL-части чтобы понять, какие из Vulkan-оптимизаций реально нужны.
-5. ❌ Бенчмарки до и после, отчёт цифр в этот документ. **Не начат** — требует запуска Minecraft на Windows, задача владельца.
-
-## Оценки для Этапов 3-4 (после Stage 1-2)
-- **Этап 3 (остальное)**: ~25 mixin'ов + ~8 helper-классов, ~80-100 новых .java-файлов. Сложные: `AnimFreeze` (vertex format + MemoryUtil), `SkinAtlas` (glCopyImageSubData + LRU), `HudCache` (RenderPipeline + RenderPass + TextureTarget). Безопасные простые: `LevelRendererOutlineMixin`, `BubbleColumnUpParticleMixin`, `SodiumEntityRendererMixin`. ~3-4 рабочих сессии.
-- **Этап 4**: 6 пунктов, каждый требует профилирования. Минимум 1 сессия на `vkCmdCopyImage` (чтобы SkinAtlas заработал на Vulkan), остальное по мере замеров.
+1. `core/` + `RenderBackendOps` + порт сущностей, частиц, HUD, текста, блоков (бэкенд-независимые части). Тесты, сборка.
+2. Бюджет кадра, профилировщик, `-Dlovisual.opt.*`.
+3. `gl/`: shared FBO, FrameFence, lazy clear, TBO cache, SkinAtlas через GL; затем новые GL-идеи из раздела ниже.
+4. `vulkan/`: `vkCmdCopyImage`, затем `VkPipelineCache`, затем остальное по замерам.
+5. Бенчмарки до и после, отчёт цифр в этот документ.
## Риски
- Миксины 26.2 проверяются только компиляцией и запуском владельцем (`./gradlew runClient`), вживую я не смотрю.
diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/Optimize.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/Optimize.java
index 1892d673..05203522 100644
--- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/Optimize.java
+++ b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/Optimize.java
@@ -1,14 +1,11 @@
package dev.loki.lovisual.features.module.modules.misc.optimize;
-import dev.loki.lovisual.config.values.mode.EnumValue;
import dev.loki.lovisual.config.values.primitive.BooleanValue;
import dev.loki.lovisual.config.values.primitive.NumberValue;
import dev.loki.lovisual.features.module.core.Module;
import dev.loki.lovisual.features.module.core.ModuleCategory;
import dev.loki.lovisual.features.module.core.ModuleInfo;
import dev.loki.lovisual.features.module.phase.Notifier;
-import dev.loki.lovisual.render.engine.optimize.profile.FrameBudget;
-import dev.loki.lovisual.render.engine.optimize.profile.OptimizePropertyBridge;
import dev.loki.lovisual.render.engine.optimize.OptimizeState;
import dev.loki.lovisual.render.engine.optimize.OptimizeToggles;
@@ -19,18 +16,17 @@ import dev.loki.lovisual.render.engine.optimize.OptimizeToggles;
* particle LOD, spawner tick-cache, etc.).
*
*
No auto-degradation by FPS — the owner's rule. Render code reads
- * {@link OptimizeState} (the original cuts), {@link OptimizeToggles} (the
- * Stage 1 transparent helpers), {@link FrameBudget} (Stage 2 frame budget)
- * — never this class; this module only pushes state into them on
- * enable/disable and once per frame.
+ * {@link OptimizeState} (the original cuts) and {@link OptimizeToggles} (the
+ * new transparent helpers), never this class; this module only pushes
+ * state into them on enable/disable and once per frame.
*
- *
Stage 2 of {@code mod/docs/optimize-layer-design.md}: the module now also
- * pushes a {@link FrameBudget} snapshot (mode + target FPS) and resolves
- * {@code -Dlovisual.opt.*} system-property overrides via
- * {@link OptimizePropertyBridge}. The frame profiler ({@code FrameProfiler})
- * is fed by the {@code MinecraftFrameMixin} (Stage 3 — not yet present); the
- * F3 overlay ({@code OptimizeDebugHudMixin}) reads the profiler's snapshot
- * whenever the user opens F3.
+ *
Stage 1 of {@code mod/docs/optimize-layer-design.md}: the toggles below
+ * wire the engine-side state holders up; the actual hooks (mixins on
+ * {@code LivingEntityRenderer}, {@code ParticleGroup}, {@code SpawnerRenderer},
+ * {@code BlockEntity}, {@code ClientLanguage}, etc.) are added in Stage 3
+ * alongside the GL path. The helpers themselves (LRU, LOD math, workers, HUD
+ * hysteresis) are already in place under
+ * {@code features/module/modules/misc/optimize/{core,entity,particle,hud,block,text}/}.
*/
@ModuleInfo(
id = "optimize",
@@ -58,14 +54,6 @@ public final class Optimize extends Module {
private final BooleanValue preparedTextCache = bool("prepared_text_cache", true);
private final BooleanValue microOpts = bool("micro_opts", true);
- // --- Stage 2: frame budget + profiling ---
- private final EnumValue budgetMode =
- enumMode("budget_mode", FrameBudget.Mode.OFF, FrameBudget.Mode.values());
- private final NumberValue targetFps =
- num("target_fps", FrameBudget.DEFAULT_TARGET_FPS, 15, 360);
- private final BooleanValue showProfiler =
- bool("show_profiler", false);
-
private boolean notified;
@Override
@@ -83,7 +71,6 @@ public final class Optimize extends Module {
public void onDisable() {
OptimizeState.reset();
OptimizeToggles.reset();
- FrameBudget.reset();
}
/** Picks up knob changes made while the module stays on. */
@@ -94,41 +81,21 @@ public final class Optimize extends Module {
private void pushState() {
boolean on = isEnabled();
- // Original four "rubilnik" cuts.
OptimizeState.apply(
on && noGlass.get(),
on && litePost.get(),
on && liteSky.get(),
on && leanHud.get());
-
- // Stage 1 toggles — wire through the -Dlovisual.opt.* overrides.
- OptimizePropertyBridge.Snapshot props = OptimizePropertyBridge.resolve();
OptimizeToggles.apply(
- resolveBool(props, props.entityLod, on && entityLod.get()),
- resolveInt(props, props.entityLodDistance, entityLodDistance.get()),
- resolveBool(props, props.particleLod, on && particleLod.get()),
- resolveBool(props, props.particleLod, on && particleLod.get()),
- resolveBool(props, props.particleLod, on && particleLod.get()),
- resolveBool(props, props.spawnerCull, on && spawnerCull.get()),
- resolveInt(props, props.spawnerDistance, spawnerDistance.get()),
- resolveBool(props, props.spawnerTickCache, on && spawnerTickCache.get()),
- resolveBool(props, props.blockEntityCache, on && blockEntityCache.get()),
- resolveBool(props, props.preparedTextCache, on && preparedTextCache.get()),
- resolveBool(props, props.microOpts, on && microOpts.get()));
-
- // Stage 2: frame budget. -Dlovisual.opt.budget_mode / target_fps override the module.
- FrameBudget.Mode mode = on ? budgetMode.get() : FrameBudget.Mode.OFF;
- FrameBudget.apply(props.overrides(mode, mode), props.resolveTargetFps(targetFps.get()));
- }
-
- private static boolean resolveBool(OptimizePropertyBridge.Snapshot props,
- Boolean override, boolean moduleValue) {
- return props.overrides(override, moduleValue);
- }
-
- private static int resolveInt(OptimizePropertyBridge.Snapshot props,
- int override, int moduleValue) {
- return props.overrides(override, moduleValue);
+ on && entityLod.get(), entityLodDistance.get(),
+ on && particleLod.get(),
+ on && particleLod.get(), // particleLight: same gate in Stage 1
+ on && particleLod.get(), // particlePhysics: same gate in Stage 1
+ on && spawnerCull.get(), spawnerDistance.get(),
+ on && spawnerTickCache.get(),
+ on && blockEntityCache.get(),
+ on && preparedTextCache.get(),
+ on && microOpts.get());
}
/** Compact list of what is being cut, for the first-enable notice. */
diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/gl/GlRenderBackendOps.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/gl/GlRenderBackendOps.java
deleted file mode 100644
index 63f558ff..00000000
--- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/gl/GlRenderBackendOps.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package dev.loki.lovisual.features.module.modules.misc.optimize.gl;
-
-import dev.loki.lovisual.render.engine.optimize.OptimizeToggles;
-import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * GL backend implementation of {@link RenderBackendOps}.
- *
- *
Resolves the current GL device via {@code GlBackendAccess.current()} —
- * returns {@code null} on Vulkan so all mixins short-circuit to the vanilla
- * call. The cache state is static and render-thread-only (ZakoOpt does the
- * same — the GL command encoder runs single-threaded).
- *
- *
Ported from ZakoOpt's three GL caches:
- *
- *
{@code zako.opt.mixin.gl.GlCommandEncoderClearMixin} (lazy clear) — wrapped in {@link #skipBindFramebufferZero(int)}.
- *
{@code zako.opt.gl.TexBufferCache} + {@code zako.opt.mixin.gl.GlCommandEncoderTexBufferMixin} — wrapped in the TBO-cache methods.
- *
{@code zako.opt.mixin.gl.RenderTypesMixin} — wrapped in the RenderTypes-cache methods.
- *
- *
- *
Each toggle is gated by {@link OptimizeToggles#microOpts()} (the Stage 1
- * "micro_opts" toggle wired into {@code Optimize.java}); ZakoOpt splits this
- * into {@code lookupCaches}, {@code microOpts}, {@code tboCache} — Stage 1
- * collapses them, Stage 2 may split if profiling warrants.
- */
-public final class GlRenderBackendOps implements RenderBackendOps {
-
- private static final GlRenderBackendOps INSTANCE = new GlRenderBackendOps();
-
- // --- TBO cache (ported from zako.opt.gl.TexBufferCache) ---
- /** Maps bound-texture-id -> packed (format << 32) | (buffer & 0xFFFFFFFFL). -1 = nothing attached. */
- private final Int2LongOpenHashMap tboAttached = new Int2LongOpenHashMap();
- private int boundTboTexture;
-
- // --- RenderTypes cache (ported from zako.opt.mixin.gl.RenderTypesMixin) ---
- private final Map translucentCache = new ConcurrentHashMap<>();
-
- private GlRenderBackendOps() {
- tboAttached.defaultReturnValue(-1L);
- }
-
- /**
- * @return the singleton GL backend instance, or {@code null} if the
- * current device is not GL (e.g. Vulkan backend active).
- */
- public static RenderBackendOps current() {
- // Stage 3-prep: we don't yet wire the GL device check (would require
- // the GL device accessor mixin). Return INSTANCE unconditionally for
- // now; the actual device-type check is added alongside the first GL
- // mixin that needs it (RenderTypesMixin — Stage 3b).
- return INSTANCE;
- }
-
- // --- Lazy clear ---
-
- @Override
- public boolean lazyClearSupported() {
- return OptimizeToggles.microOpts();
- }
-
- @Override
- public boolean skipBindFramebufferZero(int framebuffer) {
- if (!lazyClearSupported()) return false;
- return framebuffer == 0;
- }
-
- // --- TBO cache ---
-
- @Override
- public boolean tboCacheSupported() {
- return OptimizeToggles.microOpts();
- }
-
- @Override
- public void trackBoundTboTexture(int texture) {
- boundTboTexture = texture;
- }
-
- @Override
- public boolean tboAlreadyAttached(int format, int buffer) {
- if (!tboCacheSupported()) return false;
- return tboAttached.getOrDefault(boundTboTexture, -1L) == packTboKey(format, buffer);
- }
-
- @Override
- public void markTboAttached(int format, int buffer) {
- if (!tboCacheSupported()) return;
- tboAttached.put(boundTboTexture, packTboKey(format, buffer));
- }
-
- @Override
- public void forgetTboCache() {
- tboAttached.clear();
- }
-
- private static long packTboKey(int format, int buffer) {
- return ((long) format << 32) | (buffer & 0xFFFFFFFFL);
- }
-
- // --- RenderTypes cache ---
-
- @Override
- public boolean renderTypesCacheSupported() {
- return OptimizeToggles.microOpts();
- }
-
- @Override
- public Object renderTypeFor(Identifier id) {
- if (!renderTypesCacheSupported()) return null;
- return translucentCache.get(id);
- }
-
- @Override
- public void cacheRenderType(Identifier id, Object type) {
- if (!renderTypesCacheSupported()) return;
- translucentCache.put(id, type);
- }
-
- // --- Test helpers ---
-
- /** Test-only: clear all caches. */
- static void resetForTesting() {
- INSTANCE.tboAttached.clear();
- INSTANCE.boundTboTexture = 0;
- INSTANCE.translucentCache.clear();
- }
-
- /** Test-only: peek the bound TBO texture. */
- static int boundTboTextureForTesting() {
- return INSTANCE.boundTboTexture;
- }
-
- /** Test-only: count of cached render types. */
- static int cachedRenderTypeCountForTesting() {
- return INSTANCE.translucentCache.size();
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/gl/RenderBackendOps.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/gl/RenderBackendOps.java
deleted file mode 100644
index b0a2c59b..00000000
--- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/gl/RenderBackendOps.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package dev.loki.lovisual.features.module.modules.misc.optimize.gl;
-
-/**
- * Backend-agnostic surface for the optimization layer's GL/Vulkan hooks.
- *
- *
Stage 3 of {@code mod/docs/optimize-layer-design.md} splits the engine
- * into "what to do" (this interface) and "how to do it on this backend"
- * ({@link GlRenderBackendOps} for OpenGL, a future {@code VulkanRenderBackendOps}
- * for Vulkan). The Optimize mixins call {@link #current()} once and dispatch
- * through this surface; the Vulkan implementation returns {@code false} from
- * every {@code supported*} method so the mixin's {@code WrapOperation} falls
- * through to the original call.
- *
- *
Stage 4 will add Vulkan-specific paths ({@code vkCmdCopyImage},
- * {@code VkPipelineCache}) by implementing this surface with a no-op strategy
- * for the GL-only methods.
- */
-public interface RenderBackendOps {
-
- /** Resolve the current backend — GL backend if GL is active, otherwise {@code null}. */
- static RenderBackendOps current() {
- return GlRenderBackendOps.current();
- }
-
- // --- Lazy clear ---
-
- /** True when this backend can skip the redundant bind-framebuffer-0 after a clear. */
- boolean lazyClearSupported();
-
- /**
- * Called from {@code GlCommandEncoder.clearColorAndDepthTextures} on the
- * {@code GlStateManager._glBindFramebuffer(target, framebuffer)} call.
- *
- * @param framebuffer the framebuffer GlStateManager is about to bind
- * @return {@code true} to skip the bind (lazy clear — next pass binds its
- * own target anyway, the GlStateManager cache skips redundant binds)
- */
- boolean skipBindFramebufferZero(int framebuffer);
-
- // --- TBO cache ---
-
- /** True when this backend can cache {@code glTexBuffer} attachments per-texture. */
- boolean tboCacheSupported();
-
- /** Track the most recent {@code glBindTexture} target's texture ID. */
- void trackBoundTboTexture(int texture);
-
- /** True when the {@code (format, buffer)} pair is already attached to the bound texture. */
- boolean tboAlreadyAttached(int format, int buffer);
-
- /** Mark the {@code (format, buffer)} pair as attached to the bound texture. */
- void markTboAttached(int format, int buffer);
-
- /** Forget all TBO attachments — called when a {@code GlBuffer.Direct} is closed. */
- void forgetTboCache();
-
- // --- RenderTypes cache ---
-
- /** True when this backend can cache {@code RenderTypes.entityTranslucent(id, flag=true)}. */
- boolean renderTypesCacheSupported();
-
- /**
- * Look up a cached render type for the given identifier.
- *
- * @param id the texture identifier
- * @return the cached render type, or {@code null} if not cached
- */
- Object renderTypeFor(Identifier id);
-
- /**
- * Cache a render type for the given identifier.
- *
- * @param id the texture identifier
- * @param type the render type returned by the original lookup
- */
- void cacheRenderType(Identifier id, Object type);
-
- /** Tiny value-class carrying a texture identifier — kept out of the public API of {@link RenderBackendOps}. */
- final class Identifier {
- private final String namespace;
- private final String path;
-
- public Identifier(String namespace, String path) {
- this.namespace = namespace;
- this.path = path;
- }
-
- public String namespace() { return namespace; }
- public String path() { return path; }
-
- @Override
- public int hashCode() {
- return namespace.hashCode() * 31 + path.hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- return o instanceof Identifier i
- && i.namespace.equals(namespace)
- && i.path.equals(path);
- }
-
- @Override
- public String toString() {
- return namespace + ":" + path;
- }
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/BubbleColumnCache.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/BubbleColumnCache.java
deleted file mode 100644
index 25a33993..00000000
--- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/BubbleColumnCache.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package dev.loki.lovisual.features.module.modules.misc.optimize.particle;
-
-import dev.loki.lovisual.render.engine.optimize.OptimizeToggles;
-import net.minecraft.world.level.material.FluidState;
-
-/**
- * Per-tick cache of {@code ClientLevel.getFluidState(pos)} results for
- * {@code BubbleColumnUpParticle.tick}. Thousands of bubble particles share a
- * few columns; each one re-checks its block's fluid every tick, which is a
- * chunk-section lookup per call. This cache is keyed by {@code BlockPos.asLong()}
- * and cleared once per tick (game-time change), so it never serves stale data
- * across ticks.
- *
- *
Render-thread only (vanilla particle ticking is single-threaded). The
- * cache is static because {@code BubbleColumnUpParticle} instances are created
- * and destroyed constantly — per-particle state would be re-initialized too
- * often to be useful.
- *
- *
Ported from {@code zako.opt.mixin.particle.BubbleColumnUpParticleMixin}
- * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako.
- * The cache logic is in {@link TickCache} (a generic per-tick keyed cache),
- * so it's unit-testable without Minecraft types.
- */
-public enum BubbleColumnCache {
- ;
-
- private static final TickCache CACHE = new TickCache<>();
-
- /** True when the cache is engaged this frame. */
- public static boolean enabled() {
- return OptimizeToggles.microOpts();
- }
-
- /** Look up a cached fluid state for the given block-pos key + tick. */
- public static FluidState get(long posLong, long tick) {
- return CACHE.get(posLong, tick);
- }
-
- /** Store a fluid state for the given block-pos key. */
- public static void put(long posLong, FluidState fluid) {
- CACHE.put(posLong, fluid);
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/TickCache.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/TickCache.java
deleted file mode 100644
index 3280a355..00000000
--- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/TickCache.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package dev.loki.lovisual.features.module.modules.misc.optimize.particle;
-
-import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
-
-/**
- * Generic per-tick cache keyed by {@code long}. The cache is cleared once per
- * tick change (game-time change), so it never serves stale data across ticks.
- *
- *
Used by {@link BubbleColumnCache} for {@code ClientLevel.getFluidState}
- * results — thousands of bubble particles share a few columns; each one
- * re-checks its block's fluid every tick. Generic on the value type so the
- * logic is unit-testable without Minecraft types.
- *
- *
Render-thread only. The cache is static because particle instances are
- * created and destroyed constantly — per-particle state would be re-initialized
- * too often to be useful.
- *
- *
Ported from {@code zako.opt.mixin.particle.BubbleColumnUpParticleMixin}
- * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako.
- */
-public final class TickCache {
-
- private final Long2ObjectOpenHashMap map = new Long2ObjectOpenHashMap<>();
- private long cachedTick = Long.MIN_VALUE;
-
- /**
- * Look up a cached value for the given key, on the given tick. If the tick
- * differs from the cached tick, the cache is cleared first.
- *
- * @param key the packed position key (e.g. {@code BlockPos.asLong()})
- * @param tick the current game tick
- * @return the cached value, or {@code null} if not cached
- */
- public V get(long key, long tick) {
- if (tick != cachedTick) {
- map.clear();
- cachedTick = tick;
- }
- return map.get(key);
- }
-
- /**
- * Store a value for the given key, on the current tick. The cache must
- * have been primed by a {@link #get} call first — that's where the tick
- * check happens; this method assumes the cache is fresh.
- */
- public void put(long key, V value) {
- map.put(key, value);
- }
-
- /** Number of cached entries on the current tick. */
- public int size() {
- return map.size();
- }
-
- /** The tick the cache currently holds data for. */
- public long cachedTick() {
- return cachedTick;
- }
-
- /** Reset the cache to empty (used by tests and on disable). */
- public void reset() {
- map.clear();
- cachedTick = Long.MIN_VALUE;
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/world/OutlineTracker.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/world/OutlineTracker.java
deleted file mode 100644
index 22c36a0d..00000000
--- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/world/OutlineTracker.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package dev.loki.lovisual.features.module.modules.misc.optimize.world;
-
-import dev.loki.lovisual.render.engine.optimize.OptimizeToggles;
-
-/**
- * Per-frame state for the entity-outline skip optimization. The vanilla
- * pipeline clears the entity-outline target and runs {@code doEntityOutline}
- * every frame even when no glowing entity is on screen. This tracker flips
- * to {@code false} when the most recent frame had at least one glowing
- * entity, and the {@code LevelRendererOutlineMixin} reads it to skip the
- * clear + outline render on frames with no glowing entity.
- *
- *
Render-thread only. The state is reset at the start of every frame
- * ({@link #beginFrame()}), and {@link #markGlowing()} is called from the
- * outline-target-clear {@code WrapOperation} when the renderer actually
- * touches the outline target.
- *
- *
Ported from {@code zako.opt.mixin.entity.LevelRendererOutlineMixin}
- * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako.
- * The state is lifted out of the mixin so the mixin stays a thin wrapper.
- */
-public enum OutlineTracker {
- ;
-
- private static volatile boolean glowingThisFrame;
- private static volatile boolean dirty = true;
-
- /** True when the outline skip is engaged this frame. */
- public static boolean enabled() {
- return OptimizeToggles.microOpts();
- }
-
- /** Called at the start of every frame — clears the per-frame glowing flag. */
- public static void beginFrame() {
- glowingThisFrame = false;
- }
-
- /** Called when the renderer touches the outline target this frame. */
- public static void markGlowing() {
- glowingThisFrame = true;
- dirty = true;
- }
-
- /** True when at least one glowing entity was rendered this frame. */
- public static boolean glowingThisFrame() {
- return glowingThisFrame;
- }
-
- /** True when the outline target needs a clear this frame (first dirty frame after a glowing one). */
- public static boolean needsClear() {
- if (dirty) return true;
- return glowingThisFrame;
- }
-
- /** Called after the clear completes — the target is no longer dirty until the next glowing frame. */
- public static void markCleared() {
- dirty = false;
- }
-
- /** True when {@code doEntityOutline} should be skipped this frame. */
- public static boolean shouldSkipOutlineRender() {
- if (!enabled()) return false;
- return !glowingThisFrame;
- }
-
- /** Test-only: reset all state. */
- static void reset() {
- glowingThisFrame = false;
- dirty = true;
- }
-
- /** Test-only: peek the glowing flag. */
- static boolean glowingThisFrameRaw() {
- return glowingThisFrame;
- }
-
- /** Test-only: peek the dirty flag. */
- static boolean dirtyRaw() {
- return dirty;
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/LivingEntityLodMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/LivingEntityLodMixin.java
deleted file mode 100644
index 9c2de03d..00000000
--- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/LivingEntityLodMixin.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package dev.loki.lovisual.mixins.optimize.entity;
-
-import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
-import dev.loki.lovisual.features.module.modules.misc.optimize.entity.EntityLod;
-import net.minecraft.client.renderer.entity.LivingEntityRenderer;
-import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-
-/**
- * Stage 3: skip {@code shouldRenderLayers(state)} for far living entities —
- * the entity's armour, held items, eyes, cape, elytra, and stuck arrows are
- * all submitted by {@code renderLayers}, and they're invisible past the
- * configured LOD distance. Returning {@code false} short-circuits the whole
- * layer pass for that entity.
- *
- *
The vanilla {@code shouldRenderLayers} returns true for every visible
- * entity; we AND it with "not far" so far entities skip the layers but
- * close entities render them as usual.
- *
- *
Ported from {@code zako.opt.mixin.entity.LivingEntityLodMixin} (ZakoOpt,
- * LGPL-3.0). Original author: Zako — https://t.me/StarikZako.
- *
- *
Gated on the {@code entity_lod} toggle via {@link EntityLod#far(double)}.
- * When the toggle is off, {@code far} returns {@code false} so the modify
- * leaves the original value unchanged.
- */
-@Mixin(LivingEntityRenderer.class)
-public abstract class LivingEntityLodMixin {
-
- @ModifyExpressionValue(
- method = "submit",
- at = @At(value = "INVOKE",
- target = "Lnet/minecraft/client/renderer/entity/LivingEntityRenderer;shouldRenderLayers(Lnet/minecraft/client/renderer/entity/state/LivingEntityRenderState;)Z")
- )
- private boolean lovisual$skipFarLayers(boolean original, LivingEntityRenderState state) {
- if (!original) {
- return false;
- }
- // Stage 1 collapses player LOD into entity LOD — same toggle, same threshold.
- return !EntityLod.far(state.distanceToCameraSq);
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/GlCommandEncoderClearMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/GlCommandEncoderClearMixin.java
deleted file mode 100644
index 22ed2415..00000000
--- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/GlCommandEncoderClearMixin.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package dev.loki.lovisual.mixins.optimize.gl;
-
-import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
-import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
-import com.mojang.blaze3d.opengl.GlStateManager;
-import dev.loki.lovisual.features.module.modules.misc.optimize.gl.RenderBackendOps;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-
-/**
- * Stage 3c: lazy clear — after {@code clearColorAndDepthTextures}, vanilla
- * binds framebuffer 0 (the default framebuffer) before the next pass runs.
- * The next pass binds its own target anyway, and {@code GlStateManager}'s
- * cache skips the redundant bind. This mixin drops the explicit bind-0 so
- * we don't pay for a {@code glBindFramebuffer(GL_FRAMEBUFFER, 0)} that's
- * immediately overwritten.
- *
- *
Ported from {@code zako.opt.mixin.gl.GlCommandEncoderClearMixin} (ZakoOpt,
- * LGPL-3.0). Original author: Zako — https://t.me/StarikZako.
- *
- *
Gated on the {@code microOpts} toggle via {@link RenderBackendOps#skipBindFramebufferZero(int)}.
- * When the toggle is off, the original call runs unchanged.
- */
-@Mixin(targets = "com.mojang.blaze3d.opengl.GlCommandEncoder")
-public abstract class GlCommandEncoderClearMixin {
-
- @WrapOperation(
- method = "clearColorAndDepthTextures",
- at = @At(value = "INVOKE",
- target = "Lcom/mojang/blaze3d/opengl/GlStateManager;_glBindFramebuffer(II)V")
- )
- private void lovisual$skipBindZero(int target, int framebuffer, Operation original) {
- RenderBackendOps backend = RenderBackendOps.current();
- if (backend != null && backend.skipBindFramebufferZero(framebuffer)) {
- // Skip the bind — the next render pass binds its own target anyway.
- return;
- }
- original.call(target, framebuffer);
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/GlCommandEncoderTexBufferMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/GlCommandEncoderTexBufferMixin.java
deleted file mode 100644
index a6dfe7ee..00000000
--- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/GlCommandEncoderTexBufferMixin.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package dev.loki.lovisual.mixins.optimize.gl;
-
-import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
-import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
-import dev.loki.lovisual.features.module.modules.misc.optimize.gl.RenderBackendOps;
-import org.lwjgl.opengl.GL33C;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-
-/**
- * Stage 3d: TBO cache — when {@code GlCommandEncoder.trySetup} binds a
- * texel-buffer texture via {@code glBindTexture}, we record the texture ID.
- * When {@code glTexBuffer(target, format, buffer)} is called for the same
- * {@code (format, buffer)} pair that's already attached, we skip the call —
- * re-attaching makes the driver revalidate the texture (clouds: ~2% of a
- * frame in {@code glDrawElements}).
- *
- *
Ported from {@code zako.opt.mixin.gl.GlCommandEncoderTexBufferMixin} (ZakoOpt,
- * LGPL-3.0). Original author: Zako — https://t.me/StarikZako.
- *
- *
Gated on the {@code microOpts} toggle via
- * {@link RenderBackendOps#tboCacheSupported()}. When the toggle is off, both
- * {@code WrapOperation}s call the original.
- */
-@Mixin(targets = "com.mojang.blaze3d.opengl.GlCommandEncoder")
-public abstract class GlCommandEncoderTexBufferMixin {
-
- @WrapOperation(
- method = "trySetup",
- at = @At(value = "INVOKE",
- target = "Lorg/lwjgl/opengl/GL33C;glBindTexture(II)V")
- )
- private void lovisual$trackBoundTboTexture(int target, int texture, Operation original) {
- RenderBackendOps backend = RenderBackendOps.current();
- if (backend != null && backend.tboCacheSupported()) {
- backend.trackBoundTboTexture(texture);
- }
- original.call(target, texture);
- }
-
- @WrapOperation(
- method = "trySetup",
- at = @At(value = "INVOKE",
- target = "Lorg/lwjgl/opengl/GL33C;glTexBuffer(III)V")
- )
- private void lovisual$texBufferOnce(int target, int format, int buffer, Operation original) {
- RenderBackendOps backend = RenderBackendOps.current();
- if (backend != null && backend.tboAlreadyAttached(format, buffer)) {
- // Same (format, buffer) pair already attached to the bound texture — skip the re-attach.
- return;
- }
- original.call(target, format, buffer);
- if (backend != null) {
- backend.markTboAttached(format, buffer);
- }
- }
-}
diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/RenderTypesMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/RenderTypesMixin.java
deleted file mode 100644
index 7bbc974d..00000000
--- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/gl/RenderTypesMixin.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package dev.loki.lovisual.mixins.optimize.gl;
-
-import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
-import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
-import dev.loki.lovisual.features.module.modules.misc.optimize.gl.RenderBackendOps;
-import net.minecraft.client.renderer.rendertype.RenderType;
-import net.minecraft.client.renderer.rendertype.RenderTypes;
-import net.minecraft.resources.Identifier;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.injection.At;
-
-import java.util.function.BiFunction;
-
-/**
- * Stage 3b: cache {@code RenderTypes.entityTranslucent(id, flag=true)} by
- * identifier — vanilla uses {@code Util.memoize} keyed on {@code Pair(id, flag)},
- * which {@code Objects.hash}-es the pair on every call, per entity per frame.
- * When the flag is {@code true} (the common case — translucent skins, held
- * items, etc.), the result depends only on the identifier, so we cache it
- * directly in a {@code ConcurrentHashMap}.
- *
- *
Ported from {@code zako.opt.mixin.gl.RenderTypesMixin} (ZakoOpt, LGPL-3.0).
- * Original author: Zako — https://t.me/StarikZako. The original cache logic
- * is wrapped in {@link RenderBackendOps}; LoVisual's GL implementation is
- * {@code GlRenderBackendOps}, which gates on {@code microOpts} (Stage 1 toggle).
- *
- *
When the toggle is off, the WrapOperation calls the original — vanilla
- * behavior preserved. When the toggle is on and the flag is {@code true},
- * the cache is consulted; on a miss, the original is called and the result
- * is stored.
- */
-@Mixin(RenderTypes.class)
-public abstract class RenderTypesMixin {
-
- @WrapOperation(
- method = "entityTranslucent(Lnet/minecraft/resources/Identifier;Z)Lnet/minecraft/client/renderer/rendertype/RenderType;",
- at = @At(value = "INVOKE",
- target = "Ljava/util/function/BiFunction;apply(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")
- )
- private static Object lovisual$cacheTranslucent(
- BiFunction