Build Windows runtimes with the AMD Vulkan startup fixes
Apply the GPU address carry and dynamic attachment feedback backports after the snapshot replay patch. The runtime source archive records both patches alongside their pinned upstream base.
This commit is contained in:
1 parent
98f1677b5f
commit
3bbf37b149
4 files changed
+975
-3
No files matched your search
@@ -4,8 +4,8 @@
|
||||
|
||||
| 组件 | 源码 | 维护范围 |
|
||||
| :--- | :--- | :--- |
|
||||
| Reims vGPU | [`yxc0915/reims-vgpu`](https://github.com/yxc0915/reims-vgpu/tree/codex/intel-vm-suspend) | GPU 挂起重放、窗口和 CLI 兼容性修复 |
|
||||
| QEMU | [`yxc0915/qemu-reims-vgpu`](https://github.com/yxc0915/qemu-reims-vgpu/tree/codex/intel-vm-suspend) | Windows WHPX、文件迁移和设备状态保存恢复 |
|
||||
| Reims vGPU | [`reims-go/reims-vgpu`](https://github.com/reims-go/reims-vgpu/tree/codex/intel-vm-suspend) | GPU 挂起重放、窗口和 CLI 兼容性修复 |
|
||||
| QEMU | [`reims-go/qemu-reims-vgpu`](https://github.com/reims-go/qemu-reims-vgpu/tree/codex/intel-vm-suspend) | Windows WHPX、文件迁移和设备状态保存恢复 |
|
||||
|
||||
Reims vGPU 分支通过 `vendor/qemu` 固定 QEMU 提交,并在 `reims-go-runtime.json` 声明运行时能力。更新 QEMU 时先把新提交推到 QEMU fork,再更新 Reims vGPU 的子模块指针。Reims-Go 构建据此记录两个源码仓库及提交号。
|
||||
|
||||
@@ -19,6 +19,8 @@ Alpha 编号与挂起兼容判定见 [Alpha 运行时编号与挂起兼容性规
|
||||
| :--- | :--- | :--- |
|
||||
| [`reims-util-parallel-offline-download.patch`](reims-util-parallel-offline-download.patch) | `steelbrain/reims-util` | 有 Apple 分块校验数据时并发下载离线安装包,按顺序验证并写入镜像。 |
|
||||
| [`metal2vulkan-snapshot-replay.patch`](metal2vulkan-snapshot-replay.patch) | `steelbrain/metal2vulkan` | 读取和恢复缓冲、纹理及事件状态,为 GPU 挂起重放提供依赖。 |
|
||||
| [`metal2vulkan-psb-address-carry.patch`](metal2vulkan-psb-address-carry.patch) | `steelbrain/metal2vulkan` | 恢复 64 位 GPU 地址时显式处理低位进位。 [组织 fork 提交](https://github.com/reims-go/metal2vulkan/commit/729d91d23bb56a99f2b5b74d3d3445c65cc1cdf1) |
|
||||
| [`metal2vulkan-dynamic-attachment-feedback.patch`](metal2vulkan-dynamic-attachment-feedback.patch) | `steelbrain/metal2vulkan` | 需要动态反馈状态才启用原生附件反馈。其余设备通过影子纹理读取附件。 [组织 fork 提交](https://github.com/reims-go/metal2vulkan/commit/ea695f945626f15c27ac9b463ba4160c65530b43) |
|
||||
|
||||
构建通过 Cargo 的本地源码覆盖使用已打补丁的 `metal2vulkan`。客户端的运行时包格式见[便携运行时规范](https://github.com/Nwflower/Reims-Go/blob/main/docs/portable-runtime-spec.md)。
|
||||
|
||||
@@ -45,5 +47,5 @@ Alpha 编号与挂起兼容判定见 [Alpha 运行时编号与挂起兼容性规
|
||||
每日构建会跳过已合入的等价补丁,并在日志中报告。确认后按以下步骤清理。
|
||||
|
||||
1. 删除 `patches/` 下对应的 `.patch` 文件,并同步更新 [`series.txt`](series.txt) 与本文件。
|
||||
2. 等待下一次定时构建,或在 Reims vGPU fork 手动触发 [Preview 工作流](https://github.com/yxc0915/reims-vgpu/actions/workflows/runtime-preview.yml)。
|
||||
2. 等待下一次定时构建,或在 Reims vGPU fork 手动触发 [Preview 工作流](https://github.com/reims-go/reims-vgpu/actions/workflows/runtime-preview.yml)。
|
||||
3. 在真实宿主运行 [`smoke-runtime.ps1`](../scripts/smoke-runtime.ps1) 完成冒烟并人工确认后,将对应 Release 升级为 `stable`。
|
||||
@@ -0,0 +1,590 @@
|
||||
diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md
|
||||
index f7bc4b6c2..083011698 100644
|
||||
--- a/crates/metal2vulkan-runtime/README.md
|
||||
+++ b/crates/metal2vulkan-runtime/README.md
|
||||
@@ -4710,10 +4710,8 @@ cache is answered compile-required on both.
|
||||
from the layout the pass renders it in, the rest from home), and the rendering begins again
|
||||
with the attachment in that layout; the pass's second barrier moves the whole image home. Until then every draw of the
|
||||
pass reads the image's textures through their second elements (Set 1), a texture that reaches
|
||||
- no rendered level among them. Every render pipeline is made with the feedback loop's colour
|
||||
- flag (`VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT`), which lets a draw read an
|
||||
- attachment in the feedback layout and asks nothing of a draw that reads none, so no draw records
|
||||
- a state for the loop. Each draw that
|
||||
+ no rendered level among them. Render pipelines declare `VK_DYNAMIC_STATE_ATTACHMENT_FEEDBACK_LOOP_ENABLE_EXT`;
|
||||
+ the encoder enables color feedback while an attachment is in the feedback layout. Each draw that
|
||||
reads an attachment through the loop, through a texture or by a fetch (below), counts in
|
||||
`Metrics::attachment_loop_reads`, its barriers in `Metrics::barriers`.
|
||||
- Through a copy, on a device without the feedback loop, and for a surface plane whose image took
|
||||
@@ -5087,9 +5085,8 @@ cache is answered compile-required on both.
|
||||
same draws into a target of render-target usage alone take the same time either way. The loop's
|
||||
flag on every render pipeline costs no time measured there (m3-max-72033) or on RADV
|
||||
(m3-max-72020).
|
||||
-- On a device that does not report `attachmentFeedbackLoopLayout` (expected of the UHD 630
|
||||
- among the lab's, Windows driver 101.2145: no public report of that card on Windows lists
|
||||
- `VK_EXT_attachment_feedback_loop_layout`), a draw reads an attachment through a copy into the image's shadow, which Metal does not make: at
|
||||
+- On a device without the feedback layout or its dynamic state, a draw reads an attachment
|
||||
+ through a copy into the image's shadow, which Metal does not make: at
|
||||
the pass's first draw that reads the image, at the first after a memory barrier after draws,
|
||||
and where a draw reads what the shadow does not hold, the rendering ended and begun again
|
||||
around the copies and their two barriers; where the draw is the pass's first and reads only
|
||||
@@ -5496,7 +5493,8 @@ Presenting runs on the runtime's own device; nothing is exported or imported.
|
||||
| `VK_EXT_shader_stencil_export` | device, where listed | a fragment function's `[[stencil]]` output as the fragment's stencil reference (`FragStencilRefEXT`); a device without it draws the output by bits (the known gaps); RADV, ANV, lavapipe, KosmicKrisp and the UHD 630's Windows driver list it, NVIDIA's 615 and 620 drivers do not |
|
||||
| `VK_KHR_portability_enumeration` | instance, where offered | listing portability devices, each checked against the floor as any other |
|
||||
| `VK_KHR_portability_subset` | device, where listed | Vulkan requires it enabled where a device lists it; the device is asked for the portability features below |
|
||||
-| `VK_EXT_attachment_feedback_loop_layout` | device, with the feedback loop | a draw's read of an attachment of its own pass through a texture, in the feedback layout, with the colour flag every render pipeline takes (below) |
|
||||
+| `VK_EXT_attachment_feedback_loop_layout` | device, with the feedback loop | a draw's read of an attachment of its own pass through a texture in the feedback layout |
|
||||
+| `VK_EXT_attachment_feedback_loop_dynamic_state` | device, with the feedback loop | enables feedback for the color aspect while an attachment is in the feedback layout |
|
||||
| `VK_KHR_vertex_attribute_divisor` | device, where listed | a vertex layout stepped per instance at a rate above 1, through the step-rate feature below |
|
||||
| `VK_EXT_vertex_attribute_divisor` | device, where listed | the same, on a device that lists only this extension, which the KHR was promoted from with the same feature and pipeline structures |
|
||||
| `VK_EXT_external_memory_host` | device, where listed | importing host memory by its address (`Device::import_host_memory`) |
|
||||
@@ -5840,16 +5838,14 @@ second elements beside the floor's arrays: 65,536 sampled images more than the l
|
||||
`maxUpdateAfterBindDescriptorsInAllPools`); a device without them refuses such a draw
|
||||
(`Gap::Draw` of `DrawKind::AttachmentRead`), and is otherwise the same
|
||||
(`floor::Capabilities::attachment_reads`). The draw reads through the attachment feedback loop
|
||||
-where the device also lists the extension marked "with the feedback loop" above and reports the
|
||||
-feature below, which device creation then enables, and neither otherwise
|
||||
-(`floor::Capabilities::feedback_loop`). A device that reads attachments without them reads
|
||||
-through a copy of the image into its shadow (Render encoders), a known gap. AMD's Windows driver
|
||||
-is expected to take the loop, not verified in the lab (public reports of it list
|
||||
-`VK_EXT_attachment_feedback_loop_layout` from 2.0.250 on).
|
||||
+where the device lists both extensions marked "with the feedback loop" and reports both features
|
||||
+below (`floor::Capabilities::feedback_loop`). A device without these capabilities reads through
|
||||
+a copy of the image into its shadow (Render encoders), a known gap.
|
||||
|
||||
| Attachment-read feature | Structure | Used for |
|
||||
|---|---|---|
|
||||
| `attachmentFeedbackLoopLayout` | `VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT` | the feedback layout and usage |
|
||||
+| `attachmentFeedbackLoopDynamicState` | `VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT` | enables feedback for the color aspect at draw time |
|
||||
|
||||
### Bound kernel buffers
|
||||
|
||||
diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs
|
||||
--- a/crates/metal2vulkan-runtime/src/device.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/device.rs
|
||||
@@ -269,10 +269,8 @@
|
||||
pub(crate) ticks: Ticks,
|
||||
/// `VK_EXT_calibrated_timestamps`, the floor's: the GPU's clock read with the host's.
|
||||
pub(crate) calibrated: ash::ext::calibrated_timestamps::Device,
|
||||
- /// Device creation enabled the attachment feedback loop (`floor::Capabilities::feedback_loop`):
|
||||
- /// 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,
|
||||
+ /// Device entry points for dynamic attachment feedback (`floor::Capabilities::feedback_loop`).
|
||||
+ pub(crate) feedback_loop: Option<ash::ext::attachment_feedback_loop_dynamic_state::Device>,
|
||||
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`).
|
||||
@@ -600,6 +598,7 @@
|
||||
mut robustness2,
|
||||
mut portability,
|
||||
mut feedback_loop,
|
||||
+ mut feedback_dynamic,
|
||||
mut divisor,
|
||||
mut border_swizzle,
|
||||
mut linear_attachment,
|
||||
@@ -654,7 +653,9 @@
|
||||
features = features.push_next(&mut portability);
|
||||
}
|
||||
if capabilities.feedback_loop {
|
||||
- features = features.push_next(&mut feedback_loop);
|
||||
+ features = features
|
||||
+ .push_next(&mut feedback_loop)
|
||||
+ .push_next(&mut feedback_dynamic);
|
||||
}
|
||||
if enabled(ash::khr::vertex_attribute_divisor::NAME)
|
||||
|| enabled(ash::ext::vertex_attribute_divisor::NAME)
|
||||
@@ -844,6 +845,9 @@
|
||||
alignment,
|
||||
);
|
||||
let submit_calls = Arc::new(SubmitCalls::new(counters.clone()));
|
||||
+ let feedback_loop = capabilities.feedback_loop.then(|| {
|
||||
+ ash::ext::attachment_feedback_loop_dynamic_state::Device::new(vk_instance, &device)
|
||||
+ });
|
||||
let live = instance.teardowns().live();
|
||||
let core = Arc::new(Core {
|
||||
instance,
|
||||
@@ -860,7 +864,7 @@
|
||||
counters,
|
||||
ticks,
|
||||
calibrated,
|
||||
- feedback_loop: capabilities.feedback_loop,
|
||||
+ feedback_loop,
|
||||
capture_replay: capabilities.buffer_device_address_capture_replay,
|
||||
fault,
|
||||
indirect,
|
||||
diff --git a/crates/metal2vulkan-runtime/src/floor.rs b/crates/metal2vulkan-runtime/src/floor.rs
|
||||
index 0e165934f..f598f0f93 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/floor.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/floor.rs
|
||||
@@ -134,14 +134,14 @@ const _: () = {
|
||||
assert!(offset_of!(Maintenance8Features, maintenance8) == 16);
|
||||
};
|
||||
|
||||
-/// The device extension of the attachment feedback loop (`VK_EXT_attachment_feedback_loop_layout`),
|
||||
-/// through which a draw reads, through a texture, an attachment its own pass renders (Metal's
|
||||
-/// texture read of a render target): its layout, its image usage and its pipeline flag, which every
|
||||
-/// render pipeline takes. Device creation enables it, with its feature, where the device reads
|
||||
-/// attachments (`Capabilities::attachment_reads`), lists it and reports the feature, and not
|
||||
-/// otherwise. A device that reads attachments without it reads through a copy of the image
|
||||
-/// (`Capabilities::feedback_loop`).
|
||||
-pub const ATTACHMENT_READ_EXTENSIONS: &[&CStr] = &[ash::ext::attachment_feedback_loop_layout::NAME];
|
||||
+/// The device extensions for reading an attachment of the current pass in the feedback layout,
|
||||
+/// with feedback enabled dynamically for its color aspect. Device creation enables both
|
||||
+/// extensions and both features where the device reads attachments and supports them.
|
||||
+/// Otherwise, attachment reads use the image's shadow (`Capabilities::feedback_loop`).
|
||||
+pub const ATTACHMENT_READ_EXTENSIONS: &[&CStr] = &[
|
||||
+ ash::ext::attachment_feedback_loop_layout::NAME,
|
||||
+ ash::ext::attachment_feedback_loop_dynamic_state::NAME,
|
||||
+];
|
||||
|
||||
/// The device extension of a sampler's border colour through a view's component mapping
|
||||
/// (`VK_EXT_border_color_swizzle`), after `VK_EXT_custom_border_color`, which it requires and of
|
||||
@@ -399,6 +399,8 @@ pub struct Features {
|
||||
/// `VK_EXT_attachment_feedback_loop_layout`: read where the device lists it, and enabled where
|
||||
/// the device reads attachments through the feedback loop alone.
|
||||
pub feedback_loop: vk::PhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT<'static>,
|
||||
+ /// Dynamic feedback state, queried and enabled with the feedback layout when available.
|
||||
+ pub feedback_dynamic: vk::PhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT<'static>,
|
||||
/// `VkPhysicalDeviceVertexAttributeDivisorFeaturesKHR`, of `VK_KHR_vertex_attribute_divisor`
|
||||
/// and `VK_EXT_vertex_attribute_divisor` (the same structure): read and enabled only where the
|
||||
/// device lists one of them, and then only the step-rate feature.
|
||||
@@ -477,6 +479,9 @@ macro_rules! feature {
|
||||
(@structure feedback_loop) => {
|
||||
"VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT"
|
||||
};
|
||||
+ (@structure feedback_dynamic) => {
|
||||
+ "VkPhysicalDeviceAttachmentFeedbackLoopDynamicStateFeaturesEXT"
|
||||
+ };
|
||||
(@structure divisor) => {
|
||||
"VkPhysicalDeviceVertexAttributeDivisorFeaturesKHR"
|
||||
};
|
||||
@@ -715,11 +720,11 @@ pub(crate) const OPTIONAL: &[Feature] = &[
|
||||
feature!(maintenance8.maintenance8 => Maintenance8),
|
||||
];
|
||||
|
||||
-/// The feature of the attachment feedback loop ([`ATTACHMENT_READ_EXTENSIONS`]): enabled where the
|
||||
-/// device reads attachments and reports it, and not otherwise; a device that reads attachments
|
||||
-/// without it reads through a copy of the image.
|
||||
-pub(crate) const ATTACHMENT_READS: &[Feature] =
|
||||
- &[feature!(feedback_loop.attachment_feedback_loop_layout => AttachmentFeedbackLoopLayout)];
|
||||
+/// The features needed for native attachment feedback ([`ATTACHMENT_READ_EXTENSIONS`]).
|
||||
+pub(crate) const ATTACHMENT_READS: &[Feature] = &[
|
||||
+ feature!(feedback_loop.attachment_feedback_loop_layout => AttachmentFeedbackLoopLayout),
|
||||
+ feature!(feedback_dynamic.attachment_feedback_loop_dynamic_state),
|
||||
+];
|
||||
|
||||
/// The features device creation enables where the device reports them, for Metal's per-instance
|
||||
/// step at a rate above 1, which the translator builds in one form, a binding's divisor, and
|
||||
@@ -1231,6 +1236,8 @@ unsafe fn query(
|
||||
let robustness2_listed = listed(ash::ext::robustness2::NAME);
|
||||
let portability_listed = listed(ash::khr::portability_subset::NAME);
|
||||
let feedback_loop_listed = listed(ash::ext::attachment_feedback_loop_layout::NAME);
|
||||
+ let feedback_dynamic_listed =
|
||||
+ listed(ash::ext::attachment_feedback_loop_dynamic_state::NAME);
|
||||
let divisor_listed = listed(ash::khr::vertex_attribute_divisor::NAME)
|
||||
|| listed(ash::ext::vertex_attribute_divisor::NAME);
|
||||
let border_swizzle_listed = listed(ash::ext::border_color_swizzle::NAME);
|
||||
@@ -1254,6 +1261,7 @@ unsafe fn query(
|
||||
robustness2,
|
||||
portability,
|
||||
feedback_loop,
|
||||
+ feedback_dynamic,
|
||||
divisor,
|
||||
border_swizzle,
|
||||
linear_attachment,
|
||||
@@ -1292,6 +1300,9 @@ unsafe fn query(
|
||||
if feedback_loop_listed {
|
||||
features = features.push_next(&mut *feedback_loop);
|
||||
}
|
||||
+ if feedback_dynamic_listed {
|
||||
+ features = features.push_next(&mut *feedback_dynamic);
|
||||
+ }
|
||||
if divisor_listed {
|
||||
features = features.push_next(&mut *divisor);
|
||||
}
|
||||
@@ -1332,6 +1343,7 @@ unsafe fn query(
|
||||
robustness2.p_next = std::ptr::null_mut();
|
||||
portability.p_next = std::ptr::null_mut();
|
||||
feedback_loop.p_next = std::ptr::null_mut();
|
||||
+ feedback_dynamic.p_next = std::ptr::null_mut();
|
||||
divisor.p_next = std::ptr::null_mut();
|
||||
border_swizzle.p_next = std::ptr::null_mut();
|
||||
linear_attachment.p_next = std::ptr::null_mut();
|
||||
diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs
|
||||
index 8d9480c8f..89ceff148 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/render.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/render.rs
|
||||
@@ -232,12 +232,6 @@ pub(crate) struct RenderCompiled {
|
||||
stages: Vec<Module>,
|
||||
/// The fixed-function state every `VkPipeline` of the content takes.
|
||||
fixed: Fixed,
|
||||
- /// The create flags every `VkPipeline` of the content takes: the feedback loop's colour flag
|
||||
- /// where device creation enabled the attachment feedback loop (`Core::feedback_loop`), and
|
||||
- /// none otherwise. A state is made before any draw binds its textures, and which texture a
|
||||
- /// draw binds decides whether it reads an attachment of its pass, so every pipeline takes it;
|
||||
- /// a draw that reads none is valid with it.
|
||||
- pub(crate) flags: vk::PipelineCreateFlags,
|
||||
/// The content's main `VkPipeline`: the triangle class's, or a post-tessellation vertex
|
||||
/// function's patch class's, its only class, at the default [`Raster`].
|
||||
primary: Main,
|
||||
@@ -1283,10 +1277,6 @@ impl RenderCompiled {
|
||||
core: Arc::clone(core),
|
||||
stages,
|
||||
fixed: Fixed::of(&pipeline),
|
||||
- flags: match core.feedback_loop {
|
||||
- true => vk::PipelineCreateFlags::COLOR_ATTACHMENT_FEEDBACK_LOOP_EXT,
|
||||
- false => vk::PipelineCreateFlags::empty(),
|
||||
- },
|
||||
primary: Main::default(),
|
||||
named: named.map(|list| (list, Main::default())),
|
||||
later: Mutex::new(Vec::new()),
|
||||
@@ -1523,6 +1513,11 @@ impl RenderCompiled {
|
||||
.discard
|
||||
.then_some(vk::DynamicState::RASTERIZER_DISCARD_ENABLE),
|
||||
)
|
||||
+ .chain(
|
||||
+ core.feedback_loop
|
||||
+ .as_ref()
|
||||
+ .map(|_| vk::DynamicState::ATTACHMENT_FEEDBACK_LOOP_ENABLE_EXT),
|
||||
+ )
|
||||
.collect();
|
||||
let dynamic_states = vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&states);
|
||||
let mut rendering = vk::PipelineRenderingCreateInfo::default()
|
||||
@@ -1530,7 +1525,6 @@ impl RenderCompiled {
|
||||
.depth_attachment_format(fixed.depth)
|
||||
.stencil_attachment_format(fixed.stencil);
|
||||
let mut info = vk::GraphicsPipelineCreateInfo::default()
|
||||
- .flags(self.flags)
|
||||
.push_next(&mut rendering)
|
||||
.stages(&stages)
|
||||
.vertex_input_state(&vertex_input)
|
||||
diff --git a/crates/metal2vulkan-runtime/src/render_encoder.rs b/crates/metal2vulkan-runtime/src/render_encoder.rs
|
||||
index 88405a427..bd43630a4 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/render_encoder.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/render_encoder.rs
|
||||
@@ -34,9 +34,8 @@
|
||||
//! attachment layout, the rest from home), and the rendering begins again with the attachment in
|
||||
//! that layout; the pass's second barrier moves the whole image home. While it is there, every
|
||||
//! draw of the pass reads the image's textures through their elements in that layout
|
||||
-//! (`crate::arrays`). Every render pipeline is made with the feedback loop's colour flag
|
||||
-//! (`VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT`), so any draw may read an
|
||||
-//! attachment in the feedback layout and a draw that reads none needs nothing set.
|
||||
+//! (`crate::arrays`). Render pipelines declare dynamic feedback state. The encoder enables
|
||||
+//! color feedback for draws while an attachment is in the feedback layout.
|
||||
//!
|
||||
//! What such a draw reads that an earlier draw of the pass rendered, Metal orders by a memory
|
||||
//! barrier between the two. A memory barrier after draws that wrote no memory, where the pass
|
||||
@@ -2742,6 +2741,14 @@ impl RenderCommandEncoder {
|
||||
core.device.cmd_set_rasterizer_discard_enable(command, true);
|
||||
}
|
||||
}
|
||||
+ if let Some(feedback) = &core.feedback_loop {
|
||||
+ let aspects = if self.moved.is_empty() {
|
||||
+ vk::ImageAspectFlags::empty()
|
||||
+ } else {
|
||||
+ vk::ImageAspectFlags::COLOR
|
||||
+ };
|
||||
+ (feedback.fp().cmd_set_attachment_feedback_loop_enable_ext)(command, aspects);
|
||||
+ }
|
||||
self.record_state(topology, restart, hidden);
|
||||
// A mode's query begins at its first draw, after what that draw ended the rendering
|
||||
// to record first: the command buffer is inside the pass's rendering, and keeps the
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/device.rs b/crates/metal2vulkan-runtime/src/tests/device.rs
|
||||
index 8d9a1eb60..4e147bdef 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/device.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/device.rs
|
||||
@@ -426,7 +426,7 @@ fn every_device_of_the_cfgs_kind_enables_the_consumers_extensions_it_offers() {
|
||||
.filter(|&name| lists(name)),
|
||||
);
|
||||
// The attachment reads' extensions, where device creation took them.
|
||||
- if device.core().feedback_loop {
|
||||
+ if device.core().feedback_loop.is_some() {
|
||||
expected.extend(floor::ATTACHMENT_READ_EXTENSIONS);
|
||||
}
|
||||
// The border swizzle's, where the device reports it from the image.
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/draw.rs b/crates/metal2vulkan-runtime/src/tests/draw.rs
|
||||
index 406179311..a7601ae11 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/draw.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/draw.rs
|
||||
@@ -2902,7 +2902,7 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" {
|
||||
(device.grant_indices(IndexClass::Texture, 4096, 4))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let reads = device.core().attachment_reads;
|
||||
- let looped = device.core().feedback_loop;
|
||||
+ let looped = device.core().feedback_loop.is_some();
|
||||
let plain = state(name, &device, &plain);
|
||||
let mut buffers = Buffers::new(&device);
|
||||
// Three triangles over the whole target, their colors none, blue and green.
|
||||
@@ -3065,41 +3065,22 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" {
|
||||
});
|
||||
}
|
||||
|
||||
- /// Where device creation enabled the attachment feedback loop, every render pipeline takes the
|
||||
- /// loop's colour flag, `VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT`: that of a
|
||||
- /// fragment function that reads no texture as much as that of one that reads its pass's
|
||||
- /// attachment through one, since a state is made before any draw binds its textures. A
|
||||
- /// device without the loop makes them with no flag. Then, through the loop, a pass draws with
|
||||
- /// both after the first reads the attachment, and the second writes it: every pixel is the
|
||||
- /// second's.
|
||||
+ /// A draw can sample its attachment with dynamic feedback enabled. The following draw can
|
||||
+ /// bind a different pipeline and write to the same attachment in the feedback layout.
|
||||
#[test]
|
||||
- fn every_device_makes_every_render_pipeline_with_the_loop_s_flag_where_it_has_the_loop() {
|
||||
- use ash::vk;
|
||||
+ fn a_draw_reads_an_attachment_with_dynamic_feedback() {
|
||||
let Some(library) = examples() else {
|
||||
return;
|
||||
};
|
||||
let plain = descriptor(&library, "colored_fragment", PixelFormat::RGBA8Unorm);
|
||||
let own = descriptor(&library, "own_pixel_fragment", PixelFormat::RGBA8Unorm);
|
||||
- each_device("loop_flags", |name, _, device| {
|
||||
- let looped = device.core().feedback_loop;
|
||||
- let want = match looped {
|
||||
- true => vk::PipelineCreateFlags::COLOR_ATTACHMENT_FEEDBACK_LOOP_EXT,
|
||||
- false => vk::PipelineCreateFlags::empty(),
|
||||
- };
|
||||
- let plain = state(name, &device, &plain);
|
||||
- let reading = state(name, &device, &own);
|
||||
- for (what, state) in [("reading no texture", &plain), ("reading one", &reading)] {
|
||||
- // Raw: ash's flag types are not `Debug` under the features the runtime takes.
|
||||
- assert_eq!(
|
||||
- state.inner.compiled.flags.as_raw(),
|
||||
- want.as_raw(),
|
||||
- "{name}: a state's pipelines {what}, the loop {looped}"
|
||||
- );
|
||||
- }
|
||||
- if !looped {
|
||||
- println!("{name}: no feedback loop; every render pipeline made with no flag");
|
||||
+ each_device("dynamic_feedback", |name, _, device| {
|
||||
+ if device.core().feedback_loop.is_none() {
|
||||
+ println!("{name}: no dynamic attachment feedback support");
|
||||
return;
|
||||
}
|
||||
+ let plain = state(name, &device, &plain);
|
||||
+ let reading = state(name, &device, &own);
|
||||
(device.grant_indices(IndexClass::Texture, 4096, 4))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let mut buffers = Buffers::new(&device);
|
||||
@@ -3147,7 +3128,7 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" {
|
||||
want,
|
||||
"{name}: every pixel the second draw's blue"
|
||||
);
|
||||
- println!("{name}: every render pipeline made with the loop's colour flag");
|
||||
+ println!("{name}: the feedback layout survived a pipeline change");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3170,7 +3151,7 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" {
|
||||
}
|
||||
(device.grant_indices(IndexClass::Texture, 4096, 4))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
- let looped = device.core().feedback_loop;
|
||||
+ let looped = device.core().feedback_loop.is_some();
|
||||
let plain = state(name, &device, &plain);
|
||||
let reading = state(name, &device, &own);
|
||||
let mut buffers = Buffers::new(&device);
|
||||
@@ -3258,7 +3239,7 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" {
|
||||
println!("{name}: no attachment reads");
|
||||
return;
|
||||
}
|
||||
- let looped = device.core().feedback_loop;
|
||||
+ let looped = device.core().feedback_loop.is_some();
|
||||
let counters = device.counters();
|
||||
let before = counters.metrics();
|
||||
for (class, first) in [(IndexClass::Texture, 4096), (IndexClass::Sampler, 1)] {
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/fetch.rs b/crates/metal2vulkan-runtime/src/tests/fetch.rs
|
||||
index a77caf19d..feb279ee5 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/fetch.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/fetch.rs
|
||||
@@ -213,7 +213,7 @@ mod on_device {
|
||||
(device.grant_indices(IndexClass::Texture, 4096, DRAWS.len() as u32))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let reads = device.core().attachment_reads;
|
||||
- let looped = device.core().feedback_loop;
|
||||
+ let looped = device.core().feedback_loop.is_some();
|
||||
let state = state(name, &device, &d);
|
||||
let queue = device.new_command_queue(4).expect("a queue");
|
||||
let clear = ClearColor {
|
||||
@@ -446,7 +446,7 @@ mod on_device {
|
||||
(device.grant_indices(IndexClass::Texture, 4096, DRAWS.len() as u32))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let reads = device.core().attachment_reads;
|
||||
- let feedback = device.core().feedback_loop;
|
||||
+ let feedback = device.core().feedback_loop.is_some();
|
||||
// The feedback usage is the loop's extension's, so only a device with the loop is
|
||||
// asked it (`VUID-VkPhysicalDeviceImageFormatInfo2-usage-parameter`); the answer is
|
||||
// read only there.
|
||||
@@ -586,7 +586,7 @@ mod on_device {
|
||||
(device.grant_indices(IndexClass::Texture, 4096, count))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let reads = device.core().attachment_reads;
|
||||
- let feedback = device.core().feedback_loop;
|
||||
+ let feedback = device.core().feedback_loop.is_some();
|
||||
// The feedback usage is the loop's extension's, so only a device with the loop is
|
||||
// asked it (`VUID-VkPhysicalDeviceImageFormatInfo2-usage-parameter`); the answer is
|
||||
// read only there.
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/floor.rs b/crates/metal2vulkan-runtime/src/tests/floor.rs
|
||||
index 8e03e9515..3aa5c1d2f 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/floor.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/floor.rs
|
||||
@@ -1834,12 +1834,8 @@ fn a_run_time_texel_offset_is_the_sample_s_operand_where_maintenance8_is_reporte
|
||||
assert_eq!(answer(&device), (true, true, true, true, true));
|
||||
}
|
||||
|
||||
-/// A device reads attachments where its descriptor limits hold the sampled-texture array's second
|
||||
-/// elements: through the attachment feedback loop where it lists
|
||||
-/// `VK_EXT_attachment_feedback_loop_layout` and reports its feature, which device creation then
|
||||
-/// enables, with no other extension (its dynamic state is never enabled, listed or not), and
|
||||
-/// through a copy of the image where it does not, enabling neither. A device without the room
|
||||
-/// reads no attachment, whatever it reports.
|
||||
+/// Attachment reads require room in the descriptor arrays. Native feedback also requires
|
||||
+/// both extensions and both features; otherwise reads use the shadow.
|
||||
#[test]
|
||||
fn the_attachment_reads_take_the_feedback_loop_where_reported_and_a_copy_elsewhere() {
|
||||
let roomy = |device: &mut Queried| {
|
||||
@@ -1875,10 +1871,15 @@ fn the_attachment_reads_take_the_feedback_loop_where_reported_and_a_copy_elsewhe
|
||||
let mut device = at_the_floor();
|
||||
assert_eq!(answer(&device), (false, false, 0, 0), "at the floor");
|
||||
looped(&mut device);
|
||||
+ device.extensions.push(dynamic.to_owned());
|
||||
+ device
|
||||
+ .features
|
||||
+ .feedback_dynamic
|
||||
+ .attachment_feedback_loop_dynamic_state = vk::TRUE;
|
||||
assert_eq!(
|
||||
answer(&device),
|
||||
(false, false, 0, 0),
|
||||
- "no room, the loop reported"
|
||||
+ "no room, both features reported"
|
||||
);
|
||||
let mut device = at_the_floor();
|
||||
roomy(&mut device);
|
||||
@@ -1900,15 +1901,23 @@ fn the_attachment_reads_take_the_feedback_loop_where_reported_and_a_copy_elsewhe
|
||||
looped(&mut device);
|
||||
assert_eq!(
|
||||
answer(&device),
|
||||
- (true, true, 1, 1),
|
||||
- "room and the layout extension alone: the loop"
|
||||
+ (true, false, 0, 0),
|
||||
+ "room and the layout extension alone: the copy"
|
||||
);
|
||||
device.extensions.push(dynamic.to_owned());
|
||||
- let capabilities = decide(&device).unwrap_or_else(|below| panic!("{below}"));
|
||||
- assert!(capabilities.feedback_loop);
|
||||
- assert!(
|
||||
- !capabilities.extensions.contains(&dynamic),
|
||||
- "the loop's dynamic state is never enabled"
|
||||
+ assert_eq!(
|
||||
+ answer(&device),
|
||||
+ (true, false, 0, 0),
|
||||
+ "room and both extensions but no dynamic feature: the copy"
|
||||
+ );
|
||||
+ device
|
||||
+ .features
|
||||
+ .feedback_dynamic
|
||||
+ .attachment_feedback_loop_dynamic_state = vk::TRUE;
|
||||
+ assert_eq!(
|
||||
+ answer(&device),
|
||||
+ (true, true, 2, 2),
|
||||
+ "room and both features reported: the loop"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2306,6 +2315,7 @@ fn every_device_the_loader_lists_is_above_the_floor() {
|
||||
mut robustness2,
|
||||
mut portability,
|
||||
mut feedback_loop,
|
||||
+ mut feedback_dynamic,
|
||||
mut divisor,
|
||||
mut border_swizzle,
|
||||
mut linear_attachment,
|
||||
@@ -2343,7 +2353,9 @@ fn every_device_the_loader_lists_is_above_the_floor() {
|
||||
features = features.push_next(&mut portability);
|
||||
}
|
||||
if capabilities.feedback_loop {
|
||||
- features = features.push_next(&mut feedback_loop);
|
||||
+ features = features
|
||||
+ .push_next(&mut feedback_loop)
|
||||
+ .push_next(&mut feedback_dynamic);
|
||||
}
|
||||
if enabled(ash::khr::vertex_attribute_divisor::NAME)
|
||||
|| enabled(ash::ext::vertex_attribute_divisor::NAME)
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs b/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs
|
||||
index 5d0d0c52d..07e8658e8 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/held_loop_reads.rs
|
||||
@@ -62,7 +62,7 @@ mod on_device {
|
||||
held.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
|
||||
each_device("held_loop_reads", |name, _, device| {
|
||||
let core = device.core();
|
||||
- let (reads, looped) = (core.attachment_reads, core.feedback_loop);
|
||||
+ let (reads, looped) = (core.attachment_reads, core.feedback_loop.is_some());
|
||||
println!("{name}: attachment reads {reads}, feedback loop {looped}");
|
||||
if !reads {
|
||||
println!("{name}: SKIPPED: the device reads no attachment through a texture");
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs b/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs
|
||||
index 2e130a17f..6c766acdd 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/real_size_overs.rs
|
||||
@@ -1104,7 +1104,7 @@ declare <2 x i32> @air.convert.u.v2i32.f.v2f32(<2 x float>)
|
||||
each_device("real_size_attachment_loops", |name, _, device| {
|
||||
let (reads, looped) = {
|
||||
let core = device.core();
|
||||
- (core.attachment_reads, core.feedback_loop)
|
||||
+ (core.attachment_reads, core.feedback_loop.is_some())
|
||||
};
|
||||
if !reads {
|
||||
println!("real-size: {name}: no attachment reads; the loop cells not run");
|
||||
diff --git a/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs b/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs
|
||||
index a4027e806..2559de92c 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/tests/real_size_renders.rs
|
||||
@@ -1312,7 +1312,7 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a
|
||||
each_device("real_size_two_target_loops", |name, _, device| {
|
||||
let (reads, looped) = {
|
||||
let core = device.core();
|
||||
- (core.attachment_reads, core.feedback_loop)
|
||||
+ (core.attachment_reads, core.feedback_loop.is_some())
|
||||
};
|
||||
if !reads {
|
||||
println!("real-size: {name}: no attachment reads; the two-target cells not run");
|
||||
@@ -1802,7 +1802,7 @@ declare { <4 x float>, i8 } @air.sample_texture_2d.v4f32(ptr addrspace(1), ptr a
|
||||
each_device("real_size_screens", |name, _, device| {
|
||||
let (reads, looped) = {
|
||||
let core = device.core();
|
||||
- (core.attachment_reads, core.feedback_loop)
|
||||
+ (core.attachment_reads, core.feedback_loop.is_some())
|
||||
};
|
||||
if !reads {
|
||||
println!("real-size: {name}: no attachment reads; the screen cells not run");
|
||||
diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs
|
||||
index ef71a2753..a616a8914 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/texture.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/texture.rs
|
||||
@@ -1752,7 +1752,7 @@ impl Device {
|
||||
});
|
||||
let attachment_reads = plan.attachment_reads && !laid_over;
|
||||
// On a device without the feedback loop, a draw reads such an image through its shadow.
|
||||
- let shadowing = (attachment_reads && !core.feedback_loop).then(|| {
|
||||
+ let shadowing = (attachment_reads && core.feedback_loop.is_none()).then(|| {
|
||||
Box::new(Shadowing {
|
||||
made: (d, shape, plan.shadow()),
|
||||
shadow: Mutex::new(None),
|
||||
@@ -2729,7 +2729,7 @@ fn planned(
|
||||
// it has the attachment feedback loop, else through a copy into the image's shadow. The image
|
||||
// takes the sampled usage for it where shaders do not read the texture.
|
||||
let mut attachment_reads = plan.reads_attachments(core);
|
||||
- let looped = attachment_reads && core.feedback_loop;
|
||||
+ let looped = attachment_reads && core.feedback_loop.is_some();
|
||||
let mut image_usage = plan.usage;
|
||||
if attachment_reads {
|
||||
image_usage |= vk::ImageUsageFlags::SAMPLED;
|
||||
@@ -6525,7 +6525,7 @@ impl Device {
|
||||
Ok(crate::surface::PlanePlan {
|
||||
format: plan.format,
|
||||
usage: plan.linear_usage(),
|
||||
- looped: plan.reads_attachments(self.core()) && self.core().feedback_loop,
|
||||
+ looped: plan.reads_attachments(self.core()) && self.core().feedback_loop.is_some(),
|
||||
view_formats: plan.view_formats.clone(),
|
||||
texel,
|
||||
})
|
||||
@@ -0,0 +1,378 @@
|
||||
diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs
|
||||
index 810b53918..986f44a70 100644
|
||||
--- a/crates/metal2vulkan-runtime/src/pipeline.rs
|
||||
+++ b/crates/metal2vulkan-runtime/src/pipeline.rs
|
||||
@@ -858,9 +858,8 @@ pub(crate) enum Place {
|
||||
|
||||
/// The word a buffer slot's [`FieldValue::BufferAddress`] parameter holds for `address`: the
|
||||
/// address less 2^31, as the translator's identity domains read a buffer slot's `SlotGuestBase`
|
||||
-/// (`docs/API.md`, section 5). A module adds an access's 32-bit byte offset plus 2^31 to the word,
|
||||
-/// zero-extended, which is the address plus the offset read as signed, and adds 2^31 back where it
|
||||
-/// reads the address itself.
|
||||
+/// (`docs/API.md`, section 5). A module restores the address with an explicit carry and adds
|
||||
+/// the access's sign-extended byte displacement.
|
||||
pub(crate) fn address_word(address: u64) -> u64 {
|
||||
address.wrapping_sub(1 << 31)
|
||||
}
|
||||
diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs
|
||||
index d5cbd7424..91c8efb77 100644
|
||||
--- a/crates/metal2vulkan/src/cache/mod.rs
|
||||
+++ b/crates/metal2vulkan/src/cache/mod.rs
|
||||
@@ -60,7 +60,7 @@ mod tests;
|
||||
/// unchanged version, and its bless records the version. Independent of the crate's version and of
|
||||
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
|
||||
/// history.
|
||||
-pub const SEMANTICS_VERSION: u32 = 2308;
|
||||
+pub const SEMANTICS_VERSION: u32 = 2309;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
diff --git a/crates/metal2vulkan/src/lower/access/emit.rs b/crates/metal2vulkan/src/lower/access/emit.rs
|
||||
index 16c49e4bf..02e30c8d9 100644
|
||||
--- a/crates/metal2vulkan/src/lower/access/emit.rs
|
||||
+++ b/crates/metal2vulkan/src/lower/access/emit.rs
|
||||
@@ -338,21 +338,13 @@ fn prepare_access(
|
||||
let lowering = cx.plan.families.access.slots.get(t.slot).copied().flatten();
|
||||
let ops = WordOps::of(crate::lower::sync::memory_model::coherence(cx.plan));
|
||||
if let Some(SlotLowering::Psb { start }) = lowering {
|
||||
- // Under the identity domains a slot whose address the binder holds to an alignment is
|
||||
- // reached from that address as it is (its biased word), a leaf at an offset proven a
|
||||
- // multiple of 8 or 16 accessed at that alignment up to the address's; any other from the
|
||||
- // word below each access.
|
||||
+ // Aligned slots keep their aligned leaf loads. Other slots use the word below the access.
|
||||
let aligned = cx.plan.families.access.aligned.get(&t.slot).copied();
|
||||
let a = if cx.plan.families.access.identity {
|
||||
+ let address = super::pointer::slot_address(cx, fb, choice.slot)?;
|
||||
match aligned {
|
||||
- Some(held) => {
|
||||
- let base = super::pointer::biased_slot_address(cx, fb, choice.slot)?;
|
||||
- psb::prepare_direct(base, m, held)
|
||||
- }
|
||||
- None => {
|
||||
- let address = super::pointer::slot_address(cx, fb, choice.slot)?;
|
||||
- psb::prepare_at(fb, address, m)?
|
||||
- }
|
||||
+ Some(held) => psb::prepare_direct(address, m, held),
|
||||
+ None => psb::prepare_at(fb, address, m)?,
|
||||
}
|
||||
} else {
|
||||
let table = cx.push_field(fb, PushField::RootTableAddress)?;
|
||||
diff --git a/crates/metal2vulkan/src/lower/access/mod.rs b/crates/metal2vulkan/src/lower/access/mod.rs
|
||||
index 47fac1863..34ce24166 100644
|
||||
--- a/crates/metal2vulkan/src/lower/access/mod.rs
|
||||
+++ b/crates/metal2vulkan/src/lower/access/mod.rs
|
||||
@@ -1127,10 +1127,8 @@ fn address_field(slot: SlotRef) -> PushField {
|
||||
}
|
||||
|
||||
/// The bias of a buffer slot's `SlotGuestBase` word under the identity domains, 2^31: the runtime
|
||||
-/// pushes the slot's address less it. An access adds its 32-bit byte offset plus the bias to the
|
||||
-/// word, zero-extended ([`psb::prepare_direct`]), which is the address plus the offset read as
|
||||
-/// signed in one 32-bit add, and every other read of the word adds the bias back
|
||||
-/// ([`pointer::slot_address`]).
|
||||
+/// pushes the slot's address less it. The translator adds the bias back with carry across
|
||||
+/// two words before using the address ([`pointer::slot_address`]).
|
||||
pub(crate) const SLOT_ADDRESS_BIAS: u64 = 1 << 31;
|
||||
|
||||
/// Whether profile `p` takes the identity domains, where a pointer is a device address used
|
||||
diff --git a/crates/metal2vulkan/src/lower/access/pointer.rs b/crates/metal2vulkan/src/lower/access/pointer.rs
|
||||
index c2cf85d17..9cfced155 100644
|
||||
--- a/crates/metal2vulkan/src/lower/access/pointer.rs
|
||||
+++ b/crates/metal2vulkan/src/lower/access/pointer.rs
|
||||
@@ -754,16 +754,26 @@ fn guest_base(
|
||||
if !words {
|
||||
return Ok(Address::U64(slot_address(cx, fb, slot)?));
|
||||
}
|
||||
- let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
- let word = wide::split(fb, v)?;
|
||||
+ let word = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
+ Ok(Address::Words(slot_address_words(cx, fb, word)?))
|
||||
+}
|
||||
+
|
||||
+/// Recover the two address words from a slot's push value. An explicit carry keeps the bias from
|
||||
+/// becoming a signed 32-bit offset to a physical storage buffer access.
|
||||
+fn slot_address_words(
|
||||
+ cx: &EmitCx<'_>,
|
||||
+ fb: &mut FunctionBuilder<'_>,
|
||||
+ value: SValue,
|
||||
+) -> BResult<Pair> {
|
||||
+ let word = wide::split(fb, value)?;
|
||||
if !biased(cx) {
|
||||
- return Ok(Address::Words(word));
|
||||
+ return Ok(word);
|
||||
}
|
||||
let bias = Pair {
|
||||
lo: k32(fb, super::SLOT_ADDRESS_BIAS as u32)?,
|
||||
hi: k32(fb, 0)?,
|
||||
};
|
||||
- Ok(Address::Words(wide::add(fb, word, bias)?))
|
||||
+ wide::add(fb, word, bias)
|
||||
}
|
||||
|
||||
/// Whether buffer slots' `SlotGuestBase` words are their Metal addresses less
|
||||
@@ -773,48 +783,24 @@ fn biased(cx: &EmitCx<'_>) -> bool {
|
||||
cx.plan.families.access.identity && !cx.plan.families.access.replay
|
||||
}
|
||||
|
||||
-/// Buffer slot `slot`'s `SlotGuestBase` word (a `uvec2`, low word first) as a `u64` (needs
|
||||
-/// `shaderInt64`).
|
||||
-fn slot_word(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, slot: SlotRef) -> BResult<SValue> {
|
||||
- let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
- let u64_ = fb.module().ty(SType::Int {
|
||||
- width: 64,
|
||||
- signed: false,
|
||||
- })?;
|
||||
- fb.convert(ConvOp::Bitcast, v, u64_)
|
||||
-}
|
||||
-
|
||||
-/// Buffer slot `slot`'s Metal address, the bound buffer's `gpuAddress` plus the bind offset, as a
|
||||
-/// `u64` (needs `shaderInt64`): its `SlotGuestBase` word, plus
|
||||
-/// [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS) where the word is biased ([`biased`]). What a
|
||||
-/// pointer compare, a converted or stored pointer, and an access from the word below it read.
|
||||
+/// Buffer slot's Metal address, the bound buffer's device address plus the bind offset.
|
||||
pub(super) fn slot_address(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
slot: SlotRef,
|
||||
) -> BResult<SValue> {
|
||||
- let word = slot_word(cx, fb, slot)?;
|
||||
- if !biased(cx) {
|
||||
- return Ok(word);
|
||||
- }
|
||||
- let bias = k64(fb, super::SLOT_ADDRESS_BIAS)?;
|
||||
- fb.binary(BinOp::IAdd, word, bias)
|
||||
-}
|
||||
-
|
||||
-/// Buffer slot `slot`'s Metal address less [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS), a
|
||||
-/// `u64`: its `SlotGuestBase` word where the word is biased ([`biased`]), the base an access
|
||||
-/// reached from the slot's own address adds its biased offset to (`psb::prepare_direct`).
|
||||
-pub(super) fn biased_slot_address(
|
||||
- cx: &mut EmitCx<'_>,
|
||||
- fb: &mut FunctionBuilder<'_>,
|
||||
- slot: SlotRef,
|
||||
-) -> BResult<SValue> {
|
||||
- let word = slot_word(cx, fb, slot)?;
|
||||
- if biased(cx) {
|
||||
- return Ok(word);
|
||||
- }
|
||||
- let bias = k64(fb, super::SLOT_ADDRESS_BIAS)?;
|
||||
- fb.binary(BinOp::ISub, word, bias)
|
||||
+ let word = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
+ let address = if biased(cx) {
|
||||
+ let words = slot_address_words(cx, fb, word)?;
|
||||
+ wide::join(fb, wide::wide_form(64, 1), words)?
|
||||
+ } else {
|
||||
+ word
|
||||
+ };
|
||||
+ let u64_ = fb.module().ty(SType::Int {
|
||||
+ width: 64,
|
||||
+ signed: false,
|
||||
+ })?;
|
||||
+ fb.convert(ConvOp::Bitcast, address, u64_)
|
||||
}
|
||||
|
||||
/// The start of the 2³² bytes a pointer into plan slot `slot` whose offset range the analysis
|
||||
diff --git a/crates/metal2vulkan/src/lower/access/psb.rs b/crates/metal2vulkan/src/lower/access/psb.rs
|
||||
index 41927edb8..b09b0c354 100644
|
||||
--- a/crates/metal2vulkan/src/lower/access/psb.rs
|
||||
+++ b/crates/metal2vulkan/src/lower/access/psb.rs
|
||||
@@ -42,7 +42,6 @@
|
||||
//! below its argument's alignment, `LoweringInputs::word_bound_buffers`), and any other rounds
|
||||
//! down to a multiple of 4.
|
||||
|
||||
-use super::SLOT_ADDRESS_BIAS;
|
||||
use crate::device::DeviceProfile;
|
||||
use crate::memory::leaf::{k32, u32_op, Units, WordMem, WordOps};
|
||||
use crate::spirv::builder::FunctionBuilder;
|
||||
@@ -196,19 +195,9 @@ enum Reach {
|
||||
/// making no buffer longer than 2 GiB (`metal2vulkan_runtime::MAX_BUFFER_LENGTH`), so the product is
|
||||
/// exact, and no 64-bit shift or multiply scales an index.
|
||||
Below,
|
||||
- /// From a slot's own device address under the identity domains ([`prepare_direct`]), held
|
||||
- /// as that address less [`SLOT_ADDRESS_BIAS`] (2^31): each unit at that base plus its 32-bit
|
||||
- /// byte offset plus 2^31, modulo 2^32, zero-extended, in 64-bit integers, then one
|
||||
- /// `OpConvertUToPtr` to the unit's block (`NonWritable` for a load of an unwritten slot).
|
||||
- /// Every byte of a buffer lies within 2^31 bytes of each bind address in it, the runtime
|
||||
- /// making no buffer longer than 2 GiB (`metal2vulkan_runtime::MAX_BUFFER_LENGTH`), so the offset
|
||||
- /// read as signed is in `[-2^31, 2^31)`, the biased one is that offset plus 2^31 exactly, and
|
||||
- /// the sum is the address plus the offset. A unit index `x + c` with a constant `c` folds
|
||||
- /// `c`'s bytes into the bias: `(x + c) * s + 2^31` is `x * s + (c * s + 2^31)` modulo 2^32.
|
||||
- /// The bias is one 32-bit add, which a device fuses with the index's shift; the offset is
|
||||
- /// zero-extended, which a device splits into a scalar base and a vector offset; no shift of
|
||||
- /// the offset in 64 bits and no pointer bitcast. It holds the alignment the binder holds the
|
||||
- /// slot's address to (`RuntimeFact::AddressAlignment`).
|
||||
+ /// From an aligned slot's own device address under the identity domains. Add the 32-bit
|
||||
+ /// byte displacement as a signed value in 64 bits. Each valid access is within 2 GiB of
|
||||
+ /// the bind address, so the displacement fits on either side of it.
|
||||
Direct(u32),
|
||||
}
|
||||
|
||||
@@ -235,14 +224,8 @@ pub fn prepare_at(fb: &mut FunctionBuilder<'_>, address: Value, m: Value) -> BRe
|
||||
})
|
||||
}
|
||||
|
||||
-/// Prepare an access of a static slot at the `u32` displacement `m` from its bind offset, under
|
||||
-/// the identity domains, from `base` (a `u64`), the slot's own device address less
|
||||
-/// [`SLOT_ADDRESS_BIAS`], an address the binder holds to a multiple of `held`
|
||||
-/// (`RuntimeFact::AddressAlignment`): the access is the byte offset `m`, read as signed, from that
|
||||
-/// address, as a descriptor view's is `m` from its base ([`Reach::Direct`]). Every byte of a
|
||||
-/// buffer lies within 2^31 bytes of each bind address in it, the runtime making no buffer longer
|
||||
-/// than 2 GiB (`metal2vulkan_runtime::MAX_BUFFER_LENGTH`), so the offset is exact whatever the slot's
|
||||
-/// window. Nothing is rounded. The check, where the access takes one, is `emit::prepare`'s.
|
||||
+/// Prepare an access from the slot's own device address at displacement m. The binder holds
|
||||
+/// the address to alignment held, so leaves can keep their alignment without rounding the base.
|
||||
pub fn prepare_direct(base: Value, m: Value, held: u32) -> PsbAccess {
|
||||
PsbAccess {
|
||||
mem: PsbMem {
|
||||
@@ -394,15 +377,10 @@ impl PsbMem {
|
||||
self.place(fb, addr, ty, load)
|
||||
}
|
||||
Reach::Direct(_) => {
|
||||
- let shift = bytes.trailing_zeros();
|
||||
- let (x, c) = fb.sum_of(index).unwrap_or((index, 0));
|
||||
- let s = k32(fb, shift)?;
|
||||
- let at = u32_op(fb, BinOp::ShiftLeftLogical, x, s)?;
|
||||
- let bias = (c << shift).wrapping_add(SLOT_ADDRESS_BIAS as u32);
|
||||
- let bias = k32(fb, bias)?;
|
||||
- let at = u32_op(fb, BinOp::IAdd, at, bias)?;
|
||||
+ let shift = k32(fb, bytes.trailing_zeros())?;
|
||||
+ let at = u32_op(fb, BinOp::ShiftLeftLogical, index, shift)?;
|
||||
let u64_ = u64_ty(fb)?;
|
||||
- let d = fb.convert(ConvOp::UConvert, at, u64_)?;
|
||||
+ let d = fb.convert(ConvOp::SConvert, at, u64_)?;
|
||||
let addr = fb.binary(BinOp::IAdd, self.base, d)?;
|
||||
self.place(fb, addr, ty, load)
|
||||
}
|
||||
@@ -491,12 +469,10 @@ impl PsbMem {
|
||||
(u32_op(fb, BinOp::BitwiseAnd, off, mask)?, 4)
|
||||
}
|
||||
};
|
||||
- let (x, c) = fb.sum_of(off).unwrap_or((off, 0));
|
||||
- let bias = c.wrapping_add(at).wrapping_add(SLOT_ADDRESS_BIAS as u32);
|
||||
- let bias = k32(fb, bias)?;
|
||||
- let biased = u32_op(fb, BinOp::IAdd, x, bias)?;
|
||||
+ let at = k32(fb, at)?;
|
||||
+ let offset = u32_op(fb, BinOp::IAdd, off, at)?;
|
||||
let u64_ = u64_ty(fb)?;
|
||||
- let d = fb.convert(ConvOp::UConvert, biased, u64_)?;
|
||||
+ let d = fb.convert(ConvOp::SConvert, offset, u64_)?;
|
||||
let addr = fb.binary(BinOp::IAdd, self.base, d)?;
|
||||
Ok((self.place(fb, addr, pointee, load)?, align))
|
||||
}
|
||||
diff --git a/crates/metal2vulkan/src/memory/leaf.rs b/crates/metal2vulkan/src/memory/leaf.rs
|
||||
index 180f2118a..a55e75ecc 100644
|
||||
--- a/crates/metal2vulkan/src/memory/leaf.rs
|
||||
+++ b/crates/metal2vulkan/src/memory/leaf.rs
|
||||
@@ -683,14 +683,6 @@ pub fn u32_op(fb: &mut FunctionBuilder<'_>, op: BinOp, a: Value, b: Value) -> BR
|
||||
(BinOp::IMul, Some(1), _) | (BinOp::BitwiseAnd, Some(u32::MAX), _) => Ok(b),
|
||||
(BinOp::IMul | BinOp::BitwiseAnd, Some(0), _)
|
||||
| (BinOp::IMul | BinOp::BitwiseAnd, _, Some(0)) => k32(fb, 0),
|
||||
- // A sum of a value and a constant is noted, for a consumer that folds the constant
|
||||
- // (`psb`'s biased offsets).
|
||||
- (BinOp::IAdd, None, Some(c)) | (BinOp::IAdd, Some(c), None) => {
|
||||
- let x = if y.is_some() { a } else { b };
|
||||
- let r = fb.binary(op, a, b)?;
|
||||
- fb.note_sum(r, x, c);
|
||||
- Ok(r)
|
||||
- }
|
||||
_ => fb.binary(op, a, b),
|
||||
}
|
||||
}
|
||||
diff --git a/crates/metal2vulkan/src/spirv/builder/function.rs b/crates/metal2vulkan/src/spirv/builder/function.rs
|
||||
index 1707e1094..4d03f302a 100644
|
||||
--- a/crates/metal2vulkan/src/spirv/builder/function.rs
|
||||
+++ b/crates/metal2vulkan/src/spirv/builder/function.rs
|
||||
@@ -177,16 +177,6 @@ impl<'m> FunctionBuilder<'m> {
|
||||
self.m.lanes.get(&y).copied()
|
||||
}
|
||||
|
||||
- /// Note that `y`, a 32-bit unsigned integer, is `x + c` modulo 2^32: `x` dominates `y`.
|
||||
- pub fn note_sum(&mut self, y: Value, x: Value, c: u32) {
|
||||
- self.m.sums.insert(y, (x, c));
|
||||
- }
|
||||
-
|
||||
- /// The value and constant `y` was noted to add.
|
||||
- pub fn sum_of(&self, y: Value) -> Option<(Value, u32)> {
|
||||
- self.m.sums.get(&y).copied()
|
||||
- }
|
||||
-
|
||||
/// Note that `y`, a 32-bit unsigned integer, is the zero extension of 16-bit integer `of`:
|
||||
/// `of` dominates `y`.
|
||||
pub fn note_widened16(&mut self, y: Value, of: Value) {
|
||||
diff --git a/crates/metal2vulkan/src/spirv/builder/module.rs b/crates/metal2vulkan/src/spirv/builder/module.rs
|
||||
index c5b252ce5..4709996e6 100644
|
||||
--- a/crates/metal2vulkan/src/spirv/builder/module.rs
|
||||
+++ b/crates/metal2vulkan/src/spirv/builder/module.rs
|
||||
@@ -118,9 +118,6 @@ pub struct ModuleBuilder {
|
||||
/// The heap bytes of [`ModuleBuilder::vector_parts`]' part lists, for
|
||||
/// [`ModuleBuilder::footprint`].
|
||||
pub(super) vector_part_bytes: usize,
|
||||
- /// The value and constant each 32-bit unsigned sum of a value and a constant the lowering
|
||||
- /// noted adds (`FunctionBuilder::note_sum`). Nothing here changes the IR.
|
||||
- pub(super) sums: HashMap<Value, (Value, u32)>,
|
||||
/// How each struct the builder made holds its members, and what each extract from a struct
|
||||
/// reads (`FunctionBuilder::member_source`): every `OpCompositeConstruct` and
|
||||
/// `OpCompositeInsert` of a struct type and every `OpCompositeExtract` from one, by result.
|
||||
@@ -334,7 +331,6 @@ impl ModuleBuilder {
|
||||
+ map_bytes(&self.inserts)
|
||||
+ map_bytes(&self.vector_parts)
|
||||
+ self.vector_part_bytes
|
||||
- + map_bytes(&self.sums)
|
||||
+ map_bytes(&self.structs)
|
||||
+ self.struct_bytes
|
||||
+ map_bytes(&self.widened16)
|
||||
diff --git a/crates/metal2vulkan/src/tests/engine_identity.rs b/crates/metal2vulkan/src/tests/engine_identity.rs
|
||||
index af70dfd31..05a80706a 100644
|
||||
--- a/crates/metal2vulkan/src/tests/engine_identity.rs
|
||||
+++ b/crates/metal2vulkan/src/tests/engine_identity.rs
|
||||
@@ -286,6 +286,20 @@ fn a_buffer_kernel_reads_each_slot_at_its_pushed_device_address() {
|
||||
assert!(a.interface.descriptors.is_empty(), "{stem}");
|
||||
assert!(!a.interface.needs_pointer_translation, "{stem}");
|
||||
assert_eq!(plan.push.argument_table_size, 0, "{stem}");
|
||||
+ // The push value for each of these slots crosses a 32-bit word boundary when unbiassed.
|
||||
+ // Restore that carry before handing the address to the memory operation.
|
||||
+ let words = &a.module.words;
|
||||
+ let mut at_word = 5;
|
||||
+ let mut carries = 0;
|
||||
+ while at_word < words.len() {
|
||||
+ let header = words[at_word];
|
||||
+ carries += usize::from(header & 0xffff == crate::spv::Op::IAddCarry as u32);
|
||||
+ at_word += (header >> 16) as usize;
|
||||
+ }
|
||||
+ assert!(
|
||||
+ carries >= at.len(),
|
||||
+ "{stem}: expected a carry for each pushed slot"
|
||||
+ );
|
||||
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}"));
|
||||
let mut push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)];
|
||||
let mut read = Vec::new();
|
||||
@@ -349,8 +363,8 @@ fn a_buffer_kernel_reads_each_slot_at_its_pushed_device_address() {
|
||||
|
||||
/// A slot pointer used as a value under the identity domains is its Metal address, though the
|
||||
/// runtime pushes each buffer slot's address less 2^31 (`lower::access::SLOT_ADDRESS_BIAS`): two
|
||||
-/// address compares add the bias back, and the loads beside them, one 4 bytes below its slot's
|
||||
-/// bind address, add their offsets plus the bias to the word. The two slots lie on either side of
|
||||
+/// address compares restore the address, and the loads beside them add signed displacements,
|
||||
+/// including one 4 bytes below its slot's bind address. The two slots lie on either side of
|
||||
/// 2^31, so their words lie on either side of 0 and a compare of the words would answer the other
|
||||
/// way.
|
||||
#[test]
|
||||
diff --git a/docs/API.md b/docs/API.md
|
||||
index 726741b97..4ee8b6e7f 100644
|
||||
--- a/docs/API.md
|
||||
+++ b/docs/API.md
|
||||
@@ -1148,11 +1148,10 @@ for dependency in &pipeline.dependencies {
|
||||
- Under the identity domains (section 1) a buffer slot's `PushField::SlotGuestBase` is its
|
||||
address, the bound buffer's `gpuAddress` plus the bind offset (or the address of its
|
||||
`setBytes` copy, or of the consumer's nil buffer where nothing is bound), less 2^31, modulo
|
||||
- 2^64. An access through the slot adds its 32-bit byte offset plus 2^31, modulo 2^32,
|
||||
- zero-extended, to that word; a pointer compare, a pulled vertex fetch and an access from the
|
||||
- word below it add the 2^31 back to read the address itself, and so does a slot pointer
|
||||
- converted to an integer or stored, which is the slot's address plus its offset. A runtime
|
||||
- writes the word so. A pointer loaded from memory (an argument buffer's pointer member, a `gpuAddress` the
|
||||
+ 2^64. The translator restores the address using separate low and high words with carry.
|
||||
+ Loads and stores through the slot add a signed 32-bit byte displacement to the restored
|
||||
+ 64-bit address. Pointer comparisons and conversions also use the restored address. A runtime
|
||||
+ writes the biased word. A pointer loaded from memory (an argument buffer's pointer member, a `gpuAddress` the
|
||||
program stored) and a pointer made from an integer are the device address the word holds,
|
||||
unbiased and used directly, unchecked: there is no root table, no `PushField::RootTableAddress`
|
||||
and no search. A texture's or sampler's `SlotGuestBase` is its `gpuResourceID`, unbiased. A
|
||||
@@ -6,3 +6,5 @@
|
||||
# scripts/pack-runtime.ps1 both read this file; add or retire patches here.
|
||||
reims-util reims-util-parallel-offline-download.patch
|
||||
metal2vulkan metal2vulkan-snapshot-replay.patch
|
||||
metal2vulkan metal2vulkan-psb-address-carry.patch
|
||||
metal2vulkan metal2vulkan-dynamic-attachment-feedback.patch
|
||||
Reference in new issue
Block a user