Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Centralize the fixed 640x360 RGBA8888/60 Hz contract in the existing HAL. Preserve 8/16/32 tiles and composition, cover partial edges and mixed-size camera movement, and adapt firmware, fixtures, hosts and native tests. Share nearest-neighbor presentation geometry with pointer input. Measure actual framebuffer publications and successful host presentations separately from VM ticks, with bounded opt-in diagnostics and release harnesses. Validated with the complete tooling verify gate, native rendering tests, GPU readback, headless/process integration, formatting and strict clippy. The existing synchronous session path is documented; no worker/session architecture replacement or format compatibility layer is introduced. Work: WRK-0016 / DEC-0001 / PLN-0001 Commit and push explicitly authorized by the user after completion.
149 lines
6.2 KiB
Rust
149 lines
6.2 KiB
Rust
//! GPU readback qualification of the actual host blit, not a software geometry mirror.
|
|
#[path = "../src/presentation_blit.rs"]
|
|
mod presentation_blit;
|
|
#[path = "../src/viewport.rs"]
|
|
mod viewport;
|
|
use pixels::{PixelsBuilder, SurfaceTexture, wgpu};
|
|
use winit::{
|
|
application::ApplicationHandler,
|
|
event_loop::{ActiveEventLoop, EventLoop},
|
|
window::Window,
|
|
};
|
|
|
|
#[derive(Default)]
|
|
struct Probe;
|
|
impl ApplicationHandler for Probe {
|
|
fn resumed(&mut self, events: &ActiveEventLoop) {
|
|
let window = Box::leak(Box::new(
|
|
events
|
|
.create_window(
|
|
Window::default_attributes()
|
|
.with_title("PROMETEU graphics qualification")
|
|
.with_inner_size(winit::dpi::PhysicalSize::new(640, 360)),
|
|
)
|
|
.unwrap(),
|
|
));
|
|
let size = window.inner_size();
|
|
let mut pixels =
|
|
PixelsBuilder::new(640, 360, SurfaceTexture::new(size.width, size.height, &*window))
|
|
.build()
|
|
.unwrap();
|
|
for (i, p) in pixels.frame_mut().as_chunks_mut::<4>().0.iter_mut().enumerate() {
|
|
let (x, y) = (i % 640, i / 640);
|
|
// Single-pixel checkerboard detects smoothing; all channels equal avoid channel-order ambiguity.
|
|
let value = if (x + y) % 2 == 0 { 255 } else { 0 };
|
|
p.copy_from_slice(&[value, value, value, 255]);
|
|
}
|
|
// Exercise real surface acquisition/upload/shader validation too.
|
|
let blit = presentation_blit::PresentationBlit::new(&pixels);
|
|
pixels
|
|
.render_with(|e, t, _| {
|
|
blit.render(
|
|
e,
|
|
t,
|
|
viewport::Viewport::new((size.width, size.height), (640, 360)).unwrap(),
|
|
);
|
|
Ok(())
|
|
})
|
|
.unwrap();
|
|
let ctx = pixels.context();
|
|
// A newly created macOS surface may be occluded: render_with then returns
|
|
// without uploading. Offscreen verification must establish its own input.
|
|
ctx.queue.write_texture(
|
|
wgpu::TexelCopyTextureInfo {
|
|
texture: &ctx.texture,
|
|
mip_level: 0,
|
|
origin: wgpu::Origin3d::ZERO,
|
|
aspect: wgpu::TextureAspect::All,
|
|
},
|
|
pixels.frame(),
|
|
wgpu::TexelCopyBufferLayout {
|
|
offset: 0,
|
|
bytes_per_row: Some(640 * 4),
|
|
rows_per_image: Some(360),
|
|
},
|
|
ctx.texture_extent,
|
|
);
|
|
for (w, h) in [(1280u32, 720u32), (1000, 700), (320, 240), (641, 361)] {
|
|
let view = viewport::Viewport::new((w, h), (640, 360)).unwrap();
|
|
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
|
|
label: Some("blit-readback"),
|
|
size: wgpu::Extent3d { width: w, height: h, depth_or_array_layers: 1 },
|
|
mip_level_count: 1,
|
|
sample_count: 1,
|
|
dimension: wgpu::TextureDimension::D2,
|
|
format: pixels.render_texture_format(),
|
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC,
|
|
view_formats: &[],
|
|
});
|
|
let stride = (w * 4).div_ceil(256) * 256;
|
|
let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
|
|
label: Some("readback"),
|
|
size: u64::from(stride) * u64::from(h),
|
|
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ,
|
|
mapped_at_creation: false,
|
|
});
|
|
let mut encoder = ctx.device.create_command_encoder(&Default::default());
|
|
blit.render(&mut encoder, &texture.create_view(&Default::default()), view);
|
|
encoder.copy_texture_to_buffer(
|
|
wgpu::TexelCopyTextureInfo {
|
|
texture: &texture,
|
|
mip_level: 0,
|
|
origin: wgpu::Origin3d::ZERO,
|
|
aspect: wgpu::TextureAspect::All,
|
|
},
|
|
wgpu::TexelCopyBufferInfo {
|
|
buffer: &buffer,
|
|
layout: wgpu::TexelCopyBufferLayout {
|
|
offset: 0,
|
|
bytes_per_row: Some(stride),
|
|
rows_per_image: Some(h),
|
|
},
|
|
},
|
|
wgpu::Extent3d { width: w, height: h, depth_or_array_layers: 1 },
|
|
);
|
|
ctx.queue.submit([encoder.finish()]);
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
|
buffer.slice(..).map_async(wgpu::MapMode::Read, move |result| tx.send(result).unwrap());
|
|
ctx.device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
|
|
rx.recv().unwrap().unwrap();
|
|
let data = buffer.slice(..).get_mapped_range();
|
|
let mut checked = 0;
|
|
for y in 0..h {
|
|
for x in 0..w {
|
|
let offset = (y * stride + x * 4) as usize;
|
|
let rgb = &data[offset..offset + 3];
|
|
// Every output pixel is black or white: any intermediate value means smoothing.
|
|
assert!(
|
|
rgb == [0, 0, 0] || rgb == [255, 255, 255],
|
|
"filtered pixel at {w}x{h}:({x},{y})={rgb:?}"
|
|
);
|
|
if let Some((nx, ny)) = view.inverse(x as f64 + 0.5, y as f64 + 0.5) {
|
|
let expected = if (nx + ny) % 2 == 0 { 255 } else { 0 };
|
|
assert_eq!(
|
|
rgb, [expected; 3],
|
|
"GPU/input transform mismatch at {w}x{h}:({x},{y})"
|
|
);
|
|
checked += 1;
|
|
} else {
|
|
assert_eq!(rgb, [0, 0, 0], "bar");
|
|
}
|
|
}
|
|
}
|
|
assert!(checked > 0);
|
|
println!("GPU_NEAREST_PASS={w}x{h} checked={checked}");
|
|
}
|
|
events.exit();
|
|
}
|
|
fn window_event(
|
|
&mut self,
|
|
_: &ActiveEventLoop,
|
|
_: winit::window::WindowId,
|
|
_: winit::event::WindowEvent,
|
|
) {
|
|
}
|
|
}
|
|
fn main() {
|
|
EventLoop::new().unwrap().run_app(&mut Probe).unwrap();
|
|
}
|