Translator: the graphics state says whether the fragment module interpolates at a sample
GraphicsState::interpolates_at_sample is true where the fragment stage's module statically uses GLSL.std.450's InterpolateAtSample (interpolate_at_sample, or a sample-qualified varying read in the loop over the covered samples), read from the module's instructions at link: an OpExtInst of instruction 77 through the GLSL.std.450 import. Vulkan forbids that instruction in a pipeline whose sampleLocationsEnable is true (VUID-VkGraphicsPipelineCreateInfo-sampleLocationsEnable-01524), so a runtime that draws Metal's programmable sample positions through VK_EXT_sample_locations reads it before it makes such a pipeline. The field is encoded with the graphics state, so ARTIFACT_FORMAT_VERSION moves to 600, and it is a new reflection fact of every render pipeline, so SEMANTICS_VERSION moves to 2317 (development's is 2316). No module's words change. Test: engine_pull_model's the_graphics_state_states_whether_the_fragment_module_interpolates_at_a_sample (pm_sample and pm_sample_id true, pm_center, pm_centroid and pm_offset false, at four samples on every committed profile that compiles them). Verification: the lane's msi job (below the fix).
This commit is contained in:
1 parent
dcd502c921
commit
d4b181c2a8
8 files changed
+94
-3
No files matched your search
+2
-1
@@ -1355,7 +1355,8 @@ codec_struct! {
|
||||
alpha_to_coverage, alpha_to_one, rasterizer_discard, dynamic_states, input_attachments,
|
||||
max_vertex_amplification_count, declares_layer,
|
||||
tessellation, vertex_writes_memory, writes_viewport_index, writes_point_size, writes_depth,
|
||||
reads_barycentric_coord, reads_primitive_id, fragment_writes_memory, color_outputs,
|
||||
reads_barycentric_coord, reads_primitive_id, interpolates_at_sample,
|
||||
fragment_writes_memory, color_outputs,
|
||||
sample_mask, logic_op, line_band,
|
||||
}
|
||||
TessellationState {
|
||||
|
||||
Vendored
+2
-2
@@ -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 = 2316;
|
||||
pub const SEMANTICS_VERSION: u32 = 2317;
|
||||
|
||||
/// 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 = 2316;
|
||||
/// 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 = 599;
|
||||
pub const ARTIFACT_FORMAT_VERSION: u32 = 600;
|
||||
|
||||
/// The version of what this crate gives a runtime for the runs of a compiled pipeline, beside the
|
||||
/// compile: the device a run opens and what it enables, the Vulkan and Metal vocabularies a runtime
|
||||
|
||||
@@ -521,6 +521,7 @@ mod serde_round_trips {
|
||||
writes_depth: true,
|
||||
reads_barycentric_coord: true,
|
||||
reads_primitive_id: true,
|
||||
interpolates_at_sample: true,
|
||||
fragment_writes_memory: true,
|
||||
color_outputs: 0b101,
|
||||
sample_mask: Some(0b1001),
|
||||
|
||||
@@ -122,6 +122,17 @@ pub struct GraphicsState {
|
||||
/// quad, as two triangles) changes what a draw shows only where this is set.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub reads_primitive_id: bool,
|
||||
/// Whether the fragment stage's module statically uses `GLSL.std.450`'s
|
||||
/// `InterpolateAtSample`: the function reads a varying at a sample
|
||||
/// (`interpolate_at_sample`), or a sample-qualified varying in the loop over its covered
|
||||
/// samples. Read from the module's instructions, never from names. `false` for a pipeline
|
||||
/// without a fragment function. Vulkan forbids that instruction in a pipeline whose
|
||||
/// `VkPipelineSampleLocationsStateCreateInfoEXT::sampleLocationsEnable` is true
|
||||
/// (`VUID-VkGraphicsPipelineCreateInfo-sampleLocationsEnable-01524`), so a consumer that
|
||||
/// rasterizes Metal's programmable sample positions through `VK_EXT_sample_locations` cannot
|
||||
/// draw such a pipeline at them.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub interpolates_at_sample: bool,
|
||||
/// The fragment function writes memory (`StageInterface::writes_memory`): it stores to a
|
||||
/// buffer or a texture, or updates one atomically. `false` for a pipeline without a fragment
|
||||
/// function. Metal never runs a function that declares `[[early_fragment_tests]]` for a
|
||||
@@ -316,6 +327,7 @@ impl GraphicsState {
|
||||
writes_depth: false,
|
||||
reads_barycentric_coord: false,
|
||||
reads_primitive_id: false,
|
||||
interpolates_at_sample: false,
|
||||
fragment_writes_memory: false,
|
||||
color_outputs: 0,
|
||||
sample_mask: None,
|
||||
|
||||
@@ -513,6 +513,8 @@ fn render_state(
|
||||
p,
|
||||
)?;
|
||||
gs.color_outputs = color_outputs(fs)?;
|
||||
gs.interpolates_at_sample =
|
||||
fragment.is_some_and(|f| graphics::interpolates_at_sample(&f.module.words));
|
||||
Ok(gs)
|
||||
}
|
||||
|
||||
|
||||
@@ -690,6 +690,8 @@ pub fn graphics_state(
|
||||
}),
|
||||
reads_barycentric_coord: fs.is_some_and(|fs| reads_barycentric_coord(&fs.io)),
|
||||
reads_primitive_id: fs.is_some_and(|fs| reads_primitive_id(&fs.io)),
|
||||
// Read from the fragment module's words once it is made (`link::render_state`).
|
||||
interpolates_at_sample: false,
|
||||
fragment_writes_memory: fs.is_some_and(|fs| fs.writes_memory),
|
||||
// The outputs' writes, once the color attachments are decided.
|
||||
color_outputs: 0,
|
||||
@@ -711,6 +713,41 @@ fn reads_barycentric_coord(io: &StageIo) -> bool {
|
||||
.any(|b| matches!(b, StageBuiltin::BaryCoord { .. }))
|
||||
}
|
||||
|
||||
/// Whether `words`, a module this crate wrote, statically uses `GLSL.std.450`'s
|
||||
/// `InterpolateAtSample` (`GraphicsState::interpolates_at_sample`): an `OpExtInst` of instruction
|
||||
/// 77 through the result of the `OpExtInstImport` that names that set. A malformed instruction
|
||||
/// ends the walk, and what it read stands.
|
||||
pub(crate) fn interpolates_at_sample(words: &[u32]) -> bool {
|
||||
use crate::spv::{GlslStd450Op, Op};
|
||||
// The set's name as an import's literal: its UTF-8 bytes, a NUL and zero padding, packed
|
||||
// little-endian into words.
|
||||
let mut name = b"GLSL.std.450".to_vec();
|
||||
name.resize(name.len() / 4 * 4 + 4, 0);
|
||||
let name: Vec<u32> = (name.as_chunks::<4>().0.iter())
|
||||
.map(|&bytes| u32::from_le_bytes(bytes))
|
||||
.collect();
|
||||
let mut glsl = None;
|
||||
let mut rest = words.get(5..).unwrap_or_default();
|
||||
while let Some(&first) = rest.first() {
|
||||
let count = (first >> 16) as usize;
|
||||
let Some((inst, after)) = rest.split_at_checked(count).filter(|_| count > 0) else {
|
||||
return false;
|
||||
};
|
||||
rest = after;
|
||||
let opcode = first & 0xFFFF;
|
||||
if opcode == Op::ExtInstImport as u32 && inst.get(2..) == Some(&name[..]) {
|
||||
glsl = inst.get(1).copied();
|
||||
} else if opcode == Op::ExtInst as u32
|
||||
&& glsl.is_some()
|
||||
&& inst.get(3).copied() == glsl
|
||||
&& inst.get(4).copied() == Some(GlslStd450Op::InterpolateAtSample as u32)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Whether a fragment stage of interface `io` reads `[[primitive_id]]`
|
||||
/// (`GraphicsState::reads_primitive_id`): the `PrimitiveId` builtin, or its varying
|
||||
/// (`IoRole::PrimitiveId`).
|
||||
|
||||
@@ -130,3 +130,40 @@ fn an_offset_read_where_the_quad_may_have_left_is_not_lowered() {
|
||||
}
|
||||
assert!(checked > 20, "{checked}");
|
||||
}
|
||||
|
||||
/// A render pipeline's graphics state states whether its fragment module statically uses
|
||||
/// `InterpolateAtSample` (`GraphicsState::interpolates_at_sample`), read from the module's
|
||||
/// instructions: a read at a sample does, by an index the function is given (`pm_sample`) or its
|
||||
/// own `[[sample_id]]` (`pm_sample_id`); reads at the center, the centroid and an offset do not, at
|
||||
/// four samples, on every profile that compiles them. Vulkan forbids that instruction in a
|
||||
/// pipeline drawn at custom sample locations, so a runtime that sets Metal's sample positions reads
|
||||
/// it before it does.
|
||||
#[test]
|
||||
fn the_graphics_state_states_whether_the_fragment_module_interpolates_at_a_sample() {
|
||||
let Some(lib) = library("pull_model_interpolants") else {
|
||||
return;
|
||||
};
|
||||
let mut checked = [0; 2];
|
||||
for stem in stems() {
|
||||
let dev = Device::from_queries(description(&stem), DevicePolicy::RESIDENT_TABLES)
|
||||
.expect("device");
|
||||
for (fragment, want) in [
|
||||
("pm_center", false),
|
||||
("pm_centroid", false),
|
||||
("pm_sample", true),
|
||||
("pm_sample_id", true),
|
||||
("pm_offset", false),
|
||||
] {
|
||||
let what = format!("{stem} {fragment}");
|
||||
let d = render(&lib, fragment, (PixelFormat::RGBA32Float, 2), 4);
|
||||
// A profile without four samples or without the reads' features refuses the
|
||||
// pipeline; the module tests every profile that compiles it.
|
||||
let Ok(pipeline) = dev.compile_render_pipeline(&d, &Budget::standard()) else {
|
||||
continue;
|
||||
};
|
||||
assert_eq!(pipeline.graphics.interpolates_at_sample, want, "{what}");
|
||||
checked[usize::from(want)] += 1;
|
||||
}
|
||||
}
|
||||
assert!(checked.iter().all(|&n| n > 4), "{checked:?}");
|
||||
}
|
||||
@@ -2410,6 +2410,7 @@ field metal2vulkan::pipeline::GraphicsState.depth_format pub depth_format: Optio
|
||||
field metal2vulkan::pipeline::GraphicsState.dynamic_states pub dynamic_states: Vec<vk::DynamicState>
|
||||
field metal2vulkan::pipeline::GraphicsState.fragment_writes_memory pub fragment_writes_memory: bool
|
||||
field metal2vulkan::pipeline::GraphicsState.input_attachments pub input_attachments: Vec<InputAttachmentUse>
|
||||
field metal2vulkan::pipeline::GraphicsState.interpolates_at_sample pub interpolates_at_sample: bool
|
||||
field metal2vulkan::pipeline::GraphicsState.line_band pub line_band: Option<LineBandState>
|
||||
field metal2vulkan::pipeline::GraphicsState.logic_op pub logic_op: Option<vk::LogicOp>
|
||||
field metal2vulkan::pipeline::GraphicsState.max_vertex_amplification_count pub max_vertex_amplification_count: u32
|
||||
|
||||
|
Can't render this file because it is too large.
|
Reference in new issue
Block a user