GPL splits a graphics pipeline into four parts. Each part is a pipeline made with VK_PIPELINE_CREATE_LIBRARY_BIT_KHR
and a VkGraphicsPipelineLibraryCreateInfoEXT that names it:
pVertexInputState, pInputAssemblyState. Cheap.pViewportState, pRasterizationState, pTessellationState, the layout, and viewMask of
VkPipelineRenderingCreateInfo. This is the expensive part for the Ounce game.pDepthStencilState, a pMultisampleState when sample shading is
on, the layout and viewMask.pColorBlendState, pMultisampleState, the attachment formats of
VkPipelineRenderingCreateInfo and VkAttachmentSampleCountInfoNV. Cheap.Only PR and FS compile shaders. VI and FO hold fixed-function state, and the driver makes them in microseconds. So the plan keeps most fixed-function state static in VI and FO, where a new value costs almost nothing. It makes state dynamic only where it would otherwise go into PR or FS. The optimized pipeline then keeps static blend state, which is the best case for the GPU.
PipeKey field | Part | How |
|---|---|---|
vs, tcs, tes, gs | PR | the modules, in the PR key |
patch | PR | dynamic (VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT) with extendedDynamicState2PatchControlPoints, else in the PR key |
topo_class | VI | in the VI key. The topology is dynamic already (VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY) |
polygon | PR | dynamic with extendedDynamicState3PolygonMode, else in the PR key |
depth_clamp | PR | dynamic with extendedDynamicState3DepthClampEnable, else in the PR key |
depth_clip | PR | 0 without VK_EXT_depth_clip_enable. With it, 1 off and 2 on: dynamic with extendedDynamicState3DepthClipEnable where the clamp is dynamic too, else in the PR key |
vi | VI | in the VI key. All zero with dynamic vertex input, as now |
ncolor, color[8], depth, stencil | FO | in the FO key (formats cannot be dynamic) |
blend[8] | FO | in the FO key |
feedback | FS and FO | dynamic with has_feedback_dynamic (the case here). Without it, the flag goes on both parts and on the link (see the open questions) |
provoking_last | PR | dynamic with extendedDynamicState3ProvokingVertexMode, else in the PR key |
logic_op | FO | in the FO key |
arrays | PR and FS | each part keeps the bits of its own sets (see Layouts) |
samples | FO | in the FO key. Also in the FS key when sample_shading is set |
coverage | FO | in the FO key (rare state, mixed samples) |
sample_off, alpha_to_coverage, alpha_to_one | FO | in the FO key. Also in the FS key when sample_shading is set |
sample_shading | FS and FO | in both keys |
conservative | PR | dynamic with extendedDynamicState3ConservativeRasterizationMode and ExtraPrimitiveOverestimationSize, else in the PR key |
fs | FS | the module (or null_fs()), in the FS key |
fs_spec | FS | the module's specialization constants (the alpha test's function, the window's origin, the point sprite's flip), in the FS key |
Some state goes into every part and into the link, and it is the same for all pipelines of a run. These are the
VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT flag with has_descriptor_buffers
(VUID-VkGraphicsPipelineCreateInfo-flags-12355 and 12356), the VkPipelineRobustnessCreateInfoEXT with
has_vertex_robustness2, and viewMask 0. They are not in the keys.
The draws set these in render.c beside the dynamic state that they set now (the DYN macro and g_dyn, so a value
goes into the command buffer only when it changes). Each one needs a rec_CmdSet... wrapper in record.c, and the
DYN cache must start again for each command buffer, as it does now.
| State | Call | Feature |
|---|---|---|
| polygon mode | vkCmdSetPolygonModeEXT | extendedDynamicState3PolygonMode |
| depth clamp | vkCmdSetDepthClampEnableEXT | extendedDynamicState3DepthClampEnable |
| provoking vertex | vkCmdSetProvokingVertexModeEXT | extendedDynamicState3ProvokingVertexMode |
| conservative mode and its size | vkCmdSetConservativeRasterizationModeEXT, vkCmdSetExtraPrimitiveOverestimationSizeEXT | the two extendedDynamicState3 members, with has_conservative |
| patch control points | vkCmdSetPatchControlPointsEXT | extendedDynamicState2PatchControlPoints |
| depth range of the clip volume | vkCmdSetDepthClipNegativeOneToOneEXT | extendedDynamicState3DepthClipNegativeOneToOne, with depthClipControl of VK_EXT_depth_clip_control |
| depth clip | vkCmdSetDepthClipEnableEXT | extendedDynamicState3DepthClipEnable, with VK_EXT_depth_clip_enable, only where the depth clamp is dynamic too |
| depth clamp range | vkCmdSetDepthClampRangeEXT | depthClampControl of VK_EXT_depth_clamp_control, on the whole-pipeline path too |
Each state becomes dynamic only on the GPL path, and only when its feature is there. A state without its feature
stays in the PR key, as a static value. This keeps the whole-pipeline path of today unchanged, and a device with
partial EDS3 still works. g_vk gets one bit for each state (g_vk.dyn_pr, a mask), which the key split and the
draw both read. The device must enable VK_EXT_extended_dynamic_state3 and the members that it uses, and
extendedDynamicState2PatchControlPoints.
A member that a line of extension_bans.txt turns off on the driver counts as absent (vk_gpl_bans).
The depth range is in no key. Without its state, the last stage before rasterization makes a range of -1 to 1
(shader_vertex_position_fix, z = (z + w) / 2), as on the whole-pipeline path. With it, the device makes the
range and the push constant that turns the fix on stays 0. The log line at start says which, and what the device
lacks.
Without VK_EXT_depth_clip_enable, depth clip is the opposite of depth clamp, for a static value and for a dynamic
one. With it, the clip is a state of its own (depth_clip), as the console's clip control sets the clip and the
clamp apart; a dynamic clamp without a dynamic clip would turn the clip the other way whatever the pipeline says
(vkCmdSetDepthClampEnableEXT), so the extension is used with a dynamic clamp only where the clip is dynamic too.
The clamp's range (VK_EXT_depth_clamp_control) is the viewport's clip range, or 0 to 1 where the clip control forces
it (bit 0, the console's clamp off), set with the viewport on both paths and in no key. A driver that lists the
extension and its feature but gives no vkCmdSetDepthClampRangeEXT (NVIDIA's 621.01) runs without the extension: the
device is made again without it (Driver bans).
Each part lists only the dynamic states of its own subset in its pDynamicState, as vkd3d-proton does with its
VKD3D_VERTEX_INPUT_DYNAMIC_STATE_MASK and VKD3D_FRAGMENT_OUTPUT_DYNAMIC_STATE_MASK. The link and the optimized
pipeline get the union from their parts. One function (pipe_dynamic(part, out)) builds each list from the list of
pipe_create now, so the whole pipeline and the parts cannot disagree.
The FS part can take pMultisampleState as NULL, and the FO part must have one. When the FS part has one, the two
must be "identically defined" (VUID-VkGraphicsPipelineCreateInfo-pLibraries-06635). When sample shading is on, the
FS part must have one, and it must also match (06636, 06637). So:
sample_shading 0 (nearly all draws), the FS part has no multisample state. Its key does not hold samples,
and one FS part links with every sample count.sample_shading 1, the FS key holds the whole multisample key (samples, coverage, sample_off,
alpha_to_coverage, alpha_to_one). One function builds the VkPipelineMultisampleStateCreateInfo for both
parts from the same fields, so the two are the same by construction.Made from docs/layers/gpu/pipeline-libraries.md at 69237645142c. GPL-3.0-or-later.