Push placement: a post-tessellation vertex function's window starts past the control stage's range
A tessellation render pipeline whose vertex and fragment functions' push fields filled the
floor's 256 bytes was refused at link ("unsupported: Tessellation; needs AnyOf: Limit
MaxPushConstantsSize, required 260, available 256"): link places the synthesized control stage's
push range (8 to 24 bytes) at the first free offset beside the two functions' ranges, and since
the tail placement (0cd2ad765d: each stage's push ends with its tail, 24 bytes above its other
fields) the pair's ranges can end within 8 bytes of 256. Metal makes the pipeline, and the device
lacks nothing.
The form, one on every device: a post-tessellation vertex function's window is [24, 248) instead
of [0, 248), so the control stage's range, at most control::PUSH_BYTES (24) in either form, is
placed at 0, and the fields the pair cannot push spill into their parameter blocks, the form a
function's fields past its window already take. The tail and its 24-byte hole are unchanged. A
fragment function behind such a vertex function that pushes nothing starts at 24 too.
- lower/push.rs: window(Vertex, base) starts at base; TESSELLATION_BASE (= control::PUSH_BYTES);
base(cx), the start of a function's fields (24 for a post-tessellation vertex function, else
LoweringInputs::push_base); fragment_base(), the vertex function's push end or its window's
start, used by CompiledFunction::fragment_push_base, compile::vertex_push_end and link's
check_push_base.
- select and access place and census the fields from push::base.
- SEMANTICS_VERSION 2204 (a post-tessellation vertex function's and its fragment function's
placements move).
- Tests: push.rs pins the vertex window from either start, and that the control stage's range in
every form (bound and address, each factor step, scale on and off) fits below 24 and a
fragment base behind an empty post-tessellation placement is 24. rt's
every_device_draws_patches_whose_fragment_fills_the_push_range: a patch state behind fragment
functions of 4, 8, 12 and 16 buffers is made, pushes the factors' address at 0, and draws its
patches with every buffer's bits; the widest pair's fields end past 248.
- Docs: API.md section 5, the rt README's push range, PushPlacement::push_range,
LoweringInputs::push_base, CompiledFunction::fragment_push_base, the tessellation link docs.
The line band's evaluation stage (16 bytes, WideLines) and the fan-out probe's geometry stage (4
bytes, RasterizationRateMap) are still placed by tessellation::push_offset beside the pair's
ranges and refused where those fill the floor: the same shape, not changed here.
This commit is contained in:
1 parent
82e7c39216
commit
23d6572c18
13 files changed
+302
-31
No files matched your search
@@ -2633,7 +2633,8 @@ or does not check is rebuilt from the generations' names, with young counted ful
|
||||
differ only in a field their compile does not read are two contents, each compiled.
|
||||
- A render pipeline's two functions push their values (each buffer's address, each constexpr
|
||||
sampler's index) in one range of the floor's 256 bytes, dense by link: the vertex function's
|
||||
from 0, ending by 248, the fragment function's from the vertex function's end, each value at
|
||||
from 0 (from 24 for a post-tessellation function, whose control stage pushes the factors'
|
||||
address at 0), ending by 248, the fragment function's from the vertex function's end, each value at
|
||||
the next offset aligned to it (a framebuffer fetch's element index, four bytes, before the
|
||||
eight-byte values, where the four bytes below one are free), so only the values the pair uses
|
||||
take space. Compute and render pipelines share the device's one pipeline layout and its one
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
//! - the same patches of a post-tessellation function whose fields pass its push window (16 more
|
||||
//! buffer arguments, written here): its parameter block survives the control stage's placement
|
||||
//! of the vertex stage, and every buffer's address and bounds reach the function from it.
|
||||
//! - the same patches behind a fragment function whose fields fill the push range (4 to 16 buffer
|
||||
//! arguments, written here): the state is made, as Metal makes it, with the control stage's
|
||||
//! range at 0 below the post-tessellation function's window, and the fragment function's fields
|
||||
//! past the range in its block.
|
||||
//! - what Metal refuses is refused: a patch draw with a plain state, a plain draw with a patch
|
||||
//! state, a patch draw with no factor buffer and factors at an odd byte. What the runtime does
|
||||
//! not build is a gap: a patch index buffer, a per-instance factor step and an enabled factor
|
||||
@@ -86,6 +90,87 @@ attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) }
|
||||
/// The buffer arguments of [`wide_vertex`]'s function.
|
||||
const WIDE: u32 = 16;
|
||||
|
||||
/// [`wide_fragment`]'s text but its buffer arguments, their reads and their metadata.
|
||||
const WIDE_FRAGMENT_TEMPLATE: &str = r#"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"
|
||||
target triple = "air64_v28-apple-macosx26.0.0"
|
||||
|
||||
define <4 x float> @tess_wide_fragment(<4 x float> %0ARGS) local_unnamed_addr #0 {
|
||||
READS ret <4 x float> SUM
|
||||
}
|
||||
|
||||
attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read) }
|
||||
|
||||
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
|
||||
!air.fragment = !{!9}
|
||||
!air.compile_options = !{!14, !15}
|
||||
!air.version = !{!16}
|
||||
!air.language_version = !{!17}
|
||||
|
||||
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 26, i32 5]}
|
||||
!1 = !{i32 1, !"wchar_size", i32 4}
|
||||
!2 = !{i32 7, !"frame-pointer", i32 2}
|
||||
!3 = !{i32 7, !"air.max_device_buffers", i32 31}
|
||||
!4 = !{i32 7, !"air.max_constant_buffers", i32 31}
|
||||
!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31}
|
||||
!6 = !{i32 7, !"air.max_textures", i32 128}
|
||||
!7 = !{i32 7, !"air.max_read_write_textures", i32 8}
|
||||
!8 = !{i32 7, !"air.max_samplers", i32 16}
|
||||
!9 = !{ptr @tess_wide_fragment, !10, !12}
|
||||
!10 = !{!11}
|
||||
!11 = !{!"air.render_target", i32 0, i32 0, !"air.arg_type_name", !"float4"}
|
||||
!12 = !{!13BUFFERS}
|
||||
!13 = !{i32 0, !"air.fragment_input", !"user(locn0)", !"air.center", !"air.perspective", !"air.arg_type_name", !"float4", !"air.arg_name", !"color"}
|
||||
!14 = !{!"air.compile.denorms_disable"}
|
||||
!15 = !{!"air.compile.fast_math_enable"}
|
||||
!16 = !{i32 2, i32 8, i32 0}
|
||||
!17 = !{!"Metal", i32 4, i32 0, i32 0}
|
||||
BUFFER_META"#;
|
||||
|
||||
/// The buffer arguments of each of [`wide_fragment`]'s functions: the narrowest pushes
|
||||
/// every field, the widest spills.
|
||||
const FRAGMENT_WIDTHS: [u32; 4] = [4, 8, 12, 16];
|
||||
|
||||
/// A fragment function that writes its `user(locn0)` colour plus `width` `float4` buffer
|
||||
/// arguments at indices 0 and on, each read at element 0, a read checked against the
|
||||
/// buffer's bounds.
|
||||
fn wide_fragment(width: u32) -> String {
|
||||
let args: String = (0..width)
|
||||
.map(|k| {
|
||||
format!(
|
||||
r#", ptr addrspace(1) noundef readonly align 16 captures(none) "air-buffer-no-alias" %f{k}"#
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let mut reads = String::new();
|
||||
let mut sum = "%0".to_owned();
|
||||
for k in 0..width {
|
||||
reads += &format!(
|
||||
" %v{k} = load <4 x float>, ptr addrspace(1) %f{k}, align 16\n \
|
||||
%s{k} = fadd fast <4 x float> {sum}, %v{k}\n"
|
||||
);
|
||||
sum = format!("%s{k}");
|
||||
}
|
||||
let buffers: String = (0..width).map(|k| format!(", !{}", 30 + k)).collect();
|
||||
let meta: String = (0..width)
|
||||
.map(|k| {
|
||||
format!(
|
||||
"!{} = !{{i32 {}, !\"air.buffer\", !\"air.location_index\", i32 {k}, i32 1, \
|
||||
!\"air.read\", !\"air.address_space\", i32 1, !\"air.arg_type_size\", i32 16, \
|
||||
!\"air.arg_type_align_size\", i32 16, !\"air.arg_type_name\", !\"float4\", \
|
||||
!\"air.arg_name\", !\"f{k}\"}}\n",
|
||||
30 + k,
|
||||
1 + k
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
WIDE_FRAGMENT_TEMPLATE
|
||||
.replace("ARGS", &args)
|
||||
.replace("READS", &reads)
|
||||
.replace("SUM", &sum)
|
||||
.replace("BUFFERS", &buffers)
|
||||
.replace("BUFFER_META", &meta)
|
||||
}
|
||||
|
||||
/// [`wide_vertex`]'s text but its buffer arguments, their reads and their metadata.
|
||||
const WIDE_TEMPLATE: &str = r#"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"
|
||||
target triple = "air64_v28-apple-macosx26.0.0"
|
||||
@@ -453,6 +538,108 @@ BUFFER_META"#;
|
||||
});
|
||||
}
|
||||
|
||||
/// A patch state whose fragment function's fields fill the floor's push range behind the
|
||||
/// post-tessellation function's ([`wide_fragment`]) is made, as Metal makes it, and draws its
|
||||
/// patches: the control stage pushes the factors' address at 0, below the post-tessellation
|
||||
/// function's window, and the fragment function's fields past the range go to its block. The
|
||||
/// widest fragment function's fields reach past 248 bytes, where no range of the factors'
|
||||
/// address is left above the pair's. Buffer `k` holds `2^(k % 4) / 255` in channel `k / 4`
|
||||
/// and the tints are 0, so the first patch's colour holds every bit of the buffers a function
|
||||
/// reads only where each buffer's address and bounds reach it; the second patch is culled.
|
||||
#[test]
|
||||
fn every_device_draws_patches_whose_fragment_fills_the_push_range() {
|
||||
use crate::pipeline::FieldValue;
|
||||
use crate::render::DrawPlace;
|
||||
let Some(libraries) = libraries() else {
|
||||
return;
|
||||
};
|
||||
let mut fragments = Vec::new();
|
||||
for width in FRAGMENT_WIDTHS {
|
||||
match llvm_assemble_text(&wide_fragment(width)) {
|
||||
Ok(bitcode) => fragments.push((
|
||||
width,
|
||||
Library::from_air(&bitcode).expect("the wide fragment library"),
|
||||
)),
|
||||
Err(AssembleError::Missing(why)) => {
|
||||
eprintln!("SKIPPED: {why}");
|
||||
return;
|
||||
}
|
||||
Err(error) => panic!("the wide fragment {width}: {error:?}"),
|
||||
}
|
||||
}
|
||||
each_device("draw_patches_full_range", |name, _, device| {
|
||||
let mut widest = 0;
|
||||
for (width, library) in &fragments {
|
||||
let mut d = patches(&libraries);
|
||||
d.fragment = Some(StageSource::Function(FunctionDescriptor::new(
|
||||
library
|
||||
.function("tess_wide_fragment")
|
||||
.expect("the function"),
|
||||
)));
|
||||
let state = state(name, &device, &d);
|
||||
let draws = &state.inner.compiled.draws;
|
||||
assert!(
|
||||
(draws.fields.iter()).any(|(place, _, value)| matches!(
|
||||
(place, value),
|
||||
(DrawPlace::Push(0), FieldValue::TessellationFactors)
|
||||
)),
|
||||
"{name}: {width} buffers: the factors' address at 0"
|
||||
);
|
||||
widest = widest.max(draws.push_len);
|
||||
let mut buffers = Buffers::new(&device);
|
||||
let (points, _, factors) = patch_buffers(&device, &mut buffers);
|
||||
let tints = buffers.of(&device, &[0; 32]);
|
||||
let summed: Vec<Buffer> = (0..*width)
|
||||
.map(|k| {
|
||||
let mut value = [0.0; 4];
|
||||
value[(k / 4) as usize] = f32::from(1u8 << (k % 4)) / 255.0;
|
||||
buffers.of(&device, &floats(&value))
|
||||
})
|
||||
.collect();
|
||||
let color = target(
|
||||
&device,
|
||||
PixelFormat::RGBA8Unorm,
|
||||
TextureUsage::RENDER_TARGET,
|
||||
);
|
||||
let queue = device.new_command_queue(4).expect("a queue");
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
let mut encoder = (command_buffer.render_command_encoder(&pass(&color, None)))
|
||||
.unwrap_or_else(|error| panic!("{name}: {error}"));
|
||||
let draw =
|
||||
|result: Result<(), Error>| result.unwrap_or_else(|e| panic!("{name}: {e}"));
|
||||
draw(encoder.set_render_pipeline_state(&state));
|
||||
draw(encoder.set_vertex_buffer(Some(&points), 0, 0));
|
||||
draw(encoder.set_vertex_buffer(Some(&tints), 0, 1));
|
||||
for (k, buffer) in summed.iter().enumerate() {
|
||||
draw(encoder.set_fragment_buffer(Some(buffer), 0, k as u32));
|
||||
}
|
||||
draw(encoder.set_tessellation_factor_buffer(Some(&factors), 8, 0));
|
||||
draw(encoder.draw_patches(3, 0, 2, None, 1, 0));
|
||||
encoder.end_encoding();
|
||||
run(name, &command_buffer);
|
||||
let mut sums = [0u8; 4];
|
||||
for k in 0..*width {
|
||||
sums[(k / 4) as usize] += 1 << (k % 4);
|
||||
}
|
||||
let black = [0, 0, 0, 255];
|
||||
let want: Vec<u8> = (0..SIDE * SIDE)
|
||||
.flat_map(|at| if at / SIDE < 4 { sums } else { black })
|
||||
.collect();
|
||||
assert_eq!(read(&color, 4), want, "{name}: {width} buffers: the texels");
|
||||
println!(
|
||||
"{name}: {width} fragment buffers, a push range of {} bytes, the fragment \
|
||||
function's block {:?}",
|
||||
draws.push_len,
|
||||
draws.blocks[crate::render::FRAGMENT]
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
widest > 248,
|
||||
"{name}: the widest pair's fields end at {widest}, not past 248"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// What Metal refuses is refused, and what the runtime does not build is a gap.
|
||||
#[test]
|
||||
fn every_device_refuses_the_patch_draws_it_does_not_build() {
|
||||
|
||||
Vendored
+1
-1
@@ -62,7 +62,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 = 2203;
|
||||
pub const SEMANTICS_VERSION: u32 = 2204;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -339,11 +339,14 @@ impl CompiledFunction {
|
||||
|
||||
/// Where a fragment function linked after this vertex function pushes its fields on
|
||||
/// `Device::from_queries`' profile (`LoweringInputs::push_base`): this function's push end, a
|
||||
/// multiple of 4, 0 where it pushes nothing; each fragment field is placed at the next offset
|
||||
/// aligned to it, so a four-byte field may take the bytes below an eight-byte one. A consumer
|
||||
/// compiling a render pipeline's fragment function on its own compiles it under this offset.
|
||||
/// multiple of 4; where it pushes nothing, 24 for a post-tessellation function (past its
|
||||
/// pipeline's control stage's push range) and 0 for any other. Each fragment field is placed
|
||||
/// at the next offset aligned to it, so a four-byte field may take the bytes below an
|
||||
/// eight-byte one. A consumer compiling a render pipeline's fragment function on its own
|
||||
/// compiles it under this offset.
|
||||
pub fn fragment_push_base(&self) -> u32 {
|
||||
(self.0.interface.push.push_range).map_or(0, |(offset, size)| offset + size)
|
||||
let interface = &self.0.interface;
|
||||
crate::lower::push::fragment_base(&interface.push, interface.tessellation.is_some())
|
||||
}
|
||||
|
||||
/// Whether the function is a vertex function whose module writes its `[[point_size]]`
|
||||
|
||||
@@ -1483,7 +1483,7 @@ fn place_slots(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<Vec<Option<SlotCh
|
||||
(
|
||||
cx.families.access.dynamic.used,
|
||||
identity(p),
|
||||
cx.inputs.push_base,
|
||||
crate::lower::push::base(cx),
|
||||
),
|
||||
forms,
|
||||
m,
|
||||
@@ -1716,7 +1716,8 @@ fn place_slots(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<Vec<Option<SlotCh
|
||||
}
|
||||
let counts = census.counts(stage);
|
||||
cx.descriptors = cx.descriptors.plus(&counts);
|
||||
cx.families.access.argument_table = table::spills(stage, cx.inputs.push_base, &cx.push);
|
||||
cx.families.access.argument_table =
|
||||
table::spills(stage, crate::lower::push::base(cx), &cx.push);
|
||||
// Under the identity domains a function whose fields spill, of any stage, reads them from a
|
||||
// parameter block whose address its window holds first: a render pipeline's stages too, in
|
||||
// their shares of the floor's one range (`push::VERTEX_FLOOR_END`).
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
//! `maxPushConstantsSize ≥ 256`: a compute window is `[0, 256)` (a dispatch region and 24 buffer
|
||||
//! addresses below its tail), and a render
|
||||
//! pipeline's two stages share one range `[0, 256)`, dense by link: the vertex function's fields
|
||||
//! from 0, the fragment function's from its `LoweringInputs::push_base`, the vertex function's push
|
||||
//! end, so only the fields the pair places take space (a four-byte field the fragment function
|
||||
//! places before its eight-byte ones takes the four bytes the vertex function's end may leave).
|
||||
//! The vertex function's window there is `[0, 248)`, 8 bytes short of the range's end
|
||||
//! from its start ([`base`]), the fragment function's from its `LoweringInputs::push_base`, the
|
||||
//! vertex function's push end, so only the fields the pair places take space (a four-byte field
|
||||
//! the fragment function places before its eight-byte ones takes the four bytes the vertex
|
||||
//! function's end may leave). A vertex function starts at 0, and a post-tessellation one at
|
||||
//! [`TESSELLATION_BASE`], past the push range link places for the pipeline's control stage at 0,
|
||||
//! so the pair's fields never take its bytes: where they pass the range they spill, as any
|
||||
//! function's do, and the pipeline is made on every device.
|
||||
//! The vertex function's window there ends at 248, 8 bytes short of the range's end
|
||||
//! ([`VERTEX_FLOOR_END`]): a vertex function is lowered without knowing its fragment function, and
|
||||
//! a fragment function whose fields spill must push its parameter block's address (8 bytes,
|
||||
//! 8-aligned) from the vertex function's end, so the vertex function leaves that room. The
|
||||
@@ -41,14 +45,16 @@
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::air::abi::Stage as AirStage;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::pipeline::interface::{PlacedField, PushLoc, PushPlacement};
|
||||
use crate::pipeline::sym::{PushField, Stage};
|
||||
|
||||
/// The byte range `[start, end)` of `stage`'s push window; `base` is a fragment function's
|
||||
/// `LoweringInputs::push_base`.
|
||||
/// `LoweringInputs::push_base`, or a vertex function's start ([`base`]).
|
||||
pub const fn window(stage: Stage, base: u32) -> (u32, u32) {
|
||||
match stage {
|
||||
Stage::Vertex => (0, VERTEX_FLOOR_END),
|
||||
Stage::Vertex => (base, VERTEX_FLOOR_END),
|
||||
Stage::Fragment => (base, FLOOR_BYTES),
|
||||
Stage::Kernel => (0, FLOOR_BYTES),
|
||||
// A mesh render pipeline's object, mesh and fragment functions share the 128 bytes: the
|
||||
@@ -61,6 +67,34 @@ pub const fn window(stage: Stage, base: u32) -> (u32, u32) {
|
||||
/// The push bytes of the runtime's floor: its `maxPushConstantsSize`.
|
||||
pub const FLOOR_BYTES: u32 = 256;
|
||||
|
||||
/// Where a post-tessellation vertex function's window starts: past the most bytes the pipeline's
|
||||
/// control stage pushes in either form (`control::PUSH_BYTES`), whose range link places at 0
|
||||
/// (`tessellation::push_offset`, the first free offset), so the control stage's range fits beside
|
||||
/// the vertex and fragment functions' whatever their fields.
|
||||
pub const TESSELLATION_BASE: u32 = crate::pipeline::link::tessellation::control::PUSH_BYTES;
|
||||
|
||||
/// Where the fields of `cx`'s function start in its window ([`window`]): a post-tessellation
|
||||
/// vertex function's at [`TESSELLATION_BASE`], any other function's at its
|
||||
/// `LoweringInputs::push_base`, a fragment function's place behind its vertex function and 0 for
|
||||
/// the rest.
|
||||
pub fn base(cx: &SelectCx<'_>) -> u32 {
|
||||
match cx.entry.ep.stage {
|
||||
AirStage::Vertex { patch: Some(_) } => TESSELLATION_BASE,
|
||||
_ => cx.inputs.push_base,
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a fragment function's fields start on the floor behind vertex function placement
|
||||
/// `vertex`, of a post-tessellation function or not (`tessellated`): the vertex function's push
|
||||
/// end, or where it pushes nothing, its window's start ([`base`]).
|
||||
pub fn fragment_base(vertex: &PushPlacement, tessellated: bool) -> u32 {
|
||||
let start = match tessellated {
|
||||
true => TESSELLATION_BASE,
|
||||
false => 0,
|
||||
};
|
||||
(vertex.push_range).map_or(start, |(offset, size)| offset + size)
|
||||
}
|
||||
|
||||
/// The end of a vertex function's window on the floor: the floor's end less one address, so the
|
||||
/// fragment function's window, from the vertex function's end, always holds its parameter block's
|
||||
/// address (`PushField::ArgumentTableAddress`, which the order places first, at the next multiple
|
||||
@@ -680,17 +714,53 @@ mod tests {
|
||||
assert!(check_floor(&past).is_err());
|
||||
}
|
||||
|
||||
/// The windows a pipeline of each kind pushes, pinned: on the guaranteed window the fixed
|
||||
/// ones, whatever a fragment function's base; on the floor a compute kernel's `[0, 256)`, and a
|
||||
/// render pipeline's one range `[0, 256)`, the vertex function's from 0 and the fragment
|
||||
/// function's from its base. A compute kernel's window does not move with a render base.
|
||||
/// The windows a pipeline of each kind pushes, pinned: a compute kernel's `[0, 256)`, and a
|
||||
/// render pipeline's one range `[0, 256)`, the vertex function's from its start (0, or 24 for
|
||||
/// a post-tessellation function) and the fragment function's from its base. A compute
|
||||
/// kernel's window does not move with a render base.
|
||||
#[test]
|
||||
fn each_kind_pushes_its_own_window() {
|
||||
for base in [0, 8, 40, 248] {
|
||||
assert_eq!(window(Stage::Kernel, base), (0, 256));
|
||||
assert_eq!(window(Stage::Vertex, base), (0, 248));
|
||||
assert_eq!(window(Stage::Fragment, base), (base, 256));
|
||||
}
|
||||
assert_eq!(TESSELLATION_BASE, 24);
|
||||
for base in [0, TESSELLATION_BASE] {
|
||||
assert_eq!(window(Stage::Vertex, base), (base, 248));
|
||||
}
|
||||
}
|
||||
|
||||
/// The control stage's push range fits below a post-tessellation vertex function's window in
|
||||
/// either form, with every factor step and scale, so link places it at 0 beside any pair of
|
||||
/// functions; a fragment function behind such a vertex function that pushes nothing starts
|
||||
/// past it too, and behind any other at 0.
|
||||
#[test]
|
||||
fn the_control_stage_fits_below_a_post_tessellation_window() {
|
||||
use crate::metal::TessellationFactorStepFunction as Step;
|
||||
use crate::pipeline::link::tessellation::control::Control;
|
||||
let steps = [
|
||||
Step::Constant,
|
||||
Step::PerPatch,
|
||||
Step::PerInstance,
|
||||
Step::PerPatchAndPerInstance,
|
||||
];
|
||||
for addressed in [false, true] {
|
||||
for step in steps {
|
||||
for scale in [false, true] {
|
||||
let (bytes, align) = Control::push_bytes(addressed, step, scale);
|
||||
assert!(bytes <= TESSELLATION_BASE, "{addressed} {step:?} {scale}");
|
||||
assert_eq!(TESSELLATION_BASE % align, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
let empty = place(Stage::Vertex, TESSELLATION_BASE, &BTreeSet::new());
|
||||
assert_eq!(empty.push_range, None);
|
||||
assert_eq!(fragment_base(&empty, true), TESSELLATION_BASE);
|
||||
assert_eq!(fragment_base(&empty, false), 0);
|
||||
let one = BTreeSet::from([PushField::ArgumentTableAddress]);
|
||||
let pushed = place(Stage::Vertex, TESSELLATION_BASE, &one);
|
||||
assert_eq!(pushed.push_range, Some((TESSELLATION_BASE, 8)));
|
||||
assert_eq!(fragment_base(&pushed, true), TESSELLATION_BASE + 8);
|
||||
}
|
||||
|
||||
/// On the floor a render pipeline's fields are dense by link: a fragment function placed from
|
||||
|
||||
@@ -1677,7 +1677,7 @@ fn finish(
|
||||
}
|
||||
|
||||
stage_io::finish_merged(&mut cx)?;
|
||||
let placement = push::place(stage, cx.inputs.push_base, &cx.push);
|
||||
let placement = push::place(stage, push::base(&cx), &cx.push);
|
||||
access::accept_placement(&cx, &placement)?;
|
||||
// On the floor every stage that pushes more than one short field ends with its tail, a hole
|
||||
// above the others, so every load a driver widens from them stays inside its upload.
|
||||
|
||||
@@ -694,7 +694,8 @@ pub(crate) fn vertex_push_end(
|
||||
let analyzed = analyze_one(r, p, m)?;
|
||||
let widest = crate::lower::simd::WidestPin::Weighed;
|
||||
let (plan, _) = analyzed.select(p, widest, m)?;
|
||||
Ok((plan.push.push_range).map_or(0, |(offset, size)| offset + size))
|
||||
let tessellated = crate::lower::tessellation::interface(&plan).is_some();
|
||||
Ok(crate::lower::push::fragment_base(&plan.push, tessellated))
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1082,8 +1082,9 @@ pub struct PushPlacement {
|
||||
/// Every field, in placement order.
|
||||
pub fields: Vec<PlacedField>,
|
||||
/// `(offset, size)` of the stage's push-constant range, when any field is pushed. The offset
|
||||
/// is the stage window's start: vertex 0, fragment 64, compute 0; on `Device::from_queries`'
|
||||
/// profile a fragment function's `LoweringInputs::push_base`.
|
||||
/// is the stage window's start: a kernel's 0, a vertex function's 0 (24 for a
|
||||
/// post-tessellation function, past its pipeline's control stage's range), a fragment
|
||||
/// function's `LoweringInputs::push_base`.
|
||||
pub push_range: Option<(u32, u32)>,
|
||||
/// Byte size of the stage's `ArgumentTable` uniform buffer (a multiple of 16); 0 without one.
|
||||
/// Under the identity domains it is the size of the parameter block at
|
||||
|
||||
@@ -342,9 +342,10 @@ impl SymbolTable for Linked {
|
||||
}
|
||||
|
||||
/// A render pipeline's fragment function pushes after its vertex function: its push fields
|
||||
/// start at or past the vertex function's end, which the floor's one range gives where the
|
||||
/// fragment compiled under its vertex function's `CompiledFunction::fragment_push_base`.
|
||||
/// `InvalidDescriptor(PushBase)` where it does not.
|
||||
/// start at or past the vertex function's end (`push::fragment_base`: past the control stage's
|
||||
/// range behind a post-tessellation function that pushes nothing), which the floor's one range
|
||||
/// gives where the fragment compiled under its vertex function's
|
||||
/// `CompiledFunction::fragment_push_base`. `InvalidDescriptor(PushBase)` where it does not.
|
||||
fn check_push_base(ifaces: &[&StageInterface]) -> Result<(), Error> {
|
||||
let [vertex, fragment, ..] = ifaces else {
|
||||
return Ok(());
|
||||
@@ -352,7 +353,7 @@ fn check_push_base(ifaces: &[&StageInterface]) -> Result<(), Error> {
|
||||
if vertex.stage != Stage::Vertex || fragment.stage != Stage::Fragment {
|
||||
return Ok(());
|
||||
}
|
||||
let vertex_end = (vertex.push.push_range).map_or(0, |(offset, size)| offset + size);
|
||||
let vertex_end = crate::lower::push::fragment_base(&vertex.push, vertex.tessellation.is_some());
|
||||
match fragment.push.push_range {
|
||||
Some((start, _)) if start < vertex_end => {
|
||||
Err(Error::InvalidDescriptor(DescriptorError::PushBase {
|
||||
|
||||
@@ -35,7 +35,9 @@
|
||||
//! buffers of the control stage ([`ControlPlan::slots`]), among set 0's bindings and places the control stage's push range
|
||||
//! ([`control::PUSH_BYTES`]) at the first 4-byte-aligned offset no other stage's range covers
|
||||
//! ([`push_offset`]), within `maxPushConstantsSize` (`Unsupported{Tessellation; Limit}`
|
||||
//! otherwise). A fragment function that reads `[[primitive_id]]` behind the evaluation stage is
|
||||
//! otherwise): 0, as the post-tessellation vertex function's window starts past those bytes
|
||||
//! (`push::TESSELLATION_BASE`) and its fragment function's behind it, so the range fits beside
|
||||
//! theirs on every device the floor admits. A fragment function that reads `[[primitive_id]]` behind the evaluation stage is
|
||||
//! not implemented ([`check_fragment`]): Vulkan's primitive id there counts patches, and what
|
||||
//! Metal's is for a tessellated triangle has not been read.
|
||||
//!
|
||||
|
||||
@@ -949,8 +949,9 @@ pub struct LoweringInputs {
|
||||
pub unit_axes: u8,
|
||||
/// Where a fragment function's push fields start on `Device::from_queries`' profile
|
||||
///, whose render pipeline pushes one range `[0, 256)` for both stages:
|
||||
/// its vertex function's fields first, from 0, then the fragment function's from this offset,
|
||||
/// the vertex function's push end
|
||||
/// its vertex function's fields first, from 0 (from 24 for a post-tessellation function, past
|
||||
/// the control stage's range), then the fragment function's from this offset, the vertex
|
||||
/// function's push end
|
||||
/// ([`CompiledFunction::fragment_push_base`](crate::library::CompiledFunction::fragment_push_base)).
|
||||
/// `Device::compile_render_pipeline` sets it for a `Function` fragment stage from the vertex
|
||||
/// function it compiled, and `Device::render_pipeline_key` hands it out in the fragment
|
||||
|
||||
+4
-1
@@ -132,7 +132,10 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
|
||||
the command reads it. A kernel's window is 256 bytes, as the runtime's floor requires that much
|
||||
`maxPushConstantsSize`: a dispatch region and 24 buffer addresses below its tail. A render
|
||||
pipeline's two functions share one 256-byte range: the vertex function's window is `[0, 248)`,
|
||||
and the fragment function's runs from the vertex function's end to 256. A
|
||||
and the fragment function's runs from the vertex function's end to 256. A post-tessellation
|
||||
vertex function's window is `[24, 248)`, and its fragment function's starts at 24 or past: the
|
||||
pipeline's control stage pushes its fields (8 to 24 bytes) at 0, so the pair's fields, which
|
||||
spill where they pass their windows, never take its bytes. A
|
||||
vertex function is lowered without knowing its fragment function, so it leaves the last 8
|
||||
bytes, where a fragment function whose fields spill always pushes its block's address; that
|
||||
costs only a vertex function whose own fields pass 248 bytes, which spills where it would have
|
||||
|
||||
Reference in new issue
Block a user