Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7df96f018 | ||
|
|
011fe14323 | ||
|
|
c6e8df0463 | ||
|
|
f7f0af3500 | ||
|
|
6527829878 | ||
|
|
91c0ce917a | ||
|
|
5a2083b951 | ||
|
|
acd68ab830 | ||
|
|
7c00df2c0b |
No files matched your search
Generated
+3
-3
@@ -213,7 +213,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
[[package]]
|
||||
name = "metal2vulkan"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/reims-go/metal2vulkan?rev=1dd4e970c0562c73bd3eba12cd15999bb035e019#1dd4e970c0562c73bd3eba12cd15999bb035e019"
|
||||
source = "git+https://github.com/reims-go/metal2vulkan?rev=8fd7fb5d9cf2df9164b121995b63187f95a3a191#8fd7fb5d9cf2df9164b121995b63187f95a3a191"
|
||||
dependencies = [
|
||||
"ash",
|
||||
"metal2vulkan-air",
|
||||
@@ -224,7 +224,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "metal2vulkan-air"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/reims-go/metal2vulkan?rev=1dd4e970c0562c73bd3eba12cd15999bb035e019#1dd4e970c0562c73bd3eba12cd15999bb035e019"
|
||||
source = "git+https://github.com/reims-go/metal2vulkan?rev=8fd7fb5d9cf2df9164b121995b63187f95a3a191#8fd7fb5d9cf2df9164b121995b63187f95a3a191"
|
||||
dependencies = [
|
||||
"sha2 0.11.1",
|
||||
]
|
||||
@@ -232,7 +232,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "metal2vulkan-runtime"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/reims-go/metal2vulkan?rev=1dd4e970c0562c73bd3eba12cd15999bb035e019#1dd4e970c0562c73bd3eba12cd15999bb035e019"
|
||||
source = "git+https://github.com/reims-go/metal2vulkan?rev=8fd7fb5d9cf2df9164b121995b63187f95a3a191#8fd7fb5d9cf2df9164b121995b63187f95a3a191"
|
||||
dependencies = [
|
||||
"ash",
|
||||
"libc",
|
||||
|
||||
+2
-2
@@ -33,11 +33,11 @@ reims-vgpu-graphics = { path = "crates/reims-vgpu-graphics" }
|
||||
reims-vgpu-video = { path = "crates/reims-vgpu-video" }
|
||||
# metal2vulkan's Metal types, for the Metal enums and descriptor values the runtime's calls take,
|
||||
# from metal2vulkan's public repository at the commit both name.
|
||||
metal2vulkan = { git = "https://github.com/reims-go/metal2vulkan", rev = "1dd4e970c0562c73bd3eba12cd15999bb035e019" }
|
||||
metal2vulkan = { git = "https://github.com/reims-go/metal2vulkan", rev = "8fd7fb5d9cf2df9164b121995b63187f95a3a191" }
|
||||
# The Vulkan platform's runtime (architecture D1), metal2vulkan-runtime: a Metal-shaped API on
|
||||
# Vulkan, one path for every device, under reims-vgpu-vulkan's `rt_platform` and `seam` and
|
||||
# reims-vgpu's `pool::rt_blocks`.
|
||||
metal2vulkan-runtime = { git = "https://github.com/reims-go/metal2vulkan", rev = "1dd4e970c0562c73bd3eba12cd15999bb035e019" }
|
||||
metal2vulkan-runtime = { git = "https://github.com/reims-go/metal2vulkan", rev = "8fd7fb5d9cf2df9164b121995b63187f95a3a191" }
|
||||
# The hashes of the Vulkan platform's metallib sources (reims-vgpu-vulkan/build.rs).
|
||||
sha2 = "0.10.9"
|
||||
# A display window's swapchain on Linux (reims-vgpu-vulkan/src/swapchain.rs), at the runtime's
|
||||
|
||||
@@ -720,6 +720,9 @@ pub struct CreateArgs {
|
||||
/// directory are on one file system that makes them, else a full copy) or in-place
|
||||
#[arg(long, default_value = "copy")]
|
||||
pub disk_mode: String,
|
||||
/// Host I/O cache policy for the system disk: default, writeback, none or unsafe
|
||||
#[arg(long)]
|
||||
pub disk_cache: Option<String>,
|
||||
/// Download this macOS from Apple to install: a name (tahoe), a number (26) or latest; with
|
||||
/// --offline, also a release (26.6.2) or a build (25G83)
|
||||
#[arg(long, value_name = "VERSION", conflicts_with = "installer")]
|
||||
@@ -813,6 +816,9 @@ pub struct SetArgs {
|
||||
/// OpenCore may start it
|
||||
#[arg(long)]
|
||||
pub disk_controller: Option<String>,
|
||||
/// Host I/O cache policy for the system disk: default, writeback, none or unsafe
|
||||
#[arg(long)]
|
||||
pub disk_cache: Option<String>,
|
||||
/// The size each of reims-vgpu's windows opens at, WIDTHxHEIGHT in the desktop's points:
|
||||
/// one size for every display, or one for each display, comma-separated
|
||||
/// (2560x1440,1920x1080); on a headless start (start --headless), each display's mode
|
||||
@@ -1203,7 +1209,11 @@ fn create_cmd(a: CreateArgs, host: Host) -> Result<()> {
|
||||
size_mib: parse_size_mib(sz)?,
|
||||
}),
|
||||
(None, Some(p)) => Some(DiskSource::Existing {
|
||||
path: paths::absolute(&p.to_string_lossy()),
|
||||
path: if vm::is_windows_raw_device(p) {
|
||||
p.to_path_buf()
|
||||
} else {
|
||||
paths::absolute(&p.to_string_lossy())
|
||||
},
|
||||
mode: ImportMode::parse(&a.disk_mode)?,
|
||||
}),
|
||||
(None, None) => Some(DiskSource::New {
|
||||
@@ -1225,6 +1235,11 @@ fn create_cmd(a: CreateArgs, host: Host) -> Result<()> {
|
||||
}
|
||||
});
|
||||
s.mac = a.mac.clone();
|
||||
s.disk_cache = a
|
||||
.disk_cache
|
||||
.as_deref()
|
||||
.map(vm::DiskCache::parse)
|
||||
.transpose()?;
|
||||
s.graphics = a.graphics.as_deref().map(vm::Graphics::parse).transpose()?;
|
||||
if let Some(n) = a.displays {
|
||||
s.display.count = n;
|
||||
@@ -1446,14 +1461,19 @@ pub fn describe(vm: &Vm, host: Host, full: Option<&runtime::DiskFull>) -> Vec<(S
|
||||
Err(_) => paths::tilde(&disk),
|
||||
};
|
||||
match &c.q35 {
|
||||
Some(q) => add(
|
||||
"disk",
|
||||
format!(
|
||||
"{disk_name} ({}, {})",
|
||||
c.disk_format.as_str(),
|
||||
q.disk_controller.describe()
|
||||
),
|
||||
),
|
||||
Some(q) => {
|
||||
add(
|
||||
"disk",
|
||||
format!(
|
||||
"{disk_name} ({}, {})",
|
||||
c.disk_format.as_str(),
|
||||
q.disk_controller.describe()
|
||||
),
|
||||
);
|
||||
if !q.disk_cache.is_default() {
|
||||
add("disk cache", q.disk_cache.id().into());
|
||||
}
|
||||
}
|
||||
None => add("disk", format!("{disk_name} ({})", c.disk_format.as_str())),
|
||||
}
|
||||
if let Some(a) = &c.vmapple {
|
||||
@@ -1708,6 +1728,13 @@ fn set(a: SetArgs, host: Host) -> Result<()> {
|
||||
None => bail!("{}: --disk-controller is for x86-64 VMs", c.name),
|
||||
}
|
||||
}
|
||||
if let Some(dc) = &a.disk_cache {
|
||||
let dc = vm::DiskCache::parse(dc)?;
|
||||
match &mut c.q35 {
|
||||
Some(q) => q.disk_cache = dc,
|
||||
None => bail!("{}: --disk-cache is for x86-64 VMs", c.name),
|
||||
}
|
||||
}
|
||||
// A count given is checked against the graphics; one kept from reims-vgpu waits unused on
|
||||
// VMware SVGA, as the resolution does.
|
||||
if let Some(n) = a.displays {
|
||||
|
||||
@@ -92,6 +92,7 @@ pub struct Spec {
|
||||
pub ssh_port: Option<u16>,
|
||||
pub mac: Option<String>,
|
||||
// q35
|
||||
pub disk_cache: Option<DiskCache>,
|
||||
/// macOS to download from Apple, for the installer.
|
||||
pub macos: Option<Download>,
|
||||
pub opencore: Option<PathBuf>,
|
||||
@@ -119,6 +120,7 @@ impl Spec {
|
||||
network: true,
|
||||
ssh_port: None,
|
||||
mac: None,
|
||||
disk_cache: None,
|
||||
macos: None,
|
||||
opencore: None,
|
||||
installer: None,
|
||||
@@ -224,13 +226,28 @@ pub fn create_with(
|
||||
check_free(&dir)?;
|
||||
// What was given is checked before the slow steps: a download, a disk's copy.
|
||||
let mut foreign = None;
|
||||
if let Some(DiskSource::Existing { path, .. }) = &spec.disk {
|
||||
if !path.is_file() {
|
||||
bail!("the disk {} does not exist", path.display());
|
||||
let is_raw_dev = matches!(
|
||||
&spec.disk,
|
||||
Some(DiskSource::Existing { path, .. }) if crate::vm::is_windows_raw_device(path)
|
||||
);
|
||||
if let Some(DiskSource::Existing { path, mode }) = &spec.disk {
|
||||
if crate::vm::is_windows_raw_device(path) {
|
||||
if *mode != ImportMode::InPlace {
|
||||
bail!(
|
||||
"raw Windows disk/partition {} can only be used in-place (--disk-mode in-place)",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if !path.is_file() {
|
||||
bail!("the disk {} does not exist", path.display());
|
||||
}
|
||||
foreign = foreign_disk(path, profile)?;
|
||||
}
|
||||
foreign = foreign_disk(path, profile)?;
|
||||
}
|
||||
check_disk_fits(&spec, &dir, foreign.as_ref())?;
|
||||
if !is_raw_dev {
|
||||
check_disk_fits(&spec, &dir, foreign.as_ref())?;
|
||||
}
|
||||
if let (Some(f), Some(DiskSource::Existing { path, .. })) = (&foreign, &spec.disk) {
|
||||
check_room(f, path, &dir)?;
|
||||
}
|
||||
@@ -1409,6 +1426,7 @@ fn make_q35(
|
||||
cpu_model: default_cpu_model(),
|
||||
cpu_flags: default_cpu_flags(),
|
||||
disk_controller: DiskController::Ahci,
|
||||
disk_cache: spec.disk_cache.unwrap_or_default(),
|
||||
disk_port: 3,
|
||||
});
|
||||
Ok(Vm {
|
||||
@@ -1424,6 +1442,15 @@ fn import_disk(
|
||||
stem: &str,
|
||||
progress: &mut dyn FnMut(&str),
|
||||
) -> Result<(PathBuf, ImageFormat)> {
|
||||
if crate::vm::is_windows_raw_device(src) {
|
||||
if mode != ImportMode::InPlace {
|
||||
bail!(
|
||||
"raw Windows disk/partition {} can only be used in-place (--disk-mode in-place)",
|
||||
src.display()
|
||||
);
|
||||
}
|
||||
return Ok((src.to_path_buf(), ImageFormat::Raw));
|
||||
}
|
||||
if !src.is_file() {
|
||||
bail!("the disk {} does not exist", src.display());
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ pub fn home() -> PathBuf {
|
||||
/// after a `\`; elsewhere as it is.
|
||||
pub fn native(p: PathBuf) -> PathBuf {
|
||||
if cfg!(windows) {
|
||||
if crate::vm::is_windows_raw_device(&p) {
|
||||
let s = p.to_string_lossy().replace('/', "\\");
|
||||
return PathBuf::from(s.trim_end_matches('\\'));
|
||||
}
|
||||
p.components().collect()
|
||||
} else {
|
||||
p
|
||||
|
||||
+182
-12
@@ -169,6 +169,8 @@ pub struct Ctx {
|
||||
/// The host CPU's brand string ([`crate::host::cpu_brand`]), which an x86-64 guest's CPU
|
||||
/// gives as its own (`model-id`); None where the host gives none.
|
||||
pub cpu_brand: Option<String>,
|
||||
/// Whether this Windows QEMU has the repaired native block AIO backend.
|
||||
pub win32_native_aio: bool,
|
||||
/// Whether QEMU's own window can open ([`crate::host::has_screen`]).
|
||||
pub screen: bool,
|
||||
/// Whether the start is headless (`reims-ctl start --headless`): it opens no window, and
|
||||
@@ -451,31 +453,72 @@ fn q35(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
|
||||
),
|
||||
]);
|
||||
push(&["-device", "ide-hd,bus=sata.2,drive=opencore,bootindex=1"]);
|
||||
let mut disk = format!(
|
||||
"id=disk,if=none,format={},file={}",
|
||||
c.disk_format.as_str(),
|
||||
optp(&vm.disk())
|
||||
);
|
||||
let disk_path = vm.disk();
|
||||
let is_raw_dev = crate::vm::is_windows_raw_device(&disk_path);
|
||||
let mut disk = if is_raw_dev {
|
||||
format!(
|
||||
"id=disk,if=none,format=raw,file.driver=host_device,file.filename={}",
|
||||
optp(&disk_path)
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"id=disk,if=none,format={},file={}",
|
||||
c.disk_format.as_str(),
|
||||
optp(&disk_path)
|
||||
)
|
||||
};
|
||||
// The qcow2 image's L2 cache, its table of where each cluster is, up to 32 MiB, which maps
|
||||
// 256 GiB of a disk of 64 KiB clusters (qemu-img's default, which a new disk has). QEMU's own
|
||||
// limit is 32 MiB on Linux and 8 MiB elsewhere, which maps 64 GiB, half a new 128 GiB disk:
|
||||
// on Windows a guest access whose table has left the cache reads it from the image again.
|
||||
// QEMU takes the smaller of this and what the image's size needs (block/qcow2.c,
|
||||
// `read_cache_sizes`), so a smaller disk keeps a smaller cache.
|
||||
if c.disk_format == crate::vm::ImageFormat::Qcow2 {
|
||||
if !is_raw_dev && c.disk_format == crate::vm::ImageFormat::Qcow2 {
|
||||
disk.push_str(",l2-cache-size=32M");
|
||||
}
|
||||
// An install's flushes, which the module's doc measures, are dropped while the installer is
|
||||
// attached.
|
||||
if q.installer.is_some() {
|
||||
disk.push_str(",cache.no-flush=on");
|
||||
if ctx.win32_native_aio
|
||||
&& matches!(
|
||||
q.disk_controller,
|
||||
DiskController::Nvme | DiskController::Virtio
|
||||
)
|
||||
{
|
||||
if is_raw_dev {
|
||||
disk.push_str(",file.aio=native");
|
||||
} else {
|
||||
disk.push_str(",aio=native");
|
||||
}
|
||||
}
|
||||
match q.disk_cache {
|
||||
crate::vm::DiskCache::Default => {
|
||||
// An install's flushes, which the module's doc measures, are dropped while the
|
||||
// installer is attached.
|
||||
if q.installer.is_some() {
|
||||
disk.push_str(",cache.no-flush=on");
|
||||
}
|
||||
}
|
||||
crate::vm::DiskCache::Writeback => {
|
||||
disk.push_str(",cache.direct=off");
|
||||
if q.installer.is_some() {
|
||||
disk.push_str(",cache.no-flush=on");
|
||||
}
|
||||
}
|
||||
crate::vm::DiskCache::None => {
|
||||
disk.push_str(",cache.direct=on");
|
||||
if q.installer.is_some() {
|
||||
disk.push_str(",cache.no-flush=on");
|
||||
}
|
||||
}
|
||||
crate::vm::DiskCache::Unsafe => {
|
||||
disk.push_str(",cache.direct=off,cache.no-flush=on");
|
||||
}
|
||||
}
|
||||
let discard_opt = if is_raw_dev { "" } else { ",discard=unmap" };
|
||||
match q.disk_controller {
|
||||
// `discard=unmap` passes the guest's TRIMs to the image, which frees their space. QEMU's
|
||||
// NVMe controller needs a serial, and without an address takes slot 3, virtio-net's.
|
||||
DiskController::Nvme => push(&[
|
||||
"-drive",
|
||||
&format!("{disk},discard=unmap"),
|
||||
&format!("{disk}{discard_opt}"),
|
||||
"-device",
|
||||
"nvme,drive=disk,serial=reims-ctl,addr=0xa",
|
||||
]),
|
||||
@@ -492,7 +535,7 @@ fn q35(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
|
||||
"-object",
|
||||
"iothread,id=io0",
|
||||
"-drive",
|
||||
&format!("{disk},discard=unmap"),
|
||||
&format!("{disk}{discard_opt}"),
|
||||
"-device",
|
||||
"virtio-blk-pci,drive=disk,iothread=io0,addr=0x6",
|
||||
]),
|
||||
@@ -953,6 +996,7 @@ pub(crate) mod tests {
|
||||
cpu_model: default_cpu_model(),
|
||||
cpu_flags: default_cpu_flags(),
|
||||
disk_controller: DiskController::Ahci,
|
||||
disk_cache: crate::vm::DiskCache::Default,
|
||||
disk_port: 3,
|
||||
}),
|
||||
vmapple: None,
|
||||
@@ -980,6 +1024,7 @@ pub(crate) mod tests {
|
||||
smbios_error_correction: Some(3),
|
||||
smbios_memory_slots: None,
|
||||
cpu_brand: None,
|
||||
win32_native_aio: false,
|
||||
screen: true,
|
||||
headless: false,
|
||||
graphics_rom: "/d/firmware/ReimsGraphics-0123456789abcdef.rom".into(),
|
||||
@@ -2231,6 +2276,131 @@ pub(crate) mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_patched_windows_qemu_gets_native_aio_on_the_system_disk() {
|
||||
let mut vm = q35_vm();
|
||||
for controller in [
|
||||
DiskController::Nvme,
|
||||
DiskController::Virtio,
|
||||
DiskController::Ahci,
|
||||
] {
|
||||
vm.config.q35.as_mut().unwrap().disk_controller = controller;
|
||||
for supported in [false, true] {
|
||||
let c = Ctx {
|
||||
win32_native_aio: supported,
|
||||
..ctx(Host {
|
||||
os: Os::Windows,
|
||||
..linux()
|
||||
})
|
||||
};
|
||||
let args = invocation(&vm, &c).unwrap().args;
|
||||
let disk = args.iter().find(|arg| arg.starts_with("id=disk,")).unwrap();
|
||||
assert_eq!(
|
||||
disk.split(',').any(|opt| opt == "aio=native"),
|
||||
supported
|
||||
&& matches!(controller, DiskController::Nvme | DiskController::Virtio),
|
||||
);
|
||||
assert!(args.iter().filter(|arg| arg.contains("aio=native")).count() <= 1);
|
||||
assert!(!disk.contains("cache.no-flush"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disk_cache_modes_emit_expected_qemu_drive_options() {
|
||||
use crate::vm::{DiskCache, ImageFormat};
|
||||
for fmt in [ImageFormat::Qcow2, ImageFormat::Raw] {
|
||||
let mut vm = q35_vm();
|
||||
vm.config.disk_format = fmt;
|
||||
vm.config.disk = if fmt == ImageFormat::Raw {
|
||||
"disk.img".into()
|
||||
} else {
|
||||
"disk.qcow2".into()
|
||||
};
|
||||
vm.config.q35.as_mut().unwrap().disk_controller = DiskController::Nvme;
|
||||
let c = Ctx {
|
||||
win32_native_aio: true,
|
||||
..ctx(Host {
|
||||
os: Os::Windows,
|
||||
..linux()
|
||||
})
|
||||
};
|
||||
|
||||
vm.config.q35.as_mut().unwrap().disk_cache = DiskCache::Default;
|
||||
let d = invocation(&vm, &c)
|
||||
.unwrap()
|
||||
.args
|
||||
.into_iter()
|
||||
.find(|a| a.starts_with("id=disk,"))
|
||||
.unwrap();
|
||||
assert!(!d.contains("cache.direct"), "{d}");
|
||||
assert!(!d.contains("cache.no-flush"), "{d}");
|
||||
|
||||
vm.config.q35.as_mut().unwrap().disk_cache = DiskCache::Writeback;
|
||||
let d = invocation(&vm, &c)
|
||||
.unwrap()
|
||||
.args
|
||||
.into_iter()
|
||||
.find(|a| a.starts_with("id=disk,"))
|
||||
.unwrap();
|
||||
assert!(d.contains(",cache.direct=off"), "{d}");
|
||||
assert!(!d.contains("cache.no-flush"), "{d}");
|
||||
|
||||
vm.config.q35.as_mut().unwrap().disk_cache = DiskCache::None;
|
||||
let d = invocation(&vm, &c)
|
||||
.unwrap()
|
||||
.args
|
||||
.into_iter()
|
||||
.find(|a| a.starts_with("id=disk,"))
|
||||
.unwrap();
|
||||
assert!(d.contains(",cache.direct=on"), "{d}");
|
||||
assert!(!d.contains("cache.no-flush"), "{d}");
|
||||
|
||||
vm.config.q35.as_mut().unwrap().disk_cache = DiskCache::Unsafe;
|
||||
let d = invocation(&vm, &c)
|
||||
.unwrap()
|
||||
.args
|
||||
.into_iter()
|
||||
.find(|a| a.starts_with("id=disk,"))
|
||||
.unwrap();
|
||||
assert!(d.contains(",cache.direct=off,cache.no-flush=on"), "{d}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_raw_partition_uses_host_device_with_native_aio() {
|
||||
use crate::vm::{DiskCache, ImageFormat};
|
||||
let win_ctx = Ctx {
|
||||
win32_native_aio: true,
|
||||
..ctx(Host {
|
||||
os: Os::Windows,
|
||||
..linux()
|
||||
})
|
||||
};
|
||||
for raw_path in [
|
||||
r"\\?\Volume{11111111-2222-3333-4444-555555555555}",
|
||||
r"\\.\PhysicalDrive2",
|
||||
] {
|
||||
let mut vm = q35_vm();
|
||||
vm.config.disk = raw_path.into();
|
||||
vm.config.disk_format = ImageFormat::Raw;
|
||||
let q = vm.config.q35.as_mut().unwrap();
|
||||
q.disk_controller = DiskController::Nvme;
|
||||
q.disk_cache = DiskCache::Unsafe;
|
||||
let args = invocation(&vm, &win_ctx).unwrap().args;
|
||||
let d = args.iter().find(|a| a.starts_with("id=disk,")).unwrap();
|
||||
assert!(
|
||||
d.contains("format=raw,file.driver=host_device,file.filename="),
|
||||
"{d}"
|
||||
);
|
||||
assert!(d.contains(raw_path), "{d}");
|
||||
assert!(d.contains(",file.aio=native"), "{d}");
|
||||
assert!(d.contains(",cache.direct=off,cache.no-flush=on"), "{d}");
|
||||
assert!(!d.contains("discard=unmap"), "{d}");
|
||||
assert!(!d.contains("l2-cache-size"), "{d}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn installer_disk_goes_on_its_own_port_through_an_overlay() {
|
||||
let mut vm = q35_vm();
|
||||
|
||||
@@ -378,9 +378,15 @@ fn preflight_on(vm: &Vm, host: Host, kernel: &dyn Fn() -> Option<(u32, u32)>) ->
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
need(&vm.disk(), "the disk")?;
|
||||
crate::create::check_disk_format(&vm.disk(), c.profile, crate::create::MAKE_A_VM_OF_THE_COPY)?;
|
||||
crate::create::check_image_fits(&vm.disk(), c.disk_format)?;
|
||||
if !crate::vm::is_windows_raw_device(&vm.disk()) {
|
||||
need(&vm.disk(), "the disk")?;
|
||||
crate::create::check_disk_format(
|
||||
&vm.disk(),
|
||||
c.profile,
|
||||
crate::create::MAKE_A_VM_OF_THE_COPY,
|
||||
)?;
|
||||
crate::create::check_image_fits(&vm.disk(), c.disk_format)?;
|
||||
}
|
||||
match c.profile {
|
||||
Profile::Q35X86_64 => {
|
||||
let q = c.q35.as_ref().unwrap();
|
||||
@@ -973,6 +979,7 @@ pub fn context(vm: &Vm, host: Host) -> Result<Ctx> {
|
||||
let smbios_memory_type = smbios_memory_type(vm, &qemu);
|
||||
let smbios_error_correction = smbios_error_correction(vm, &qemu);
|
||||
let smbios_memory_slots = smbios_memory_slots(vm, &qemu);
|
||||
let win32_native_aio = win32_native_aio(vm, host, &qemu);
|
||||
Ok(Ctx {
|
||||
host,
|
||||
qemu,
|
||||
@@ -985,6 +992,7 @@ pub fn context(vm: &Vm, host: Host) -> Result<Ctx> {
|
||||
smbios_error_correction,
|
||||
smbios_memory_slots,
|
||||
cpu_brand: crate::host::cpu_brand(),
|
||||
win32_native_aio,
|
||||
screen,
|
||||
headless: false,
|
||||
graphics_rom: graphics_rom(vm)?,
|
||||
@@ -1044,6 +1052,14 @@ fn smbios_memory_slots(vm: &Vm, qemu: &Path) -> Option<crate::reims_util::Memory
|
||||
crate::reims_util::model_memory_slots(&config.identity().ok()?.model)
|
||||
}
|
||||
|
||||
/// A version number alone does not distinguish the fixed Windows block backend.
|
||||
fn win32_native_aio(vm: &Vm, host: Host, qemu: &Path) -> bool {
|
||||
host.os == Os::Windows
|
||||
&& vm.config.profile == Profile::Q35X86_64
|
||||
&& crate::install::qemu_version(qemu)
|
||||
.is_some_and(|version| version.ends_with(" [reims-win32-native-aio]"))
|
||||
}
|
||||
|
||||
/// The option ROM of reims-vgpu's own device, written into the data directory for an x86-64 VM
|
||||
/// on it ([`crate::prebuilt::graphics_rom`]); an empty path, which no command names, for another
|
||||
/// VM. An arm64 VM's device has no option ROM: Ambrosia drives it with its module.
|
||||
@@ -1094,6 +1110,7 @@ pub fn invocation_for_print(vm: &Vm, host: Host) -> Result<Invocation> {
|
||||
let smbios_memory_type = smbios_memory_type(vm, &qemu);
|
||||
let smbios_error_correction = smbios_error_correction(vm, &qemu);
|
||||
let smbios_memory_slots = smbios_memory_slots(vm, &qemu);
|
||||
let win32_native_aio = win32_native_aio(vm, host, &qemu);
|
||||
Ctx {
|
||||
host,
|
||||
qemu,
|
||||
@@ -1106,6 +1123,7 @@ pub fn invocation_for_print(vm: &Vm, host: Host) -> Result<Invocation> {
|
||||
smbios_error_correction,
|
||||
smbios_memory_slots,
|
||||
cpu_brand: crate::host::cpu_brand(),
|
||||
win32_native_aio,
|
||||
screen: crate::host::has_screen(&vm.config.extra_env),
|
||||
headless: false,
|
||||
graphics_rom: graphics_rom(vm).unwrap_or_else(|_| crate::prebuilt::graphics_rom_path()),
|
||||
|
||||
@@ -244,6 +244,73 @@ impl DiskController {
|
||||
}
|
||||
}
|
||||
|
||||
/// Host cache policy for an x86-64 VM's system disk.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum DiskCache {
|
||||
/// QEMU's default (`writeback` with flushes forwarded to the host, except
|
||||
/// during installation when `cache.no-flush=on` is added automatically).
|
||||
#[default]
|
||||
Default,
|
||||
/// Host page cache enabled (`cache.direct=off`), guest flushes forwarded.
|
||||
Writeback,
|
||||
/// Bypass host page cache (`cache.direct=on`), guest flushes forwarded.
|
||||
None,
|
||||
/// Host page cache enabled and guest flushes ignored (`cache.direct=off,cache.no-flush=on`).
|
||||
Unsafe,
|
||||
}
|
||||
|
||||
impl DiskCache {
|
||||
pub const ALL: [DiskCache; 4] = [
|
||||
DiskCache::Default,
|
||||
DiskCache::Writeback,
|
||||
DiskCache::None,
|
||||
DiskCache::Unsafe,
|
||||
];
|
||||
|
||||
pub fn id(self) -> &'static str {
|
||||
match self {
|
||||
DiskCache::Default => "default",
|
||||
DiskCache::Writeback => "writeback",
|
||||
DiskCache::None => "none",
|
||||
DiskCache::Unsafe => "unsafe",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(s: &str) -> Result<DiskCache> {
|
||||
let low = s.trim().to_ascii_lowercase();
|
||||
DiskCache::ALL
|
||||
.into_iter()
|
||||
.find(|c| c.id() == low)
|
||||
.with_context(|| format!("disk cache is default, writeback, none or unsafe, not {s:?}"))
|
||||
}
|
||||
|
||||
pub fn is_default(&self) -> bool {
|
||||
*self == DiskCache::Default
|
||||
}
|
||||
}
|
||||
|
||||
/// Reports whether `path` is a Windows raw physical disk or volume/partition
|
||||
/// device path (`\\.\PhysicalDriveN`, `\\.\HarddiskVolumeN`,
|
||||
/// `\\.\HarddiskNPartitionM`, `\\.\Volume{...}`, or `\\?\Volume{...}`),
|
||||
/// excluding extended-length regular file paths like `\\?\D:\...`.
|
||||
pub fn is_windows_raw_device(path: &Path) -> bool {
|
||||
let norm = path.to_string_lossy().replace('/', "\\");
|
||||
let rest = if let Some(r) = norm.strip_prefix(r"\\.\") {
|
||||
r
|
||||
} else if let Some(r) = norm.strip_prefix(r"\\?\") {
|
||||
let low = r.to_ascii_lowercase();
|
||||
return low.starts_with("volume{");
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
let low = rest.to_ascii_lowercase();
|
||||
low.starts_with("physicaldrive")
|
||||
|| low.starts_with("harddiskvolume")
|
||||
|| low.starts_with("harddisk")
|
||||
|| low.starts_with("volume{")
|
||||
}
|
||||
|
||||
/// reims-vgpu's displays, one by default and up to [`DISPLAYS_MAX`], each in a window of its own:
|
||||
/// each window opens at its display's size of the resolution ([`Display::window_sizes`]) and keeps
|
||||
/// the size the person gives it, which its display follows, at the refresh rate of the host
|
||||
@@ -558,6 +625,9 @@ pub struct Q35 {
|
||||
/// installer may boot instead.
|
||||
#[serde(default, skip_serializing_if = "DiskController::is_ahci")]
|
||||
pub disk_controller: DiskController,
|
||||
/// Host I/O cache mode for the system disk.
|
||||
#[serde(default, skip_serializing_if = "DiskCache::is_default")]
|
||||
pub disk_cache: DiskCache,
|
||||
/// The system disk's AHCI port, on [`DiskController::Ahci`]: 3, after OpenCore's 2.
|
||||
#[serde(default = "default_disk_port")]
|
||||
pub disk_port: u32,
|
||||
@@ -991,6 +1061,10 @@ impl Vm {
|
||||
}
|
||||
|
||||
pub fn disk(&self) -> PathBuf {
|
||||
if is_windows_raw_device(&self.config.disk) {
|
||||
let s = self.config.disk.to_string_lossy().replace('/', "\\");
|
||||
return PathBuf::from(s.trim_end_matches('\\'));
|
||||
}
|
||||
self.path(&self.config.disk)
|
||||
}
|
||||
|
||||
@@ -1411,6 +1485,7 @@ pub(crate) mod tests {
|
||||
cpu_model: default_cpu_model(),
|
||||
cpu_flags: default_cpu_flags(),
|
||||
disk_controller: DiskController::Nvme,
|
||||
disk_cache: DiskCache::Default,
|
||||
disk_port: 3,
|
||||
}),
|
||||
vmapple: None,
|
||||
|
||||
@@ -320,6 +320,10 @@ pub trait GpuDevice<P: Platform>: Handle {
|
||||
/// queue between command queues answers `new_command_queue`'s queue. Never nil-checked; a raise
|
||||
/// inside it dies at the call, as one inside `newCommandQueue` does.
|
||||
fn new_command_queue_unshared(&self) -> Option<P::CommandQueue>;
|
||||
/// The private IOSurface copy FIFO. A cache transaction may record all its copies before
|
||||
/// it can publish any of them. Allocating a command buffer here must not wait for a
|
||||
/// previously recorded copy to retire. GPU execution still follows queue order.
|
||||
fn new_cache_transfer_queue(&self) -> Option<P::CommandQueue>;
|
||||
/// No Metal counterpart: how many times the platform recovered the device's GPU so far, its
|
||||
/// lost device made again behind the same device object (the Vulkan platform's runtime makes
|
||||
/// a new `VkDevice`, `device-recovered`). The textures, pipelines and pooled buffers made
|
||||
|
||||
@@ -490,6 +490,11 @@ impl GpuDevice<FakePlatform> for Fk<kind::Device> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn new_cache_transfer_queue(&self) -> Option<<FakePlatform as Platform>::CommandQueue> {
|
||||
// Fake queues allocate independent handles immediately.
|
||||
self.new_command_queue_unshared()
|
||||
}
|
||||
|
||||
/// Unlogged, as the property the platform answers it from: [`World::copy_guest_ram`].
|
||||
///
|
||||
/// [`World::copy_guest_ram`]: crate::core::testkit::objects::World::copy_guest_ram
|
||||
|
||||
@@ -2274,6 +2274,18 @@ impl GpuDevice<RtPlatform> for RtObj<RtDevice> {
|
||||
recorded_answer
|
||||
}
|
||||
|
||||
fn new_cache_transfer_queue(&self) -> Option<RtObj<RtQueue>> {
|
||||
let call = crate::recorder::rec_call!("m2v.newCacheTransferQueue", self);
|
||||
let queue = crate::recorder::run(|| {
|
||||
Some(RtObj::new(RtQueue::new(
|
||||
self.rt.new_host_batch_queue(),
|
||||
self.clone_ref(),
|
||||
)))
|
||||
});
|
||||
crate::recorder::rec_done!(call, queue);
|
||||
queue
|
||||
}
|
||||
|
||||
/// No: rt copies no guest RAM by its host addresses.
|
||||
fn copies_guest_ram(&self) -> bool {
|
||||
false
|
||||
@@ -3164,6 +3176,56 @@ mod tests {
|
||||
use crate::core::platform::device::relaying_gaps;
|
||||
use crate::core::platform::values::{OptionSet, TextureDesc};
|
||||
|
||||
#[test]
|
||||
fn a_cache_transfer_batch_publishes_its_bytes_to_a_waiting_queue() {
|
||||
use crate::core::platform::command::{CommandBuffer as _, CommandQueue as _};
|
||||
|
||||
let platform = RtPlatform::new();
|
||||
let device = platform.system_default_device().expect("a Vulkan device");
|
||||
let copies = device.new_cache_transfer_queue().expect("cache transfers");
|
||||
let consumer = device.new_command_queue().expect("a guest queue");
|
||||
let shared = || {
|
||||
device
|
||||
.new_buffer_of_length(OnFault::Return, 16, 0)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
};
|
||||
let (source, destination) = (shared(), shared());
|
||||
let filled = device.rt().new_event().unwrap();
|
||||
let done = device.rt().new_shared_event().unwrap();
|
||||
let mut batch = Vec::new();
|
||||
for value in 1..=3 {
|
||||
let copy = copies.command_buffer(OnFault::Return).unwrap().unwrap();
|
||||
let mut blit = copy.rt().blit_command_encoder().unwrap();
|
||||
blit.fill_buffer(source.rt(), 0..16, value).unwrap();
|
||||
blit.end_encoding();
|
||||
copy.rt()
|
||||
.encode_signal_event(&filled, u64::from(value))
|
||||
.unwrap();
|
||||
batch.push(copy);
|
||||
}
|
||||
let read = consumer.command_buffer(OnFault::Return).unwrap().unwrap();
|
||||
read.rt().encode_wait_for_event(&filled, 3).unwrap();
|
||||
let mut blit = read.rt().blit_command_encoder().unwrap();
|
||||
blit.copy_from_buffer_to_buffer(source.rt(), 0, destination.rt(), 0, 16)
|
||||
.unwrap();
|
||||
blit.end_encoding();
|
||||
read.rt().encode_signal_event(done.as_event(), 1).unwrap();
|
||||
read.commit(OnFault::Return).unwrap();
|
||||
for copy in batch {
|
||||
copy.commit(OnFault::Return).unwrap();
|
||||
}
|
||||
assert!(
|
||||
done.wait_until_signaled_value(1, std::time::Duration::from_secs(10))
|
||||
.unwrap()
|
||||
);
|
||||
let at = destination.rt().contents().expect("shared storage");
|
||||
// SAFETY: the GPU signal covers the final copy, the allocation is 16 bytes and kept
|
||||
// alive by destination, and there are no further writers.
|
||||
let bytes = unsafe { std::slice::from_raw_parts(at.as_ptr(), 16) };
|
||||
assert_eq!(bytes, &[3; 16]);
|
||||
}
|
||||
|
||||
/// The options a device is opened with carry the helper's memory ceiling on this host, the
|
||||
/// one a memory breach is kept under.
|
||||
#[test]
|
||||
|
||||
@@ -27,6 +27,8 @@ them; its `manual` checks are on a Linux host's guest boot.
|
||||
| `resolution=2560x1600` | the mode the window opens for, and the guest is offered until the window's pixels are known (QEMU's reims-graphics-pci property; 1920x1080 by default); with several displays, every window's |
|
||||
| `displays=2` | the reims-graphics device's displays, 1 to 4, a window each (QEMU's reims-graphics-pci property; 1 by default) |
|
||||
| `REIMS_VGPU_WINDOW_IMPL=sdl` | macOS, built with the `macos-sdl` feature (on by default): SDL3's window in place of AppKit's ("On macOS through SDL3" below) |
|
||||
| `REIMS_VGPU_WINDOW_RELEASE_KEYS=Ctrl+Shift+F12` | additional release shortcut for SDL windows on Windows and Linux; when unset, `REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_KEYS` can supply it |
|
||||
| `REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_RELEASE_ON_LEAVE=1` | on Windows and Linux, release the keyboard grab while the mouse is out of the SDL window |
|
||||
|
||||
Unset or unparsable values give the defaults below.
|
||||
`test: env::unset_or_unparsable_values_are_the_defaults`,
|
||||
@@ -833,6 +835,19 @@ runtime's own device. The switches above apply, and `resolution=` too.
|
||||
GNOME asks once whether the window may take its shortcuts, the answer
|
||||
kept for the installed app's entry, and Super+Escape gives GNOME its
|
||||
shortcuts until the window is focused again)
|
||||
- An additional release shortcut uses at least one modifier and one to three
|
||||
ordinary keys, and releases as the release chord does. The title names it
|
||||
in place of the chord, which still works. An empty or invalid setting
|
||||
leaves the chord alone.
|
||||
`test: native::sdl_thread::input::a_custom_shortcut_releases_the_grab_and_keeps_its_last_key`,
|
||||
`test: native::sdl_thread::input::a_custom_shortcut_can_hold_two_regular_keys`,
|
||||
`test: native::sdl_thread::input::an_invalid_shortcut_keeps_the_default`
|
||||
- With release on mouse leave on, the mouse leaving the window lifts the held
|
||||
keys and buttons and releases the keyboard grab until the mouse comes back
|
||||
or the window next gains the keyboard. The setting also turns off a game's
|
||||
pointer lock and a drag gone on onto another display.
|
||||
`test: native::sdl_thread::input::the_mouse_leaving_releases_the_grab_until_it_returns_when_enabled`,
|
||||
`manual` (move the pointer out of the window and back)
|
||||
- Scrolling: the wheel's notches, or, where the host takes smooth
|
||||
scrolling, its lines at 10 points each, in no gesture (SDL gives no
|
||||
phases); the guest gets the device's own direction.
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
//! guest's display mode from the window's pixel size so the display keeps offering the
|
||||
//! configured resolution (e.g. 5120x2880 HiDPI supersampled into a 4K borderless window) and
|
||||
//! scales the frame on the GPU. Default: off.
|
||||
//! - `REIMS_VGPU_WINDOW_RELEASE_KEYS`: an additional release shortcut for SDL's windows on
|
||||
//! Windows and Linux, such as `Ctrl+Shift+F12`. Reims-Go's capture shortcut plugin can supply
|
||||
//! it through its own namespace. The built-in release chord remains available.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
@@ -31,6 +34,12 @@ pub const IMPL_VAR: &str = "REIMS_VGPU_WINDOW_IMPL";
|
||||
pub const CAPTURE_VAR: &str = "REIMS_VGPU_WINDOW_CAPTURE";
|
||||
/// The fixed guest mode switch's variable.
|
||||
pub const FIXED_MODE_VAR: &str = "REIMS_VGPU_WINDOW_FIXED_MODE";
|
||||
/// The extra release shortcut for Windows and Linux SDL windows.
|
||||
pub const RELEASE_KEYS_VAR: &str = "REIMS_VGPU_WINDOW_RELEASE_KEYS";
|
||||
/// The same shortcut supplied through the Reims-Go capture shortcut plugin.
|
||||
const PLUGIN_RELEASE_KEYS_VAR: &str = "REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_KEYS";
|
||||
/// The plugin's switch for releasing input when the mouse leaves the window.
|
||||
const PLUGIN_RELEASE_ON_LEAVE_VAR: &str = "REIMS_PLUGIN_LOCAL_CAPTURE_SHORTCUT_RELEASE_ON_LEAVE";
|
||||
|
||||
/// Whether the window may grab the keyboard and lock the game pointer by default.
|
||||
pub const CAPTURE_DEFAULT: bool = true;
|
||||
@@ -48,6 +57,10 @@ pub struct Settings {
|
||||
pub capture: bool,
|
||||
/// Keep offering the configured guest resolution instead of following the window's pixels.
|
||||
pub fixed_mode: bool,
|
||||
/// Additional release shortcut text for the SDL window.
|
||||
pub release_keys: Option<String>,
|
||||
/// Release input when the mouse leaves the SDL window.
|
||||
pub release_on_leave: bool,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@@ -58,6 +71,8 @@ impl Default for Settings {
|
||||
window_impl: WindowImpl::AppKit,
|
||||
capture: CAPTURE_DEFAULT,
|
||||
fixed_mode: false,
|
||||
release_keys: None,
|
||||
release_on_leave: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +146,10 @@ pub fn settings() -> &'static Settings {
|
||||
window_impl: parse_impl(var(IMPL_VAR).as_deref()),
|
||||
capture: parse_capture(var(CAPTURE_VAR).as_deref()),
|
||||
fixed_mode: parse_fixed_mode(var(FIXED_MODE_VAR).as_deref()),
|
||||
release_keys: var(RELEASE_KEYS_VAR).or_else(|| var(PLUGIN_RELEASE_KEYS_VAR)),
|
||||
release_on_leave: var(PLUGIN_RELEASE_ON_LEAVE_VAR)
|
||||
.as_deref()
|
||||
.is_some_and(parse_switch),
|
||||
..parse(borderless.as_deref(), screens.as_deref())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
//! it where it is, moved nowhere, the guest's cursor left where the drag took it; the release
|
||||
//! chord, losing the keyboard and closing unlock it where it was held.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::super::HOST_OS;
|
||||
@@ -81,7 +82,7 @@ use crate::config::{
|
||||
use crate::game::Game;
|
||||
use crate::geometry::{self, Rect};
|
||||
use crate::grab::{self, Grab};
|
||||
use crate::keys::{KeyEvent, KeyState};
|
||||
use crate::keys::{KeyEvent, KeyState, Modifiers};
|
||||
use crate::scroll::POINTS_PER_LINE;
|
||||
|
||||
/// What the window knows when an event reaches it.
|
||||
@@ -175,6 +176,109 @@ fn fixed(points: f64) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// An additional release shortcut, using USB key positions like SDL's keyboard path.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ReleaseShortcut {
|
||||
modifiers: Modifiers,
|
||||
keys: Vec<u16>,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl ReleaseShortcut {
|
||||
pub(crate) fn parse(value: &str) -> Option<Self> {
|
||||
let parts = value.split('+').map(str::trim).map(str::to_ascii_uppercase);
|
||||
let mut modifiers = Modifiers::default();
|
||||
let mut keys = Vec::new();
|
||||
let mut key_names = Vec::new();
|
||||
for part in parts {
|
||||
let held = match part.as_str() {
|
||||
"CTRL" => &mut modifiers.control,
|
||||
"ALT" => &mut modifiers.option,
|
||||
"SHIFT" => &mut modifiers.shift,
|
||||
"WIN" | "SUPER" => &mut modifiers.command,
|
||||
_ => {
|
||||
let key = Self::parse_key(&part)?;
|
||||
if keys.len() == 3 || keys.contains(&key) {
|
||||
return None;
|
||||
}
|
||||
keys.push(key);
|
||||
key_names.push(part);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if std::mem::replace(held, true) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
if modifiers == Modifiers::default() || keys.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut name = String::new();
|
||||
for (held, label) in [
|
||||
(modifiers.control, "Ctrl+"),
|
||||
(modifiers.option, "Alt+"),
|
||||
(modifiers.shift, "Shift+"),
|
||||
(
|
||||
modifiers.command,
|
||||
if cfg!(windows) { "Win+" } else { "Super+" },
|
||||
),
|
||||
] {
|
||||
if held {
|
||||
name.push_str(label);
|
||||
}
|
||||
}
|
||||
name.push_str(&key_names.join("+"));
|
||||
Some(Self {
|
||||
modifiers,
|
||||
keys,
|
||||
name,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_key(key_name: &str) -> Option<u16> {
|
||||
let key = match key_name.as_bytes() {
|
||||
[letter @ b'A'..=b'Z'] => u16::from(*letter - b'A') + 0x04,
|
||||
[digit @ b'1'..=b'9'] => u16::from(*digit - b'1') + 0x1e,
|
||||
[b'0'] => 0x27,
|
||||
_ => {
|
||||
let number = key_name.strip_prefix('F')?.parse::<u16>().ok()?;
|
||||
if !matches!(
|
||||
key_name,
|
||||
"F1" | "F2"
|
||||
| "F3"
|
||||
| "F4"
|
||||
| "F5"
|
||||
| "F6"
|
||||
| "F7"
|
||||
| "F8"
|
||||
| "F9"
|
||||
| "F10"
|
||||
| "F11"
|
||||
| "F12"
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
0x3a + number - 1
|
||||
}
|
||||
};
|
||||
Some(key)
|
||||
}
|
||||
|
||||
pub(crate) fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// Whether `usage` going down completes the shortcut, `keys` the keys already down.
|
||||
fn pressed(&self, usage: u16, keys: &KeyState) -> bool {
|
||||
self.keys.contains(&usage)
|
||||
&& self
|
||||
.keys
|
||||
.iter()
|
||||
.all(|&key| key == usage || keys.is_held(key))
|
||||
&& self.modifiers == keys.held_modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
/// One window's input decisions (the module doc).
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Input {
|
||||
@@ -182,6 +286,12 @@ pub(crate) struct Input {
|
||||
keys: KeyState,
|
||||
/// Whether the window holds the keyboard grab.
|
||||
grab: Grab,
|
||||
/// The person's own shortcut, which releases as the release chord does.
|
||||
release_shortcut: Option<ReleaseShortcut>,
|
||||
/// Whether the mouse leaving the window releases the input.
|
||||
release_on_leave: bool,
|
||||
/// The mouse leaving released the keyboard grab, until the mouse comes back.
|
||||
left: bool,
|
||||
/// The `BUTTON_*` bits of the buttons the guest was told are down.
|
||||
buttons: u32,
|
||||
/// The pointer event last sent.
|
||||
@@ -246,6 +356,42 @@ impl Input {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets an additional shortcut for releasing the input.
|
||||
pub(crate) fn with_release_shortcut(self, release_shortcut: Option<ReleaseShortcut>) -> Input {
|
||||
Input {
|
||||
release_shortcut,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Releases the input when the mouse leaves the window. Nothing then locks the pointer, so it
|
||||
/// can always leave.
|
||||
pub(crate) fn with_release_on_leave(self, release_on_leave: bool) -> Input {
|
||||
Input {
|
||||
release_on_leave,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// The mouse left the window: where the setting asks, every key and button held is lifted and
|
||||
/// the shell has its keys until the mouse comes back or the window next gains the keyboard.
|
||||
pub(crate) fn mouse_left(&mut self) -> Reaction {
|
||||
if !self.release_on_leave || !self.focused || self.question || !self.holds_keyboard() {
|
||||
return Reaction::default();
|
||||
}
|
||||
self.lift_buttons();
|
||||
self.left = true;
|
||||
self.release()
|
||||
}
|
||||
|
||||
/// The mouse came back to the window: the grab its leaving released is held again.
|
||||
pub(crate) fn mouse_entered(&mut self) -> Reaction {
|
||||
let left = std::mem::take(&mut self.left);
|
||||
Reaction {
|
||||
held_changed: left && self.focused && self.grab.focus_gained(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a drag has gone past the image's edge.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn is_away(&self) -> bool {
|
||||
@@ -305,13 +451,20 @@ impl Input {
|
||||
|
||||
/// What the title ends with: the release chord while the window has the keyboard and holds
|
||||
/// its grab, or a game's lock holds the pointer, in the host's OS's names for its keys
|
||||
/// ([`grab::held_suffix`]); nothing otherwise.
|
||||
pub(crate) fn title_suffix(&self) -> &'static str {
|
||||
grab::held_suffix(
|
||||
/// ([`grab::held_suffix`]); nothing otherwise. The person's own shortcut is named in place of
|
||||
/// the chord.
|
||||
pub(crate) fn title_suffix(&self) -> Cow<'static, str> {
|
||||
let suffix = grab::held_suffix(
|
||||
HOST_OS,
|
||||
self.focused && self.holds_keyboard(),
|
||||
self.game.is_on(),
|
||||
)
|
||||
);
|
||||
match &self.release_shortcut {
|
||||
Some(shortcut) => suffix
|
||||
.replace(grab::chord_name(HOST_OS), &shortcut.name)
|
||||
.into(),
|
||||
None => suffix.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// What to send, taken.
|
||||
@@ -344,7 +497,8 @@ impl Input {
|
||||
return;
|
||||
}
|
||||
if let (Some(point), Some(mode)) = (at.point, guest_mode(at)) {
|
||||
if self.focused
|
||||
if !self.release_on_leave
|
||||
&& self.focused
|
||||
&& geometry::contains(at.image, point)
|
||||
&& let Some(motion) = self.motion.clone()
|
||||
&& let Some(hold) = self.game.begin(motion.as_ref(), point)
|
||||
@@ -356,7 +510,8 @@ impl Input {
|
||||
Some(ToHost::Pointer { at, .. }) => Some(at),
|
||||
_ => None,
|
||||
};
|
||||
if self.buttons != 0
|
||||
if !self.release_on_leave
|
||||
&& self.buttons != 0
|
||||
&& let Some(beyond) = self.beyond.clone()
|
||||
&& let Some(hold) =
|
||||
self.away
|
||||
@@ -552,6 +707,15 @@ impl Input {
|
||||
}
|
||||
return Reaction::default();
|
||||
}
|
||||
if !repeat
|
||||
&& (self.holds_keyboard() || self.game.is_on())
|
||||
&& self
|
||||
.release_shortcut
|
||||
.as_ref()
|
||||
.is_some_and(|shortcut| shortcut.pressed(usage, &self.keys))
|
||||
{
|
||||
return self.release();
|
||||
}
|
||||
if let Some(event) = self.keys.key_down(usage, repeat) {
|
||||
self.out.push(ToHost::Key(event));
|
||||
}
|
||||
@@ -568,6 +732,7 @@ impl Input {
|
||||
/// ([`Grab::focus_gained`]), and the title names the chord where it does.
|
||||
pub(crate) fn focus_gained(&mut self) -> Reaction {
|
||||
self.focused = true;
|
||||
self.left = false;
|
||||
let regrab = self.grab.focus_gained();
|
||||
Reaction {
|
||||
held_changed: regrab || self.holds_keyboard(),
|
||||
@@ -927,6 +1092,86 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// The person's own shortcut releases the grab as the chord does, its last key kept from the
|
||||
/// guest and the rest lifted there; the title names it.
|
||||
#[test]
|
||||
fn a_custom_shortcut_releases_the_grab_and_keeps_its_last_key() {
|
||||
let mut input =
|
||||
focused().with_release_shortcut(ReleaseShortcut::parse(" shift + ctrl + f12 "));
|
||||
assert!(input.title_suffix().contains("press Ctrl+Shift+F12 to"));
|
||||
input.key(0xE0, true, false);
|
||||
input.key(0xE1, true, false);
|
||||
assert!(input.key(0x45, true, false).held_changed);
|
||||
assert!(!input.holds_keyboard());
|
||||
assert_eq!(input.title_suffix(), "");
|
||||
assert_eq!(
|
||||
input.take(),
|
||||
vec![
|
||||
ToHost::Key(KeyEvent::down(0xE0)),
|
||||
ToHost::Key(KeyEvent::down(0xE1)),
|
||||
ToHost::Key(KeyEvent::up(0xE1)),
|
||||
ToHost::Key(KeyEvent::up(0xE0)),
|
||||
]
|
||||
);
|
||||
// Released, the shortcut is the guest's keys.
|
||||
input.key(0xE0, true, false);
|
||||
input.key(0xE1, true, false);
|
||||
assert!(!input.key(0x45, true, false).held_changed);
|
||||
assert_eq!(input.take().len(), 3);
|
||||
input.focus_gained();
|
||||
assert!(input.holds_keyboard());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_custom_shortcut_can_hold_two_regular_keys() {
|
||||
let mut input = focused().with_release_shortcut(ReleaseShortcut::parse("Ctrl+A+Z"));
|
||||
assert!(!input.key(0xE0, true, false).held_changed);
|
||||
assert!(!input.key(0x04, true, false).held_changed);
|
||||
assert!(input.key(0x1D, true, false).held_changed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_invalid_shortcut_keeps_the_default() {
|
||||
for value in [
|
||||
"",
|
||||
"F12",
|
||||
"Ctrl+Shift",
|
||||
"Ctrl+Ctrl+F12",
|
||||
"Ctrl+F13",
|
||||
"Ctrl+F01",
|
||||
] {
|
||||
assert!(ReleaseShortcut::parse(value).is_none(), "{value:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// With the setting on, the mouse leaving the window lifts what is held and releases the grab
|
||||
/// until it comes back; the release chord's own release outlasts a visit elsewhere.
|
||||
#[test]
|
||||
fn the_mouse_leaving_releases_the_grab_until_it_returns_when_enabled() {
|
||||
for enabled in [false, true] {
|
||||
let mut input = focused().with_release_on_leave(enabled);
|
||||
input.button_down(BUTTON_LEFT, &at((10.0, 10.0)));
|
||||
input.key(0x04, true, false);
|
||||
input.take();
|
||||
assert_eq!(input.mouse_left().held_changed, enabled);
|
||||
assert_eq!(input.holds_keyboard(), !enabled);
|
||||
let sent = input.take();
|
||||
assert_eq!(sent.contains(&ToHost::Key(KeyEvent::up(0x04))), enabled);
|
||||
assert_eq!(
|
||||
sent.iter()
|
||||
.any(|event| matches!(event, ToHost::Pointer { buttons: 0, .. })),
|
||||
enabled
|
||||
);
|
||||
assert_eq!(input.mouse_entered().held_changed, enabled);
|
||||
assert!(input.holds_keyboard());
|
||||
}
|
||||
let mut input = focused().with_release_on_leave(true);
|
||||
input.release();
|
||||
assert!(!input.mouse_left().held_changed);
|
||||
assert!(!input.mouse_entered().held_changed);
|
||||
assert!(!input.holds_keyboard());
|
||||
}
|
||||
|
||||
/// Nothing holds the pointer: it is sent over the image alone, and outside it only in a drag,
|
||||
/// held at the image's edge, which ends there
|
||||
#[test]
|
||||
|
||||
@@ -133,6 +133,16 @@ impl Input {
|
||||
self.0.focus_lost().held_changed
|
||||
}
|
||||
|
||||
/// The mouse left the window: whether the keyboard's grab and the title follow.
|
||||
pub(crate) fn mouse_left(&mut self) -> bool {
|
||||
self.0.mouse_left().held_changed
|
||||
}
|
||||
|
||||
/// The mouse came back to the window: whether the keyboard's grab and the title follow.
|
||||
pub(crate) fn mouse_entered(&mut self) -> bool {
|
||||
self.0.mouse_entered().held_changed
|
||||
}
|
||||
|
||||
/// The compositor took the keyboard while the window keeps its focus (the module doc): every
|
||||
/// key and button held is lifted.
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -154,7 +164,7 @@ impl Input {
|
||||
|
||||
/// What the title ends with: the release chord while something holds
|
||||
/// ([`input::Input::title_suffix`]).
|
||||
pub(crate) fn title_suffix(&self) -> &'static str {
|
||||
pub(crate) fn title_suffix(&self) -> std::borrow::Cow<'static, str> {
|
||||
self.0.title_suffix()
|
||||
}
|
||||
|
||||
@@ -256,6 +266,25 @@ pub(crate) fn open(window: &Arc<Window>, borderless: bool, _taken: &[Frame]) ->
|
||||
display.0
|
||||
);
|
||||
let callbacks = window.callbacks();
|
||||
let settings = crate::env::settings();
|
||||
let release_shortcut = settings
|
||||
.release_keys
|
||||
.as_deref()
|
||||
.and_then(input::ReleaseShortcut::parse);
|
||||
if release_shortcut.is_none()
|
||||
&& settings
|
||||
.release_keys
|
||||
.as_deref()
|
||||
.is_some_and(|keys| !keys.trim().is_empty())
|
||||
{
|
||||
log::warn!(target: "reims_vgpu_window", "invalid input release shortcut; using the default");
|
||||
}
|
||||
log::info!(target: "reims_vgpu_window",
|
||||
"input settings: capture={}, release shortcut={}, release on mouse leave={}",
|
||||
settings.capture,
|
||||
release_shortcut.as_ref().map_or("default", input::ReleaseShortcut::name),
|
||||
settings.release_on_leave,
|
||||
);
|
||||
Some(Opened {
|
||||
sdl,
|
||||
asked: size,
|
||||
@@ -266,7 +295,9 @@ pub(crate) fn open(window: &Arc<Window>, borderless: bool, _taken: &[Frame]) ->
|
||||
.and_then(|callbacks| callbacks.beyond.clone()),
|
||||
callbacks.and_then(|callbacks| callbacks.motion),
|
||||
)
|
||||
.with_capture(crate::env::settings().capture),
|
||||
.with_capture(settings.capture)
|
||||
.with_release_shortcut(release_shortcut)
|
||||
.with_release_on_leave(settings.release_on_leave),
|
||||
),
|
||||
state: State {
|
||||
display,
|
||||
|
||||
@@ -442,7 +442,15 @@ impl Shell {
|
||||
// SDL's cursor is the process's: another window may have hidden it.
|
||||
self.over_image = false;
|
||||
self.refresh_cursor();
|
||||
false
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let held_changed = if k == SDL_EVENT_WINDOW_MOUSE_LEAVE.0 {
|
||||
self.input.mouse_left()
|
||||
} else {
|
||||
self.input.mouse_entered()
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
let held_changed = false;
|
||||
held_changed
|
||||
}
|
||||
k if k == SDL_EVENT_DROP_BEGIN.0 => {
|
||||
self.drop_batch.begin();
|
||||
|
||||
@@ -2634,10 +2634,9 @@ impl CarriedPages {
|
||||
|
||||
/// The host's transfer queue, on which every copy runs, and the event its fills signal.
|
||||
struct Transfer<P: Platform> {
|
||||
/// Unshared ([`new_command_queue_unshared`]): a present of a surface waits for its fill, and
|
||||
/// a frame drawn from a cache for the fill before it ([`FillWait`]).
|
||||
///
|
||||
/// [`new_command_queue_unshared`]: reims_vgpu_vulkan::core::platform::device::GpuDevice::new_command_queue_unshared
|
||||
/// Private copy FIFO. A transaction can prepare all of its fills under the cache lock and
|
||||
/// publish them in order after unlocking. Presents and consumers wait for their fill
|
||||
/// ([`FillWait`]).
|
||||
queue: P::CommandQueue,
|
||||
/// The early copies behind writers that hold no video encoder
|
||||
/// ([`SurfaceCaches::early_copies`]), apart from the fills, so neither waits behind the
|
||||
@@ -2659,7 +2658,7 @@ impl<P: Platform> Transfer<P> {
|
||||
/// A transfer queue and its event, its fills telling `hook`; `None` where the platform makes
|
||||
/// either not.
|
||||
fn new(device: &P::Device, hook: &Arc<OnceLock<FillHook>>) -> RaiseResult<Option<Self>> {
|
||||
let Some(queue) = device.new_command_queue_unshared() else {
|
||||
let Some(queue) = device.new_cache_transfer_queue() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(event) = device.new_event(ON)? else {
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
"win10-compat",
|
||||
"win10-startup-ipis",
|
||||
"win32-coroutine-fiber",
|
||||
"win32-native-aio",
|
||||
"win32-unicode-input",
|
||||
"window-file-drop",
|
||||
"window-release-shortcut",
|
||||
"window-text-drop"
|
||||
]
|
||||
}
|
||||
Vendored
+1
-1
Submodule vendor/qemu updated: 0c0d881c49...c6f4d7b5c6.
Reference in new issue
Block a user