rt: the depth clip mode Clamp and the triangle fill mode Lines, as pipelines of the draw's class made at first use

setDepthClipMode: and setTriangleFillMode: refused every value but Metal's defaults
(DrawKind::DepthClamp, DrawKind::FillMode). Vulkan 1.3 bakes both in
VkPipelineRasterizationStateCreateInfo, and only VK_EXT_extended_dynamic_state3 makes them
dynamic. The floor cannot require that extension: the UHD 630's Windows driver lists no EDS3, and
KosmicKrisp reports extendedDynamicState3PolygonMode false. So both are now first-use pipeline
variants, the accepted form. The encoder keeps a Raster (clamp, lines) and each draw takes
RenderCompiled::pipeline(topology, raster). The content keeps its primary VkPipeline (the triangle
or patch class at the default state) and a bounded list of the others, by class list topology and
raster state: at most 7 (three more states of the triangle or patch class, two of each other
class). The line and point classes take the clip mode alone, since Metal and Vulkan apply the fill
mode to triangles only. A triangle's edges under Lines chain Bresenham's rule, as the line class
does ("the effective rasterization input topology is in the line topology class"). The first draw
under a state makes its pipeline and waits for it: a first-use wait of a new site,
FirstUse::Raster (Metrics::first_use_raster_waits, _nanos, _max_nanos). The line and point
classes' first draws at the default state count where they did.

Floor:
- depthClamp joins REQUIRED, and the translator is told (=> DepthClamp), so the encoder maps the
  mode through metal::state::depth_clamp_enable. Vulkan 1.4 and Roadmap 2022 require it. The venue
  dumps report it true on every venue: m3-max-48727, 48728, 48729, 48730, 48731, 48736, 48737 and
  61508. tests/floor.rs, the README floor table, RUNTIME_FLOOR and profiles/runtime-floor.json
  add it.
- fillModeNonSolid is enabled where reported (FILL_MODES, told to the translator), and the setter
  maps Lines through metal::state::polygon_mode. KosmicKrisp on the M3 Max reports it false
  (m3-max-48737); every other dumped venue reports it true. There Lines stays DrawKind::FillMode,
  and so does the raw value 2, which no SDK header declares.

DrawKind::DepthClamp is deleted. The consumer's checkout names it nowhere (git grep in
reims-vgpu: 0 hits). Its only call sites are set_triangle_fill_mode and set_depth_clip_mode at
crates/reims-vgpu-vulkan/src/rt_platform/render.rs:371 and :374, whose signatures are unchanged.

The translator's raster-state test reads runtime-floor, which now states depthClamp. Clamp maps
there, and the refusal is asserted on runtime-floor without it, as ab8277a560 did for
depthBiasClamp. Other translator tests that read runtime-floor were grepped for DepthClamp and
FillModeNonSolid, and none reads the floor as lacking them.

Known gaps (README): a content's first draw under Clamp or Lines makes a VkPipeline, which Metal
does not. Under Clamp the depth a fragment function writes is the device's clamp's: Metal stores a
negative NaN as 0 below a range above 0, and the translator's depth_clamp_range variant is not
drawn.

Conformance: render-state-depth-clip and render-state-facing leave known-gaps-rt.tsv;
CONFORMANCE-COVERAGE.md regenerated. Docs: README (encoder, first-use waits, floor and fill-mode
tables, known gaps), REFUSALS.md, the api_signatures table (3 Metrics fields, 1 variant gone).

Tests:
- tests/raster.rs: a triangle in front of the near plane draws nothing under Clip and every
  texel under Clamp (twice: one pipeline made). Under Lines, through a viewport half a pixel
  right of and above the corner, the triangle draws its two edges inside the target, column 0
  and row 7, and nothing inside. Without fillModeNonSolid it is FillMode and fills. Pipelines
  made, raster first-use waits and first-use waits are each 1 + fillModeNonSolid.
- draw.rs: setting both modes makes no pipeline when no draw follows.
- floor.rs: depthClamp's missing case, and the fill-mode feature enabled where reported.
- first_use_sites.rs: the raster site.
This commit is contained in:
Anees Iqbal committed 2026-11-21 00:14:34 -08:00
1 parent 43f7439dc9
commit a5fac6fa9b
18 files changed
+426 -125

No files matched your search

@@ -6088,8 +6088,6 @@ read-write-tier-round-trip-float AMD Radeon 780M refused case/MTLPixelFormatRGBA
read-write-tier-round-trip-float RX 7900 XTX refused case/MTLPixelFormatRGBA8Unorm_sRGB/beyond/read-write Err(Error::Unsupported("texture slot 0, which a function writes or reads as storage, bound to a RGBA8UnormSRGB texture with no storage element on this device, or one it cannot read without a format, is not built")) The device's own answer (rule 2): this device's format queries offer no storage image of MTLPixelFormatRGBA8Unorm_sRGB, so rt binds no such texture to a read_write or write slot.
read-write-tier-round-trip-float NVIDIA refused case/MTLPixelFormatRGBA8Unorm_sRGB/beyond/read-write Err(Error::Unsupported("texture slot 0, which a function writes or reads as storage, bound to a RGBA8UnormSRGB texture with no storage element on this device, or one it cannot read without a format, is not built")) The device's own answer (rule 2): this device's format queries offer no storage image of MTLPixelFormatRGBA8Unorm_sRGB, so rt binds no such texture to a read_write or write slot.
read-write-tier-round-trip-float Iris(R) Xe refused case/MTLPixelFormatRGBA8Unorm_sRGB/beyond/read-write Err(Error::Unsupported("texture slot 0, which a function writes or reads as storage, bound to a RGBA8UnormSRGB texture with no storage element on this device, or one it cannot read without a format, is not built")) The device's own answer (rule 2): this device's format queries offer no storage image of MTLPixelFormatRGBA8Unorm_sRGB, so rt binds no such texture to a read_write or write slot.
render-state-depth-clip * refused case/pieces/pass Err(Error::Unsupported("a draw with DepthClamp is not built")) refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, every depth clip mode Clip). rt refuses it (a draw with DepthClamp is not built), and no replay stream asks it.
render-state-facing * refused case/pieces/pass Err(Error::Unsupported("a draw with FillMode is not built")) refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, every setTriangleFillMode: Fill). rt refuses it (a draw with FillMode is not built), and no replay stream asks it.
render-state-heap-residency * refused case/heap Err(Unavailable({call: "sparse_heap"})) refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, no sparse texture, heap or tile call). The rt side of the suite answers `sparse_heap` Unavailable: rt has no counterpart of the call, and no replay stream makes it.
render-state-render-barriers * refused case/pieces/pass Err(Unavailable({call: "render step UseResourceInStages"})) refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, no useResource:usage:stages: or useHeap:stages:). The rt side of the suite answers `render step UseResourceInStages` Unavailable: rt has no counterpart of the call, and no replay stream makes it.
render-state-texture-accesses * refused case/pipeline Err(Unavailable({call: "render_pipeline_with_reflection"})) refused: the consumer's own (MTLComputePipelineReflection, MTLRenderPipelineReflection, MTLPipelineOptionFailOnBinaryArchiveMiss, MTLPipelineOptionArgumentInfo, MTLPipelineOptionBufferTypeInfo, MTLPipelineOptionBindingInfo). rt builds no reflection and acts on no pipeline option; its consumer builds reflection from the library's AIR.
Can't render this file because it is too large.
+33 -9
View File
@@ -2341,7 +2341,9 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
`first_use_wait_nanos` and the longest in `first_use_wait_max_nanos`, and again by where it
waited, each with its count, time and longest: `first_use_variant_waits` (a kernel's pipeline
for a new workgroup size, threadgroup memory lengths or tiles), `first_use_line_waits` (a
render content's line-class pipeline) and `first_use_point_waits` (its point-class pipeline).
render content's line-class pipeline), `first_use_point_waits` (its point-class pipeline) and
`first_use_raster_waits` (its pipeline under the depth clip mode `Clamp` or the triangle fill
mode `Lines`).
No dispatch lowers a function. `Counters::variant_makes(from)` answers the kept makes of
kernels' `VkPipeline`s numbered `from` or later, the last 256 to end on the device, each a
`VariantMake`: its key (the `DispatchVariant` its dispatches answer), who started it
@@ -2820,9 +2822,13 @@ or does not check is rebuilt from the generations' names, with young counted ful
cache, and so is the line or the point class's where the descriptor's `inputPrimitiveTopology`
names `MTLPrimitiveTopologyClassLine` or `MTLPrimitiveTopologyClassPoint`; otherwise each is
made by the content's first draw of lines or of points, which waits for it
(`Metrics::first_use_waits`, `first_use_line_waits`, `first_use_point_waits`). Of the two replay streams' 537 render contents
drawn, 527 draw only triangles and 2 lines and triangles; a content drawn only as lines (8 of
them) makes a triangle `VkPipeline` it never uses.
(`Metrics::first_use_waits`, `first_use_line_waits`, `first_use_point_waits`). Of the two replay
streams' 537 render contents drawn, 527 draw only triangles and 2 lines and triangles; a content
drawn only as lines (8 of them) makes a triangle `VkPipeline` it never uses. A draw under the
depth clip mode `Clamp` or the triangle fill mode `Lines` takes its class's `VkPipeline` for that
state, which the content's first such draw makes and waits for (`first_use_raster_waits`). The
fill mode is a triangle's alone, in Metal and in Vulkan, so a draw of lines or points takes the
clip mode alone, and a triangle's edges under `Lines` are drawn by Bresenham's rule as lines are.
- A point is as wide as the `PointSize` the vertex module writes: the function's `[[point_size]]`,
stored as Metal's largest point, 511 pixels, where it is past it, which the device draws through
`largePoints` (Floor) and clamps to its `pointSizeRange` (`PrecisionNote::DevicePointSize` where
@@ -2919,8 +2925,13 @@ or does not check is rebuilt from the generations' names, with young counted ful
`Error::Translation` naming `RasterOrderGroups` and `fragmentShaderPixelInterlock`. Of the venues
run, KosmicKrisp on the M3 Max and RADV on the RX 550 list neither the extension nor the feature
(vulkaninfo, jobs m3-max-61291 and m3-max-61296).
- Metal's triangle fill mode and depth clip mode, which Vulkan 1.3 bakes into a `VkPipeline`, are
their defaults.
- The depth clip mode `Clamp` and the triangle fill mode `Lines`, which Vulkan 1.3 bakes into a
`VkPipeline`, are each a `VkPipeline` of the draw's class that a content's first draw under them
makes, which Metal does not: that draw waits for it (`Metrics::first_use_raster_waits`).
- Under the depth clip mode `Clamp`, the depth a fragment function writes is the device's depth
clamp's, clamped to the viewport's range. Metal stores a negative NaN there as 0, below a range
above 0; the translator's `LoweringInputs::depth_clamp_range` variant, which stores it as Metal
does, is not drawn.
- On a driver that keeps the topology class in a pipeline (dynamicPrimitiveTopologyUnrestricted
false; RADV), a render pipeline state's first draw in a second topology class compiles a second
pipeline in full when the driver's cache is cold: 225 ms for the heaviest pipeline measured on a
@@ -3234,9 +3245,10 @@ or does not check is rebuilt from the generations' names, with young counted ful
`VkBuffer`, so such a draw reads the block's later bytes as indices, and a count past the block's
end is outside Vulkan's valid usage without `robustBufferAccess2`, which the floor does not
require (`VUID-vkCmdDrawIndexedIndirect-robustBufferAccess2-08798`).
- Refused by `Gap::Draw`, naming its `DrawKind`: a triangle fill mode but `Fill`
(`FillMode`, `set_triangle_fill_mode`), the depth clip mode `Clamp` (`DepthClamp`,
`set_depth_clip_mode`), a count of viewports or scissor rectangles other than 1 (`Viewports`,
- Refused by `Gap::Draw`, naming its `DrawKind`: the triangle fill mode `Lines` on a device
without `fillModeNonSolid` (KosmicKrisp on the M3 Max, of the venues dumped, m3-max-48737) and
the fill mode of raw value 2, which no SDK header declares (`FillMode`,
`set_triangle_fill_mode`), a count of viewports or scissor rectangles other than 1 (`Viewports`,
`set_viewports`, `set_scissor_rects`), a visibility result mode but `Disabled`
(`VisibilityResults`, `set_visibility_result_mode`), each refused where it is set, the
encoder's state unchanged; the replay streams set Metal's defaults alone, which those setters
@@ -3622,6 +3634,7 @@ Presenting runs on the runtime's own device; nothing is exported or imported.
| `fullDrawIndexUint32` | `VkPhysicalDeviceFeatures` | an indexed draw's 32-bit indices past `2^24 - 1`; Vulkan 1.4 and Roadmap 2022 require it |
| `depthBiasClamp` | `VkPhysicalDeviceFeatures` | a depth bias's clamp (`set_depth_bias`), the device's own; Vulkan 1.4 and Roadmap 2022 require it |
| `drawIndirectFirstInstance` | `VkPhysicalDeviceFeatures` | an indirect draw's base instance, which the GPU reads from Metal's arguments; Vulkan 1.4 requires it |
| `depthClamp` | `VkPhysicalDeviceFeatures` | the depth clip mode `Clamp` (`set_depth_clip_mode`), a pipeline's depth clamp, the device's own; Vulkan 1.4 and Roadmap 2022 require it |
| `shaderClipDistance` | `VkPhysicalDeviceFeatures` | a vertex or post-tessellation vertex function's `[[clip_distance]]` |
| `tessellationShader` | `VkPhysicalDeviceFeatures` | a post-tessellation vertex function's patches, drawn through the device's tessellator |
| `shaderTessellationAndGeometryPointSize` | `VkPhysicalDeviceFeatures` | a post-tessellation vertex function's `[[point_size]]`; without it the device draws every such point at size 1 |
@@ -3679,6 +3692,17 @@ sample; elsewhere it refuses the function at creation, an `Error::Translation` n
|---|---|---|
| `shaderResourceMinLod` | `VkPhysicalDeviceFeatures` | a sample's `min_lod_clamp`, the device's own level-of-detail clamp |
### Fill modes
The triangle fill mode `Lines` has one form, a pipeline's `polygonMode` `LINE`. Where the device
reports the feature below, device creation enables it, and the render encoder sets the mode;
elsewhere `set_triangle_fill_mode` refuses it, `Gap::Draw` of `DrawKind::FillMode` (Known gaps of
render encoders).
| Fill-mode feature | Structure | Used for |
|---|---|---|
| `fillModeNonSolid` | `VkPhysicalDeviceFeatures` | the triangle fill mode `Lines`, each triangle's edges drawn as lines |
### Quad control
A fragment function whose group operations read, combine or count other lanes has one form: its
+25 -4
View File
@@ -111,6 +111,9 @@ pub(crate) enum FirstUse {
/// A render content's point-class pipeline, at its first draw of points
/// ([`Metrics::first_use_point_waits`]).
Points,
/// A render content's pipeline for the depth clip mode `Clamp` or the triangle fill mode
/// `Lines`, at its first draw under them ([`Metrics::first_use_raster_waits`]).
Raster,
}
/// The variant makes [`Counters::variant_makes`] keeps: the last this many to end.
@@ -561,7 +564,7 @@ struct Atomics {
first_use_wait_nanos: AtomicU64,
first_use_wait_max_nanos: AtomicU64,
/// Each [`FirstUse`] site's waits, at its index: their count, total and longest nanoseconds.
first_use_sites: [[AtomicU64; 3]; 3],
first_use_sites: [[AtomicU64; 3]; 4],
/// The makes ahead of a dispatch: their count and total nanoseconds.
made_ahead: [AtomicU64; 2],
/// [`Counters::variant_makes`].
@@ -1411,8 +1414,13 @@ impl Counters {
};
let first_use =
|site: FirstUse| (a.first_use_sites[site as usize].each_ref()).map(|n| n.load(Relaxed));
let [variant, lines, points] =
[FirstUse::Variant, FirstUse::Lines, FirstUse::Points].map(first_use);
let [variant, lines, points, raster] = [
FirstUse::Variant,
FirstUse::Lines,
FirstUse::Points,
FirstUse::Raster,
]
.map(first_use);
let made_ahead = (a.made_ahead.each_ref()).map(|n| n.load(Relaxed));
let part = |part: Part| {
let [count, bytes, total, _, over_1, over_5, over_20] = &a.parts[part as usize];
@@ -1487,6 +1495,9 @@ impl Counters {
first_use_point_waits: points[0],
first_use_point_wait_nanos: points[1],
first_use_point_wait_max_nanos: points[2],
first_use_raster_waits: raster[0],
first_use_raster_wait_nanos: raster[1],
first_use_raster_wait_max_nanos: raster[2],
made_ahead_variants: made_ahead[0],
made_ahead_variant_nanos: made_ahead[1],
blocks_made: a.blocks_made.load(Relaxed),
@@ -1883,7 +1894,8 @@ pub struct Metrics {
/// First-use waits: encoding calls that waited while the `VkPipeline` they needed was made,
/// for a workgroup size (a threadgroup size, or the tile of an image-only kernel's grid more
/// than one deep) or threadgroup memory lengths no state of the kernel's content had run with
/// before, or for a render content's first draw of lines or of points.
/// before, or for a render content's first draw of lines or of points, or under the depth
/// clip mode `Clamp` or the triangle fill mode `Lines`.
pub first_use_waits: u64,
/// The nanoseconds of [`host_time`](crate::host_time) the first-use waits took, in total.
pub first_use_wait_nanos: u64,
@@ -1916,6 +1928,15 @@ pub struct Metrics {
/// The longest of the [`first_use_point_waits`](Self::first_use_point_waits), in
/// nanoseconds; a maximum since the device was made.
pub first_use_point_wait_max_nanos: u64,
/// Of the [`first_use_waits`](Self::first_use_waits), those for a render content's pipeline
/// under the depth clip mode `Clamp` or the triangle fill mode `Lines`, made by its first draw
/// under them.
pub first_use_raster_waits: u64,
/// The nanoseconds of the [`first_use_raster_waits`](Self::first_use_raster_waits), in total.
pub first_use_raster_wait_nanos: u64,
/// The longest of the [`first_use_raster_waits`](Self::first_use_raster_waits), in
/// nanoseconds; a maximum since the device was made.
pub first_use_raster_wait_max_nanos: u64,
/// The compute kernels' pipelines that
/// [`prepare_dispatch`](crate::ComputePipelineState::prepare_dispatch) made on its caller's
/// thread, ahead of the dispatches that run them (`vkCreateComputePipelines`).
+3 -3
View File
@@ -1458,10 +1458,10 @@ pub enum KernelInputKind {
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DrawKind {
/// A triangle fill mode but `Fill` (`setTriangleFillMode:`), which no replay stream sets.
/// The triangle fill mode `Lines` (`setTriangleFillMode:`) on a device without
/// `fillModeNonSolid`, which a pipeline's `polygonMode` `LINE` needs, and the mode of raw value
/// 2, which no SDK header declares and no replay stream sets.
FillMode,
/// The depth clip mode `Clamp` (`setDepthClipMode:`), which no replay stream sets.
DepthClamp,
/// A draw of lines or a line strip while the encoder's line width (Apple's `setLineWidth:`
/// SPI, [`RenderCommandEncoder::set_line_width`](crate::RenderCommandEncoder::set_line_width))
/// is not 1: Metal draws such a line as a parallelogram that width wide; the runtime draws
+10
View File
@@ -443,6 +443,9 @@ pub(crate) const REQUIRED: &[Feature] = &[
// `firstInstance`; without it Vulkan takes 0 alone there. Vulkan 1.4 requires it of every
// device.
feature!(core.draw_indirect_first_instance),
// The depth clip mode `Clamp` (`setDepthClipMode:`), a pipeline's depth clamp, the device's
// own. Vulkan 1.4 and Roadmap 2022 require it of every device.
feature!(core.depth_clamp => DepthClamp),
// A vertex or post-tessellation vertex function's `[[clip_distance]]`, the device's own
// clipping. Every floor driver reports it.
feature!(core.shader_clip_distance => ShaderClipDistance),
@@ -541,6 +544,11 @@ pub(crate) const STEP_RATES: &[Feature] = &[feature!(
pub(crate) const MIN_LOD_CLAMPS: &[Feature] =
&[feature!(core.shader_resource_min_lod => ShaderResourceMinLod)];
/// The feature device creation enables where the device reports it, for the triangle fill mode
/// `Lines` (`setTriangleFillMode:`), a pipeline's `polygonMode` `LINE`, which the render encoder
/// refuses on a device without it (`DrawKind::FillMode`). No answer chooses a second form.
pub(crate) const FILL_MODES: &[Feature] = &[feature!(core.fill_mode_non_solid => FillModeNonSolid)];
/// The feature of `VK_KHR_shader_quad_control` (one of [`OPTIONAL_EXTENSIONS`]), which device
/// creation enables where the device lists the extension and reports it: a fragment function whose
/// group operations read, combine or count other lanes runs its quads whole
@@ -598,6 +606,7 @@ pub(crate) fn shader_enables(capabilities: &Capabilities) -> EnableSet {
.chain(PORTABILITY)
.chain(STEP_RATES)
.chain(MIN_LOD_CLAMPS)
.chain(FILL_MODES)
.chain(QUAD_CONTROL)
.chain(PIXEL_INTERLOCK)
.chain(BARYCENTRICS)
@@ -1064,6 +1073,7 @@ pub(crate) fn decide(device: &Queried) -> Result<Capabilities, BelowFloor> {
};
for feature in (OPTIONAL.iter().chain(STEP_RATES))
.chain(MIN_LOD_CLAMPS)
.chain(FILL_MODES)
.chain(QUAD_CONTROL)
.chain(PIXEL_INTERLOCK)
{
+94 -58
View File
@@ -15,15 +15,19 @@
//! the content. The cost of keying on the descriptor: two descriptors that differ only in a field
//! their compile does not read are two contents, each compiled.
//!
//! What a `VkPipeline` bakes is what Vulkan 1.3 cannot leave dynamic: the content, and the
//! topology class (point, line or triangle) of the draws it serves. Everything Metal sets on the
//! What a `VkPipeline` bakes is what Vulkan 1.3 cannot leave dynamic: the content, the topology
//! class (point, line or triangle) of the draws it serves, and the encoder's depth clip mode and
//! triangle fill mode ([`Raster`]). Everything Metal sets on the
//! encoder that Vulkan 1.3 makes dynamic without a feature is dynamic state: viewport, scissor,
//! cull mode, front face, the primitive topology within its class and primitive restart, the
//! depth test, write and compare, the stencil test, operations, masks and reference, depth bias
//! and blend constants. Vertex buffer strides are the descriptor's, so the content's: they are
//! baked, and a layout whose stride is set per bind (`MTLBufferLayoutStrideDynamic`), which the
//! replay streams' never are, is refused. Metal's triangle fill mode and depth clip mode, which
//! Vulkan 1.3 bakes, are their defaults: the render encoder does not set them yet.
//! replay streams' never are, is refused. A draw under the depth clip mode `Clamp` or the triangle
//! fill mode `Lines` takes a `VkPipeline` of its class made for that raster state, by the first
//! such draw of the content, which waits for it, as a draw of a class not made with the content
//! does: Metal sets both per encoder and compiles nothing for them. The fill mode is a triangle's
//! alone, in Metal and in Vulkan, so the line and point classes take the clip mode alone.
//!
//! What a draw supplies is the content's [`Draws`]: each function's slots with their accesses,
//! its push fields (addresses, resource IDs and indices of the slots, in the floor's one push
@@ -201,14 +205,13 @@ pub(crate) struct RenderCompiled {
/// The fixed-function state every `VkPipeline` of the content takes.
fixed: Fixed,
/// The `VkPipeline` made with the content: the triangle class's, or a post-tessellation vertex
/// function's patch class's, its only one.
/// function's patch class's, its only class, at the default [`Raster`].
primary: vk::Pipeline,
/// The line class's: made with the content where its descriptor names that class, else by the
/// first draw of lines; null until then.
lines: Mutex<vk::Pipeline>,
/// The point class's, as the line class's: made with the content where its descriptor names
/// that class, else by the first draw of points; null until then.
points: Mutex<vk::Pipeline>,
/// The content's other `VkPipeline`s, each by its class's list topology and its raster state:
/// the line or the point class's at the default raster state, made with the content where its
/// descriptor names that class, and every other, made by the first draw that takes it. At most
/// 7: the triangle or patch class's three other raster states, and two of each other class.
later: Mutex<Vec<(vk::PrimitiveTopology, Raster, vk::Pipeline)>>,
/// Whether a draw of points rasterizes them: the vertex function writes `[[point_size]]`, or
/// the descriptor names the point class, under which Metal draws a point of a function that
/// writes no size 1 pixel wide (the module writes `PointSize` 1.0). Under any other class
@@ -234,6 +237,18 @@ pub(crate) struct RenderCompiled {
samples: u32,
}
/// What the render encoder sets that a `VkPipeline` bakes: `setDepthClipMode:` and
/// `setTriangleFillMode:`, in `VkPipelineRasterizationStateCreateInfo`, which only
/// `VK_EXT_extended_dynamic_state3` makes dynamic, and the floor does not require it. The default
/// is Metal's, `Clip` and `Fill`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct Raster {
/// `MTLDepthClipModeClamp`: `depthClampEnable`.
pub(crate) clamp: bool,
/// `MTLTriangleFillModeLines`: `polygonMode` `LINE`.
pub(crate) lines: bool,
}
/// One stage's shader module and what a `VkPipeline` of it takes.
pub(crate) struct Module {
pub(crate) module: vk::ShaderModule,
@@ -1047,8 +1062,7 @@ impl RenderCompiled {
stages,
fixed,
primary: vk::Pipeline::null(),
lines: Mutex::new(vk::Pipeline::null()),
points: Mutex::new(vk::Pipeline::null()),
later: Mutex::new(Vec::new()),
rasterizes_points: pipeline.graphics.writes_point_size
|| lowered.input_primitive_topology == PrimitiveTopologyClass::Point,
notes,
@@ -1063,34 +1077,30 @@ impl RenderCompiled {
true => vk::PrimitiveTopology::PATCH_LIST,
false => vk::PrimitiveTopology::TRIANGLE_LIST,
};
compiled.primary = compiled.make(class)?;
compiled.primary = compiled.make(class, Raster::default())?;
// A descriptor that names the line or the point class (`inputPrimitiveTopology`) gives
// that class's key: its `VkPipeline` is made here too, and its draws wait for none.
let named = match lowered.input_primitive_topology {
PrimitiveTopologyClass::Line => compiled.later(vk::PrimitiveTopology::LINE_LIST),
PrimitiveTopologyClass::Point => compiled.later(vk::PrimitiveTopology::POINT_LIST),
PrimitiveTopologyClass::Line => Some(vk::PrimitiveTopology::LINE_LIST),
PrimitiveTopologyClass::Point => Some(vk::PrimitiveTopology::POINT_LIST),
_ => None,
};
if let (false, Some((later, list, _))) = (compiled.draws.patches, named) {
let made = compiled.make(list)?;
*lock(later) = made;
if let (false, Some(list)) = (compiled.draws.patches, named) {
let made = compiled.make(list, Raster::default())?;
lock(&compiled.later).push((list, Raster::default(), made));
}
Ok(compiled)
}
/// Where the content keeps the `VkPipeline` of `topology`'s class when that is the line or
/// the point class, which it makes after its triangle class's: the pipeline's place, the
/// class's list topology it is made with, and the first-use site that counts its make at a
/// draw. `None` for a triangle or patch topology.
fn later(
&self,
topology: vk::PrimitiveTopology,
) -> Option<(&Mutex<vk::Pipeline>, vk::PrimitiveTopology, FirstUse)> {
/// The list topology of `topology`'s class, which its `VkPipeline` is made with: a
/// post-tessellation vertex function's content draws the patch class alone.
fn class(&self, topology: vk::PrimitiveTopology) -> vk::PrimitiveTopology {
use vk::PrimitiveTopology as T;
match topology {
T::LINE_LIST | T::LINE_STRIP => Some((&self.lines, T::LINE_LIST, FirstUse::Lines)),
T::POINT_LIST => Some((&self.points, T::POINT_LIST, FirstUse::Points)),
_ => None,
match (self.draws.patches, topology) {
(true, _) => T::PATCH_LIST,
(false, T::LINE_LIST | T::LINE_STRIP) => T::LINE_LIST,
(false, T::POINT_LIST) => T::POINT_LIST,
(false, _) => T::TRIANGLE_LIST,
}
}
@@ -1108,26 +1118,41 @@ impl RenderCompiled {
/// The `VkPipeline` of the content for draws of `topology`'s class, a point, line or triangle
/// one, or for a post-tessellation vertex function's content the patch one, which the encoder
/// draws alone with it: the point or line class's, where the content was not made with it,
/// made by its first draw, which waits for it, a first-use wait
/// ([`Metrics::first_use_waits`](crate::Metrics::first_use_waits)).
/// draws alone with it, under `raster`, whose fill mode a line or point class does not take:
/// one the content was not made with is made by its first draw, which waits for it, a
/// first-use wait ([`Metrics::first_use_waits`](crate::Metrics::first_use_waits)), counted as
/// the line or point class's at the default raster state and as a raster state's otherwise.
///
/// Err: [`Error::Vulkan`] where the pipeline cannot be made.
pub(crate) fn pipeline(&self, topology: vk::PrimitiveTopology) -> Result<vk::Pipeline, Error> {
let later = match self.draws.patches {
true => None,
false => self.later(topology),
pub(crate) fn pipeline(
&self,
topology: vk::PrimitiveTopology,
raster: Raster,
) -> Result<vk::Pipeline, Error> {
use vk::PrimitiveTopology as T;
let class = self.class(topology);
let polygons = matches!(class, T::TRIANGLE_LIST | T::PATCH_LIST);
let raster = Raster {
clamp: raster.clamp,
lines: raster.lines && polygons,
};
let Some((later, list, site)) = later else {
if polygons && raster == Raster::default() {
return Ok(self.primary);
};
let mut made = lock(later);
if *made == vk::Pipeline::null() {
let began = host_time();
*made = self.make(list)?;
(self.core.counters).first_use_wait(site, host_time().saturating_sub(began));
}
Ok(*made)
let mut later = lock(&self.later);
if let Some(&(.., made)) = (later.iter()).find(|&&(c, r, _)| (c, r) == (class, raster)) {
return Ok(made);
}
let began = host_time();
let made = self.make(class, raster)?;
later.push((class, raster, made));
let site = match (class, raster == Raster::default()) {
(T::LINE_LIST, true) => FirstUse::Lines,
(T::POINT_LIST, true) => FirstUse::Points,
_ => FirstUse::Raster,
};
(self.core.counters).first_use_wait(site, host_time().saturating_sub(began));
Ok(made)
}
/// Whether the content's `VkPipeline`s render into `pass`'s attachments: its colour formats are
@@ -1146,11 +1171,11 @@ impl RenderCompiled {
&& fixed.samples == pass.samples
}
/// A `VkPipeline` of the content for draws of the class of `topology`, a list topology, made
/// through the device's pipeline data, rendering dynamically into the descriptor's attachment
/// formats. A draw sets its own topology within the class as dynamic state. A patch list takes
/// the translator's control points per patch.
fn make(&self, topology: vk::PrimitiveTopology) -> Result<vk::Pipeline, Error> {
/// A `VkPipeline` of the content for draws of the class of `topology`, a list topology, under
/// `raster`, made through the device's pipeline data, rendering dynamically into the
/// descriptor's attachment formats. A draw sets its own topology within the class as dynamic
/// state. A patch list takes the translator's control points per patch.
fn make(&self, topology: vk::PrimitiveTopology, raster: Raster) -> Result<vk::Pipeline, Error> {
let core = &self.core;
let fixed = &self.fixed;
let specializations: Vec<vk::SpecializationInfo<'_>> = (self.stages.iter())
@@ -1179,18 +1204,29 @@ impl RenderCompiled {
let viewport = vk::PipelineViewportStateCreateInfo::default()
.viewport_count(1)
.scissor_count(1);
// `Clamp` keeps what lies past the near and far planes and clamps its depth to the
// viewport's range, as Vulkan's depth clamp does (`depthClamp`, Floor); `Lines` draws each
// triangle's edges as lines 1 pixel wide (`fillModeNonSolid`, which the encoder asks of
// the device before it sets the mode).
let polygon_mode = match raster.lines {
true => vk::PolygonMode::LINE,
false => vk::PolygonMode::FILL,
};
let mut rasterization = vk::PipelineRasterizationStateCreateInfo::default()
.polygon_mode(vk::PolygonMode::FILL)
.depth_clamp_enable(raster.clamp)
.polygon_mode(polygon_mode)
.rasterizer_discard_enable(fixed.discard)
.line_width(1.0);
// The line class draws by Bresenham's rule, Metal's (`bresenhamLines`, Floor), except
// under alpha to coverage or alpha to one, which Vulkan's Bresenham mode does not take
// Lines, of the line class or a triangle's edges under `Lines`, draw by Bresenham's rule,
// Metal's (`bresenhamLines`, Floor), except under alpha to coverage or alpha to one, which
// Vulkan's Bresenham mode does not take
// (`VUID-VkGraphicsPipelineCreateInfo-lineRasterizationMode-02766`; the runtime enables no
// sample shading, the third it names): such a state draws its lines by the device's
// default rule (`PrecisionNote::DeviceLineRasterization`, of `lines_by_device_rule`).
let mut line = vk::PipelineRasterizationLineStateCreateInfoEXT::default()
.line_rasterization_mode(vk::LineRasterizationModeEXT::BRESENHAM);
if topology == vk::PrimitiveTopology::LINE_LIST && !lines_by_device_rule(fixed) {
let draws_lines = topology == vk::PrimitiveTopology::LINE_LIST || raster.lines;
if draws_lines && !lines_by_device_rule(fixed) {
rasterization = rasterization.push_next(&mut line);
}
// The private sample mask, which the translator states (`GraphicsState::sample_mask`)
@@ -1360,9 +1396,9 @@ impl Drop for RenderCompiled {
// No state holds it, so no command buffer that used it is left: each kept its state until
// it retired.
self.core.counters.fall(Gauge::RenderContents);
let lines = *self.lines.get_mut().unwrap_or_else(|e| e.into_inner());
let points = *self.points.get_mut().unwrap_or_else(|e| e.into_inner());
for pipeline in [self.primary, lines, points] {
let later = self.later.get_mut().unwrap_or_else(|e| e.into_inner());
let later = later.iter().map(|&(.., pipeline)| pipeline);
for pipeline in std::iter::once(self.primary).chain(later) {
if pipeline != vk::Pipeline::null() {
(self.core.reaper).give(Job::Free(Free::Pipeline(pipeline)));
}
@@ -92,7 +92,7 @@ use crate::pass::{
};
use crate::pipeline::{address_word, FieldValue, PUSH_STAGES};
use crate::record::{memory_barrier, Reach};
use crate::render::{DrawPlace, Draws, RenderPipelineState, FRAGMENT, VERTEX};
use crate::render::{DrawPlace, Draws, Raster, RenderPipelineState, FRAGMENT, VERTEX};
use crate::ring::{Placed, CHUNK};
use crate::sampler::SamplerState;
use crate::shadow::{self, Area, Held};
@@ -100,7 +100,7 @@ use crate::texture::{Texture, TextureInner, TextureObject};
use ash::vk;
use metal2vulkan::bind::alpha_test_code;
use metal2vulkan::metal::format::{integer_channels_word, BICUBIC_TEXELS_UNBOUND};
use metal2vulkan::metal::state::{input_assembly, DepthStencilDescriptor};
use metal2vulkan::metal::state::{self, input_assembly, DepthStencilDescriptor};
use metal2vulkan::metal::{
CullMode, DepthClipMode, IndexType, PixelFormat, PrimitiveType, TriangleFillMode, Winding,
};
@@ -549,15 +549,15 @@ struct Declarations {
///
/// Built: a render pipeline state, the vertex and fragment functions' buffers, bytes, textures
/// and sampler states, one viewport and scissor rectangle, the cull mode, the front-facing
/// winding, a depth-stencil state's depth and stencil tests, the depth bias without a clamp, the
/// stencil references, the blend color, the line width (lines drawn at 1 alone: a draw of lines
/// at another width is [`DrawKind::LineWidth`]), the store actions an encoder sets for an
/// attachment whose pass left them unknown, memory barriers, fences, draws of points, lines and
/// triangles, indexed or not, draws of patches with a tessellation factor buffer, each direct or
/// indirect, and the `Disabled` visibility result mode (`Boolean` and `Counting` are
/// [`DrawKind::VisibilityResults`]). Not built, and so not methods: several viewports or scissor
/// rectangles, the triangle fill mode, the depth clip mode, the store action options setters,
/// tile functions, the `setVertexBuffer:offset:attributeStride:atIndex:` family,
/// winding, the depth clip mode, the triangle fill modes `Fill` and `Lines`, a depth-stencil
/// state's depth and stencil tests, the depth bias and its clamp, the stencil references, the
/// blend color, the line width (lines drawn at 1 alone: a draw of lines at another width is
/// [`DrawKind::LineWidth`]), the store actions an encoder sets for an attachment whose pass left
/// them unknown, memory barriers, fences, draws of points, lines and triangles, indexed or not,
/// draws of patches with a tessellation factor buffer, each direct or indirect, and the `Disabled`
/// visibility result mode (`Boolean` and `Counting` are [`DrawKind::VisibilityResults`]). Not
/// built, and so not methods: several viewports or scissor rectangles, the store action options
/// setters, tile functions, the `setVertexBuffer:offset:attributeStride:atIndex:` family,
/// `setTessellationFactorScale:` (read by a pipeline that enables the scale, which is refused),
/// and indexed patch draws (`drawIndexedPatches:`, read by a pipeline of a control-point index
/// type, which is refused). A draw of what the runtime does not build is [`Gap::Draw`], naming
@@ -602,6 +602,9 @@ pub struct RenderCommandEncoder {
alpha_test: u32,
/// The line width `set_line_width` set last, Metal's 1 until set.
line_width: f32,
/// The depth clip mode and triangle fill mode set last, Metal's `Clip` and `Fill` until set,
/// which each draw's `VkPipeline` takes.
raster: Raster,
/// The depth bias's constant, slope scale and clamp, Metal's `depthBias`, `slopeScale` and
/// `clamp`.
depth_bias: [f32; 3],
@@ -695,6 +698,7 @@ impl CommandBuffer {
blend_color: [0.0; 4],
alpha_test: alpha_test_code(1.0),
line_width: 1.0,
raster: Raster::default(),
depth_bias: [0.0; 3],
biased: false,
hidden: false,
@@ -1288,17 +1292,26 @@ impl RenderCommandEncoder {
}
}
/// `setTriangleFillMode:`: `Fill`, Metal's default, is every draw's; another mode is not
/// built.
/// `setTriangleFillMode:` for the encoder's later draws: `Fill`, Metal's default, or `Lines`,
/// each triangle's edges drawn as lines 1 pixel wide by Bresenham's rule, as the encoder's
/// lines are, through a `VkPipeline` of the draw's class made for it by the content's first
/// draw under it. Draws of lines and points take no fill mode, as in Metal.
///
/// Err: [`Gap::Draw`] of [`DrawKind::FillMode`] for another mode.
/// Err: [`Gap::Draw`] of [`DrawKind::FillMode`] for `Lines` on a device without
/// `fillModeNonSolid` (`floor`'s fill modes) and for the mode of raw value 2, which no SDK
/// header declares; the encoder's mode is unchanged.
pub fn set_triangle_fill_mode(&mut self, mode: TriangleFillMode) -> Result<(), Error> {
match mode {
TriangleFillMode::Fill => Ok(()),
_ => Err(Error::Unsupported(Gap::Draw {
kind: DrawKind::FillMode,
})),
}
let profile = self.core.translator.profile();
self.raster.lines = match (mode, state::polygon_mode(mode, profile)) {
(TriangleFillMode::Fill, _) => false,
(TriangleFillMode::Lines, Ok(_)) => true,
_ => {
return Err(Error::Unsupported(Gap::Draw {
kind: DrawKind::FillMode,
}))
}
};
Ok(())
}
/// `setVisibilityResultMode:offset:`: `Disabled`, Metal's default, is every draw's, at any
@@ -1322,16 +1335,17 @@ impl RenderCommandEncoder {
}
}
/// `setDepthClipMode:`: `Clip`, Metal's default, is every draw's; `Clamp` is not built.
/// `setDepthClipMode:` for the encoder's later draws: `Clip`, Metal's default, or `Clamp`,
/// which keeps what lies past the near and far planes and clamps its depth to the viewport's
/// range, the device's own depth clamp (`depthClamp`, Floor), through a `VkPipeline` of the
/// draw's class made for it by the content's first draw under it.
///
/// Err: [`Gap::Draw`] of [`DrawKind::DepthClamp`] for `Clamp`.
/// Err: [`Error::Translation`] where the translator maps no depth clamp for the device, which
/// the floor's `depthClamp` leaves to no device.
pub fn set_depth_clip_mode(&mut self, mode: DepthClipMode) -> Result<(), Error> {
match mode {
DepthClipMode::Clip => Ok(()),
_ => Err(Error::Unsupported(Gap::Draw {
kind: DrawKind::DepthClamp,
})),
}
let profile = self.core.translator.profile();
self.raster.clamp = state::depth_clamp_enable(mode, profile).map_err(Error::translation)?;
Ok(())
}
/// `setViewports:count:`: one viewport is [`set_viewport`](Self::set_viewport)'s; several are
@@ -2125,7 +2139,7 @@ impl RenderCommandEncoder {
}
// Points Metal does not rasterize: the vertex function runs, behind an empty scissor.
let hidden = topology == vk::PrimitiveTopology::POINT_LIST && !compiled.rasterizes_points();
let pipeline = compiled.pipeline(topology)?;
let pipeline = compiled.pipeline(topology, self.raster)?;
let discards = compiled.discards();
let writes_memory = draws.writes_memory;
let building = (self.building.as_ref())
+14 -9
View File
@@ -1289,8 +1289,10 @@ pub(crate) mod on_device {
/// `Less` with writes, biased by a constant of 2^23 (which Vulkan's unit for a `float` depth of
/// exponent -2 makes 0.25, or 0.125 where the device counts 24 mantissa bits) clamped to
/// 0.0625, passes and writes 0.3125 on every device; one at 0.375 with no bias then fails; one
/// at 0.25 under `Greater`, without writes, passes only by its unclamped bias of 2^23. The
/// setters that take Metal's defaults as nothing refuse every other value.
/// at 0.25 under `Greater`, without writes, passes only by its unclamped bias of 2^23. Setting
/// the depth clip mode `Clamp` and the triangle fill mode `Lines` (refused without
/// `fillModeNonSolid`) makes no pipeline when no draw follows; the viewport and scissor setters
/// refuse a count but 1.
#[test]
fn every_device_tests_writes_and_biases_a_depth_attachment() {
let Some(library) = examples() else {
@@ -1375,18 +1377,21 @@ pub(crate) mod on_device {
draw(encoder.set_viewport(at(0.25)));
encoder.set_depth_bias(8_388_608.0, 0.0, 0.0);
draw(encoder.draw_primitives(PrimitiveType::Triangle, 6, 3, 1, 0));
draw(encoder.set_triangle_fill_mode(crate::TriangleFillMode::Fill));
// The modes a later draw's pipeline takes: setting them makes none.
let non_solid = (device.core().translator.profile().enabled().features)
.contains(&metal2vulkan::device::VkFeature::FillModeNonSolid);
same(
encoder.set_triangle_fill_mode(crate::TriangleFillMode::Lines),
gap(DrawKind::FillMode),
if non_solid {
Ok(())
} else {
gap(DrawKind::FillMode)
},
"a fill mode of lines",
);
draw(encoder.set_triangle_fill_mode(crate::TriangleFillMode::Fill));
draw(encoder.set_depth_clip_mode(crate::DepthClipMode::Clamp));
draw(encoder.set_depth_clip_mode(crate::DepthClipMode::Clip));
same(
encoder.set_depth_clip_mode(crate::DepthClipMode::Clamp),
gap(DrawKind::DepthClamp),
"the depth clip mode Clamp",
);
draw(encoder.set_viewports(&[at(0.25)]));
same(
encoder.set_viewports(&[at(0.25), at(0.5)]),
@@ -13,6 +13,7 @@ fn each_first_use_wait_adds_to_its_site_and_the_total() {
counters.first_use_wait(FirstUse::Variant, 7_000);
counters.first_use_wait(FirstUse::Lines, 11_000);
counters.first_use_wait(FirstUse::Points, 5_000);
counters.first_use_wait(FirstUse::Raster, 13_000);
let m = counters.metrics();
assert_eq!(
(
@@ -38,13 +39,21 @@ fn each_first_use_wait_adds_to_its_site_and_the_total() {
),
(1, 5_000, 5_000)
);
assert_eq!(
(
m.first_use_raster_waits,
m.first_use_raster_wait_nanos,
m.first_use_raster_wait_max_nanos
),
(1, 13_000, 13_000)
);
assert_eq!(
(
m.first_use_waits,
m.first_use_wait_nanos,
m.first_use_wait_max_nanos
),
(4, 26_000, 11_000)
(5, 39_000, 13_000)
);
}
+30 -2
View File
@@ -5,7 +5,7 @@
use crate::floor::{
choose, decide, flag_names, limits, vulkan_name, BelowFloor, Features, MemoryTypes, Missing,
Queried, ATTACHMENT_READS, ATTACHMENT_READ_EXTENSIONS, BARYCENTRICS, BARYCENTRIC_EXTENSIONS,
BORDER_SWIZZLE, BORDER_SWIZZLE_EXTENSIONS, DEVICE_EXTENSIONS, INSTANCE_EXTENSIONS,
BORDER_SWIZZLE, BORDER_SWIZZLE_EXTENSIONS, DEVICE_EXTENSIONS, FILL_MODES, INSTANCE_EXTENSIONS,
LINEAR_ATTACHMENTS, MEMORY_FLAG_NAMES, MIN_LOD_CLAMPS, OPTIONAL, OPTIONAL_EXTENSIONS,
OPTIONAL_INSTANCE_EXTENSIONS, PIXEL_INTERLOCK, PORTABILITY, PRIVATE_MEMORY, QUAD_CONTROL,
REQUIRED, RING_MEMORY, SHARED_MEMORY, STEP_RATES, TIMESTAMP_BITS, TIME_DOMAINS, VERSION,
@@ -65,6 +65,7 @@ fn at_the_floor() -> Queried {
features.core.full_draw_index_uint32 = vk::TRUE;
features.core.depth_bias_clamp = vk::TRUE;
features.core.draw_indirect_first_instance = vk::TRUE;
features.core.depth_clamp = vk::TRUE;
features.core.shader_clip_distance = vk::TRUE;
features.core.shader_tessellation_and_geometry_point_size = vk::TRUE;
features.core.large_points = vk::TRUE;
@@ -333,6 +334,7 @@ fn a_device_at_the_floor_is_above_it() {
}
for optional in (OPTIONAL.iter().chain(STEP_RATES))
.chain(MIN_LOD_CLAMPS)
.chain(FILL_MODES)
.chain(QUAD_CONTROL)
.chain(PIXEL_INTERLOCK)
.chain(BARYCENTRICS)
@@ -371,7 +373,7 @@ fn each_missing_feature_is_named() {
const CORE: &str = "VkPhysicalDeviceFeatures";
const ROBUSTNESS2: &str = "VkPhysicalDeviceRobustness2FeaturesEXT";
type Clear = fn(&mut Features);
let cases: [(Clear, Missing); 55] = [
let cases: [(Clear, Missing); 56] = [
(
|f| f.vulkan12.buffer_device_address = vk::FALSE,
feature(V12, "bufferDeviceAddress"),
@@ -575,6 +577,10 @@ fn each_missing_feature_is_named() {
|f| f.core.draw_indirect_first_instance = vk::FALSE,
feature(CORE, "drawIndirectFirstInstance"),
),
(
|f| f.core.depth_clamp = vk::FALSE,
feature(CORE, "depthClamp"),
),
(
|f| f.core.shader_clip_distance = vk::FALSE,
feature(CORE, "shaderClipDistance"),
@@ -1218,6 +1224,27 @@ fn the_min_lod_clamp_is_enabled_where_reported() {
.contains(&VkFeature::ShaderResourceMinLod));
}
/// A device that reports `fillModeNonSolid` is given it, and the translator sees it; one that does
/// not is given neither.
#[test]
fn the_fill_mode_feature_is_enabled_where_reported() {
use crate::floor::shader_enables;
use metal2vulkan::device::VkFeature;
let mut device = at_the_floor();
let unreported = decide(&device).unwrap_or_else(|below| panic!("{below}"));
assert_eq!(unreported.features.core.fill_mode_non_solid, vk::FALSE);
assert!(!shader_enables(&unreported)
.features
.contains(&VkFeature::FillModeNonSolid));
device.features.core.fill_mode_non_solid = vk::TRUE;
let capabilities = decide(&device).unwrap_or_else(|below| panic!("{below}"));
assert_eq!(capabilities.features.core.fill_mode_non_solid, vk::TRUE);
assert!(shader_enables(&capabilities)
.features
.contains(&VkFeature::FillModeNonSolid));
}
/// A device that lists `VK_KHR_shader_quad_control` and reports `shaderQuadControl` is given both,
/// and the translator sees both; one that lists the extension without the feature is given the
/// extension alone.
@@ -1617,6 +1644,7 @@ fn the_readme_states_the_floor() {
),
(["Step-rate feature", "Structure", "Used for"], STEP_RATES),
(["Min-LOD feature", "Structure", "Used for"], MIN_LOD_CLAMPS),
(["Fill-mode feature", "Structure", "Used for"], FILL_MODES),
(
["Quad-control feature", "Structure", "Used for"],
QUAD_CONTROL,
@@ -71,6 +71,7 @@ mod present;
mod private_arena;
mod push_window;
mod quad_control;
mod raster;
mod read_write_tier;
mod readback;
mod render;
@@ -0,0 +1,148 @@
//! The render encoder's depth clip mode and triangle fill mode (`render::Raster`), each a
//! `VkPipeline` of the draw's class that the content's first draw under it makes, under a device
//! cfg on every device of the cfg's kind. `cfb_depth_vertex` (engine `cfb_sample_depth`) returns
//! the `float4` of its buffer 0 for each vertex, and `cfb_depth_white` colours white.
//!
//! - A triangle over the whole target in front of the near plane (z -0.5) draws nothing under
//! `Clip` and every texel under `Clamp`, which keeps it at the near plane (the conformance case
//! `render-state-depth-clip`).
//! - Under `Lines`, where the device has `fillModeNonSolid`, the triangle at z 0.5 through a
//! viewport half a pixel right of and above the target's corner draws the two edges that lie
//! inside the target through texel centers, column 0 and row 7, and nothing inside them; without
//! the feature the mode is `DrawKind::FillMode` and the encoder's mode stays `Fill`.
//! - The first draw under each raster state makes one pipeline, a first-use wait of the raster
//! site; a later encoder's draw under the same state makes none.
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod on_device {
use crate::tests::blit::on_device::settled;
use crate::tests::command::on_device::each_device;
use crate::tests::draw::on_device::{
floats, library, pass, read, run, state, target, texels, Buffers, BLACK, SIDE,
};
use crate::{
Buffer, ColorAttachmentDescriptor, DepthClipMode, DrawKind, Error, FunctionDescriptor, Gap,
PixelFormat, PrimitiveType, RenderPipelineDescriptor, StageSource, TextureUsage,
TriangleFillMode, Viewport,
};
use metal2vulkan::device::VkFeature;
use metal2vulkan_devtools::engine_dir;
const WHITE: [f32; 4] = [1.0; 4];
/// The triangle `(-1, -1)`, `(3, -1)`, `(-1, 3)` of clip space, which covers the clip square,
/// at depth `z`: `cfb_depth_vertex`'s positions.
fn triangle(z: f32) -> Vec<u8> {
floats(&[-1.0, -1.0, z, 1.0, 3.0, -1.0, z, 1.0, -1.0, 3.0, z, 1.0])
}
#[test]
fn every_device_draws_clamped_and_edge_triangles_through_pipelines_made_at_first_use() {
let Some(library) = library(&engine_dir().join("cfb_sample_depth.ll")) else {
return;
};
let function = |name| {
StageSource::Function(FunctionDescriptor::new(
library.function(name).expect("the function"),
))
};
let mut d = RenderPipelineDescriptor::new(function("cfb_depth_vertex"));
d.fragment = Some(function("cfb_depth_white"));
d.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
each_device("raster", |name, _, device| {
let state = state(name, &device, &d);
let mut buffers = Buffers::new(&device);
let near = buffers.of(&device, &triangle(-0.5));
let inside = buffers.of(&device, &triangle(0.5));
let non_solid = (device.core().translator.profile().enabled().features)
.contains(&VkFeature::FillModeNonSolid);
let queue = device.new_command_queue(4).expect("a queue");
let draw = |result: Result<(), Error>| result.unwrap_or_else(|e| panic!("{name}: {e}"));
// Each pass in an encoder of its own, so each sets its modes from Metal's defaults.
let passes: [(DepthClipMode, TriangleFillMode, &Buffer); 4] = [
(DepthClipMode::Clip, TriangleFillMode::Fill, &near),
(DepthClipMode::Clamp, TriangleFillMode::Fill, &near),
(DepthClipMode::Clamp, TriangleFillMode::Fill, &near),
(DepthClipMode::Clip, TriangleFillMode::Lines, &inside),
];
let colors: Vec<_> = (passes.iter())
.map(|_| {
target(
&device,
PixelFormat::RGBA8Unorm,
TextureUsage::RENDER_TARGET,
)
})
.collect();
// The upload that moves the new targets to their home layout, in a submission apart.
let first = queue.command_buffer().expect("a command buffer");
(first.record_for_test(&[], |_, _| {})).expect("a command buffer's commands");
run(name, &first);
let counters = device.counters();
settled(&device);
let before = counters.metrics();
let command_buffer = queue.command_buffer().expect("a command buffer");
for ((clip, fill, positions), color) in passes.iter().zip(&colors) {
let mut encoder = (command_buffer.render_command_encoder(&pass(color, None)))
.unwrap_or_else(|error| panic!("{name}: {error}"));
draw(encoder.set_render_pipeline_state(&state));
draw(encoder.set_vertex_buffer(Some(*positions), 0, 0));
draw(encoder.set_depth_clip_mode(*clip));
let lines = *fill == TriangleFillMode::Lines;
match (encoder.set_triangle_fill_mode(*fill), lines && !non_solid) {
(Ok(()), false) => {}
(Err(Error::Unsupported(Gap::Draw { kind })), true) => {
assert_eq!(kind, DrawKind::FillMode, "{name}");
}
(other, _) => panic!("{name}: {fill:?}: {other:?}"),
}
if lines && non_solid {
// Clip space's left and bottom edges through texel centers.
draw(encoder.set_viewport(Viewport {
origin_x: 0.5,
origin_y: -0.5,
width: f64::from(SIDE),
height: f64::from(SIDE),
znear: 0.0,
zfar: 1.0,
}));
}
draw(encoder.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0));
encoder.end_encoding();
}
run(name, &command_buffer);
let after = counters.metrics();
let made = 1 + u64::from(non_solid);
assert_eq!(
(
after.pipelines_created - before.pipelines_created,
after.first_use_raster_waits - before.first_use_raster_waits,
after.first_use_waits - before.first_use_waits,
),
(made, made, made),
"{name}: pipelines made, raster first-use waits, first-use waits"
);
let all = |c| texels(|_, _| c);
assert_eq!(read(&colors[0], 4), all(BLACK), "{name}: clipped");
assert_eq!(read(&colors[1], 4), all(WHITE), "{name}: clamped");
assert_eq!(read(&colors[2], 4), all(WHITE), "{name}: clamped again");
let edges = match non_solid {
true => texels(|x, y| match x == 0 || y == SIDE - 1 {
true => WHITE,
false => BLACK,
}),
// The mode refused, the triangle fills the target through the whole viewport.
false => all(WHITE),
};
assert_eq!(read(&colors[3], 4), edges, "{name}: the edges");
println!(
"{name}: a near triangle clipped, then clamped through 1 pipeline made at first \
use; fillModeNonSolid {non_solid}: {} under Lines",
match non_solid {
true => "its two edges inside the target drawn, 1 pipeline more",
false => "refused (FillMode), filled",
}
);
});
}
}
@@ -1141,6 +1141,7 @@
"fullDrawIndexUint32": true,
"depthBiasClamp": true,
"drawIndirectFirstInstance": true,
"depthClamp": true,
"shaderClipDistance": true,
"tessellationShader": true,
"shaderTessellationAndGeometryPointSize": true,
+7 -1
View File
@@ -640,7 +640,8 @@ mod tests {
/// The encoder's fill mode, depth clip mode, and depth bias clamp map where the device has
/// their features and are refused, naming the feature, where it does not. The floor states
/// `depthBiasClamp`, so its refusal is on `runtime-floor` without it (below the floor).
/// `depthBiasClamp` and `depthClamp`, so their refusals are on `runtime-floor` without them
/// (below the floor).
#[test]
fn encoder_raster_state_needs_its_features() {
let (floor, lavapipe) = (committed("runtime-floor"), committed("lavapipe"));
@@ -689,6 +690,11 @@ mod tests {
);
assert_eq!(
depth_clamp_enable(DepthClipMode::Clamp, floor.profile()),
Ok(true)
);
let unclamped = committed_without("runtime-floor", &[VkFeature::DepthClamp]);
assert_eq!(
depth_clamp_enable(DepthClipMode::Clamp, unclamped.profile()),
Err(needs(Feature::DepthClipClamp, VkFeature::DepthClamp))
);
assert_eq!(
+3 -1
View File
@@ -1574,6 +1574,9 @@ field metal2vulkan-runtime::Metrics.first_use_line_waits pub first_use_line_wait
field metal2vulkan-runtime::Metrics.first_use_point_wait_max_nanos pub first_use_point_wait_max_nanos: u64
field metal2vulkan-runtime::Metrics.first_use_point_wait_nanos pub first_use_point_wait_nanos: u64
field metal2vulkan-runtime::Metrics.first_use_point_waits pub first_use_point_waits: u64
field metal2vulkan-runtime::Metrics.first_use_raster_wait_max_nanos pub first_use_raster_wait_max_nanos: u64
field metal2vulkan-runtime::Metrics.first_use_raster_wait_nanos pub first_use_raster_wait_nanos: u64
field metal2vulkan-runtime::Metrics.first_use_raster_waits pub first_use_raster_waits: u64
field metal2vulkan-runtime::Metrics.first_use_variant_wait_max_nanos pub first_use_variant_wait_max_nanos: u64
field metal2vulkan-runtime::Metrics.first_use_variant_wait_nanos pub first_use_variant_wait_nanos: u64
field metal2vulkan-runtime::Metrics.first_use_variant_waits pub first_use_variant_waits: u64
@@ -9142,7 +9145,6 @@ variant metal2vulkan-runtime::DispatchType::Concurrent Concurrent
variant metal2vulkan-runtime::DispatchType::Serial Serial
variant metal2vulkan-runtime::DrawKind::AttachmentFormats AttachmentFormats
variant metal2vulkan-runtime::DrawKind::AttachmentRead AttachmentRead
variant metal2vulkan-runtime::DrawKind::DepthClamp DepthClamp
variant metal2vulkan-runtime::DrawKind::DividedBaseInstance DividedBaseInstance
variant metal2vulkan-runtime::DrawKind::FetchedAttachment FetchedAttachment
variant metal2vulkan-runtime::DrawKind::FillMode FillMode
Can't render this file because it is too large.
+1 -3
View File
@@ -42,7 +42,7 @@ Its limits, measured rather than asserted:
| committed recordings | 1319 |
| distinct SDK items the Metal leg reaches, of any status | 804 |
| of those, reached only where this cannot name the family | 5 |
| ledger rows (a case whose gap is recorded) | 7689 |
| ledger rows (a case whose gap is recorded) | 7687 |
| declared crossings of the option space (pairs put to Metal at once) | 26 |
| declared crossings that are no pair of it (a boolean or numeric field, or one type in two slots) | 30 |
@@ -8077,8 +8077,6 @@ A case whose difference from Metal is recorded rather than compared away. The le
| `read-write-tier-round-trip-float` | The device's own answer (rule 2): this device's format queries offer no storage image of MTLPixelFormatRGBA8Unorm_sRGB, so rt binds no such texture to a read_wr… |
| `read-write-tier-round-trip-float` | The device's own answer (rule 2): this device's format queries offer no storage image of MTLPixelFormatRGBA8Unorm_sRGB, so rt binds no such texture to a read_wr… |
| `read-write-tier-round-trip-float` | The device's own answer (rule 2): this device's format queries offer no storage image of MTLPixelFormatRGBA8Unorm_sRGB, so rt binds no such texture to a read_wr… |
| `render-state-depth-clip` | refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, every depth clip mode Clip). rt refuses it (a dr… |
| `render-state-facing` | refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, every setTriangleFillMode: Fill). rt refuses it … |
| `render-state-heap-residency` | refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, no sparse texture, heap or tile call). The rt si… |
| `render-state-render-barriers` | refused: no stream uses it yet (full selector census 11-19, m3-max-53207-53208, 53213, 53217-53221: 26 streams, no useResource:usage:stages: or useHeap:stages:)… |
| `render-state-texture-accesses` | refused: the consumer's own (MTLComputePipelineReflection, MTLRenderPipelineReflection, MTLPipelineOptionFailOnBinaryArchiveMiss, MTLPipelineOptionArgumentInfo,… |
+2 -2
View File
@@ -388,7 +388,7 @@ Columns:
| `BicubicTexels` | A dispatch or a draw whose function samples texture slot `slot` through a constexpr sampler with Metal's bicubic filter (`filter::bicubic`), where... | every device (a public call's own check of its arguments) | `ours`: each refused format's treatment is built when a guest binds one | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` | `-` |
| `TextureView` | `Texture::new_texture_view` of a kind Metal makes and the runtime does not build | every device (a public call's own check of its arguments) | `ours`: the replay streams' views that compute binds are same-format views of every slice, 2D views of one slice of a 2D array, and level subranges, swizzled or not; each other kind is built when a replay stream binds one | 1: `crates/metal2vulkan-runtime/src/texture.rs (view)` | `-` |
| `RenderPass` | A render pass of something the runtime does not build yet (`CommandBuffer::render_command_encoder`) | every device (a public call's own check of its arguments) | `ours`: the replay streams' passes render into one to two color attachments and a stencil or a depth attachment, each a level of a 2D texture of one sample, with no resolve and a clear depth of 1, none naming two textures for its depth and stencil; each other kind is built when a replay stream makes one; `DepthStencilViews` and `ClearDepth` are what Vulkan's rendering under the floor takes no form of | 6: `crates/metal2vulkan-runtime/src/pass.rs (check)`, `crates/metal2vulkan-runtime/src/pass.rs (ops)` (+4) | `-` |
| `Draw` | A draw or render encoder state the runtime does not build yet (`RenderCommandEncoder`) | every device (a public call's own check of its arguments) | `ours`: the replay streams draw lines and triangles through one viewport Vulkan's is, with pipeline states of their pass's formats, filled and clipped; each other kind is built when a replay stream draws one), and device for [`DrawKind::DividedBaseInstance`] (a device that does not report `supportsNonZeroFirstInstance` | 13: `crates/metal2vulkan-runtime/src/render_encoder.rs (attachment_reads, 3 sites)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` (+9) | `-` |
| `Draw` | A draw or render encoder state the runtime does not build yet (`RenderCommandEncoder`) | every device (a public call's own check of its arguments) | `ours`: the replay streams draw lines and triangles through one viewport Vulkan's is, with pipeline states of their pass's formats, filled and clipped; each other kind is built when a replay stream draws one), and device for [`DrawKind::DividedBaseInstance`] (a device that does not report `supportsNonZeroFirstInstance` | 12: `crates/metal2vulkan-runtime/src/render_encoder.rs (attachment_reads, 3 sites)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)` (+8) | `-` |
| `LinearPlanePass` | A render pass over a surface plane that renders as a linear colour attachment alone, in a shape the device does not render... | at the device's limit | `device`: VK_NV_linear_color_attachment renders such a format as a colour attachment only "as long as all the color attachments in the render pass instance have VK_IMAGE_TILING_LINEAR tiling"; the RTX 3090's driver lost the device rendering a linear colour attachment beside a depth or stencil attachment | 1: `crates/metal2vulkan-runtime/src/pass.rs (check)` | `-` |
## Appendix: every site
@@ -674,6 +674,6 @@ Each refusal's sites, with the function that builds it.
- `rt:Gap::BicubicTexels`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)`
- `rt:Gap::TextureView`: `crates/metal2vulkan-runtime/src/texture.rs (view)`
- `rt:Gap::RenderPass`: `crates/metal2vulkan-runtime/src/pass.rs (check)`; `crates/metal2vulkan-runtime/src/pass.rs (ops)`; `crates/metal2vulkan-runtime/src/pass.rs (resolve)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (later_store)`; `crates/metal2vulkan-runtime/src/texture.rs (attachment_view)`; `crates/metal2vulkan-runtime/src/texture.rs (resolve_attachment)`
- `rt:Gap::Draw`: `crates/metal2vulkan-runtime/src/render_encoder.rs (attachment_reads, 3 sites)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw_patches)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw_patches_indirect)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_depth_clip_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_scissor_rects)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_triangle_fill_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_viewport)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_viewports)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_visibility_result_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (shadow_copies)`
- `rt:Gap::Draw`: `crates/metal2vulkan-runtime/src/render_encoder.rs (attachment_reads, 3 sites)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw_patches)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (draw_patches_indirect)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_scissor_rects)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_triangle_fill_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_viewport)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_viewports)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_visibility_result_mode)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (shadow_copies)`
- `rt:Gap::LinearPlanePass`: `crates/metal2vulkan-runtime/src/pass.rs (check)`
@@ -115,7 +115,7 @@ RUNTIME_FLOOR = {
"shaderStorageImageExtendedFormats", "samplerAnisotropy",
"shaderImageGatherExtended", "shaderInt16", "independentBlend",
"fragmentStoresAndAtomics", "alphaToOne", "logicOp", "fullDrawIndexUint32",
"depthBiasClamp", "drawIndirectFirstInstance", "shaderClipDistance",
"depthBiasClamp", "drawIndirectFirstInstance", "depthClamp", "shaderClipDistance",
"tessellationShader", "shaderTessellationAndGeometryPointSize", "largePoints",
"dualSrcBlend", "sampleRateShading", "vertexPipelineStoresAndAtomics")},
"VkPhysicalDeviceVulkan11Features": {member: True for member in (