🐛 The draw path leaves the same layout hole, on three rails and every boot, and the guard that found it only counted

Pathway: x86 macOS / Linux Vulkan, render path. Companion to 25051457, which
repaired the compute path after a user's host was killed by it.

WHY THIS IS THE SAME BUG

`kb/frag-descriptor-unbound-is-a-real-violation.md` measured this population
already: a fragment module referencing a `set = 0` binding the descriptor set
layout does not contain, 2-3 a boot on macos-14, macos-15 and macos-26, and
fifteen of fifteen answering `Used`. That note named the repair and did not
build it, on the grounds that it "declines no draw and costs no visible guest
work".

That reading is too soft, and 25051457 is why. `engine/exec.rs` builds the
layout from provided resources alone, so an unbound-but-used texture is not an
unwritten descriptor — the binding is absent from the layout entirely. Mesa's
ANV sizes its binding array to `max_binding + 1`, zero-fills every number
nothing declared, and scores each used binding as
`(use_count << 7) / array_size`. The hole divides by zero, so pipeline creation
does not return an error: the host process dies of SIGFPE and takes the VM with
it. On an Intel host every one of those firings is a candidate host kill, on
three rails, on every boot.

WHAT CHANGED

- `draw::frag_unbound_textures_to_neutralize` narrows the guard's existing
  verdict list to the gaps this device can repair: textures, statically used.
  The guard block now yields that list instead of only counting.
- `draw/vulkan.rs` pushes a neutral 1x1 transparent `SampledImageResource` for
  each, at the relocated binding the module actually carries
  (`TEXTURE_BINDING_BASE + index` plus `FRAG_SAMPLED_RESOURCE_BINDING_OFFSET`
  when the fragment sampled band moved), reported on the fail channel as
  `frag_neutral_texture_substituted`.

The shape comes from `reflected_sampled_kind`, asked in the translator's
numbering the way the bind path asks it, so an array or volume sampler gets an
image of its own declared kind — binding a plain 2D view where the shader
samples an array would be a second violation wearing the repair's clothes.
Cube and cube-array have no single-texel neutral this engine builds and are
declined where they are bound too, so those keep the hole and say so by name
(`frag_neutral_texture_shape_unsupported`) rather than being given a shape the
shader did not declare.

Three narrowings, each load-bearing and each covered by the test: textures only
(the sampler class provisions its own default a few lines below, and a storage
buffer has no neutral to invent); `Used` only (`DeclaredUnused` is legal to omit
and must stay omitted or the census cannot separate the populations);
not `Ambiguous` (two variables on one binding is its own defect, and picking one
is a guess).

COST

Nothing on the hot path. The guard already ran per draw and already computed
each gap's `DescriptorUse`; this reuses that verdict rather than adding a second
SPIR-V walk. On a draw that binds what it samples the new vector is empty and
the loop does not execute. Deliberately NOT the compute path's backstop refusal
— that walks the module, which is affordable per dispatch and is not per draw.

VERIFIED

- 1879 tests pass, `--test-threads=1`, backend-vulkan,host-window. One new test
  covers all three narrowings, including the two classes that answer `Used`
  unconditionally from `frag_unbound_static_use` and so are exactly what a
  filter written on the verdict alone would let through.
- Clippy `-D warnings` clean on all three arms (backend-vulkan+host-window,
  the same with an explicit x86_64-unknown-linux-gnu target, and backend-metal
  under --target aarch64-apple-darwin).

NOT VERIFIED

- No live boot, and no boot on the host class that reproduces the crash: this
  dev machine has no Intel GPU. Neither the SIGFPE nor its absence can be
  observed here.
- Not measured on the rails that fire it. macos-14, macos-15 and macos-26 each
  produce 2-3 of these a boot per the kb note, so a driven boot of any of them
  should now show `frag_neutral_texture_substituted` at the same count and the
  desktop unchanged. That reading is owed and not taken.
- Vertex-stage texture gaps are not covered. The scan is fragment-only by an
  older and narrower argument (a vertex `[[buffer(n)]]` may legitimately be a
  stage-in attribute), which is about buffers and does not extend to textures.
  A vertex texture declared, used and unbound would still hole the layout.
- Whether any guest shader depended on the contents of the textures it did not
  bind. The substitute is transparent and 1x1; the fail line is what makes that
  reliance findable.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Anees IqbalandClaude committed 2026-08-11 15:56:22 +03:00
1 parent 25051457a3
commit 71462a94c8
3 files changed
+164 -2

No files matched your search

+32
View File
@@ -503,6 +503,38 @@ impl std::fmt::Display for FragUnbound {
}
}
/// The fragment textures a draw must substitute a neutral image for: the gaps
/// the scan flagged that are textures and that the module *statically uses*.
///
/// Vulkan requires the pipeline layout to contain a descriptor for every
/// statically-used resource, and `engine/exec.rs` builds that layout from
/// provided resources alone — so one of these left alone is not an unwritten
/// descriptor, it is a binding the layout does not mention. Mesa's Intel driver
/// scores each used binding as `(use_count << 7) / array_size` over an array it
/// sized to `max_binding + 1` and zero-filled, so the omission divides by zero
/// and kills the host process inside pipeline creation rather than returning an
/// error. That is why this population has to be filled rather than only counted.
///
/// Three narrowings, each load-bearing:
///
/// - **Textures only.** The sampler class provisions its own default where it
/// binds, and a storage buffer has no neutral this device can invent; both are
/// still reported by the caller.
/// - **[`DescriptorUse::Used`] only.** A declared-and-never-referenced variable
/// is legal to omit and must stay omitted, or the census that separated those
/// two populations cannot tell them apart any more.
/// - **Not `Ambiguous`.** Two variables on one binding is its own defect and is
/// not repaired by picking one of them; `is_violation` already excludes it.
#[cfg(feature = "backend-vulkan")]
fn frag_unbound_textures_to_neutralize(
uses: &[(FragUnbound, crate::runtime::spirv_bind::DescriptorUse)],
) -> Vec<u32> {
uses.iter()
.filter(|(gap, use_)| use_.is_violation() && gap.class == FragUnboundClass::Texture)
.map(|(gap, _)| gap.metal_index)
.collect()
}
/// One pass over the fragment reflection classifying the two bind gaps the render
/// path cannot recover from. Returns `(unbound, embedded)`:
/// - **`unbound`** — standard directly-bound kinds (`[[buffer(n)]]` /
@@ -5876,3 +5876,40 @@ fn a_depth_attachment_is_keyed_on_the_guest_texture_the_pass_bound() {
"and neither does a pass with no depth attachment at all"
);
}
/// Only a texture gap the fragment module statically uses is substituted for.
///
/// The three narrowings are the whole content of the rule and each one fails in
/// a different direction. Filling a `DeclaredUnused` gap pays a descriptor for a
/// variable nothing references and destroys the census that separated it from a
/// real violation; filling an `Ambiguous` one picks between two variables on a
/// binding, which is a guess; filling a buffer or sampler gap invents a resource
/// where the caller either has its own default or has no neutral at all. Leaving
/// a `Used` texture gap alone is the one that kills the host process, because
/// Mesa's Intel driver divides `(use_count << 7)` by the array size its own
/// zero-fill gave the binding the layout never declared.
#[test]
#[cfg(feature = "backend-vulkan")]
fn only_a_statically_used_texture_gap_is_given_a_neutral_image() {
use crate::runtime::spirv_bind::DescriptorUse;
let gap = |class, metal_index| FragUnbound { class, metal_index };
let uses = vec![
(gap(FragUnboundClass::Texture, 3), DescriptorUse::Used),
(
gap(FragUnboundClass::Texture, 4),
DescriptorUse::DeclaredUnused,
),
(gap(FragUnboundClass::Texture, 5), DescriptorUse::Ambiguous),
(gap(FragUnboundClass::Texture, 6), DescriptorUse::NotDeclared),
// Both other classes answer `Used` unconditionally from
// `frag_unbound_static_use`, so they are exactly the case that would slip
// through a filter written on the verdict alone.
(gap(FragUnboundClass::Buffer, 7), DescriptorUse::Used),
(gap(FragUnboundClass::Sampler, 8), DescriptorUse::Used),
];
assert_eq!(frag_unbound_textures_to_neutralize(&uses), vec![3]);
// Nothing flagged, nothing substituted — the hot path.
assert!(frag_unbound_textures_to_neutralize(&[]).is_empty());
}
+95 -2
View File
@@ -5525,7 +5525,10 @@ fn try_metal2vulkan_draw<M: HostMemory + HostOps>(
// Verified non-flooding: 0 fires across a full x86 boot (desktop convergence
// + Safari + CSS gradients + a 23-binding compositor shader), so any fire is
// a genuine bind gap, not expected control flow.
{
// The guard below reports; its value is the population the repair after
// the texture loop acts on. Empty on every draw that binds what it
// samples, which is the hot path.
let frag_unbound_used_textures: Vec<u32> = {
// Membership predicates over the (tiny) provided-resource slices — the
// scan allocates nothing on the all-bound hot path (both result Vecs
// stay empty). The `frag_embedded_*` reason names a DIFFERENT silent
@@ -5618,7 +5621,14 @@ fn try_metal2vulkan_draw<M: HostMemory + HostOps>(
req.pipeline_ref, w, h
));
}
}
// Textures only, and violations only. A buffer or sampler gap is
// reported above and not repaired here: the sampler class already
// provisions its own default further down, and a storage buffer gap
// has no neutral this device can invent. `DeclaredUnused` is legal
// to omit and must stay omitted, or the census this block exists to
// keep cannot tell the two populations apart.
frag_unbound_textures_to_neutralize(&uses)
};
// Framebuffer fetch (`air.render_target` INPUT param `dest_N` →
// reflection `ColorInput` at binding 96+N): the engine supports the
@@ -5920,6 +5930,89 @@ fn try_metal2vulkan_draw<M: HostMemory + HostOps>(
push_tex(t.index, t.texture_ref, true)?;
}
}
// Repair the gaps the guard found. A fragment texture the module
// statically uses and this draw did not bind is absent from the
// descriptor set layout *entirely* — `engine/exec.rs` builds the layout
// from provided resources alone, so it is not an unwritten slot in a
// layout that has the binding. Vulkan requires a descriptor for every
// statically-used resource, and on Mesa's Intel driver the omission is
// fatal rather than undefined: it sizes its binding array to
// `max_binding + 1`, zero-fills every number nothing declared, and
// scores each *used* binding as `(use_count << 7) / array_size`, so the
// hole divides by zero and the host process dies of `SIGFPE` inside
// pipeline creation with nothing returned for this device to decline on.
//
// Cold path: the vector is empty on every draw that binds what it
// samples, so this costs one `is_empty` on the hot path.
for &index in &frag_unbound_used_textures {
use crate::runtime::spirv_bind::{ReflectedSampledKind, SampledImageKind};
let base_off = if separate_sampled {
FRAG_SAMPLED_RESOURCE_BINDING_OFFSET
} else {
0
};
let img_bind = TEXTURE_BINDING_BASE + index + base_off;
if images.iter().any(|img| img.binding == img_bind) {
continue;
}
// The shape has to be the one the module declared: a plain 2D view
// bound where the shader samples an array is a different violation,
// not a repair. The reflection is asked in the translator's
// numbering, which is what `reflected_sampled_kind` takes — the
// relocation above applies to the SPIR-V, not to the signature.
let kind = match crate::runtime::spirv_bind::reflected_sampled_kind(
&f_shader.reflection,
TEXTURE_BINDING_BASE + index,
) {
ReflectedSampledKind::Kind(k) => k,
ReflectedSampledKind::Absent | ReflectedSampledKind::Unsupported => {
SampledImageKind::D2
}
};
let Some(shape) = sampled_image_shape(kind) else {
// Cube and cube-array need six faces, and this engine declines
// them where they are bound too. The hole stays and is named,
// rather than papered over with a shape the shader did not
// declare — which would be a second violation wearing the
// repair's clothes.
crate::observe::fail(format!(
"shader_resource_declared_unbound \
reason=frag_neutral_texture_shape_unsupported \
pipe={} idx={index} binding={img_bind} kind={kind:?}",
req.pipeline_ref
));
continue;
};
// A repair that succeeded, not a success: the shader samples a
// texture whose contents this device invented, so it stays on the
// fail channel and the reliance stays measurable.
crate::observe::fail(format!(
"shader_resource_declared_unbound \
reason=frag_neutral_texture_substituted \
pipe={} idx={index} binding={img_bind} kind={kind:?} 1x1",
req.pipeline_ref
));
images.push(crate::backend::vulkan::engine::SampledImageResource {
binding: img_bind,
width: 1,
height: 1,
layers: shape.layers,
arrayed: shape.arrayed,
volume: shape.volume,
cube: shape.cube,
one_dim: shape.one_dim,
source: crate::backend::vulkan::engine::SampledSource::Bytes(
std::sync::Arc::new(crate::contract::pixel_format::solid_rgba8(
1,
1,
&[0.0; 4],
)),
),
format: ash::vk::Format::R8G8B8A8_UNORM,
identity: None,
swizzle: Default::default(),
});
}
{
let mut push_smp = |index: u32,
sampler_ref: u32,