feat(patches): add reims-vgpu/metal2vulkan snapshot replay and build pipeline support
This commit is contained in:
1 parent
585669e0b3
commit
347840490e
8 files changed
+4972
-70
No files matched your search
@@ -142,6 +142,21 @@ jobs:
|
||||
if ($LASTEXITCODE) { throw 'reims-util fetch failed' }
|
||||
git -C $utilRepo checkout -q --detach FETCH_HEAD
|
||||
if ($LASTEXITCODE) { throw 'reims-util checkout failed' }
|
||||
$m2vRepo = Join-Path $env:RUNNER_TEMP 'metal2vulkan'
|
||||
$cargoToml = Get-Content -Raw -LiteralPath (Join-Path $work 'Cargo.toml')
|
||||
if ($cargoToml -match 'metal2vulkan\s*=\s*\{[^}]*rev\s*=\s*"([0-9a-f]{40})"') {
|
||||
$m2vRev = $Matches[1]
|
||||
} else {
|
||||
$lockTxt = Get-Content -Raw -LiteralPath (Join-Path $work 'Cargo.lock')
|
||||
if ($lockTxt -notmatch 'metal2vulkan\?rev=([0-9a-f]{40})') { throw 'metal2vulkan rev not found in Cargo.toml or Cargo.lock' }
|
||||
$m2vRev = $Matches[1]
|
||||
}
|
||||
git init -q $m2vRepo
|
||||
if ($LASTEXITCODE) { throw 'metal2vulkan init failed' }
|
||||
git -C $m2vRepo fetch -q --depth 1 https://github.com/steelbrain/metal2vulkan.git $m2vRev
|
||||
if ($LASTEXITCODE) { throw 'metal2vulkan fetch failed' }
|
||||
git -C $m2vRepo checkout -q --detach FETCH_HEAD
|
||||
if ($LASTEXITCODE) { throw 'metal2vulkan checkout failed' }
|
||||
$short = (git -C $work rev-parse --short=7 HEAD).Trim()
|
||||
$releaseId = "$short${{ needs.resolve.outputs.suffix }}"
|
||||
"short=$short" >> $env:GITHUB_OUTPUT
|
||||
@@ -151,7 +166,7 @@ jobs:
|
||||
# conflict without touching the patch (AGENTS.md rule 4).
|
||||
$resultFile = Join-Path $env:RUNNER_TEMP 'patches.json'
|
||||
try {
|
||||
pwsh -NoProfile -File scripts/apply-patch-series.ps1 -ReimsRepo $work -UtilRepo $utilRepo -ResultFile $resultFile
|
||||
pwsh -NoProfile -File scripts/apply-patch-series.ps1 -ReimsRepo $work -UtilRepo $utilRepo -Metal2VulkanRepo $m2vRepo -ResultFile $resultFile
|
||||
$ok = $LASTEXITCODE -eq 0
|
||||
} finally {
|
||||
if (Test-Path $resultFile) {
|
||||
@@ -163,11 +178,20 @@ jobs:
|
||||
}
|
||||
}
|
||||
if (-not $ok) { throw 'patch queue does not apply' }
|
||||
$cargoHome = Join-Path $env:RUNNER_TEMP 'cargo'
|
||||
$m2vFwd = $m2vRepo.Replace('\', '/')
|
||||
$cargoCfg = @"
|
||||
[patch."https://github.com/steelbrain/metal2vulkan"]
|
||||
metal2vulkan = { path = "$m2vFwd/crates/metal2vulkan" }
|
||||
metal2vulkan-runtime = { path = "$m2vFwd/crates/metal2vulkan-runtime" }
|
||||
"@ -replace '(?m)^ ', ''
|
||||
[IO.File]::WriteAllText((Join-Path $cargoHome 'config.toml'), ($cargoCfg.Replace("`r`n", "`n") + "`n"), [Text.UTF8Encoding]::new($false))
|
||||
"UPSTREAM_DIR=$work" >> $env:GITHUB_ENV
|
||||
"REIMS_UTIL_DIR=$utilRepo" >> $env:GITHUB_ENV
|
||||
"METAL2VULKAN_DIR=$m2vRepo" >> $env:GITHUB_ENV
|
||||
"SHORT_COMMIT=$short" >> $env:GITHUB_ENV
|
||||
"RELEASE_ID=$releaseId" >> $env:GITHUB_ENV
|
||||
"CARGO_HOME=$(Join-Path $env:RUNNER_TEMP 'cargo')" >> $env:GITHUB_ENV
|
||||
"CARGO_HOME=$cargoHome" >> $env:GITHUB_ENV
|
||||
"XDG_DATA_HOME=$(Join-Path $env:RUNNER_TEMP 'xdg-data')" >> $env:GITHUB_ENV
|
||||
"XDG_CACHE_HOME=$(Join-Path $env:RUNNER_TEMP 'xdg-cache')" >> $env:GITHUB_ENV
|
||||
|
||||
@@ -200,6 +224,7 @@ jobs:
|
||||
& ./scripts/pack-runtime.ps1 `
|
||||
-ReimsRepo $env:UPSTREAM_DIR `
|
||||
-UtilRepo $env:REIMS_UTIL_DIR `
|
||||
-Metal2VulkanRepo $env:METAL2VULKAN_DIR `
|
||||
-CargoHome $env:CARGO_HOME `
|
||||
-QemuDir (Join-Path $env:XDG_DATA_HOME 'reims-ctl\qemu\current') `
|
||||
-Msys2 '${{ steps.msys2.outputs.msys2-location }}' `
|
||||
|
||||
+18
-3
@@ -4,12 +4,12 @@
|
||||
|
||||
## 维护原则
|
||||
|
||||
1. **不长期维护 fork**:所有底层修复优先向相应上游仓库提交 PR。目标仓库包括 [`reims-vgpu`](https://github.com/steelbrain/reims-vgpu)、[`qemu-reims-vgpu`](https://github.com/steelbrain/qemu-reims-vgpu) 和 [`reims-util`](https://github.com/steelbrain/reims-util)。
|
||||
1. **不长期维护 fork**:所有底层修复优先向相应上游仓库提交 PR。目标仓库包括 [`reims-vgpu`](https://github.com/steelbrain/reims-vgpu)、[`qemu-reims-vgpu`](https://github.com/steelbrain/qemu-reims-vgpu)、[`reims-util`](https://github.com/steelbrain/reims-util) 和 [`metal2vulkan`](https://github.com/steelbrain/metal2vulkan)。
|
||||
2. **人工提 PR,冲突即停**:更新上游基线时由 [`scripts/apply-patch-series.ps1`](../scripts/apply-patch-series.ps1) 按顺序执行 `git apply --check`。已合入上游(反向检查通过)的补丁会自动跳过并开 Issue 提醒退役;遇到冲突时立刻中止构建,不自动改写补丁。
|
||||
3. **文件格式约束**:所有 `.patch` 文件必须为 **无 BOM、LF 行尾**(由 `.gitattributes` 中的 `*.patch -text` 约束),避免 `git apply` 在 Windows 上失败。
|
||||
4. **来源透明与协议兼容**:每个运行时包的 `manifest.json` 与 `patches/` 目录必须如实记录实际应用的全部补丁及哈希;本目录补丁不适用根目录的 Apache-2.0,而是遵循目标上游兼容协议(详见 [`patches/LICENSE`](LICENSE))。
|
||||
|
||||
本地构建时,`-UtilRepo` 指向 `reims-ctl` 固定版本的 `reims-util` 工作树。用相同的 MSYS2 CLANG64 工具链安装其中的 `reims-util` 后,把同一工作树传给打包脚本。
|
||||
本地构建时,`-UtilRepo` 指向 `reims-ctl` 固定版本的 `reims-util` 工作树,`-Metal2VulkanRepo` 指向 `reims-vgpu/Cargo.toml` 固定版本的 `metal2vulkan` 工作树(并通过 `$CARGO_HOME/config.toml` 的 `[patch."https://github.com/steelbrain/metal2vulkan"]` 覆盖,使 `reims-vgpu/Cargo.lock` 与上游保持逐字节一致)。用相同的 MSYS2 CLANG64 工具链构建后,把同一组工作树传给打包脚本。
|
||||
|
||||
---
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
|
||||
| 补丁文件 | 目标仓库与路径 | 解决的问题 | 当前状态 |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| [`reims-vgpu-cargo-lock.patch`](reims-vgpu-cargo-lock.patch) | `reims-vgpu` (`Cargo.lock`) | 补齐 `metal2vulkan` 三个 crate 的 `source` 锁定信息,使源码包与实际 Cargo 构建逐字节一致 | 仅用于构建可复现;上游补齐 `Cargo.lock` 后删除 |
|
||||
| [`reims-vgpu-win32-unicode-input.patch`](reims-vgpu-win32-unicode-input.patch) | `reims-vgpu` (`crates/reims-vgpu-window`) | 通过 `SDL_SetWindowsMessageHook` 在设置 `REIMS_GO_INPUT_URL`(仅限 `127.0.0.1`)时转发非物理按键的 `WM_CHAR`/`WM_UNICHAR`/`WM_IME_CHAR`,解决 Windows IME 与中文输入被吞 | 待编入 `alpha` 冒烟验证后提 PR |
|
||||
| [`reims-vgpu-display-fixed-mode.patch`](reims-vgpu-display-fixed-mode.patch) | `reims-vgpu` (`crates/reims-vgpu-window`, `crates/reims-vgpu`) | 新增 `REIMS_VGPU_WINDOW_FIXED_MODE=1` 将全屏/窗口物理尺寸与客体渲染分辨率解耦,按 `scale * (guest_w / drawable_w)` 推导有效 DPI,并在帧尺寸与目标区域不一致时自动走线性采样 GPU 着色器缩放(支持 4K 全屏 1.5× 超采样 `5120×2880` HiDPI) | `git apply --check` 在 `3731afd9` 通过;待编入 `alpha` 真机验证后提 PR |
|
||||
| [`reims-ctl-win32-random-bytes.patch`](reims-ctl-win32-random-bytes.patch) | `reims-vgpu` (`crates/reims-ctl/src/vm.rs`) | 修复 Windows 下打不开 `/dev/urandom` 时回退到低熵时间戳种子的缺陷,改用标准库 `RandomState`(底层调用 `ProcessPrng`)生成 MAC/ROM 随机字节 | `git apply --check` 通过;待编入 `alpha` 验证后提 PR |
|
||||
| [`reims-ctl-virtio-discard-iothread.patch`](reims-ctl-virtio-discard-iothread.patch) | `reims-vgpu` (`crates/reims-ctl/src/qemu.rs`) | 为 VirtIO 系统盘补齐 `discard=unmap`(与 NVMe 一致透传客体 TRIM)并启用独立 `-object iothread,id=io0`,避免块完成回调与 QEMU 主循环争抢 | `git apply --check` 在 `3731afd9` 与上游 `main` 均通过;真机实测与休眠唤醒通过,暂留 `patches/` 待编入 `alpha` 验证后提 PR |
|
||||
| [`reims-ctl-qcow2-l2-cache.patch`](reims-ctl-qcow2-l2-cache.patch) | `reims-vgpu` (`crates/reims-ctl/src/qemu.rs`) | 按 `qcow2` 文件头虚拟容量与簇大小计算全覆盖所需 `l2-cache-size`(上限 32 MiB,仅大于 8 MiB 默认值时追加),避免非 Linux 宿主默认 8 MiB 上限仅覆盖 64 GiB | `git apply --check` 在 `3731afd9` 与上游 `main` 均通过;128 GiB 镜像真机实测通过,暂留 `patches/` 待编入 `alpha` 验证后提 PR |
|
||||
| [`reims-vgpu-snapshot-replay.patch`](reims-vgpu-snapshot-replay.patch) | `reims-vgpu` (`crates/reims-vgpu*`) | 实现 GPU 静止、实时对象日志与 `RVGSNAP1` 二进制编解码(含统一计数边界校验、因果父对象保留、`whole_library_key` 索引及未附着延迟 SurfaceCache 持久化)、显存与事件保存/重放及严格错误传播 | 单元测试、双进程 RTX A5000 Vulkan 测试及 Intel macOS 26.7.3 同 PID Metal 读回实测通过;待提 PR |
|
||||
| [`reims-util-parallel-offline-download.patch`](reims-util-parallel-offline-download.patch) | `reims-util` (`src/http.rs`, `src/installer.rs`) | 对有 Apple 分块校验数据的完整离线包并发请求四段,按顺序校验并写入镜像。分段读取失败时用原有单路下载继续 | 待编入 `alpha` 冒烟验证 |
|
||||
| [`metal2vulkan-snapshot-replay.patch`](metal2vulkan-snapshot-replay.patch) | `metal2vulkan` (`crates/metal2vulkan-runtime/src/`) | 暴露 Private/Shared/Managed 缓冲与纹理(含多层/多 Mip)及事件计数的快照读出与精确地址/内容回写接口 | 随 `reims-vgpu-snapshot-replay.patch` 在干净 checkout 构建并实测通过;待提 PR |
|
||||
| [`qemu-whpx-win10-compat.patch`](qemu-whpx-win10-compat.patch) | `vendor/qemu` (`target/i386/whpx/whpx-all.c`) | 修复 Windows 10 19045 上两处 WHPX 必现崩溃(探测 TSC deadline 污染主分区、`WHvResetPartition` 未判空) | 已在 Win10 19045 真机验证并随稳定运行时发布;待提 PR |
|
||||
| [`qemu-whpx-win10-startup-ipis.patch`](qemu-whpx-win10-startup-ipis.patch) | `vendor/qemu` (`target/i386/whpx/whpx-all.c`) | 在 Win10 开启 `kernel-irqchip` 且多核启动时经 `WHvRequestInterrupt` 转发 INIT/SIPI,避免 XNU 从核卡死(依赖上一项) | 8/12 核冷启动通过;客体软重启待验证,待提 PR |
|
||||
| [`qemu-whpx-nested-virt-nonfatal.patch`](qemu-whpx-nested-virt-nonfatal.patch) | `vendor/qemu` (`target/i386/whpx/whpx-all.c`) | 部分 Win11 宿主设置嵌套虚拟化属性返回 `0x80370302` 时改为警告并清零特性位,保留 `kernel-irqchip=on` 加速(依赖前两项) | 待编入 `alpha` 并在 Win11 真机验证后提 PR |
|
||||
@@ -121,6 +122,20 @@
|
||||
2. 补齐 WHPX x86-64 vCPU/LAPIC/x2APIC/TSC 寄存器与 AppleSMC、`reims-graphics-pci` 设备 VMState 保存恢复回调(含损坏快照向 QMP 返回错误并保留挂起文件)。
|
||||
- **实测证据**:7 项 QMP 闸门回归全部通过;Windows 11 WHPX + RTX A5000 + Intel macOS 26.7.3 解锁桌面实测跨完整 QEMU 退出及真实 Windows 重启恢复,首帧 1920×1080 SHA-256 完全一致,原应用 PID / Metal 队列 / Private 资源读回 100% 匹配。
|
||||
|
||||
### 11. `metal2vulkan-snapshot-replay.patch`
|
||||
- **建议 PR 标题**:`runtime: add snapshot readback and exact-address restore hooks for buffers, textures, and events`
|
||||
- **目标**:`steelbrain/metal2vulkan`(`crates/metal2vulkan-runtime/src/{block,device,event,floor,lib,memory,places}.rs`)
|
||||
- **最小修复**:为 `metal2vulkan-runtime` 增加共享/私有池块分配恢复、Private 缓冲/纹理全子资源(含多 mip/slice)内容读回与回写、以及事件值读写接口,使上层 `reims-vgpu` 可在宿主进程重启后原位重建客体可见 GPU 地址与显存内容。
|
||||
|
||||
### 12. `reims-vgpu-snapshot-replay.patch`
|
||||
- **建议 PR 标题**:`graphics & pool: add RVGSNAP1 device quiesce, live object log, and strict snapshot replay`
|
||||
- **目标**:`steelbrain/reims-vgpu`(`crates/reims-vgpu*`)
|
||||
- **最小修复**:
|
||||
1. 统一 `quiesce_device()` 静止流程(排空传输与编译任务、刷写表面缓存并等待 GPU 空闲),由 `reims-vgpu-c` 暴露保存/加载 C ABI 供 `reims-graphics-pci` VMState 调用。
|
||||
2. 新增 `RVGSNAP1` 二进制快照编解码,由 `Dec::checked_count` / `read_vec` 在分配前统一按剩余字节和最小条目大小校验计数并校验尾部无多余字节。
|
||||
3. 完整保存与回放共享/私有内存池、实时对象日志(含 `whole_library_key` 索引与因果父对象保留,避免 ARC 释放 `MTLLibrary` 后导致活跃管线回放失败)、事件计数、Private 缓冲/纹理与未附着延迟 `SurfaceCache`(含 VA-API P010 视频帧),任何关键对象或显存保存/恢复失败均向 QMP 返回错误且不解除静止。
|
||||
- **实测证据**:干净上游 checkout 通过 `reims-vgpu-graphics` 与 `reims-vgpu` 快照单元测试及 `reims-vgpu-c` 零警告 release 构建;RTX A5000 双进程 Vulkan 读回与 Intel macOS 26.7.3 解锁桌面跨进程同 PID Metal 读回(Buffer/Texture/Event/SharedEvent + 恢复后原队列继续 Compute 变异)100% 通过。
|
||||
|
||||
---
|
||||
|
||||
## 关注中的上游 PR 与演进
|
||||
|
||||
@@ -0,0 +1,525 @@
|
||||
diff --git a/crates/metal2vulkan-runtime/src/block.rs b/crates/metal2vulkan-runtime/src/block.rs
|
||||
index 0ac77ecac0f3abb9e9b76fb82d17c3536e22f4f5..426d025513a2f04e97f31efa66d1632635f7254d 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/block.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/block.rs
|
||||
@@ -54,6 +54,12 @@ impl Block {
|
||||
Block { claim }
|
||||
}
|
||||
|
||||
+ /// Returns capture/replay address metadata for this block (if supported).
|
||||
+ pub fn capture_info(&self) -> Option<memory::BlockCaptureInfo> {
|
||||
+ let (core, block) = self.held().ok()?;
|
||||
+ core.pool.capture_info(&block.memory)
|
||||
+ }
|
||||
+
|
||||
/// Whether the block is of `core`'s device.
|
||||
pub(crate) fn is_of(&self, core: &Arc<Core>) -> bool {
|
||||
Weak::as_ptr(&self.claim.core) == Arc::as_ptr(core)
|
||||
diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs
|
||||
index 8edf1f27202f9a19b19cc4a4484d1e31341b8ab1..68f79440cc7727f2fae6063756380fe7a85ce7f9 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/device.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/device.rs
|
||||
@@ -273,6 +273,7 @@ pub(crate) struct Core {
|
||||
/// every render pipeline takes its colour flag, and a draw reads an attachment of its pass
|
||||
/// with the image in the feedback layout.
|
||||
pub(crate) feedback_loop: bool,
|
||||
+ pub(crate) capture_replay: bool,
|
||||
/// `VK_EXT_device_fault`'s command, where device creation enabled it (where the device lists
|
||||
/// it): a lost device's fault report, read once, at its first loss (`crate::fault`).
|
||||
pub(crate) fault: Option<ash::ext::device_fault::Device>,
|
||||
@@ -860,6 +861,7 @@ impl Device {
|
||||
ticks,
|
||||
calibrated,
|
||||
feedback_loop: capabilities.feedback_loop,
|
||||
+ capture_replay: capabilities.buffer_device_address_capture_replay,
|
||||
fault,
|
||||
indirect,
|
||||
attachment_reads: capabilities.attachment_reads,
|
||||
@@ -1140,6 +1142,41 @@ impl Device {
|
||||
/// allocation past the device's count; [`Limit::AllocationNotMapped`](crate::Limit::AllocationNotMapped)
|
||||
/// where the consumer did not map the allocation the take made; [`Error::Vulkan`] where the
|
||||
/// device is out of memory or lost; [`Error::Quiesced`].
|
||||
+ /// Whether Vulkan `bufferDeviceAddressCaptureReplay` is enabled on this device.
|
||||
+ pub fn buffer_device_address_capture_replay(&self) -> bool {
|
||||
+ self.shared.core.capture_replay
|
||||
+ }
|
||||
+
|
||||
+ /// Waits non-destructively until all in-flight GPU work has completed and retired.
|
||||
+ pub fn wait_idle(&self) -> Result<(), Error> {
|
||||
+ let core = &self.shared.core;
|
||||
+ if core.closed() {
|
||||
+ return Err(Error::Quiesced);
|
||||
+ }
|
||||
+ // Wait for submitted command buffers to retire on the completion thread.
|
||||
+ let deadline = Instant::now() + Duration::from_secs(10);
|
||||
+ while core.pool.in_flight() > 0 && Instant::now() < deadline {
|
||||
+ std::thread::sleep(Duration::from_millis(1));
|
||||
+ }
|
||||
+ // SAFETY: `device` is live and wait_idle synchronizes all host queues.
|
||||
+ let _q = lock(&core.queues.runtime);
|
||||
+ unsafe { core.device.device_wait_idle() }.map_err(Error::vulkan("vkDeviceWaitIdle"))?;
|
||||
+ Ok(())
|
||||
+ }
|
||||
+
|
||||
+ /// Replays a previously captured block at its exact Vulkan device address.
|
||||
+ pub fn take_block_replayed(&self, capture: memory::BlockCaptureInfo) -> Result<Block, Error> {
|
||||
+ let core = &self.shared.core;
|
||||
+ if core.closed() {
|
||||
+ return Err(Error::Quiesced);
|
||||
+ }
|
||||
+ let memory = core.pool.take_replayed(core, capture, crate::counters::Site::take(capture.class))?;
|
||||
+ let info = memory.info();
|
||||
+ let block = memory::Block::new(memory, Arc::clone(core));
|
||||
+ Ok(Block::claim(core, info, block))
|
||||
+ }
|
||||
+
|
||||
+ /// Allocates a new GPU memory block of `class` and `len` bytes.
|
||||
pub fn take_block(&self, class: MemoryClass, len: u64) -> Result<Block, Error> {
|
||||
let core = &self.shared.core;
|
||||
if core.closed() {
|
||||
diff --git a/crates/metal2vulkan-runtime/src/event.rs b/crates/metal2vulkan-runtime/src/event.rs
|
||||
index fe95046625fb1d1c81e2925458c22c4dd3641197..8b47e5604f50dec0549733c515ce80e02dbe348e 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/event.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/event.rs
|
||||
@@ -140,6 +140,35 @@ impl Event {
|
||||
}
|
||||
}
|
||||
|
||||
+impl Event {
|
||||
+ /// Reads the current signaled value of this timeline event (for checkpointing).
|
||||
+ pub fn signaled_value(&self) -> u64 {
|
||||
+ let inner = &self.inner;
|
||||
+ let state = lock(&inner.state);
|
||||
+ let floor = state.observed.max(state.floor);
|
||||
+ inner.reached(None).map_or(floor, |reached| reached.max(floor))
|
||||
+ }
|
||||
+
|
||||
+ /// Restores the timeline semaphore and CPU floor to `value` on a freshly created event.
|
||||
+ pub fn restore_signaled_value(&self, value: u64) -> Result<(), Error> {
|
||||
+ if value == 0 {
|
||||
+ return Ok(());
|
||||
+ }
|
||||
+ let inner = &self.inner;
|
||||
+ let info = vk::SemaphoreSignalInfo::default()
|
||||
+ .semaphore(inner.semaphore)
|
||||
+ .value(value);
|
||||
+ // SAFETY: `semaphore` is a live timeline semaphore on `inner.core.device`.
|
||||
+ unsafe { inner.core.device.signal_semaphore(&info) }
|
||||
+ .map_err(Error::vulkan("vkSignalSemaphore"))?;
|
||||
+ let mut state = lock(&inner.state);
|
||||
+ state.floor = state.floor.max(value);
|
||||
+ state.observed = state.observed.max(value);
|
||||
+ inner.changed.notify_all();
|
||||
+ Ok(())
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
impl SharedEvent {
|
||||
/// `signaledValue`: the higher of the semaphore's value and the host's floor, the semaphore's
|
||||
/// value being one a host wait confirmed: a counter read finds it, and a wait with a timeout
|
||||
diff --git a/crates/metal2vulkan-runtime/src/floor.rs b/crates/metal2vulkan-runtime/src/floor.rs
|
||||
index 0e165934f4b7534d0a093b1a22bcd763a47db8d7..90c7f9e354af205aa5a6b2fbeb506e58fbba1ab8 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/floor.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/floor.rs
|
||||
@@ -1079,6 +1079,8 @@ pub struct Capabilities {
|
||||
/// [`ATTACHMENT_READ_EXTENSIONS`]: a draw reads an attachment through the attachment feedback
|
||||
/// loop, the feedback layout its image moves to and the flag every render pipeline takes.
|
||||
pub feedback_loop: bool,
|
||||
+ /// Whether `bufferDeviceAddressCaptureReplay` is enabled for checkpoint/restore.
|
||||
+ pub buffer_device_address_capture_replay: bool,
|
||||
/// The features device creation enables: every one the floor requires, each of the optional,
|
||||
/// step-rate, min-LOD, fill-mode, alpha-to-one, quad-control, pixel-interlock, linear-attachment
|
||||
/// and fault-report ones the device reports, the attachment-read ones where
|
||||
@@ -1425,6 +1427,10 @@ pub(crate) fn decide(device: &Queried) -> Result<Capabilities, BelowFloor> {
|
||||
let Some((queue_family, _)) = family.filter(|_| missing.is_empty()) else {
|
||||
return Err(BelowFloor { missing });
|
||||
};
|
||||
+ let capture_replay = reported.vulkan12.buffer_device_address_capture_replay == vk::TRUE;
|
||||
+ if capture_replay {
|
||||
+ features.vulkan12.buffer_device_address_capture_replay = vk::TRUE;
|
||||
+ }
|
||||
for feature in (OPTIONAL.iter().chain(STEP_RATES))
|
||||
.chain(MIN_LOD_CLAMPS)
|
||||
.chain(FILL_MODES)
|
||||
@@ -1491,6 +1497,7 @@ pub(crate) fn decide(device: &Queried) -> Result<Capabilities, BelowFloor> {
|
||||
texel_offset_operand: features.maintenance8.maintenance8 == vk::TRUE,
|
||||
attachment_reads,
|
||||
feedback_loop,
|
||||
+ buffer_device_address_capture_replay: capture_replay,
|
||||
features,
|
||||
extensions: DEVICE_EXTENSIONS
|
||||
.iter()
|
||||
diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs
|
||||
index a2d59cc6f31eb64307c1a886fe7cf75f401511b1..557a1a4b213773df976895f703cd4c037ad2602b 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/lib.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/lib.rs
|
||||
@@ -100,7 +100,7 @@ pub use host_bytes::HostBytes;
|
||||
pub use import::ImportHandle;
|
||||
pub use indirect::{IndirectCommandBuffer, IndirectCommandBufferDescriptor, IndirectCommandType};
|
||||
pub use instance::{Instance, PhysicalDevice};
|
||||
-pub use memory::{AllocationId, AllocationInfo, BlockId, BlockInfo, BlockMappings, MemoryClass};
|
||||
+pub use memory::{AllocationId, AllocationInfo, BlockCaptureInfo, BlockId, BlockInfo, BlockMappings, MemoryClass};
|
||||
/// `MTLLibrary`: the translator's, read from AIR or a metallib.
|
||||
/// `MTLSamplerDescriptor`: the translator's.
|
||||
pub use metal2vulkan::bind::SamplerDescriptor;
|
||||
diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs
|
||||
index 173e0858f2e6d07660cafd5f7893aee280f2dcdc..2864f4ba6b48a4892e6d9651548c75a4babcf395 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/memory.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/memory.rs
|
||||
@@ -235,8 +235,28 @@ impl AllocationId {
|
||||
/// device is torn down. It is a range of one allocation, whose one `VkBuffer`, with every buffer
|
||||
/// usage and a device address, spans it; an imported or exported block is the whole of an
|
||||
/// allocation of its own. Only an exported block is exportable.
|
||||
+/// Capture/replay address metadata for restoring a block at its exact Vulkan device address.
|
||||
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
+pub struct BlockCaptureInfo {
|
||||
+ /// Storage mode (`Shared` or `Private`).
|
||||
+ pub class: MemoryClass,
|
||||
+ /// Full parent Vulkan allocation length in bytes.
|
||||
+ pub alloc_len: u64,
|
||||
+ /// Offset of this block inside its parent allocation.
|
||||
+ pub offset: u64,
|
||||
+ /// Block length in bytes.
|
||||
+ pub len: u64,
|
||||
+ /// Guest-visible `VkDeviceAddress` of this block's first byte.
|
||||
+ pub gpu_address: u64,
|
||||
+ /// Opaque capture address of the parent `VkBuffer`.
|
||||
+ pub opaque_buffer_address: u64,
|
||||
+ /// Opaque capture address of the parent `VkDeviceMemory`.
|
||||
+ pub opaque_memory_address: u64,
|
||||
+}
|
||||
+
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
+/// Metadata describing an allocated GPU memory block.
|
||||
pub struct BlockInfo {
|
||||
/// The block's number.
|
||||
pub id: BlockId,
|
||||
@@ -611,6 +631,10 @@ struct Allocation {
|
||||
buffer: vk::Buffer,
|
||||
/// The device address of its first byte.
|
||||
address: u64,
|
||||
+ /// Opaque capture address of `buffer` (0 if capture-replay unsupported).
|
||||
+ opaque_buffer_address: u64,
|
||||
+ /// Opaque capture address of `memory` (0 if capture-replay unsupported).
|
||||
+ opaque_memory_address: u64,
|
||||
len: u64,
|
||||
mapping: Option<Mapping>,
|
||||
device_local: bool,
|
||||
@@ -823,6 +847,8 @@ struct State {
|
||||
/// The internal the block-maker thread took up and is making ([`run`]).
|
||||
making: Option<Internal>,
|
||||
stop: bool,
|
||||
+ replaying: bool,
|
||||
+ making_ahead: bool,
|
||||
next_id: u32,
|
||||
next_allocation: u32,
|
||||
/// The allocations [`BlockMappings::map`] accepted whose unmap has not run.
|
||||
@@ -952,6 +978,8 @@ impl Pool {
|
||||
asked: [true; INTERNALS],
|
||||
making: None,
|
||||
stop: false,
|
||||
+ replaying: false,
|
||||
+ making_ahead: false,
|
||||
next_id: 1,
|
||||
next_allocation: 1,
|
||||
mapped: HashSet::new(),
|
||||
@@ -1368,6 +1396,158 @@ impl Pool {
|
||||
}
|
||||
}
|
||||
|
||||
+ /// Returns capture/replay info for a pool block, if capture-replay is enabled.
|
||||
+ pub(crate) fn capture_info(&self, memory: &Memory) -> Option<BlockCaptureInfo> {
|
||||
+ if memory.own.is_some() {
|
||||
+ return None;
|
||||
+ }
|
||||
+ let state = self.lock();
|
||||
+ let alloc = state.allocations[memory.class.index()]
|
||||
+ .iter()
|
||||
+ .find(|a| a.memory == memory.memory)?;
|
||||
+
|
||||
+ Some(BlockCaptureInfo {
|
||||
+ class: memory.class,
|
||||
+ alloc_len: alloc.len,
|
||||
+ offset: memory.base,
|
||||
+ len: memory.len,
|
||||
+ gpu_address: memory.address,
|
||||
+ opaque_buffer_address: alloc.opaque_buffer_address,
|
||||
+ opaque_memory_address: alloc.opaque_memory_address,
|
||||
+ })
|
||||
+ }
|
||||
+
|
||||
+ /// Replays a previously captured pool block at its exact Vulkan device address.
|
||||
+ pub(crate) fn take_replayed(
|
||||
+ &self,
|
||||
+ core: &Core,
|
||||
+ cap: BlockCaptureInfo,
|
||||
+ site: Site,
|
||||
+ ) -> Result<Memory, Error> {
|
||||
+ let index = cap.class.index();
|
||||
+ // 1. Check if the parent allocation is already present (e.g. another sub-block restored it,
|
||||
+ // or a pre-stocked idle reserve landed at the exact same address!).
|
||||
+ {
|
||||
+ let mut state = self.lock();
|
||||
+ if state.stop {
|
||||
+ return Err(Error::Quiesced);
|
||||
+ }
|
||||
+ let id = number(&mut state)?;
|
||||
+ let want_base = cap.gpu_address.saturating_sub(cap.offset);
|
||||
+ if let Some(alloc) = state.allocations[index].iter_mut().find(|a| {
|
||||
+ a.address == want_base
|
||||
+ && a.opaque_buffer_address == cap.opaque_buffer_address
|
||||
+ && a.opaque_memory_address == cap.opaque_memory_address
|
||||
+ && a.len == cap.alloc_len
|
||||
+ }) {
|
||||
+ if alloc.free.take_at(cap.offset, cap.len) {
|
||||
+ let carve = alloc.carve(cap.offset);
|
||||
+ alloc.live += 1;
|
||||
+ alloc.placed += cap.len;
|
||||
+ alloc.ahead = false;
|
||||
+ self.counters.rise_by(cap.class.placed_gauge(), cap.len);
|
||||
+ self.settle(&mut state, cap.class);
|
||||
+ self.changed.notify_all();
|
||||
+ return Ok(carve.block(id, cap.class, cap.len));
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // 2. Pause block-maker ahead allocations, wait for any in-flight ahead make,
|
||||
+ // and purge idle reserve slabs so none collide with the target opaque VA!
|
||||
+ let idle_allocs: Vec<Allocation> = {
|
||||
+ let mut state = self.lock();
|
||||
+ state.replaying = true;
|
||||
+ while state.making_ahead {
|
||||
+ state = self.wait(state);
|
||||
+ }
|
||||
+ // Re-check if an ahead allocation that just finished landed at the exact target VA!
|
||||
+ let want_base = cap.gpu_address.saturating_sub(cap.offset);
|
||||
+ let hit = state.allocations[index].iter_mut().find_map(|a| {
|
||||
+ if a.address == want_base
|
||||
+ && a.opaque_buffer_address == cap.opaque_buffer_address
|
||||
+ && a.opaque_memory_address == cap.opaque_memory_address
|
||||
+ && a.len == cap.alloc_len
|
||||
+ && a.free.take_at(cap.offset, cap.len)
|
||||
+ {
|
||||
+ let carve = a.carve(cap.offset);
|
||||
+ a.live += 1;
|
||||
+ a.placed += cap.len;
|
||||
+ a.ahead = false;
|
||||
+ Some(carve)
|
||||
+ } else {
|
||||
+ None
|
||||
+ }
|
||||
+ });
|
||||
+ if let Some(carve) = hit {
|
||||
+ let id = number(&mut state)?;
|
||||
+ state.replaying = false;
|
||||
+ self.counters.rise_by(cap.class.placed_gauge(), cap.len);
|
||||
+ self.settle(&mut state, cap.class);
|
||||
+ self.changed.notify_all();
|
||||
+ return Ok(carve.block(id, cap.class, cap.len));
|
||||
+ }
|
||||
+ let mut drained = Vec::new();
|
||||
+ for c in MemoryClass::ALL {
|
||||
+ let ci = c.index();
|
||||
+ let mut kept = Vec::new();
|
||||
+ for a in state.allocations[ci].drain(..) {
|
||||
+ if a.live == 0 {
|
||||
+ drained.push(a);
|
||||
+ } else {
|
||||
+ kept.push(a);
|
||||
+ }
|
||||
+ }
|
||||
+ state.allocations[ci] = kept;
|
||||
+ self.settle(&mut state, c);
|
||||
+ }
|
||||
+ drained
|
||||
+ };
|
||||
+ for a in idle_allocs {
|
||||
+ free_idle(core, a);
|
||||
+ }
|
||||
+ // 3. Allocate at the exact captured opaque buffer + memory addresses.
|
||||
+ let alloc_res = make_allocation_ex(
|
||||
+ core,
|
||||
+ cap.class,
|
||||
+ cap.alloc_len,
|
||||
+ Some(site),
|
||||
+ Some((cap.opaque_buffer_address, cap.opaque_memory_address)),
|
||||
+ );
|
||||
+ let mut allocation = match alloc_res {
|
||||
+ Ok(a) => a,
|
||||
+ Err(e) => {
|
||||
+ let mut state = self.lock();
|
||||
+ state.replaying = false;
|
||||
+ self.changed.notify_all();
|
||||
+ return Err(e);
|
||||
+ }
|
||||
+ };
|
||||
+ let mapped = self.map(&allocation, cap.class, true);
|
||||
+ if !mapped {
|
||||
+ free_allocation(core, allocation);
|
||||
+ let mut state = self.lock();
|
||||
+ state.replaying = false;
|
||||
+ self.changed.notify_all();
|
||||
+ return Err(Error::Limit(Limit::AllocationNotMapped {
|
||||
+ class: cap.class,
|
||||
+ len: cap.alloc_len,
|
||||
+ }));
|
||||
+ }
|
||||
+ let ok = allocation.free.take_at(cap.offset, cap.len);
|
||||
+ debug_assert!(ok, "fresh allocation must contain captured block range");
|
||||
+ let mut state = self.lock();
|
||||
+ let id = number(&mut state)?;
|
||||
+ let memory = allocation.carve(cap.offset).block(id, cap.class, cap.len);
|
||||
+ allocation.live = 1;
|
||||
+ allocation.placed = cap.len;
|
||||
+ state.allocations[index].push(allocation);
|
||||
+ state.replaying = false;
|
||||
+ self.counters.rise_by(cap.class.placed_gauge(), cap.len);
|
||||
+ self.settle(&mut state, cap.class);
|
||||
+ self.changed.notify_all();
|
||||
+ Ok(memory)
|
||||
+ }
|
||||
+
|
||||
/// Takes back a block taken with [`take`](Self::take): its bytes are a free range of its
|
||||
/// allocation at once.
|
||||
pub(crate) fn give_back(&self, memory: Memory) {
|
||||
@@ -1788,12 +1968,16 @@ pub(crate) fn run(core: Arc<Core>) {
|
||||
state = pool.lock();
|
||||
continue;
|
||||
}
|
||||
- let wanted = (MemoryClass::ALL.into_iter())
|
||||
- .find(|&class| !state.failed[class.index()] && !state.whole(class));
|
||||
+ let wanted = (!state.replaying).then(|| {
|
||||
+ (MemoryClass::ALL.into_iter())
|
||||
+ .find(|&class| !state.failed[class.index()] && !state.whole(class))
|
||||
+ }).flatten();
|
||||
if let Some(class) = wanted {
|
||||
+ state.making_ahead = true;
|
||||
drop(state);
|
||||
let made = ahead(&core, class);
|
||||
state = pool.lock();
|
||||
+ state.making_ahead = false;
|
||||
match made {
|
||||
// Idle from now: the reserve, which the idle rule does not weigh.
|
||||
Some(mut allocation) => {
|
||||
@@ -2022,6 +2206,16 @@ fn make_allocation(
|
||||
class: MemoryClass,
|
||||
len: u64,
|
||||
site: Option<Site>,
|
||||
+) -> Result<Allocation, Error> {
|
||||
+ make_allocation_ex(core, class, len, site, None)
|
||||
+}
|
||||
+
|
||||
+fn make_allocation_ex(
|
||||
+ core: &Core,
|
||||
+ class: MemoryClass,
|
||||
+ len: u64,
|
||||
+ site: Option<Site>,
|
||||
+ replay: Option<(u64, u64)>,
|
||||
) -> Result<Allocation, Error> {
|
||||
let device = &core.device;
|
||||
let (id, freed_at) = {
|
||||
@@ -2031,22 +2225,38 @@ fn make_allocation(
|
||||
state.freed_at[class.index()],
|
||||
)
|
||||
};
|
||||
- let info = vk::BufferCreateInfo::default()
|
||||
+ let mut buf_opaque = vk::BufferOpaqueCaptureAddressCreateInfo::default()
|
||||
+ .opaque_capture_address(replay.map_or(0, |(b, _)| b));
|
||||
+ let mut info = vk::BufferCreateInfo::default()
|
||||
.size(len)
|
||||
.usage(floor::BUFFER_USAGE)
|
||||
.sharing_mode(vk::SharingMode::EXCLUSIVE);
|
||||
+ if core.capture_replay {
|
||||
+ info = info.flags(vk::BufferCreateFlags::DEVICE_ADDRESS_CAPTURE_REPLAY);
|
||||
+ if replay.is_some_and(|(b, _)| b != 0) {
|
||||
+ info = info.push_next(&mut buf_opaque);
|
||||
+ }
|
||||
+ }
|
||||
// SAFETY: the device is live, and the create info valid: `len` is at most its
|
||||
// `maxBufferSize`.
|
||||
let buffer =
|
||||
unsafe { device.create_buffer(&info, None) }.map_err(Error::vulkan("vkCreateBuffer"))?;
|
||||
// SAFETY: the buffer is the device's.
|
||||
let requirements = unsafe { device.get_buffer_memory_requirements(buffer) };
|
||||
- let mut flags =
|
||||
- vk::MemoryAllocateFlagsInfo::default().flags(vk::MemoryAllocateFlags::DEVICE_ADDRESS);
|
||||
- let allocate_info = vk::MemoryAllocateInfo::default()
|
||||
+ let mut mem_flags = vk::MemoryAllocateFlags::DEVICE_ADDRESS;
|
||||
+ if core.capture_replay {
|
||||
+ mem_flags |= vk::MemoryAllocateFlags::DEVICE_ADDRESS_CAPTURE_REPLAY;
|
||||
+ }
|
||||
+ let mut flags = vk::MemoryAllocateFlagsInfo::default().flags(mem_flags);
|
||||
+ let mut mem_opaque = vk::MemoryOpaqueCaptureAddressAllocateInfo::default()
|
||||
+ .opaque_capture_address(replay.map_or(0, |(_, m)| m));
|
||||
+ let mut allocate_info = vk::MemoryAllocateInfo::default()
|
||||
.allocation_size(requirements.size.max(len))
|
||||
.memory_type_index(core.memory_type(class))
|
||||
.push_next(&mut flags);
|
||||
+ if core.capture_replay && replay.is_some_and(|(_, m)| m != 0) {
|
||||
+ allocate_info = allocate_info.push_next(&mut mem_opaque);
|
||||
+ }
|
||||
let bits = requirements.memory_type_bits;
|
||||
// SAFETY: the floor chose the memory type for buffers of this usage on this device, and
|
||||
// `bufferDeviceAddress` is enabled; a spill takes a type the buffer's requirements allow.
|
||||
@@ -2065,6 +2275,8 @@ fn make_allocation(
|
||||
memory,
|
||||
buffer,
|
||||
address: 0,
|
||||
+ opaque_buffer_address: 0,
|
||||
+ opaque_memory_address: 0,
|
||||
len,
|
||||
mapping: None,
|
||||
device_local: !spilled && core.device_local & (1 << core.memory_type(class)) != 0,
|
||||
@@ -2101,6 +2313,13 @@ fn make_allocation(
|
||||
let of = vk::BufferDeviceAddressInfo::default().buffer(buffer);
|
||||
// SAFETY: the buffer has device-address usage and is bound.
|
||||
allocation.address = unsafe { device.get_buffer_device_address(&of) };
|
||||
+ if core.capture_replay {
|
||||
+ allocation.opaque_buffer_address =
|
||||
+ unsafe { device.get_buffer_opaque_capture_address(&of) };
|
||||
+ let mof = vk::DeviceMemoryOpaqueCaptureAddressInfo::default().memory(memory);
|
||||
+ allocation.opaque_memory_address =
|
||||
+ unsafe { device.get_device_memory_opaque_capture_address(&mof) };
|
||||
+ }
|
||||
(core.spans).made(
|
||||
buffer,
|
||||
allocation.address,
|
||||
diff --git a/crates/metal2vulkan-runtime/src/places.rs b/crates/metal2vulkan-runtime/src/places.rs
|
||||
index 137fb5790de850552affd179497df69d9912266a..3d679bbaa5285e87d1639a7cc140e0025b49e84f 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/places.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/places.rs
|
||||
@@ -248,6 +248,33 @@ impl Ranges {
|
||||
Some(at)
|
||||
}
|
||||
|
||||
+ /// Takes the exact range `at..at + len` if it is completely free.
|
||||
+ pub(crate) fn take_at(&mut self, at: u64, len: u64) -> bool {
|
||||
+ let Some(stop) = at.checked_add(len) else {
|
||||
+ return false;
|
||||
+ };
|
||||
+ let Some(index) = self
|
||||
+ .free
|
||||
+ .iter()
|
||||
+ .position(|&(start, end)| start <= at && stop <= end)
|
||||
+ else {
|
||||
+ return false;
|
||||
+ };
|
||||
+ let (start, end) = self.free[index];
|
||||
+ match (start < at, stop < end) {
|
||||
+ (false, false) => {
|
||||
+ self.free.remove(index);
|
||||
+ }
|
||||
+ (true, false) => self.free[index] = (start, at),
|
||||
+ (false, true) => self.free[index] = (stop, end),
|
||||
+ (true, true) => {
|
||||
+ self.free[index] = (start, at);
|
||||
+ self.free.insert(index + 1, (stop, end));
|
||||
+ }
|
||||
+ }
|
||||
+ true
|
||||
+ }
|
||||
+
|
||||
/// Frees `offset..offset + len`, taken before, joining it to the free ranges beside it.
|
||||
pub(crate) fn give(&mut self, offset: u64, len: u64) {
|
||||
let end = offset + len;
|
||||
@@ -1,28 +0,0 @@
|
||||
diff --git a/Cargo.lock b/Cargo.lock
|
||||
index 106e75e..01bf052 100644
|
||||
--- a/Cargo.lock
|
||||
+++ b/Cargo.lock
|
||||
@@ -213,6 +213,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
[[package]]
|
||||
name = "metal2vulkan"
|
||||
version = "0.2.0"
|
||||
+source = "git+https://github.com/steelbrain/metal2vulkan?rev=0b0ac58eb0f69ed3b37007fbdf3b135a46f90699#0b0ac58eb0f69ed3b37007fbdf3b135a46f90699"
|
||||
dependencies = [
|
||||
"ash",
|
||||
"metal2vulkan-air",
|
||||
@@ -223,6 +224,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "metal2vulkan-air"
|
||||
version = "0.2.0"
|
||||
+source = "git+https://github.com/steelbrain/metal2vulkan?rev=0b0ac58eb0f69ed3b37007fbdf3b135a46f90699#0b0ac58eb0f69ed3b37007fbdf3b135a46f90699"
|
||||
dependencies = [
|
||||
"sha2 0.11.1",
|
||||
]
|
||||
@@ -230,6 +232,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "metal2vulkan-runtime"
|
||||
version = "0.2.0"
|
||||
+source = "git+https://github.com/steelbrain/metal2vulkan?rev=0b0ac58eb0f69ed3b37007fbdf3b135a46f90699#0b0ac58eb0f69ed3b37007fbdf3b135a46f90699"
|
||||
dependencies = [
|
||||
"ash",
|
||||
"libc",
|
||||
File diff suppressed because it is too large.
Load diff
+15
-14
@@ -1,18 +1,19 @@
|
||||
# Patch queue, in the order the patches are applied (see patches/README.md).
|
||||
# One patch per line: <target> <file>.
|
||||
# Targets are "reims-vgpu", "vendor/qemu", and "reims-util".
|
||||
# Targets are "reims-vgpu", "vendor/qemu", "reims-util", and "metal2vulkan".
|
||||
# CI (build-runtime.yml via scripts/apply-patch-series.ps1) and
|
||||
# scripts/pack-runtime.ps1 both read this file; add or retire patches here.
|
||||
reims-vgpu reims-vgpu-cargo-lock.patch
|
||||
reims-vgpu reims-vgpu-win32-unicode-input.patch
|
||||
reims-vgpu reims-vgpu-display-fixed-mode.patch
|
||||
reims-vgpu reims-ctl-win32-random-bytes.patch
|
||||
reims-vgpu reims-ctl-virtio-discard-iothread.patch
|
||||
reims-vgpu reims-ctl-qcow2-l2-cache.patch
|
||||
reims-util reims-util-parallel-offline-download.patch
|
||||
vendor/qemu qemu-whpx-win10-compat.patch
|
||||
vendor/qemu qemu-whpx-win10-startup-ipis.patch
|
||||
vendor/qemu qemu-whpx-nested-virt-nonfatal.patch
|
||||
vendor/qemu qemu-win32-coroutine-fiber-commit.patch
|
||||
vendor/qemu qemu-win32-mapped-ram-io.patch
|
||||
vendor/qemu qemu-intel-whpx-suspend.patch
|
||||
reims-vgpu reims-vgpu-win32-unicode-input.patch
|
||||
reims-vgpu reims-vgpu-display-fixed-mode.patch
|
||||
reims-vgpu reims-ctl-win32-random-bytes.patch
|
||||
reims-vgpu reims-ctl-virtio-discard-iothread.patch
|
||||
reims-vgpu reims-ctl-qcow2-l2-cache.patch
|
||||
reims-vgpu reims-vgpu-snapshot-replay.patch
|
||||
reims-util reims-util-parallel-offline-download.patch
|
||||
metal2vulkan metal2vulkan-snapshot-replay.patch
|
||||
vendor/qemu qemu-whpx-win10-compat.patch
|
||||
vendor/qemu qemu-whpx-win10-startup-ipis.patch
|
||||
vendor/qemu qemu-whpx-nested-virt-nonfatal.patch
|
||||
vendor/qemu qemu-win32-coroutine-fiber-commit.patch
|
||||
vendor/qemu qemu-win32-mapped-ram-io.patch
|
||||
vendor/qemu qemu-intel-whpx-suspend.patch
|
||||
@@ -16,23 +16,25 @@
|
||||
was really applied, AGENTS.md rule 5) and report merged or conflicting patches.
|
||||
|
||||
.EXAMPLE
|
||||
pwsh -File scripts/apply-patch-series.ps1 -ReimsRepo $env:RUNNER_TEMP\reims-vgpu -UtilRepo $env:RUNNER_TEMP\reims-util -ResultFile patches.json
|
||||
pwsh -File scripts/apply-patch-series.ps1 -ReimsRepo $env:RUNNER_TEMP\reims-vgpu -UtilRepo $env:RUNNER_TEMP\reims-util -Metal2VulkanRepo $env:RUNNER_TEMP\metal2vulkan -ResultFile patches.json
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$ReimsRepo,
|
||||
[string]$ResultFile = '',
|
||||
[string]$UtilRepo = ''
|
||||
[string]$UtilRepo = '',
|
||||
[string]$Metal2VulkanRepo = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$patchesDir = Join-Path $repoRoot 'patches'
|
||||
$repositories = @{
|
||||
'reims-vgpu' = $ReimsRepo
|
||||
'vendor/qemu' = Join-Path $ReimsRepo 'vendor\qemu'
|
||||
'reims-util' = $UtilRepo
|
||||
'reims-vgpu' = $ReimsRepo
|
||||
'vendor/qemu' = Join-Path $ReimsRepo 'vendor\qemu'
|
||||
'reims-util' = $UtilRepo
|
||||
'metal2vulkan' = $Metal2VulkanRepo
|
||||
}
|
||||
|
||||
function Read-PatchSeries {
|
||||
@@ -59,6 +61,9 @@ $series = @(Read-PatchSeries)
|
||||
if (-not $UtilRepo -and $series.Target -contains 'reims-util') {
|
||||
throw 'Pass -UtilRepo with a checkout at the reims-util revision pinned by reims-ctl.'
|
||||
}
|
||||
if (-not $Metal2VulkanRepo -and $series.Target -contains 'metal2vulkan') {
|
||||
throw 'Pass -Metal2VulkanRepo with a checkout at the metal2vulkan revision pinned by reims-vgpu.'
|
||||
}
|
||||
|
||||
foreach ($p in $series) {
|
||||
$file = Join-Path $patchesDir $p.Name
|
||||
|
||||
+68
-18
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Pack a portable reims-vgpu runtime for Windows x64, its matching source
|
||||
package, and SHA256SUMS.txt, ready to publish as a GitHub Release.
|
||||
@@ -29,13 +29,14 @@
|
||||
|
||||
.EXAMPLE
|
||||
pwsh -File scripts/pack-runtime.ps1 -Channel alpha
|
||||
pwsh -File scripts/pack-runtime.ps1 -Patches reims-vgpu-cargo-lock.patch,qemu-whpx-win10-compat.patch
|
||||
pwsh -File scripts/pack-runtime.ps1 -Patches reims-vgpu-snapshot-replay.patch,metal2vulkan-snapshot-replay.patch,qemu-whpx-win10-compat.patch
|
||||
#>
|
||||
[CmdletBinding(PositionalBinding = $false)]
|
||||
param(
|
||||
[string]$ReimsRepo = 'D:\DevTools\reims-vgpu',
|
||||
[string]$UtilRepo = '',
|
||||
[string]$CargoHome = 'D:\DevTools\cargo',
|
||||
[string]$ReimsRepo = 'D:\DevTools\reims-vgpu',
|
||||
[string]$UtilRepo = '',
|
||||
[string]$Metal2VulkanRepo = '',
|
||||
[string]$CargoHome = 'D:\DevTools\cargo',
|
||||
[string]$QemuDir = 'D:\Data\macos-vm-lab\reims\data\reims-ctl\qemu\current',
|
||||
[string]$Msys2 = 'D:\DevTools\msys64',
|
||||
[string]$OutDir = 'D:\Data\reims-go\releases',
|
||||
@@ -139,19 +140,35 @@ if (-not $utilTree) { throw "reims-util source at $utilCommit not found" }
|
||||
$actualUtil = git -C $utilTree rev-parse HEAD
|
||||
if ($LASTEXITCODE -ne 0 -or $actualUtil -ne $utilCommit) { throw "reims-util checkout must be at $utilCommit" }
|
||||
|
||||
# metal2vulkan's git rev as built (Cargo.lock in the build tree).
|
||||
$lock = Get-Content -Raw -LiteralPath (Join-Path $ReimsRepo 'Cargo.lock')
|
||||
if ($lock -notmatch 'metal2vulkan\?rev=([0-9a-f]{40})') { throw 'metal2vulkan rev not found in Cargo.lock' }
|
||||
$m2vCommit = $Matches[1]
|
||||
# metal2vulkan's pinned commit (workspace Cargo.toml, falling back to Cargo.lock).
|
||||
$cargoToml = Get-Content -Raw -LiteralPath (Join-Path $ReimsRepo 'Cargo.toml')
|
||||
if ($cargoToml -match 'metal2vulkan\s*=\s*\{[^}]*rev\s*=\s*"([0-9a-f]{40})"') {
|
||||
$m2vCommit = $Matches[1]
|
||||
} else {
|
||||
$lock = Get-Content -Raw -LiteralPath (Join-Path $ReimsRepo 'Cargo.lock')
|
||||
if ($lock -notmatch 'metal2vulkan\?rev=([0-9a-f]{40})') { throw 'metal2vulkan rev not found in Cargo.toml or Cargo.lock' }
|
||||
$m2vCommit = $Matches[1]
|
||||
}
|
||||
$m2vTree = if ($Metal2VulkanRepo) {
|
||||
(Resolve-Path -LiteralPath $Metal2VulkanRepo).Path
|
||||
} else {
|
||||
Get-ChildItem -LiteralPath $checkouts -Directory -Filter 'metal2vulkan-*' -ErrorAction SilentlyContinue |
|
||||
ForEach-Object { Join-Path $_.FullName $m2vCommit.Substring(0, 7) } |
|
||||
Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
|
||||
}
|
||||
if (-not $m2vTree) { throw "metal2vulkan source at $m2vCommit not found (pass -Metal2VulkanRepo or check $checkouts)" }
|
||||
$actualM2v = (git -C $m2vTree rev-parse HEAD).Trim()
|
||||
if ($LASTEXITCODE -ne 0 -or $actualM2v -ne $m2vCommit) { throw "metal2vulkan checkout must be at $m2vCommit (got $actualM2v)" }
|
||||
|
||||
$qemuVersionLine = (& $qemuExe --version | Select-Object -First 1).Trim()
|
||||
$utilVersionLine = (& $utilExe --version | Select-Object -First 1).Trim()
|
||||
|
||||
# ── 2. Patches must equal the build tree's diffs ─────────────
|
||||
$repositories = @{
|
||||
'reims-vgpu' = $ReimsRepo
|
||||
'vendor/qemu' = $qemuRepo
|
||||
'reims-util' = $utilTree
|
||||
'reims-vgpu' = $ReimsRepo
|
||||
'vendor/qemu' = $qemuRepo
|
||||
'reims-util' = $utilTree
|
||||
'metal2vulkan' = $m2vTree
|
||||
}
|
||||
$series = @(foreach ($line in Get-Content -LiteralPath (Join-Path $patchesDir 'series.txt')) {
|
||||
$t = $line.Trim()
|
||||
@@ -257,6 +274,20 @@ foreach ($targetName in $byTarget.Keys) {
|
||||
Write-Host "Expected patch stack diff --stat:`n$expStat"
|
||||
throw "Patch stack ($(($group | ForEach-Object { $_.Name }) -join ', ')) does not match the build tree's diff in $repo. Stop: don't edit patches automatically (AGENTS.md rule 4)."
|
||||
}
|
||||
# Also verify newly created (untracked) files added by patches byte-for-byte.
|
||||
$addedFiles = @(& git -C $verifyDir ls-files --others --exclude-standard | Where-Object { $_ })
|
||||
foreach ($rel in $addedFiles) {
|
||||
$expPath = Join-Path $verifyDir ($rel -replace '/', '\')
|
||||
$treePath = Join-Path $repo ($rel -replace '/', '\')
|
||||
if (-not (Test-Path -LiteralPath $treePath -PathType Leaf)) {
|
||||
throw "Patch stack expected new file $rel in $repo, but it is missing."
|
||||
}
|
||||
$expText = [IO.File]::ReadAllText($expPath).Replace("`r`n", "`n")
|
||||
$treeText = [IO.File]::ReadAllText($treePath).Replace("`r`n", "`n")
|
||||
if ($treeText -cne $expText) {
|
||||
throw "New file $rel in $repo does not match the declared patch stack. Stop: don't edit patches automatically (AGENTS.md rule 4)."
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (Test-Path -LiteralPath $verifyDir) { Remove-Item -Recurse -Force -LiteralPath $verifyDir }
|
||||
}
|
||||
@@ -273,8 +304,10 @@ $otherCtl = Get-Undeclared $ReimsRepo 'reims-vgpu' @('--ignore-submodules=all'
|
||||
$otherQemu = Get-Undeclared $qemuRepo 'vendor/qemu' @('--untracked-files=no')
|
||||
$utilStatusArgs = if ($UtilRepo) { '--untracked-files=all' } else { '--untracked-files=no' }
|
||||
$otherUtil = Get-Undeclared $utilTree 'reims-util' @($utilStatusArgs)
|
||||
if ($otherCtl.Count -or $otherQemu.Count -or $otherUtil.Count) {
|
||||
throw "Undeclared changes in the build trees:`n$($otherCtl + $otherQemu + $otherUtil -join "`n")"
|
||||
$m2vStatusArgs = if ($Metal2VulkanRepo) { '--untracked-files=all' } else { '--untracked-files=no' }
|
||||
$otherM2v = Get-Undeclared $m2vTree 'metal2vulkan' @($m2vStatusArgs)
|
||||
if ($otherCtl.Count -or $otherQemu.Count -or $otherUtil.Count -or $otherM2v.Count) {
|
||||
throw "Undeclared changes in the build trees:`n$($otherCtl + $otherQemu + $otherUtil + $otherM2v -join "`n")"
|
||||
}
|
||||
|
||||
$bundleName = "reims-runtime-win-x64-$id"
|
||||
@@ -306,7 +339,7 @@ if (Test-Path -LiteralPath (Join-Path $patchesDir 'LICENSE')) {
|
||||
Copy-Item -LiteralPath (Join-Path $patchesDir 'LICENSE') -Destination "$bundleDir\patches\LICENSE"
|
||||
}
|
||||
# The order the patches above were applied in (only those really applied).
|
||||
Write-Utf8 "$bundleDir\patches\series.txt" ((($patchSpecs | ForEach-Object { '{0,-11} {1}' -f $_.Target, $_.Name }) -join "`n") + "`n")
|
||||
Write-Utf8 "$bundleDir\patches\series.txt" ((($patchSpecs | ForEach-Object { '{0,-12} {1}' -f $_.Target, $_.Name }) -join "`n") + "`n")
|
||||
$licenses = @{
|
||||
'reims-vgpu-LICENSE.txt' = (Join-Path $ReimsRepo 'LICENSE')
|
||||
'qemu-COPYING.txt' = (Join-Path $qemuRepo 'COPYING')
|
||||
@@ -388,8 +421,6 @@ Get-ChildItem -LiteralPath (Join-Path $qemuRepo 'subprojects') -Directory |
|
||||
Where-Object { $_.Name -ne 'packagecache' -and -not (Test-Path -LiteralPath (Join-Path $srcDir "reims-vgpu-$commit\vendor\qemu\subprojects\$($_.Name)")) } |
|
||||
ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $srcDir "reims-vgpu-$commit\vendor\qemu\subprojects\") -Recurse -Force }
|
||||
|
||||
$m2vTree = Get-ChildItem -LiteralPath $checkouts -Directory -Filter 'metal2vulkan-*' | ForEach-Object { Join-Path $_.FullName $m2vCommit.Substring(0, 7) } | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
|
||||
if (-not $m2vTree) { throw "metal2vulkan source at $m2vCommit not found under $checkouts" }
|
||||
Export-GitTree $utilTree $utilCommit (Join-Path $srcDir "reims-util-$($utilCommit.Substring(0, 7))")
|
||||
Export-GitTree $m2vTree $m2vCommit (Join-Path $srcDir "metal2vulkan-$($m2vCommit.Substring(0, 7))")
|
||||
foreach ($extra in @(
|
||||
@@ -411,6 +442,23 @@ New-Item -ItemType Directory -Force -Path "$srcDir\patches" | Out-Null
|
||||
Copy-Item -Path "$bundleDir\patches\*" -Destination "$srcDir\patches\"
|
||||
Copy-Item -LiteralPath "$bundleDir\MSYS2-PACKAGES.txt" -Destination "$srcDir\MSYS2-PACKAGES.txt"
|
||||
Copy-Item -LiteralPath "$bundleDir\NOTICE.md" -Destination "$srcDir\NOTICE.md"
|
||||
$m2vBuildSteps = if ($byTarget.Contains('metal2vulkan')) {
|
||||
$m2vDir = "metal2vulkan-$($m2vCommit.Substring(0, 7))"
|
||||
$m2vApply = ($byTarget['metal2vulkan'] | ForEach-Object { " git -C $m2vDir apply `"`$(pwd)/patches/$($_.Name)`"" }) -join "`n"
|
||||
@"
|
||||
|
||||
Before running ``scripts/install-ctl.sh``, apply the ``metal2vulkan`` patches
|
||||
and point Cargo at the patched checkout via ```$CARGO_HOME/config.toml``:
|
||||
|
||||
$m2vApply
|
||||
cat >> "`${CARGO_HOME:-`$HOME/.cargo}/config.toml" <<EOF
|
||||
[patch."https://github.com/steelbrain/metal2vulkan"]
|
||||
metal2vulkan = { path = "`$(cygpath -m "`$(pwd)/$m2vDir")/crates/metal2vulkan" }
|
||||
metal2vulkan-runtime = { path = "`$(cygpath -m "`$(pwd)/$m2vDir")/crates/metal2vulkan-runtime" }
|
||||
EOF
|
||||
|
||||
"@
|
||||
}
|
||||
$utilBuildSteps = if ($byTarget.Contains('reims-util')) {
|
||||
$utilDir = "reims-util-$($utilCommit.Substring(0, 7))"
|
||||
$utilApply = ($byTarget['reims-util'] | ForEach-Object { " git -C $utilDir apply `"`$(pwd)/patches/$($_.Name)`"" }) -join "`n"
|
||||
@@ -447,7 +495,9 @@ $((($patchSpecs | Where-Object { $_.Target -eq 'reims-vgpu' } | ForEach-Object {
|
||||
cd vendor/qemu
|
||||
$((($patchSpecs | Where-Object { $_.Target -eq 'vendor/qemu' } | ForEach-Object { " git apply ../../../patches/$($_.Name)" }) -join "`n"))
|
||||
|
||||
(``patch -p1`` works too.) Then build as upstream documents (``scripts/install-ctl.sh``
|
||||
(``patch -p1`` works too.)
|
||||
$m2vBuildSteps
|
||||
Then build as upstream documents (``scripts/install-ctl.sh``
|
||||
in an MSYS2 CLANG64 shell). The DLLs in ``qemu/bin`` come from the MSYS2
|
||||
packages listed in ``MSYS2-PACKAGES.txt``, with links to their sources.
|
||||
$utilBuildSteps
|
||||
|
||||
Reference in new issue
Block a user