Verify native macOS client startup and framebuffer readback
This commit is contained in:
@@ -59,6 +59,9 @@ jobs:
|
||||
run: python -c "from tools.build_mod import benchmark_headers; benchmark_headers()"
|
||||
- name: Test pack integrity and comparisons
|
||||
run: python -m unittest discover -s tests -v
|
||||
- name: Start native macOS clients and verify framebuffer readback
|
||||
if: runner.os == 'macOS'
|
||||
run: python tools/test_client_graphics.py --native-display
|
||||
- name: Compile the private dispatch fixture
|
||||
run: python -c "from tools.build_mod import build_dispatch_fixture; build_dispatch_fixture()"
|
||||
- name: Compile the private tick-manager state fixture
|
||||
@@ -123,3 +126,4 @@ jobs:
|
||||
dist/terrain-position-integration.json
|
||||
dist/quad-reuse-integration.json
|
||||
dist/quad-size-integration.json
|
||||
dist/client-graphics-smoke.json
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package dev.horizonlab.metrics;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashSet;
|
||||
import java.util.HexFormat;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.Screenshot;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
|
||||
/** Private startup/readback probe. Never packaged in a playable release. */
|
||||
public final class ClientGraphicsIntegration implements ClientModInitializer {
|
||||
private long titleStarted;
|
||||
private int titleTicks;
|
||||
private boolean requested;
|
||||
|
||||
@Override public void onInitializeClient() {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (requested || !(client.gui.screen() instanceof TitleScreen)) return;
|
||||
if (titleStarted == 0) titleStarted = System.nanoTime();
|
||||
titleTicks++;
|
||||
if (titleTicks < 40 || System.nanoTime() - titleStarted < 2_000_000_000L) return;
|
||||
requested = true;
|
||||
Screenshot.takeScreenshot(client.gameRenderer.mainRenderTarget(), image -> {
|
||||
try (image) {
|
||||
int width = image.getWidth(), height = image.getHeight();
|
||||
if (width < 64 || height < 64) throw new AssertionError("Incomplete title framebuffer");
|
||||
var colors = new HashSet<Integer>();
|
||||
int samples = 0;
|
||||
for (int y = 0; y < height; y += Math.max(1, height / 64)) {
|
||||
for (int x = 0; x < width; x += Math.max(1, width / 64)) {
|
||||
colors.add(image.getPixel(x, y) & 0xFFFFFF);
|
||||
samples++;
|
||||
}
|
||||
}
|
||||
if (samples < 256 || colors.size() < 8) throw new AssertionError("Uniform title readback");
|
||||
var screenshot = client.gameDirectory.toPath().resolve("client-graphics-private.png");
|
||||
image.writeToFile(screenshot);
|
||||
var device = RenderSystem.getDevice().getDeviceInfo();
|
||||
var result = new JsonObject();
|
||||
result.addProperty("title_screen_observed", true);
|
||||
result.addProperty("title_client_ticks", titleTicks);
|
||||
result.addProperty("framebuffer_width", width);
|
||||
result.addProperty("framebuffer_height", height);
|
||||
result.addProperty("sampled_pixels", samples);
|
||||
result.addProperty("distinct_sampled_rgb", colors.size());
|
||||
result.addProperty("gpu", device.name());
|
||||
result.addProperty("graphics_backend", device.backendName());
|
||||
result.addProperty("graphics_driver", device.driverInfo());
|
||||
result.addProperty("private_png_sha256", HexFormat.of().formatHex(
|
||||
MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(screenshot))));
|
||||
System.out.println("HORIZON_CLIENT_GRAPHICS_RESULT " + result);
|
||||
client.execute(client::stop);
|
||||
} catch (Exception error) {
|
||||
throw new AssertionError("Private client graphics readback failed", error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -136,7 +136,7 @@ def build_culling_empty_fixture():
|
||||
return build_integration_fixture("culling-empty", "dev.horizonlab.dispatch.CullingEmptyIntegration", ["entityculling"])
|
||||
|
||||
|
||||
def build_integration_fixture(name, entrypoint, extra_projects=(), fixture_mixins=()):
|
||||
def build_integration_fixture(name, entrypoint, extra_projects=(), fixture_mixins=(), fixture_dependencies=None):
|
||||
"""Create a private integration-test mod; never include it in release packs."""
|
||||
arguments = [json.loads(line) for line in (BUILD / "javac.args").read_text().splitlines()]
|
||||
classpath = arguments[arguments.index("-classpath") + 1] + os.pathsep + str(BUILD / "classes")
|
||||
@@ -157,7 +157,8 @@ def build_integration_fixture(name, entrypoint, extra_projects=(), fixture_mixin
|
||||
output = BUILD / f"{name}-fixture.jar"
|
||||
metadata = {"schemaVersion": 1, "id": "horizon_" + name.replace("-", "_") + "_fixture",
|
||||
"version": "1.0.0", "environment": "client", "entrypoints": {"client": [entrypoint]},
|
||||
"depends": {"horizonlab": "*", "distanthorizons": "3.3.4"}}
|
||||
"depends": {"horizonlab": "*", **({"distanthorizons": "3.3.4"}
|
||||
if fixture_dependencies is None else fixture_dependencies)}}
|
||||
if fixture_mixins:
|
||||
metadata["mixins"] = [name + "-fixture.mixins.json"]
|
||||
with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Start real clients and verify a nonuniform GPU framebuffer readback."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
try:
|
||||
from . import build_mod, build_pack
|
||||
from .test_culling_rays import run_fixture
|
||||
from .test_dispatch import failure_summary
|
||||
except ImportError:
|
||||
import build_mod
|
||||
import build_pack
|
||||
from test_culling_rays import run_fixture
|
||||
from test_dispatch import failure_summary
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--native-display', action='store_true')
|
||||
parser.add_argument('--profile', action='append', choices=sorted(build_pack.PROFILES))
|
||||
args = parser.parse_args()
|
||||
root = build_pack.ROOT
|
||||
fixture = build_mod.build_integration_fixture('client-graphics',
|
||||
'dev.horizonlab.metrics.ClientGraphicsIntegration', fixture_dependencies={})
|
||||
version = build_pack.read_lock()['pack_version']
|
||||
mod = root / 'dist' / f'horizon-lab-{version}.jar'
|
||||
original_hash = hashlib.sha256(mod.read_bytes()).hexdigest()
|
||||
results = []
|
||||
for profile in args.profile or ['core-performance', 'm2-balanced', 'vulkan']:
|
||||
instance = root / '.local/runtime' / ('client-graphics-' + profile)
|
||||
build_pack.prepare_instance(profile, instance, mod)
|
||||
shutil.copy2(fixture, instance / 'mods/client-graphics-fixture.jar')
|
||||
command = [sys.executable, str(root / 'tools/runtime.py'), 'demo',
|
||||
'--instance', str(instance), '--heap', '3G']
|
||||
if platform.system() == 'Linux' and not args.native_display:
|
||||
command = ['xvfb-run', '-a', *command]
|
||||
try:
|
||||
run = run_fixture(command, instance, os.environ.copy())
|
||||
except RuntimeError:
|
||||
print('HORIZON_FIXTURE_FAILURE ' + json.dumps({'fixture': 'client-graphics',
|
||||
'profile': profile, 'completed': False}), flush=True)
|
||||
raise RuntimeError('Graphics probe did not finish; diagnostics remain private') from None
|
||||
marker = 'HORIZON_CLIENT_GRAPHICS_RESULT '
|
||||
reports = [json.loads(line.split(marker, 1)[1]) for line in run.stdout.splitlines() if marker in line]
|
||||
if run.returncode or len(reports) != 1:
|
||||
print('HORIZON_FIXTURE_FAILURE ' + json.dumps(failure_summary(run, len(reports))), flush=True)
|
||||
raise RuntimeError('Graphics probe failed; diagnostics remain private')
|
||||
report = reports[0]
|
||||
if report['title_screen_observed'] is not True or report['title_client_ticks'] < 40:
|
||||
raise AssertionError('Client never reached the title screen')
|
||||
if report['sampled_pixels'] < 256 or report['distinct_sampled_rgb'] < 8:
|
||||
raise AssertionError('GPU readback was uniform')
|
||||
if hashlib.sha256((instance / 'mods' / mod.name).read_bytes()).hexdigest() != original_hash:
|
||||
raise AssertionError('Runtime original mod differs from the intended build')
|
||||
screenshot = instance / 'client-graphics-private.png'
|
||||
if not screenshot.is_file() or hashlib.sha256(screenshot.read_bytes()).hexdigest() != report['private_png_sha256']:
|
||||
raise AssertionError('Private screenshot evidence is missing or changed')
|
||||
report.update(profile=profile, launcher_exit_code=run.returncode)
|
||||
results.append(report)
|
||||
print(json.dumps(report), flush=True)
|
||||
output = root / 'dist/client-graphics-smoke.json'
|
||||
output.write_text(json.dumps({'schema': 1, 'platform': platform.platform(),
|
||||
'architecture': platform.machine(), 'minecraft': '26.3',
|
||||
'original_mod_sha256': original_hash, 'results': results,
|
||||
'limits': ['Title-screen startup and nonuniform framebuffer readback only.',
|
||||
'No world gameplay, visual-correctness, FPS or M2 Pro performance claim.',
|
||||
'Vulkan preference can fall back; inspect the observed backend.',
|
||||
'PNG images, assets and full logs remain in the private runtime directory.']}, indent=2) + '\n')
|
||||
print('Client graphics startup/readback checks passed.', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user