gpu: Capturer::on_device and Renderer::report

A capturer on a device already open (the app's), and the renderer's
JSON shared by every reply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
jyvikoandClaude Opus 5.5 authored and Irakli Kourtis committed 2026-10-16 08:27:21 -04:00
1 parent 7f0af28e9c
commit b655af305a
5 files changed
+18 -4

No files matched your search

Generated
+1
View File
@@ -1379,6 +1379,7 @@ dependencies = [
"fieldcraft-render",
"log",
"pollster 0.4.0",
"serde_json",
"thiserror 2.0.21",
"wgpu",
]
+1
View File
@@ -13,6 +13,7 @@ fieldcraft-render = { workspace = true }
wgpu = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
serde_json = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
pollster = { workspace = true }
+6
View File
@@ -61,6 +61,12 @@ impl Capturer {
.map_err(|e| GpuError::Device(e.to_string()))?;
// Errors outside a scope are logged, replacing wgpu's default handler, which panics.
device.on_uncaptured_error(Arc::new(|e: wgpu::Error| log::error!("graphics device error: {e}")));
Capturer::on_device(adapter, device, queue, tier)
}
/// A capturer on a device already open on `adapter` (the desktop app's), which keeps its
/// error handler: pictures share the window's device instead of opening another.
pub fn on_device(adapter: &wgpu::Adapter, device: wgpu::Device, queue: wgpu::Queue, tier: Tier) -> Result<Capturer> {
let samples = if adapter.get_texture_format_features(FORMAT).flags.sample_count_supported(SAMPLES)
&& adapter.get_texture_format_features(DEPTH).flags.sample_count_supported(SAMPLES)
{
+9
View File
@@ -69,4 +69,13 @@ impl Renderer {
Renderer::Cpu { .. } => "cpu",
}
}
/// What drew a picture, for a reply: `{kind, adapter, msaa}` on a GPU, `{kind, why}` on
/// the CPU (`why` null when the CPU was asked for).
pub fn report(&self) -> serde_json::Value {
match self {
Renderer::Gpu { adapter, samples, .. } => serde_json::json!({"kind": self.kind(), "adapter": adapter, "msaa": samples}),
Renderer::Cpu { why } => serde_json::json!({"kind": self.kind(), "why": why}),
}
}
}
+1 -4
View File
@@ -35,10 +35,7 @@ fn draw(f: &fieldcraft_engine::view::Framed, w: u32, h: u32) -> Result<(Vec<u8>,
/// the adapter, or why the CPU drew it), `results` (step, scale, contour), `undrawn_bodies` and
/// `sampled_symbols`. The MCP `screenshot` reply and `fieldcraft-cli snapshot` print it.
pub fn picture_report(r: &Renderer, shown: &Shown) -> Value {
let renderer = match r {
Renderer::Gpu { adapter, samples, .. } => json!({"kind": r.kind(), "adapter": adapter, "msaa": samples}),
Renderer::Cpu { why } => json!({"kind": r.kind(), "why": why}),
};
let renderer = r.report();
let contour = shown
.contour
.as_ref()