Skip to content

Commit

Permalink
change: add more debug features, remove current fallback for bfs
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerindividual committed Jan 15, 2023
1 parent 95b0725 commit ddfb9f2
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,21 @@ private void deleteProgram0(GlProgram<?> program) {
public Fence createFence() {
return new GlFence();
}


@Override
public void pushDebugGroup(String location) {
if (this.renderConfiguration.apiDebug) {
GL45C.glPushDebugGroup(GL45C.GL_DEBUG_SOURCE_APPLICATION, 0, location);
}
}

@Override
public void popDebugGroup() {
if (this.renderConfiguration.apiDebug) {
GL45C.glPopDebugGroup();
}
}

@Override
public RenderDeviceProperties properties() {
return this.properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public interface RenderDevice extends ResourceFactory, ResourceDestructors {
void updateBuffer(DynamicBuffer buffer, int offset, ByteBuffer data);

void copyBuffer(Buffer readBuffer, Buffer writeBuffer, long readOffset, long writeOffset, long length);

void pushDebugGroup(String location);

void popDebugGroup();

RenderDeviceProperties properties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ public static OptionPage advanced() {
.setBinding((opts, value) -> opts.advanced.allowDirectMemoryAccess = value, opts -> opts.advanced.allowDirectMemoryAccess)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setName(Text.translatable("sodium.options.enable_memory_tracing.name"))
.setTooltip(Text.translatable("sodium.options.enable_memory_tracing.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.MEDIUM)
.setBinding((opts, value) -> opts.advanced.enableMemoryTracing = value, opts -> opts.advanced.enableMemoryTracing)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setName(Text.translatable("sodium.options.enable_api_debug.name"))
.setTooltip(Text.translatable("sodium.options.enable_api_debug.tooltip"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.caffeinemc.sodium.mixin.features.debug;

import java.util.function.Supplier;
import net.caffeinemc.sodium.SodiumClientMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.TickDurationMonitor;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.profiler.SampleType;
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.CallbackInfoReturnable;

@Mixin(MinecraftClient.class)
public class MixinMinecraftClient {

private static final Profiler GFX_DEBUGGER = new Profiler() {
@Override
public void startTick() {
this.push(Profiler.ROOT_NAME);
}

@Override
public void endTick() {
this.pop();
}

@Override
public void push(String location) {
SodiumClientMod.DEVICE.pushDebugGroup(location);
}

@Override
public void push(Supplier<String> locationGetter) {
this.push(locationGetter.get());
}

@Override
public void pop() {
SodiumClientMod.DEVICE.popDebugGroup();
}

@Override
public void swap(String location) {
this.pop();
this.push(location);
}

@Override
public void swap(Supplier<String> locationGetter) {
this.swap(locationGetter.get());
}

@Override
public void markSampleType(SampleType type) {
// noop
}

@Override
public void visit(String marker, int i) {
// noop
}

@Override
public void visit(Supplier<String> markerGetter, int i) {
// noop
}
};

@Inject(method = "startMonitor", at = @At("RETURN"), cancellable = true)
private void addDebugger(boolean active, TickDurationMonitor monitor, CallbackInfoReturnable<Profiler> cir) {
cir.setReturnValue(Profiler.union(cir.getReturnValue(), GFX_DEBUGGER));
}

}
Loading

0 comments on commit ddfb9f2

Please sign in to comment.