Skip to content
Draft
59 changes: 31 additions & 28 deletions src/main/java/rs117/hd/HdPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
import rs117.hd.opengl.uniforms.UBOGlobal;
import rs117.hd.opengl.uniforms.UBOLights;
import rs117.hd.opengl.uniforms.UBOUI;
import rs117.hd.overlays.FrameTimer;
import rs117.hd.overlays.GammaCalibrationOverlay;
import rs117.hd.overlays.ShadowMapOverlay;
import rs117.hd.overlays.TiledLightingOverlay;
import rs117.hd.overlays.Timer;
import rs117.hd.profiling.Profiler;
import rs117.hd.profiling.Timer;
import rs117.hd.renderer.Renderer;
import rs117.hd.renderer.legacy.LegacyRenderer;
import rs117.hd.renderer.zone.SceneManager;
Expand Down Expand Up @@ -294,7 +294,7 @@ public class HdPlugin extends Plugin {
private DeveloperTools developerTools;

@Inject
private FrameTimer frameTimer;
private Profiler profiler;

@Inject
private UIShaderProgram uiProgram;
Expand Down Expand Up @@ -572,6 +572,8 @@ protected void startUp() {
String glVendor = Objects.requireNonNullElse(glGetString(GL_VENDOR), "Unknown");
var runtime = Runtime.getRuntime();

boolean supportsThreadAllocationTracking = HDUtils.setupThreadAllocatedBytesMonitoring();

APPLE = osType == OSType.MacOS;
APPLE_ARM = APPLE && osArch.equals("aarch64");
AMD_GPU = glRenderer.contains("AMD") || glRenderer.contains("Radeon") || glVendor.contains("ATI");
Expand All @@ -582,19 +584,20 @@ protected void startUp() {
SUPPORTS_STORAGE_BUFFERS = GL_CAPS.GL_ARB_buffer_storage && !DEBUG_MAC_OS && config.storageBuffers().get(!INTEL_GPU);

log.info("Starting 117 HD... (count: {})", startupCount);
log.info("Renderer: {}", rendererClass.getSimpleName());
log.info("rlawt version: {}", rlawtVersion);
log.info("LWJGL Version: {}", Version.getVersion());
log.info("Java version: {} ({})", javaVmName, javaVersion);
log.info("Java memory limit: {} (free: {})", formatBytes(runtime.maxMemory()), formatBytes(runtime.freeMemory()));
log.info("Operating system: {} {} ({}-bit {})", osType, osVersion, wordSize, osArch);
log.info("CPU: {} ({} threads)", HDUtils.getCpuName(), runtime.availableProcessors());
log.info("Memory: {}", formatBytes(HDUtils.getTotalSystemMemory()));
log.info("GPU: {} ({})", glRenderer, glVendor);
log.info("GPU driver: {}", glGetString(GL_VERSION));
log.info("Indirect draw: {}", SUPPORTS_INDIRECT_DRAW);
log.info("Storage buffers: {}", SUPPORTS_STORAGE_BUFFERS);
log.info("Low memory mode: {}", useLowMemoryMode);
log.info("Renderer: {}", rendererClass.getSimpleName());
log.info("rlawt version: {}", rlawtVersion);
log.info("LWJGL Version: {}", Version.getVersion());
log.info("Java version: {} ({})", javaVmName, javaVersion);
log.info("Java memory limit: {} (free: {})", formatBytes(runtime.maxMemory()), formatBytes(runtime.freeMemory()));
log.info("Operating system: {} {} ({}-bit {})", osType, osVersion, wordSize, osArch);
log.info("CPU: {} ({} threads)", HDUtils.getCpuName(), runtime.availableProcessors());
log.info("Memory: {}", formatBytes(HDUtils.getTotalSystemMemory()));
log.info("GPU: {} ({})", glRenderer, glVendor);
log.info("GPU driver: {}", glGetString(GL_VERSION));
log.info("Indirect draw: {}", SUPPORTS_INDIRECT_DRAW);
log.info("Storage buffers: {}", SUPPORTS_STORAGE_BUFFERS);
log.info("Allocation Tracking: {}", supportsThreadAllocationTracking);
log.info("Low memory mode: {}", useLowMemoryMode);

renderer = injector.getInstance(rendererClass);

Expand Down Expand Up @@ -1507,10 +1510,10 @@ public void prepareInterfaceTexture() {
uiWidth = bufferProvider.getWidth();
uiHeight = bufferProvider.getHeight();

frameTimer.begin(Timer.MAP_UI_BUFFER);
profiler.begin(Timer.MAP_UI_BUFFER);
final GLBuffer pbo = pboUi[frame % 3];
pbo.map(MAP_WRITE, 0, uiWidth * uiHeight * 4L);
frameTimer.end(Timer.MAP_UI_BUFFER);
profiler.end(Timer.MAP_UI_BUFFER);
if (!pbo.isMapped()) {
log.error("Unable to map interface PBO. Skipping UI...");
} else if (uiWidth > uiResolution[0] || uiHeight > uiResolution[1]) {
Expand All @@ -1520,9 +1523,9 @@ public void prepareInterfaceTexture() {
.build(
"AsyncUICopy",
t -> {
long start = System.nanoTime();
long timestamp = profiler.getTimeStamp();
pbo.mapped().intView().put(pixels, 0, uiWidth * uiHeight);
frameTimer.add(Timer.COPY_UI_ASYNC, System.nanoTime() - start);
profiler.add(Timer.COPY_UI_ASYNC, timestamp);
}
)
.setExecuteAsync(!isPowerSaving)
Expand All @@ -1539,7 +1542,7 @@ public void drawUi(int overlayColor) {
if (client.getGameState().getState() < GameState.LOADING.getState())
overlayColor = 0;

frameTimer.begin(Timer.RENDER_UI);
profiler.begin(Timer.RENDER_UI);

glBindFramebuffer(GL_FRAMEBUFFER, awtContext.getFramebuffer(false));
// Disable alpha writes, just in case the default FBO has an alpha channel
Expand All @@ -1564,19 +1567,19 @@ public void drawUi(int overlayColor) {
glBindTexture(GL_TEXTURE_2D, texUi);

if (uiCopyJob != null) {
frameTimer.begin(Timer.COPY_UI);
profiler.begin(Timer.COPY_UI);
uiCopyJob.waitForCompletion(true);
uiCopyJob = null;
frameTimer.end(Timer.COPY_UI);
profiler.end(Timer.COPY_UI);

frameTimer.begin(Timer.UPLOAD_UI);
profiler.begin(Timer.UPLOAD_UI);
final GLBuffer pbo = pboUi[frame % 3];
pbo.unmap();
pbo.bind();

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, uiWidth, uiHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
pbo.unbind();
frameTimer.end(Timer.UPLOAD_UI);
profiler.end(Timer.UPLOAD_UI);
}

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, function);
Expand All @@ -1595,7 +1598,7 @@ public void drawUi(int overlayColor) {
glDisable(GL_BLEND);
glColorMask(true, true, true, true);

frameTimer.end(Timer.RENDER_UI);
profiler.end(Timer.RENDER_UI);
}

/**
Expand Down Expand Up @@ -1922,7 +1925,7 @@ public void processPendingConfigChanges() {
sceneManager.getLoadingLock().unlock();
log.trace("loadingLock unlocked - holdCount: {}", sceneManager.getLoadingLock().getHoldCount());
pendingConfigChanges.clear();
frameTimer.reset();
profiler.reset();
}
});
}
Expand All @@ -1932,7 +1935,7 @@ public void setupSyncMode() {
boolean unlockFps = config.unlockFps();
HdPluginConfig.SyncMode syncMode = unlockFps ? config.syncMode() : HdPluginConfig.SyncMode.OFF;

if (frameTimer.isActive()) {
if (profiler.isActive()) {
unlockFps = true;
syncMode = SyncMode.OFF;
}
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/rs117/hd/HdPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,72 @@ default boolean multithreadedModelProcessing() {

/*====== Internal settings ======*/

String KEY_FRAME_TIMER_OVERLAY_ENABLED = "frameTimerOverlayEnabled";
@ConfigItem(keyName = KEY_FRAME_TIMER_OVERLAY_ENABLED, hidden = true, name = "", description = "")
default boolean frameTimerOverlayEnabled() {
return false;
}

String KEY_FRAME_TIMER_GRAPH_ENABLED = "frameTimerGraphEnabled";
@ConfigItem(keyName = KEY_FRAME_TIMER_GRAPH_ENABLED, hidden = true, name = "", description = "")
default boolean frameTimerGraphEnabled() {
return false;
}

String KEY_FRAME_TIMER_HIDDEN_GRAPHS = "frameTimerHiddenGraphs";
@ConfigItem(keyName = KEY_FRAME_TIMER_HIDDEN_GRAPHS, hidden = true, name = "", description = "")
default String frameTimerHiddenGraphs() {
return "";
}

String KEY_FRAME_TIMER_SELECTED_TAB = "frameTimerSelectedTab";
@ConfigItem(keyName = KEY_FRAME_TIMER_SELECTED_TAB, hidden = true, name = "", description = "")
default String frameTimerSelectedTab() {
return "ALL";
}

String KEY_FRAME_TIMER_HIDDEN_TABS = "frameTimerHiddenTabs";
@ConfigItem(keyName = KEY_FRAME_TIMER_HIDDEN_TABS, hidden = true, name = "", description = "")
default String frameTimerHiddenTabs() {
return "";
}

String KEY_FRAME_TIMER_DETACHED_TABS = "frameTimerDetachedTabs";
@ConfigItem(keyName = KEY_FRAME_TIMER_DETACHED_TABS, hidden = true, name = "", description = "")
default String frameTimerDetachedTabs() {
return "";
}

String KEY_FRAME_TIMER_SETTINGS_DETACHED = "frameTimerSettingsDetached";
@ConfigItem(keyName = KEY_FRAME_TIMER_SETTINGS_DETACHED, hidden = true, name = "", description = "")
default boolean frameTimerSettingsDetached() {
return false;
}

String KEY_FRAME_TIMER_GRAPH_DETACHED = "frameTimerGraphDetached";
@ConfigItem(keyName = KEY_FRAME_TIMER_GRAPH_DETACHED, hidden = true, name = "", description = "")
default boolean frameTimerGraphDetached() {
return false;
}

String KEY_FRAME_TIMER_GRAPH_WIDTH = "frameTimerGraphWidth";
@ConfigItem(keyName = KEY_FRAME_TIMER_GRAPH_WIDTH, hidden = true, name = "", description = "")
default int frameTimerGraphWidth() {
return 800;
}

String KEY_FRAME_TIMER_GRAPH_HEIGHT = "frameTimerGraphHeight";
@ConfigItem(keyName = KEY_FRAME_TIMER_GRAPH_HEIGHT, hidden = true, name = "", description = "")
default int frameTimerGraphHeight() {
return 200;
}

String KEY_FRAME_TIMER_MEMORY_GRAPH_HEIGHT = "frameTimerMemoryGraphHeight";
@ConfigItem(keyName = KEY_FRAME_TIMER_MEMORY_GRAPH_HEIGHT, hidden = true, name = "", description = "")
default int frameTimerMemoryGraphHeight() {
return 75;
}

@ConfigItem(keyName = "pluginUpdateMessage", hidden = true, name = "", description = "")
void setPluginUpdateMessage(int version);
@ConfigItem(keyName = "pluginUpdateMessage", hidden = true, name = "", description = "")
Expand Down
Loading