🆕 Scale a frame of another size than its place to fill it
A display now offers smaller modes, and its window keeps its size at them, so the window's draw must fill the window with a frame smaller than it. The draw copied the scanout, and a BGRA8 surface, a guest pixel to a pixel at the image's top left, clipped: a smaller mode showed in a corner. One rule now draws what the display shows: a copy where the frame (the scanout, or a presented surface in the drawable's format) is the size of its place, the layout's region, and otherwise a draw of the display's present shaders that samples it over the whole place, filtering linearly. The scanout is sampled through a texture over its pixels in its pages' import, in place, made at its first such draw and kept with the import (made again after a recovery); a refused one keeps the window's frame and counts as the display's refused view (display-view-refused), as a refused view of a surface does. The colour's draw follows the same rule. The host's read of the display (QEMU's console and screendump) draws with it, so it shows a smaller mode scaled to the display's first mode. What the host observes: at a smaller mode the window, and the read, show the guest's frame filling the image's place; while a resized window waits for the guest's next mode, the old one is scaled to the new place rather than clipped. At the display's first mode every draw is the one it was, and makes nothing more: a test holds it for the scanout, a BGRA8 surface and WindowServer's 10-bit one, and others hold the sampled draws and the refused texture; a GPU test holds that a 2 x 2 scanout and surface fill an 8 x 8 drawable on the Vulkan platform. The read's tests held the old draw, a small scanout at the read's top left and the rest black: they now read a scanout of the mode's size pixel for pixel, a smaller scanout scaled over the whole read with its corners at the read's corners, and a smaller surface drawn through the display's view of it, not copied.
This commit is contained in:
1 parent
934ce50043
commit
fb3108a832
5 files changed
+553
-87
No files matched your search
@@ -9,12 +9,14 @@
|
||||
//!
|
||||
//! **The window** ([`WindowScreen`]) is a display window of `reims-vgpu-window` that keeps its size
|
||||
//! (`WindowConfig::keeps_its_size`): the guest follows it. It opens sized for the config's mode,
|
||||
//! else 1920 × 1080, and the display then offers the guest one mode, the window's size in pixels as
|
||||
//! else 1920 × 1080, and the display then offers the guest first the window's size in pixels as
|
||||
//! its render thread last drew into it, its width rounded down to a multiple of 16 and its height
|
||||
//! to even, so each row of a guest surface of the mode's width starts and ends on a 64-byte line of
|
||||
//! the GPU's memory (`geometry::offered_mode`; a window of other pixels shows the guest's mode
|
||||
//! unscaled, beside up to 15 columns and a row of black), at the refresh rate of the host screen
|
||||
//! it opened on; when that size changes (the person resized the window) the device tells the guest
|
||||
//! unscaled, beside up to 15 columns and a row of black), then the smaller modes of its ratio
|
||||
//! (`reims-vgpu-graphics`' `display::offered_modes`), which the window shows scaled to fill it,
|
||||
//! keeping its size (`sink`, "Sizes"), every one at the refresh rate of the host screen it opened
|
||||
//! on; when that size changes (the person resized the window) the device tells the guest
|
||||
//! (`DISPLAY_CHANGED`). The guest's scanout shows in the window at once and then again at each of
|
||||
//! the display's refreshes, at the screen's rate, while no presented surface shows in its place;
|
||||
//! the window draws it at the screen's pace. While a surface shows, a refresh draws nothing: the
|
||||
@@ -26,7 +28,7 @@
|
||||
//! draws the guest's cursor into its image there itself, and the host's cursor is invisible over
|
||||
//! the image (`reims_vgpu_window::handle`'s module doc; `sink`, "The guest's cursor").
|
||||
//!
|
||||
//! **Without a window** the display offers 1920 × 1080 at 60 Hz and shows nothing.
|
||||
//! **Without a window** the display offers 1920 × 1080 at 60 Hz first, and shows nothing.
|
||||
//!
|
||||
//! **Several displays** ([`GraphicsConfig::display_count`], docs/graphics-kext/design.md,
|
||||
//! "Multiple displays"): each display has what display 0 has, its own window (display `i`'s on the
|
||||
@@ -5439,7 +5441,7 @@ impl Screen for WindowScreen {
|
||||
/// The window's size in pixels as last drawn into, else the mode it opened for, its width
|
||||
/// rounded down to a multiple of 16 and its height to even ([`geometry::offered_mode`]), at
|
||||
/// its host screen's rate, with the backing scale it was last drawn at (none before its first
|
||||
/// draw).
|
||||
/// draw): the display's first mode, which its smaller modes follow.
|
||||
fn mode(&self) -> Mode {
|
||||
let drawn = *self.shown.drawable.lock();
|
||||
let (width, height) = geometry::offered_mode(drawn.map_or_else(
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
//! texture of the display's mode, the size the guest is told (the window's size in pixels, or
|
||||
//! 1920 × 1080 without a window, sized to the display's scanout room on a device of several
|
||||
//! displays: `reims-vgpu-graphics`' `display::offered_in_room`), placed and clipped as in a
|
||||
//! drawable of that size. Where the
|
||||
//! drawable of that size: a frame of the guest's smaller mode is drawn scaled over the whole
|
||||
//! texture (`sink`'s module doc, "Sizes"), as the window shows it. Where the
|
||||
//! guest has no scanout and presents no surface the display shows black, and so does the read,
|
||||
//! as it does where the platform refuses the display's view of a presented surface (`sink`'s
|
||||
//! module doc, "The display's view").
|
||||
|
||||
@@ -4,21 +4,29 @@
|
||||
//! buffer into the drawable's texture, at the image's place, in one command buffer: the GPU reads
|
||||
//! the guest's pixels in place, and the CPU copies nothing.
|
||||
//!
|
||||
//! **Sizes.** The guest sets a scanout of the size the display offers, the window's size in
|
||||
//! **Sizes.** The guest sets a scanout of a mode the display offers: first the window's size in
|
||||
//! pixels, its width rounded down to a multiple of 16 and its height to even, so the image is the
|
||||
//! whole drawable, or, for a drawable of other pixels, all of it but up to 15 columns and a row,
|
||||
//! which stay black: the layout draws that mode a guest pixel to a pixel, at the drawable's top
|
||||
//! left (`geometry::offered_mode`). While the two differ
|
||||
//! otherwise (the window resized, the guest not yet following), the blit copies what fits of the
|
||||
//! scanout at the image's top left, clipped to the drawable, after a clear of the drawable to
|
||||
//! black: a blit cannot scale, and the guest's next mode makes the sizes match again.
|
||||
//! left (`geometry::offered_mode`); or a smaller mode of its ratio (`reims-vgpu-graphics`'
|
||||
//! `display::offered_modes`), which the layout scales to fill the drawable, the window keeping
|
||||
//! its size. One rule draws what the display shows, the scanout or a presented surface: a copy
|
||||
//! where it is the size of the image's place (the layout's region), and otherwise a draw of the
|
||||
//! display's present shaders (core's [`DisplayPipelineCache`]), which sample it over the whole
|
||||
//! region, filtering linearly, so it fills the region whatever its size: a smaller mode, and the
|
||||
//! guest's last mode while the window is resized and the guest not yet following. The scanout's
|
||||
//! draw samples a texture over the scanout's pixels in its import (below), made at its first such
|
||||
//! draw and kept with the import; where the platform refuses it the draw is `None`, counted as
|
||||
//! the display's refused view is ("The display's view"). At the display's first mode the draw is
|
||||
//! the copy it was, and makes nothing more.
|
||||
//!
|
||||
//! **A presented surface.** While the display pipe shows an IOSurface (`PRESENT_SURFACE`), the
|
||||
//! draw puts the texture the decoder made over it into the drawable instead, on the GPU: a copy,
|
||||
//! texture to texture, where the two have one pixel format (BGRA8, with or without sRGB), and
|
||||
//! otherwise a draw of the display's present shaders (core's [`DisplayPipelineCache`]), which
|
||||
//! sample the surface in its own format (WindowServer's display surfaces are 10-bit,
|
||||
//! `BGR10A2Unorm`) and write the drawable's. The first surface of each format is logged.
|
||||
//! texture to texture, where the two have one pixel format (BGRA8, with or without sRGB) and the
|
||||
//! surface is the size of the image's place ("Sizes"), and otherwise a draw of the display's
|
||||
//! present shaders, which sample the surface in its own format (WindowServer's display surfaces
|
||||
//! are 10-bit, `BGR10A2Unorm`) and write the drawable's. The first surface of each format
|
||||
//! is logged.
|
||||
//!
|
||||
//! **The display's view.** The passes that sample a presented surface (the present shaders'
|
||||
//! and the colour's) read its texture through the display's own view of it
|
||||
@@ -69,8 +77,9 @@
|
||||
//! a presented surface is drawn into the drawable by the colour's fragment function
|
||||
//! (`displayPipeColorFragment`), in place of the copy or the plain present shaders, and the
|
||||
//! scanout by its twin (`displayPipeColorScanoutFragment`), which reads the guest's pixels in
|
||||
//! place from the imported pages, as the blit does, one drawable pixel for each, clipped as the
|
||||
//! blit clips. The colour's buffers are made again only when a present changes it. With every
|
||||
//! place from the imported pages, as the blit does, one drawable pixel for each, where the
|
||||
//! scanout is the size of the image's place; a scanout of another size, by the surface's
|
||||
//! function over the scanout's texture ("Sizes"). The colour's buffers are made again only when a present changes it. With every
|
||||
//! stage off, the draw is as before.
|
||||
//!
|
||||
//! **The colour as a table.** A colour with no matrix maps each channel on its own: its output
|
||||
@@ -96,7 +105,10 @@
|
||||
//! its size, so the region's other pages stay the guest's alone: an import pins what it covers
|
||||
//! (the Vulkan platform's does, on every driver), and the region's untouched pages then cost the
|
||||
//! host nothing (`Region`). A refused import is logged once for its pages, and the window shows
|
||||
//! nothing of that scanout. The buffer's deallocator holds the region, which keeps the region
|
||||
//! nothing of that scanout. A draw that samples the scanout ("Sizes") reads it through a texture
|
||||
//! over the import's bytes, in place, kept with the import while the scanout keeps its shape and
|
||||
//! made again after a recovery of the device. The buffer's deallocator holds the region, which
|
||||
//! keeps the region
|
||||
//! mapped while a command buffer still reads it: Metal (or the runtime) runs it once the buffer
|
||||
//! has gone, after the sink, a later import and every command buffer that used it.
|
||||
//!
|
||||
@@ -472,8 +484,19 @@ pub(crate) struct ScanoutImport<P: Platform> {
|
||||
pub(crate) length: u64,
|
||||
/// The pages as a no-copy buffer; `None` where the platform refused them.
|
||||
pub(crate) buffer: Option<P::Buffer>,
|
||||
/// A texture over the buffer's bytes of the scanout it was made for, which a draw that
|
||||
/// samples the scanout reads (the module doc, "Sizes"); made at the first such draw.
|
||||
texture: Option<(Scanout, P::Texture)>,
|
||||
}
|
||||
|
||||
/// The scanout's pixel format, `MTLPixelFormatBGRA8Unorm` (`kIO32BGRAPixelFormat`'s bytes).
|
||||
const SCANOUT_FORMAT: u64 = 80;
|
||||
/// `MTLTextureUsageShaderRead`: a texture over the scanout's pixels is only sampled.
|
||||
const SCANOUT_TEXTURE_USAGE: u64 = 0x1;
|
||||
/// The resource options of the scanout's import and of a texture over it:
|
||||
/// `MTLResourceStorageModeShared`, the CPU's pages.
|
||||
const IMPORT_OPTIONS: u64 = 0;
|
||||
|
||||
/// What draws a presented surface of another format into the drawable: core's display pipelines
|
||||
/// and the full-viewport strip they draw (positions at vertex buffer 0, texture coordinates at 1).
|
||||
struct Converter<P: Platform> {
|
||||
@@ -582,8 +605,8 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
}
|
||||
|
||||
/// Lets go of the objects the draws made and keep (the converter, the colour's functions,
|
||||
/// pipelines, buffers and table, the ramps, and the cursor's and the overlay's pipelines and
|
||||
/// textures)
|
||||
/// pipelines, buffers and table, the ramps, the texture over the scanout's import, and the
|
||||
/// cursor's and the overlay's pipelines and textures)
|
||||
/// where the device recovered since they were made ([`GpuDevice::recoveries`], the module
|
||||
/// doc, "A recovered device"): the next draw that needs one makes it again on the device's
|
||||
/// new GPU device. The scanout's import is a no-copy buffer over the region's pages, which a
|
||||
@@ -607,6 +630,9 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
*self.color_table.lock() = None;
|
||||
self.ramps.lock().clear();
|
||||
self.scanout_ramp.forget();
|
||||
if let Some(import) = self.import.lock().as_mut() {
|
||||
import.texture = None;
|
||||
}
|
||||
*self.cursor.lock() = CursorPass::cursor();
|
||||
*self.overlay.lock() = CursorPass::overlay();
|
||||
}
|
||||
@@ -652,12 +678,59 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
start,
|
||||
length,
|
||||
buffer: self.import_pages(start, length),
|
||||
texture: None,
|
||||
});
|
||||
}
|
||||
let buffer = import.as_ref()?.buffer.as_ref()?.clone_ref();
|
||||
Some((buffer, first - start))
|
||||
}
|
||||
|
||||
/// A texture over `scanout`'s pixels in its pages' import, for a draw that samples it (the
|
||||
/// module doc, "Sizes"): BGRA8, `stride` bytes a row, from where its first row starts, in
|
||||
/// place. Made at the first such draw of the scanout and kept with the import; `None`, with
|
||||
/// the refusal counted and logged as the display's refused view is, where the platform
|
||||
/// refuses the pages or the texture.
|
||||
fn scanout_texture(&self, scanout: &Scanout) -> Option<P::Texture> {
|
||||
let (buffer, offset) = self.scanout_buffer(scanout)?;
|
||||
let mut import = self.import.lock();
|
||||
let import = import.as_mut()?;
|
||||
if let Some((made_for, texture)) = &import.texture
|
||||
&& made_for == scanout
|
||||
{
|
||||
return Some(texture.clone_ref());
|
||||
}
|
||||
import.texture = None;
|
||||
let descriptor = self.platform.texture_descriptor(&TextureDesc {
|
||||
pixel_format: SCANOUT_FORMAT,
|
||||
width: u64::from(scanout.width),
|
||||
height: u64::from(scanout.height),
|
||||
usage: SCANOUT_TEXTURE_USAGE,
|
||||
resource_options: Some(IMPORT_OPTIONS),
|
||||
..TextureDesc::default()
|
||||
});
|
||||
let made = no_catch(buffer.new_texture(
|
||||
OnFault::Die,
|
||||
&descriptor,
|
||||
offset,
|
||||
u64::from(scanout.stride),
|
||||
));
|
||||
let Some(texture) = made else {
|
||||
reims_vgpu_vulkan::answer::count_kind(VIEW_REFUSED_CODE);
|
||||
log::warn!(
|
||||
target: "reims_vgpu::graphics", kind:% = VIEW_REFUSED_CODE;
|
||||
"the platform refused a texture over the scanout's pixels ({}x{}, {} bytes a row, \
|
||||
at 0x{:x} in the region): the window keeps the frame it shows ({VIEW_REFUSED_CODE})",
|
||||
scanout.width,
|
||||
scanout.height,
|
||||
scanout.stride,
|
||||
scanout.offset
|
||||
);
|
||||
return None;
|
||||
};
|
||||
import.texture = Some((*scanout, texture.clone_ref()));
|
||||
Some(texture)
|
||||
}
|
||||
|
||||
/// The `length` bytes of the region at `start` as a no-copy buffer; `None`, logged, where
|
||||
/// the platform refuses them.
|
||||
fn import_pages(&self, start: u64, length: u64) -> Option<P::Buffer> {
|
||||
@@ -678,7 +751,7 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
no_catch(self.device.new_buffer_over_host_memory(
|
||||
OnFault::Die,
|
||||
bytes,
|
||||
0,
|
||||
IMPORT_OPTIONS,
|
||||
Some(Box::new(move || drop(keep))),
|
||||
))
|
||||
});
|
||||
@@ -901,7 +974,10 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
let (from, to) = (surface.pixel_format(), texture.pixel_format());
|
||||
self.presented.seen_format(from, to);
|
||||
let copied = BGRA8_FORMATS.contains(&from) && BGRA8_FORMATS.contains(&to);
|
||||
let drawn = if color.is_none() && copied {
|
||||
// A copy where the surface is its place's size, else a pass that samples it over
|
||||
// the place (the module doc, "Sizes").
|
||||
let unscaled = (surface.width(), surface.height()) == (region.width, region.height);
|
||||
let drawn = if color.is_none() && copied && unscaled {
|
||||
self.encode_surface(&surface, texture, region)
|
||||
} else {
|
||||
// A pass samples the surface through the display's view of it (the module doc,
|
||||
@@ -934,9 +1010,26 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
self.clear(&command_buffer, texture);
|
||||
return Some((command_buffer, None));
|
||||
}
|
||||
let command_buffer = match &color {
|
||||
Some((changes, color)) => self.encode_scanout_colored(*changes, color, texture, region),
|
||||
None => self.encode_scanout(texture, region),
|
||||
let scanout = (*self.shown.scanout.lock())?;
|
||||
let unscaled =
|
||||
(u64::from(scanout.width), u64::from(scanout.height)) == (region.width, region.height);
|
||||
let command_buffer = if unscaled {
|
||||
match &color {
|
||||
Some((changes, color)) => {
|
||||
self.encode_scanout_colored(*changes, color, texture, region)
|
||||
}
|
||||
None => self.encode_scanout(texture, region),
|
||||
}
|
||||
} else {
|
||||
// Of another size than its place: a pass samples it over the place (the module doc,
|
||||
// "Sizes"), through a texture over its pixels.
|
||||
let read = self.scanout_texture(&scanout)?;
|
||||
match &color {
|
||||
Some((changes, color)) => {
|
||||
self.encode_colored(*changes, color, &read, texture, region)
|
||||
}
|
||||
None => self.encode_converted(&read, texture, region),
|
||||
}
|
||||
}?;
|
||||
Some((command_buffer, None))
|
||||
}
|
||||
@@ -994,10 +1087,11 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
Some(command_buffer)
|
||||
}
|
||||
|
||||
/// A command buffer of the sink's queue with the presented `surface` drawn into `texture` at
|
||||
/// `region` through `color` (the module doc), after a clear of the drawable to black where
|
||||
/// `region` does not cover it; not committed. `None`, with nothing committed, where the platform refuses the colour's
|
||||
/// pipeline or buffers.
|
||||
/// A command buffer of the sink's queue with `surface`, a presented surface or a texture over
|
||||
/// the scanout's pixels, drawn into `texture` over `region` through `color` (the module doc),
|
||||
/// after a clear of the drawable to black where `region` does not cover it; not committed.
|
||||
/// `None`, with nothing committed, where the platform refuses the colour's pipeline or
|
||||
/// buffers.
|
||||
fn encode_colored(
|
||||
&self,
|
||||
changes: u64,
|
||||
@@ -1569,11 +1663,12 @@ impl<P: ApiPlatform> ScanoutDraw<P> {
|
||||
})
|
||||
}
|
||||
|
||||
/// A command buffer of the sink's queue with the presented `surface` drawn into `texture` at
|
||||
/// `region` by the display's present shaders, which convert its format to the drawable's,
|
||||
/// after a clear of the drawable to black where `region` does not cover it ([`pass_load`]);
|
||||
/// not committed. `None`, with nothing committed,
|
||||
/// where the converter or a pipeline for the drawable's format is refused.
|
||||
/// A command buffer of the sink's queue with `surface`, a presented surface or a texture over
|
||||
/// the scanout's pixels, drawn into `texture` over `region` by the display's present shaders,
|
||||
/// which convert its format to the drawable's and scale it to the region (the module doc,
|
||||
/// "Sizes"), after a clear of the drawable to black where `region` does not cover it
|
||||
/// ([`pass_load`]); not committed. `None`, with nothing committed, where the converter or a
|
||||
/// pipeline for the drawable's format is refused.
|
||||
fn encode_converted(
|
||||
&self,
|
||||
surface: &P::Texture,
|
||||
@@ -1709,6 +1804,8 @@ mod tests {
|
||||
const NAMED: &str = "newFunctionWithName:";
|
||||
const FRAGMENT_TEXTURE: &str = "setFragmentTexture:atIndex:";
|
||||
const REPLACE: &str = "replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:";
|
||||
const NEW_OVER_BUFFER: &str = "newTextureWithDescriptor:offset:bytesPerRow:";
|
||||
const RENDER_ENCODER: &str = "renderCommandEncoderWithDescriptor:";
|
||||
|
||||
/// The scanout `rig` shows.
|
||||
const SCANOUT: Scanout = Scanout {
|
||||
@@ -2993,6 +3090,192 @@ mod tests {
|
||||
assert!(log.sels_since(mark).contains(&"commit"));
|
||||
}
|
||||
|
||||
/// A texture of `format`, `width` x `height`, on the draw's device.
|
||||
fn texture_sized(
|
||||
draw: &ScanoutDraw<FakePlatform>,
|
||||
format: u64,
|
||||
(width, height): (u64, u64),
|
||||
) -> <FakePlatform as Platform>::Texture {
|
||||
let descriptor = draw.platform.texture_descriptor(&TextureDesc {
|
||||
pixel_format: format,
|
||||
width,
|
||||
height,
|
||||
..TextureDesc::default()
|
||||
});
|
||||
draw.device
|
||||
.new_texture(OnFault::Die, &descriptor)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// The calls since `mark` whose selector starts with `prefix`.
|
||||
fn starting(platform: &FakePlatform, mark: u64, prefix: &str) -> usize {
|
||||
(platform.call_log().sels_since(mark).iter())
|
||||
.filter(|s| s.starts_with(prefix))
|
||||
.count()
|
||||
}
|
||||
|
||||
/// The viewports set since `mark`.
|
||||
fn viewports(platform: &FakePlatform, mark: u64) -> Vec<Arg> {
|
||||
(platform.call_log().since(mark).into_iter())
|
||||
.filter(|c| c.sel == "setViewport:")
|
||||
.map(|c| c.args[0].clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A viewport over `place`.
|
||||
fn viewport_over(place: PixelRect) -> Arg {
|
||||
Arg::val(&MtlViewport {
|
||||
origin_x: place.x as f64,
|
||||
origin_y: place.y as f64,
|
||||
width: place.width as f64,
|
||||
height: place.height as f64,
|
||||
znear: 0.0,
|
||||
zfar: 1.0,
|
||||
})
|
||||
}
|
||||
|
||||
/// At the display's first mode, each frame the size of its place (the window's pixels), every
|
||||
/// draw is the one it was before the display offered smaller modes, and makes nothing more:
|
||||
/// the scanout a copy from its pages; a BGRA8 surface a texture copy, with no view; a 10-bit
|
||||
/// surface, WindowServer's, one pass of the present shaders through the display's view. No
|
||||
/// draw makes a texture over the scanout's pages
|
||||
#[test]
|
||||
fn at_the_display_s_first_mode_every_draw_is_as_before() {
|
||||
let (platform, draw, presented, drawable) = rig();
|
||||
let log = platform.call_log();
|
||||
let mark = log.mark();
|
||||
let _ = draw
|
||||
.encode(&drawable, WHOLE, None, None)
|
||||
.expect("the scanout");
|
||||
assert_eq!(count_since(&platform, mark, COPY_IN), 1);
|
||||
assert_eq!(starting(&platform, mark, RENDER_ENCODER), 0);
|
||||
assert_eq!(count_since(&platform, mark, NEW_OVER_BUFFER), 0);
|
||||
|
||||
let surface = texture(&draw, 80);
|
||||
let _held = show_held(&presented, &surface, false);
|
||||
let mark = log.mark();
|
||||
let _ = draw
|
||||
.encode(&drawable, WHOLE, None, None)
|
||||
.expect("a BGRA8 surface");
|
||||
assert_eq!(starting(&platform, mark, "copyFromTexture"), 1);
|
||||
assert_eq!(starting(&platform, mark, RENDER_ENCODER), 0);
|
||||
assert_eq!(count_since(&platform, mark, NEW_VIEW), 0);
|
||||
assert_eq!(count_since(&platform, mark, NEW_OVER_BUFFER), 0);
|
||||
|
||||
let surface = texture(&draw, 94);
|
||||
let _held = show_held(&presented, &surface, false);
|
||||
let mark = log.mark();
|
||||
let _ = draw
|
||||
.encode(&drawable, WHOLE, None, None)
|
||||
.expect("a 10-bit surface");
|
||||
assert_eq!(starting(&platform, mark, RENDER_ENCODER), 1);
|
||||
assert_eq!(count_since(&platform, mark, DRAW), 1);
|
||||
assert_eq!(viewports(&platform, mark), [viewport_over(WHOLE)]);
|
||||
assert_eq!(starting(&platform, mark, "copyFrom"), 0);
|
||||
assert_eq!(count_since(&platform, mark, NEW_OVER_BUFFER), 0);
|
||||
}
|
||||
|
||||
/// A frame of another size than its place, a smaller mode's or the guest's last mode in a
|
||||
/// window resized since, is sampled over its whole place by the present shaders, never copied:
|
||||
/// a BGRA8 surface through the display's view of it, and the scanout through a texture over its
|
||||
/// pixels in its pages' import, in place (from its first row's offset in the import, its
|
||||
/// stride a row), made at the first such draw and kept while the scanout keeps its shape
|
||||
#[test]
|
||||
fn a_frame_of_another_size_than_its_place_is_sampled_over_it() {
|
||||
let (platform, draw, presented, drawable) = rig();
|
||||
let log = platform.call_log();
|
||||
let smaller = Scanout {
|
||||
width: 32,
|
||||
height: 16,
|
||||
stride: 256,
|
||||
offset: SCANOUT.offset + 0x100,
|
||||
};
|
||||
let shrunk = PixelRect {
|
||||
x: 16,
|
||||
y: 8,
|
||||
width: 32,
|
||||
height: 16,
|
||||
};
|
||||
// The smaller scanout, drawn twice; then the first mode's in a window shrunk since.
|
||||
for (place, scanout, makes) in [
|
||||
(WHOLE, smaller, true),
|
||||
(WHOLE, smaller, false),
|
||||
(shrunk, SCANOUT, true),
|
||||
] {
|
||||
*draw.shown.scanout.lock() = Some(scanout);
|
||||
let mark = log.mark();
|
||||
let _ = draw.encode(&drawable, place, None, None).expect("a draw");
|
||||
let made: Vec<Call> = (log.since(mark).into_iter())
|
||||
.filter(|c| c.sel == NEW_OVER_BUFFER)
|
||||
.collect();
|
||||
let import = draw.import.lock();
|
||||
let import = import.as_ref().unwrap();
|
||||
let (made_for, over) = import.texture.as_ref().expect("a texture over the scanout");
|
||||
assert_eq!(*made_for, scanout);
|
||||
assert_eq!(made.len(), usize::from(makes), "{place:?} {scanout:?}");
|
||||
if makes {
|
||||
assert_eq!(made[0].obj, import.buffer.as_ref().unwrap().id());
|
||||
let offset = scanout.offset - import.start;
|
||||
assert_eq!(made[0].args[1].as_u64(), Some(offset));
|
||||
assert_eq!(made[0].args[2].as_u64(), Some(u64::from(scanout.stride)));
|
||||
}
|
||||
assert_eq!(count_since(&platform, mark, COPY_IN), 0);
|
||||
assert_eq!(fragment_textures(&platform, mark), [(over.id(), 0)]);
|
||||
assert_eq!(viewports(&platform, mark), [viewport_over(place)]);
|
||||
}
|
||||
|
||||
let surface = texture_sized(&draw, 80, (32, 16));
|
||||
let view = Arc::<ShownView<FakePlatform>>::default();
|
||||
*presented.texture.lock() = Some(ShownTexture {
|
||||
texture: surface.clone_ref(),
|
||||
view: Arc::clone(&view),
|
||||
hold: Arc::new(DisplayHold {
|
||||
span: None,
|
||||
answers: Mutex::default(),
|
||||
queued: false,
|
||||
}),
|
||||
});
|
||||
let mark = log.mark();
|
||||
let _ = draw.encode(&drawable, WHOLE, None, None).expect("a draw");
|
||||
assert_eq!(starting(&platform, mark, "copyFrom"), 0);
|
||||
let viewed = view.made().expect("the display's view");
|
||||
assert_eq!(fragment_textures(&platform, mark), [(viewed.id(), 0)]);
|
||||
assert_eq!(viewports(&platform, mark), [viewport_over(WHOLE)]);
|
||||
}
|
||||
|
||||
/// Where the platform refuses the texture over the scanout's pixels a draw of another size
|
||||
/// would sample, the draw answers nothing, the refusal counted as the display's refused view:
|
||||
/// nothing is encoded; the next draw makes the texture and draws through it
|
||||
#[test]
|
||||
fn a_refused_texture_over_the_scanout_draws_nothing_and_is_counted() {
|
||||
use reims_vgpu_vulkan::core::testkit::Step;
|
||||
let (platform, draw, _presented, drawable) = rig();
|
||||
let log = platform.call_log();
|
||||
*draw.shown.scanout.lock() = Some(Scanout {
|
||||
width: 32,
|
||||
height: 16,
|
||||
..SCANOUT
|
||||
});
|
||||
let refused = || {
|
||||
(reims_vgpu_vulkan::answer::degradation_counts().into_iter())
|
||||
.find(|(code, _)| code == VIEW_REFUSED_CODE)
|
||||
.map_or(0, |(_, n)| n)
|
||||
};
|
||||
let before = refused();
|
||||
platform.script().push(NEW_OVER_BUFFER, Step::Nil);
|
||||
let mark = log.mark();
|
||||
assert!(draw.encode(&drawable, WHOLE, None, None).is_none());
|
||||
assert_eq!(refused(), before + 1);
|
||||
assert_eq!(starting(&platform, mark, RENDER_ENCODER), 0);
|
||||
assert_eq!(starting(&platform, mark, "copyFrom"), 0);
|
||||
|
||||
let mark = log.mark();
|
||||
let _ = draw.encode(&drawable, WHOLE, None, None).expect("a draw");
|
||||
assert_eq!(count_since(&platform, mark, NEW_OVER_BUFFER), 1);
|
||||
assert_eq!(count_since(&platform, mark, DRAW), 1);
|
||||
}
|
||||
|
||||
/// While the display shows a presented surface the guest placed at its index, the guest lets
|
||||
/// go of it and places a new texture of other pixels at that index: the display's next read
|
||||
/// still reads the shown surface's pixels, through the display's view of it, and the new
|
||||
@@ -3508,4 +3791,124 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// On the Vulkan platform a frame smaller than its place fills it, sampled over it: a 2 x 2
|
||||
/// scanout of four colours, its rows 256 bytes apart from a room's start as the kexts and the
|
||||
/// option ROM lay theirs, and a 2 x 2 BGRA8 surface of them, drawn over an 8 x 8 drawable,
|
||||
/// each corner of which is its colour's, and none of whose pixels is black
|
||||
#[test]
|
||||
fn on_vulkan_a_smaller_frame_fills_its_place() {
|
||||
let platform = crate::rt_test_end::platform();
|
||||
crate::entry::run(|_| a_smaller_frame_fills_its_place(&platform));
|
||||
}
|
||||
|
||||
/// [`on_vulkan_a_smaller_frame_fills_its_place`]'s body, inside the library's entry.
|
||||
fn a_smaller_frame_fills_its_place<P: ApiPlatform>(platform: &Arc<P>) {
|
||||
use reims_vgpu_graphics::wire::{RGFX_ALLOCATIONS_OFFSET, RGFX_SCANOUT_STRIDE_ALIGN};
|
||||
|
||||
// Red, green, blue and white, BGRA8, row by row.
|
||||
const COLOURS: [[u8; 4]; 4] = [
|
||||
[0, 0, 255, 255],
|
||||
[0, 255, 0, 255],
|
||||
[255, 0, 0, 255],
|
||||
[255, 255, 255, 255],
|
||||
];
|
||||
let region = Arc::new(crate::platform::test_region(
|
||||
&**platform,
|
||||
reims_vgpu_graphics::REGION_SIZE as usize,
|
||||
));
|
||||
let stride = RGFX_SCANOUT_STRIDE_ALIGN;
|
||||
for row in 0..2 {
|
||||
let bytes: Vec<u8> = COLOURS[row * 2..row * 2 + 2].concat();
|
||||
// SAFETY: the row lies inside the region, mapped while it lives.
|
||||
unsafe {
|
||||
let at = RGFX_ALLOCATIONS_OFFSET as usize + row * stride as usize;
|
||||
std::ptr::copy_nonoverlapping(bytes.as_ptr(), region.base().add(at), bytes.len());
|
||||
}
|
||||
}
|
||||
let shown = Arc::new(Shown::default());
|
||||
*shown.scanout.lock() = Some(Scanout {
|
||||
width: 2,
|
||||
height: 2,
|
||||
stride,
|
||||
offset: RGFX_ALLOCATIONS_OFFSET,
|
||||
});
|
||||
let presented = Arc::new(Presented::<P>::default());
|
||||
let draw = ScanoutDraw::new(Arc::clone(platform), ®ion, &shown, &presented).unwrap();
|
||||
let new_texture = |usage: u64, side: u64| {
|
||||
let descriptor = platform.texture_descriptor(&TextureDesc {
|
||||
pixel_format: 80,
|
||||
width: side,
|
||||
height: side,
|
||||
usage,
|
||||
resource_options: Some(0),
|
||||
..TextureDesc::default()
|
||||
});
|
||||
(platform.metal_device(None).unwrap())
|
||||
.new_texture(OnFault::Die, &descriptor)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
};
|
||||
let surface = new_texture(0x1, 2);
|
||||
let pixels = COLOURS.concat();
|
||||
// SAFETY: the bytes live across the call, which copies them out.
|
||||
let range = unsafe {
|
||||
HostRange::new(
|
||||
HostPtr::from_ptr(pixels.as_ptr().cast_mut()),
|
||||
pixels.len() as u64,
|
||||
)
|
||||
};
|
||||
surface
|
||||
.replace_region(
|
||||
MtlRegion {
|
||||
origin: MtlOrigin::new(0, 0, 0),
|
||||
size: MtlSize::new(2, 2, 1),
|
||||
},
|
||||
0,
|
||||
0,
|
||||
range,
|
||||
8,
|
||||
16,
|
||||
)
|
||||
.unwrap();
|
||||
let place = PixelRect {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 8,
|
||||
height: 8,
|
||||
};
|
||||
for source in ["the scanout", "the surface"] {
|
||||
*presented.texture.lock() = (source == "the surface").then(|| ShownTexture {
|
||||
texture: Handle::clone_ref(&surface),
|
||||
view: Arc::default(),
|
||||
hold: Arc::new(DisplayHold {
|
||||
span: None,
|
||||
answers: Mutex::default(),
|
||||
queued: false,
|
||||
}),
|
||||
});
|
||||
let target = new_texture(0x1 | 0x4, 8);
|
||||
let (command_buffer, hold) = draw.encode_shown(&target, place).expect(source);
|
||||
command_buffer.commit(OnFault::Die).unwrap();
|
||||
command_buffer.wait_until_completed(OnFault::Die).unwrap();
|
||||
assert_eq!(
|
||||
command_buffer.status(),
|
||||
CommandBufferStatus::COMPLETED,
|
||||
"{source}"
|
||||
);
|
||||
drop(hold);
|
||||
let mut bytes = vec![0; 8 * 8 * 4];
|
||||
platform.read_pixels(&target, &mut bytes, 8 * 4);
|
||||
let at = |x: usize, y: usize| -> [u8; 4] {
|
||||
bytes[(y * 8 + x) * 4..][..4].try_into().unwrap()
|
||||
};
|
||||
assert_eq!(
|
||||
[at(0, 0), at(7, 0), at(0, 7), at(7, 7)],
|
||||
COLOURS,
|
||||
"{source}: the corners"
|
||||
);
|
||||
let black = (0..64).find(|p| at(p % 8, p / 8) == [0, 0, 0, 255]);
|
||||
assert_eq!(black, None, "{source}: a black pixel in its place");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12344,9 +12344,10 @@ fn color_matrix(rows: [[f32; 4]; 3]) -> Vec<u8> {
|
||||
}
|
||||
|
||||
/// On the Vulkan platform, a display colour of the identity matrix reads as no colour: the
|
||||
/// scanout's bytes as the guest wrote them, its alpha included (a colour pass would make it
|
||||
/// opaque), with each of blue, green and red taking all 256 values; a matrix off the identity
|
||||
/// still draws through the colour, which swaps red and blue here and makes every pixel opaque
|
||||
/// bytes of a scanout of the display's mode as the guest wrote them, its alpha included (a colour
|
||||
/// pass would make it opaque), with each of blue, green and red taking all 256 values in its first
|
||||
/// rows; a matrix off the identity still draws through the colour, which swaps red and blue here
|
||||
/// and makes every pixel opaque
|
||||
#[test]
|
||||
fn on_vulkan_an_identity_colour_matrix_reads_as_no_colour() {
|
||||
let platform = crate::singleton::platform();
|
||||
@@ -12362,7 +12363,8 @@ fn on_vulkan_an_identity_colour_matrix_reads_as_no_colour() {
|
||||
..GraphicsConfig::default()
|
||||
};
|
||||
let device = GraphicsDevice::with_platform(platform, config).unwrap();
|
||||
let (width, height, stride) = (256usize, 4usize, 1024usize);
|
||||
// The pattern's 256 × 4 pixels at the top left of a scanout of the mode's size.
|
||||
let (width, height, stride) = (256usize, 4usize, 1920 * 4usize);
|
||||
let pixel = |x: usize, y: usize| -> [u8; 4] {
|
||||
let x = x as u8;
|
||||
let y = y as u8;
|
||||
@@ -12381,7 +12383,7 @@ fn on_vulkan_an_identity_colour_matrix_reads_as_no_colour() {
|
||||
device.mmio_write(RGFX_REG_STATUS.into(), RGFX_STATUS_DRIVER_READY);
|
||||
let mut guest = Guest::new(&device);
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(256, 4, 1024)),
|
||||
answered(&device, &mut guest, set_scanout(1920, 1080, 1920 * 4)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let keep = || {
|
||||
@@ -12455,11 +12457,13 @@ fn set_scanout(width: u32, height: u32, stride: u32) -> Vec<u8> {
|
||||
|
||||
/// The host's read of the display (`read_display`) has the display's mode, 1920 × 1080 without
|
||||
/// a window: a buffer short of it is refused with nothing written, and the size is given all the
|
||||
/// same. With no scanout the display shows black, and the read draws nothing. With one, the read
|
||||
/// blits it into its texture of the mode's size, kept from the read before, as the window draws
|
||||
/// it, waits for that draw and reads the texture back (the testkit's pixels read as zero). A
|
||||
/// presented surface is copied into the read's texture in place of the scanout. The guest is told
|
||||
/// nothing of any read
|
||||
/// same. With no scanout the display shows black, and the read draws nothing. With one of the
|
||||
/// mode's size, the read blits it into its texture of the mode's size, kept from the read before,
|
||||
/// as the window draws it, waits for that draw and reads the texture back (the testkit's pixels
|
||||
/// read as zero). A smaller scanout, a smaller mode's, is sampled over the whole texture through
|
||||
/// a texture over its pixels, as the window draws it, and never blitted. A presented surface is
|
||||
/// drawn into the read's texture in place of the scanout: this one, smaller than the mode, sampled
|
||||
/// over it through the display's view of it, never copied. The guest is told nothing of any read
|
||||
#[test]
|
||||
fn a_read_of_the_display_draws_what_it_shows() {
|
||||
let raised = Arc::new(AtomicU32::new(0));
|
||||
@@ -12504,7 +12508,7 @@ fn a_read_of_the_display_draws_what_it_shows() {
|
||||
|
||||
let (mut guest, _ring) = surface_and_queue(&device);
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(64, 32, 256)),
|
||||
answered(&device, &mut guest, set_scanout(1920, 1080, 1920 * 4)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let mark = log.mark();
|
||||
@@ -12522,6 +12526,22 @@ fn a_read_of_the_display_draws_what_it_shows() {
|
||||
"a read of the same size made a texture"
|
||||
);
|
||||
assert_eq!(count(SCANOUT_BLIT), 1);
|
||||
assert_eq!(count(TEXTURE_OVER_BUFFER), 0);
|
||||
assert_eq!(count("commit"), 1);
|
||||
assert_eq!(count("waitUntilCompleted"), 1);
|
||||
assert!(quiet(&guest), "a read told the guest something");
|
||||
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(64, 32, 256)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let mark = log.mark();
|
||||
assert_eq!(device.read_display(&mut dst), (mode, Ok(())));
|
||||
let sels = log.sels_since(mark);
|
||||
let count = |sel: &str| sels.iter().filter(|s| **s == sel).count();
|
||||
assert_eq!(count(SCANOUT_BLIT), 0, "a smaller scanout was blitted");
|
||||
assert_eq!(count(TEXTURE_OVER_BUFFER), 1, "the texture over its pixels");
|
||||
assert_eq!(count("renderCommandEncoderWithDescriptor:"), 1);
|
||||
assert_eq!(count("commit"), 1);
|
||||
assert_eq!(count("waitUntilCompleted"), 1);
|
||||
assert!(quiet(&guest), "a read told the guest something");
|
||||
@@ -12530,22 +12550,35 @@ fn a_read_of_the_display_draws_what_it_shows() {
|
||||
answered(&device, &mut guest, present_surface(0x77)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let surface = Handle::clone_ref(&device.control.presented[0].shown().unwrap().0);
|
||||
let (surface, view, _) = device.control.presented[0].shown().unwrap();
|
||||
let mark = log.mark();
|
||||
assert_eq!(device.read_display(&mut dst), (mode, Ok(())));
|
||||
let copies: Vec<_> = (log.since(mark).into_iter())
|
||||
.filter(|c| c.sel == SURFACE_COPY)
|
||||
let sels = log.sels_since(mark);
|
||||
assert!(
|
||||
!sels.contains(&SURFACE_COPY),
|
||||
"a smaller surface was copied"
|
||||
);
|
||||
assert!(!sels.contains(&SCANOUT_BLIT));
|
||||
assert!(!sels.contains(&TEXTURE_OVER_BUFFER));
|
||||
let viewed = view.made().expect("the display's view of the surface");
|
||||
assert_ne!(viewed.id(), surface.id());
|
||||
let drawn: Vec<_> = (log.since(mark).into_iter())
|
||||
.filter(|c| c.sel == "setFragmentTexture:atIndex:")
|
||||
.map(|c| c.args[0].clone())
|
||||
.collect();
|
||||
assert_eq!(copies.len(), 1);
|
||||
assert!(copies[0].args.contains(&Arg::obj(&surface)));
|
||||
assert!(!log.sels_since(mark).contains(&SCANOUT_BLIT));
|
||||
assert_eq!(drawn, [Arg::obj(viewed)]);
|
||||
assert!(quiet(&guest), "a read told the guest something");
|
||||
}
|
||||
|
||||
/// `newTextureWithDescriptor:offset:bytesPerRow:`, a texture over a buffer's bytes: the one over
|
||||
/// a smaller scanout's pixels, which a draw of the display samples.
|
||||
const TEXTURE_OVER_BUFFER: &str = "newTextureWithDescriptor:offset:bytesPerRow:";
|
||||
|
||||
/// While the display's panel is off (`SET_DISPLAY_POWER`), a read of the display clears its
|
||||
/// texture to black and reads neither the scanout nor the presented surface; the guest's presents
|
||||
/// are answered as with the panel on. Once the panel is on, the read copies the presented
|
||||
/// surface again. The guest is told nothing of any read
|
||||
/// are answered as with the panel on. Once the panel is on, the read draws the presented surface
|
||||
/// again, sampled through the display's view of it, as it is smaller than the display's mode.
|
||||
/// The guest is told nothing of any read
|
||||
#[test]
|
||||
fn a_read_of_the_display_is_black_while_its_panel_is_off() {
|
||||
let raised = Arc::new(AtomicU32::new(0));
|
||||
@@ -12596,15 +12629,22 @@ fn a_read_of_the_display_is_black_while_its_panel_is_off() {
|
||||
);
|
||||
let mark = log.mark();
|
||||
assert_eq!(device.read_display(&mut dst), ((1920, 1080), Ok(())));
|
||||
let sels = log.sels_since(mark);
|
||||
assert_eq!(sels.iter().filter(|s| **s == SURFACE_COPY).count(), 1);
|
||||
let (_, view, _) = device.control.presented[0].shown().unwrap();
|
||||
let viewed = view.made().expect("the display's view of the surface");
|
||||
let drawn: Vec<_> = (log.since(mark).into_iter())
|
||||
.filter(|c| c.sel == "setFragmentTexture:atIndex:")
|
||||
.map(|c| c.args[0].clone())
|
||||
.collect();
|
||||
assert_eq!(drawn, [Arg::obj(viewed)]);
|
||||
assert!(!log.sels_since(mark).contains(&SURFACE_COPY));
|
||||
assert!(quiet(&guest), "a read told the guest something");
|
||||
}
|
||||
|
||||
/// On the Vulkan platform, the read gives the guest's pixels: a scanout smaller than the mode
|
||||
/// shows at its top left, B, G, R and A as the guest wrote them, and the rest of the mode is black.
|
||||
/// While the display's panel is off the read is black all over, and once it is on the scanout's
|
||||
/// pixels show again
|
||||
/// On the Vulkan platform, the read gives the guest's pixels: a scanout of the display's mode
|
||||
/// reads as the guest wrote it, B, G, R and A, pixel for pixel. A smaller scanout, a smaller
|
||||
/// mode's, is drawn scaled over the whole read: each of the read's corners is the scanout's corner
|
||||
/// pixel, alpha included, and no pixel is the black of a read with nothing to show. While the
|
||||
/// display's panel is off the read is black all over, and once it is on the scanout shows again
|
||||
#[test]
|
||||
fn on_vulkan_a_read_of_the_display_gives_the_scanout_s_pixels() {
|
||||
let platform = crate::singleton::platform();
|
||||
@@ -12620,35 +12660,59 @@ fn on_vulkan_a_read_of_the_display_gives_the_scanout_s_pixels() {
|
||||
..GraphicsConfig::default()
|
||||
};
|
||||
let device = GraphicsDevice::with_platform(platform, config).unwrap();
|
||||
let (width, height, stride) = (64usize, 32usize, 256usize);
|
||||
let pixel = |x: usize, y: usize| [x as u8, y as u8, (x ^ y) as u8, 0xff - x as u8];
|
||||
// SAFETY: the scanout lies in the device's region, mapped while the device lives.
|
||||
unsafe {
|
||||
let base = device.region_base().add(RGFX_ALLOCATIONS_OFFSET as usize);
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
let p = pixel(x, y);
|
||||
std::ptr::copy_nonoverlapping(p.as_ptr(), base.add(y * stride + x * 4), 4);
|
||||
let write =
|
||||
|width: usize, height: usize, stride: usize, pixel: &dyn Fn(usize, usize) -> [u8; 4]| {
|
||||
// SAFETY: the scanout lies in the device's region, mapped while the device lives.
|
||||
unsafe {
|
||||
let base = device.region_base().add(RGFX_ALLOCATIONS_OFFSET as usize);
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
let p = pixel(x, y);
|
||||
std::ptr::copy_nonoverlapping(p.as_ptr(), base.add(y * stride + x * 4), 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let full = |x: usize, y: usize| [x as u8, y as u8, (x ^ y) as u8, 0xff - x as u8];
|
||||
write(1920, 1080, 1920 * 4, &full);
|
||||
device.mmio_write(RGFX_REG_STATUS.into(), RGFX_STATUS_DRIVER_READY);
|
||||
let mut guest = Guest::new(&device);
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(64, 32, 256)),
|
||||
answered(&device, &mut guest, set_scanout(1920, 1080, 1920 * 4)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let mut dst = vec![7u8; 1920 * 1080 * 4];
|
||||
assert_eq!(device.read_display(&mut dst), ((1920, 1080), Ok(())));
|
||||
let at = |x: usize, y: usize| &dst[(y * 1920 + x) * 4..][..4];
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
assert_eq!(at(x, y), pixel(x, y), "({x}, {y})");
|
||||
let unlike = (0..1080)
|
||||
.flat_map(|y| (0..1920).map(move |x| (x, y)))
|
||||
.find(|&(x, y)| dst[(y * 1920 + x) * 4..][..4] != full(x, y));
|
||||
assert_eq!(unlike, None, "the first pixel unlike the guest's");
|
||||
|
||||
// A smaller mode's scanout, 64 × 32 pixels at 256 bytes a row, none of them black.
|
||||
let small = |x: usize, y: usize| [(x * 4 + 1) as u8, (y * 8 + 1) as u8, 0x80, 0xff - x as u8];
|
||||
write(64, 32, 256, &small);
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, set_scanout(64, 32, 256)),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
let filled = |dst: &[u8], when: &str| {
|
||||
let at = |x: usize, y: usize| &dst[(y * 1920 + x) * 4..][..4];
|
||||
for ((x, y), (sx, sy)) in [
|
||||
((0, 0), (0, 0)),
|
||||
((1919, 0), (63, 0)),
|
||||
((0, 1079), (0, 31)),
|
||||
((1919, 1079), (63, 31)),
|
||||
] {
|
||||
assert_eq!(at(x, y), small(sx, sy), "({x}, {y}) {when}");
|
||||
}
|
||||
}
|
||||
for (x, y) in [(64, 0), (0, 32), (1919, 1079), (100, 100)] {
|
||||
assert_eq!(at(x, y), [0, 0, 0, 0xff], "({x}, {y}) is not black");
|
||||
}
|
||||
assert!(
|
||||
dst.chunks(4).all(|p| p != [0, 0, 0, 0xff]),
|
||||
"black in the read {when}"
|
||||
);
|
||||
};
|
||||
dst.fill(7);
|
||||
assert_eq!(device.read_display(&mut dst), ((1920, 1080), Ok(())));
|
||||
filled(&dst, "at the smaller mode");
|
||||
|
||||
assert_eq!(
|
||||
answered(&device, &mut guest, display_power(0)),
|
||||
@@ -12665,12 +12729,7 @@ fn on_vulkan_a_read_of_the_display_gives_the_scanout_s_pixels() {
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
assert_eq!(device.read_display(&mut dst), ((1920, 1080), Ok(())));
|
||||
let at = |x: usize, y: usize| &dst[(y * 1920 + x) * 4..][..4];
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
assert_eq!(at(x, y), pixel(x, y), "({x}, {y}) once the panel is on");
|
||||
}
|
||||
}
|
||||
filled(&dst, "once the panel is on");
|
||||
}
|
||||
|
||||
/// The pixel the odd-width reads put at `(x, y)`, B, G, R and A: no two alike within 7 rows
|
||||
|
||||
+3
-2
@@ -235,8 +235,9 @@ repeats the ones code cites.
|
||||
`os/linux/heap_trim.rs`), the display's
|
||||
(`display-view-refused`, a draw of the display that kept the window's
|
||||
last frame, or a read of it that answered black, because the platform
|
||||
refused the display's view of the texture it shows: `graphics/sink.rs`,
|
||||
"The display's view"), and the guest's slow answers'
|
||||
refused the display's view of the texture it shows, or the texture over
|
||||
the scanout's pixels a draw that scales the scanout samples:
|
||||
`graphics/sink.rs`, "The display's view" and "Sizes"), and the guest's slow answers'
|
||||
(`slow-answer-over-make`, a ring-0 answer that went on its ring a frame,
|
||||
16.7 ms, or more after the device read its command, during which a make
|
||||
of rt's pool ran, and `slow-answer-over-make-max-ns` the longest;
|
||||
|
||||
Reference in new issue
Block a user