Non-uniform un-provider

- Delete UniformBuffer on renderer reload to fix crash when switching
  backend to off
- Use library method for getting boolean property (ty pepper!)
This commit is contained in:
Jozufozu 2023-04-16 17:20:32 -07:00
parent b03f1ab0e0
commit 73d053472d
3 changed files with 29 additions and 9 deletions

View file

@ -6,6 +6,7 @@ import org.slf4j.Logger;
import com.jozufozu.flywheel.backend.Backends; import com.jozufozu.flywheel.backend.Backends;
import com.jozufozu.flywheel.backend.Loader; import com.jozufozu.flywheel.backend.Loader;
import com.jozufozu.flywheel.backend.Pipelines; import com.jozufozu.flywheel.backend.Pipelines;
import com.jozufozu.flywheel.backend.engine.UniformBuffer;
import com.jozufozu.flywheel.backend.engine.batching.DrawBuffer; import com.jozufozu.flywheel.backend.engine.batching.DrawBuffer;
import com.jozufozu.flywheel.config.BackendArgument; import com.jozufozu.flywheel.config.BackendArgument;
import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwCommands;
@ -81,6 +82,7 @@ public class Flywheel {
forgeEventBus.addListener(EventPriority.HIGHEST, QuadConverter::onReloadRenderers); forgeEventBus.addListener(EventPriority.HIGHEST, QuadConverter::onReloadRenderers);
forgeEventBus.addListener(Models::onReloadRenderers); forgeEventBus.addListener(Models::onReloadRenderers);
forgeEventBus.addListener(DrawBuffer::onReloadRenderers); forgeEventBus.addListener(DrawBuffer::onReloadRenderers);
forgeEventBus.addListener(UniformBuffer::onReloadRenderers);
forgeEventBus.addListener(VisualizedRenderDispatcher::onRenderStage); forgeEventBus.addListener(VisualizedRenderDispatcher::onRenderStage);
forgeEventBus.addListener(VisualizedRenderDispatcher::onBeginFrame); forgeEventBus.addListener(VisualizedRenderDispatcher::onBeginFrame);

View file

@ -6,6 +6,7 @@ import java.util.Set;
import org.lwjgl.opengl.GL32; import org.lwjgl.opengl.GL32;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.api.event.ReloadRenderersEvent;
import com.jozufozu.flywheel.api.uniform.ShaderUniforms; import com.jozufozu.flywheel.api.uniform.ShaderUniforms;
import com.jozufozu.flywheel.gl.buffer.GlBuffer; import com.jozufozu.flywheel.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.gl.buffer.GlBufferType; import com.jozufozu.flywheel.gl.buffer.GlBufferType;
@ -60,27 +61,39 @@ public class UniformBuffer {
} }
} }
private void delete() {
providerSet.delete();
buffer.delete();
}
public static void onReloadRenderers(ReloadRenderersEvent event) {
if (instance != null) {
instance.delete();
instance = null;
}
}
private static class LiveProvider { private static class LiveProvider {
private final ShaderUniforms provider; private final ShaderUniforms shaderUniforms;
private final int offset; private final int offset;
private final int size; private final int size;
private ShaderUniforms.Provider activeProvider; private ShaderUniforms.Provider provider;
private LiveProvider(ShaderUniforms provider, int offset, int size) { private LiveProvider(ShaderUniforms shaderUniforms, int offset, int size) {
this.provider = provider; this.shaderUniforms = shaderUniforms;
this.offset = offset; this.offset = offset;
this.size = size; this.size = size;
} }
private void updatePtr(MemoryBlock bufferBase) { private void updatePtr(MemoryBlock bufferBase) {
if (activeProvider != null) { if (provider != null) {
activeProvider.delete(); provider.delete();
} }
activeProvider = provider.activate(bufferBase.ptr() + offset); provider = shaderUniforms.activate(bufferBase.ptr() + offset);
} }
public boolean maybePoll() { public boolean maybePoll() {
return activeProvider != null && activeProvider.poll(); return provider != null && provider.poll();
} }
} }
@ -116,5 +129,10 @@ public class UniformBuffer {
} }
return changed; return changed;
} }
public void delete() {
allocatedProviders.forEach(p -> p.provider.delete());
data.free();
}
} }
} }

View file

@ -12,7 +12,7 @@ public class ClientMainMixin {
@Inject(method = "main([Ljava/lang/String;)V", at = @At("HEAD")) @Inject(method = "main([Ljava/lang/String;)V", at = @At("HEAD"))
private static void flywheel$injectRenderDoc(CallbackInfo ci) { private static void flywheel$injectRenderDoc(CallbackInfo ci) {
// Only try to load RenderDoc if a system property is set to true. // Only try to load RenderDoc if a system property is set to true.
if (!Boolean.parseBoolean(System.getProperty("flw.loadRenderDoc"))) { if (!Boolean.getBoolean("flw.loadRenderDoc")) {
return; return;
} }