Translator: a post-tessellation function reads a Constant layout's control-point attribute from its one element
pulled_read takes (ControlPoint, Constant) as it takes (Patch, Constant): Element::None, the attribute's offset alone, with no stride pushed or depended on. A control-point call fetches such a member with no element. It computes the control point's element only when some member steps per control point, so a struct of Constant members alone needs no elements input. The module doc states the rule and Metal's measured answer (every control point reads element 0, Mac job m3-max-80062). Verified: lavapipe (llvmpipe), job m3-max-80143 at the same tree on a scratch branch: both tests pass, with the patch draws beside them.
This commit is contained in:
1 parent
3fbaca0b9b
commit
9f4aded219
1 file changed
+13
-6
@@ -33,8 +33,10 @@
|
||||
//! which the pipeline's control stage hands the stage as patch inputs from
|
||||
//! `TessellationStage::CONTROL_POINT_LOCATION`: `patch_id · N + k`, or the control-point index
|
||||
//! buffer's index there. An index `k` outside `[0, N)`, undefined in Metal, reads control point
|
||||
//! `N - 1`'s element. A member no instruction reads, and a field Metal marks `air.arg_unused`, is
|
||||
//! zero and fetches nothing.
|
||||
//! `N - 1`'s element. A field whose layout has the `Constant` step function reads no element:
|
||||
//! the attribute's offset alone, the same for every control point of every patch, as Metal
|
||||
//! fetches it once (measured on an Apple M3 Max: each control point reads element 0). A member no
|
||||
//! instruction reads, and a field Metal marks `air.arg_unused`, is zero and fetches nothing.
|
||||
//! - `[[base_instance]]` is the second lane of `PushField::BaseVertexInstance`, which the binder
|
||||
//! writes with the draw's base instance: an evaluation shader has no `BaseInstance`. An indirect
|
||||
//! draw of patches then needs its arguments on the host, which the runtime does not read yet
|
||||
@@ -124,7 +126,7 @@ pub enum Element {
|
||||
Instance,
|
||||
/// `patch · N + k` for the control-point index `k` of the call (`PerPatchControlPoint`).
|
||||
ControlPoint,
|
||||
/// None: the attribute's offset alone (`Constant`).
|
||||
/// None: the attribute's offset alone (`Constant`), for a patch input or a control point.
|
||||
None,
|
||||
}
|
||||
|
||||
@@ -538,7 +540,7 @@ fn pulled_read(
|
||||
1 => Element::Instance,
|
||||
_ => return Err(not_implemented()),
|
||||
},
|
||||
(Kind::Patch, VertexStepFunction::Constant) => Element::None,
|
||||
(Kind::Patch | Kind::ControlPoint, VertexStepFunction::Constant) => Element::None,
|
||||
_ => return Err(not_implemented()),
|
||||
};
|
||||
if element != Element::None {
|
||||
@@ -982,8 +984,12 @@ pub fn emit(
|
||||
return Err(cx.fail("a control-point struct that is not a composite"));
|
||||
};
|
||||
// Control point `k`'s element, as the control stage hands it: component `k % 4` of element
|
||||
// `k / 4`, `k` at most `N - 1` (the module docs).
|
||||
let element = if members.iter().any(Option::is_some) {
|
||||
// `k / 4`, `k` at most `N - 1` (the module docs). A field on a `Constant` layout reads none.
|
||||
let per_point = members
|
||||
.iter()
|
||||
.flatten()
|
||||
.any(|r| r.element == Element::ControlPoint);
|
||||
let element = if per_point {
|
||||
let k = cx.operand(fb, index)?;
|
||||
let last = k32(fb, n.saturating_sub(1))?;
|
||||
let k = fb.glsl(GlslOp::UMin, &[k, last])?;
|
||||
@@ -1003,6 +1009,7 @@ pub fn emit(
|
||||
let mut values = Vec::with_capacity(members.len());
|
||||
for (m, part) in members.iter().zip(parts.iter()) {
|
||||
let x = match (m, element) {
|
||||
(Some(r), _) if r.element == Element::None => fetch_at(cx, fb, r, None)?,
|
||||
(Some(r), Some(e)) => fetch_at(cx, fb, r, Some(e))?,
|
||||
_ => {
|
||||
let Some(t) = arith::spirv_type(fb.module(), part)? else {
|
||||
|
||||
Reference in new issue
Block a user