identity: texture slots are the set-1 elements their pushed resource IDs name
Under the identity domains a kernel's texture slots now lower. A slot's gpuResourceID is pushed as its PushField::SlotGuestBase (the index in the low word, the word in the high one). Its texture is the element at that index of one of set 1's two fixed arrays: binding 0, SAMPLED_IMAGE x 65,536, and binding 1, STORAGE_IMAGE x 4,096. Each is partially bound, updated after binding and while unused elements are pending, and seen by every stage, with the same layout for every pipeline (BindingSource::IdentityArray). Each image class the kernel declares (shape, numeric type and depth comparison, sampled, or storage without a format) is a variable of its descriptor type's binding. The slot binds no descriptor and declares no specialization constant: - is_null_texture answers whether the index is 0. Nil needs nothing else in the shader, since element 0 of each array is a null descriptor (the device test ofba4454b05b). - A read the shader checks itself takes Metal's out-of-bounds alpha of 1 from bit 12 of the word (TextureWord::OUT_OF_BOUNDS_ALPHA_ONE). - The ResourcePresence and OutOfBoundsAlpha facts are not stated there. No binder chooses a variant under identity, so a slot reads whatever texture its ID names through the plain form: - the variant facts (cross-class reads, planes read in place, texel rows, texture-buffer parts) are not stated; - a float or half read takes the device's sRGB decode with PrecisionNote::SrgbTexelDecode (VkProperty::MetalSampler on MoltenVK), as a heap element's does, with no SrgbTexture twin; - no texture is sparse (the consumer refuses one): no write-dropping SparseTexture constant and no ConstantLanes; - a storage slot is formatless with no StorageTextureFormat fact. Where the device cannot access it without a format, the slot is refused as Unsupported{IdentityDomains} instead of asking for an input no consumer gives there. Admission stays typed. Under identity, a function is refused as Unsupported{IdentityDomains}, not implemented, if it: - samples (any sampler plan; Metal's own sampler as a requirement is allowed); - reaches textures through argument buffers (any heap group); - declares a slot with no identity class: texture buffers, level views, cube-as-array, planes, extended range, RGBX, ulong, or a storage image with a format; - uses a slot whose state comes from anything but its ID: border texels, sparse residency arms, a half conversion by the bound format, swizzles, offset bases; - carries a fact naming such state (identity_unsourced). That keeps the arm64-only forms (two-plane, extended range, sRGB twins) out of the identity domains, as the x86 scope wants. The old binder refuses an identity array as an internal error, since the consumer writes those arrays. SEMANTICS_VERSION 2150 (identity output changes), ARTIFACT_FORMAT_VERSION 529 (BindingSource gains IdentityArray). docs/RESOURCE-ID.md says what the arrays are and what the shader reads of an ID. docs/API.md says what the identity domains lower. The refusal surface and the API signatures are regenerated. The blessed table also gains metal2vulkan-rt::PrecisionNote::CappedLodBias, a variant development's table lacked. Verified, on developmentcfa389aa9b(check commit 564d131163, same tree): - msi, job m3-max-41519: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc -D warnings, and nextest of metal2vulkan's whole suite: 3672 tests run, 3672 passed, 20 skipped. - msi, job m3-max-41520: clippy of metal2vulkan under --cfg m2v_gpu and --cfg m2v_cpu_icd, both clean. - The new test, texture_slots_are_the_set_1_elements_their_pushed_resource_ids_name, runs on lavapipe, moltenvk-m3, and moltenvk-m3 without robustImageAccess2. Its words come from tests/resource_words.tsv rows 70 and 10, checked against TextureWord::of. It checks the fixed set-1 layout and that the pushed fields are exactly the buffer, the three texture IDs and the region. On the interpreter, with the source at sampled element 3 and the destination at storage element 2, it checks the reads, the writes, the width and is_null_texture both ways (index 0 and index 1). On moltenvk-m3 without robustImageAccess2, where the shader checks the read, the source image traps any access outside it and the out-of-bounds alpha comes from bit 12 of the word: 1.0 for R8Unorm, 0.0 for RGBA8Unorm. On the other two profiles the device's robust texel answers. - The same change on the earlier base 9a3b6587b2 (jobs m3-max-41478 and 41479): 3670 of 3670, clippy clean in all three configurations.
This commit is contained in:
1 parent
1ceaea8eec
commit
fa52012831
16 files changed
+736
-72
No files matched your search
@@ -2192,6 +2192,10 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result<Bindin
|
||||
| BindingSource::SamplerArray { .. } => {
|
||||
return Err(internal("a heap binding outside the heap planner"))
|
||||
}
|
||||
// The identity domains' arrays are the consumer's, written as it makes textures.
|
||||
BindingSource::IdentityArray => {
|
||||
return Err(internal("an identity array in the binder's plan"))
|
||||
}
|
||||
BindingSource::SeparateSampler { .. } => {
|
||||
return Err(internal("a separate sampler outside its planner"))
|
||||
}
|
||||
|
||||
+1
@@ -1538,6 +1538,7 @@ codec_enum! {
|
||||
SnapshotTexels(f0),
|
||||
YCbCrPlanes(f0),
|
||||
SamplerArray { stage, compare, integer },
|
||||
IdentityArray,
|
||||
}
|
||||
VertexStride { Static(f0), PerBind }
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -61,7 +61,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 = 2149;
|
||||
pub const SEMANTICS_VERSION: u32 = 2150;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
@@ -71,7 +71,7 @@ pub const SEMANTICS_VERSION: u32 = 2149;
|
||||
/// 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 = 528;
|
||||
pub const ARTIFACT_FORMAT_VERSION: u32 = 529;
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -1862,9 +1862,54 @@ fn finish(
|
||||
Ok(plan)
|
||||
}
|
||||
|
||||
/// Whether fact `f` names state of a bound texture or sampler the identity domains do not source
|
||||
/// yet: anything but a texture's presence and its format's missing alpha, which its resource ID
|
||||
/// holds.
|
||||
fn identity_unsourced(f: &RuntimeFact) -> bool {
|
||||
matches!(
|
||||
f,
|
||||
RuntimeFact::StorageTextureFormat { .. }
|
||||
| RuntimeFact::SamplerCoordinates { .. }
|
||||
| RuntimeFact::SamplerReduction { .. }
|
||||
| RuntimeFact::ImageViewShape { .. }
|
||||
| RuntimeFact::TexelBufferRange { .. }
|
||||
| RuntimeFact::HeapNumericType { .. }
|
||||
| RuntimeFact::StorageTextureNumericType { .. }
|
||||
| RuntimeFact::BicubicTexels { .. }
|
||||
| RuntimeFact::StorageTextureLevels { .. }
|
||||
| RuntimeFact::StorageTextureLevelViews { .. }
|
||||
| RuntimeFact::SparseTexture { .. }
|
||||
| RuntimeFact::TexelFormat { .. }
|
||||
| RuntimeFact::SrgbTexture { .. }
|
||||
| RuntimeFact::UlongAtomicView { .. }
|
||||
| RuntimeFact::OpenClLineTexture { .. }
|
||||
| RuntimeFact::SparseTextureWrites { .. }
|
||||
| RuntimeFact::TextureSwizzle { .. }
|
||||
| RuntimeFact::ConstantLanes { .. }
|
||||
| RuntimeFact::ConstexprSampled { .. }
|
||||
| RuntimeFact::CubicSampler { .. }
|
||||
| RuntimeFact::CubicArgumentSampler { .. }
|
||||
| RuntimeFact::HeapRawSamples { .. }
|
||||
| RuntimeFact::CrossClassReads { .. }
|
||||
| RuntimeFact::StorageTextureWriteRounding { .. }
|
||||
| RuntimeFact::HeapWriteRounding { .. }
|
||||
| RuntimeFact::HeapCrossClassNeutral { .. }
|
||||
| RuntimeFact::HeapResidency { .. }
|
||||
| RuntimeFact::HeapStorageReads { .. }
|
||||
| RuntimeFact::AnisotropicSampler { .. }
|
||||
| RuntimeFact::StorageTextureIntegerChannels { .. }
|
||||
| RuntimeFact::YCbCrInPlace { .. }
|
||||
| RuntimeFact::TexelRows { .. }
|
||||
| RuntimeFact::BorderTexels { .. }
|
||||
| RuntimeFact::TexelBufferParts { .. }
|
||||
)
|
||||
}
|
||||
|
||||
/// Under the identity domains, the plans lowered so far: a kernel that reaches memory only
|
||||
/// through its buffer slots' device addresses, with no descriptor. Its fields past the push window
|
||||
/// are a parameter block, whose address the window holds.
|
||||
/// through its buffer slots' device addresses and its texture slots' resource IDs, with no
|
||||
/// descriptor, no sampler, and no state of a bound texture but its resource ID's
|
||||
/// (`SlotPlan::identity_lowered`, [`identity_unsourced`]). Its fields past the push window are a
|
||||
/// parameter block, whose address the window holds.
|
||||
fn identity_admits(plan: &Plan) -> Result<(), Error> {
|
||||
let fields = plan.push.fields.iter().all(|f| match (f.field, f.loc) {
|
||||
(PushField::ArgumentTableAddress, loc) => matches!(loc, PushLoc::Push { .. }),
|
||||
@@ -1878,9 +1923,22 @@ fn identity_admits(plan: &Plan) -> Result<(), Error> {
|
||||
.iter()
|
||||
.flatten()
|
||||
.all(|c| c.form == BufferForm::Psb);
|
||||
let t = &plan.families.texture;
|
||||
let textures = t.heap.is_empty() && t.slots.values().all(|s| s.identity_lowered());
|
||||
// No sampler use: a read's decode through Metal's own texture unit (`metal_sampler`) is only
|
||||
// a requirement.
|
||||
let sampled = &plan.families.sampler;
|
||||
let unsampled = *sampled
|
||||
== sampler::SamplerPlan {
|
||||
metal_sampler: sampled.metal_sampler,
|
||||
..Default::default()
|
||||
};
|
||||
if plan.stage == Stage::Kernel
|
||||
&& fields
|
||||
&& addressed
|
||||
&& textures
|
||||
&& unsampled
|
||||
&& !plan.facts.iter().any(identity_unsourced)
|
||||
&& plan.descriptors == DescriptorCounts::default()
|
||||
{
|
||||
return Ok(());
|
||||
|
||||
@@ -61,6 +61,12 @@ fn value(
|
||||
return Ok(None);
|
||||
}
|
||||
TextureStrategy::Sampling(x) => crate::lower::sampler::sampling_value(cx, fb, x, grads)?,
|
||||
// Under the identity domains a slot is nil where its resource ID's index is 0.
|
||||
TextureStrategy::IsNull { index } if cx.plan.families.access.identity => {
|
||||
let (element, _) = identity_id(cx, fb, *index)?;
|
||||
let null = u32s(fb, 1, 0)?;
|
||||
fb.binary(BinOp::IEqual, element, null)?
|
||||
}
|
||||
TextureStrategy::IsNull { index } => {
|
||||
let Some(p) = cx.decl.families.texture.presence.get(index).copied() else {
|
||||
return Err(cx.fail("an is_null of a slot without a presence constant"));
|
||||
@@ -458,6 +464,9 @@ fn image_in(
|
||||
});
|
||||
}
|
||||
};
|
||||
if cx.plan.families.access.identity {
|
||||
return identity_image(cx, fb, index, level);
|
||||
}
|
||||
let slot = cx.plan.families.texture.slots.get(&index);
|
||||
let (decl, at) = (slot.and_then(|s| s.decl), slot.map(|s| s.slot));
|
||||
let global = cx.decl.families.texture.images.get(&index).copied();
|
||||
@@ -502,6 +511,57 @@ fn image_in(
|
||||
})
|
||||
}
|
||||
|
||||
/// Under the identity domains, texture slot `index`'s resource ID, from its push field: the index
|
||||
/// of its element in the set-1 arrays (the low word) and its word (the high word,
|
||||
/// `metal::resource_word::TextureWord`).
|
||||
pub(crate) fn identity_id(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
index: u32,
|
||||
) -> BResult<(SValue, SValue)> {
|
||||
let Some(slot) = cx.plan.families.texture.slots.get(&index).map(|s| s.slot) else {
|
||||
return Err(cx.fail(format!("texture slot {index} is not planned")));
|
||||
};
|
||||
let id = cx.push_field(fb, crate::pipeline::sym::PushField::SlotGuestBase(slot))?;
|
||||
Ok((
|
||||
fb.composite_extract(id, &[0])?,
|
||||
fb.composite_extract(id, &[1])?,
|
||||
))
|
||||
}
|
||||
|
||||
/// Under the identity domains, texture slot `index`'s image: the element of its class's set-1
|
||||
/// array (`slot::identity_class`) at the index its resource ID holds, which is uniform over the
|
||||
/// call. A slot has one level here (`level` is `None`).
|
||||
fn identity_image(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
index: u32,
|
||||
level: Option<ValueId>,
|
||||
) -> BResult<Loaded> {
|
||||
let decl = cx
|
||||
.plan
|
||||
.families
|
||||
.texture
|
||||
.slots
|
||||
.get(&index)
|
||||
.and_then(|s| s.decl);
|
||||
let global = cx.decl.families.texture.images.get(&index).copied();
|
||||
let (Some(decl), Some((g, _)), None) = (decl, global, level) else {
|
||||
return Err(cx.fail(format!("texture slot {index} is not declared")));
|
||||
};
|
||||
let (element, _) = identity_id(cx, fb, index)?;
|
||||
let base = fb.module().global_value(g)?;
|
||||
let p = fb.access_chain(base, &[element])?;
|
||||
let img = fb.load(p, MemAccess::default())?;
|
||||
Ok(Loaded {
|
||||
decl,
|
||||
img,
|
||||
live: None,
|
||||
within: None,
|
||||
flagged: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Texture slot `index`'s image, loaded in the open block, with its declaration: an
|
||||
/// extended-range sample fetches its raw texels from it (`sampler::extended`).
|
||||
pub(crate) fn slot_image(
|
||||
@@ -2112,6 +2172,18 @@ pub(super) fn out_of_bounds_texel(
|
||||
return fb.module().const_value(z);
|
||||
}
|
||||
let spec = match *image {
|
||||
// Under the identity domains the format's missing alpha is the resource ID's word's.
|
||||
ImageRef::Slot(index) if cx.plan.families.access.identity => {
|
||||
let (_, word) = identity_id(cx, fb, index)?;
|
||||
let bit = u32s(
|
||||
fb,
|
||||
1,
|
||||
crate::metal::resource_word::TextureWord::OUT_OF_BOUNDS_ALPHA_ONE,
|
||||
)?;
|
||||
let set = fb.binary(BinOp::BitwiseAnd, word, bit)?;
|
||||
let zero = u32s(fb, 1, 0)?;
|
||||
fb.binary(BinOp::INotEqual, set, zero)?
|
||||
}
|
||||
ImageRef::Slot(index) => match cx.decl.families.texture.oob_alpha.get(&index).copied() {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
|
||||
@@ -1237,7 +1237,32 @@ pub fn declare(
|
||||
_modes: &mut Vec<ExecMode>,
|
||||
) -> BResult<Declared> {
|
||||
let mut d = Declared::default();
|
||||
for (index, s) in &plan.families.texture.slots {
|
||||
// Under the identity domains a slot's texture is an element of its class's set-1 array
|
||||
// (`slot::identity_class`), declared once per class, and the slot has no constant: its
|
||||
// presence and its format's missing alpha are its resource ID's (`emit::identity_id`).
|
||||
if plan.families.access.identity {
|
||||
let mut decorated = std::collections::BTreeSet::new();
|
||||
for (index, s) in &plan.families.texture.slots {
|
||||
let Some(decl) = &s.decl else { continue };
|
||||
let Some(class) = slot::identity_class(decl) else {
|
||||
continue;
|
||||
};
|
||||
let g = match d.heap.get(&class) {
|
||||
Some(g) => *g,
|
||||
None => {
|
||||
let g = heap_array(mb, plan.stage, class, *decl)?;
|
||||
d.heap.insert(class, g);
|
||||
g
|
||||
}
|
||||
};
|
||||
if s.volatile && volatile_decorated(plan) && decorated.insert(g) {
|
||||
mb.volatile(g)?;
|
||||
}
|
||||
d.images.insert(*index, (g, decl.declare(mb)?));
|
||||
}
|
||||
}
|
||||
let slots = (plan.families.texture.slots.iter()).filter(|_| !plan.families.access.identity);
|
||||
for (index, s) in slots {
|
||||
if let Some(decl) = &s.decl {
|
||||
let image = decl.declare(mb)?;
|
||||
// A slot's level views are one descriptor array of single-level views, and a texture
|
||||
@@ -1857,9 +1882,14 @@ pub(crate) fn srgb_texels(
|
||||
if shape.dim == ImageDim::Buffer || shape.depth {
|
||||
return Ok(false);
|
||||
}
|
||||
let ImageRef::Slot(index) = image else {
|
||||
device_decode(cx, None, m)?;
|
||||
return Ok(false);
|
||||
// Under the identity domains a slot's format is never known, as a heap element's is not.
|
||||
let index = match image {
|
||||
ImageRef::Slot(index) if !crate::lower::access::identity(cx.profile) => index,
|
||||
ImageRef::Slot(index) if slot_of(cx, index)?.storage() => return Ok(false),
|
||||
_ => {
|
||||
device_decode(cx, None, m)?;
|
||||
return Ok(false);
|
||||
}
|
||||
};
|
||||
let s = slot_of(cx, index)?;
|
||||
if s.storage() {
|
||||
@@ -3168,14 +3198,17 @@ fn select_image(
|
||||
if let Some(s) = cx.families.texture.slots.get_mut(&index) {
|
||||
s.presence = true;
|
||||
}
|
||||
cx.facts
|
||||
.insert(crate::pipeline::facts::RuntimeFact::ResourcePresence {
|
||||
slot: SlotRef {
|
||||
stage: cx.stage,
|
||||
class: SlotClass::Texture,
|
||||
index,
|
||||
},
|
||||
});
|
||||
// Under the identity domains the slot's resource ID says it (`emit::identity_id`).
|
||||
if !crate::lower::access::identity(cx.profile) {
|
||||
cx.facts
|
||||
.insert(crate::pipeline::facts::RuntimeFact::ResourcePresence {
|
||||
slot: SlotRef {
|
||||
stage: cx.stage,
|
||||
class: SlotClass::Texture,
|
||||
index,
|
||||
},
|
||||
});
|
||||
}
|
||||
Ok(TextureStrategy::IsNull { index })
|
||||
}
|
||||
TexOp::Query(q) => select_query(cx, ops, image, shape, q),
|
||||
@@ -3423,8 +3456,12 @@ fn select_read_as(
|
||||
if let Some(s) = cx.families.texture.slots.get_mut(&index) {
|
||||
s.oob_alpha = true;
|
||||
}
|
||||
cx.facts
|
||||
.insert(crate::pipeline::facts::RuntimeFact::OutOfBoundsAlpha { slot });
|
||||
// Under the identity domains the slot's resource ID's word says it
|
||||
// (`TextureWord::OUT_OF_BOUNDS_ALPHA_ONE`).
|
||||
if !crate::lower::access::identity(cx.profile) {
|
||||
cx.facts
|
||||
.insert(crate::pipeline::facts::RuntimeFact::OutOfBoundsAlpha { slot });
|
||||
}
|
||||
true
|
||||
}
|
||||
// A heap element's format is the resident texture's: its handle-table entry's flags say
|
||||
@@ -3507,9 +3544,11 @@ fn select_read_as(
|
||||
.enabled
|
||||
.features
|
||||
.contains(&crate::device::requirements::VkFeature::ShaderResourceResidency);
|
||||
// Under the identity domains no texture is sparse (the consumer refuses one).
|
||||
let constant_lanes = match image {
|
||||
ImageRef::Slot(index)
|
||||
if sparse_images
|
||||
&& !crate::lower::access::identity(cx.profile)
|
||||
&& shape.dim != ImageDim::Buffer
|
||||
&& texel.lanes == 4
|
||||
&& !matches!(texel.conv, TexelConv::U64Words { .. }) =>
|
||||
|
||||
@@ -800,6 +800,11 @@ fn storage_format(
|
||||
StorageImageClass::Identity,
|
||||
));
|
||||
}
|
||||
// Under the identity domains no input names the bound format, and a formatless access the
|
||||
// device does not take is not lowered yet.
|
||||
if crate::lower::access::identity(cx.profile) {
|
||||
return Err(Unsupported::not_implemented(Feature::IdentityDomains).into());
|
||||
}
|
||||
return Err(Error::NeedsInput(RuntimeInput::StorageTextureFormat {
|
||||
slot: s.slot,
|
||||
}));
|
||||
@@ -1271,7 +1276,10 @@ fn declare_slot(
|
||||
None
|
||||
};
|
||||
let (format, class) = if storage {
|
||||
facts.push(RuntimeFact::StorageTextureFormat { slot: s.slot });
|
||||
// Under the identity domains no input names the bound format: the slot is formatless.
|
||||
if !crate::lower::access::identity(cx.profile) {
|
||||
facts.push(RuntimeFact::StorageTextureFormat { slot: s.slot });
|
||||
}
|
||||
if s.uses.int_channels {
|
||||
facts.push(RuntimeFact::StorageTextureIntegerChannels { slot: s.slot });
|
||||
push.push(PushField::TextureIntegerChannels(s.slot));
|
||||
@@ -1455,47 +1463,52 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
let volatile = !d.rows && forwards(cx, &s.uses, shape.dim == ImageDim::Buffer);
|
||||
decls.push((*index, d, volatile));
|
||||
}
|
||||
// The slots read, sampled or gathered in any class (a slot only sampled is declared by its
|
||||
// combined bindings, `sampler::finish`).
|
||||
for s in cx.families.texture.slots.values() {
|
||||
if s.shape.is_some_and(|shape| cross_reads(s, shape)) {
|
||||
facts.push(RuntimeFact::CrossClassReads { slot: s.slot });
|
||||
// The variants a slot may take by its bound texture (cross-class reads, planes read in place,
|
||||
// a texture's rows, a texture buffer's parts): under the identity domains no binder chooses a
|
||||
// variant, and the slot reads whatever texture its resource ID names through the plain form.
|
||||
if !crate::lower::access::identity(cx.profile) {
|
||||
// The slots read, sampled or gathered in any class (a slot only sampled is declared by its
|
||||
// combined bindings, `sampler::finish`).
|
||||
for s in cx.families.texture.slots.values() {
|
||||
if s.shape.is_some_and(|shape| cross_reads(s, shape)) {
|
||||
facts.push(RuntimeFact::CrossClassReads { slot: s.slot });
|
||||
}
|
||||
}
|
||||
}
|
||||
// The slots whose every access the in-place form reads, on a profile that takes it: their
|
||||
// compile under the form states the same, which its plan holds to.
|
||||
for s in cx.families.texture.slots.values() {
|
||||
let reads = in_place_reads(cx, s);
|
||||
if !reads && cx.inputs.ycbcr_in_place.contains(&s.slot) {
|
||||
return Err(
|
||||
cx.invariant("an in-place texture slot whose accesses the form does not read")
|
||||
);
|
||||
// The slots whose every access the in-place form reads, on a profile that takes it: their
|
||||
// compile under the form states the same, which its plan holds to.
|
||||
for s in cx.families.texture.slots.values() {
|
||||
let reads = in_place_reads(cx, s);
|
||||
if !reads && cx.inputs.ycbcr_in_place.contains(&s.slot) {
|
||||
return Err(
|
||||
cx.invariant("an in-place texture slot whose accesses the form does not read")
|
||||
);
|
||||
}
|
||||
if s.in_place.device_blocked && cx.inputs.ycbcr_planes_sampled.contains_key(&s.slot) {
|
||||
return Err(cx.invariant(
|
||||
"a planes image's texture slot with a sample the device's sampler does not take",
|
||||
));
|
||||
}
|
||||
if reads {
|
||||
facts.push(RuntimeFact::YCbCrInPlace {
|
||||
slot: s.slot,
|
||||
samplers: s.in_place.samplers,
|
||||
device: !s.in_place.device_blocked,
|
||||
});
|
||||
}
|
||||
}
|
||||
if s.in_place.device_blocked && cx.inputs.ycbcr_planes_sampled.contains_key(&s.slot) {
|
||||
return Err(cx.invariant(
|
||||
"a planes image's texture slot with a sample the device's sampler does not take",
|
||||
));
|
||||
// The slots whose every access the rows answer: their compile under the rows variant states
|
||||
// the same, which its plan holds to.
|
||||
for s in cx.families.texture.slots.values() {
|
||||
if rows_reads(s) {
|
||||
facts.push(RuntimeFact::TexelRows { slot: s.slot });
|
||||
}
|
||||
}
|
||||
if reads {
|
||||
facts.push(RuntimeFact::YCbCrInPlace {
|
||||
slot: s.slot,
|
||||
samplers: s.in_place.samplers,
|
||||
device: !s.in_place.device_blocked,
|
||||
});
|
||||
}
|
||||
}
|
||||
// The slots whose every access the rows answer: their compile under the rows variant states
|
||||
// the same, which its plan holds to.
|
||||
for s in cx.families.texture.slots.values() {
|
||||
if rows_reads(s) {
|
||||
facts.push(RuntimeFact::TexelRows { slot: s.slot });
|
||||
}
|
||||
}
|
||||
// The texture-buffer slots whose every access their parts answer: their compile under the
|
||||
// parts variant states the same, which its plan holds to.
|
||||
for s in cx.families.texture.slots.values() {
|
||||
if parts_reads(cx, s) {
|
||||
facts.push(RuntimeFact::TexelBufferParts { slot: s.slot });
|
||||
// The texture-buffer slots whose every access their parts answer: their compile under the
|
||||
// parts variant states the same, which its plan holds to.
|
||||
for s in cx.families.texture.slots.values() {
|
||||
if parts_reads(cx, s) {
|
||||
facts.push(RuntimeFact::TexelBufferParts { slot: s.slot });
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut heap = Vec::new();
|
||||
@@ -1657,8 +1670,12 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
// texel buffer or a 1D texture): Metal drops every write to a sparse texture, which the slot's
|
||||
// `SparseTexture` specialization drops, and the binder refuses a sparse texture at a slot
|
||||
// updated atomically.
|
||||
// Under the identity domains no texture is sparse (the consumer refuses one), so no write is
|
||||
// dropped.
|
||||
let mut written = Vec::new();
|
||||
for (index, s) in &cx.families.texture.slots {
|
||||
let slots =
|
||||
(cx.families.texture.slots.iter()).filter(|_| !crate::lower::access::identity(cx.profile));
|
||||
for (index, s) in slots {
|
||||
let sparse_type = s
|
||||
.shape
|
||||
.is_some_and(|x| !matches!(x.dim, ImageDim::Buffer | ImageDim::D1));
|
||||
@@ -1700,6 +1717,86 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
}
|
||||
cx.facts.extend(facts);
|
||||
cx.push.extend(push);
|
||||
cx.descriptors = cx.descriptors.plus(&counts);
|
||||
// Under the identity domains a slot's texture is the element of the set-1 array of its
|
||||
// declaration's class ([`identity_class`]) at the index its resource ID holds, which the
|
||||
// slot's push field carries: the slot binds no descriptor of its own.
|
||||
match crate::lower::access::identity(cx.profile) {
|
||||
true => {
|
||||
for s in cx.families.texture.slots.values() {
|
||||
cx.push.insert(PushField::SlotGuestBase(s.slot));
|
||||
}
|
||||
}
|
||||
false => cx.descriptors = cx.descriptors.plus(&counts),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl SlotPlan {
|
||||
/// Whether the identity domains lower the slot: its declaration has an identity array class
|
||||
/// ([`identity_class`]), or it has none (a slot that is only tested for presence), and it reads
|
||||
/// no state of the bound texture but its resource ID's (its presence and its format's missing
|
||||
/// alpha). A conversion by the bound format, a swizzle, sparse residency, border texels,
|
||||
/// constant lanes and offset bases each read a constant or a binding the slot does not have
|
||||
/// there yet.
|
||||
pub(crate) fn identity_lowered(&self) -> bool {
|
||||
let state = self.border_texels
|
||||
|| self.sparse_arm
|
||||
|| self.tile_map
|
||||
|| self.sparse_writes
|
||||
|| self.declares_texel_format()
|
||||
|| self.unmeasured
|
||||
|| self.swizzle
|
||||
|| self.constant_lanes
|
||||
|| self.offset_base;
|
||||
!state
|
||||
&& self
|
||||
.decl
|
||||
.as_ref()
|
||||
.is_none_or(|d| identity_class(d).is_some())
|
||||
}
|
||||
}
|
||||
|
||||
/// Under the identity domains, the class of the set-1 array whose elements texture slot
|
||||
/// declaration `decl` takes: its shape, numeric type and depth comparison, sampled, or a storage
|
||||
/// image without a format (the floor's `shaderStorageImageWriteWithoutFormat`). `None` for a
|
||||
/// declaration the identity arrays hold no element of yet: a cube viewed as an array, level views,
|
||||
/// a texture buffer, its parts or rows, planes, an extended-range, RGBX or `ulong` form, or a
|
||||
/// storage image with a format or a conversion.
|
||||
pub(crate) fn identity_class(decl: &ImageDecl) -> Option<ImageHandleClass> {
|
||||
let plain = !decl.cube_as_array
|
||||
&& decl.level_views.is_none()
|
||||
&& decl.extended.is_none()
|
||||
&& !decl.x_channel
|
||||
&& !decl.in_place
|
||||
&& decl.planes_sampler.is_none()
|
||||
&& !decl.rows
|
||||
&& decl.parts.is_none()
|
||||
&& decl.class == StorageImageClass::Identity
|
||||
&& decl.texel != TexelClass::Uint64;
|
||||
let dim = match decl.dim {
|
||||
Dim::D1 => SymDim::D1,
|
||||
Dim::D2 => SymDim::D2,
|
||||
Dim::D3 => SymDim::D3,
|
||||
Dim::Cube => SymDim::Cube,
|
||||
_ => return None,
|
||||
};
|
||||
let storage = decl.usage == ImageUsage::Storage;
|
||||
if !plain || (storage && decl.format != crate::spv::ImageFormat::Unknown) {
|
||||
return None;
|
||||
}
|
||||
Some(ImageHandleClass {
|
||||
dim,
|
||||
arrayed: decl.arrayed,
|
||||
multisampled: decl.multisampled,
|
||||
sampled_type: decl.texel.sampled_type(),
|
||||
depth_compare: decl.depth,
|
||||
access: match storage {
|
||||
true => ImageAccess::Storage,
|
||||
false => ImageAccess::Sampled,
|
||||
},
|
||||
format: match storage {
|
||||
true => StorageFormatClass::Unknown,
|
||||
false => StorageFormatClass::NotStorage,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -101,6 +101,11 @@ pub enum BindingSource {
|
||||
},
|
||||
/// One runtime array of the set-1 heap.
|
||||
Heap(HandleClass),
|
||||
/// An array of the identity domains' set 1: binding 0 the sampled images, binding 1 the
|
||||
/// storage images, element `i` the texture whose resource ID holds index `i`
|
||||
/// (`docs/RESOURCE-ID.md`). The consumer writes an element as it makes a texture, for every
|
||||
/// pipeline at once.
|
||||
IdentityArray,
|
||||
/// A separate sampler of `stage` that samples set-1 heap images. A constexpr sampler is the
|
||||
/// binding's `immutable_sampler`, which takes no descriptor write.
|
||||
HeapSampler {
|
||||
|
||||
@@ -1181,6 +1181,9 @@ fn heap_set(
|
||||
if heap.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
if crate::lower::access::identity(p) {
|
||||
return identity_set(heap, table).map(Some);
|
||||
}
|
||||
// The layout's own features (the module states its indexing features); `select` refuses a
|
||||
// function whose heap the profile cannot hold, so a miss here is a function compiled for
|
||||
// another profile.
|
||||
@@ -1238,6 +1241,67 @@ fn heap_set(
|
||||
}))
|
||||
}
|
||||
|
||||
/// The sampled-image array of the identity domains' set 1: binding 0, one element per index a
|
||||
/// texture's resource ID may hold (`docs/RESOURCE-ID.md`).
|
||||
const IDENTITY_SAMPLED_IMAGES: u32 = 65_536;
|
||||
|
||||
/// The storage-image array of the identity domains' set 1: binding 1, one element per index of a
|
||||
/// storage-capable texture.
|
||||
const IDENTITY_STORAGE_IMAGES: u32 = 4_096;
|
||||
|
||||
/// Set 1 under the identity domains: the same layout for every pipeline, so the consumer binds one
|
||||
/// set for every command. Binding 0 is the sampled-image array and binding 1 the storage-image
|
||||
/// array, each element the texture whose resource ID holds its index; every heap class the
|
||||
/// pipeline's stages declare is a variable of its descriptor type's binding, as the variables of
|
||||
/// one set and binding may be (Vulkan's "DescriptorSet and Binding Assignment"). Every stage sees
|
||||
/// both arrays, partially bound, updated after binding and while unused elements are pending: the
|
||||
/// floor's features.
|
||||
fn identity_set(
|
||||
heap: &BTreeMap<HandleClass, HeapDecl>,
|
||||
table: &mut LinkTable,
|
||||
) -> Result<DescriptorSetLayout, Error> {
|
||||
for h in heap.values() {
|
||||
let binding = match h.ty {
|
||||
vk::DescriptorType::SAMPLED_IMAGE => 0,
|
||||
vk::DescriptorType::STORAGE_IMAGE => 1,
|
||||
_ => return Err(Unsupported::not_implemented(Feature::IdentityDomains).into()),
|
||||
};
|
||||
for slot in &h.slots {
|
||||
table.bindings.insert(*slot, (1, binding));
|
||||
}
|
||||
}
|
||||
let flags = vk::DescriptorBindingFlags::PARTIALLY_BOUND
|
||||
| vk::DescriptorBindingFlags::UPDATE_AFTER_BIND
|
||||
| vk::DescriptorBindingFlags::UPDATE_UNUSED_WHILE_PENDING;
|
||||
let array = |binding, ty, count| DescriptorBinding {
|
||||
binding,
|
||||
ty,
|
||||
count,
|
||||
stages: vk::ShaderStageFlags::ALL,
|
||||
source: BindingSource::IdentityArray,
|
||||
immutable_sampler: None,
|
||||
flags,
|
||||
variables: 0,
|
||||
immutable_samplers: Vec::new(),
|
||||
};
|
||||
Ok(DescriptorSetLayout {
|
||||
set: 1,
|
||||
bindings: vec![
|
||||
array(
|
||||
0,
|
||||
vk::DescriptorType::SAMPLED_IMAGE,
|
||||
IDENTITY_SAMPLED_IMAGES,
|
||||
),
|
||||
array(
|
||||
1,
|
||||
vk::DescriptorType::STORAGE_IMAGE,
|
||||
IDENTITY_STORAGE_IMAGES,
|
||||
),
|
||||
],
|
||||
flags: vk::DescriptorSetLayoutCreateFlags::UPDATE_AFTER_BIND_POOL,
|
||||
})
|
||||
}
|
||||
|
||||
/// The features a set-1 array of descriptor type `ty` needs in its layout that `p` lacks (the
|
||||
/// module docs), in the order they are refused: `runtimeDescriptorArray`,
|
||||
/// `descriptorBindingPartiallyBound`, then the type's update-after-bind feature. `None` for a type
|
||||
|
||||
@@ -1069,7 +1069,9 @@ pub enum PushField {
|
||||
/// Residual bind offset of a descriptor-form slot: the bind offset minus the descriptor base,
|
||||
/// modulo 2^32.
|
||||
SlotBindOffset(SlotRef),
|
||||
/// Guest base address of a static-root slot.
|
||||
/// Guest base address of a static-root slot. Under the identity domains, a `u64`: a buffer
|
||||
/// slot's device address (its `gpuAddress` plus the bind offset), and a texture slot's
|
||||
/// `gpuResourceID` (`docs/RESOURCE-ID.md`), 0 for nil.
|
||||
SlotGuestBase(SlotRef),
|
||||
/// Stride of a pulled vertex buffer layout.
|
||||
VertexBufferStride(u32),
|
||||
|
||||
@@ -17,7 +17,13 @@
|
||||
//! - A kernel's partial-threadgroups variant (`partial`, generated) dispatched at its whole
|
||||
//! threadgroup size over a ragged grid, its pushed region flagged `NONUNIFORM`, answers each
|
||||
//! edge threadgroup's own size, and its invocations past the grid store nothing.
|
||||
//! - A kernel that reads a texture (`engine/a2_dynamic_texel_offset`) is still refused as
|
||||
//! - A kernel's texture slots (`tex`, generated: a read, a write, a width and an `is_null_texture`)
|
||||
//! are the elements of the two fixed set-1 arrays at the indices their pushed resource IDs hold,
|
||||
//! with no descriptor of their own. It passes L3 and, on the CPU interpreter, reads and writes
|
||||
//! the textures there, answers the width and `is_null_texture` by the index (0 for nil), and,
|
||||
//! where the shader checks reads (no `robustImageAccess2`), takes a format's missing alpha out of
|
||||
//! bounds from the word, as `tests/resource_words.tsv` gives it.
|
||||
//! - A kernel that samples a texture (`engine/a2_dynamic_texel_offset`) is still refused as
|
||||
//! `Unsupported{IdentityDomains}`, not implemented, where the default domains compile it.
|
||||
//!
|
||||
//! `llvm-as` assembles the kernels; without it the tests skip visibly.
|
||||
@@ -25,18 +31,25 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use crate::device::profile::{HandleDomain, PointerDomain};
|
||||
use crate::device::DevicePolicy;
|
||||
use crate::device::profile::{DeviceProfile, HandleDomain, PointerDomain};
|
||||
use crate::device::requirements::VkFeature;
|
||||
use crate::device::{Device, DeviceDescription, DevicePolicy};
|
||||
use crate::error::{Error, Feature, Needs};
|
||||
use crate::lower::dispatch::{region_bytes, NONUNIFORM};
|
||||
use crate::lower::select::{LowerInputs, Plan};
|
||||
use crate::metal::resource_word::TextureWord;
|
||||
use crate::metal::{PixelFormat, TextureSwizzleChannels};
|
||||
use crate::pipeline::facts::RuntimeFact;
|
||||
use crate::pipeline::interface::PushLoc;
|
||||
use crate::pipeline::sym::{Axis, PushField, SlotClass, SlotRef, SpecKey, Stage};
|
||||
use crate::pipeline::layout::BindingSource;
|
||||
use crate::pipeline::link::{link, LinkInputs};
|
||||
use crate::pipeline::sym::{Axis, PushField, ResourceSlot, SlotClass, SlotRef, SpecKey, Stage};
|
||||
use crate::pipeline::testing::{
|
||||
compile, compile_kept, compile_with, engine_dir, link_and_validate, llvm_assemble, profile,
|
||||
typed_module_with, AssembleError,
|
||||
};
|
||||
use crate::spirv::interp::{run, Buffer, Config, Resources};
|
||||
use crate::spirv::interp::{run, run_with_images, Buffer, Config, Image, Resources};
|
||||
use crate::vk;
|
||||
|
||||
/// Profiles with `bufferDeviceAddress` and `shaderInt64`.
|
||||
const PROFILES: [&str; 2] = ["lavapipe", "moltenvk-m3"];
|
||||
@@ -220,9 +233,9 @@ fn a_buffer_kernel_reads_each_slot_at_its_pushed_device_address() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A kernel that reads a texture is not lowered under the identity domains yet.
|
||||
/// A kernel that samples a texture is not lowered under the identity domains yet.
|
||||
#[test]
|
||||
fn a_texture_kernel_is_refused_under_the_identity_domains() {
|
||||
fn a_sampling_kernel_is_refused_under_the_identity_domains() {
|
||||
let Some(bc) = assemble("a2_dynamic_texel_offset") else {
|
||||
return;
|
||||
};
|
||||
@@ -244,6 +257,288 @@ fn a_texture_kernel_is_refused_under_the_identity_domains() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `gpuResourceID` high word of a texture of pixel format `pf` with the identity swizzle, from the test vectors (`docs/RESOURCE-ID.md`), checked against
|
||||
/// `TextureWord::of`: the word the runtime writes.
|
||||
fn vector_word(pf: PixelFormat) -> u32 {
|
||||
let format = pf.as_raw();
|
||||
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/resource_words.tsv");
|
||||
let text = std::fs::read_to_string(path).expect("resource_words.tsv");
|
||||
let row = format!("texture\t{format}\t2\t3\t4\t5\t");
|
||||
let line = text
|
||||
.lines()
|
||||
.find(|l| l.starts_with(&row))
|
||||
.unwrap_or_else(|| panic!("no vector for format {format}"));
|
||||
let word = u32::from_str_radix(line[row.len()..].trim_start_matches("0x"), 16).expect("hex");
|
||||
let of = TextureWord::of(pf, TextureSwizzleChannels::DEFAULT).expect("a word");
|
||||
assert_eq!(of, TextureWord(word), "format {format}");
|
||||
word
|
||||
}
|
||||
|
||||
/// A kernel over a `5 × 2` grid that reads `src` (texture 0) at its position, writes the texel to
|
||||
/// `dst` (texture 1) there, and stores, at word `2 · (y · 5 + x)` of `out`, `src`'s width with
|
||||
/// `is_null_texture(other)` (texture 2) in bit 16, and the texel's alpha bits in the next word.
|
||||
fn texture_kernel() -> String {
|
||||
"target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32\"\n\
|
||||
target triple = \"air64_v28-apple-macosx26.0.0\"\n\n\
|
||||
define void @tex(ptr addrspace(1) %0, ptr addrspace(1) %1, ptr addrspace(1) %2, ptr addrspace(1) noundef \"air-buffer-no-alias\" %3, <2 x i32> noundef %4) {\n\
|
||||
entry:\n\
|
||||
%s = tail call ptr addrspace(2) @air.get_read_sampler()\n\
|
||||
%r = tail call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) %0, ptr addrspace(2) %s, <2 x i32> %4, <2 x i32> zeroinitializer, i32 0, i32 1)\n\
|
||||
%v = extractvalue { <4 x float>, i8 } %r, 0\n\
|
||||
tail call void @air.write_texture_2d.v4f32(ptr addrspace(1) %1, <2 x i32> %4, <4 x float> %v, i32 0, i32 2)\n\
|
||||
%w = tail call i32 @air.get_width_texture_2d(ptr addrspace(1) %0, i32 0)\n\
|
||||
%n = tail call i1 @air.is_null_texture_2d(ptr addrspace(1) %2)\n\
|
||||
%nz = zext i1 %n to i32\n\
|
||||
%ns = shl i32 %nz, 16\n\
|
||||
%q = or i32 %w, %ns\n\
|
||||
%a = extractelement <4 x float> %v, i64 3\n\
|
||||
%ab = bitcast float %a to i32\n\
|
||||
%tx = extractelement <2 x i32> %4, i64 0\n\
|
||||
%ty = extractelement <2 x i32> %4, i64 1\n\
|
||||
%row = mul i32 %ty, 5\n\
|
||||
%idx = add i32 %row, %tx\n\
|
||||
%i0 = shl i32 %idx, 1\n\
|
||||
%i1 = or i32 %i0, 1\n\
|
||||
%e0 = zext i32 %i0 to i64\n\
|
||||
%e1 = zext i32 %i1 to i64\n\
|
||||
%p0 = getelementptr inbounds i32, ptr addrspace(1) %3, i64 %e0\n\
|
||||
%p1 = getelementptr inbounds i32, ptr addrspace(1) %3, i64 %e1\n\
|
||||
store i32 %q, ptr addrspace(1) %p0, align 4\n\
|
||||
store i32 %ab, ptr addrspace(1) %p1, align 4\n\
|
||||
ret void\n\
|
||||
}\n\n\
|
||||
declare ptr addrspace(2) @air.get_read_sampler()\n\
|
||||
declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1), ptr addrspace(2), <2 x i32>, <2 x i32>, i32, i32)\n\
|
||||
declare void @air.write_texture_2d.v4f32(ptr addrspace(1), <2 x i32>, <4 x float>, i32, i32)\n\
|
||||
declare i32 @air.get_width_texture_2d(ptr addrspace(1), i32)\n\
|
||||
declare i1 @air.is_null_texture_2d(ptr addrspace(1))\n\n\
|
||||
!air.kernel = !{!9}\n!air.version = !{!17}\n!air.language_version = !{!18}\n\
|
||||
!9 = !{ptr @tex, !10, !11}\n!10 = !{}\n!11 = !{!12, !13, !14, !15, !16}\n\
|
||||
!12 = !{i32 0, !\"air.texture\", !\"air.location_index\", i32 0, i32 1, !\"air.read\", !\"air.arg_type_name\", !\"texture2d<float, read>\", !\"air.arg_name\", !\"src\"}\n\
|
||||
!13 = !{i32 1, !\"air.texture\", !\"air.location_index\", i32 1, i32 1, !\"air.write\", !\"air.arg_type_name\", !\"texture2d<float, write>\", !\"air.arg_name\", !\"dst\"}\n\
|
||||
!14 = !{i32 2, !\"air.texture\", !\"air.location_index\", i32 2, i32 1, !\"air.read\", !\"air.arg_type_name\", !\"texture2d<float, read>\", !\"air.arg_name\", !\"other\"}\n\
|
||||
!15 = !{i32 3, !\"air.buffer\", !\"air.location_index\", i32 0, i32 1, !\"air.read_write\", !\"air.address_space\", i32 1, !\"air.arg_type_size\", i32 4, !\"air.arg_type_align_size\", i32 4, !\"air.arg_type_name\", !\"uint\", !\"air.arg_name\", !\"out\"}\n\
|
||||
!16 = !{i32 4, !\"air.thread_position_in_grid\", !\"air.arg_type_name\", !\"uint2\", !\"air.arg_name\", !\"tid\"}\n\
|
||||
!17 = !{i32 2, i32 8, i32 0}\n!18 = !{!\"Metal\", i32 4, i32 0, i32 0}\n"
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// `stem`'s committed profile under the identity domains, without `drop`.
|
||||
fn identity_without(stem: &str, drop: &[VkFeature]) -> DeviceProfile {
|
||||
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../metal2vulkan-validation/profiles")
|
||||
.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");
|
||||
for f in drop {
|
||||
desc.features.remove(f);
|
||||
}
|
||||
Device::new(desc, identity())
|
||||
.expect("device")
|
||||
.profile()
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// A texture slot's push field: its resource ID, the index in the low word and the word in the
|
||||
/// high one.
|
||||
fn resource_id(index: u32, word: u32) -> u64 {
|
||||
u64::from(index) | u64::from(word) << 32
|
||||
}
|
||||
|
||||
/// A `w × h` image of `slot` at element `element`, its texels `texel(x, y)`, and robust with
|
||||
/// `robust`.
|
||||
fn texture(
|
||||
slot: ResourceSlot,
|
||||
element: u32,
|
||||
[w, h]: [u32; 2],
|
||||
texel: impl Fn(u32, u32) -> [u32; 4],
|
||||
robust: Option<[u32; 4]>,
|
||||
) -> Image {
|
||||
let mut img = Image::new(slot, [w, h, 1], 1, 1, 1);
|
||||
img.element = element;
|
||||
img.texels = (0..h)
|
||||
.flat_map(|y| (0..w).map(move |x| (x, y)))
|
||||
.map(|(x, y)| texel(x, y))
|
||||
.collect();
|
||||
img.robust = robust;
|
||||
img
|
||||
}
|
||||
|
||||
/// A kernel's texture slots under the identity domains are elements of the two fixed set-1
|
||||
/// arrays at the indices their pushed resource IDs hold: it reads and writes them there, queries
|
||||
/// their size, answers `is_null_texture` by the index, and takes a format's missing alpha out of
|
||||
/// bounds from the word, as the test vectors give it.
|
||||
#[test]
|
||||
fn texture_slots_are_the_set_1_elements_their_pushed_resource_ids_name() {
|
||||
let Some(bc) = assemble_text("tex", &texture_kernel()) else {
|
||||
return;
|
||||
};
|
||||
const L: [u32; 3] = [5, 2, 1];
|
||||
// `src` at index 3 of the sampled array, `dst` at index 2 of the storage array, `other` at
|
||||
// index 1 or nil; the elements below theirs are other textures.
|
||||
const SRC: u32 = 3;
|
||||
const DST: u32 = 2;
|
||||
let rgba = vector_word(PixelFormat::RGBA8Unorm);
|
||||
let red = vector_word(PixelFormat::R8Unorm);
|
||||
let f = |v: f32| v.to_bits();
|
||||
let src_texel = |x: u32, y: u32| {
|
||||
[
|
||||
f((x + 1) as f32),
|
||||
f((y + 1) as f32),
|
||||
f(0.5),
|
||||
f((y * 4 + x + 1) as f32 / 8.0),
|
||||
]
|
||||
};
|
||||
let filler = |_: u32, _: u32| [0xdead_beef; 4];
|
||||
let mut profiles: Vec<(String, DeviceProfile)> = PROFILES
|
||||
.iter()
|
||||
.map(|stem| {
|
||||
let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}"));
|
||||
(stem.to_string(), p)
|
||||
})
|
||||
.collect();
|
||||
// Without `robustImageAccess2` the shader clamps the read and selects Metal's out-of-bounds
|
||||
// texel, whose alpha the word says; the images then trap on any access outside them.
|
||||
profiles.push((
|
||||
"moltenvk-m3 without robustImageAccess2".to_string(),
|
||||
identity_without("moltenvk-m3", &[VkFeature::RobustImageAccess2]),
|
||||
));
|
||||
for (stem, p) in &profiles {
|
||||
let checked = !p.fields().images.robust_image_access2;
|
||||
let (a, plan, module) =
|
||||
compile_kept(&bc, "tex", p).unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
link_and_validate(&a, p).unwrap_or_else(|e| panic!("{stem}: L3: {e}"));
|
||||
assert!(
|
||||
a.interface
|
||||
.spec
|
||||
.iter()
|
||||
.all(|c| !matches!(c.key, SpecKey::Presence(_) | SpecKey::OutOfBoundsAlpha(_))),
|
||||
"{stem}"
|
||||
);
|
||||
assert!(
|
||||
!plan.facts.iter().any(|f| matches!(
|
||||
f,
|
||||
RuntimeFact::ResourcePresence { .. } | RuntimeFact::OutOfBoundsAlpha { .. }
|
||||
)),
|
||||
"{stem}"
|
||||
);
|
||||
// Set 1 is the fixed pair of arrays; each class the kernel declares is a variable of its
|
||||
// descriptor type's binding, and set 0 holds nothing.
|
||||
let linked = link(&[&a], &LinkInputs::standalone(), p).unwrap_or_else(|e| panic!("{e}"));
|
||||
let sets: Vec<_> = (linked.layout.sets.iter())
|
||||
.map(|s| {
|
||||
let b: Vec<_> = (s.bindings.iter())
|
||||
.map(|b| (b.binding, b.ty, b.count, b.source))
|
||||
.collect();
|
||||
(s.set, b)
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
sets,
|
||||
[
|
||||
(0, vec![]),
|
||||
(
|
||||
1,
|
||||
vec![
|
||||
(
|
||||
0,
|
||||
vk::DescriptorType::SAMPLED_IMAGE,
|
||||
65_536,
|
||||
BindingSource::IdentityArray
|
||||
),
|
||||
(
|
||||
1,
|
||||
vk::DescriptorType::STORAGE_IMAGE,
|
||||
4_096,
|
||||
BindingSource::IdentityArray
|
||||
),
|
||||
]
|
||||
)
|
||||
],
|
||||
"{stem}"
|
||||
);
|
||||
let class = |binding: u32| {
|
||||
let mut s = (linked.table.bindings.iter()).filter(|(_, b)| **b == (1, binding));
|
||||
let (slot, _) = s
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("{stem}: no class at {binding}"));
|
||||
assert!(s.next().is_none(), "{stem}: two classes at {binding}");
|
||||
*slot
|
||||
};
|
||||
let (sampled, storage) = (class(0), class(1));
|
||||
// Two dispatches: `src` of a format without alpha and `other` nil, then `src` with alpha
|
||||
// and `other` bound.
|
||||
for (word, other, alpha) in [(red, 0, 1.0f32), (rgba, resource_id(1, rgba), 0.0)] {
|
||||
let oob = [0, 0, 0, f(alpha)];
|
||||
let robust = (!checked).then_some(oob);
|
||||
let mut push = vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)];
|
||||
let mut fields = Vec::new();
|
||||
for field in &plan.push.fields {
|
||||
let PushLoc::Push { offset } = field.loc else {
|
||||
panic!("{stem}: {field:?} spilled");
|
||||
};
|
||||
let o = offset as usize;
|
||||
let bytes = match field.field {
|
||||
PushField::SlotGuestBase(s) => match (s.class, s.index) {
|
||||
(SlotClass::Buffer, 0) => OUT,
|
||||
(SlotClass::Texture, 0) => resource_id(SRC, word),
|
||||
(SlotClass::Texture, 1) => resource_id(DST, rgba),
|
||||
(SlotClass::Texture, 2) => other,
|
||||
_ => panic!("{stem}: unexpected slot {s:?}"),
|
||||
},
|
||||
PushField::DispatchRegion => {
|
||||
let region = region_bytes([0; 3], L, L).expect("packs");
|
||||
push[o..o + 32].copy_from_slice(®ion);
|
||||
fields.push(field.field);
|
||||
continue;
|
||||
}
|
||||
_ => panic!("{stem}: unexpected push field {field:?}"),
|
||||
};
|
||||
push[o..o + 8].copy_from_slice(&bytes.to_le_bytes());
|
||||
fields.push(field.field);
|
||||
}
|
||||
assert_eq!(fields.len(), 5, "{stem}: {fields:?}");
|
||||
let mut images: Vec<Image> = (0..SRC)
|
||||
.map(|e| texture(sampled, e, [1, 1], filler, None))
|
||||
.collect();
|
||||
images.push(texture(sampled, SRC, [4, 2], src_texel, robust));
|
||||
images.extend((0..DST).map(|e| texture(storage, e, [1, 1], filler, None)));
|
||||
images.push(texture(storage, DST, [5, 2], |_, _| [0; 4], None));
|
||||
let res = Resources {
|
||||
buffers: vec![Buffer {
|
||||
slot: None,
|
||||
address: Some(OUT),
|
||||
bytes: vec![0; 4 * 21],
|
||||
}],
|
||||
push,
|
||||
spec: local_size3(L),
|
||||
};
|
||||
let (got, images) = run_with_images(&module, &Config::default(), res, images)
|
||||
.unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
let read = |x: u32, y: u32| match x < 4 {
|
||||
true => src_texel(x, y),
|
||||
false => oob,
|
||||
};
|
||||
let mut want = Vec::new();
|
||||
for y in 0..2 {
|
||||
for x in 0..5 {
|
||||
let null = u32::from(other == 0);
|
||||
want.extend_from_slice(&(4 | null << 16).to_le_bytes());
|
||||
want.extend_from_slice(&read(x, y)[3].to_le_bytes());
|
||||
}
|
||||
}
|
||||
want.extend_from_slice(&[0; 4]);
|
||||
assert_eq!(got.buffers[0], want, "{stem}: out, alpha {alpha}");
|
||||
let dst = &images[(SRC + 1 + DST) as usize];
|
||||
let written: Vec<[u32; 4]> = (0..2)
|
||||
.flat_map(|y| (0..5).map(move |x| (x, y)))
|
||||
.map(|(x, y)| read(x, y))
|
||||
.collect();
|
||||
assert_eq!(dst.texels, written, "{stem}: dst, alpha {alpha}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The read buffers of [`many`]: with its output, 21 slot addresses of 8 bytes, past the window.
|
||||
const READS: u32 = 20;
|
||||
|
||||
|
||||
@@ -12770,6 +12770,7 @@ variant metal2vulkan-rt::PrecisionNote::AnisotropicFilter AnisotropicFilter
|
||||
variant metal2vulkan-rt::PrecisionNote::ArgumentPixelSamplerScaling ArgumentPixelSamplerScaling
|
||||
variant metal2vulkan-rt::PrecisionNote::BicubicFilterArithmetic BicubicFilterArithmetic
|
||||
variant metal2vulkan-rt::PrecisionNote::BlendedWriteRounding BlendedWriteRounding
|
||||
variant metal2vulkan-rt::PrecisionNote::CappedLodBias CappedLodBias
|
||||
variant metal2vulkan-rt::PrecisionNote::ClippedCoverageSplit ClippedCoverageSplit
|
||||
variant metal2vulkan-rt::PrecisionNote::ColorAttachmentGroups ColorAttachmentGroups
|
||||
variant metal2vulkan-rt::PrecisionNote::ComputedSampleDepth ComputedSampleDepth
|
||||
@@ -15537,6 +15538,7 @@ variant metal2vulkan::pipeline::BindingSource::CombinedTextureSampler CombinedTe
|
||||
variant metal2vulkan::pipeline::BindingSource::ExtendedShadow ExtendedShadow(u32)
|
||||
variant metal2vulkan::pipeline::BindingSource::Heap Heap(HandleClass)
|
||||
variant metal2vulkan::pipeline::BindingSource::HeapSampler HeapSampler { stage: Stage, sampler: CombinedSampler }
|
||||
variant metal2vulkan::pipeline::BindingSource::IdentityArray IdentityArray
|
||||
variant metal2vulkan::pipeline::BindingSource::InputAttachment InputAttachment(u32)
|
||||
variant metal2vulkan::pipeline::BindingSource::Sampler Sampler(SlotRef)
|
||||
variant metal2vulkan::pipeline::BindingSource::SamplerArray SamplerArray { stage: Stage, compare: bool, integer: bool }
|
||||
|
||||
|
Can't render this file because it is too large.
|
+11
-2
@@ -117,8 +117,17 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
|
||||
the window always holds. A kernel that reads a grid builtin reads `PushField::DispatchRegion` on
|
||||
every dispatch, with no `MultiRegion` constant: a dispatch the host knows states Metal's grid
|
||||
and its piece's first threadgroup there, and an indirect dispatch a zero grid, whose kernel
|
||||
takes `NumWorkgroups` times its workgroup size. So far they lower a kernel that reaches memory
|
||||
only through its buffer slots; any other function is refused as `Unsupported{IdentityDomains}`.
|
||||
takes `NumWorkgroups` times its workgroup size. A texture slot's `gpuResourceID` is pushed as
|
||||
its `PushField::SlotGuestBase`, and its texture is the element at the ID's index of set 1's two
|
||||
fixed arrays, the same layout for every pipeline ([RESOURCE-ID.md](RESOURCE-ID.md)); it binds no
|
||||
descriptor of its own and declares no specialization constant. No binder chooses a variant
|
||||
there: a slot reads whatever texture its ID names through the plain form, its `float` or `half`
|
||||
reads take the device's sRGB decode with `PrecisionNote::SrgbTexelDecode`, as a heap element's
|
||||
do, and no texture is sparse (the consumer refuses a sparse texture). So far they lower a
|
||||
kernel that reaches memory through its buffer slots and reads, writes, sizes or tests for nil
|
||||
its texture slots. Any other function is refused as `Unsupported{IdentityDomains}`: one that samples, uses
|
||||
an argument buffer's textures, a texture buffer, a slot's levels or swizzle, a two-plane,
|
||||
extended-range or sRGB-twin form, or any other state of a bound texture beyond its ID.
|
||||
- **The model's linear sample of planes read in place** (`YCbCrInPlacePolicy::Model`, the
|
||||
default; changes emitted code). On an integrated GPU or a CPU device a function that only
|
||||
samples, gathers or sizes a `YCBCR8_420_2P` or `YCBCR10_420_2P` texture reads its planes' codes
|
||||
|
||||
+2
-2
@@ -143,7 +143,7 @@ Columns:
|
||||
| `RasterizationRateMap` | | devices without VkFeature::MultiViewport; devices without VkFeature::ShaderDrawParameters; devices without VkFeature::ShaderOutputViewportIndex; devices without VkLimit::MaxGeometryTotalOutputComponents; devices without a capability the site computes; devices without a capability the site computes (`vec![Capability::Feature(lacks)]`); every device (not implemented) | `ours` | 10: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_copy, 3 sites)`, `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)` (+3) | `rare`: rasterization rate maps |
|
||||
| `GpuEncodedIndirectCommands` | | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism); every device (not implemented) | `ours` | 20: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`, `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)` (+13) | `rare`: indirect command buffers encoded by a kernel |
|
||||
| `VulkanVersion` | The device's Vulkan version is below the 1.2 floor | devices without ApiVersion::V1_2 | `device` | 2: `crates/metal2vulkan/src/ash_interop/query.rs (query)`, `crates/metal2vulkan/src/device/derive.rs (derived)` | `none`: a device below Vulkan 1.2 |
|
||||
| `IdentityDomains` | The identity pointer and handle domains (`PointerDomain::Identity`, `HandleDomain::Identity`) | devices without a capability the site computes (`all`); every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`, `crates/metal2vulkan/src/lower/select.rs (identity_admits)` | `none`: the identity domains, which the new runtime alone takes and which lower only kernels over buffer slots so far |
|
||||
| `IdentityDomains` | The identity pointer and handle domains (`PointerDomain::Identity`, `HandleDomain::Identity`) | devices without a capability the site computes (`all`); every device (not implemented) | `ours` | 4: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`, `crates/metal2vulkan/src/lower/select.rs (identity_admits)` (+2) | `none`: the identity domains, which the new runtime alone takes and which lower only kernels over buffer slots and unsampled texture slots so far |
|
||||
| `Constant` | A constants-block record LLVM defines that the typed model has no form for (a block address, a `select` and the other constant expressions of... | - | `-` | via a helper: 3: `crates/metal2vulkan-air/src/bitcode/constants.rs (record, 2 sites)`, `crates/metal2vulkan/src/error/mod.rs (from)` | `none`: LLVM constant forms AIR does not emit |
|
||||
| `Attribute` | An LLVM attribute kind that changes the calling ABI and that AIR does not use (`inalloca`, `preallocated`, `byref`, `nest`, the `swift*` kinds) | - | `-` | via a helper: 2: `crates/metal2vulkan-air/src/bitcode/attrs.rs (known)`, `crates/metal2vulkan/src/error/mod.rs (from)` | `none`: LLVM ABI attributes AIR does not use |
|
||||
| `BitcodeRecord` | A bitcode record LLVM defines in `block` that the typed model does not cover and that has no more specific variant (legacy spellings predating... | - | `-` | via a helper: 8: `crates/metal2vulkan-air/src/bitcode/attrs.rs (decode_lists)`, `crates/metal2vulkan-air/src/bitcode/function.rs (symtab)` (+5) | `none`: bitcode records AIR does not emit |
|
||||
@@ -726,7 +726,7 @@ Each refusal's sites, with the function that builds it.
|
||||
- `feature::RasterizationRateMap`: `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_copy, 3 sites)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (region_viewport, 2 sites)`; `crates/metal2vulkan/src/pipeline/link.rs (region_box)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs (check_limits)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs (fan_plan, 3 sites)`
|
||||
- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/flat.rs (flat_dispatch_module)`; `crates/metal2vulkan/src/bind/replay/merged.rs (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs (needs, 2 sites)`; `crates/metal2vulkan/src/lower/access/encode.rs (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs (plan_replay, 3 sites)`; `crates/metal2vulkan/src/lower/mesh/mod.rs (plan_partial_groups)`; `crates/metal2vulkan/src/lower/select.rs (finish, 2 sites)`; `crates/metal2vulkan/src/lower/simd/divergent.rs (barriers)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (param)`; `crates/metal2vulkan/src/pipeline/compile.rs (analyze_one, 2 sites)`
|
||||
- `feature::VulkanVersion`: `crates/metal2vulkan/src/ash_interop/query.rs (query)`; `crates/metal2vulkan/src/device/derive.rs (derived)`
|
||||
- `feature::IdentityDomains`: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`; `crates/metal2vulkan/src/lower/select.rs (identity_admits)`
|
||||
- `feature::IdentityDomains`: `crates/metal2vulkan/src/device/derive.rs (identity_domains)`; `crates/metal2vulkan/src/lower/select.rs (identity_admits)`; `crates/metal2vulkan/src/lower/texture/slot.rs (storage_format)`; `crates/metal2vulkan/src/pipeline/link.rs (identity_set)`
|
||||
- `feature::Constant`: `crates/metal2vulkan-air/src/bitcode/constants.rs (record, 2 sites)`; `crates/metal2vulkan/src/error/mod.rs (from)`
|
||||
- `feature::Attribute`: `crates/metal2vulkan-air/src/bitcode/attrs.rs (known)`; `crates/metal2vulkan/src/error/mod.rs (from)`
|
||||
- `feature::BitcodeRecord`: `crates/metal2vulkan-air/src/bitcode/attrs.rs (decode_lists)`; `crates/metal2vulkan-air/src/bitcode/function.rs (symtab)`; `crates/metal2vulkan-air/src/bitcode/metadata.rs (decode, 2 sites)`; `crates/metal2vulkan-air/src/bitcode/module.rs (check_bodies)`; `crates/metal2vulkan-air/src/bitcode/module.rs (read)`; `crates/metal2vulkan-air/src/bitcode/module.rs (symtab)`; `crates/metal2vulkan/src/error/mod.rs (from)`
|
||||
|
||||
@@ -26,6 +26,22 @@ the same IDs on every run, and a replay reproduces them.
|
||||
A texture view takes its own index, in the class of its own usage. A texture buffer has no index:
|
||||
it is a typed refusal under these domains.
|
||||
|
||||
## The arrays
|
||||
|
||||
Under the identity domains set 1 has one layout for every pipeline: binding 0 is the sampled-image
|
||||
array of 65,536 elements and binding 1 the storage-image array of 4,096, each partially bound,
|
||||
updated after binding and while unused elements are pending, and seen by every stage. Element `i`
|
||||
of each is the texture whose ID holds index `i`, so the consumer writes an element once, as it
|
||||
makes the texture, for every pipeline. Element 0 is a null descriptor (`nullDescriptor`): a nil
|
||||
texture sizes 0, reads and samples zero, and drops a store, as Metal answers for a nil texture, with
|
||||
no code in the shader. Each texture class a shader declares (its shape, numeric type and depth
|
||||
comparison, sampled, or storage without a format) is a variable of its descriptor type's binding.
|
||||
|
||||
A shader takes a texture slot's ID from the slot's push field (`PushField::SlotGuestBase`). It
|
||||
indexes the arrays with the low word, answers `is_null_texture` by whether the index is 0, and,
|
||||
where it checks a `read` itself (a device without `robustImageAccess2`), takes an out-of-bounds
|
||||
alpha of 1 from bit 12 of the word. Samplers are not lowered under these domains yet.
|
||||
|
||||
## The texture word
|
||||
|
||||
`metal2vulkan::metal::resource_word::TextureWord::of(pixelFormat, swizzle)`:
|
||||
|
||||
@@ -82,7 +82,7 @@ feature Tensors rare shader tensors
|
||||
feature RasterizationRateMap rare rasterization rate maps
|
||||
feature GpuEncodedIndirectCommands rare indirect command buffers encoded by a kernel
|
||||
feature VulkanVersion none a device below Vulkan 1.2
|
||||
feature IdentityDomains none the identity domains, which the new runtime alone takes and which lower only kernels over buffer slots so far
|
||||
feature IdentityDomains none the identity domains, which the new runtime alone takes and which lower only kernels over buffer slots and unsampled texture slots so far
|
||||
feature Constant none LLVM constant forms AIR does not emit
|
||||
feature Attribute none LLVM ABI attributes AIR does not use
|
||||
feature BitcodeRecord none bitcode records AIR does not emit
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 17 and column 65.
|
Reference in new issue
Block a user