diff --git a/crates/metal2vulkan-validation/src/candidate/engine/tests.rs b/crates/metal2vulkan-validation/src/candidate/engine/tests.rs index cd477aebd..dfeec9ecc 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine/tests.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine/tests.rs @@ -2758,7 +2758,8 @@ fn a_plain_draw_and_only_one_runs_through_the_runtime() { }; assert!(runs_render_through_runtime(&authored, &unrasterized)); // An attribute buffer's out-of-bounds target draws through the runtime, whose facts refuse or - // run it (`runtime_bounds::drawn`); an index buffer's stays on the executor's own context. + // run it (`runtime_bounds::drawn`); no other target does (an index buffer's case carries the + // runtime's limit, `index_buffer_past_end`, which stops it before either context). use crate::case::out_of_bounds::ContainmentForm; let bounded = |resource, form| RenderCase { out_of_bounds: vec![OutOfBoundsTarget { diff --git a/crates/metal2vulkan-validation/src/executor_contract.rs b/crates/metal2vulkan-validation/src/executor_contract.rs index d70656f72..3d707e47a 100644 --- a/crates/metal2vulkan-validation/src/executor_contract.rs +++ b/crates/metal2vulkan-validation/src/executor_contract.rs @@ -19,6 +19,7 @@ use crate::air::reflect::{ ResourceKind, ShaderInterface, ShaderStage, TextureDimension, TextureFormat as ReflectedTextureFormat, }; +use crate::case::out_of_bounds::OutOfBoundsResource; use crate::case::{ AuthoredCase, DeviceBufferArrayResource, OutputSelection, Primitive, Stage, TextureFormat, ThreadgroupMemoryResource, @@ -787,7 +788,8 @@ pub fn engine_source_requirements(reflection: &ShaderInterface) -> BTreeSet BTreeSet { let render = matches!(case.stage, Stage::Vertex | Stage::Fragment); let drawn = render || case.stage.is_mesh_pipeline_stage(); @@ -836,6 +838,15 @@ pub fn case_requirements(case: &AuthoredCase) -> BTreeSet { case.is_rasterization_disabled_vertex() && !case.render_targets.is_empty(), ToolingRequirement::RasterizationDisabledRenderTarget, ), + ( + case.out_of_bounds.iter().any(|declaration| { + declaration + .targets + .iter() + .any(|target| target.resource == OutOfBoundsResource::IndexBuffer) + }), + ToolingRequirement::IndexBufferPastEnd, + ), ] .into_iter() .filter_map(|(present, requirement)| present.then_some(requirement)) @@ -2918,6 +2929,34 @@ entry: vertex.stage = Stage::Vertex; vertex.vertex_observation = Some(VertexObservation::Position); assert!(case_requirements(&vertex).is_empty()); + // An indexed draw past its index buffer is the runtime's limit; a vertex fetch past its + // vertex buffer is no requirement. + let past = |resource, form| { + let mut past = vertex.clone(); + past.out_of_bounds = Some(crate::case::out_of_bounds::OutOfBounds { + targets: vec![crate::case::out_of_bounds::OutOfBoundsTarget { + resource, + form, + reach_before: 0, + reach_after: 8, + }], + reads: Vec::new(), + }); + past + }; + use crate::case::out_of_bounds::ContainmentForm; + only( + &past( + OutOfBoundsResource::IndexBuffer, + ContainmentForm::IndexBuffer, + ), + ToolingRequirement::IndexBufferPastEnd, + ); + assert!(case_requirements(&past( + OutOfBoundsResource::AttributeBuffer { location: 0 }, + ContainmentForm::VertexInput + )) + .is_empty()); vertex.depth_stencil = Some(DepthStencilResource { dimensions: [1, 1], initial_depth_b64: Some("AAAAAA==".into()), diff --git a/crates/metal2vulkan-validation/src/requirement.rs b/crates/metal2vulkan-validation/src/requirement.rs index 5632489cd..7597479e7 100644 --- a/crates/metal2vulkan-validation/src/requirement.rs +++ b/crates/metal2vulkan-validation/src/requirement.rs @@ -190,6 +190,15 @@ pub enum ToolingRequirement { /// candidate does not run the case. The Metal oracle draws it, so a case of it stays /// Metal-qualified ([`Self::qualifies_on_metal`]). RenderFunctionTable, + /// An indexed draw that reads past its index buffer: a case's out-of-bounds target of a draw's + /// index buffer (`executor_contract::case_requirements`). The runtime refuses a draw whose + /// indices run past the buffer, as Metal's validation stops it + /// (`metal2vulkan_runtime::Refusal::IndexBufferOffset`, a refusal its README states, which is + /// its guard), so the limit is the runtime's ([`Limit::Runtime`]) and the engine's candidate + /// does not run the case. The case checker raises it from the case's literals, never a + /// source's structure, so no census row carries it. The Metal oracle draws it, so a case of it + /// stays Metal-qualified ([`Self::qualifies_on_metal`]). + IndexBufferPastEnd, } /// Every executor (the requirement leaves no case to author, or none to observe). @@ -197,7 +206,7 @@ const AUTHORING: &[Executor] = &Executor::ALL; const ENGINE: &[Executor] = &[Executor::EngineCandidate]; impl ToolingRequirement { - pub const ALL: [Self; 27] = [ + pub const ALL: [Self; 28] = [ Self::FunctionConstantLiteral, Self::VertexAttributeLiteral, Self::TessellationAttributeLiteral, @@ -225,6 +234,7 @@ impl ToolingRequirement { Self::ReplayedTemplateResources, Self::SeqCstFence, Self::RenderFunctionTable, + Self::IndexBufferPastEnd, ]; pub const fn as_str(self) -> &'static str { @@ -258,6 +268,7 @@ impl ToolingRequirement { Self::ReplayedTemplateResources => "replayed_template_resources", Self::SeqCstFence => "seq_cst_fence", Self::RenderFunctionTable => "render_function_table", + Self::IndexBufferPastEnd => "index_buffer_past_end", } } @@ -279,9 +290,9 @@ impl ToolingRequirement { /// template it does not draw or replay ([`ToolingRequirement::MeshRenderPipeline`], /// [`ToolingRequirement::ReplayedTemplateResources`]), and a texture buffer an argument /// buffer or a texture-handle array holds ([`ToolingRequirement::TextureBufferMember`]), - /// and a sequentially consistent fence and a render function's function table, which the - /// runtime refuses ([`ToolingRequirement::SeqCstFence`], - /// [`ToolingRequirement::RenderFunctionTable`]). + /// and a sequentially consistent fence, a render function's function table and an indexed + /// draw past its index buffer, which the runtime refuses ([`ToolingRequirement::SeqCstFence`], + /// [`ToolingRequirement::RenderFunctionTable`], [`ToolingRequirement::IndexBufferPastEnd`]). /// /// The requirements that stopped only the old engine's candidate were retired with it. pub const fn stops(self) -> &'static [Executor] { @@ -312,7 +323,8 @@ impl ToolingRequirement { | Self::TextureBufferMember | Self::ReplayedTemplateResources | Self::SeqCstFence - | Self::RenderFunctionTable => ENGINE, + | Self::RenderFunctionTable + | Self::IndexBufferPastEnd => ENGINE, } } @@ -321,8 +333,8 @@ impl ToolingRequirement { /// accepts it with no candidate (`executor_contract::evidence_gap`), and the engine's candidate /// refuses it, typed. Only [`ToolingRequirement::MeshRenderPipeline`], /// [`ToolingRequirement::TextureBufferMember`], [`ToolingRequirement::DepthOutsideUnitRange`], - /// [`ToolingRequirement::SeqCstFence`] and [`ToolingRequirement::RenderFunctionTable`]: their - /// cases are qualified on Metal. + /// [`ToolingRequirement::SeqCstFence`], [`ToolingRequirement::RenderFunctionTable`] and + /// [`ToolingRequirement::IndexBufferPastEnd`]: their cases are qualified on Metal. pub const fn qualifies_on_metal(self) -> bool { matches!( self, @@ -331,14 +343,16 @@ impl ToolingRequirement { | Self::DepthOutsideUnitRange | Self::SeqCstFence | Self::RenderFunctionTable + | Self::IndexBufferPastEnd ) } /// Whose limit this requirement records. Every requirement is this crate's tooling's except /// [`ToolingRequirement::KernelMinLodClamp`], which Apple's compiler cannot build a pipeline /// for, and [`ToolingRequirement::SeqCstFence`], [`ToolingRequirement::TextureBufferMember`], - /// [`ToolingRequirement::DepthOutsideUnitRange`], [`ToolingRequirement::MeshRenderPipeline`] - /// and [`ToolingRequirement::RenderFunctionTable`], which the runtime refuses. + /// [`ToolingRequirement::DepthOutsideUnitRange`], [`ToolingRequirement::MeshRenderPipeline`], + /// [`ToolingRequirement::RenderFunctionTable`] and [`ToolingRequirement::IndexBufferPastEnd`], + /// which the runtime refuses. pub const fn limit(self) -> Limit { match self { Self::KernelMinLodClamp => Limit::Metal, @@ -346,7 +360,8 @@ impl ToolingRequirement { | Self::TextureBufferMember | Self::DepthOutsideUnitRange | Self::MeshRenderPipeline - | Self::RenderFunctionTable => Limit::Runtime, + | Self::RenderFunctionTable + | Self::IndexBufferPastEnd => Limit::Runtime, _ => Limit::Tooling, } } @@ -499,7 +514,8 @@ mod tests { ToolingRequirement::DepthOutsideUnitRange, ToolingRequirement::MeshRenderPipeline, ToolingRequirement::SeqCstFence, - ToolingRequirement::RenderFunctionTable + ToolingRequirement::RenderFunctionTable, + ToolingRequirement::IndexBufferPastEnd ] ); } @@ -545,6 +561,19 @@ mod tests { assert_eq!("render_function_table".parse(), Ok(requirement)); } + /// An indexed draw past its index buffer: the Metal oracle draws it, so its cases stay + /// Metal-qualified; the runtime refuses the draw as Metal's validation does, so the engine's + /// candidate runs none, the runtime's limit, which closes its rows. + #[test] + fn an_index_buffer_past_its_end_stops_only_the_candidate() { + let requirement = ToolingRequirement::IndexBufferPastEnd; + assert_eq!(requirement.stops(), [Executor::EngineCandidate]); + assert_eq!(requirement.limit(), Limit::Runtime, "{requirement}"); + assert!(!requirement.blocks_closure(), "{requirement}"); + assert!(requirement.qualifies_on_metal(), "{requirement}"); + assert_eq!("index_buffer_past_end".parse(), Ok(requirement)); + } + /// Every requirement stops some executor, and an executor's name is as stable as a /// requirement's. A requirement that stops the Metal oracle stops every executor: when Metal /// cannot run a case, no candidate has an observation to be compared with. Only a tooling gap @@ -593,7 +622,8 @@ mod tests { ToolingRequirement::DepthOutsideUnitRange, ToolingRequirement::MeshRenderPipeline, ToolingRequirement::SeqCstFence, - ToolingRequirement::RenderFunctionTable + ToolingRequirement::RenderFunctionTable, + ToolingRequirement::IndexBufferPastEnd ] ); for executor in Executor::ALL { diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 5749626ff..a949dec93 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -493,8 +493,11 @@ cargo run -p metal2vulkan-validation --release --bin corpus-moltenvk -- \ `not_supported{uncontained:unchecked vertex_input}`. A rasterization-disabled vertex case renders into the oracle's 1x1 `R8Unorm` attachment. A depth/stencil attachment, more samples, layered rendering, a dynamic vertex stride, an argument-buffer member, tessellation, an imageblock, a rasterization-rate map, an - index buffer's out-of-bounds target or a fragment pass with no color target (the runtime makes - no pass without an attachment) keeps the case on the executor's own context. Its device worker enables the + out-of-bounds target other than an attribute buffer or a fragment pass with no color target (the + runtime makes no pass without an attachment) keeps the case on the executor's own context. An + indexed draw past its index buffer, which the runtime refuses as Metal's validation does + (`Refusal::IndexBufferOffset`), carries `index_buffer_past_end`, the runtime's limit, and runs + on Metal alone. Its device worker enables the validation layer through the loader's and the layer's variables, and any message the layer logs fails the row. The pipeline state's make is held to 500 MiB of peak live allocations and 20 s. Its row records the state's precision notes, the runtime's fingerprint and an out-of-bounds