mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-28 20:54:40 +01:00
Merge remote-tracking branch 'origin/1.18/dev' into 1.18/fabric/dev
Conflicts: src/main/java/com/jozufozu/flywheel/FlywheelClient.java src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java
This commit is contained in:
commit
44f3358f3e
21 changed files with 113 additions and 67 deletions
|
@ -1,3 +1,8 @@
|
|||
0.5.0a:
|
||||
Fixes
|
||||
- Address crash experienced by some users while rendering any tile.
|
||||
- Fix crash caused by loading a world with flywheel backend off.
|
||||
|
||||
0.5.0:
|
||||
New
|
||||
- Added parallel batching backend, effectively a CPU instancer.
|
||||
|
|
|
@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx3G
|
|||
org.gradle.daemon = false
|
||||
|
||||
# mod version info
|
||||
mod_version = 0.5.0
|
||||
mod_version = 0.5.0a
|
||||
mc_update_version = 1.18
|
||||
minecraft_version = 1.18.1
|
||||
loader_version = 0.12.12
|
||||
|
|
|
@ -27,7 +27,7 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
||||
public class Backend {
|
||||
public static final Logger log = LogManager.getLogger(Backend.class);
|
||||
public static final Logger LOGGER = LogManager.getLogger(Backend.class);
|
||||
|
||||
protected static final Backend INSTANCE = new Backend();
|
||||
public static Backend getInstance() {
|
||||
|
@ -39,8 +39,6 @@ public class Backend {
|
|||
public GLCapabilities capabilities;
|
||||
public GlCompat compat;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public final Loader loader;
|
||||
private final List<ShaderContext<?>> contexts = new ArrayList<>();
|
||||
private final Map<ResourceLocation, StructType<?>> materialRegistry = new HashMap<>();
|
||||
|
@ -93,7 +91,7 @@ public class Backend {
|
|||
}
|
||||
materialRegistry.put(name, spec);
|
||||
|
||||
log.debug("registered material '" + name + "' with instance size " + spec.getLayout().getStride());
|
||||
LOGGER.debug("registered material '" + name + "' with instance size " + spec.getLayout().getStride());
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
@ -104,20 +102,12 @@ public class Backend {
|
|||
|
||||
public void refresh() {
|
||||
OptifineHandler.refresh();
|
||||
boolean usingShaders = OptifineHandler.usingShaders();
|
||||
|
||||
capabilities = GL.createCapabilities();
|
||||
|
||||
compat = new GlCompat(capabilities);
|
||||
|
||||
engine = FlwConfig.get()
|
||||
.getEngine();
|
||||
|
||||
enabled = switch (engine) {
|
||||
case OFF -> false;
|
||||
case BATCHING -> true;
|
||||
case INSTANCING -> !usingShaders && compat.instancedArraysSupported();
|
||||
};
|
||||
engine = chooseEngine(compat);
|
||||
}
|
||||
|
||||
public Collection<StructType<?>> allMaterials() {
|
||||
|
@ -133,7 +123,7 @@ public class Backend {
|
|||
}
|
||||
|
||||
public static boolean isOn() {
|
||||
return getInstance().enabled;
|
||||
return getInstance().engine != FlwEngine.OFF;
|
||||
}
|
||||
|
||||
public static boolean canUseInstancing(@Nullable Level world) {
|
||||
|
@ -174,4 +164,18 @@ public class Backend {
|
|||
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
private static FlwEngine chooseEngine(GlCompat compat) {
|
||||
FlwEngine preferredChoice = FlwConfig.get()
|
||||
.getEngine();
|
||||
|
||||
boolean usingShaders = OptifineHandler.usingShaders();
|
||||
boolean canUseEngine = switch (preferredChoice) {
|
||||
case OFF -> true;
|
||||
case BATCHING -> !usingShaders;
|
||||
case INSTANCING -> !usingShaders && compat.instancedArraysSupported();
|
||||
};
|
||||
|
||||
return canUseEngine ? preferredChoice : FlwEngine.OFF;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,10 +82,10 @@ public class Loader {
|
|||
throw new ShaderLoadingException("Could not load all shaders, see log for details");
|
||||
}
|
||||
|
||||
Backend.log.info("Loaded all shader programs.");
|
||||
Backend.LOGGER.info("Loaded all shader programs.");
|
||||
|
||||
ClientLevel world = Minecraft.getInstance().level;
|
||||
if (Backend.isFlywheelWorld(world)) {
|
||||
if (Backend.canUseInstancing(world)) {
|
||||
// TODO: looks like it might be good to have another event here
|
||||
InstancedRenderDispatcher.resetInstanceWorld(world);
|
||||
CrumblingRenderer.reset();
|
||||
|
@ -115,7 +115,7 @@ public class Loader {
|
|||
|
||||
backend.register(spec);
|
||||
} catch (Exception e) {
|
||||
Backend.log.error(e);
|
||||
Backend.LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ public class OptifineHandler {
|
|||
optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
|
||||
|
||||
if (optifine == null) {
|
||||
Backend.log.info("Optifine not detected.");
|
||||
Backend.LOGGER.info("Optifine not detected.");
|
||||
} else {
|
||||
Backend.log.info("Optifine detected.");
|
||||
Backend.LOGGER.info("Optifine detected.");
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class OptifineHandler {
|
|||
return false;
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Backend.log.info("No shader config found.");
|
||||
Backend.LOGGER.info("No shader config found.");
|
||||
}
|
||||
return shadersOff;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.jozufozu.flywheel.backend.Backend;
|
|||
import com.jozufozu.flywheel.backend.gl.GlFence;
|
||||
import com.jozufozu.flywheel.backend.gl.error.GlError;
|
||||
import com.jozufozu.flywheel.backend.gl.error.GlException;
|
||||
import com.jozufozu.flywheel.util.StringUtil;
|
||||
|
||||
public class PersistentGlBuffer extends GlBuffer implements Mappable {
|
||||
|
||||
|
@ -49,13 +48,6 @@ public class PersistentGlBuffer extends GlBuffer implements Mappable {
|
|||
|
||||
Backend.getInstance().compat.bufferStorage.bufferStorage(type, size, flags);
|
||||
|
||||
GlError error = GlError.poll();
|
||||
if (error != null) {
|
||||
// If this error is being thrown but everything seems fine,
|
||||
// GlError.poll() might be returning an error from something earlier.
|
||||
throw new GlException(error, StringUtil.args("bufferStorage", type, size, flags));
|
||||
}
|
||||
|
||||
ByteBuffer byteBuffer = GL30.glMapBufferRange(type.glEnum, 0, size, flags);
|
||||
|
||||
if (byteBuffer == null) {
|
||||
|
|
|
@ -5,8 +5,6 @@ import java.util.function.Supplier;
|
|||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
||||
|
@ -41,10 +39,10 @@ public enum GlError {
|
|||
}
|
||||
|
||||
public static void pollAndThrow(Supplier<String> context) {
|
||||
// TODO: build flag? to enable or disable this function
|
||||
GlError err = GlError.poll();
|
||||
if (err != null) {
|
||||
Flywheel.LOGGER.error("{}: {}", err.name(), context.get());
|
||||
}
|
||||
// This was a bad idea.
|
||||
// GlError err = GlError.poll();
|
||||
// if (err != null) {
|
||||
// Flywheel.LOGGER.error("{}: {}", err.name(), context.get());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public abstract class GlProgram extends GlObject {
|
|||
int index = glGetUniformLocation(this.handle(), uniform);
|
||||
|
||||
if (index < 0) {
|
||||
Backend.log.debug("No active uniform '{}' exists in program '{}'. Could be unused.", uniform, this.name);
|
||||
Backend.LOGGER.debug("No active uniform '{}' exists in program '{}'. Could be unused.", uniform, this.name);
|
||||
}
|
||||
|
||||
return index;
|
||||
|
|
|
@ -24,8 +24,8 @@ public class GlShader extends GlObject {
|
|||
String log = GL20.glGetShaderInfoLog(handle);
|
||||
|
||||
if (!log.isEmpty()) {
|
||||
Backend.log.error("Shader compilation log for " + name + ": " + log);
|
||||
Backend.log.error(source);
|
||||
Backend.LOGGER.error("Shader compilation log for " + name + ": " + log);
|
||||
Backend.LOGGER.error(source);
|
||||
}
|
||||
//Backend.log.debug(shader.printSource());
|
||||
|
||||
|
|
|
@ -22,8 +22,11 @@ public class InstancedRenderDispatcher {
|
|||
* @param te The tile whose instance you want to update.
|
||||
*/
|
||||
public static void enqueueUpdate(BlockEntity te) {
|
||||
if (te.hasLevel() && te.getLevel() instanceof ClientLevel)
|
||||
getTiles(te.getLevel()).queueUpdate(te);
|
||||
if (Backend.isOn() && te.hasLevel() && te.getLevel() instanceof ClientLevel) {
|
||||
instanceWorlds.get(te.getLevel())
|
||||
.getTileEntityInstanceManager()
|
||||
.queueUpdate(te);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,17 +34,29 @@ public class InstancedRenderDispatcher {
|
|||
* @param entity The entity whose instance you want to update.
|
||||
*/
|
||||
public static void enqueueUpdate(Entity entity) {
|
||||
getEntities(entity.level).queueUpdate(entity);
|
||||
if (Backend.isOn()) {
|
||||
instanceWorlds.get(entity.level)
|
||||
.getEntityInstanceManager()
|
||||
.queueUpdate(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public static InstanceManager<BlockEntity> getTiles(LevelAccessor world) {
|
||||
if (Backend.isOn()) {
|
||||
return instanceWorlds.get(world)
|
||||
.getTileEntityInstanceManager();
|
||||
} else {
|
||||
throw new NullPointerException("Backend is off, cannot retrieve instance world.");
|
||||
}
|
||||
}
|
||||
|
||||
public static InstanceManager<Entity> getEntities(LevelAccessor world) {
|
||||
if (Backend.isOn()) {
|
||||
return instanceWorlds.get(world)
|
||||
.getEntityInstanceManager();
|
||||
} else {
|
||||
throw new NullPointerException("Backend is off, cannot retrieve instance world.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void tick(Minecraft mc) {
|
||||
|
@ -52,11 +67,14 @@ public class InstancedRenderDispatcher {
|
|||
ClientLevel world = mc.level;
|
||||
AnimationTickHolder.tick();
|
||||
|
||||
instanceWorlds.get(world).tick();
|
||||
if (Backend.isOn()) {
|
||||
instanceWorlds.get(world)
|
||||
.tick();
|
||||
}
|
||||
}
|
||||
|
||||
public static void onBeginFrame(BeginFrameEvent event) {
|
||||
if (Backend.isGameActive()) {
|
||||
if (Backend.isGameActive() && Backend.isOn()) {
|
||||
instanceWorlds.get(event.getWorld())
|
||||
.beginFrame(event);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ProtoProgram {
|
|||
String log = glGetProgramInfoLog(this.program);
|
||||
|
||||
if (!log.isEmpty()) {
|
||||
Backend.log.debug("Program link log for " + parent.name + ": " + log);
|
||||
Backend.LOGGER.debug("Program link log for " + parent.name + ": " + log);
|
||||
}
|
||||
|
||||
int result = glGetProgrami(this.program, GL_LINK_STATUS);
|
||||
|
|
|
@ -73,7 +73,7 @@ public class FileResolution {
|
|||
builder.pointAtFile(span.getSourceFile())
|
||||
.pointAt(span, 2);
|
||||
}
|
||||
Backend.log.error(builder.build());
|
||||
Backend.LOGGER.error(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ErrorReporter {
|
|||
.pointAt(span, 2)
|
||||
.build();
|
||||
|
||||
Backend.log.error(error);
|
||||
Backend.LOGGER.error(error);
|
||||
}
|
||||
|
||||
public static void generateFileError(SourceFile file, String message) {
|
||||
|
@ -27,7 +27,7 @@ public class ErrorReporter {
|
|||
.pointAtFile(file)
|
||||
.build();
|
||||
|
||||
Backend.log.error(error);
|
||||
Backend.LOGGER.error(error);
|
||||
}
|
||||
|
||||
public static void generateMissingStruct(SourceFile file, Span vertexName, CharSequence msg) {
|
||||
|
@ -45,7 +45,7 @@ public class ErrorReporter {
|
|||
.pointAt(vertexName, 2)
|
||||
.hintIncludeFor(span.orElse(null), hint);
|
||||
|
||||
Backend.log.error(error.build());
|
||||
Backend.LOGGER.error(error.build());
|
||||
}
|
||||
|
||||
public static void generateMissingFunction(SourceFile file, CharSequence functionName, CharSequence msg) {
|
||||
|
@ -62,6 +62,6 @@ public class ErrorReporter {
|
|||
.pointAtFile(file)
|
||||
.hintIncludeFor(span.orElse(null), hint);
|
||||
|
||||
Backend.log.error(error.build());
|
||||
Backend.LOGGER.error(error.build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
|||
@Override
|
||||
public void load() {
|
||||
|
||||
Backend.log.info("Loading context '{}'", name);
|
||||
Backend.LOGGER.info("Loading context '{}'", name);
|
||||
|
||||
specStream.get()
|
||||
.map(backend::getSpec)
|
||||
|
@ -46,10 +46,10 @@ public class WorldContext<P extends WorldProgram> implements ShaderContext<P> {
|
|||
try {
|
||||
programs.put(spec.name, pipeline.compile(spec));
|
||||
|
||||
Backend.log.debug("Loaded program {}", spec.name);
|
||||
Backend.LOGGER.debug("Loaded program {}", spec.name);
|
||||
} catch (Exception e) {
|
||||
Backend.log.error("Error loading program {}", spec.name);
|
||||
Backend.log.error("", e);
|
||||
Backend.LOGGER.error("Error loading program {}", spec.name);
|
||||
Backend.LOGGER.error("", e);
|
||||
backend.loader.notifyError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jozufozu.flywheel.event;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
@ -8,12 +9,12 @@ import net.minecraft.world.entity.Entity;
|
|||
public class EntityWorldHandler {
|
||||
|
||||
public static void onEntityJoinWorld(Entity entity, ClientLevel level) {
|
||||
InstancedRenderDispatcher.getEntities(level)
|
||||
if (Backend.isOn()) InstancedRenderDispatcher.getEntities(level)
|
||||
.queueAdd(entity);
|
||||
}
|
||||
|
||||
public static void onEntityLeaveWorld(Entity entity, ClientLevel level) {
|
||||
InstancedRenderDispatcher.getEntities(level)
|
||||
if (Backend.isOn()) InstancedRenderDispatcher.getEntities(level)
|
||||
.remove(entity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.jozufozu.flywheel.fabric.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
|
||||
import net.minecraft.SystemReport;
|
||||
|
||||
@Mixin(value = SystemReport.class, priority = 1100)
|
||||
public class SystemReportMixin {
|
||||
@Inject(method = "<init>()V", at = @At("TAIL"))
|
||||
private void onTailInit(CallbackInfo ci) {
|
||||
SystemReport self = (SystemReport) (Object) this;
|
||||
self.setDetail("Flywheel Backend", () -> Backend.getInstance().getBackendDescriptor());
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ public class ChunkRebuildHooksMixin {
|
|||
@Inject(method = "handleBlockEntity", at = @At("HEAD"), cancellable = true)
|
||||
private <E extends BlockEntity> void addAndFilterBEs(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> set, E be, CallbackInfo ci) {
|
||||
|
||||
if (Backend.isOn() && Backend.isFlywheelWorld(be.getLevel())) {
|
||||
if (Backend.canUseInstancing(be.getLevel())) {
|
||||
|
||||
InstancedRenderRegistry registry = InstancedRenderRegistry.getInstance();
|
||||
if (registry.canInstance(be.getType()))
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
|
@ -23,7 +24,9 @@ public class InstanceAddMixin {
|
|||
@Inject(method = "setBlockEntity",
|
||||
at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
|
||||
private void tileAdded(BlockEntity be, CallbackInfo ci) {
|
||||
if (level.isClientSide) InstancedRenderDispatcher.getTiles(this.level)
|
||||
if (level.isClientSide && Backend.isOn()) {
|
||||
InstancedRenderDispatcher.getTiles(this.level)
|
||||
.add(be);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
@ -23,9 +24,11 @@ public class InstanceRemoveMixin {
|
|||
|
||||
@Inject(at = @At("TAIL"), method = "setRemoved")
|
||||
private void removeInstance(CallbackInfo ci) {
|
||||
if (level instanceof ClientLevel) InstancedRenderDispatcher.getTiles(this.level)
|
||||
if (level instanceof ClientLevel && Backend.isOn()) {
|
||||
InstancedRenderDispatcher.getTiles(this.level)
|
||||
.remove((BlockEntity) (Object) this);
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Don't do this.
|
||||
|
|
|
@ -83,7 +83,9 @@ public class RenderHooksMixin {
|
|||
*/
|
||||
@Inject(at = @At("TAIL"), method = "setBlockDirty(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;)V")
|
||||
private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) {
|
||||
if (Backend.isOn()) {
|
||||
InstancedRenderDispatcher.getTiles(level)
|
||||
.update(level.getBlockEntity(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"DebugScreenOverlayMixin",
|
||||
"Matrix4fMixin",
|
||||
"MinecraftMixin",
|
||||
"SystemReportMixin",
|
||||
"TextureAtlasMixin",
|
||||
"VertexFormatAccessor"
|
||||
],
|
||||
|
|
Loading…
Add table
Reference in a new issue