The four parts

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:

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.

Where each PipeKey field goes

PipeKey fieldPartHow
vs, tcs, tes, gsPRthe modules, in the PR key
patchPRdynamic (VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT) with extendedDynamicState2PatchControlPoints, else in the PR key
topo_classVIin the VI key. The topology is dynamic already (VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY)
polygonPRdynamic with extendedDynamicState3PolygonMode, else in the PR key
depth_clampPRdynamic with extendedDynamicState3DepthClampEnable, else in the PR key
depth_clipPR0 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
viVIin the VI key. All zero with dynamic vertex input, as now
ncolor, color[8], depth, stencilFOin the FO key (formats cannot be dynamic)
blend[8]FOin the FO key
feedbackFS and FOdynamic with has_feedback_dynamic (the case here). Without it, the flag goes on both parts and on the link (see the open questions)
provoking_lastPRdynamic with extendedDynamicState3ProvokingVertexMode, else in the PR key
logic_opFOin the FO key
arraysPR and FSeach part keeps the bits of its own sets (see Layouts)
samplesFOin the FO key. Also in the FS key when sample_shading is set
coverageFOin the FO key (rare state, mixed samples)
sample_off, alpha_to_coverage, alpha_to_oneFOin the FO key. Also in the FS key when sample_shading is set
sample_shadingFS and FOin both keys
conservativePRdynamic with extendedDynamicState3ConservativeRasterizationMode and ExtraPrimitiveOverestimationSize, else in the PR key
fsFSthe module (or null_fs()), in the FS key
fs_specFSthe 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.

State that becomes dynamic

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.

StateCallFeature
polygon modevkCmdSetPolygonModeEXTextendedDynamicState3PolygonMode
depth clampvkCmdSetDepthClampEnableEXTextendedDynamicState3DepthClampEnable
provoking vertexvkCmdSetProvokingVertexModeEXTextendedDynamicState3ProvokingVertexMode
conservative mode and its sizevkCmdSetConservativeRasterizationModeEXT, vkCmdSetExtraPrimitiveOverestimationSizeEXTthe two extendedDynamicState3 members, with has_conservative
patch control pointsvkCmdSetPatchControlPointsEXTextendedDynamicState2PatchControlPoints
depth range of the clip volumevkCmdSetDepthClipNegativeOneToOneEXTextendedDynamicState3DepthClipNegativeOneToOne, with depthClipControl of VK_EXT_depth_clip_control
depth clipvkCmdSetDepthClipEnableEXTextendedDynamicState3DepthClipEnable, with VK_EXT_depth_clip_enable, only where the depth clamp is dynamic too
depth clamp rangevkCmdSetDepthClampRangeEXTdepthClampControl 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 multisample state of the fragment shader part

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:


Made from docs/layers/gpu/pipeline-libraries.md at 69237645142c. GPL-3.0-or-later.