Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e68e3ce939 | ||
|
|
9324949b55 | ||
|
|
48dd6d2fad | ||
|
|
0427583422 |
No files matched your search
@@ -18,9 +18,8 @@ use crate::vm::{Graphics, ImageFormat, Vm};
|
||||
use crate::{paths, prebuilt, reims_util, runtime};
|
||||
use anyhow::{Context, Result, bail, ensure};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::{self, File};
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Mutex, PoisonError};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
@@ -383,108 +382,11 @@ pub fn made_for_other_graphics(vm: &Vm) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The existing OpenCore drivers that provide keyboard and pointer input before macOS starts.
|
||||
const PREBOOT_INPUT_DRIVERS: [&str; 2] = ["ReimsTablet.efi", "OpenUsbKbDxe.efi"];
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct PrebootInput {
|
||||
config: plist::Value,
|
||||
files: BTreeMap<String, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl PrebootInput {
|
||||
/// Reads the selected driver entries, their binaries, and the existing UEFI input settings.
|
||||
fn read(config: &Config, image: &Path, format: ImageFormat) -> Result<Option<Self>> {
|
||||
let Some(uefi) = config.0.get("UEFI").and_then(plist::Value::as_dictionary) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let mut drivers = Vec::new();
|
||||
let mut files = BTreeMap::<String, Vec<u8>>::new();
|
||||
for driver in uefi
|
||||
.get("Drivers")
|
||||
.and_then(plist::Value::as_array)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
let Some(path) = driver
|
||||
.as_dictionary()
|
||||
.and_then(|entry| entry.get("Path"))
|
||||
.and_then(plist::Value::as_string)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if !PREBOOT_INPUT_DRIVERS
|
||||
.iter()
|
||||
.any(|name| path.eq_ignore_ascii_case(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ensure!(
|
||||
!files.keys().any(|seen| seen.eq_ignore_ascii_case(path)),
|
||||
"OpenCore lists the preboot input driver {path} more than once"
|
||||
);
|
||||
let efi_path = format!("EFI/OC/Drivers/{path}");
|
||||
let bytes = read_file(image, format, &efi_path)?
|
||||
.filter(|bytes| !bytes.is_empty())
|
||||
.with_context(|| {
|
||||
format!("OpenCore's preboot input driver {efi_path} is missing or empty")
|
||||
})?;
|
||||
files.insert(path.to_owned(), bytes);
|
||||
drivers.push(driver.clone());
|
||||
}
|
||||
if drivers.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let input = uefi
|
||||
.get("Input")
|
||||
.filter(|input| input.as_dictionary().is_some())
|
||||
.context("OpenCore's preboot drivers require the existing UEFI > Input dictionary")?;
|
||||
let mut bundle = plist::Dictionary::new();
|
||||
bundle.insert("Input".into(), input.clone());
|
||||
bundle.insert("Drivers".into(), plist::Value::Array(drivers));
|
||||
Ok(Some(Self {
|
||||
config: plist::Value::Dictionary(bundle),
|
||||
files,
|
||||
}))
|
||||
}
|
||||
|
||||
fn stage(&self) -> Result<PrebootInputDir> {
|
||||
static NEXT: AtomicU64 = AtomicU64::new(0);
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"reims-ctl-opencore-input-{}-{}-{}",
|
||||
std::process::id(),
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)?
|
||||
.as_nanos(),
|
||||
NEXT.fetch_add(1, Ordering::Relaxed),
|
||||
));
|
||||
crate::os::create_private_dir(&dir).context("create temporary preboot input directory")?;
|
||||
let dir = PrebootInputDir(dir);
|
||||
self.config
|
||||
.to_writer_xml(File::create(dir.0.join("input.plist"))?)
|
||||
.context("write preboot input configuration")?;
|
||||
for (name, bytes) in &self.files {
|
||||
fs::write(dir.0.join(name), bytes)
|
||||
.with_context(|| format!("stage OpenCore's preboot input driver {name}"))?;
|
||||
}
|
||||
Ok(dir)
|
||||
}
|
||||
}
|
||||
|
||||
struct PrebootInputDir(PathBuf);
|
||||
|
||||
impl Drop for PrebootInputDir {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaces a stopped VM's OpenCore image with one the installed reims-util makes, presenting
|
||||
/// the same Mac, with its boot picker shown where `show_picker` says, or as the old image shows
|
||||
/// it when `None`. The new image is made beside the old one, which stays as it was if that fails.
|
||||
/// It holds the kexts for the VM's graphics ([`reims_util::kext_args`]): on reims-vgpu's own
|
||||
/// device, the guest's that this reims-ctl carries. Existing preboot keyboard and tablet drivers
|
||||
/// and their input options are carried over. The VM keeps its OVMF: its variables hold
|
||||
/// device, the guest's that this reims-ctl carries. The VM keeps its OVMF: its variables hold
|
||||
/// its boot entries. The image is set in the VM's settings as they are once it is made, which
|
||||
/// `vm` becomes: others may be saved meanwhile. Returns what happened, and, where the old image
|
||||
/// loaded reims-vgpu's kexts on other graphics, what they left in the guest
|
||||
@@ -507,33 +409,14 @@ pub fn renew(
|
||||
let read = || format!("read the Mac {} presents", paths::tilde(&old));
|
||||
let config = Config::read(&old, q.opencore_format).with_context(read)?;
|
||||
let id = config.identity().with_context(read)?;
|
||||
let preboot = PrebootInput::read(&config, &old, q.opencore_format)
|
||||
.context("read the old OpenCore image's preboot input")?;
|
||||
let staged = preboot.as_ref().map(PrebootInput::stage).transpose()?;
|
||||
let picker = show_picker.unwrap_or_else(|| config.shows_picker());
|
||||
let image = vm.dir.join("opencore.qcow2");
|
||||
let new = vm.dir.join("opencore.new.qcow2");
|
||||
let dropped = holds_unused_guest_kexts(vm);
|
||||
let kexts = reims_util::kext_args(vm.config.graphics())?;
|
||||
let made = reims_util::opencore_as(
|
||||
&new,
|
||||
&id,
|
||||
picker,
|
||||
&kexts,
|
||||
staged.as_ref().map(|dir| dir.0.as_path()),
|
||||
progress,
|
||||
)
|
||||
.and_then(|()| {
|
||||
let made = reims_util::opencore_as(&new, &id, picker, &kexts, progress).and_then(|()| {
|
||||
let config = Config::read(&new, ImageFormat::Qcow2)
|
||||
.context("read the new OpenCore image before replacing the old one")?;
|
||||
if let Some(expected) = &preboot {
|
||||
let actual = PrebootInput::read(&config, &new, ImageFormat::Qcow2)
|
||||
.context("verify the new OpenCore image's preboot input")?;
|
||||
ensure!(
|
||||
actual.as_ref() == Some(expected),
|
||||
"reims-util did not preserve the old OpenCore image's preboot input"
|
||||
);
|
||||
}
|
||||
ensure!(
|
||||
!config
|
||||
.configured_kexts()
|
||||
@@ -1295,88 +1178,6 @@ pub(crate) mod tests {
|
||||
assert!(!dir.join("opencore.img").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renew_keeps_preboot_input_and_refuses_a_lost_driver() {
|
||||
let env = crate::testenv::Env::new("renew-preboot-input");
|
||||
let dir = env.root.join("vm");
|
||||
fs::create_dir(&dir).unwrap();
|
||||
let plist = plist(&(enabled("A.kext") + &enabled("B.kext"))).replace(
|
||||
"</dict></plist>",
|
||||
r#"<key>UEFI</key><dict>
|
||||
<key>Drivers</key><array>
|
||||
<dict><key>Path</key><string>reimstablet.efi</string>
|
||||
<key>Enabled</key><true/><key>Arguments</key><string>tablet</string></dict>
|
||||
<dict><key>Path</key><string>OpenUsbKbDxe.efi</string>
|
||||
<key>Enabled</key><true/><key>LoadEarly</key><true/></dict>
|
||||
<dict><key>Path</key><string>Extra.efi</string><key>Enabled</key><true/></dict>
|
||||
</array>
|
||||
<key>Input</key><dict><key>KeySupport</key><false/></dict>
|
||||
</dict></dict></plist>"#,
|
||||
);
|
||||
let tablet = ("EFI/OC/Drivers/ReimsTablet.efi", &b"fake tablet"[..]);
|
||||
let keyboard = ("EFI/OC/Drivers/OpenUsbKbDxe.efi", &b"fake keyboard"[..]);
|
||||
let old = image_of_config(&plist, b"", &[tablet, keyboard]);
|
||||
let mut vm = on_reims_vgpu(&dir, &old, ImageFormat::Raw);
|
||||
let made = env.root.join("made.img");
|
||||
let args = env.root.join("args");
|
||||
let input = env.root.join("staged.plist");
|
||||
let script = format!(
|
||||
"#!/bin/sh\nprintf '%s\\n' \"$@\" > '{args}'\n\
|
||||
while [ \"$1\" != -o ]; do shift; done\n\
|
||||
out=$2\nshift 2\n\
|
||||
while [ \"$1\" != --preboot-input ]; do shift; done\n\
|
||||
cp \"$2/input.plist\" '{input}'\n\
|
||||
test \"$(cat \"$2/reimstablet.efi\")\" = 'fake tablet' || exit 1\n\
|
||||
test \"$(cat \"$2/OpenUsbKbDxe.efi\")\" = 'fake keyboard' || exit 1\n\
|
||||
test ! -e \"$2/Extra.efi\" || exit 1\n\
|
||||
cp '{made}' \"$out\"\n\
|
||||
echo '{{\"event\":\"done\",\"result\":{{}}}}'\n",
|
||||
args = args.display(),
|
||||
input = input.display(),
|
||||
made = made.display(),
|
||||
);
|
||||
let util = crate::testenv::program(&env.root.join("reims-util"), &script);
|
||||
env.set("REIMS_CTL_UTIL", &util);
|
||||
|
||||
let old_path = dir.join("opencore.img");
|
||||
fs::write(&old_path, image_of_config(&plist, b"", &[keyboard])).unwrap();
|
||||
let err = renew(&mut vm, None, &mut |_| {}).unwrap_err();
|
||||
assert!(format!("{err:#}").contains("reimstablet.efi is missing"));
|
||||
assert!(!args.exists());
|
||||
fs::write(&old_path, &old).unwrap();
|
||||
fs::write(&made, qcow2(&image_of_config(&plist, b"", &[tablet]))).unwrap();
|
||||
let err = renew(&mut vm, None, &mut |_| {}).unwrap_err();
|
||||
assert!(format!("{err:#}").contains("OpenUsbKbDxe.efi is missing"));
|
||||
assert_eq!(fs::read(&old_path).unwrap(), old);
|
||||
assert!(!dir.join("opencore.new.qcow2").exists());
|
||||
|
||||
let carried = crate::prebuilt::set().unwrap()[0].files[1].1;
|
||||
fs::write(
|
||||
&made,
|
||||
qcow2(&image_of_config(&plist, carried, &[tablet, keyboard])),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(holds_other_guest_kexts(&vm));
|
||||
let warnings = crate::runtime::prepare(&mut vm, &mut |_| {});
|
||||
assert!(warnings.is_empty(), "{warnings:?}");
|
||||
assert!(holds_guest_kexts(&vm));
|
||||
let captured = fs::read_to_string(&args).unwrap();
|
||||
assert!(captured.lines().any(|arg| arg == "--add-kext"));
|
||||
let staging = captured.lines().last().unwrap();
|
||||
assert!(!Path::new(staging).exists());
|
||||
let bundle = plist::Value::from_file(input).unwrap();
|
||||
let bundle = bundle.as_dictionary().unwrap();
|
||||
assert_eq!(
|
||||
bundle["Input"].as_dictionary().unwrap()["KeySupport"].as_boolean(),
|
||||
Some(false)
|
||||
);
|
||||
assert_eq!(bundle["Drivers"].as_array().unwrap().len(), 2);
|
||||
assert!(!old_path.exists());
|
||||
fs::remove_file(&args).unwrap();
|
||||
let warnings = crate::runtime::prepare(&mut vm, &mut |_| {});
|
||||
assert!(warnings.is_empty() && !args.exists(), "{warnings:?}");
|
||||
}
|
||||
|
||||
/// The old image goes only where its path, resolved, names a file in the VM's directory
|
||||
/// other than the new image: an OpenCore path edited to `../other/oc.img` leaves that file
|
||||
/// be, and one spelling the new image's place another way, `sub/../opencore.qcow2`, leaves
|
||||
@@ -1721,10 +1522,7 @@ pub(crate) mod tests {
|
||||
|
||||
/// [`image_with_set`]'s files, its config.plist's Kernel > Add holding `kexts`.
|
||||
pub(crate) fn image_loading(kexts: &str, a: &[u8], more: &[(&str, &[u8])]) -> Vec<u8> {
|
||||
image_of_config(&plist(kexts), a, more)
|
||||
}
|
||||
|
||||
fn image_of_config(config: &str, a: &[u8], more: &[(&str, &[u8])]) -> Vec<u8> {
|
||||
let config = plist(kexts);
|
||||
let mut files: Vec<(&str, &[u8])> = vec![
|
||||
("EFI/OC/config.plist", config.as_bytes()),
|
||||
(
|
||||
|
||||
@@ -45,7 +45,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
pub const REPO: &str = "https://github.com/reims-go/reims-util";
|
||||
/// The commit [`install`] installs.
|
||||
pub const REV: &str = "c363a029b1a9bce696184b3247e6465aa11321bc";
|
||||
pub const REV: &str = "573d4a5ffacfc31430ff7372727fce287fef89e1";
|
||||
|
||||
/// The reims-util binary: `REIMS_CTL_UTIL`, else the one beside reims-ctl, where both are
|
||||
/// installed, else the first on PATH.
|
||||
@@ -342,7 +342,7 @@ pub fn opencore(
|
||||
args.extend(["--model", m]);
|
||||
}
|
||||
args.extend(kexts.iter().map(String::as_str));
|
||||
make_opencore(image, &args, None, progress)
|
||||
make_opencore(image, &args, progress)
|
||||
}
|
||||
|
||||
/// Makes an OpenCore image at `image` presenting the Mac `id`, for a VM that has its OVMF: no
|
||||
@@ -353,7 +353,6 @@ pub fn opencore_as(
|
||||
id: &Identity,
|
||||
show_picker: bool,
|
||||
kexts: &[String],
|
||||
preboot_input: Option<&Path>,
|
||||
progress: &mut dyn FnMut(&str),
|
||||
) -> Result<()> {
|
||||
let mut args = identity_args(id);
|
||||
@@ -362,7 +361,7 @@ pub fn opencore_as(
|
||||
args.push("--show-picker");
|
||||
}
|
||||
args.extend(kexts.iter().map(String::as_str));
|
||||
make_opencore(image, &args, preboot_input, progress)
|
||||
make_opencore(image, &args, progress)
|
||||
}
|
||||
|
||||
/// Makes an OpenCore image at `image` presenting the Mac `id`, with `OVMF_CODE.fd` and
|
||||
@@ -376,7 +375,7 @@ pub fn opencore_presenting(
|
||||
) -> Result<()> {
|
||||
let mut args = identity_args(id);
|
||||
args.extend(kexts.iter().map(String::as_str));
|
||||
make_opencore(image, &args, None, progress)
|
||||
make_opencore(image, &args, progress)
|
||||
}
|
||||
|
||||
/// The arguments that make reims-util's image present the Mac `id`.
|
||||
@@ -387,17 +386,9 @@ fn identity_args(id: &Identity) -> Vec<&str> {
|
||||
]
|
||||
}
|
||||
|
||||
fn make_opencore(
|
||||
image: &Path,
|
||||
args: &[&str],
|
||||
preboot_input: Option<&Path>,
|
||||
progress: &mut dyn FnMut(&str),
|
||||
) -> Result<()> {
|
||||
fn make_opencore(image: &Path, args: &[&str], progress: &mut dyn FnMut(&str)) -> Result<()> {
|
||||
let mut all: Vec<&OsStr> = vec!["opencore".as_ref(), "-o".as_ref(), image.as_os_str()];
|
||||
all.extend(args.iter().map(OsStr::new));
|
||||
if let Some(dir) = preboot_input {
|
||||
all.extend([OsStr::new("--preboot-input"), dir.as_os_str()]);
|
||||
}
|
||||
let r = run(&all, progress)?;
|
||||
if let Ok(o) = serde_json::from_value::<OpencoreResult>(r) {
|
||||
progress(&format!(
|
||||
|
||||
@@ -529,7 +529,7 @@ use reims_vgpu_vulkan::core::platform::os::clock::MonoTime;
|
||||
#[cfg(unix)]
|
||||
use reims_vgpu_vulkan::core::platform::resource::SurfaceHandle;
|
||||
use reims_vgpu_vulkan::core::platform::resource::{Buffer as _, MemoryFor};
|
||||
use reims_vgpu_vulkan::core::platform::types::NsRange;
|
||||
use reims_vgpu_vulkan::core::platform::types::{CommandBufferStatus, NsRange};
|
||||
use reims_vgpu_vulkan::core::platform::values::{PagesPlane, TextureDesc};
|
||||
use reims_vgpu_vulkan::core::platform::{Handle, Platform};
|
||||
use reims_vgpu_vulkan::core::raise::{OnFault, Raise, RaiseResult, refusals};
|
||||
@@ -8366,6 +8366,25 @@ impl<P: Platform> Caches<P> {
|
||||
pub(crate) fn export_unattached(
|
||||
&self,
|
||||
device: &P::Device,
|
||||
) -> Result<Vec<(u64, Vec<u8>)>, &'static str> {
|
||||
self.export_unattached_with(
|
||||
device,
|
||||
|queue| queue.command_buffer(ON),
|
||||
|cb| cb.commit(ON),
|
||||
|| device.wait_idle(),
|
||||
|cb| cb.wait_until_completed(ON),
|
||||
|buffer| device.read_standalone_buffer(buffer),
|
||||
)
|
||||
}
|
||||
|
||||
fn export_unattached_with(
|
||||
&self,
|
||||
device: &P::Device,
|
||||
mut command_buffer: impl FnMut(&P::CommandQueue) -> RaiseResult<Option<P::CommandBuffer>>,
|
||||
mut commit: impl FnMut(&P::CommandBuffer) -> RaiseResult<()>,
|
||||
mut wait_idle: impl FnMut(),
|
||||
mut wait_completed: impl FnMut(&P::CommandBuffer) -> RaiseResult<()>,
|
||||
mut read_buffer: impl FnMut(&P::Buffer) -> Result<Option<Vec<u8>>, &'static str>,
|
||||
) -> Result<Vec<(u64, Vec<u8>)>, &'static str> {
|
||||
let need_mem: Vec<P::Buffer> = {
|
||||
let state = self.lock();
|
||||
@@ -8373,17 +8392,14 @@ impl<P: Platform> Caches<P> {
|
||||
.by_block
|
||||
.values()
|
||||
.filter(|c| {
|
||||
c.pages.is_none()
|
||||
&& !c.device.memory_made()
|
||||
&& c.shapes.iter().any(|s| s.dirty)
|
||||
c.pages.is_none() && !c.device.memory_made() && c.shapes.iter().any(|s| s.dirty)
|
||||
})
|
||||
.map(|c| c.device.clone_ref())
|
||||
.collect()
|
||||
};
|
||||
self.make_memory(need_mem, MemoryFor::WriteBack);
|
||||
|
||||
let mut flushed_any = false;
|
||||
{
|
||||
let (dirty_blocks, queue) = {
|
||||
let mut state = self.lock();
|
||||
let dirty_blocks: Vec<u64> = state
|
||||
.by_block
|
||||
@@ -8391,45 +8407,85 @@ impl<P: Platform> Caches<P> {
|
||||
.filter(|(_, c)| c.pages.is_none() && c.shapes.iter().any(|s| s.dirty))
|
||||
.map(|(&b, _)| b)
|
||||
.collect();
|
||||
if !dirty_blocks.is_empty() {
|
||||
let queue = if dirty_blocks.is_empty() {
|
||||
None
|
||||
} else {
|
||||
if !state
|
||||
.make_transfer(device)
|
||||
.map_err(|_| "snapshot_save: surface cache transfer init failed")?
|
||||
{
|
||||
return Err("snapshot_save: surface cache transfer queue unavailable");
|
||||
}
|
||||
state
|
||||
.transfer
|
||||
.as_ref()
|
||||
.map(|transfer| transfer.queue.clone_ref())
|
||||
};
|
||||
(dirty_blocks, queue)
|
||||
};
|
||||
if let Some(queue) = queue {
|
||||
let mut submitted = Vec::new();
|
||||
let flushed = (|| {
|
||||
for block in dirty_blocks {
|
||||
let cb_opt = {
|
||||
let transfer = state
|
||||
.transfer
|
||||
.as_mut()
|
||||
.ok_or("snapshot_save: surface cache transfer missing")?;
|
||||
transfer
|
||||
.queue
|
||||
.command_buffer(ON)
|
||||
.map_err(|_| "snapshot_save: surface cache command buffer failed")?
|
||||
};
|
||||
let Some(cb) = cb_opt else {
|
||||
return Err("snapshot_save: surface cache command buffer unavailable");
|
||||
};
|
||||
let Some(cache) = state.by_block.get_mut(&block) else {
|
||||
let cb = command_buffer(&queue)
|
||||
.map_err(|_| "snapshot_save: surface cache command buffer failed")?
|
||||
.ok_or("snapshot_save: surface cache command buffer unavailable")?;
|
||||
let mut state = self.lock();
|
||||
let Some(cache) = state.by_block.get_mut(&block).filter(|cache| {
|
||||
cache.pages.is_none() && cache.shapes.iter().any(|s| s.dirty)
|
||||
}) else {
|
||||
continue;
|
||||
};
|
||||
if !cache.copy_through(MemoryFor::WriteBack) {
|
||||
return Err("snapshot_save: deferred surface cache allocation failed");
|
||||
}
|
||||
let back = shapes::write_back::<P>(&cb, &cache.device, &cache.shapes, |s| {
|
||||
s.dirty
|
||||
})
|
||||
.map_err(|_| "snapshot_save: surface cache shape write_back failed")?;
|
||||
cache.wrote_shapes(&back);
|
||||
state.owed_commits.push(cb);
|
||||
flushed_any = true;
|
||||
let back =
|
||||
shapes::write_back::<P>(&cb, &cache.device, &cache.shapes, |s| s.dirty)
|
||||
.map_err(|_| "snapshot_save: surface cache shape write_back failed")?;
|
||||
if back.is_empty() {
|
||||
return Err("snapshot_save: surface cache blit encoder unavailable");
|
||||
}
|
||||
// Retirement frees the queue slot even while we keep the handle for status.
|
||||
let commit_failed = "snapshot_save: surface cache command buffer commit failed";
|
||||
state.unlocked(|| commit(&cb)).map_err(|_| commit_failed)?;
|
||||
let status = cb.status();
|
||||
if status.raw() < CommandBufferStatus::COMMITTED.raw()
|
||||
|| status == CommandBufferStatus::ERROR
|
||||
{
|
||||
return Err(commit_failed);
|
||||
}
|
||||
drop(state);
|
||||
submitted.push((block, back, cb));
|
||||
}
|
||||
Ok(())
|
||||
})();
|
||||
let mut wait_failed = false;
|
||||
if !submitted.is_empty() {
|
||||
wait_idle();
|
||||
for (_, _, cb) in &submitted {
|
||||
if wait_completed(cb).is_err() {
|
||||
wait_failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
flushed?;
|
||||
if wait_failed
|
||||
|| submitted
|
||||
.iter()
|
||||
.any(|(_, _, cb)| cb.status() != CommandBufferStatus::COMPLETED)
|
||||
{
|
||||
return Err(
|
||||
"snapshot_save: surface cache command buffer did not complete successfully",
|
||||
);
|
||||
}
|
||||
let mut state = self.lock();
|
||||
let state = &mut *state;
|
||||
for (block, back, _) in &submitted {
|
||||
if let Some(cache) = state.by_block.get_mut(block) {
|
||||
cache.wrote_shapes(back);
|
||||
cache.shapes.written_back(back, &mut state.counts.shapes);
|
||||
}
|
||||
}
|
||||
}
|
||||
if flushed_any {
|
||||
device.wait_idle();
|
||||
}
|
||||
|
||||
let mut to_read: Vec<(u64, P::Buffer)> = {
|
||||
@@ -8445,7 +8501,7 @@ impl<P: Platform> Caches<P> {
|
||||
|
||||
let mut out = Vec::with_capacity(to_read.len());
|
||||
for (block, buf) in to_read {
|
||||
match device.read_standalone_buffer(&buf)? {
|
||||
match read_buffer(&buf)? {
|
||||
Some(bytes) => out.push((block, bytes)),
|
||||
None => return Err("snapshot_save: unattached surface cache buffer unreadable"),
|
||||
}
|
||||
@@ -16385,6 +16441,325 @@ pub(super) mod tests {
|
||||
r.pages_flagged(block, 0, &[], length, flags)
|
||||
}
|
||||
|
||||
const SNAPSHOT_CACHE_LENGTH: u64 = 0x1000;
|
||||
|
||||
fn snapshot_rig(blocks: u64) -> Rig {
|
||||
let r = rig(8);
|
||||
r.dec.set_deferred_budget(blocks * SNAPSHOT_CACHE_LENGTH);
|
||||
r.dec.caches().shaped = true;
|
||||
r
|
||||
}
|
||||
|
||||
fn dirty_unattached_cache(r: &mut Rig, block: u64) -> reims_vgpu_vulkan::core::platform::ObjId {
|
||||
assert_eq!(defer(r, block, SNAPSHOT_CACHE_LENGTH), RGFX_STATUS_OK);
|
||||
let key = ShapeKey {
|
||||
plane: 0,
|
||||
offset: 128,
|
||||
bytes_per_row: 128,
|
||||
width: 16,
|
||||
height: 2,
|
||||
texel_bytes: 4,
|
||||
storage: false,
|
||||
};
|
||||
let desc = r.p.texture_descriptor(&TextureDesc {
|
||||
pixel_format: 80,
|
||||
width: key.width,
|
||||
height: key.height,
|
||||
..TextureDesc::default()
|
||||
});
|
||||
let image = r.device.new_texture(ON, &desc).unwrap().unwrap();
|
||||
let id = image.id();
|
||||
let mut state = r.dec.caches();
|
||||
let cache = state.by_block.get_mut(&block).unwrap();
|
||||
assert!(cache.pages.is_none());
|
||||
assert!(!cache.device.memory_made());
|
||||
let (reference, _) = cache.shapes.insert(key, image, false, 0);
|
||||
assert!(cache.shapes.mark_dirty(reference.id()));
|
||||
id
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_exports_more_dirty_unattached_caches_than_the_transfer_queue_holds() {
|
||||
use reims_vgpu_vulkan::core::platform::types::MtlSize;
|
||||
|
||||
const BLOCKS: u64 = 80;
|
||||
const CAPACITY: usize = 64;
|
||||
let mut r = snapshot_rig(BLOCKS + 1);
|
||||
let mut textures = HashMap::default();
|
||||
let mut expected = Vec::new();
|
||||
for i in 0..BLOCKS {
|
||||
let block = BLOCK + i * 0x2000;
|
||||
let texture = dirty_unattached_cache(&mut r, block);
|
||||
let texels = [[i as u8; 64], [255 - i as u8; 64]];
|
||||
let mut bytes = vec![0; SNAPSHOT_CACHE_LENGTH.to_usize()];
|
||||
for (row, texels) in bytes[128..].chunks_mut(128).zip(&texels) {
|
||||
row[..64].copy_from_slice(texels);
|
||||
}
|
||||
textures.insert(texture, texels);
|
||||
expected.push((block, bytes));
|
||||
}
|
||||
assert_eq!(
|
||||
defer(&mut r, BLOCK + BLOCKS * 0x2000, SNAPSHOT_CACHE_LENGTH),
|
||||
RGFX_STATUS_OK
|
||||
);
|
||||
|
||||
let mark = r.p.call_log().mark();
|
||||
let world = r.p.world();
|
||||
let mut acquired = 0;
|
||||
let retired = Cell::new(0);
|
||||
let caches = &r.dec.surface_caches;
|
||||
let exported = caches.export_unattached_with(
|
||||
&r.device,
|
||||
|queue| {
|
||||
assert!(
|
||||
caches.try_lock().is_some(),
|
||||
"queue acquisition holds the cache lock"
|
||||
);
|
||||
let in_flight = world.committed().len();
|
||||
assert_eq!(
|
||||
world.live("MTLCommandBuffer").len(),
|
||||
in_flight + retired.get(),
|
||||
"a previous buffer is uncommitted"
|
||||
);
|
||||
if in_flight == CAPACITY {
|
||||
retired.set(retired.get() + world.complete_all(CompleteOn::Caller));
|
||||
}
|
||||
assert!(world.committed().len() < CAPACITY);
|
||||
acquired += 1;
|
||||
queue.command_buffer(ON)
|
||||
},
|
||||
|cb| cb.commit(ON),
|
||||
|| {
|
||||
assert_eq!(caches.try_lock().unwrap().counts.shapes.written_back, 0);
|
||||
retired.set(retired.get() + world.complete_all(CompleteOn::Caller));
|
||||
},
|
||||
|cb| cb.wait_until_completed(ON),
|
||||
|buffer| {
|
||||
assert!(world.live("MTLCommandBuffer").is_empty());
|
||||
// The fake logs blits without executing them. Reproduce each logged GPU copy.
|
||||
let calls = r.p.call_log().since(mark);
|
||||
let mut copies = calls.iter().filter(|call| {
|
||||
call.sel.starts_with("copyFromTexture:")
|
||||
&& call.args[5].as_obj() == Some(buffer.id())
|
||||
});
|
||||
let copy = copies.next().expect("a copy into this cache");
|
||||
assert!(copies.next().is_none());
|
||||
assert_eq!(copy.args[4], Arg::val(&MtlSize::new(16, 2, 1)));
|
||||
let source = &textures[©.args[0].as_obj().unwrap()];
|
||||
let offset = copy.args[6].as_u64().unwrap().to_usize();
|
||||
let pitch = copy.args[7].as_u64().unwrap().to_usize();
|
||||
let mut bytes = vec![0; buffer.length().to_usize()];
|
||||
for (row, texels) in source.iter().enumerate() {
|
||||
let at = offset + row * pitch;
|
||||
bytes[at..at + 64].copy_from_slice(texels);
|
||||
}
|
||||
Ok(Some(bytes))
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(acquired, BLOCKS);
|
||||
assert_eq!(retired.get(), BLOCKS.to_usize());
|
||||
assert_eq!(exported.unwrap(), expected);
|
||||
let state = r.dec.caches();
|
||||
assert_eq!(state.counts.shapes.written_back, BLOCKS);
|
||||
assert!(
|
||||
state
|
||||
.by_block
|
||||
.values()
|
||||
.all(|cache| cache.shapes.iter().all(|s| !s.dirty))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_drops_uncommitted_unattached_writebacks_on_error() {
|
||||
use reims_vgpu_vulkan::core::testkit::Step;
|
||||
use reims_vgpu_vulkan::core::testkit::impls::resource::MAKE_MEMORY;
|
||||
|
||||
for (selector, steps, error) in [
|
||||
(
|
||||
"commandBuffer",
|
||||
vec![Step::Nil],
|
||||
"snapshot_save: surface cache command buffer unavailable",
|
||||
),
|
||||
(
|
||||
MAKE_MEMORY,
|
||||
vec![Step::value(false); 2],
|
||||
"snapshot_save: deferred surface cache allocation failed",
|
||||
),
|
||||
(
|
||||
"blitCommandEncoder",
|
||||
vec![Step::Nil],
|
||||
"snapshot_save: surface cache blit encoder unavailable",
|
||||
),
|
||||
(
|
||||
"endEncoding",
|
||||
vec![Step::unrecognized("endEncoding")],
|
||||
"snapshot_save: surface cache shape write_back failed",
|
||||
),
|
||||
(
|
||||
"commit",
|
||||
vec![Step::unrecognized("commit")],
|
||||
"snapshot_save: surface cache command buffer commit failed",
|
||||
),
|
||||
] {
|
||||
let mut r = snapshot_rig(1);
|
||||
dirty_unattached_cache(&mut r, BLOCK);
|
||||
for step in steps {
|
||||
r.p.script().push(selector, step);
|
||||
}
|
||||
let caches = &r.dec.surface_caches;
|
||||
assert_eq!(caches.export_unattached(&r.device), Err(error));
|
||||
assert!(r.p.world().live("MTLCommandBuffer").is_empty());
|
||||
assert!(
|
||||
r.dec.caches().by_block[&BLOCK]
|
||||
.shapes
|
||||
.iter()
|
||||
.all(|s| s.dirty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_stops_before_readback_if_a_later_writeback_fails() {
|
||||
let mut r = snapshot_rig(2);
|
||||
dirty_unattached_cache(&mut r, BLOCK);
|
||||
dirty_unattached_cache(&mut r, BLOCK + 0x2000);
|
||||
r.p.faults()
|
||||
.at("MTLCommandQueue", "commandBuffer", 1, Fault::Nil);
|
||||
|
||||
let caches = &r.dec.surface_caches;
|
||||
let world = r.p.world();
|
||||
let mut retired = 0;
|
||||
let exported = caches.export_unattached_with(
|
||||
&r.device,
|
||||
|queue| queue.command_buffer(ON),
|
||||
|cb| cb.commit(ON),
|
||||
|| retired += world.complete_all(CompleteOn::Caller),
|
||||
|cb| cb.wait_until_completed(ON),
|
||||
|_| panic!("a failed writeback must stop the snapshot before readback"),
|
||||
);
|
||||
assert_eq!(
|
||||
exported,
|
||||
Err("snapshot_save: surface cache command buffer unavailable")
|
||||
);
|
||||
assert_eq!(retired, 1);
|
||||
assert!(world.live("MTLCommandBuffer").is_empty());
|
||||
let state = r.dec.caches();
|
||||
assert_eq!(state.counts.shapes.written_back, 0);
|
||||
assert_eq!(
|
||||
state
|
||||
.by_block
|
||||
.values()
|
||||
.filter(|c| c.shapes.iter().any(|s| s.dirty))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_preserves_dirty_shapes_if_writeback_commit_is_silently_refused() {
|
||||
let mut r = snapshot_rig(1);
|
||||
dirty_unattached_cache(&mut r, BLOCK);
|
||||
|
||||
let exported = r.dec.surface_caches.export_unattached_with(
|
||||
&r.device,
|
||||
|queue| queue.command_buffer(ON),
|
||||
|_| Ok(()),
|
||||
|| panic!("a refused commit leaves no submitted work to wait for"),
|
||||
|_| panic!("a refused commit leaves no submitted work to wait for"),
|
||||
|_| panic!("a refused commit must stop the snapshot before readback"),
|
||||
);
|
||||
assert_eq!(
|
||||
exported,
|
||||
Err("snapshot_save: surface cache command buffer commit failed")
|
||||
);
|
||||
assert!(r.p.world().live("MTLCommandBuffer").is_empty());
|
||||
let state = r.dec.caches();
|
||||
assert_eq!(state.counts.shapes.written_back, 0);
|
||||
assert!(state.by_block[&BLOCK].shapes.iter().all(|s| s.dirty));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_preserves_dirty_shapes_if_a_submitted_writeback_fails() {
|
||||
let mut r = snapshot_rig(2);
|
||||
dirty_unattached_cache(&mut r, BLOCK);
|
||||
dirty_unattached_cache(&mut r, BLOCK + 0x2000);
|
||||
|
||||
let world = r.p.world();
|
||||
let exported = r.dec.surface_caches.export_unattached_with(
|
||||
&r.device,
|
||||
|queue| queue.command_buffer(ON),
|
||||
|cb| cb.commit(ON),
|
||||
|| {
|
||||
let [first, second] = world.committed().try_into().unwrap();
|
||||
assert!(world.complete(
|
||||
first,
|
||||
CommandBufferStatus::COMPLETED,
|
||||
None,
|
||||
CompleteOn::Caller
|
||||
));
|
||||
assert!(world.complete(
|
||||
second,
|
||||
CommandBufferStatus::ERROR,
|
||||
None,
|
||||
CompleteOn::Caller
|
||||
));
|
||||
},
|
||||
|cb| cb.wait_until_completed(ON),
|
||||
|_| panic!("a failed writeback must stop the snapshot before readback"),
|
||||
);
|
||||
assert_eq!(
|
||||
exported,
|
||||
Err("snapshot_save: surface cache command buffer did not complete successfully")
|
||||
);
|
||||
assert!(world.live("MTLCommandBuffer").is_empty());
|
||||
let state = r.dec.caches();
|
||||
assert_eq!(state.counts.shapes.written_back, 0);
|
||||
assert!(
|
||||
state
|
||||
.by_block
|
||||
.values()
|
||||
.all(|cache| cache.shapes.iter().all(|s| s.dirty))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_waits_for_each_submitted_writeback_status_after_wait_idle() {
|
||||
let mut r = snapshot_rig(1);
|
||||
dirty_unattached_cache(&mut r, BLOCK);
|
||||
|
||||
let world = r.p.world();
|
||||
let mut waited_completed = 0;
|
||||
let exported = r.dec.surface_caches.export_unattached_with(
|
||||
&r.device,
|
||||
|queue| queue.command_buffer(ON),
|
||||
|cb| cb.commit(ON),
|
||||
|| {
|
||||
// Simulate wait_idle returning before the completion worker has
|
||||
// published the command buffer's final COMPLETED status.
|
||||
assert_eq!(world.committed().len(), 1);
|
||||
},
|
||||
|cb| {
|
||||
waited_completed += 1;
|
||||
assert_eq!(cb.status(), CommandBufferStatus::SCHEDULED);
|
||||
assert_eq!(world.complete_all(CompleteOn::Caller), 1);
|
||||
cb.wait_until_completed(ON)
|
||||
},
|
||||
|buffer| {
|
||||
assert!(world.live("MTLCommandBuffer").is_empty());
|
||||
Ok(Some(vec![0xAB; buffer.length().to_usize()]))
|
||||
},
|
||||
);
|
||||
assert_eq!(waited_completed, 1);
|
||||
assert_eq!(
|
||||
exported,
|
||||
Ok(vec![(BLOCK, vec![0xAB; SNAPSHOT_CACHE_LENGTH.to_usize()])])
|
||||
);
|
||||
let state = r.dec.caches();
|
||||
assert_eq!(state.counts.shapes.written_back, 1);
|
||||
assert!(state.by_block[&BLOCK].shapes.iter().all(|s| !s.dirty));
|
||||
}
|
||||
|
||||
/// A `SURFACE_PAGES` naming the pages of the deferred block at `block`, `runs` as
|
||||
/// [`Rig::pages`]'s, from context `context`; its answer.
|
||||
fn attach(r: &mut Rig, block: u64, context: u32, runs: &[(u64, u64)], length: u64) -> u32 {
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
* moved the cursor yet: the latest is where the host's pointer is.
|
||||
*
|
||||
* Where the point lies, and the rectangles the host is told:
|
||||
* - on x86-64, each framebuffer holds its display's rectangle as WindowServer placed it
|
||||
* (getBoundingRect), and a move of the cursor on any display tells the host each display's
|
||||
* that changed (tellBounds);
|
||||
* - on x86-64, each framebuffer holds its display's virtual desktop rectangle as WindowServer
|
||||
* placed it (getBoundingRect), and a move of the cursor on any display tells the host each
|
||||
* virtual rectangle that changed (tellBounds);
|
||||
* - on arm64, WindowServer tells the displays nothing of where it placed them, so the kext
|
||||
* learns it from its own posts: a crossing posts at the display's pixel of the rectangle held
|
||||
* for it, and again beside the other displays where the cursor did not reach it, at most
|
||||
@@ -185,7 +185,7 @@ void ReimsGraphics::movePointer(thread_call_param_t self, thread_call_param_t)
|
||||
IOSimpleLockUnlock(me->interruptLock);
|
||||
if (!me->hasStarted())
|
||||
return;
|
||||
// The display's mode and its rectangle in the global space.
|
||||
// The display's scanout size and its virtual desktop rectangle.
|
||||
ReimsGraphics *fb = me->copyDisplay(me->drivenIndex(at.display));
|
||||
if (!fb)
|
||||
return;
|
||||
@@ -221,7 +221,7 @@ void ReimsGraphics::movePointer(thread_call_param_t self, thread_call_param_t)
|
||||
move == RgfxPointerMove::moved ? "moves" : "is dragged", globalX, globalY, posted);
|
||||
}
|
||||
|
||||
// Each framebuffer holds its display's rectangle as WindowServer placed it (getBoundingRect).
|
||||
// The virtual rectangles used for both IOHIDSystem posts and DISPLAY_BOUNDS.
|
||||
void ReimsGraphics::displayPlaces(RgfxGlobalRect *rects, bool *placed)
|
||||
{
|
||||
ReimsGraphics *fbs[RGFX_DISPLAYS_MAX];
|
||||
@@ -232,7 +232,7 @@ void ReimsGraphics::displayPlaces(RgfxGlobalRect *rects, bool *placed)
|
||||
fbs[i]->getBoundingRect(&bounds);
|
||||
if (!bounds || display >= RGFX_DISPLAYS_MAX)
|
||||
continue;
|
||||
rects[display] = {bounds->minx, bounds->miny, bounds->maxx, bounds->maxy};
|
||||
rects[display] = rgfxFramebufferDesktopBounds(bounds);
|
||||
placed[display] = true;
|
||||
}
|
||||
releaseDisplays(fbs, n);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// RgfxDisplayBounds: which displays' rectangles the kext tells the host in DISPLAY_BOUNDS
|
||||
// (design.md, "Multiple displays", "A drag across displays"). On x86-64 each framebuffer holds its
|
||||
// display's rectangle in WindowServer's global space as WindowServer placed it (IOFBSetBounds,
|
||||
// which IOFramebuffer::getBoundingRect reads; RgfxPointerOver.hpp), and on arm64 the kext holds
|
||||
// display's virtual desktop rectangle as WindowServer placed it (IOFBSetBounds, which
|
||||
// IOFramebuffer::getBoundingRect reads; RgfxPointerOver.hpp), and on arm64 the kext holds
|
||||
// each one a landing of its own moves of the cursor confirmed (RgfxDisplayPlaces.hpp); the host
|
||||
// carries its captured pointer past one display's edge onto the display whose rectangle meets it
|
||||
// there. Each move of the cursor, on any display, tells the host every display's rectangle that
|
||||
@@ -21,6 +21,15 @@
|
||||
#include "RgfxPointerOver.hpp"
|
||||
#include "reims_graphics_wire.h"
|
||||
|
||||
// IOFramebuffer's getBoundingRect returns its physical and virtual rectangles in order.
|
||||
// IOFBSetBounds supplies both, or IOFramebuffer uses the sole rectangle for both.
|
||||
template <class Bounds>
|
||||
inline RgfxGlobalRect rgfxFramebufferDesktopBounds(const Bounds *bounds)
|
||||
{
|
||||
const Bounds &rect = bounds[1];
|
||||
return {rect.minx, rect.miny, rect.maxx, rect.maxy};
|
||||
}
|
||||
|
||||
// The rectangle the host was last told of each display, by id, where it was told one.
|
||||
struct RgfxBoundsTold {
|
||||
RgfxGlobalRect rects[RGFX_DISPLAYS_MAX];
|
||||
|
||||
@@ -4,16 +4,12 @@
|
||||
// the display its cursor is on, so the kext moves the cursor onto that display, at that point,
|
||||
// before the tablet's next position comes (ReimsGraphicsPointer.cpp).
|
||||
//
|
||||
// The point is in WindowServer's global space, in which it placed each display: on x86-64 each
|
||||
// framebuffer holds its display's rectangle there as WindowServer gave it (IOFBSetBounds, which
|
||||
// IOFramebuffer::getBoundingRect reads), the space the cursor's moves arrive in
|
||||
// (IOFramebuffer::extSetCursorPosition); on arm64 the kext learns each one from its own moves
|
||||
// (RgfxDisplayPlaces.hpp). The display's pixel lies in that rectangle as the pixel
|
||||
// lies in the display's mode, scaled from the mode's pixels to the rectangle's size. Measured on
|
||||
// x86-64 macOS 11.7.11, 15.8.2 and 26.7.2 with two 1920 x 1080 displays side by side: each
|
||||
// framebuffer's rectangle is the display's CGDisplayBounds, and IOHIDSystem's mouse-moved posted
|
||||
// at a point of display 1's rectangle puts the cursor there (lane ptrcross, potluck jobs
|
||||
// m3-max-34583 to 34585).
|
||||
// IOHIDSystem's post takes a point in WindowServer's virtual desktop. On x86-64 the framebuffer
|
||||
// holds the virtual rectangle WindowServer gave it (IOFBSetBounds); on arm64 the kext learns
|
||||
// each rectangle from its own moves (RgfxDisplayPlaces.hpp). Scale the scanout pixels into that
|
||||
// rectangle. Measured on x86-64 macOS 11.7.11, 15.8.2 and 26.7.2 with two 1920 x 1080 displays
|
||||
// side by side: a mouse-moved posted at a point in display 1's CGDisplayBounds puts the cursor
|
||||
// there (lane ptrcross, potluck jobs m3-max-34583 to 34585).
|
||||
//
|
||||
// The move is a mouse-moved where no button is held, and the drag of the button held where one is,
|
||||
// as IOHIDSystem's own moves are (the left button's before the right's, the right's before any
|
||||
|
||||
@@ -19,10 +19,38 @@ void check(bool ok, const char *what)
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void mixedScaleDesktop()
|
||||
{
|
||||
// IOFramebuffer keeps the physical and virtual desktop rectangles, in that order.
|
||||
const RgfxGlobalRect framebuffers[2][2] = {
|
||||
{{0, 0, 3840, 2160}, {0, 0, 1920, 1080}},
|
||||
{{3840, 0, 6400, 1440}, {1920, 0, 4480, 1440}},
|
||||
};
|
||||
const RgfxGlobalRect left = rgfxFramebufferDesktopBounds(framebuffers[0]);
|
||||
const RgfxGlobalRect right = rgfxFramebufferDesktopBounds(framebuffers[1]);
|
||||
int32_t x = 0, y = 0;
|
||||
check(rgfxPointerGlobal(right, 2560, 1440, 2, 653, &x, &y) && x == 1922 && y == 653,
|
||||
"crossing onto the native display uses its virtual origin");
|
||||
check(rgfxPointerGlobal(left, 3840, 2160, 3834, 943, &x, &y) && x == 1917 && y == 471,
|
||||
"crossing back scales scanout pixels into the HiDPI desktop rectangle");
|
||||
|
||||
// Both displays were native before the switch. Their physical rectangles stay the same.
|
||||
RgfxBoundsTold told = {};
|
||||
rgfxBoundsWereTold(&told, 0, framebuffers[0][0]);
|
||||
rgfxBoundsWereTold(&told, 1, framebuffers[1][0]);
|
||||
check(rgfxBoundsToTell(told, 0, left) && rgfxBoundsToTell(told, 1, right),
|
||||
"a HiDPI switch reports the resized display and the moved neighbor");
|
||||
const RgfxDisplayBounds command = rgfxBoundsCommand(1, right);
|
||||
check(command.min_x == 1920 && command.max_x == 4480 && command.max_y == 1440,
|
||||
"DISPLAY_BOUNDS uses the same desktop rectangle as the pointer post");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
mixedScaleDesktop();
|
||||
|
||||
// The wire's command: 40 bytes, the display then the rectangle past the 16-byte header.
|
||||
check(sizeof(RgfxDisplayBounds) == 40 && RGFX_CMD_DISPLAY_BOUNDS == 9, "the wire's");
|
||||
check(offsetof(RgfxDisplayBounds, display) == 16 && offsetof(RgfxDisplayBounds, min_x) == 20 &&
|
||||
|
||||
Binary file not shown.
@@ -34,4 +34,4 @@ Arch = "arm64e"
|
||||
MinKernel = "23.0.0"
|
||||
MaxKernel = ""
|
||||
Comment = "Installs the reims-graphics Metal bundle and admits it"
|
||||
sha256 = "09853275a5e976bb9c435f76e8f84702f1692b7b98029957404951f626bbebfc"
|
||||
sha256 = "969de78746515a49078709af17268af29ee398262dd45911e897c8ce2e806792"
|
||||
@@ -3,8 +3,8 @@
|
||||
# when a source or an output differs from its SHA-256 here (guest/tools/prebuilt.py).
|
||||
# [built] records the local toolchain; every input is in the tree.
|
||||
[built]
|
||||
xcode = "unknown"
|
||||
sdk = "MacOSX.sdk"
|
||||
xcode = "Xcode 27.2 Build version 27B52"
|
||||
sdk = "MacOSX27.2.sdk"
|
||||
clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
|
||||
[sources]
|
||||
@@ -331,7 +331,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/kext/src/ReimsGraphics.cpp" = "7ea4b22d26781eb7f673968cf77e33b65cd09042f4a949f600d27d1f9024ebec"
|
||||
"guest/kext/src/ReimsGraphics.hpp" = "e4162466ced71dd89ca50a38dcdf26c874765aab471bd96375fcb99f0766f20d"
|
||||
"guest/kext/src/ReimsGraphicsMobile.cpp" = "b73a2e5f5b061453817c5d0b18211a2d0782f5971f02d90b0fb7f930365086de"
|
||||
"guest/kext/src/ReimsGraphicsPointer.cpp" = "255f049c3a5244a148d80fd25ef3388001ba180c58901e3620451c3158908f0e"
|
||||
"guest/kext/src/ReimsGraphicsPointer.cpp" = "7b3482545b8e5e459327ab31648e32d83fd8317587b453b4133a5974fa44e35d"
|
||||
"guest/kext/src/RgfxAccelTypes.hpp" = "c65e032a617cda503b2534c68bec87947d7856accda676f35a1affa145998259"
|
||||
"guest/kext/src/RgfxAccelerator.cpp" = "319e1148d2644e922ed2c30859019392764c9e64328594c1f593c5c4fe890030"
|
||||
"guest/kext/src/RgfxAccelerator.hpp" = "2711b9225040feae3e45bb8057a60b30f5d17d83d953eadc82c2db91e83e28c5"
|
||||
@@ -359,7 +359,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/kext/src/RgfxDeviceControl.cpp" = "53c7c6a722ef4d7edeb5756eb04091d4a56f397dc5aef83c3637b1c0f129b934"
|
||||
"guest/kext/src/RgfxDeviceControl.hpp" = "c1357b80ee2141e1e2fd57213f3c9361cb497b8c6490a0b6aff8c64649be48c6"
|
||||
"guest/kext/src/RgfxDeviceName.hpp" = "b242e0ccdce31c3c454bc3a4d64b13c30e574b25379a0833973dcecbbb1146d3"
|
||||
"guest/kext/src/RgfxDisplayBounds.hpp" = "c1e8fe52f89bcb25ee178f4e0ea4ac53396109fd934348408692d21d1931ecf7"
|
||||
"guest/kext/src/RgfxDisplayBounds.hpp" = "7aafbc6d1c2bb28e50c973f77d21c1aa00b322fb5fc934d4b1238b50f3aa89db"
|
||||
"guest/kext/src/RgfxDisplayIdentity.hpp" = "ce4328b8e255f942aea0f0dc097e2e80eb4a8d7e126ea0f342fd116252357731"
|
||||
"guest/kext/src/RgfxDisplayModes.hpp" = "62026ac6fa3febe5ce403fbfe026760f0434b70cc47e5d74c191fa5509ae12cd"
|
||||
"guest/kext/src/RgfxDisplayPipeUserClient.cpp" = "460c7d61a305d7d145b3318bb4fbe940c0d2d48d63afbbfeb6f273cd929aa3af"
|
||||
@@ -397,7 +397,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/kext/src/RgfxPointerDevice.cpp" = "a4f88cc9b272259c3a85325b2295feea6a22221f52035fc5130d72f52cb88891"
|
||||
"guest/kext/src/RgfxPointerDevice.hpp" = "a393c90bed65528495868778e4130851e98aeafcb11401aef05d2d41d5b90d3f"
|
||||
"guest/kext/src/RgfxPointerMotion.hpp" = "d5cbe1a09db996980319d0b907782675fa82b5a03fd84a51f7c7d12c5dada926"
|
||||
"guest/kext/src/RgfxPointerOver.hpp" = "c2c38dbd101b1f59400bb159bd8cb44ed8c937bf25b93e9d62a03d6c2fd9ae50"
|
||||
"guest/kext/src/RgfxPointerOver.hpp" = "757946b2332ba278201f4c2f44ec1ee2bb21ca10b017a7c7933f696d8ee8f10c"
|
||||
"guest/kext/src/RgfxPointerReporting.cpp" = "c9f33023f3acea2e638353e8943c65f28f8befa984989ae88e7abc24858b961e"
|
||||
"guest/kext/src/RgfxPoolBlocks.hpp" = "a657b67922b04b75ccef6f12e10d775867f4037e50b89a8cf0d4972af43747fe"
|
||||
"guest/kext/src/RgfxQueueLimits.hpp" = "13f8ecd60e8d19f438b8ddc1cf3a0273fba1028bc049110776b637fa2097173c"
|
||||
@@ -445,7 +445,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/rgfxgate/src/RgfxGate.hpp" = "90cf92a9b031fc857dfda215db37a4056ea1919d418289b1d8a2dd056fe9d51c"
|
||||
"guest/rgfxgate/src/RgfxGateFile.hpp" = "4683d072fe3d0aecc0308eb6e9896bb694a9d2899e44070a17a7859448b10566"
|
||||
"guest/rgfxgate/src/RgfxGateHooks.cpp" = "3c77cf33042c062ccc41f864801db1759afe145dbaaaa4336e935ddc305d3843"
|
||||
"guest/rgfxgate/src/RgfxGateInstall.cpp" = "533d7d489d240ef34a065256ad16025dec6f7a1c929db5eae92ed27073a578ef"
|
||||
"guest/rgfxgate/src/RgfxGateInstall.cpp" = "0dd5e94467eb37ad447e638c561148d42bbc5cd2bf0129e290f87e9490d3c9fc"
|
||||
"guest/rgfxgate/src/RgfxGatePrefs.cpp" = "19851da9d270161f3c58ae97b35cfc15b2c7484514c287d41cb23f95c83ea3b8"
|
||||
"guest/rgfxgate/src/RgfxGatePrefs.hpp" = "7a9cbf500b1578ee780470e9b789030dd12c88469fda9d557e65e52cd81b1a07"
|
||||
"guest/rgfxgate/src/RgfxGateVnop.hpp" = "ca2743778b2c13cfaf48807469f926134bb3813a0963f0dcc3f5346a3e7dd84c"
|
||||
@@ -466,5 +466,5 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"ReimsGraphics.kext/Contents/Info.plist" = "9683153587659c4bd4d5c52167eff1f3d2ae51dae575f60c15a27d89240f46c5"
|
||||
"ReimsGraphics.kext/Contents/MacOS/ReimsGraphics" = "33a086b90fa116b3cf0c6bb826c27f8a55cd83f15522ee794e20186d469bdbc7"
|
||||
"RgfxGate.kext/Contents/Info.plist" = "7b78d915fab4d36e6cdb3f40aa2a6c1e7224f30158ee879af23451d2e6969992"
|
||||
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "09853275a5e976bb9c435f76e8f84702f1692b7b98029957404951f626bbebfc"
|
||||
"set.toml" = "7b7041b0b0644f18b18ca17f17d7a65eb8d8525f37c8603baf7e81c4519ec066"
|
||||
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "969de78746515a49078709af17268af29ee398262dd45911e897c8ce2e806792"
|
||||
"set.toml" = "934935a19dea7d19f09c411552120e3290f2f534bf12d97c8b4900e140aa4140"
|
||||
Binary file not shown.
Binary file not shown.
@@ -24,7 +24,7 @@ Arch = "x86_64"
|
||||
MinKernel = "20.0.0"
|
||||
MaxKernel = ""
|
||||
Comment = "The reims-graphics display, accelerator and device control"
|
||||
sha256 = "d0277f202173dcecc35bce8aa2ec84cd9d53759a0fd34c26e913bcd65a191d50"
|
||||
sha256 = "2f15b6a13b44e98d4af81240c44720c0004f3c7d5c9dfecfde3b39f069930349"
|
||||
|
||||
[[kext]]
|
||||
BundlePath = "RgfxGate.kext"
|
||||
@@ -34,4 +34,4 @@ Arch = "x86_64"
|
||||
MinKernel = "20.0.0"
|
||||
MaxKernel = ""
|
||||
Comment = "Installs the reims-graphics Metal bundle and admits it"
|
||||
sha256 = "9801337a4a9b1cd60dc83eaac59f2a64637c123d178dbc63d8247476161810a4"
|
||||
sha256 = "534ab7e2f0b39ce9f6403b8988e89419889893b68ea91687b5aaeff38f5a9be6"
|
||||
@@ -3,8 +3,8 @@
|
||||
# when a source or an output differs from its SHA-256 here (guest/tools/prebuilt.py).
|
||||
# [built] records the local toolchain; every input is in the tree.
|
||||
[built]
|
||||
xcode = "unknown"
|
||||
sdk = "MacOSX.sdk"
|
||||
xcode = "Xcode 27.2 Build version 27B52"
|
||||
sdk = "MacOSX27.2.sdk"
|
||||
clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
|
||||
[sources]
|
||||
@@ -331,7 +331,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/kext/src/ReimsGraphics.cpp" = "7ea4b22d26781eb7f673968cf77e33b65cd09042f4a949f600d27d1f9024ebec"
|
||||
"guest/kext/src/ReimsGraphics.hpp" = "e4162466ced71dd89ca50a38dcdf26c874765aab471bd96375fcb99f0766f20d"
|
||||
"guest/kext/src/ReimsGraphicsMobile.cpp" = "b73a2e5f5b061453817c5d0b18211a2d0782f5971f02d90b0fb7f930365086de"
|
||||
"guest/kext/src/ReimsGraphicsPointer.cpp" = "255f049c3a5244a148d80fd25ef3388001ba180c58901e3620451c3158908f0e"
|
||||
"guest/kext/src/ReimsGraphicsPointer.cpp" = "7b3482545b8e5e459327ab31648e32d83fd8317587b453b4133a5974fa44e35d"
|
||||
"guest/kext/src/RgfxAccelTypes.hpp" = "c65e032a617cda503b2534c68bec87947d7856accda676f35a1affa145998259"
|
||||
"guest/kext/src/RgfxAccelerator.cpp" = "319e1148d2644e922ed2c30859019392764c9e64328594c1f593c5c4fe890030"
|
||||
"guest/kext/src/RgfxAccelerator.hpp" = "2711b9225040feae3e45bb8057a60b30f5d17d83d953eadc82c2db91e83e28c5"
|
||||
@@ -359,7 +359,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/kext/src/RgfxDeviceControl.cpp" = "53c7c6a722ef4d7edeb5756eb04091d4a56f397dc5aef83c3637b1c0f129b934"
|
||||
"guest/kext/src/RgfxDeviceControl.hpp" = "c1357b80ee2141e1e2fd57213f3c9361cb497b8c6490a0b6aff8c64649be48c6"
|
||||
"guest/kext/src/RgfxDeviceName.hpp" = "b242e0ccdce31c3c454bc3a4d64b13c30e574b25379a0833973dcecbbb1146d3"
|
||||
"guest/kext/src/RgfxDisplayBounds.hpp" = "c1e8fe52f89bcb25ee178f4e0ea4ac53396109fd934348408692d21d1931ecf7"
|
||||
"guest/kext/src/RgfxDisplayBounds.hpp" = "7aafbc6d1c2bb28e50c973f77d21c1aa00b322fb5fc934d4b1238b50f3aa89db"
|
||||
"guest/kext/src/RgfxDisplayIdentity.hpp" = "ce4328b8e255f942aea0f0dc097e2e80eb4a8d7e126ea0f342fd116252357731"
|
||||
"guest/kext/src/RgfxDisplayModes.hpp" = "62026ac6fa3febe5ce403fbfe026760f0434b70cc47e5d74c191fa5509ae12cd"
|
||||
"guest/kext/src/RgfxDisplayPipeUserClient.cpp" = "460c7d61a305d7d145b3318bb4fbe940c0d2d48d63afbbfeb6f273cd929aa3af"
|
||||
@@ -397,7 +397,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/kext/src/RgfxPointerDevice.cpp" = "a4f88cc9b272259c3a85325b2295feea6a22221f52035fc5130d72f52cb88891"
|
||||
"guest/kext/src/RgfxPointerDevice.hpp" = "a393c90bed65528495868778e4130851e98aeafcb11401aef05d2d41d5b90d3f"
|
||||
"guest/kext/src/RgfxPointerMotion.hpp" = "d5cbe1a09db996980319d0b907782675fa82b5a03fd84a51f7c7d12c5dada926"
|
||||
"guest/kext/src/RgfxPointerOver.hpp" = "c2c38dbd101b1f59400bb159bd8cb44ed8c937bf25b93e9d62a03d6c2fd9ae50"
|
||||
"guest/kext/src/RgfxPointerOver.hpp" = "757946b2332ba278201f4c2f44ec1ee2bb21ca10b017a7c7933f696d8ee8f10c"
|
||||
"guest/kext/src/RgfxPointerReporting.cpp" = "c9f33023f3acea2e638353e8943c65f28f8befa984989ae88e7abc24858b961e"
|
||||
"guest/kext/src/RgfxPoolBlocks.hpp" = "a657b67922b04b75ccef6f12e10d775867f4037e50b89a8cf0d4972af43747fe"
|
||||
"guest/kext/src/RgfxQueueLimits.hpp" = "13f8ecd60e8d19f438b8ddc1cf3a0273fba1028bc049110776b637fa2097173c"
|
||||
@@ -445,7 +445,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"guest/rgfxgate/src/RgfxGate.hpp" = "90cf92a9b031fc857dfda215db37a4056ea1919d418289b1d8a2dd056fe9d51c"
|
||||
"guest/rgfxgate/src/RgfxGateFile.hpp" = "4683d072fe3d0aecc0308eb6e9896bb694a9d2899e44070a17a7859448b10566"
|
||||
"guest/rgfxgate/src/RgfxGateHooks.cpp" = "3c77cf33042c062ccc41f864801db1759afe145dbaaaa4336e935ddc305d3843"
|
||||
"guest/rgfxgate/src/RgfxGateInstall.cpp" = "533d7d489d240ef34a065256ad16025dec6f7a1c929db5eae92ed27073a578ef"
|
||||
"guest/rgfxgate/src/RgfxGateInstall.cpp" = "0dd5e94467eb37ad447e638c561148d42bbc5cd2bf0129e290f87e9490d3c9fc"
|
||||
"guest/rgfxgate/src/RgfxGatePrefs.cpp" = "19851da9d270161f3c58ae97b35cfc15b2c7484514c287d41cb23f95c83ea3b8"
|
||||
"guest/rgfxgate/src/RgfxGatePrefs.hpp" = "7a9cbf500b1578ee780470e9b789030dd12c88469fda9d557e65e52cd81b1a07"
|
||||
"guest/rgfxgate/src/RgfxGateVnop.hpp" = "ca2743778b2c13cfaf48807469f926134bb3813a0963f0dcc3f5346a3e7dd84c"
|
||||
@@ -464,7 +464,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
|
||||
"Graft.kext/Contents/Info.plist" = "fa8533d5ec06430f3ede502e6f9e739e9c8c3f6b6909c46d854effe6028cbc7f"
|
||||
"Graft.kext/Contents/MacOS/Graft" = "04a1d44c0c80c20a71f3a662c46b56a1732b8134f095fb2ac57ec790f72baf72"
|
||||
"ReimsGraphics.kext/Contents/Info.plist" = "ae0dafd3b6c36c24d1c92467d8203d76360eb6e4f6ad5c496167a21033b2c209"
|
||||
"ReimsGraphics.kext/Contents/MacOS/ReimsGraphics" = "d0277f202173dcecc35bce8aa2ec84cd9d53759a0fd34c26e913bcd65a191d50"
|
||||
"ReimsGraphics.kext/Contents/MacOS/ReimsGraphics" = "2f15b6a13b44e98d4af81240c44720c0004f3c7d5c9dfecfde3b39f069930349"
|
||||
"RgfxGate.kext/Contents/Info.plist" = "7b78d915fab4d36e6cdb3f40aa2a6c1e7224f30158ee879af23451d2e6969992"
|
||||
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "9801337a4a9b1cd60dc83eaac59f2a64637c123d178dbc63d8247476161810a4"
|
||||
"set.toml" = "8947f58f02818cd1ac50e9fad53a77d983f2a424ace8320b5b085a965c1adb6b"
|
||||
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "534ab7e2f0b39ce9f6403b8988e89419889893b68ea91687b5aaeff38f5a9be6"
|
||||
"set.toml" = "c2f6659892f049da4bc81ec2854915cdb5cd1c4de8b15728582264b64f166131"
|
||||
@@ -371,8 +371,6 @@ static void renameIdentity(vnode_t vp, vnode_t olddvp, const char *oldleaf, vnod
|
||||
// swap (both ends must exist), the two are exchanged atomically
|
||||
// (VFS_RENAME_SWAP): a reader of `to` always sees one whole tree, never a
|
||||
// half-swapped one. Without swap, `from` replaces `to`, which need not exist.
|
||||
// Look up the directory entries themselves: a symlink is exchanged as a link,
|
||||
// even if dangling, and its target stays where it is.
|
||||
// Each renamed vnode then takes its new name and parent (renameIdentity), as
|
||||
// after vn_rename: the installed bundle's vnodes would otherwise keep the
|
||||
// staging name, reims-graphics.bundle.new.
|
||||
@@ -380,10 +378,10 @@ static void renameIdentity(vnode_t vp, vnode_t olddvp, const char *oldleaf, vnod
|
||||
bool rgfxRenameNode(const char *from, const char *to, bool swap,
|
||||
vfs_context_t ctx) {
|
||||
vnode_t fvp = nullptr;
|
||||
if (vnode_lookup(from, VNODE_LOOKUP_NOFOLLOW, &fvp, ctx) != 0)
|
||||
if (vnode_lookup(from, 0, &fvp, ctx) != 0)
|
||||
return false; // nothing to rename
|
||||
vnode_t tvp = nullptr;
|
||||
if (vnode_lookup(to, VNODE_LOOKUP_NOFOLLOW, &tvp, ctx) != 0)
|
||||
if (vnode_lookup(to, 0, &tvp, ctx) != 0)
|
||||
tvp = nullptr; // target absent: a plain rename into a free name
|
||||
bool ok = false;
|
||||
if (!(swap && tvp == nullptr)) {
|
||||
@@ -561,14 +559,13 @@ static bool installBundle(vfs_context_t ctx) {
|
||||
tagTree(stageRoot, ctx);
|
||||
if (ok) {
|
||||
vnode_t live = nullptr;
|
||||
// A newer runtime may have placed its bundle behind a symlink.
|
||||
bool haveLive = vnode_lookup(kBundlePath, VNODE_LOOKUP_NOFOLLOW, &live, ctx) == 0;
|
||||
bool haveLive = vnode_lookup(kBundlePath, 0, &live, ctx) == 0;
|
||||
if (haveLive)
|
||||
vnode_put(live);
|
||||
ok = rgfxRenameNode(stageRoot, kBundlePath, haveLive, ctx);
|
||||
}
|
||||
// On a swap the old tree or link is now at stageRoot; on a move it is gone;
|
||||
// on a failure the staged tree is still there. The sweep never follows links.
|
||||
// On a swap the old tree is now at stageRoot; on a move it is gone; on a
|
||||
// failure the staged tree is still there. One sweep clears whichever remains.
|
||||
removeTree(stageRoot, ctx);
|
||||
// The container carries the class on every install (it may be freshly made).
|
||||
tagRootless(kContainerPath, ctx);
|
||||
|
||||
@@ -235,24 +235,6 @@ void testLinksAreNotFollowed() {
|
||||
assert(exists("outside/kept/file"));
|
||||
}
|
||||
|
||||
void testSwappedBundleLinkLeavesItsTarget() {
|
||||
PosixFs fs;
|
||||
const char *bundle = "t7/reims-graphics.bundle";
|
||||
const std::string stage = std::string(bundle) + ".new";
|
||||
const char *placed = "t7-cache/reims-graphics.bundle";
|
||||
const char *oldMarker = "t7-cache/reims-graphics.bundle/Contents/Resources/wire-version-3";
|
||||
mkdirs(std::string(placed) + "/Contents/Resources");
|
||||
touch(oldMarker);
|
||||
mkdirs(stage + "/Contents/Resources");
|
||||
touch(stage + "/Contents/Resources/wire-version-2");
|
||||
assert(symlink(at(placed).c_str(), at(bundle).c_str()) == 0);
|
||||
assert(renamex_np(at(stage).c_str(), at(bundle).c_str(), RENAME_SWAP) == 0);
|
||||
assert(removeTree(stage, fs));
|
||||
assert(!exists(stage));
|
||||
assert(exists(std::string(bundle) + "/Contents/Resources/wire-version-2"));
|
||||
assert(exists(oldMarker));
|
||||
}
|
||||
|
||||
// A tree deeper than the walk descends stops it, and the walk says so; what
|
||||
// lies outside the tree is untouched.
|
||||
void testTooDeep() {
|
||||
@@ -314,7 +296,6 @@ int main() {
|
||||
testLeftoverOfAnOlderBuild();
|
||||
testShapes();
|
||||
testLinksAreNotFollowed();
|
||||
testSwappedBundleLinkLeavesItsTarget();
|
||||
testTooDeep();
|
||||
testStuck();
|
||||
testPathTooLong();
|
||||
|
||||
Reference in new issue
Block a user