fix(metal): on a device that fixes each pipeline's topology class, as RADV, points and lines drawn with a render pipeline that names no input primitive topology bind a variant built for their class, and GPU-resident draws of it are reported once and draw triangles, where the Metal device required dynamicPrimitiveTopologyUnrestricted and refused every such device
This commit is contained in:
1 parent
97f3f4e2e1
commit
f8b623bd74
10 files changed
+318
-45
No files matched your search
@@ -10,6 +10,7 @@
|
||||
//! Encoder state is the command buffer's: one encoder is active at a time,
|
||||
//! as in Metal. Its operations are in [`render`], [`compute`] and [`blit`].
|
||||
use super::{
|
||||
abi::PrimitiveTopologyClass,
|
||||
binding::{
|
||||
ArgumentTable, BufferBinding, PassImageblock, PassSamples, PushConstants, ResourceId,
|
||||
},
|
||||
@@ -148,11 +149,14 @@ pub trait Resolver: ChunkSource {
|
||||
|
||||
/// The variant of a vertex pipeline whose vertex and fragment stages
|
||||
/// filter the samplers at `bicubic` bicubically
|
||||
/// ([`RenderPipelineState::bicubic`]), compiled on first use.
|
||||
/// ([`RenderPipelineState::bicubic`]), built for primitives of `class`
|
||||
/// ([`RenderPipelinePlan::topology_variants`]; `Unspecified` for the
|
||||
/// state's own), compiled on first use.
|
||||
fn bicubic_render_pipeline(
|
||||
&mut self,
|
||||
state: &RenderPipelineState,
|
||||
bicubic: [u32; 2],
|
||||
class: PrimitiveTopologyClass,
|
||||
) -> Result<Pipeline>;
|
||||
|
||||
/// A reset query pool of `query_type` and its query count; pipeline
|
||||
|
||||
@@ -529,7 +529,7 @@ impl CommandBuffer {
|
||||
.iter()
|
||||
.fold(ShaderStages::EMPTY, |stages, &(stage, _)| stages | stage),
|
||||
rasterization: plan.rasterization_enabled,
|
||||
topology: plan.topology_class,
|
||||
topology: plan.indirect_topology(),
|
||||
patches,
|
||||
vertex_buffers: plan
|
||||
.info
|
||||
|
||||
@@ -2276,7 +2276,14 @@ impl CommandBuffer {
|
||||
"the primitive type is outside the pipeline's topology class",
|
||||
)?;
|
||||
self.bindings.require_buffers(&pipeline.interfaces)?;
|
||||
self.bind_bicubic(resolver)?;
|
||||
// A pipeline that draws triangles alone takes a variant for points
|
||||
// and lines.
|
||||
let variant = match primitive.class() {
|
||||
PrimitiveTopologyClass::Triangle => PrimitiveTopologyClass::Unspecified,
|
||||
class if pipeline.plan.topology_variants => class,
|
||||
_ => PrimitiveTopologyClass::Unspecified,
|
||||
};
|
||||
self.bind_bicubic(resolver, variant)?;
|
||||
let render = self::render(&mut self.encoder)?;
|
||||
let pipeline = render
|
||||
.pipeline
|
||||
@@ -2420,7 +2427,7 @@ impl CommandBuffer {
|
||||
index_bytes.is_some() == source.control_point_indices.is_some(),
|
||||
"indexed patch draws match the pipeline's control point index type",
|
||||
)?;
|
||||
self.bind_bicubic(resolver)?;
|
||||
self.bind_bicubic(resolver, PrimitiveTopologyClass::Unspecified)?;
|
||||
let render = self::render(&mut self.encoder)?;
|
||||
let pipeline = render
|
||||
.pipeline
|
||||
@@ -2494,9 +2501,14 @@ impl CommandBuffer {
|
||||
}
|
||||
|
||||
/// Binds the variant of the vertex pipeline whose stages filter the
|
||||
/// bicubic samplers the draw binds them bicubically, or the pipeline
|
||||
/// itself when it does.
|
||||
fn bind_bicubic(&mut self, resolver: &mut dyn Resolver) -> Result<()> {
|
||||
/// bicubic samplers the draw binds them bicubically, built for
|
||||
/// primitives of `class` unless it is `Unspecified`, or the pipeline
|
||||
/// itself when it does both.
|
||||
fn bind_bicubic(
|
||||
&mut self,
|
||||
resolver: &mut dyn Resolver,
|
||||
class: PrimitiveTopologyClass,
|
||||
) -> Result<()> {
|
||||
let render = render(&mut self.encoder)?;
|
||||
let Some(state) = render.pipeline.as_ref() else {
|
||||
return Ok(());
|
||||
@@ -2509,12 +2521,15 @@ impl CommandBuffer {
|
||||
};
|
||||
bicubic[stage] |= self.bindings.bicubic_samplers(interface.stage, interface);
|
||||
}
|
||||
let pipeline =
|
||||
if !state.outdated && (0..2).all(|stage| bicubic[stage] & !state.bicubic[stage] == 0) {
|
||||
state.pipeline
|
||||
} else {
|
||||
Some(resolver.bicubic_render_pipeline(state, bicubic)?)
|
||||
};
|
||||
let own = class == PrimitiveTopologyClass::Unspecified;
|
||||
let pipeline = if own
|
||||
&& !state.outdated
|
||||
&& (0..2).all(|stage| bicubic[stage] & !state.bicubic[stage] == 0)
|
||||
{
|
||||
state.pipeline
|
||||
} else {
|
||||
Some(resolver.bicubic_render_pipeline(state, bicubic, class)?)
|
||||
};
|
||||
if let Some(pipeline) = pipeline.filter(|&pipeline| render.bound != Some(pipeline)) {
|
||||
render.bound = Some(pipeline);
|
||||
self.recorder.push(Command::BindPipeline {
|
||||
|
||||
@@ -72,6 +72,8 @@ struct MockResolver {
|
||||
layouts: Vec<GeneratedLayoutKey>,
|
||||
/// The bicubic samplers of each render variant asked for.
|
||||
bicubic: Vec<[u32; 2]>,
|
||||
/// The topology class of each variant bound.
|
||||
topology_classes: Vec<PrimitiveTopologyClass>,
|
||||
}
|
||||
|
||||
impl ChunkSource for MockResolver {
|
||||
@@ -113,9 +115,13 @@ impl Resolver for MockResolver {
|
||||
&mut self,
|
||||
_: &RenderPipelineState,
|
||||
bicubic: [u32; 2],
|
||||
class: PrimitiveTopologyClass,
|
||||
) -> Result<Pipeline> {
|
||||
self.bicubic.push(bicubic);
|
||||
Ok(Pipeline(800 + u64::from(bicubic[0] | bicubic[1] << 16)))
|
||||
self.topology_classes.push(class);
|
||||
Ok(Pipeline(
|
||||
800 + u64::from(bicubic[0] | bicubic[1] << 16) + (class.raw() << 40),
|
||||
))
|
||||
}
|
||||
|
||||
fn mesh_pipeline(
|
||||
@@ -866,6 +872,65 @@ fn draws_bind_no_variant_for_samplers_their_pipeline_filters_bicubically() {
|
||||
assert!(resolver.bicubic.is_empty());
|
||||
}
|
||||
|
||||
/// A pipeline without an input primitive topology on a device that fixes
|
||||
/// each pipeline's topology class draws triangles itself, and points and
|
||||
/// lines through a variant built for their class.
|
||||
#[test]
|
||||
fn points_and_lines_of_fixed_class_pipelines_bind_their_class_variant() {
|
||||
let color = texture(PixelFormat::Rgba8Unorm);
|
||||
let draws = [
|
||||
PrimitiveType::Point,
|
||||
PrimitiveType::Triangle,
|
||||
PrimitiveType::LineStrip,
|
||||
PrimitiveType::Line,
|
||||
PrimitiveType::TriangleStrip,
|
||||
];
|
||||
for variants in [true, false] {
|
||||
let mut resolver = MockResolver::default();
|
||||
let mut commands = CommandBuffer::new(FEATURES);
|
||||
commands
|
||||
.begin_render(
|
||||
&mut resolver,
|
||||
pass(&color, StoreAction::Store, false),
|
||||
None,
|
||||
Vec::new(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut state = render_state(1);
|
||||
state.plan.topology_class = PrimitiveTopologyClass::Unspecified;
|
||||
state.plan.topology_variants = variants;
|
||||
commands.set_render_pipeline_state(&state).unwrap();
|
||||
commands
|
||||
.set_render_buffer(Stage::Vertex, Some(buffer(3, 256)), 0, 2)
|
||||
.unwrap();
|
||||
for primitive in draws {
|
||||
commands
|
||||
.draw_primitives(&mut resolver, primitive, 0, 3, 1, 0)
|
||||
.unwrap();
|
||||
}
|
||||
commands.end_encoding(&mut resolver).unwrap();
|
||||
let recording = commit(commands, &mut resolver, (Semaphore(1), 1));
|
||||
let pipelines: Vec<Pipeline> = recording.segments[0]
|
||||
.commands
|
||||
.iter()
|
||||
.filter_map(|command| match command {
|
||||
Command::BindPipeline { pipeline, .. } => Some(*pipeline),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let variant = |class: PrimitiveTopologyClass| Pipeline(800 + (class.raw() << 40));
|
||||
if variants {
|
||||
use PrimitiveTopologyClass::{Line, Point};
|
||||
assert_eq!(resolver.topology_classes, [Point, Line, Line]);
|
||||
let own = Pipeline(42);
|
||||
assert_eq!(pipelines, [own, variant(Point), own, variant(Line), own]);
|
||||
} else {
|
||||
assert!(resolver.topology_classes.is_empty());
|
||||
assert_eq!(pipelines, [Pipeline(42)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A pipeline made before its process's first bicubic or pixel-coordinate
|
||||
/// sampler draws through a variant compiled since, whatever it binds.
|
||||
#[test]
|
||||
|
||||
@@ -60,7 +60,7 @@ impl ClassKey {
|
||||
.find(|interface| interface.stage == Stage::Fragment);
|
||||
Self {
|
||||
info,
|
||||
topology: plan.topology_class,
|
||||
topology: plan.indirect_topology(),
|
||||
patches: plan.tessellation.as_ref().map(|tessellation| {
|
||||
match tessellation.control_point_index {
|
||||
TessellationControlPointIndexType::None => RecordLayout::DRAW_PATCHES,
|
||||
|
||||
@@ -283,9 +283,11 @@ struct RenderObject {
|
||||
/// A vertex pipeline's request, which its bicubic variants compile.
|
||||
request: Option<RenderPipelineRequest>,
|
||||
/// Variants whose vertex and fragment stages filter the samplers at
|
||||
/// these indices bicubically ([`RenderPipelineState::bicubic`]), and
|
||||
/// whether their process had made such samplers when they compiled.
|
||||
bicubic: Vec<([u32; 2], bool, Pipeline)>,
|
||||
/// these indices bicubically ([`RenderPipelineState::bicubic`]), built
|
||||
/// for primitives of a topology class (`Unspecified` for the state's
|
||||
/// own, [`RenderPipelinePlan::topology_variants`]), and whether their
|
||||
/// process had made such samplers when they compiled.
|
||||
bicubic: Vec<([u32; 2], PrimitiveTopologyClass, bool, Pipeline)>,
|
||||
}
|
||||
|
||||
/// The object and mesh functions of a mesh pipeline, which its variants
|
||||
@@ -1271,8 +1273,22 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
} else {
|
||||
[0; 2]
|
||||
};
|
||||
let (vulkan, plan, interfaces) =
|
||||
self.create_render(request, linkings, &sources, bicubic, indirect_bindable)?;
|
||||
let (vulkan, plan, interfaces) = self.create_render(
|
||||
request,
|
||||
linkings,
|
||||
&sources,
|
||||
bicubic,
|
||||
indirect_bindable,
|
||||
PrimitiveTopologyClass::Unspecified,
|
||||
)?;
|
||||
if plan.topology_variants && plan.info.indirect_bindable {
|
||||
// GPU-resident commands bind no variants: such a pipeline's
|
||||
// point and line draws there draw nothing.
|
||||
self.unsupported(
|
||||
"GPU-resident point and line draws of render pipelines without an input \
|
||||
primitive topology on a device that fixes each pipeline's topology class",
|
||||
);
|
||||
}
|
||||
self.tests_fragments |= plan.tests_fragments;
|
||||
let indirect = if plan.info.indirect_bindable {
|
||||
match self.add_indirect_render(&plan, &interfaces, vulkan) {
|
||||
@@ -1332,6 +1348,7 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
sources: &Sources,
|
||||
[vertex_bicubic, fragment_bicubic]: [u32; 2],
|
||||
indirect_bindable: bool,
|
||||
class: PrimitiveTopologyClass,
|
||||
) -> Result<(Pipeline, RenderPipelinePlan, Vec<Interface>)> {
|
||||
let pipelines = &self.pipelines;
|
||||
let function = pipelines.interface(request.vertex_function)?;
|
||||
@@ -1411,7 +1428,10 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
fragment_function: fragment.as_ref(),
|
||||
vertex_descriptor: request.vertex_descriptor.as_ref(),
|
||||
targets: request.targets,
|
||||
input_primitive_topology: request.input_primitive_topology,
|
||||
input_primitive_topology: match class {
|
||||
PrimitiveTopologyClass::Unspecified => request.input_primitive_topology,
|
||||
class => class,
|
||||
},
|
||||
max_vertex_amplification_count: request.max_vertex_amplification_count,
|
||||
tessellation: tessellation.as_ref().zip(feeding).map(
|
||||
|(tessellation, [vertex, control])| TessellatedVertex {
|
||||
@@ -1421,12 +1441,20 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
},
|
||||
),
|
||||
};
|
||||
let fixed_class = !self
|
||||
.backend
|
||||
.physical_device()
|
||||
.features
|
||||
.dynamic_primitive_topology_unrestricted;
|
||||
// The driver compiles the NIR into the pipeline, which outlives it.
|
||||
let start = self.timing.now();
|
||||
let created =
|
||||
pipeline::render_pipeline(&self.capabilities, &descriptor).and_then(|mut plan| {
|
||||
let start = self.timing.since(Phase::PipelinePlan, start);
|
||||
plan.info.indirect_bindable = indirect_bindable;
|
||||
plan.topology_variants = fixed_class
|
||||
&& plan.tessellation.is_none()
|
||||
&& descriptor.input_primitive_topology == PrimitiveTopologyClass::Unspecified;
|
||||
let pipeline = self.create_from(sources, |backend, source| {
|
||||
plan.info.source = source;
|
||||
backend.create_graphics_pipeline(&plan.info)
|
||||
@@ -1587,10 +1615,21 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
/// The vertex pipeline whose vertex and fragment stages filter the
|
||||
/// samplers at `bicubic` bicubically, for draws binding bicubic samplers
|
||||
/// there; compiled on first use.
|
||||
pub(super) fn render_variant(&mut self, id: u64, bicubic: [u32; 2]) -> Result<Pipeline> {
|
||||
pub(super) fn render_variant(
|
||||
&mut self,
|
||||
id: u64,
|
||||
bicubic: [u32; 2],
|
||||
class: PrimitiveTopologyClass,
|
||||
) -> Result<Pipeline> {
|
||||
let index = u32::try_from(id).map_err(|_| Error::Invalid("unknown pipeline"))?;
|
||||
let render = self.pipelines.render.get(index)?;
|
||||
// Only a pipeline of topology variants builds one for a class.
|
||||
let class = match render.state.plan.topology_variants {
|
||||
true => class,
|
||||
false => PrimitiveTopologyClass::Unspecified,
|
||||
};
|
||||
if bicubic == render.state.bicubic
|
||||
&& class == PrimitiveTopologyClass::Unspecified
|
||||
&& !render.state.outdated
|
||||
&& let Some(pipeline) = render.state.pipeline
|
||||
{
|
||||
@@ -1601,10 +1640,13 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
.clone()
|
||||
.ok_or(Error::Invalid("not a vertex pipeline"))?;
|
||||
let arguments = self.admitted(request.vertex_function)?;
|
||||
if let Some((_, _, pipeline)) = render
|
||||
.bicubic
|
||||
.iter()
|
||||
.find(|(known, admitted, _)| *known == bicubic && *admitted == arguments)
|
||||
if let Some((_, _, _, pipeline)) =
|
||||
render
|
||||
.bicubic
|
||||
.iter()
|
||||
.find(|(known, known_class, admitted, _)| {
|
||||
*known == bicubic && *known_class == class && *admitted == arguments
|
||||
})
|
||||
{
|
||||
return Ok(*pipeline);
|
||||
}
|
||||
@@ -1621,12 +1663,13 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
&Sources::default(),
|
||||
bicubic,
|
||||
false,
|
||||
class,
|
||||
)?;
|
||||
self.pipelines
|
||||
.render
|
||||
.get_mut(index)?
|
||||
.bicubic
|
||||
.push((bicubic, arguments, pipeline));
|
||||
.push((bicubic, class, arguments, pipeline));
|
||||
Ok(pipeline)
|
||||
}
|
||||
|
||||
@@ -1744,7 +1787,10 @@ impl<B: Backend, C: Compiler> Device<B, C> {
|
||||
(_, pipeline) => pipeline,
|
||||
};
|
||||
let variants = render.variants.into_iter().map(|(_, _, pipeline)| pipeline);
|
||||
let bicubic = render.bicubic.into_iter().map(|(_, _, pipeline)| pipeline);
|
||||
let bicubic = render
|
||||
.bicubic
|
||||
.into_iter()
|
||||
.map(|(_, _, _, pipeline)| pipeline);
|
||||
for pipeline in pipeline.into_iter().chain(variants).chain(bicubic) {
|
||||
self.defer(Object::Pipeline(pipeline));
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ use super::{
|
||||
};
|
||||
use crate::metal::{
|
||||
abi::{
|
||||
LoadAction, MultisampleDepthResolveFilter, MultisampleStencilResolveFilter, StoreAction,
|
||||
StoreActionOptions, VisibilityResultType,
|
||||
LoadAction, MultisampleDepthResolveFilter, MultisampleStencilResolveFilter,
|
||||
PrimitiveTopologyClass, StoreAction, StoreActionOptions, VisibilityResultType,
|
||||
},
|
||||
binding::ResourceId,
|
||||
command_buffer::{
|
||||
@@ -2710,8 +2710,9 @@ impl<B: Backend, C: Compiler> Resolver for DeviceResolver<'_, B, C> {
|
||||
&mut self,
|
||||
state: &RenderPipelineState,
|
||||
bicubic: [u32; 2],
|
||||
class: PrimitiveTopologyClass,
|
||||
) -> Result<Pipeline> {
|
||||
self.device.render_variant(state.id, bicubic)
|
||||
self.device.render_variant(state.id, bicubic, class)
|
||||
}
|
||||
|
||||
fn mesh_pipeline(
|
||||
|
||||
@@ -1141,21 +1141,35 @@ fn pipelines_made_before_admission_compile_again_on_next_use() {
|
||||
let state = device.render_pipeline_state(id).unwrap();
|
||||
(state.id, state.pipeline.unwrap())
|
||||
};
|
||||
let early = device.render_variant(state_id, [0, 1]).unwrap();
|
||||
let early = device
|
||||
.render_variant(state_id, [0, 1], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap();
|
||||
device.admit_bicubic(vertex).unwrap();
|
||||
device.admit_bicubic(fragment).unwrap();
|
||||
device.outdate_pipelines(&[vertex, fragment]);
|
||||
assert!(device.render_pipeline_state(id).unwrap().outdated);
|
||||
let compiled = device.compiler.compiled.len();
|
||||
let late = device.render_variant(state_id, [0; 2]).unwrap();
|
||||
let late = device
|
||||
.render_variant(state_id, [0; 2], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap();
|
||||
assert_ne!(late, base);
|
||||
assert_ne!(device.render_variant(state_id, [0, 1]).unwrap(), early);
|
||||
assert_ne!(
|
||||
device
|
||||
.render_variant(state_id, [0, 1], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap(),
|
||||
early
|
||||
);
|
||||
assert!(
|
||||
device.compiler.compiled[compiled..]
|
||||
.iter()
|
||||
.all(|stage| stage.bicubic_arguments)
|
||||
);
|
||||
assert_eq!(device.render_variant(state_id, [0; 2]).unwrap(), late);
|
||||
assert_eq!(
|
||||
device
|
||||
.render_variant(state_id, [0; 2], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap(),
|
||||
late
|
||||
);
|
||||
}
|
||||
|
||||
fn bicubic_request(vertex: FunctionId, fragment: FunctionId) -> RenderPipelineRequest {
|
||||
@@ -1174,6 +1188,97 @@ fn bicubic_request(vertex: FunctionId, fragment: FunctionId) -> RenderPipelineRe
|
||||
}
|
||||
}
|
||||
|
||||
/// A device that fixes each pipeline's topology class builds a variant of
|
||||
/// a pipeline without an input primitive topology for each class it draws,
|
||||
/// once; a device that does not, and a pipeline of a class, draw every
|
||||
/// primitive with the pipeline itself.
|
||||
#[test]
|
||||
fn fixed_class_devices_build_a_variant_per_drawn_class() {
|
||||
use crate::metal::vulkan::PrimitiveTopology;
|
||||
for unrestricted in [false, true] {
|
||||
let mut backend = MockBackend::new();
|
||||
if let Some(physical) = &mut backend.physical {
|
||||
physical.features.dynamic_primitive_topology_unrestricted = unrestricted;
|
||||
}
|
||||
let mut device = device_on(backend);
|
||||
let vertex = device.new_function(LIBRARY, "vertex", Some(&[])).unwrap();
|
||||
let fragment = device.new_function(LIBRARY, "fragment", Some(&[])).unwrap();
|
||||
for class in [
|
||||
PrimitiveTopologyClass::Unspecified,
|
||||
PrimitiveTopologyClass::Triangle,
|
||||
] {
|
||||
let request = RenderPipelineRequest {
|
||||
input_primitive_topology: class,
|
||||
..bicubic_request(vertex, fragment)
|
||||
};
|
||||
let id = device.new_render_pipeline(&request).unwrap();
|
||||
let state = device.render_pipeline_state(id).unwrap();
|
||||
let (state_id, base) = (state.id, state.pipeline.unwrap());
|
||||
let variants = !unrestricted && class == PrimitiveTopologyClass::Unspecified;
|
||||
assert_eq!(state.plan.topology_variants, variants);
|
||||
let built = device.backend().graphics.len();
|
||||
let points = device
|
||||
.render_variant(state_id, [0; 2], PrimitiveTopologyClass::Point)
|
||||
.unwrap();
|
||||
let lines = device
|
||||
.render_variant(state_id, [0; 2], PrimitiveTopologyClass::Line)
|
||||
.unwrap();
|
||||
if variants {
|
||||
assert!(points != base && lines != base && points != lines);
|
||||
let topologies: Vec<_> = device.backend().graphics[built..]
|
||||
.iter()
|
||||
.map(|info| info.topology)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
topologies,
|
||||
[PrimitiveTopology::PointList, PrimitiveTopology::LineList]
|
||||
);
|
||||
assert_eq!(
|
||||
device
|
||||
.render_variant(state_id, [0; 2], PrimitiveTopologyClass::Point)
|
||||
.unwrap(),
|
||||
points
|
||||
);
|
||||
assert_eq!(device.backend().graphics.len(), built + 2);
|
||||
} else {
|
||||
assert_eq!((points, lines), (base, base));
|
||||
assert_eq!(device.backend().graphics.len(), built);
|
||||
}
|
||||
device.destroy_render_pipeline(id).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// GPU-resident commands bind no variants: a fixed-class device's
|
||||
/// indirect-bindable pipeline without an input primitive topology draws
|
||||
/// triangles alone there, which the device reports once.
|
||||
#[test]
|
||||
fn fixed_class_indirect_pipelines_draw_triangles_and_report_once() {
|
||||
let mut backend = MockBackend::new();
|
||||
let physical = backend.physical.as_mut().unwrap();
|
||||
physical.features.dynamic_primitive_topology_unrestricted = false;
|
||||
if physical.limits.generated_commands.is_none() {
|
||||
return;
|
||||
}
|
||||
let mut device = device_on(backend);
|
||||
let vertex = device.new_function(LIBRARY, "vertex", Some(&[])).unwrap();
|
||||
let fragment = device.new_function(LIBRARY, "fragment", Some(&[])).unwrap();
|
||||
let request = RenderPipelineRequest {
|
||||
input_primitive_topology: PrimitiveTopologyClass::Unspecified,
|
||||
support_indirect_command_buffers: true,
|
||||
..bicubic_request(vertex, fragment)
|
||||
};
|
||||
while device.take_unsupported().is_some() {}
|
||||
for _ in 0..2 {
|
||||
let id = device.new_render_pipeline(&request).unwrap();
|
||||
let plan = &device.render_pipeline_state(id).unwrap().plan;
|
||||
assert_eq!(plan.indirect_topology(), PrimitiveTopologyClass::Triangle);
|
||||
}
|
||||
let reported = device.take_unsupported().unwrap();
|
||||
assert!(reported.starts_with("GPU-resident point and line draws"));
|
||||
assert_eq!(device.take_unsupported(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bicubic_render_variants_compile_once_per_sampler_mask() {
|
||||
let mut device = device();
|
||||
@@ -1186,10 +1291,17 @@ fn bicubic_render_variants_compile_once_per_sampler_mask() {
|
||||
let (state_id, base) = (state.id, state.pipeline.unwrap());
|
||||
assert_eq!(state.bicubic, [0; 2]);
|
||||
// The pipeline's own mask is the pipeline.
|
||||
assert_eq!(device.render_variant(state_id, [0; 2]).unwrap(), base);
|
||||
assert_eq!(
|
||||
device
|
||||
.render_variant(state_id, [0; 2], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap(),
|
||||
base
|
||||
);
|
||||
|
||||
let compiled = device.compiler.compiled.len();
|
||||
let variant = device.render_variant(state_id, [0, 1 << 2]).unwrap();
|
||||
let variant = device
|
||||
.render_variant(state_id, [0, 1 << 2], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap();
|
||||
assert_ne!(variant, base);
|
||||
let stages: Vec<_> = device.compiler.compiled[compiled..]
|
||||
.iter()
|
||||
@@ -1198,11 +1310,15 @@ fn bicubic_render_variants_compile_once_per_sampler_mask() {
|
||||
assert_eq!(stages, [0, 1 << 2]);
|
||||
// The variant compiles once; another mask is another variant.
|
||||
assert_eq!(
|
||||
device.render_variant(state_id, [0, 1 << 2]).unwrap(),
|
||||
device
|
||||
.render_variant(state_id, [0, 1 << 2], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap(),
|
||||
variant
|
||||
);
|
||||
assert_eq!(device.compiler.compiled.len(), compiled + 2);
|
||||
let other = device.render_variant(state_id, [1, 1 << 2]).unwrap();
|
||||
let other = device
|
||||
.render_variant(state_id, [1, 1 << 2], PrimitiveTopologyClass::Unspecified)
|
||||
.unwrap();
|
||||
assert!(other != variant && other != base);
|
||||
assert_eq!(device.compiler.compiled.len(), compiled + 4);
|
||||
device.destroy_render_pipeline(id).unwrap();
|
||||
|
||||
@@ -105,7 +105,9 @@ pub const fn stencil_op(operation: StencilOperation) -> StencilOp {
|
||||
}
|
||||
|
||||
/// The pipeline topology for a Metal input class; draws set the exact
|
||||
/// topology dynamically (`dynamicPrimitiveTopologyUnrestricted`).
|
||||
/// topology of the class dynamically, and of another class too where the
|
||||
/// device has `dynamicPrimitiveTopologyUnrestricted`
|
||||
/// ([`RenderPipelinePlan::topology_variants`] where it has not).
|
||||
pub const fn class_topology(class: PrimitiveTopologyClass) -> PrimitiveTopology {
|
||||
match class {
|
||||
PrimitiveTopologyClass::Point => PrimitiveTopology::PointList,
|
||||
@@ -447,6 +449,26 @@ pub struct RenderPipelinePlan {
|
||||
/// test no depth or stencil in the pipeline, and the pass's depth and
|
||||
/// stencil live in their copies while they draw.
|
||||
pub tests_fragments: bool,
|
||||
/// Its Vulkan pipeline draws triangles alone: the device fixes a
|
||||
/// pipeline's topology class (it lacks
|
||||
/// `dynamicPrimitiveTopologyUnrestricted`) and the state has no input
|
||||
/// primitive topology. Point and line draws bind a variant built for
|
||||
/// their class ([`Resolver::bicubic_render_pipeline`]).
|
||||
///
|
||||
/// [`Resolver::bicubic_render_pipeline`]: super::command_buffer::Resolver::bicubic_render_pipeline
|
||||
pub topology_variants: bool,
|
||||
}
|
||||
|
||||
impl RenderPipelinePlan {
|
||||
/// The topology class of the primitives GPU-resident commands draw
|
||||
/// with it, which bind no variants: triangles alone for a pipeline of
|
||||
/// topology variants.
|
||||
pub fn indirect_topology(&self) -> PrimitiveTopologyClass {
|
||||
match self.topology_variants {
|
||||
true => PrimitiveTopologyClass::Triangle,
|
||||
false => self.topology_class,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_pipeline(
|
||||
@@ -938,6 +960,7 @@ fn targets(
|
||||
mesh: None,
|
||||
tessellation: None,
|
||||
tests_fragments,
|
||||
topology_variants: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -514,7 +514,14 @@ pub struct Requirement {
|
||||
/// promises that `GENERAL` costs nothing beside the optimal layouts, and
|
||||
/// lets `GENERAL` stand for the attachment feedback loop and video layouts,
|
||||
/// which the layer never uses. The device enables it when offered.
|
||||
pub fn requirements(features: &Features) -> [Requirement; 19] {
|
||||
///
|
||||
/// Nor is `dynamicPrimitiveTopologyUnrestricted`: a device without it draws
|
||||
/// points and lines of a pipeline without an input primitive topology with
|
||||
/// a variant built for their class
|
||||
/// ([`RenderPipelinePlan::topology_variants`]).
|
||||
///
|
||||
/// [`RenderPipelinePlan::topology_variants`]: crate::metal::pipeline::RenderPipelinePlan::topology_variants
|
||||
pub fn requirements(features: &Features) -> [Requirement; 18] {
|
||||
let requirement = |name, present| Requirement { name, present };
|
||||
[
|
||||
requirement("bufferDeviceAddress", features.buffer_device_address),
|
||||
@@ -564,10 +571,6 @@ pub fn requirements(features: &Features) -> [Requirement; 19] {
|
||||
"dynamicRenderingUnusedAttachments",
|
||||
features.dynamic_rendering_unused_attachments,
|
||||
),
|
||||
requirement(
|
||||
"dynamicPrimitiveTopologyUnrestricted",
|
||||
features.dynamic_primitive_topology_unrestricted,
|
||||
),
|
||||
requirement("hostQueryReset", features.host_query_reset),
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user