Send a dropped store through a descriptor view to a sink binding, not around a branch
The steps this packet landed as, in order: - Select the sink's place only where the store needs no word atomic, and re-bless - Account for the sink's descriptor in the tests it moved, and read coherence through the selection - Set the two variable-pointer features through their Vulkan 1.1 members - Name the two variable-pointer members in validation's feature table - Flatten the one-entry by-name copy and write the runtime-sources pin - Re-pin the runtime sources onto the twin-resolve landing Content: the tree of `development` at 55117cdfe4, unchanged.
This commit is contained in:
1 parent
939e9d6e4a
commit
ca74ea24d4
36 files changed
+2691
-1964
No files matched your search
@@ -679,6 +679,8 @@ members! {
|
||||
V11.v11.multiview_tessellation_shader => MultiviewTessellationShader;
|
||||
V11.v11.multiview_geometry_shader => MultiviewGeometryShader;
|
||||
V11.v11.shader_draw_parameters => ShaderDrawParameters;
|
||||
V11.v11.variable_pointers_storage_buffer => VariablePointersStorageBuffer;
|
||||
V11.v11.variable_pointers => VariablePointers;
|
||||
V12.v12.sampler_mirror_clamp_to_edge => SamplerMirrorClampToEdge;
|
||||
V12.v12.storage_buffer8_bit_access => StorageBuffer8BitAccess;
|
||||
V12.v12.uniform_and_storage_buffer8_bit_access => UniformAndStorageBuffer8BitAccess;
|
||||
|
||||
@@ -1 +1 @@
|
||||
b9ec504178b3e663fdfc87e95b731a42cc727f0fa62677d3c2a269afd8a0adab
|
||||
0c62fe8e65cc3e8fdd73dfdebce81af3f6b621e0d82e6e62fe7f5415e582fd5e
|
||||
@@ -987,8 +987,8 @@ members! {
|
||||
V11.v11.multiview_tessellation_shader => Some(F::MultiviewTessellationShader);
|
||||
V11.v11.multiview_geometry_shader => Some(F::MultiviewGeometryShader);
|
||||
V11.v11.shader_draw_parameters => Some(F::ShaderDrawParameters);
|
||||
V11.v11.variable_pointers => None;
|
||||
V11.v11.variable_pointers_storage_buffer => None;
|
||||
V11.v11.variable_pointers => Some(F::VariablePointers);
|
||||
V11.v11.variable_pointers_storage_buffer => Some(F::VariablePointersStorageBuffer);
|
||||
V12.v12.sampler_mirror_clamp_to_edge => Some(F::SamplerMirrorClampToEdge);
|
||||
V12.v12.storage_buffer8_bit_access => Some(F::StorageBuffer8BitAccess);
|
||||
V12.v12.uniform_and_storage_buffer8_bit_access => Some(F::UniformAndStorageBuffer8BitAccess);
|
||||
@@ -1498,19 +1498,16 @@ pub(super) fn old_engine_list(supported: &FeatureChain, available: &Available) -
|
||||
F::ShaderBufferFloat32AtomicAdd,
|
||||
F::ShaderSharedFloat32AtomicAdd,
|
||||
F::FragmentShaderBarycentric,
|
||||
F::VariablePointers,
|
||||
F::VariablePointersStorageBuffer,
|
||||
] {
|
||||
let member = member_of(feature).expect("every listed feature has a member");
|
||||
enables.copy(member, supported, available);
|
||||
}
|
||||
// The members the engine's vocabulary does not name.
|
||||
for (structure, name) in [
|
||||
(Structure::V11, "variable_pointers"),
|
||||
(Structure::V11, "variable_pointers_storage_buffer"),
|
||||
(Structure::FloatControls2, "shader_float_controls2"),
|
||||
] {
|
||||
let member = named_member(structure, name).expect("every named member is listed");
|
||||
enables.copy(member, supported, available);
|
||||
}
|
||||
// The one member the engine's vocabulary does not name.
|
||||
let float_controls2 = named_member(Structure::FloatControls2, "shader_float_controls2")
|
||||
.expect("every named member is listed");
|
||||
enables.copy(float_controls2, supported, available);
|
||||
let maintenance5 = MEMBERS
|
||||
.iter()
|
||||
.find(|member| member.structure == Structure::Maintenance5)
|
||||
|
||||
@@ -66,15 +66,15 @@ nvidia-rtx5080-laptop device Stated c8bdee9689caa4fc8c0e5bd525c089416a60aed4a58c
|
||||
nvidia-rtx5080-laptop device RobustnessOff cf4765df3884aa08bd2c576c003d0c549144a518892b197a35df6cfdba244b05 members=147 extensions=49
|
||||
nvidia-rtx5080-laptop restricted Stated 6b224fcba4061574e20c2789b315744afa6bf880ddfe62b9819259d1139850f1 members=150 extensions=30
|
||||
nvidia-rtx5080-laptop restricted RobustnessOff 4b488d6d9841041989f8c9c459fde95ec3dc572b639121bd3bf2889ae8c98b56 members=146 extensions=30
|
||||
roadmap-2022 device Stated ea14a46708f56d5478ab06ec0852c15420809b3e7d942a028f6d6289a46e12fd members=42 extensions=1
|
||||
roadmap-2022 device RobustnessOff bea5bd603a66d567ab6f940ab92a878cf3d449d44d4ca8e300ef41956271b1cb members=41 extensions=1
|
||||
roadmap-2022 restricted Stated dc3f83af671640f6f93547f5e595a81efd20e15be8b01b66847fddba2db1332c members=51 extensions=1
|
||||
roadmap-2022 restricted RobustnessOff 925a4718def03119e217896f9b730efc07aea5210ae8bb8e273a279fb3edf76e members=49 extensions=1
|
||||
swiftshader device Stated ee8098a6c0135bf4c6b9827ecc4334176f630429d4d8c11efdfb00f6c1b13ce7 members=73 extensions=20
|
||||
swiftshader device RobustnessOff 506e3c6f881e125ddce24cc5cd1ef07c65dd3bbea0116d2829a971b35b10be68 members=71 extensions=20
|
||||
swiftshader restricted Stated c6e1c7e3838d003e49dc102998f772ae31de6c31664d188ad8630b372064f208 members=73 extensions=9
|
||||
swiftshader restricted RobustnessOff 887c7d116e9e4cef6149928ab47f6893ec712777418b726be3a8bd4eef35542e members=71 extensions=9
|
||||
vk12-floor device Stated fb5c005e022756a3ba051f536ddf1dfe414dc19316cca23041ccd7743b623fe2 members=10 extensions=1
|
||||
vk12-floor device RobustnessOff f7b3e7601afe98cc504fb4e8c36acdcb837dab437c4b73c92ad5acbd8773cf58 members=9 extensions=1
|
||||
vk12-floor restricted Stated fb5c005e022756a3ba051f536ddf1dfe414dc19316cca23041ccd7743b623fe2 members=10 extensions=1
|
||||
vk12-floor restricted RobustnessOff f7b3e7601afe98cc504fb4e8c36acdcb837dab437c4b73c92ad5acbd8773cf58 members=9 extensions=1
|
||||
roadmap-2022 device Stated 6d92862ce52af1041c575b22b4bcabc81ff14aec05104bdee6535810f87bb241 members=40 extensions=1
|
||||
roadmap-2022 device RobustnessOff b1324c9fb1652bf62c267fcde10cd5ecfb9389e09acd812920dd59b488b1d13f members=39 extensions=1
|
||||
roadmap-2022 restricted Stated d3d60341a45ff668278734cd8c0aa79d91e0e04c746a60c097bfe7fc493d15f1 members=49 extensions=1
|
||||
roadmap-2022 restricted RobustnessOff 76784124fdb6b289f014eb5dccf87dd1654bdadb909f4acbdfb283569c1b8c74 members=47 extensions=1
|
||||
swiftshader device Stated 11f057590610b52eacea248e2d9bbf0c558b9e06d069c49a6c27dbd03204882c members=71 extensions=20
|
||||
swiftshader device RobustnessOff f64bdea20e8ef7de0700595ca2d7738336f91e894ffb13c7d94f03c5f2397949 members=69 extensions=20
|
||||
swiftshader restricted Stated 77947281b5a00d6599516a76f13cf06a8f865e71892acdc770f0816a40272872 members=71 extensions=9
|
||||
swiftshader restricted RobustnessOff 13f1633c7bd77b4acb3299f2cf8df8e6374d7694736b0824f32a8828b1cd6031 members=69 extensions=9
|
||||
vk12-floor device Stated f4bf6239d75cea1165dad6f4bdcc3114ff5e9d34d08c6e19d566ae7559b4452b members=8 extensions=1
|
||||
vk12-floor device RobustnessOff eae5e8e1b1b6d72303ce4d86e8daf58725f9e30cf82c39b40c5b23e8da2f4803 members=7 extensions=1
|
||||
vk12-floor restricted Stated f4bf6239d75cea1165dad6f4bdcc3114ff5e9d34d08c6e19d566ae7559b4452b members=8 extensions=1
|
||||
vk12-floor restricted RobustnessOff eae5e8e1b1b6d72303ce4d86e8daf58725f9e30cf82c39b40c5b23e8da2f4803 members=7 extensions=1
|
||||
@@ -174,6 +174,8 @@ fn the_old_engine_list_is_unchanged() {
|
||||
F::ShaderBufferFloat32AtomicAdd,
|
||||
F::ShaderSharedFloat32AtomicAdd,
|
||||
F::FragmentShaderBarycentric,
|
||||
F::VariablePointers,
|
||||
F::VariablePointersStorageBuffer,
|
||||
// The portability subset's structure is chained with what the device supports, as
|
||||
// it always was; the vocabulary names these members, the next three since ARTIFACT 180,
|
||||
// and `imageViewFormatSwizzle` since ARTIFACT 203.
|
||||
|
||||
@@ -613,6 +613,8 @@ feature_sources! { c, x;
|
||||
BufferDeviceAddress => on(c.v12.buffer_device_address);
|
||||
ScalarBlockLayout => on(c.v12.scalar_block_layout);
|
||||
UniformBufferStandardLayout => on(c.v12.uniform_buffer_standard_layout);
|
||||
VariablePointersStorageBuffer => on(c.v11.variable_pointers_storage_buffer);
|
||||
VariablePointers => on(c.v11.variable_pointers);
|
||||
VulkanMemoryModel => on(c.v12.vulkan_memory_model);
|
||||
VulkanMemoryModelDeviceScope => on(c.v12.vulkan_memory_model_device_scope);
|
||||
WorkgroupMemoryExplicitLayout => on(c.explicit_layout.workgroup_memory_explicit_layout);
|
||||
|
||||
@@ -2174,6 +2174,11 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result<Bindin
|
||||
}
|
||||
// The command buffer's status, on a device that does not address buffers.
|
||||
SyntheticBinding::ExecutionStatus => WriteSource::ExecutionStatus,
|
||||
// The stage's write-only store sink, which a dropped store through a
|
||||
// descriptor view lands in (`lower::access::sink`). No shader reads it.
|
||||
SyntheticBinding::StoreSink => WriteSource::Neutral(NeutralResource::Sink {
|
||||
min_bytes: NeutralResource::SINK_BYTES,
|
||||
}),
|
||||
other => return Err(internal(format!("a render binding {other:?}"))),
|
||||
},
|
||||
BindingSource::Heap(_) | BindingSource::HeapSampler { .. } => {
|
||||
|
||||
@@ -613,6 +613,11 @@ fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result<Bindi
|
||||
SyntheticBinding::Imageblock => WriteSource::Imageblock,
|
||||
// The command buffer's status, on a device that does not address buffers.
|
||||
SyntheticBinding::ExecutionStatus => WriteSource::ExecutionStatus,
|
||||
// The stage's write-only store sink, which a dropped store through a
|
||||
// descriptor view lands in (`lower::access::sink`). No shader reads it.
|
||||
SyntheticBinding::StoreSink => WriteSource::Neutral(NeutralResource::Sink {
|
||||
min_bytes: NeutralResource::SINK_BYTES,
|
||||
}),
|
||||
other => return Err(internal(format!("a compute binding {other:?}"))),
|
||||
},
|
||||
BindingSource::Texture(slot) => {
|
||||
|
||||
+2
@@ -797,6 +797,7 @@ codec_enum! {
|
||||
ColorWriteTable,
|
||||
DepthStandIn,
|
||||
StencilStandIn,
|
||||
StoreSink,
|
||||
}
|
||||
ResourceKind {
|
||||
Buffer, Texture, Sampler, Heap(f0), Synthetic(f0), InputAttachment(f0),
|
||||
@@ -877,6 +878,7 @@ codec_enum! {
|
||||
ShaderSharedFloat32AtomicMinMax, ShaderImageFloat32Atomics, ShaderImageFloat32AtomicAdd,
|
||||
ShaderImageFloat32AtomicMinMax, BufferDeviceAddress, ScalarBlockLayout,
|
||||
UniformBufferStandardLayout, VulkanMemoryModel, VulkanMemoryModelDeviceScope,
|
||||
VariablePointersStorageBuffer, VariablePointers,
|
||||
WorkgroupMemoryExplicitLayout, WorkgroupMemoryExplicitLayout8BitAccess,
|
||||
WorkgroupMemoryExplicitLayout16BitAccess, ShaderZeroInitializeWorkgroupMemory,
|
||||
VertexPipelineStoresAndAtomics, FragmentStoresAndAtomics, ShaderDrawParameters,
|
||||
|
||||
Vendored
+3
-3
@@ -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 = 1858;
|
||||
pub const SEMANTICS_VERSION: u32 = 1859;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
@@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 1858;
|
||||
/// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag
|
||||
/// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that
|
||||
/// bumps it says what changed; this comment keeps no history.
|
||||
pub const ARTIFACT_FORMAT_VERSION: u32 = 449;
|
||||
pub const ARTIFACT_FORMAT_VERSION: u32 = 450;
|
||||
|
||||
/// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding
|
||||
/// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle
|
||||
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 449;
|
||||
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
|
||||
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
|
||||
/// keeps no history.
|
||||
pub const RUNTIME_VERSION: u32 = 1621;
|
||||
pub const RUNTIME_VERSION: u32 = 1623;
|
||||
|
||||
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
|
||||
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
|
||||
|
||||
@@ -212,7 +212,7 @@ exposures! {
|
||||
Core(v(1)) => [
|
||||
StorageBuffer16BitAccess, UniformAndStorageBuffer16BitAccess, StoragePushConstant16,
|
||||
StorageInputOutput16, Multiview, ShaderDrawParameters, MultiviewTessellationShader,
|
||||
MultiviewGeometryShader,
|
||||
MultiviewGeometryShader, VariablePointersStorageBuffer, VariablePointers,
|
||||
];
|
||||
// `VkPhysicalDeviceVulkan12Features`.
|
||||
Core(v(2)) => [
|
||||
@@ -501,6 +501,11 @@ pub const FEATURE_NEEDS: &[(VkFeature, VkFeature, &str)] = &[
|
||||
VkFeature::Multiview,
|
||||
"VUID-VkPhysicalDeviceMultiviewFeatures-multiviewGeometryShader-00580",
|
||||
),
|
||||
(
|
||||
VkFeature::VariablePointers,
|
||||
VkFeature::VariablePointersStorageBuffer,
|
||||
"VUID-VkPhysicalDeviceVariablePointersFeatures-variablePointers-01431",
|
||||
),
|
||||
];
|
||||
|
||||
/// The update-after-bind features of buffer descriptor types, which a device whose
|
||||
|
||||
@@ -1137,6 +1137,12 @@ fn feature_route(structure: &str) -> Option<Route> {
|
||||
| "VkPhysicalDeviceScalarBlockLayoutFeaturesEXT" => {
|
||||
Ext(&["VK_EXT_scalar_block_layout"], Some(2))
|
||||
}
|
||||
"VkPhysicalDeviceVariablePointersFeatures"
|
||||
| "VkPhysicalDeviceVariablePointersFeaturesKHR"
|
||||
| "VkPhysicalDeviceVariablePointerFeatures"
|
||||
| "VkPhysicalDeviceVariablePointerFeaturesKHR" => {
|
||||
Ext(&["VK_KHR_variable_pointers"], Some(1))
|
||||
}
|
||||
"VkPhysicalDeviceUniformBufferStandardLayoutFeatures"
|
||||
| "VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR" => {
|
||||
Ext(&["VK_KHR_uniform_buffer_standard_layout"], Some(2))
|
||||
@@ -1356,6 +1362,11 @@ pub(super) const FEATURE_MEMBERS: &[(&str, VkFeature)] = {
|
||||
"uniformBufferStandardLayout",
|
||||
F::UniformBufferStandardLayout,
|
||||
),
|
||||
(
|
||||
"variablePointersStorageBuffer",
|
||||
F::VariablePointersStorageBuffer,
|
||||
),
|
||||
("variablePointers", F::VariablePointers),
|
||||
("vulkanMemoryModel", F::VulkanMemoryModel),
|
||||
(
|
||||
"vulkanMemoryModelDeviceScope",
|
||||
|
||||
@@ -59,6 +59,16 @@ pub enum VkFeature {
|
||||
UniformBufferStandardLayout,
|
||||
VulkanMemoryModel,
|
||||
VulkanMemoryModelDeviceScope,
|
||||
/// `variablePointersStorageBuffer` (Vulkan 1.1, or `VK_KHR_variable_pointers`): a
|
||||
/// `StorageBuffer` pointer an instruction selects rather than an access chain alone, which
|
||||
/// Vulkan also requires enabled beside [`VkFeature::VariablePointers`].
|
||||
VariablePointersStorageBuffer,
|
||||
/// `variablePointers` (Vulkan 1.1, or `VK_KHR_variable_pointers`): such a pointer whose arms
|
||||
/// point into **two** memory objects, which the narrower feature's capability refuses
|
||||
/// ("Variable pointers must point into the same structure"). It is what sends a dropped store
|
||||
/// through a slot's descriptor view to the stage's write-only sink with no branch
|
||||
/// (`lower::access::sink`).
|
||||
VariablePointers,
|
||||
WorkgroupMemoryExplicitLayout,
|
||||
WorkgroupMemoryExplicitLayout8BitAccess,
|
||||
WorkgroupMemoryExplicitLayout16BitAccess,
|
||||
|
||||
@@ -424,6 +424,8 @@ fn with_enabled_refuses_sets_breaking_a_co_enable_rule() {
|
||||
VkFeature::RobustBufferAccess2,
|
||||
VkFeature::MultiviewTessellationShader,
|
||||
VkFeature::MultiviewGeometryShader,
|
||||
VkFeature::VariablePointers,
|
||||
VkFeature::VariablePointersStorageBuffer,
|
||||
],
|
||||
);
|
||||
d.features.extend(BUFFER_UPDATE_AFTER_BIND.iter().copied());
|
||||
|
||||
@@ -121,7 +121,7 @@ use crate::spirv::ir::{
|
||||
Type as SType, UnOp,
|
||||
};
|
||||
|
||||
use super::emit::{prepare, Mem, Prepared, ViewMem};
|
||||
use super::emit::{prepare, Mem, Prepared};
|
||||
use super::local::{self, LocalAccess, LocalPtr};
|
||||
use super::{not_lowered, refuse, static_roots, view_kind, AccessPlan, BufferReach, Target};
|
||||
use crate::error::LowerFamily;
|
||||
@@ -1109,9 +1109,7 @@ fn on_target(fb: &mut FunctionBuilder<'_>, p: Prepared, o: Op) -> BResult<Option
|
||||
let two = k32(fb, 2)?;
|
||||
let word = fb.binary(BinOp::ShiftRightLogical, p.off, two)?;
|
||||
let ptr = match (p.mem, o.typed) {
|
||||
(Mem::View(ViewMem(view, ..)), None) => {
|
||||
views::word_ptr(fb, view, word)?.ok_or_else(dangling)?
|
||||
}
|
||||
(Mem::View(m), None) => views::word_ptr(fb, m.view(), word)?.ok_or_else(dangling)?,
|
||||
(Mem::Psb(m), typed) => {
|
||||
let pointee = match typed {
|
||||
Some(t) => t,
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::memory::blob::BlobUse;
|
||||
use crate::memory::contain::{self, Check};
|
||||
use crate::memory::leaf::{self, k32, Leaf, WordOps};
|
||||
use crate::memory::leaf::{self, k32, Leaf};
|
||||
use crate::memory::plan::{ConstGlobalForm, MemoryPlan};
|
||||
use crate::memory::provenance::{Repr, RootSetId};
|
||||
use crate::memory::views;
|
||||
@@ -312,7 +312,7 @@ pub fn load_view(
|
||||
checked: bool,
|
||||
) -> BResult<SValue> {
|
||||
// The blob is read-only: its words are the same on every load, which stay plain.
|
||||
let mut mem = ViewMem(view, WordOps::default(), views::UnitViews::NONE);
|
||||
let mut mem = ViewMem::plain(view);
|
||||
if !checked {
|
||||
return leaf::load(fb, &mut mem, leaf, off);
|
||||
}
|
||||
|
||||
@@ -536,9 +536,10 @@ fn static_access(
|
||||
if write && super::view_kind(cx.profile, plan) != super::ViewKind::Storage {
|
||||
return Err(cx.invariant("a pointer store through a uniform view"));
|
||||
}
|
||||
cx.push.insert(PushField::SlotBindOffset(plan.slot));
|
||||
let slot = plan.slot;
|
||||
cx.push.insert(PushField::SlotBindOffset(slot));
|
||||
if write {
|
||||
super::request_dropped_store_word(cx, plan.slot);
|
||||
super::request_dropped_store_word(cx, t.slot, slot);
|
||||
}
|
||||
}
|
||||
Ok(Access {
|
||||
|
||||
@@ -27,24 +27,105 @@ use super::{
|
||||
/// slot's narrow views hold the leaf's units; a 16-byte aligned leaf is one `uvec4` where the slot
|
||||
/// has that view.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(super) struct ViewMem(pub(super) View, pub(super) WordOps, pub(super) UnitViews);
|
||||
pub(super) struct ViewMem {
|
||||
view: View,
|
||||
ops: WordOps,
|
||||
units: UnitViews,
|
||||
/// The condition under which a store lands at the view's own place: `None` for a store that
|
||||
/// always lands there and for every load. Where it is given, every store selects its place
|
||||
/// between the view's and the stage's write-only sink, so no store branches
|
||||
/// ([`store_one`], `super::sink`).
|
||||
at_own: Option<SValue>,
|
||||
/// The stage's write-only sink, where it binds one (`super::sink::declare`).
|
||||
sink: Option<super::sink::SinkViews>,
|
||||
}
|
||||
|
||||
impl ViewMem {
|
||||
/// The memory of `view`, with plain accesses and no unit view: the constant blob's
|
||||
/// ([`super::blob`]), which nothing stores to.
|
||||
pub(super) fn plain(view: View) -> ViewMem {
|
||||
ViewMem {
|
||||
view,
|
||||
ops: WordOps::default(),
|
||||
units: UnitViews::NONE,
|
||||
at_own: None,
|
||||
sink: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The memory of slot view `view` with unit views `units` and the stage's sink `sink`.
|
||||
pub(super) fn of(
|
||||
view: View,
|
||||
units: UnitViews,
|
||||
sink: Option<super::sink::SinkViews>,
|
||||
) -> ViewMem {
|
||||
ViewMem {
|
||||
view,
|
||||
ops: WordOps::default(),
|
||||
units,
|
||||
at_own: None,
|
||||
sink,
|
||||
}
|
||||
}
|
||||
|
||||
/// The same memory, loaded and stored with `ops`.
|
||||
fn with_ops(self, ops: WordOps) -> ViewMem {
|
||||
ViewMem { ops, ..self }
|
||||
}
|
||||
|
||||
/// The same memory, every store of it landing at its own place only where `at_own` holds and
|
||||
/// in the stage's sink otherwise. `None` where the form has no sink to select against, which
|
||||
/// leaves the condition to [`store_one`]'s branch.
|
||||
fn dropping(self, at_own: SValue) -> Option<ViewMem> {
|
||||
self.sink.map(|_| ViewMem {
|
||||
at_own: Some(at_own),
|
||||
..self
|
||||
})
|
||||
}
|
||||
|
||||
/// The slot's word view.
|
||||
pub(super) fn view(&self) -> View {
|
||||
self.view
|
||||
}
|
||||
|
||||
/// The narrow view of `bytes`-byte units: present whenever [`WordMem::units`] says so.
|
||||
fn narrow(&self, bytes: u32) -> BResult<views::NarrowView> {
|
||||
self.2.of(bytes).ok_or(self.missing())
|
||||
self.units.of(bytes).ok_or(self.missing())
|
||||
}
|
||||
|
||||
/// The `uvec4` view: present whenever [`WordMem::units`] says so.
|
||||
fn vec4(&self) -> BResult<views::Vec4View> {
|
||||
self.2.vec4.ok_or(self.missing())
|
||||
self.units.vec4.ok_or(self.missing())
|
||||
}
|
||||
|
||||
fn missing(&self) -> crate::spirv::error::BuildError {
|
||||
crate::spirv::error::BuildError::Dangling(crate::spirv::error::Dangling::Global(
|
||||
self.0.global,
|
||||
self.view.global,
|
||||
))
|
||||
}
|
||||
|
||||
/// The place a store lands at: `own`, or, under [`ViewMem::at_own`]'s negation, the sink's
|
||||
/// place `sink_of` gives for the same unit, selected between the two pointers (one `OpSelect`
|
||||
/// of `StorageBuffer` pointers, `VariablePointersStorageBuffer`). Every dropped store lands at
|
||||
/// unit 0 of the sink, which holds a whole leaf.
|
||||
fn store_place(
|
||||
&self,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
own: SValue,
|
||||
sink_of: impl FnOnce(
|
||||
&mut FunctionBuilder<'_>,
|
||||
super::sink::SinkViews,
|
||||
SValue,
|
||||
) -> BResult<SValue>,
|
||||
) -> BResult<SValue> {
|
||||
let Some(at_own) = self.at_own else {
|
||||
return Ok(own);
|
||||
};
|
||||
let sink = self.sink.ok_or(self.missing())?;
|
||||
let zero = k32(fb, 0)?;
|
||||
let at_sink = sink_of(fb, sink, zero)?;
|
||||
fb.select(at_own, own, at_sink)
|
||||
}
|
||||
}
|
||||
|
||||
impl WordMem for ViewMem {
|
||||
@@ -53,7 +134,7 @@ impl WordMem for ViewMem {
|
||||
// A uniform view's read-only vectors are read plainly, as its words are.
|
||||
let access = match view.class {
|
||||
crate::spirv::ir::StorageClass::Uniform => MemAccess::default(),
|
||||
_ => self.1.access(fb, MemAccess::default(), false)?,
|
||||
_ => self.ops.access(fb, MemAccess::default(), false)?,
|
||||
};
|
||||
views::read_vec4(fb, view, index, access)
|
||||
}
|
||||
@@ -65,12 +146,17 @@ impl WordMem for ViewMem {
|
||||
value: SValue,
|
||||
) -> BResult<()> {
|
||||
let view = self.vec4()?;
|
||||
let access = self.1.access(fb, MemAccess::default(), true)?;
|
||||
views::write_vec4(fb, view, index, value, access)
|
||||
let access = self.ops.access(fb, MemAccess::default(), true)?;
|
||||
let own = views::vec4_ptr(fb, view, index)?;
|
||||
let p = self.store_place(fb, own, |fb, sink, zero| {
|
||||
let view = sink.units.vec4.ok_or(missing(sink.view))?;
|
||||
views::vec4_ptr(fb, view, zero)
|
||||
})?;
|
||||
fb.store(p, value, access)
|
||||
}
|
||||
|
||||
fn units(&self) -> Units {
|
||||
self.2.units()
|
||||
self.units.units()
|
||||
}
|
||||
|
||||
fn read_unit(
|
||||
@@ -80,7 +166,7 @@ impl WordMem for ViewMem {
|
||||
index: SValue,
|
||||
) -> BResult<SValue> {
|
||||
let view = self.narrow(bytes)?;
|
||||
let access = self.1.access(fb, MemAccess::default(), false)?;
|
||||
let access = self.ops.access(fb, MemAccess::default(), false)?;
|
||||
views::read_unit(fb, view, index, access)
|
||||
}
|
||||
|
||||
@@ -92,22 +178,27 @@ impl WordMem for ViewMem {
|
||||
value: SValue,
|
||||
) -> BResult<()> {
|
||||
let view = self.narrow(bytes)?;
|
||||
let access = self.1.access(fb, MemAccess::default(), true)?;
|
||||
views::write_unit(fb, view, index, value, access)
|
||||
let access = self.ops.access(fb, MemAccess::default(), true)?;
|
||||
let own = views::unit_ptr(fb, view, index)?;
|
||||
let p = self.store_place(fb, own, |fb, sink, zero| {
|
||||
let view = sink.units.of(bytes).ok_or(missing(sink.view))?;
|
||||
views::unit_ptr(fb, view, zero)
|
||||
})?;
|
||||
views::write_unit(fb, view, p, value, access)
|
||||
}
|
||||
|
||||
fn read(&mut self, fb: &mut FunctionBuilder<'_>, word: SValue) -> BResult<SValue> {
|
||||
if self.1 == WordOps::default() || self.0.kind != ViewKind::Storage {
|
||||
return views::read_word(fb, self.0, word);
|
||||
if self.ops == WordOps::default() || self.view.kind != ViewKind::Storage {
|
||||
return views::read_word(fb, self.view, word);
|
||||
}
|
||||
let p = storage_ptr(fb, self.0, word)?;
|
||||
let access = self.1.access(fb, MemAccess::default(), false)?;
|
||||
let p = storage_ptr(fb, self.view, word)?;
|
||||
let access = self.ops.access(fb, MemAccess::default(), false)?;
|
||||
fb.load(p, access)
|
||||
}
|
||||
|
||||
fn write(&mut self, fb: &mut FunctionBuilder<'_>, word: SValue, value: SValue) -> BResult<()> {
|
||||
let p = storage_ptr(fb, self.0, word)?;
|
||||
let access = self.1.access(fb, MemAccess::default(), true)?;
|
||||
let p = self.store_word_place(fb, word)?;
|
||||
let access = self.ops.access(fb, MemAccess::default(), true)?;
|
||||
fb.store(p, value, access)
|
||||
}
|
||||
|
||||
@@ -118,7 +209,7 @@ impl WordMem for ViewMem {
|
||||
mask: SValue,
|
||||
bits: SValue,
|
||||
) -> BResult<()> {
|
||||
let p = storage_ptr(fb, self.0, word)?;
|
||||
let p = self.store_word_place(fb, word)?;
|
||||
let keep = fb.unary(UnOp::Not, mask)?;
|
||||
let clear = fb.binary(BinOp::BitwiseOr, keep, bits)?;
|
||||
fb.atomic(AtomicOp::And, p, Scope::Device, Semantics::RELAXED, clear)?;
|
||||
@@ -127,6 +218,20 @@ impl WordMem for ViewMem {
|
||||
}
|
||||
}
|
||||
|
||||
/// A missing view of `view`'s binding: an internal invariant failure (the stage's sink declares
|
||||
/// the unit views of every slot whose dropped stores reach it, `super::sink`).
|
||||
fn missing(view: View) -> crate::spirv::error::BuildError {
|
||||
crate::spirv::error::BuildError::Dangling(crate::spirv::error::Dangling::Global(view.global))
|
||||
}
|
||||
|
||||
impl ViewMem {
|
||||
/// The place a word store lands at ([`ViewMem::store_place`] over the word views).
|
||||
fn store_word_place(&self, fb: &mut FunctionBuilder<'_>, word: SValue) -> BResult<SValue> {
|
||||
let own = storage_ptr(fb, self.view, word)?;
|
||||
self.store_place(fb, own, |fb, sink, zero| storage_ptr(fb, sink.view, zero))
|
||||
}
|
||||
}
|
||||
|
||||
/// A word pointer of a storage view. Stores through a uniform view are refused by selection, so a
|
||||
/// missing pointer is an internal invariant failure.
|
||||
fn storage_ptr(fb: &mut FunctionBuilder<'_>, view: View, word: SValue) -> BResult<SValue> {
|
||||
@@ -149,7 +254,7 @@ impl Mem {
|
||||
/// The same memory, loaded and stored with `ops`.
|
||||
pub(super) fn with(self, ops: WordOps) -> Mem {
|
||||
match self {
|
||||
Mem::View(ViewMem(view, _, units)) => Mem::View(ViewMem(view, ops, units)),
|
||||
Mem::View(m) => Mem::View(ViewMem { ops, ..m }),
|
||||
Mem::Psb(m) => Mem::Psb(m.with(ops)),
|
||||
}
|
||||
}
|
||||
@@ -357,8 +462,9 @@ pub(super) fn prepare(
|
||||
.get(t.slot)
|
||||
.copied()
|
||||
.unwrap_or(UnitViews::NONE);
|
||||
let sink = cx.decl.families.access.store_sink;
|
||||
Ok(Prepared {
|
||||
mem: Mem::View(ViewMem(view, ops, units)),
|
||||
mem: Mem::View(ViewMem::of(view, units, sink).with_ops(ops)),
|
||||
off,
|
||||
inb,
|
||||
guard_store,
|
||||
@@ -382,11 +488,15 @@ fn load_one(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, p: Prepared) -> BResult<S
|
||||
/// Store `v` as `leaf` at `p`, contained and only where the slot's memory keeps the GPU's writes
|
||||
/// ([`Prepared::writable`]). Returns whether the store merges a partial word ([`leaf::store`]).
|
||||
///
|
||||
/// A condition left here is one the form could not fold into an address selection, so the store
|
||||
/// sits in `if_`. That branch is not free of meaning: a value a guarded store alone consumes is
|
||||
/// written inside the branch, and Apple's backend expands `air.fast_asinh.f32` and
|
||||
/// `air.fast_acosh.f32` to different last bits depending on the basic block their call sits in. The
|
||||
/// device-address form leaves nothing here ([`Prepared::writable`]).
|
||||
/// A condition left here is one `prepare` could not fold into an address selection: the
|
||||
/// device-address form leaves none ([`Prepared::writable`], `psb::prepare`). Where the stage binds
|
||||
/// its write-only sink, the store runs unconditionally at a place selected between the view's own
|
||||
/// and the sink's (`super::sink`); only where it binds none does the store sit in `if_`.
|
||||
///
|
||||
/// That branch is not free of meaning: a value a guarded store alone consumes is written inside
|
||||
/// the branch, and Apple's backend expands `air.fast_asinh.f32` and `air.fast_acosh.f32` to
|
||||
/// different last bits depending on the basic block their call sits in, so the module records
|
||||
/// `PrecisionNote::GuardedStoreBranch` where it keeps one.
|
||||
fn store_one(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, p: Prepared, v: SValue) -> BResult<bool> {
|
||||
let mut mem = p.mem;
|
||||
let contained = p.guard_store.then_some(p.inb).flatten();
|
||||
@@ -396,20 +506,32 @@ fn store_one(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, p: Prepared, v: SValue)
|
||||
(None, Some(keeps)) => Some(keeps),
|
||||
(None, None) => None,
|
||||
};
|
||||
match guard {
|
||||
Some(guard) => {
|
||||
let leaf = *leaf;
|
||||
let then: ArmFn<'_, bool> = Box::new(move |fb, merged| {
|
||||
let mut mem = p.mem;
|
||||
*merged = leaf::store(fb, &mut mem, &leaf, p.off, v)?;
|
||||
Ok(ArmEnd::FallThrough(Vec::new()))
|
||||
});
|
||||
let mut merged = false;
|
||||
fb.if_(&mut merged, guard, then, None)?;
|
||||
Ok(merged)
|
||||
let Some(guard) = guard else {
|
||||
return leaf::store(fb, &mut mem, leaf, p.off, v);
|
||||
};
|
||||
// The selecting form: no branch, and a dropped or uncontained store lands in the sink, which
|
||||
// no shader reads. The offset is already clamped for containment, so the view's own place is
|
||||
// inside its range whatever the condition says. A store that merges a partial word keeps the
|
||||
// branch: its two word atomics need a place, and an `OpSelect` of two pointers is not one
|
||||
// (SPIRV-Cross writes an atomic's pointer as `&expr`, an lvalue in MSL), so such a store is
|
||||
// still a gap (docs/FAST-PATHS.md, known gaps).
|
||||
if let Mem::View(view) = mem {
|
||||
if !leaf::merges(leaf, view.units()) {
|
||||
if let Some(view) = view.dropping(guard) {
|
||||
let mut mem = Mem::View(view);
|
||||
return leaf::store(fb, &mut mem, leaf, p.off, v);
|
||||
}
|
||||
}
|
||||
None => leaf::store(fb, &mut mem, leaf, p.off, v),
|
||||
}
|
||||
let leaf = *leaf;
|
||||
let then: ArmFn<'_, bool> = Box::new(move |fb, merged| {
|
||||
let mut mem = p.mem;
|
||||
*merged = leaf::store(fb, &mut mem, &leaf, p.off, v)?;
|
||||
Ok(ArmEnd::FallThrough(Vec::new()))
|
||||
});
|
||||
let mut merged = false;
|
||||
fb.if_(&mut merged, guard, then, None)?;
|
||||
Ok(merged)
|
||||
}
|
||||
|
||||
/// Part `i` of fat pointer `p` (0 the root, 1 the offset): a constant pointer's part, known at
|
||||
|
||||
@@ -112,6 +112,7 @@ pub mod pointer;
|
||||
mod psb;
|
||||
pub mod pulled;
|
||||
pub(crate) mod root_sets;
|
||||
pub mod sink;
|
||||
pub mod table;
|
||||
pub mod tile;
|
||||
pub(crate) mod tile_memory;
|
||||
@@ -801,6 +802,14 @@ pub struct AccessPlan {
|
||||
/// (`SyntheticBinding::ExecutionStatus`), one more storage descriptor, on a device that does
|
||||
/// not address buffers, and why ([`absent::StatusBinding`]).
|
||||
pub status_binding: Option<absent::StatusBinding>,
|
||||
/// The memory-plan slot indices a guarded store goes through: a guest buffer slot of the
|
||||
/// stage's argument table with a bit of the draw's or dispatch's `SpecKey::DroppedStoreSlots`
|
||||
/// word ([`request_dropped_store_word`]).
|
||||
pub dropped_store_slots: BTreeSet<usize>,
|
||||
/// The stage binds its write-only store sink (`SyntheticBinding::StoreSink`), one more
|
||||
/// storage descriptor, so a dropped store through a descriptor view selects a pointer into it
|
||||
/// rather than branching ([`sink`]).
|
||||
pub store_sink: Option<sink::SinkPlan>,
|
||||
}
|
||||
|
||||
impl AccessPlan {
|
||||
@@ -856,6 +865,8 @@ pub struct Declared {
|
||||
/// The stage's view of the command buffer's `ExecutionStatus` buffer, where it binds the
|
||||
/// buffer ([`absent::declare`]).
|
||||
pub status: Option<View>,
|
||||
/// The stage's write-only store sink, where it binds one ([`sink::declare`]).
|
||||
pub store_sink: Option<sink::SinkViews>,
|
||||
/// The `RangeAtBindOffset` specialization of each slot read through a uniform view, by
|
||||
/// memory-plan slot index: where it holds, an access reads the view at the Metal offset alone
|
||||
/// ([`range_at_bind_offset`]).
|
||||
@@ -1753,6 +1764,7 @@ pub fn declare(
|
||||
tile: tile::declare(mb, &plan.families.access)?,
|
||||
function_tables: function_table::declare(mb, plan)?,
|
||||
status: absent::declare(mb, plan.stage, &plan.families.access)?,
|
||||
store_sink: sink::declare(mb, plan.stage, &plan.families.access)?,
|
||||
..Declared::default()
|
||||
};
|
||||
for (i, s) in plan.slots.iter().enumerate() {
|
||||
@@ -2015,25 +2027,35 @@ fn place_targets(cx: &mut SelectCx<'_>, targets: &mut [Target], write: bool) ->
|
||||
if write && view_kind(cx.profile, plan) != ViewKind::Storage {
|
||||
return Err(cx.invariant("a write through a uniform view"));
|
||||
}
|
||||
cx.push.insert(PushField::SlotBindOffset(plan.slot));
|
||||
let slot = plan.slot;
|
||||
cx.push.insert(PushField::SlotBindOffset(slot));
|
||||
if write {
|
||||
request_dropped_store_word(cx, plan.slot);
|
||||
request_dropped_store_word(cx, t.slot, slot);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Read the stage's `SpecKey::DroppedStoreSlots` word where a store through `slot` branches on it:
|
||||
/// a guest buffer slot of the stage's argument table, the only slot a caller's memory is bound to
|
||||
/// (`emit::writable` reads the same predicate, so every selection that emits a store through a
|
||||
/// static root asks here). A synthetic binding the runtime owns has no bit of the word and no
|
||||
/// branch.
|
||||
pub(super) fn request_dropped_store_word(cx: &mut SelectCx<'_>, slot: SlotRef) {
|
||||
/// Read the stage's `SpecKey::DroppedStoreSlots` word where a store through `slot`, memory-plan
|
||||
/// slot `at`, is gated on it: a guest buffer slot of the stage's argument table, the only slot a
|
||||
/// caller's memory is bound to (`emit::writable` reads the same predicate, so every selection that
|
||||
/// emits a store through a static root asks here). A synthetic binding the runtime owns has no bit
|
||||
/// of the word and no guard.
|
||||
///
|
||||
/// The slot is recorded in [`AccessPlan::dropped_store_slots`], from which [`sink::finish`] reads
|
||||
/// which of the gated stores go through a descriptor view and so need the stage's write-only sink
|
||||
/// to select a place in, and the sink's descriptor is reserved here so the forms are chosen with
|
||||
/// it ([`sink::reserve`]).
|
||||
pub(super) fn request_dropped_store_word(cx: &mut SelectCx<'_>, at: usize, slot: SlotRef) {
|
||||
if slot.class == SlotClass::Buffer && slot.index < u32::BITS {
|
||||
cx.push
|
||||
.insert(PushField::Specialized(SpecKey::DroppedStoreSlots(
|
||||
slot.stage,
|
||||
)));
|
||||
// Before the first such slot is recorded: the sink's descriptor is counted once, and
|
||||
// ahead of the per-stage descriptor fallbacks that choose the slots' forms.
|
||||
sink::reserve(cx);
|
||||
cx.families.access.dropped_store_slots.insert(at);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -489,12 +489,12 @@ fn store_pointer(
|
||||
if super::view_kind(cx.profile, plan) != super::ViewKind::Storage {
|
||||
return Err(cx.invariant("a pointer store through a uniform view"));
|
||||
}
|
||||
// The store is emitted through `emit::access_at` with a value, so it branches on the
|
||||
// The store is emitted through `emit::access_at` with a value, so it is gated on the
|
||||
// stage's dropped-store word; `access_with_leaf` below is given none and would not ask.
|
||||
slots.push(plan.slot);
|
||||
slots.push((t.slot, plan.slot));
|
||||
}
|
||||
for slot in slots {
|
||||
super::request_dropped_store_word(cx, slot);
|
||||
for (at, slot) in slots {
|
||||
super::request_dropped_store_word(cx, at, slot);
|
||||
}
|
||||
let to = super::access_with_leaf(cx, ptr, None, leaf, targets, null, None)?;
|
||||
let words = !cx.profile.fields().leaf.int64;
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
//! The stage's write-only sink for a dropped store through a buffer slot's descriptor view.
|
||||
//!
|
||||
//! A store through a slot bound to memory whose GPU writes Metal drops is dropped on the slot's
|
||||
//! bit of the draw's or dispatch's `SpecKey::DroppedStoreSlots` word (`emit::writable`). The store
|
||||
//! must not be guarded by a branch: a branch around it moves every value only that store consumes
|
||||
//! into its block, and Apple's backend expands `air.fast_asinh.f32` and `air.fast_acosh.f32` to
|
||||
//! different last bits depending on the basic block their call sits in, so a branching guard
|
||||
//! changes what Metal's fast-math library answers.
|
||||
//!
|
||||
//! A slot reached by its device address needs nothing here: the bit joins the bounds check in the
|
||||
//! one selection of the store's address, which sends the store to the root table's write-only sink
|
||||
//! (`psb::prepare`, `memory::roots::SINK_ROOT`). A slot reached through a **descriptor view** has
|
||||
//! no second buffer of its own storage class to select a pointer against, so the stage binds one:
|
||||
//! [`SyntheticBinding::StoreSink`], a write-only storage buffer of
|
||||
//! [`NeutralResource::SINK_BYTES`](crate::bind::NeutralResource::SINK_BYTES) bytes
|
||||
//! (`WriteSource::Neutral(NeutralResource::Sink { .. })`), **one** storage descriptor of the stage
|
||||
//! however many of its slots store. Every store through a view then runs unconditionally at
|
||||
//! `select(in_bounds && keeps, own_place, sink_place)`, and the module branches for no store.
|
||||
//!
|
||||
//! The descriptor is [`reserve`]d as soon as a store through a buffer slot is selected, before the
|
||||
//! slots' forms are chosen, so the per-stage descriptor fallbacks count it like any other view and
|
||||
//! move slots to their device addresses (or read-only ones to uniform views) to make room for it;
|
||||
//! [`finish`] gives it back where no slot kept a descriptor view in the end.
|
||||
//!
|
||||
//! The selection is a variable pointer: `OpSelect` between two `StorageBuffer` pointers, which
|
||||
//! needs [`VkFeature::VariablePointers`] and the [`VkFeature::VariablePointersStorageBuffer`]
|
||||
//! Vulkan requires beside it ([`selects_pointers`]; Vulkan 1.1, and every committed profile but
|
||||
//! SwiftShader's and the Vulkan 1.2 floor has both). A stage of a device without it keeps the
|
||||
//! branch, which moves no stored value there: the values the branch holds are computed by
|
||||
//! instructions whose results do not depend on the block they sit in, and the one compiler that
|
||||
//! answers otherwise is Apple's, on a device whose `float` functions are Metal's own
|
||||
//! ([`FloatFunctions::Metal`], MoltenVK on an Apple GPU), which has the feature. A device that
|
||||
//! both answers Metal's own functions and cannot select between two descriptors' pointers has no
|
||||
//! exact form, so [`finish`] refuses it, naming the feature.
|
||||
//!
|
||||
//! The sink carries the same **unit views** as the slots whose dropped stores reach it (a `u8`, a
|
||||
//! `u16` and a `uvec4` block at the one binding, `views::UnitViews`), because `OpSelect` needs both
|
||||
//! pointers to have one result type: a dropped store of a narrow or 16-byte unit selects a pointer
|
||||
//! of that unit's own type. They are further module-scope variables at the sink's one binding, not
|
||||
//! further descriptors. The units are those of every access of such a slot, which is a superset of
|
||||
//! what its stores move: a view the stores do not reach is a declaration nothing uses, where a
|
||||
//! missing one would fail the build.
|
||||
//!
|
||||
//! Every dropped store lands at unit 0 of the sink, which is at least 64 bytes and so holds a
|
||||
//! whole leaf; no shader reads it.
|
||||
//!
|
||||
//! The stage binds the sink whenever a gated store goes through a descriptor view, before the
|
||||
//! leaves of those stores are known. A stage whose every such store merges a partial word, and so
|
||||
//! keeps its branch (`leaf::merges`), therefore binds one descriptor it does not read. Deciding
|
||||
//! otherwise would need the leaves here, where only the slots' forms and units are known; the
|
||||
//! cost is one storage descriptor of such a stage.
|
||||
|
||||
use crate::device::profile::{DeviceProfile, FloatFunctions};
|
||||
use crate::device::requirements::VkFeature;
|
||||
use crate::error::{Capability, Error, Feature, Unsupported};
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::memory::leaf::Units;
|
||||
use crate::memory::views::{self, UnitViews, View, ViewKind};
|
||||
use crate::pipeline::sym::{ResourceKind, ResourceSlot, Stage, SyntheticBinding};
|
||||
use crate::spirv::builder::ModuleBuilder;
|
||||
use crate::spirv::error::BResult;
|
||||
|
||||
use super::{AccessPlan, LowerFamily, SlotLowering};
|
||||
|
||||
/// What the stage's dropped stores through a descriptor view need of the sink: the unit views it
|
||||
/// declares beside its word view, so each such store has a place of its own type to select
|
||||
/// against (the module docs).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct SinkPlan {
|
||||
pub units: Units,
|
||||
}
|
||||
|
||||
/// The stage's declared sink: its word view, and the unit views beside it at the one binding.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct SinkViews {
|
||||
pub view: View,
|
||||
pub units: UnitViews,
|
||||
}
|
||||
|
||||
/// The binding symbol of `stage`'s store sink.
|
||||
pub fn symbol(stage: Stage) -> ResourceSlot {
|
||||
ResourceSlot {
|
||||
stage,
|
||||
kind: ResourceKind::Synthetic(SyntheticBinding::StoreSink),
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the device can select between two descriptors' `StorageBuffer` pointers, which is what
|
||||
/// a dropped store through a descriptor view lands in the sink by: `variablePointers`, and the
|
||||
/// `variablePointersStorageBuffer` Vulkan requires beside it. The narrower feature alone is not
|
||||
/// enough -- its capability holds only for arms pointing into one memory object ("Variable
|
||||
/// pointers must point into the same structure") -- and no committed profile has one without the
|
||||
/// other.
|
||||
pub fn selects_pointers(profile: &DeviceProfile) -> bool {
|
||||
let enabled = &profile.fields().enabled.features;
|
||||
enabled.contains(&VkFeature::VariablePointers)
|
||||
&& enabled.contains(&VkFeature::VariablePointersStorageBuffer)
|
||||
}
|
||||
|
||||
/// Count the stage's sink descriptor, once, where the device can select pointers: called as the
|
||||
/// first store through a buffer slot asks for the dropped-store word
|
||||
/// (`super::request_dropped_store_word`), so the per-stage descriptor fallbacks see it before they
|
||||
/// choose the slots' forms. [`finish`] gives it back where the forms left no descriptor view.
|
||||
pub(super) fn reserve(cx: &mut SelectCx<'_>) {
|
||||
if !cx.families.access.dropped_store_slots.is_empty() || !selects_pointers(cx.profile) {
|
||||
return;
|
||||
}
|
||||
cx.descriptors.storage_buffers = cx.descriptors.storage_buffers.saturating_add(1);
|
||||
}
|
||||
|
||||
/// State the stage's sink where a dropped store through a descriptor view needs it, once the
|
||||
/// slots' forms are final (`lower::select`), and give the [`reserve`]d descriptor back where none
|
||||
/// does.
|
||||
///
|
||||
/// A device that cannot select pointers keeps the branch, which moves no stored value there (the
|
||||
/// module docs); one that both keeps the branch and answers Metal's own `float` functions has no
|
||||
/// exact form and is refused, naming the feature it lacks.
|
||||
pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
let access = &cx.families.access;
|
||||
let mut units = Units::NONE;
|
||||
let mut needed = false;
|
||||
for &i in &access.dropped_store_slots {
|
||||
if !matches!(
|
||||
access.slots.get(i).copied().flatten(),
|
||||
Some(SlotLowering::View(_))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
needed = true;
|
||||
units = units.union(access.units.get(&i).copied().unwrap_or(Units::NONE));
|
||||
}
|
||||
let reserved = !access.dropped_store_slots.is_empty() && selects_pointers(cx.profile);
|
||||
if !needed {
|
||||
if reserved {
|
||||
cx.descriptors.storage_buffers = cx.descriptors.storage_buffers.saturating_sub(1);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if !reserved {
|
||||
if cx.profile.fields().float_functions == FloatFunctions::Metal {
|
||||
return Err(Unsupported::needs(
|
||||
Feature::Lowering(LowerFamily::Access),
|
||||
Capability::Feature(VkFeature::VariablePointers),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
cx.families.access.store_sink = Some(SinkPlan { units });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Declare the stage's sink views where it binds one ([`finish`]): a storage word view at its
|
||||
/// binding symbol, and the unit views the plan asks for beside it.
|
||||
pub fn declare(
|
||||
mb: &mut ModuleBuilder,
|
||||
stage: Stage,
|
||||
plan: &AccessPlan,
|
||||
) -> BResult<Option<SinkViews>> {
|
||||
let Some(p) = plan.store_sink else {
|
||||
return Ok(None);
|
||||
};
|
||||
let sym = symbol(stage);
|
||||
let view = views::declare_at(mb, sym, ViewKind::Storage)?;
|
||||
let units = UnitViews::declare_at(mb, sym, view, p.units)?;
|
||||
Ok(Some(SinkViews { view, units }))
|
||||
}
|
||||
@@ -1633,6 +1633,7 @@ fn finish(
|
||||
cx.families.arith.widened = arith::widening::widened_loads(&cx, &sel.strategy, m)?;
|
||||
|
||||
let slots = access::finish_slots(&mut cx, m)?;
|
||||
access::sink::finish(&mut cx)?;
|
||||
access::absent::finish(&mut cx);
|
||||
sync::memory_model::finish_interlock(&mut cx, &slots)?;
|
||||
charge_facts(&cx, fact_bytes, m)?;
|
||||
|
||||
@@ -1209,6 +1209,25 @@ pub fn load(
|
||||
/// the store merges a partial word into `mem` through [`WordMem::write_bits`] (the sub-word
|
||||
/// store). In a buffer slot those are two word atomics, which read the word they modify (the
|
||||
/// Vulkan memory model's "reads"), so the slot's reported access includes a read.
|
||||
/// Whether [`store`] of `leaf` into a memory whose units are `units` merges a partial word, that
|
||||
/// is calls [`WordMem::write_bits`]: the paths below are exactly [`store`]'s, and nothing in them
|
||||
/// depends on a value, so a caller can choose its form before emitting (`access::emit::store_one`
|
||||
/// takes the branching guard for such a store, whose two atomics need a place that an `OpSelect`
|
||||
/// of two pointers is not). Reading it wrong the optimistic way is loud, not silent: the builder
|
||||
/// refuses an atomic whose pointer is not a place.
|
||||
pub fn merges(leaf: &Leaf, units: Units) -> bool {
|
||||
match leaf.path {
|
||||
Path::Vec4 if units.vec4 => false,
|
||||
Path::Vec4 | Path::Aligned => {
|
||||
let partial = (0..leaf.words()).any(|j| leaf.bytes - 4 * j < 4);
|
||||
partial && units.intersect(leaf_units(leaf, true)) != leaf_units(leaf, true)
|
||||
}
|
||||
Path::OneWord => !units.has(leaf.bytes),
|
||||
// Word 0 always takes the shifted bytes through `write_bits`.
|
||||
Path::Bytes => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn store(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
mem: &mut dyn WordMem,
|
||||
|
||||
@@ -103,12 +103,16 @@ fn u32_type(mb: &mut ModuleBuilder) -> BResult<TypeId> {
|
||||
|
||||
/// Declare the view of `slot` (its `Buffer` descriptor binding symbol).
|
||||
pub fn declare(mb: &mut ModuleBuilder, slot: SlotRef, kind: ViewKind) -> BResult<View> {
|
||||
let sym = ResourceSlot {
|
||||
declare_at(mb, buffer_symbol(slot), kind)
|
||||
}
|
||||
|
||||
/// The `Buffer` descriptor binding symbol of `slot`.
|
||||
fn buffer_symbol(slot: SlotRef) -> ResourceSlot {
|
||||
ResourceSlot {
|
||||
stage: slot.stage,
|
||||
kind: ResourceKind::Buffer,
|
||||
index: slot.index,
|
||||
};
|
||||
declare_at(mb, sym, kind)
|
||||
}
|
||||
}
|
||||
|
||||
/// Declare a word view of kind `kind` at binding symbol `sym` (a Metal buffer slot, or a
|
||||
@@ -277,16 +281,28 @@ impl UnitViews {
|
||||
slot: SlotRef,
|
||||
view: View,
|
||||
units: crate::memory::leaf::Units,
|
||||
) -> BResult<UnitViews> {
|
||||
UnitViews::declare_at(mb, buffer_symbol(slot), view, units)
|
||||
}
|
||||
|
||||
/// The same, at binding symbol `sym` (a Metal buffer slot, or a synthetic binding such as the
|
||||
/// dropped-store sink, `lower::access::sink`): every view is another module-scope variable at
|
||||
/// that one binding, so the stage counts one descriptor whatever units it declares.
|
||||
pub fn declare_at(
|
||||
mb: &mut ModuleBuilder,
|
||||
sym: ResourceSlot,
|
||||
view: View,
|
||||
units: crate::memory::leaf::Units,
|
||||
) -> BResult<UnitViews> {
|
||||
let storage = view.kind == ViewKind::Storage;
|
||||
Ok(UnitViews {
|
||||
u16: if storage && units.u16 {
|
||||
Some(declare_narrow(mb, slot, 2)?)
|
||||
Some(declare_narrow(mb, sym, 2)?)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
u8: if storage && units.u8 {
|
||||
Some(declare_narrow(mb, slot, 1)?)
|
||||
Some(declare_narrow(mb, sym, 1)?)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@@ -295,24 +311,20 @@ impl UnitViews {
|
||||
global: view.global,
|
||||
class: StorageClass::Uniform,
|
||||
}),
|
||||
_ if units.vec4 => Some(declare_vec4(mb, slot, view)?),
|
||||
_ if units.vec4 => Some(declare_vec4(mb, sym, view)?),
|
||||
_ => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Declare the `uvec4` view of `slot`, whose word view [`declare`] declared as `view`:
|
||||
/// Declare the `uvec4` view at binding symbol `sym`, whose word view [`declare_at`] declared as
|
||||
/// `view`:
|
||||
/// `StorageBuffer { uvec4[] }` (std430) beside a storage view, or `Uniform { uvec4[words / 4] }`
|
||||
/// (std140, valid without `uniformBufferStandardLayout`) beside a `UniformWords` view, whose size
|
||||
/// is a multiple of 16 bytes ([`uniform_range`]). Both have `ArrayStride` 16, and the serializer
|
||||
/// decorates the storage one `Aliased` as every storage view of a Metal buffer.
|
||||
pub fn declare_vec4(mb: &mut ModuleBuilder, slot: SlotRef, view: View) -> BResult<Vec4View> {
|
||||
let sym = ResourceSlot {
|
||||
stage: slot.stage,
|
||||
kind: ResourceKind::Buffer,
|
||||
index: slot.index,
|
||||
};
|
||||
pub fn declare_vec4(mb: &mut ModuleBuilder, sym: ResourceSlot, view: View) -> BResult<Vec4View> {
|
||||
let u32_ty = u32_type(mb)?;
|
||||
let v4 = mb.ty(Type::Vector {
|
||||
elem: u32_ty,
|
||||
@@ -359,6 +371,13 @@ pub fn declare_vec4(mb: &mut ModuleBuilder, slot: SlotRef, view: View) -> BResul
|
||||
Ok(Vec4View { global, class })
|
||||
}
|
||||
|
||||
/// A pointer to `uvec4` unit `index` of `view`.
|
||||
pub fn vec4_ptr(fb: &mut FunctionBuilder<'_>, view: Vec4View, index: Value) -> BResult<Value> {
|
||||
let base = fb.module().global_value(view.global)?;
|
||||
let zero = k(fb, 0)?;
|
||||
fb.access_chain(base, &[zero, index])
|
||||
}
|
||||
|
||||
/// Load `uvec4` unit `index` of `view` with memory operands `ops`.
|
||||
pub fn read_vec4(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
@@ -366,33 +385,17 @@ pub fn read_vec4(
|
||||
index: Value,
|
||||
ops: MemAccess,
|
||||
) -> BResult<Value> {
|
||||
let base = fb.module().global_value(view.global)?;
|
||||
let zero = k(fb, 0)?;
|
||||
let p = fb.access_chain(base, &[zero, index])?;
|
||||
let p = vec4_ptr(fb, view, index)?;
|
||||
fb.load(p, ops)
|
||||
}
|
||||
|
||||
/// Store the `uvec4` `value` to unit `index` of storage view `view` with memory operands `ops`.
|
||||
pub fn write_vec4(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
view: Vec4View,
|
||||
index: Value,
|
||||
value: Value,
|
||||
ops: MemAccess,
|
||||
) -> BResult<()> {
|
||||
let base = fb.module().global_value(view.global)?;
|
||||
let zero = k(fb, 0)?;
|
||||
let p = fb.access_chain(base, &[zero, index])?;
|
||||
fb.store(p, value, ops)
|
||||
}
|
||||
|
||||
/// Declare the `bytes`-byte (1 or 2) narrow view of `slot`, whose word view [`declare`] declared.
|
||||
pub fn declare_narrow(mb: &mut ModuleBuilder, slot: SlotRef, bytes: u32) -> BResult<NarrowView> {
|
||||
let sym = ResourceSlot {
|
||||
stage: slot.stage,
|
||||
kind: ResourceKind::Buffer,
|
||||
index: slot.index,
|
||||
};
|
||||
/// Declare the `bytes`-byte (1 or 2) narrow view at binding symbol `sym`, whose word view
|
||||
/// [`declare_at`] declared.
|
||||
pub fn declare_narrow(
|
||||
mb: &mut ModuleBuilder,
|
||||
sym: ResourceSlot,
|
||||
bytes: u32,
|
||||
) -> BResult<NarrowView> {
|
||||
let u32_ty = u32_type(mb)?;
|
||||
let width = match bytes {
|
||||
1 => 8,
|
||||
@@ -426,7 +429,7 @@ pub fn declare_narrow(mb: &mut ModuleBuilder, slot: SlotRef, bytes: u32) -> BRes
|
||||
}
|
||||
|
||||
/// A pointer to unit `index` (a `u32` index of `view.bytes`-byte units) of narrow view `view`.
|
||||
fn unit_ptr(fb: &mut FunctionBuilder<'_>, view: NarrowView, index: Value) -> BResult<Value> {
|
||||
pub fn unit_ptr(fb: &mut FunctionBuilder<'_>, view: NarrowView, index: Value) -> BResult<Value> {
|
||||
let base = fb.module().global_value(view.global)?;
|
||||
let zero = k(fb, 0)?;
|
||||
fb.access_chain(base, &[zero, index])
|
||||
@@ -444,17 +447,17 @@ pub fn read_unit(
|
||||
fb.convert(ConvOp::UConvert, x, view.u32_ty)
|
||||
}
|
||||
|
||||
/// Store the low `8 · view.bytes` bits of `value` (a `u32`) to unit `index` of `view` with
|
||||
/// memory operands `ops`.
|
||||
/// Store the low `8 · view.bytes` bits of `value` (a `u32`) to the place `p` of `view`'s units
|
||||
/// ([`unit_ptr`], or a selection between one of these and another view's), with memory operands
|
||||
/// `ops`.
|
||||
pub fn write_unit(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
view: NarrowView,
|
||||
index: Value,
|
||||
p: Value,
|
||||
value: Value,
|
||||
ops: MemAccess,
|
||||
) -> BResult<()> {
|
||||
let x = fb.convert(ConvOp::UConvert, value, view.unit_ty)?;
|
||||
let p = unit_ptr(fb, view, index)?;
|
||||
fb.store(p, x, ops)
|
||||
}
|
||||
|
||||
|
||||
@@ -293,6 +293,16 @@ pub enum SyntheticBinding {
|
||||
/// writes as `WriteSource::ExecutionStatus`. A stage module of a device that addresses buffers
|
||||
/// reaches the buffer by device address ([`PushField::ExecutionStatusAddress`]) instead.
|
||||
ExecutionStatus,
|
||||
/// The write-only sink a dropped store lands in: a storage buffer of
|
||||
/// [`NeutralResource::SINK_BYTES`](crate::bind::NeutralResource::SINK_BYTES) bytes the binder
|
||||
/// binds as `WriteSource::Neutral(NeutralResource::Sink { .. })`, one storage descriptor of a
|
||||
/// stage that stores through a buffer slot's descriptor view
|
||||
/// (`lower::access::sink`). A store the draw's or dispatch's
|
||||
/// [`SpecKey::DroppedStoreSlots`] word drops selects a pointer into it instead of the slot's,
|
||||
/// so the store runs with no branch of its own. No shader reads it. A stage that reaches its
|
||||
/// written slots by device address needs none: the root table's entry 1 is the same sink
|
||||
/// (`memory::roots::SINK_ROOT`).
|
||||
StoreSink,
|
||||
/// The resident root table.
|
||||
RootTable,
|
||||
/// The handle table.
|
||||
|
||||
@@ -278,6 +278,25 @@ pub fn compile_with(
|
||||
)
|
||||
}
|
||||
|
||||
/// [`compile`] with the function constants `consts` supplied: the artifact a pipeline built with
|
||||
/// those values holds.
|
||||
pub fn compile_specialized(
|
||||
bitcode: &[u8],
|
||||
entry: &str,
|
||||
p: &DeviceProfile,
|
||||
consts: &FunctionConstantValues,
|
||||
) -> Result<Arc<FunctionArtifact>, Error> {
|
||||
compile_bitcode(
|
||||
bitcode,
|
||||
EntryRef::Name(entry),
|
||||
consts,
|
||||
p,
|
||||
&LowerInputs::new(),
|
||||
&mut meter(),
|
||||
SPIRV_WORDS,
|
||||
)
|
||||
}
|
||||
|
||||
/// [`compile`], also returning the plan and the finished typed module whose serialization the
|
||||
/// artifact holds (`compile_bitcode_kept`): one compile, so the CPU interpreter runs the module
|
||||
/// whose words `link_and_validate` links and validates, not a second compile of the same source.
|
||||
@@ -637,6 +656,7 @@ pub fn interlocked_coherence(words: &[u32]) -> Result<CoherentAccesses, String>
|
||||
let mut constants: HashMap<u32, u32> = HashMap::new();
|
||||
let mut types: HashMap<u32, u32> = HashMap::new();
|
||||
let mut roots: HashMap<u32, u32> = HashMap::new();
|
||||
let mut selected: HashMap<u32, (u32, u32)> = HashMap::new();
|
||||
let at = |inst: &[u32], i: usize| -> Result<u32, String> {
|
||||
inst.get(i)
|
||||
.copied()
|
||||
@@ -677,11 +697,25 @@ pub fn interlocked_coherence(words: &[u32]) -> Result<CoherentAccesses, String>
|
||||
roots.insert(at(inst, 2)?, r);
|
||||
}
|
||||
}
|
||||
// A selected pointer (a dropped store's place, `lower::access::sink`) has the roots of
|
||||
// both arms: it is coherent only where each one is.
|
||||
Op::Select => {
|
||||
let (a, b) = (at(inst, 4)?, at(inst, 5)?);
|
||||
if roots.contains_key(&a) && roots.contains_key(&b) {
|
||||
selected.insert(at(inst, 2)?, (a, b));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let device_scope = |id: u32| constants.get(&id) == Some(&DEVICE);
|
||||
let decorated = |id: u32| roots.get(&id).is_some_and(|r| coherent.contains(r));
|
||||
let decorated = |id: u32| {
|
||||
let own = |id: u32| roots.get(&id).is_some_and(|r| coherent.contains(r));
|
||||
match selected.get(&id) {
|
||||
Some(&(a, b)) => own(a) && own(b),
|
||||
None => own(id),
|
||||
}
|
||||
};
|
||||
for (op, inst) in &insts {
|
||||
let (ptr, mask_at, load) = match op {
|
||||
Op::Load => (at(inst, 3)?, 4, true),
|
||||
|
||||
@@ -6,8 +6,8 @@ use crate::spirv::builder::ops::{err, Num};
|
||||
use crate::spirv::error::{BResult, OperandRule};
|
||||
use crate::spirv::ids::{TypeId, Value};
|
||||
use crate::spirv::ir::{
|
||||
BinOp, ConstBits, ConstKind, Constant, Contraction, GlslOp, Inst, Shape, Type, UnOp,
|
||||
ValueOrigin,
|
||||
BinOp, ConstBits, ConstKind, Constant, Contraction, GlslOp, Inst, Shape, StorageClass, Type,
|
||||
UnOp, ValueOrigin,
|
||||
};
|
||||
|
||||
impl FunctionBuilder<'_> {
|
||||
@@ -318,16 +318,26 @@ impl FunctionBuilder<'_> {
|
||||
}
|
||||
|
||||
/// `OpSelect`: `cond` is a `bool` or a `bool` vector with the objects' component count; the
|
||||
/// objects share one data type (no opaque value or logical pointer). Result: that type.
|
||||
/// objects share one data type, or one `StorageBuffer` pointer type, which
|
||||
/// `VariablePointersStorageBuffer` allows (no opaque value and no pointer of another logical
|
||||
/// class). Result: that type.
|
||||
pub fn select(&mut self, cond: Value, t: Value, f: Value) -> BResult<Value> {
|
||||
const OP: crate::spv::Op = crate::spv::Op::Select;
|
||||
let c = self.want(OP, 0, cond, Num::is_bool)?;
|
||||
let ty = self.value_ty(t)?;
|
||||
let facts = *self.mb().types().facts(ty)?;
|
||||
if !matches!(
|
||||
let storage_pointer = matches!(
|
||||
self.mb().types().get(ty),
|
||||
Ok(Type::Pointer {
|
||||
class: StorageClass::StorageBuffer,
|
||||
..
|
||||
})
|
||||
);
|
||||
if (!matches!(
|
||||
facts.shape,
|
||||
Shape::Plain | Shape::Implicit | Shape::Explicit
|
||||
) || facts.runtime_sized
|
||||
) && !storage_pointer)
|
||||
|| facts.runtime_sized
|
||||
{
|
||||
return Err(err(OP, OperandRule::Category(1)));
|
||||
}
|
||||
|
||||
@@ -1127,6 +1127,37 @@ fn terminate(p: &Prog<'_>, l: &mut Lane, term: &Terminator) -> IResult<()> {
|
||||
}
|
||||
|
||||
/// See [`super::run`].
|
||||
/// `res` with a zero-filled buffer bound for the stage's write-only store sink
|
||||
/// (`SyntheticBinding::StoreSink`) where the module declares one and the caller bound none: a
|
||||
/// dropped store through a buffer slot's descriptor view lands there
|
||||
/// (`lower::access::sink`), the binder always supplies it from the device's neutral resources
|
||||
/// (`WriteSource::Neutral(NeutralResource::Sink)`), and no shader reads it, so a run that does
|
||||
/// not look at it need not know it exists. A caller that binds its own keeps it, and so reads
|
||||
/// back what the dropped stores wrote (`tests::engine_dropped_stores`).
|
||||
fn with_store_sink(m: &TypedModule, mut res: Resources) -> Resources {
|
||||
use crate::pipeline::sym::{ResourceKind, SyntheticBinding};
|
||||
let sink = m.globals().iter().find_map(|g| match &g.kind {
|
||||
GlobalKind::Resource(slot)
|
||||
if slot.kind == ResourceKind::Synthetic(SyntheticBinding::StoreSink) =>
|
||||
{
|
||||
Some(*slot)
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
let Some(sink) = sink else {
|
||||
return res;
|
||||
};
|
||||
if res.buffers.iter().any(|b| b.slot == Some(sink)) {
|
||||
return res;
|
||||
}
|
||||
res.buffers.push(super::Buffer {
|
||||
slot: Some(sink),
|
||||
address: None,
|
||||
bytes: vec![0; crate::bind::NeutralResource::SINK_BYTES as usize],
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
pub(super) fn run(
|
||||
m: &TypedModule,
|
||||
cfg: &Config,
|
||||
@@ -1141,6 +1172,7 @@ pub(super) fn run(
|
||||
// Kept apart from `res`, whose buffers the run consumes: specialization-length arrays (the
|
||||
// threadgroup arena) are sized by these values for the whole run.
|
||||
let spec = res.spec.clone();
|
||||
let res = with_store_sink(m, res);
|
||||
let p = Prog::new(m, &res, &images, &spec, inputs)?;
|
||||
// A vertex invocation shares no workgroup: each is a workgroup of one (see `super::run`).
|
||||
let local = match model {
|
||||
|
||||
@@ -1040,6 +1040,26 @@ impl Deriver<'_> {
|
||||
indices,
|
||||
non_uniform,
|
||||
} => self.access_chain(*base, indices, *non_uniform)?,
|
||||
// A selection between two pointers is a variable pointer. Only `StorageBuffer` ones
|
||||
// are built (a dropped store's sink, `lower::access::sink`); a
|
||||
// `PhysicalStorageBuffer` pointer is a plain 64-bit value and needs nothing. The
|
||||
// arms point into two descriptors, which the narrower capability does not allow
|
||||
// ("Variable pointers must point into the same structure"), so the full
|
||||
// `VariablePointers` is declared, with the capability it depends on, and both
|
||||
// features: Vulkan enables `variablePointers` only beside
|
||||
// `variablePointersStorageBuffer`.
|
||||
Inst::Select { t: arm, .. } => {
|
||||
if let Type::Pointer {
|
||||
class: StorageClass::StorageBuffer,
|
||||
..
|
||||
} = self.ty(self.value_ty(*arm)?)?
|
||||
{
|
||||
self.cap(Cap::VariablePointersStorageBuffer);
|
||||
self.cap(Cap::VariablePointers);
|
||||
self.feat(VkFeature::VariablePointersStorageBuffer);
|
||||
self.feat(VkFeature::VariablePointers);
|
||||
}
|
||||
}
|
||||
Inst::AtomicLoad { ptr, scope, sem } => {
|
||||
self.scope(*scope);
|
||||
self.semantics(*sem);
|
||||
|
||||
@@ -1359,7 +1359,10 @@ fn the_highest_storage_slots_fall_back_to_device_addresses() {
|
||||
.join(format!("{stem}.json"));
|
||||
let text = std::fs::read_to_string(path).expect("profile");
|
||||
let mut desc = DeviceDescription::from_khronos_json(&text, None).expect("description");
|
||||
desc.limits.max_per_stage_descriptor_storage_buffers = 2;
|
||||
// Three storage slots, and on a device that selects a dropped store's place the stage's
|
||||
// store sink beside them, one descriptor of its own (`lower::access::sink`): the limit
|
||||
// leaves room for all but one, so one slot moves either way.
|
||||
desc.limits.max_per_stage_descriptor_storage_buffers = 2 + u32::from(selects_sink(&desc));
|
||||
let p = Device::new(desc, policy())
|
||||
.expect("device")
|
||||
.profile()
|
||||
@@ -1401,7 +1404,8 @@ fn the_highest_storage_slots_fall_back_to_device_addresses() {
|
||||
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}"));
|
||||
// No robust descriptors, or no read-only slot left to move: the limit is refused.
|
||||
let mut strict = profile_desc(stem);
|
||||
strict.limits.max_per_stage_descriptor_storage_buffers = 2;
|
||||
strict.limits.max_per_stage_descriptor_storage_buffers =
|
||||
2 + u32::from(selects_sink(&strict));
|
||||
strict.features.remove(&VkFeature::RobustBufferAccess);
|
||||
strict.features.remove(&VkFeature::RobustBufferAccess2);
|
||||
let mut written = profile_desc(stem);
|
||||
@@ -1422,6 +1426,12 @@ fn the_highest_storage_slots_fall_back_to_device_addresses() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a stage of the device `desc` describes binds a store sink for a dropped store through
|
||||
/// a descriptor view, which is one storage descriptor of its own (`lower::access::sink`).
|
||||
fn selects_sink(desc: &DeviceDescription) -> bool {
|
||||
desc.has(VkFeature::VariablePointers) && desc.has(VkFeature::VariablePointersStorageBuffer)
|
||||
}
|
||||
|
||||
/// The description of committed profile `stem`.
|
||||
fn profile_desc(stem: &str) -> DeviceDescription {
|
||||
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
@@ -1432,8 +1442,9 @@ fn profile_desc(stem: &str) -> DeviceDescription {
|
||||
}
|
||||
|
||||
/// A kernel with a loop reserves no status binding (its modules carry no execution bound), so the
|
||||
/// descriptor fallback counts the Metal slots alone. With three storage slots and a per-stage limit
|
||||
/// of two, moving one slot brings the storage count to two: the highest slot to a device address
|
||||
/// descriptor fallback counts the Metal slots and the stage's store sink. With three storage slots,
|
||||
/// the sink and a per-stage limit of three, moving one slot brings the storage count to three: the
|
||||
/// highest slot to a device address
|
||||
/// where the profile has them, else (Profile F) the uniform-view fallback moves only the bounded
|
||||
/// params word, and the `Whole` data slot stays a storage descriptor.
|
||||
#[test]
|
||||
@@ -1458,7 +1469,10 @@ fn a_looping_kernel_reserves_no_status_binding_in_the_fallback() {
|
||||
.join(format!("{stem}.json"));
|
||||
let text = std::fs::read_to_string(path).expect("profile");
|
||||
let mut desc = DeviceDescription::from_khronos_json(&text, None).expect("description");
|
||||
desc.limits.max_per_stage_descriptor_storage_buffers = 2;
|
||||
// Three storage slots, and on a device that selects a dropped store's place the stage's
|
||||
// store sink beside them, one descriptor of its own (`lower::access::sink`): the limit
|
||||
// leaves room for all but one, so one slot moves either way.
|
||||
desc.limits.max_per_stage_descriptor_storage_buffers = 2 + u32::from(selects_sink(&desc));
|
||||
let p = Device::new(desc, policy())
|
||||
.expect("device")
|
||||
.profile()
|
||||
|
||||
@@ -12,8 +12,18 @@
|
||||
//! Here the kernel of the owned fixture `engine/fca_kernel_absent_builtin`, whose one store writes
|
||||
//! `out[tid]`, runs on the CPU interpreter with the word clear, with its slot's bit set, and with
|
||||
//! another slot's bit set, on every committed profile. Its slot is a descriptor view, where the
|
||||
//! bit still guards the store with a branch; `tests::engine_dropped_store_sink` runs the same word
|
||||
//! over a slot reached by its device address, where the bit selects the store's address instead.
|
||||
//! bit selects the store's place between the slot's and the stage's write-only sink
|
||||
//! (`SyntheticBinding::StoreSink`, `lower::access::sink`), so the module branches for no store:
|
||||
//! with the bit set the slot keeps its bytes and the sink holds the word, which is the drop
|
||||
//! proved as a redirect and not as a store that went missing.
|
||||
//! `tests::engine_dropped_store_sink` runs the same word over a slot reached by its device
|
||||
//! address, where the bit joins the bounds check in the one address selection instead.
|
||||
//!
|
||||
//! A profile whose device cannot select between two descriptors' pointers
|
||||
//! (`variablePointersStorageBuffer`: SwiftShader's and the Vulkan 1.2 floor among the committed
|
||||
//! ones) binds no sink and keeps the branch, which moves no stored value there; the branch's
|
||||
//! shape is asserted per profile, so neither form can quietly become the other.
|
||||
//!
|
||||
//! `llvm-as` assembles the fixture; without it the tests skip visibly. No GPU is used.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
@@ -25,10 +35,11 @@ use crate::metal::DataType;
|
||||
use crate::pipeline::interface::PushLoc;
|
||||
use crate::pipeline::sym::{Axis, PushField, ResourceKind, ResourceSlot, SpecKey, Stage};
|
||||
use crate::pipeline::testing::{
|
||||
engine_dir, llvm_assemble, profile, typed_module_specialized, AssembleError,
|
||||
compile_specialized, engine_dir, llvm_assemble, profile, typed_module_specialized,
|
||||
AssembleError,
|
||||
};
|
||||
use crate::spirv::interp::{run, Buffer, Config, Order, Resources};
|
||||
use crate::spirv::ir::TypedModule;
|
||||
use crate::spirv::ir::{Inst, Terminator, TypedModule};
|
||||
use crate::spirv::testing::committed_profiles;
|
||||
|
||||
/// The fixture's entry, whose `has_width` constant is on: every thread stores
|
||||
@@ -53,11 +64,25 @@ fn assemble() -> Option<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every word of `out` after one workgroup of [`THREADS`] threads ran `m` (planned as `plan`) with
|
||||
/// the kernel stage's `SpecKey::DroppedStoreSlots` word `dropped`, the buffer filled with
|
||||
/// [`SENTINEL`] first; identical in both scheduling orders. The interpreter writes the word into
|
||||
/// the push bytes of its placed field (`interp::specialized_push`).
|
||||
fn run_kernel(plan: &Plan, m: &TypedModule, dropped: u32) -> Vec<u32> {
|
||||
/// Bytes of the stage's sink, which holds a whole leaf whatever the leaf is
|
||||
/// (`bind::NeutralResource::SINK_BYTES`).
|
||||
const SINK_BYTES: usize = 64;
|
||||
|
||||
fn words(bytes: &[u8]) -> Vec<u32> {
|
||||
bytes
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|w| u32::from_le_bytes([w[0], w[1], w[2], w[3]]))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Every word of `out`, and of the stage's sink where it binds one, after one workgroup of
|
||||
/// [`THREADS`] threads ran `m` (planned as `plan`) with the kernel stage's
|
||||
/// `SpecKey::DroppedStoreSlots` word `dropped`, both filled with [`SENTINEL`] first; identical in
|
||||
/// both scheduling orders. The interpreter writes the word into the push bytes of its placed field
|
||||
/// (`interp::specialized_push`).
|
||||
fn run_kernel(plan: &Plan, m: &TypedModule, dropped: u32) -> (Vec<u32>, Option<Vec<u32>>) {
|
||||
let mut spec = BTreeMap::new();
|
||||
for (axis, v) in [(Axis::X, THREADS), (Axis::Y, 1), (Axis::Z, 1)] {
|
||||
spec.insert(SpecKey::LocalSize(axis), u64::from(v));
|
||||
@@ -67,16 +92,25 @@ fn run_kernel(plan: &Plan, m: &TypedModule, dropped: u32) -> Vec<u32> {
|
||||
SpecKey::DroppedStoreSlots(Stage::Kernel),
|
||||
u64::from(dropped),
|
||||
);
|
||||
let res = Resources {
|
||||
buffers: vec![Buffer {
|
||||
slot: Some(ResourceSlot {
|
||||
stage: Stage::Kernel,
|
||||
kind: ResourceKind::Buffer,
|
||||
index: 0,
|
||||
}),
|
||||
let sink = plan.families.access.store_sink.is_some();
|
||||
let mut buffers = vec![Buffer {
|
||||
slot: Some(ResourceSlot {
|
||||
stage: Stage::Kernel,
|
||||
kind: ResourceKind::Buffer,
|
||||
index: 0,
|
||||
}),
|
||||
address: None,
|
||||
bytes: [SENTINEL; 4 * THREADS as usize].to_vec(),
|
||||
}];
|
||||
if sink {
|
||||
buffers.push(Buffer {
|
||||
slot: Some(crate::lower::access::sink::symbol(Stage::Kernel)),
|
||||
address: None,
|
||||
bytes: [SENTINEL; 4 * THREADS as usize].to_vec(),
|
||||
}],
|
||||
bytes: vec![SENTINEL; SINK_BYTES],
|
||||
});
|
||||
}
|
||||
let res = Resources {
|
||||
buffers,
|
||||
push: vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)],
|
||||
spec,
|
||||
};
|
||||
@@ -90,12 +124,26 @@ fn run_kernel(plan: &Plan, m: &TypedModule, dropped: u32) -> Vec<u32> {
|
||||
outs.push(out.buffers);
|
||||
}
|
||||
assert_eq!(outs[0], outs[1], "scheduling orders disagree");
|
||||
outs[0][0]
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|w| u32::from_le_bytes([w[0], w[1], w[2], w[3]]))
|
||||
.collect()
|
||||
let out = words(&outs[0][0]);
|
||||
let sink = sink.then(|| words(&outs[0][1]));
|
||||
(out, sink)
|
||||
}
|
||||
|
||||
/// The module's conditional branches and selections.
|
||||
fn shape(m: &TypedModule) -> (usize, usize) {
|
||||
let mut branches = 0;
|
||||
let mut selects = 0;
|
||||
for b in m.blocks() {
|
||||
if matches!(b.term, Terminator::CondBranch { .. }) {
|
||||
branches += 1;
|
||||
}
|
||||
selects += b
|
||||
.insts
|
||||
.iter()
|
||||
.filter(|n| matches!(n.inst, Inst::Select { .. }))
|
||||
.count();
|
||||
}
|
||||
(branches, selects)
|
||||
}
|
||||
|
||||
/// The constants of the fixture with `has_width` on, so that the kernel stores
|
||||
@@ -137,8 +185,10 @@ fn a_storing_kernel_reads_the_dropped_store_word() {
|
||||
}
|
||||
|
||||
/// With the slot's bit of the word set, the kernel's store is dropped and the buffer's bytes are
|
||||
/// the ones it held: Metal's drop, and the dispatch runs to its end. With the word clear, or with
|
||||
/// another slot's bit set, the same pipeline stores.
|
||||
/// the ones it held: Metal's drop, and the dispatch runs to its end. Where the stage binds its
|
||||
/// sink, the sink then holds the word the store carried, so the store ran and was redirected
|
||||
/// rather than going missing. With the word clear, or with another slot's bit set, the same
|
||||
/// pipeline stores through the slot and leaves the sink alone.
|
||||
#[test]
|
||||
fn a_dropped_slots_store_leaves_the_bytes_and_the_dispatch_runs() {
|
||||
let Some(bc) = assemble() else {
|
||||
@@ -148,29 +198,187 @@ fn a_dropped_slots_store_leaves_the_bytes_and_the_dispatch_runs() {
|
||||
for (stem, p) in committed_profiles().expect("profiles") {
|
||||
let (plan, m) = typed_module_specialized(&bc, ENTRY, &p, &constants())
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
// No slot's writes dropped: the store lands.
|
||||
let untouched = plan
|
||||
.families
|
||||
.access
|
||||
.store_sink
|
||||
.is_some()
|
||||
.then(|| vec![kept; SINK_BYTES / 4]);
|
||||
// No slot's writes dropped: the store lands and no sink is written.
|
||||
let (out, sink) = run_kernel(&plan, &m, 0);
|
||||
assert_eq!(
|
||||
run_kernel(&plan, &m, 0),
|
||||
[THREADS; THREADS as usize],
|
||||
out, [THREADS; THREADS as usize],
|
||||
"{stem}: the store did not land with the word clear"
|
||||
);
|
||||
// Slot 0's dropped: the store is taken nowhere and every word is as it was.
|
||||
assert_eq!(
|
||||
run_kernel(&plan, &m, 1),
|
||||
[kept; THREADS as usize],
|
||||
sink, untouched,
|
||||
"{stem}: the sink was written with the word clear"
|
||||
);
|
||||
// Slot 0's dropped: every word of the slot is as it was, and the sink holds the word the
|
||||
// store carried.
|
||||
let (out, sink) = run_kernel(&plan, &m, 1);
|
||||
assert_eq!(
|
||||
out, [kept; THREADS as usize],
|
||||
"{stem}: the store reached memory whose writes are dropped"
|
||||
);
|
||||
if let Some(sink) = &sink {
|
||||
assert_eq!(
|
||||
sink[0], THREADS,
|
||||
"{stem}: the dropped store reached no sink"
|
||||
);
|
||||
}
|
||||
// Another slot's bit is another slot's: the store through slot 0 lands.
|
||||
let (out, sink) = run_kernel(&plan, &m, 0b10);
|
||||
assert_eq!(
|
||||
run_kernel(&plan, &m, 0b10),
|
||||
[THREADS; THREADS as usize],
|
||||
out, [THREADS; THREADS as usize],
|
||||
"{stem}: slot 1's bit dropped slot 0's store"
|
||||
);
|
||||
// Every bit of the word, slot 0's among them: still dropped, and nothing else changes.
|
||||
assert_eq!(
|
||||
run_kernel(&plan, &m, u32::MAX),
|
||||
[kept; THREADS as usize],
|
||||
sink, untouched,
|
||||
"{stem}: slot 1's bit sent slot 0's store to the sink"
|
||||
);
|
||||
// Every bit of the word, slot 0's among them: still dropped, and nothing else changes.
|
||||
let (out, sink) = run_kernel(&plan, &m, u32::MAX);
|
||||
assert_eq!(
|
||||
out, [kept; THREADS as usize],
|
||||
"{stem}: a full word let the store through"
|
||||
);
|
||||
if let Some(sink) = &sink {
|
||||
assert_eq!(
|
||||
sink[0], THREADS,
|
||||
"{stem}: the dropped store reached no sink"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The guard's shape, per profile: a device that can select between two descriptors' pointers
|
||||
/// binds the stage's sink (`variablePointers`), and then the kernel's one store runs with no
|
||||
/// conditional branch at all and at least the one selection of its place. A device that cannot
|
||||
/// binds no sink and keeps the branch.
|
||||
///
|
||||
/// This is what separates the fix from a guard that never fires: the words above would also read
|
||||
/// as Metal's if the condition were dropped, and would also read as Metal's if the store sat in a
|
||||
/// branch. One profile of each kind is asserted to exist, so a profile set that lost either kind
|
||||
/// fails here rather than passing vacuously.
|
||||
#[test]
|
||||
fn a_dropped_view_store_selects_its_place_where_the_device_selects_pointers() {
|
||||
let Some(bc) = assemble() else {
|
||||
return;
|
||||
};
|
||||
let mut selecting = 0;
|
||||
let mut branching = 0;
|
||||
for (stem, p) in committed_profiles().expect("profiles") {
|
||||
let (plan, m) = typed_module_specialized(&bc, ENTRY, &p, &constants())
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
let (branches, selects) = shape(&m);
|
||||
let pointers = crate::lower::access::sink::selects_pointers(&p);
|
||||
assert_eq!(
|
||||
plan.families.access.store_sink.is_some(),
|
||||
pointers,
|
||||
"{stem}: the sink does not follow variablePointersStorageBuffer"
|
||||
);
|
||||
if pointers {
|
||||
selecting += 1;
|
||||
assert_eq!(
|
||||
branches, 0,
|
||||
"{stem}: the module branches, so a guarded store moved a value into its block"
|
||||
);
|
||||
assert!(
|
||||
selects >= 1,
|
||||
"{stem}: {selects} selections, too few for the store's place"
|
||||
);
|
||||
// The sink is one storage descriptor of the stage, whatever unit views it holds.
|
||||
let a = compile_specialized(&bc, ENTRY, &p, &constants())
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
let sinks = a
|
||||
.interface
|
||||
.descriptors
|
||||
.iter()
|
||||
.filter(|d| {
|
||||
d.slot.kind
|
||||
== ResourceKind::Synthetic(
|
||||
crate::pipeline::sym::SyntheticBinding::StoreSink,
|
||||
)
|
||||
&& d.ty == crate::vk::DescriptorType::STORAGE_BUFFER
|
||||
})
|
||||
.count();
|
||||
assert_eq!(sinks, 1, "{stem}: {sinks} sink descriptors");
|
||||
} else {
|
||||
branching += 1;
|
||||
assert!(
|
||||
branches >= 1,
|
||||
"{stem}: no branch, but the device cannot select between two descriptors\' \
|
||||
pointers"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
selecting > 0 && branching > 0,
|
||||
"{selecting} selecting and {branching} branching profiles"
|
||||
);
|
||||
}
|
||||
|
||||
/// The selecting form reaches Metal. `engine/trn_math_fast`, the fixture the branching guard's
|
||||
/// regression was found on, stores its answers through a buffer slot's descriptor view; on a
|
||||
/// MoltenVK capture its module holds the selection of the store's place between two descriptors
|
||||
/// (`OpSelect` of two `StorageBuffer` pointers, which declares `VariablePointers`), and MoltenVK's
|
||||
/// own path -- SPIRV-Cross to MSL, then `xcrun metal` -- compiles it.
|
||||
///
|
||||
/// The selection is counted first, so the compile cannot pass by compiling a module without one.
|
||||
/// `llvm-as` or the Metal toolchain missing skips visibly.
|
||||
#[test]
|
||||
fn the_selected_place_compiles_through_moltenvks_own_path() {
|
||||
use crate::spirv::ir::{StorageClass, Type};
|
||||
let path = engine_dir().join("trn_math_fast.ll");
|
||||
let bc = match llvm_assemble(&path) {
|
||||
Ok(b) => b,
|
||||
Err(AssembleError::Missing(why)) => {
|
||||
eprintln!("SKIPPED: {why}");
|
||||
return;
|
||||
}
|
||||
Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected trn_math_fast.ll: {why}"),
|
||||
};
|
||||
let entry = "trn_math_fast";
|
||||
let mut compiled = 0;
|
||||
for (stem, p) in committed_profiles().expect("profiles") {
|
||||
if !crate::spirv::testing::is_moltenvk_capture(&stem) {
|
||||
continue;
|
||||
}
|
||||
let (plan, m) = crate::pipeline::testing::typed_module(&bc, entry, &p)
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
assert!(
|
||||
plan.families.access.store_sink.is_some(),
|
||||
"{stem}: no store sink"
|
||||
);
|
||||
let pointer_selects = m
|
||||
.blocks()
|
||||
.iter()
|
||||
.flat_map(|b| &b.insts)
|
||||
.filter(|n| match n.inst {
|
||||
crate::spirv::ir::Inst::Select { t, .. } => matches!(
|
||||
m.types().get(m.values()[t.index()].ty),
|
||||
Ok(Type::Pointer {
|
||||
class: StorageClass::StorageBuffer,
|
||||
..
|
||||
})
|
||||
),
|
||||
_ => false,
|
||||
})
|
||||
.count();
|
||||
assert!(
|
||||
pointer_selects > 0,
|
||||
"{stem}: the module selects no store place, so the compile below proves nothing"
|
||||
);
|
||||
let a = crate::pipeline::testing::compile(&bc, entry, &p)
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
let (_, words) = crate::pipeline::testing::link_and_validate(&a, &p)
|
||||
.unwrap_or_else(|e| panic!("{stem}: L3: {e}"));
|
||||
match crate::pipeline::testing::moltenvk_msl_compile(&words) {
|
||||
Ok(()) => compiled += 1,
|
||||
Err(AssembleError::Missing(why)) => eprintln!("SKIPPED MSL on {stem}: {why}"),
|
||||
Err(AssembleError::Rejected(why)) => panic!("{stem}: MSL: {why}"),
|
||||
}
|
||||
}
|
||||
eprintln!("MoltenVK captures whose selecting module compiled to Metal: {compiled}");
|
||||
}
|
||||
@@ -39,6 +39,15 @@ const PROFILES: [&str; 2] = ["vk12-floor", "moltenvk-m3"];
|
||||
|
||||
/// Committed profile `stem`, optionally with buffer robustness disabled (the in-shader encoding).
|
||||
fn profile_with(stem: &str, robust: bool) -> DeviceProfile {
|
||||
profile_room(stem, robust, 0)
|
||||
}
|
||||
|
||||
/// [`profile_with`] with `room` more per-stage storage-buffer descriptors than the profile
|
||||
/// reports: a kernel of 31 written buffer slots needs one beside them for the stage's store sink
|
||||
/// (`lower::access::sink`), and without it a profile whose limit is exactly 31 (MoltenVK's, Metal's
|
||||
/// own buffer limit) moves its highest slot to a device address, which is the descriptor
|
||||
/// fallback's subject and not this file's.
|
||||
fn profile_room(stem: &str, robust: bool, room: u32) -> DeviceProfile {
|
||||
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../metal2vulkan-validation/profiles")
|
||||
.join(format!("{stem}.json"));
|
||||
@@ -48,6 +57,8 @@ fn profile_with(stem: &str, robust: bool) -> DeviceProfile {
|
||||
desc.features.remove(&VkFeature::RobustBufferAccess);
|
||||
desc.features.remove(&VkFeature::RobustBufferAccess2);
|
||||
}
|
||||
desc.limits.max_per_stage_descriptor_storage_buffers += room;
|
||||
desc.limits.max_per_stage_resources += room;
|
||||
Device::new(desc, DevicePolicy::default())
|
||||
.expect("device")
|
||||
.profile()
|
||||
@@ -700,7 +711,7 @@ fn push_fields_in_the_argument_table_are_read_exactly() {
|
||||
for stem in ["lavapipe", "moltenvk-m3", "lunarg-desktop-baseline-2023"] {
|
||||
for robust in [true, false] {
|
||||
let what = format!("{stem} robust={robust}");
|
||||
let p = profile_with(stem, robust);
|
||||
let p = profile_room(stem, robust, 1);
|
||||
let a = compile(&bc, "many_slots", &p).unwrap_or_else(|e| panic!("{what}: {e}"));
|
||||
let spilled: Vec<PushField> = a
|
||||
.interface
|
||||
@@ -713,6 +724,15 @@ fn push_fields_in_the_argument_table_are_read_exactly() {
|
||||
// Seven slot residuals and the stage's dropped-store word.
|
||||
assert_eq!(spilled.len(), 8, "{what}: {spilled:?}");
|
||||
assert_eq!(a.interface.push.argument_table_size, 32, "{what}");
|
||||
// Every slot keeps its descriptor view: the stage's store sink has room beside them
|
||||
// (`slot_room`), so the forms the push placement is read over are the descriptor ones.
|
||||
assert!(
|
||||
!a.facts.iter().any(|f| matches!(
|
||||
f,
|
||||
crate::pipeline::facts::RuntimeFact::DeviceAddresses { .. }
|
||||
)),
|
||||
"{what}: a slot moved to its device address"
|
||||
);
|
||||
let (table, _) = link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{what}: {e}"));
|
||||
assert!(table.bindings.contains_key(&table_slot), "{what}");
|
||||
let (plan, m) = typed_module(&bc, "many_slots", &p).expect("module");
|
||||
|
||||
@@ -279,10 +279,12 @@ fn selected_samplers_switch_per_combination() {
|
||||
// samplers in each arm.
|
||||
assert_eq!(uses(&a, "sampler.sample.switch"), 2);
|
||||
assert_eq!(count(&a, OP_SWITCH), 1 + 1 + 2);
|
||||
// Combined bindings: (t, ss[0]), (t, ss[1]), and each of t, u with s0 and s1.
|
||||
// Combined bindings: (t, ss[0]), (t, ss[1]), and each of t, u with s0 and s1; the buffer
|
||||
// slot; and the stage's write-only store sink, which its store through that slot selects its
|
||||
// place in (`lower::access::sink`).
|
||||
assert_eq!(
|
||||
a.interface.descriptors.len(),
|
||||
6 + 1,
|
||||
6 + 1 + 1,
|
||||
"{:?}",
|
||||
a.interface.descriptors
|
||||
);
|
||||
|
||||
+1345
-1345
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -138,7 +138,7 @@ Columns:
|
||||
| `SubgroupOperations` | Simdgroup operations of a class the stage's subgroups do not support (the stage is not in `subgroupSupportedStages`, or an operation class is... | devices without VkFeature::ShaderQuadControl; devices without VkFeature::ShaderSubgroupExtendedTypes; devices without VkProperty::SubgroupStage | `device` | 4: `crates/metal2vulkan-runtime/src/families/features.rs (simd)`, `crates/metal2vulkan/src/lower/simd/mod.rs (finish)` (+2) | `app`: simdgroup functions in a stage a device's subgroups do not support |
|
||||
| `DirectCall` | A call to a defined function the inliner cannot take | every device (not implemented) | `ours` | 1: `crates/metal2vulkan-air/src/canon/mod.rs (post_check)` | `rare`: variadic or byval calls the inliner cannot take |
|
||||
| `WideSwitchLiteral` | A switch case literal wider than 32 bits | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/structurize/emit.rs (check_tree)` | `rare`: 64-bit switch literals |
|
||||
| `Lowering` | An instruction, intrinsic, or interface element of a lowering family whose lowering has not landed yet (each family narrows its refusals as it lands) | devices short of a device limit the site names; devices without VkFeature::ShaderDemoteToHelperInvocation; every device (not implemented) | `ours` | 35: `crates/metal2vulkan/src/bind/plan/resources.rs (level_views)`, `crates/metal2vulkan/src/lower/access/handle.rs (domain_kind)` (+33) | `system`: the catch-all of lowering families not landed: any shader can meet one |
|
||||
| `Lowering` | An instruction, intrinsic, or interface element of a lowering family whose lowering has not landed yet (each family narrows its refusals as it lands) | devices short of a device limit the site names; devices without VkFeature::ShaderDemoteToHelperInvocation; devices without VkFeature::VariablePointers; every device (not implemented) | `ours` | 36: `crates/metal2vulkan/src/bind/plan/resources.rs (level_views)`, `crates/metal2vulkan/src/lower/access/handle.rs (domain_kind)` (+34) | `system`: the catch-all of lowering families not landed: any shader can meet one |
|
||||
| `SamplerAddressMode` | A sampler address mode the device lacks (`MirrorClampToEdge`) | devices without VkFeature::SamplerMirrorClampToEdge; every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/lower/sampler/constexpr.rs`, `crates/metal2vulkan/src/metal/sampler.rs (check_sampler)` | `app`: mirror-clamp-to-edge on a device without it |
|
||||
| `AlphaToOne` | `alphaToOneEnabled` on a device without Vulkan's `alphaToOne` feature, the exact counterpart... | devices without VkFeature::AlphaToOne | `device` | 1: `crates/metal2vulkan/src/pipeline/link/graphics.rs (graphics_state)` | `rare`: alphaToOneEnabled on a device without alphaToOne |
|
||||
| `StageStoresAndAtomics` | Buffer or image stores or atomics in a vertex or fragment function without the stage's store feature (`vertexPipelineStoresAndAtomics`,... | devices without VkFeature::FragmentStoresAndAtomics | `device` | 1: `crates/metal2vulkan/src/lower/access/tile_memory.rs (written)` | `app`: stores or atomics in vertex or fragment functions on a device without the feature |
|
||||
@@ -643,7 +643,7 @@ Each refusal's sites, with the function that builds it.
|
||||
- `feature::SubgroupOperations`: `crates/metal2vulkan-runtime/src/families/features.rs (simd)`; `crates/metal2vulkan/src/lower/simd/mod.rs (finish)`; `crates/metal2vulkan/src/lower/simd/mod.rs (full_quads)`; `crates/metal2vulkan/src/lower/simd/mod.rs (select_group)`
|
||||
- `feature::DirectCall`: `crates/metal2vulkan-air/src/canon/mod.rs (post_check)`
|
||||
- `feature::WideSwitchLiteral`: `crates/metal2vulkan/src/structurize/emit.rs (check_tree)`
|
||||
- `feature::Lowering`: `crates/metal2vulkan/src/bind/plan/resources.rs (level_views)`; `crates/metal2vulkan/src/lower/access/handle.rs (domain_kind)`; `crates/metal2vulkan/src/lower/access/handle.rs (sampler_target)`; `crates/metal2vulkan/src/lower/access/handle.rs (texture_target)`; `crates/metal2vulkan/src/lower/access/imageblock.rs (operand)`; `crates/metal2vulkan/src/lower/access/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/access/pulled.rs (share)`; `crates/metal2vulkan/src/lower/arith/legal.rs (not_lowered)`; `crates/metal2vulkan/src/lower/dispatch.rs (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/discard.rs (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/discard.rs (plan)`; `crates/metal2vulkan/src/lower/fragment/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/snapshot.rs (finish)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/sampler/mod.rs (refuse)`; `crates/metal2vulkan/src/lower/sampler/select.rs (refuse)`; `crates/metal2vulkan/src/lower/select.rs (not_lowered)`; `crates/metal2vulkan/src/lower/select.rs (route_air)`; `crates/metal2vulkan/src/lower/simd/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/simd/mod.rs (select_param)`; `crates/metal2vulkan/src/lower/simd/workgroup.rs (check)`; `crates/metal2vulkan/src/lower/stage_io/fetch.rs (not_lowered)`; `crates/metal2vulkan/src/lower/stage_io/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/sync/barrier.rs (not_lowered)`; `crates/metal2vulkan/src/lower/sync/memory_model.rs (not_implemented)`; `crates/metal2vulkan/src/lower/sync/memory_model.rs (select)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/texture/mod.rs (refuse)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_write)`; `crates/metal2vulkan/src/memory/alloca.rs (not_lowered)`; `crates/metal2vulkan/src/memory/leaf.rs (not_lowered)`; `crates/metal2vulkan/src/memory/plan.rs (not_lowered)`; `crates/metal2vulkan/src/memory/provenance.rs (not_lowered)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs (patch_fetch_projection)`
|
||||
- `feature::Lowering`: `crates/metal2vulkan/src/bind/plan/resources.rs (level_views)`; `crates/metal2vulkan/src/lower/access/handle.rs (domain_kind)`; `crates/metal2vulkan/src/lower/access/handle.rs (sampler_target)`; `crates/metal2vulkan/src/lower/access/handle.rs (texture_target)`; `crates/metal2vulkan/src/lower/access/imageblock.rs (operand)`; `crates/metal2vulkan/src/lower/access/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/access/pulled.rs (share)`; `crates/metal2vulkan/src/lower/access/sink.rs (finish)`; `crates/metal2vulkan/src/lower/arith/legal.rs (not_lowered)`; `crates/metal2vulkan/src/lower/dispatch.rs (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/discard.rs (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/discard.rs (plan)`; `crates/metal2vulkan/src/lower/fragment/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/snapshot.rs (finish)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/sampler/mod.rs (refuse)`; `crates/metal2vulkan/src/lower/sampler/select.rs (refuse)`; `crates/metal2vulkan/src/lower/select.rs (not_lowered)`; `crates/metal2vulkan/src/lower/select.rs (route_air)`; `crates/metal2vulkan/src/lower/simd/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/simd/mod.rs (select_param)`; `crates/metal2vulkan/src/lower/simd/workgroup.rs (check)`; `crates/metal2vulkan/src/lower/stage_io/fetch.rs (not_lowered)`; `crates/metal2vulkan/src/lower/stage_io/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/sync/barrier.rs (not_lowered)`; `crates/metal2vulkan/src/lower/sync/memory_model.rs (not_implemented)`; `crates/metal2vulkan/src/lower/sync/memory_model.rs (select)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs (not_lowered)`; `crates/metal2vulkan/src/lower/texture/mod.rs (refuse)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_write)`; `crates/metal2vulkan/src/memory/alloca.rs (not_lowered)`; `crates/metal2vulkan/src/memory/leaf.rs (not_lowered)`; `crates/metal2vulkan/src/memory/plan.rs (not_lowered)`; `crates/metal2vulkan/src/memory/provenance.rs (not_lowered)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs (patch_fetch_projection)`
|
||||
- `feature::SamplerAddressMode`: `crates/metal2vulkan/src/lower/sampler/constexpr.rs`; `crates/metal2vulkan/src/metal/sampler.rs (check_sampler)`
|
||||
- `feature::AlphaToOne`: `crates/metal2vulkan/src/pipeline/link/graphics.rs (graphics_state)`
|
||||
- `feature::StageStoresAndAtomics`: `crates/metal2vulkan/src/lower/access/tile_memory.rs (written)`
|
||||
|
||||
Reference in new issue
Block a user