Files
prometeu-runtime/crates/host/prometeu-host-desktop-winit/src/presentation_blit.rs
T
bquarkz a32f834b2b
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
feat(graphics): migrate native target to 640x360
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.
2026-11-20 10:34:45 +00:00

108 lines
4.4 KiB
Rust

//! Host-only blit: pixels' built-in PixelPerfect path crops below 1x and Fill smooths.
use crate::viewport::Viewport;
use pixels::{Pixels, wgpu};
pub(crate) struct PresentationBlit {
pipeline: wgpu::RenderPipeline,
texture: wgpu::BindGroup,
geometry: wgpu::Buffer,
queue: wgpu::Queue,
}
impl PresentationBlit {
pub fn new(pixels: &Pixels<'_>) -> Self {
let device = pixels.device();
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("native-nearest-blit"),
source: wgpu::ShaderSource::Wgsl(
r#"
struct Vertex { @builtin(position) position: vec4f, @location(0) uv: vec2f }
@vertex fn vs(@builtin(vertex_index) i: u32) -> Vertex {
let p = array<vec2f,3>(vec2f(-1,-1),vec2f(3,-1),vec2f(-1,3));
var v: Vertex; v.position=vec4f(p[i],0,1); v.uv=vec2f((p[i].x+1)*0.5,(1-p[i].y)*0.5); return v;
}
@group(0) @binding(0) var image: texture_2d<f32>;
@group(0) @binding(1) var<uniform> geometry: vec4f;
@fragment fn fs(v: Vertex) -> @location(0) vec4f {
let size=vec2i(textureDimensions(image));
let pixel=clamp(vec2i(floor((v.position.xy-geometry.xy)/geometry.z)),vec2i(0),size-vec2i(1));
return textureLoad(image,pixel,0);
}"#
.into(),
),
});
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("native-nearest-blit"),
layout: None,
vertex: wgpu::VertexState {
module: &shader,
entry_point: Some("vs"),
buffers: &[],
compilation_options: Default::default(),
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: Some("fs"),
compilation_options: Default::default(),
targets: &[Some(wgpu::ColorTargetState {
format: pixels.render_texture_format(),
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::ALL,
})],
}),
primitive: Default::default(),
depth_stencil: None,
multisample: Default::default(),
multiview_mask: None,
cache: None,
});
let view = pixels.context().texture.create_view(&Default::default());
let geometry = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("native-viewport"),
size: 16,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let texture = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("native-nearest-texture"),
layout: &pipeline.get_bind_group_layout(0),
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(&view),
},
wgpu::BindGroupEntry { binding: 1, resource: geometry.as_entire_binding() },
],
});
Self { pipeline, texture, geometry, queue: pixels.context().queue.clone() }
}
pub fn render(
&self,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
viewport: Viewport,
) {
let geometry = [viewport.x, viewport.y, viewport.scale, 0.0].map(f32::to_ne_bytes);
self.queue.write_buffer(&self.geometry, 0, geometry.as_flattened());
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("native-nearest-present"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
});
pass.set_pipeline(&self.pipeline);
pass.set_bind_group(0, &self.texture, &[]);
pass.set_viewport(viewport.x, viewport.y, viewport.width, viewport.height, 0.0, 1.0);
pass.draw(0..3, 0..1);
}
}