25. Rasterization
Rasterization is the process by which a primitive is converted to a twodimensional image. Each discrete location of this image contains associated data such as depth, color, or other attributes.
Rasterizing a primitive begins by determining which squares of an integer grid in framebuffer coordinates are occupied by the primitive, and assigning one or more depth values to each such square. This process is described below for points, lines, and polygons.
A grid square, including its (x,y) framebuffer coordinates, z (depth), and associated data added by fragment shaders, is called a fragment. A fragment is located by its upper left corner, which lies on integer grid coordinates.
Rasterization operations also refer to a fragment’s sample locations, which are offset by fractional values from its upper left corner. The rasterization rules for points, lines, and triangles involve testing whether each sample location is inside the primitive. Fragments need not actually be square, and rasterization rules are not affected by the aspect ratio of fragments. Display of nonsquare grids, however, will cause rasterized points and line segments to appear fatter in one direction than the other.
We assume that fragments are square, since it simplifies antialiasing and texturing. After rasterization, fragments are processed by fragment operations.
Several factors affect rasterization, including the members of VkPipelineRasterizationStateCreateInfo and VkPipelineMultisampleStateCreateInfo.
The VkPipelineRasterizationStateCreateInfo
structure is defined as:
// Provided by VK_VERSION_1_0
typedef struct VkPipelineRasterizationStateCreateInfo {
VkStructureType sType;
const void* pNext;
VkPipelineRasterizationStateCreateFlags flags;
VkBool32 depthClampEnable;
VkBool32 rasterizerDiscardEnable;
VkPolygonMode polygonMode;
VkCullModeFlags cullMode;
VkFrontFace frontFace;
VkBool32 depthBiasEnable;
float depthBiasConstantFactor;
float depthBiasClamp;
float depthBiasSlopeFactor;
float lineWidth;
} VkPipelineRasterizationStateCreateInfo;

sType
is a VkStructureType value identifying this structure. 
pNext
isNULL
or a pointer to a structure extending this structure. 
flags
is reserved for future use. 
depthClampEnable
controls whether to clamp the fragment’s depth values as described in Depth Test. Enabling depth clamp will also disable clipping primitives to the z planes of the frustrum as described in Primitive Clipping. 
rasterizerDiscardEnable
controls whether primitives are discarded immediately before the rasterization stage. 
polygonMode
is the triangle rendering mode. See VkPolygonMode. 
cullMode
is the triangle facing direction used for primitive culling. See VkCullModeFlagBits. 
frontFace
is a VkFrontFace value specifying the frontfacing triangle orientation to be used for culling. 
depthBiasEnable
controls whether to bias fragment depth values. 
depthBiasConstantFactor
is a scalar factor controlling the constant depth value added to each fragment. 
depthBiasClamp
is the maximum (or minimum) depth bias of a fragment. 
depthBiasSlopeFactor
is a scalar factor applied to a fragment’s slope in depth bias calculations. 
lineWidth
is the width of rasterized line segments.
// Provided by VK_VERSION_1_0
typedef VkFlags VkPipelineRasterizationStateCreateFlags;
VkPipelineRasterizationStateCreateFlags
is a bitmask type for setting
a mask, but is currently reserved for future use.
The VkPipelineMultisampleStateCreateInfo
structure is defined as:
// Provided by VK_VERSION_1_0
typedef struct VkPipelineMultisampleStateCreateInfo {
VkStructureType sType;
const void* pNext;
VkPipelineMultisampleStateCreateFlags flags;
VkSampleCountFlagBits rasterizationSamples;
VkBool32 sampleShadingEnable;
float minSampleShading;
const VkSampleMask* pSampleMask;
VkBool32 alphaToCoverageEnable;
VkBool32 alphaToOneEnable;
} VkPipelineMultisampleStateCreateInfo;

sType
is a VkStructureType value identifying this structure. 
pNext
isNULL
or a pointer to a structure extending this structure. 
flags
is reserved for future use. 
rasterizationSamples
is a VkSampleCountFlagBits value specifying the number of samples used in rasterization. This value is ignored for the purposes of setting the number of samples used in rasterization if the pipeline is created with theVK_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT
dynamic state set, but ifVK_DYNAMIC_STATE_SAMPLE_MASK_EXT
dynamic state is not set, it is still used to define the size of thepSampleMask
array as described below. 
sampleShadingEnable
can be used to enable Sample Shading. 
minSampleShading
specifies a minimum fraction of sample shading ifsampleShadingEnable
is set toVK_TRUE
. 
pSampleMask
is a pointer to an array of VkSampleMask values used in the sample mask test. 
alphaToCoverageEnable
controls whether a temporary coverage value is generated based on the alpha component of the fragment’s first color output as specified in the Multisample Coverage section. 
alphaToOneEnable
controls whether the alpha component of the fragment’s first color output is replaced with one as described in Multisample Coverage.
Each bit in the sample mask is associated with a unique
sample index as defined for the
coverage mask.
Each bit b for mask word w in the sample mask corresponds to
sample index i, where i = 32 × w + b.
pSampleMask
has a length equal to ⌈
rasterizationSamples
/ 32 ⌉ words.
If pSampleMask
is NULL
, it is treated as if the mask has all bits
set to 1
.
// Provided by VK_VERSION_1_0
typedef VkFlags VkPipelineMultisampleStateCreateFlags;
VkPipelineMultisampleStateCreateFlags
is a bitmask type for setting a
mask, but is currently reserved for future use.
The elements of the sample mask array are of type VkSampleMask, each representing 32 bits of coverage information:
// Provided by VK_VERSION_1_0
typedef uint32_t VkSampleMask;
Rasterization only generates fragments which cover one or more pixels inside the framebuffer. Pixels outside the framebuffer are never considered covered in the fragment. Fragments which would be produced by application of any of the primitive rasterization rules described below but which lie outside the framebuffer are not produced, nor are they processed by any later stage of the pipeline, including any of the fragment operations.
Surviving fragments are processed by fragment shaders. Fragment shaders determine associated data for fragments, and can also modify or replace their assigned depth values.
25.1. Discarding Primitives Before Rasterization
Primitives are discarded before rasterization if the
rasterizerDiscardEnable
member of
VkPipelineRasterizationStateCreateInfo is enabled.
When enabled, primitives are discarded after they are processed by the last
active shader stage in the pipeline before rasterization.
To dynamically enable whether primitives are discarded before the rasterization stage, call:
// Provided by VK_VERSION_1_3
void vkCmdSetRasterizerDiscardEnable(
VkCommandBuffer commandBuffer,
VkBool32 rasterizerDiscardEnable);
or the equivalent command
// Provided by VK_EXT_shader_object
void vkCmdSetRasterizerDiscardEnableEXT(
VkCommandBuffer commandBuffer,
VkBool32 rasterizerDiscardEnable);

commandBuffer
is the command buffer into which the command will be recorded. 
rasterizerDiscardEnable
controls whether primitives are discarded immediately before the rasterization stage.
This command sets the discard enable for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with
VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE
set in
VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable
value used to create the currently active pipeline.
25.2. Rasterization Order
Within a subpass of a render pass instance, for a given (x,y,layer,sample) sample location, the following operations are guaranteed to execute in rasterization order, for each separate primitive that includes that sample location:

Fragment operations, in the order defined

Blending, logic operations, and color writes
Execution of these operations for each primitive in a subpass occurs in primitive order.
25.3. Multisampling
Multisampling is a mechanism to antialias all Vulkan primitives: points, lines, and polygons. The technique is to sample all primitives multiple times at each pixel. Each sample in each framebuffer attachment has storage for a color, depth, and/or stencil value, such that perfragment operations apply to each sample independently. The color sample values can be later resolved to a single color (see Resolving Multisample Images and the Render Pass chapter for more details on how to resolve multisample images to nonmultisample images).
Vulkan defines rasterization rules for singlesample modes in a way that is equivalent to a multisample mode with a single sample in the center of each fragment.
Each fragment includes a coverage mask with a single bit for each sample in the fragment, and a number of depth values and associated data for each sample.
It is understood that each pixel has rasterizationSamples
locations
associated with it.
These locations are exact positions, rather than regions or areas, and each
is referred to as a sample point.
The sample points associated with a pixel must be located inside or on the
boundary of the unit square that is considered to bound the pixel.
Furthermore, the relative locations of sample points may be identical for
each pixel in the framebuffer, or they may differ.
If the current pipeline includes a fragment shader with one or more
variables in its interface decorated with Sample
and Input
, the
data associated with those variables will be assigned independently for each
sample.
The values for each sample must be evaluated at the location of the sample.
The data associated with any other variables not decorated with Sample
and Input
need not be evaluated independently for each sample.
A coverage mask is generated for each fragment, based on which samples within that fragment are determined to be within the area of the primitive that generated the fragment.
Single pixel fragments
have one set of samples.
Multipixel fragments defined by setting the
fragment shading rate have one set of
samples per pixel.
Each set of samples has a number of samples determined by
VkPipelineMultisampleStateCreateInfo::rasterizationSamples
.
Each sample in a set is assigned a unique sample index i in the
range [0, rasterizationSamples
).
To dynamically set the
rasterizationSamples
, call:
// Provided by VK_EXT_extended_dynamic_state3, VK_EXT_shader_object
void vkCmdSetRasterizationSamplesEXT(
VkCommandBuffer commandBuffer,
VkSampleCountFlagBits rasterizationSamples);

commandBuffer
is the command buffer into which the command will be recorded. 
rasterizationSamples
specifiesrasterizationSamples
.
This command sets the rasterizationSamples
for subsequent drawing
commands
when drawing using shader objects, or
when the graphics pipeline is created with
VK_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT
set in
VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineMultisampleStateCreateInfo::rasterizationSamples
value
used to create the currently active pipeline.
Each sample in a fragment is also assigned a unique coverage index j
in the range [0, n × rasterizationSamples
), where n
is the number of sets in the fragment.
If the fragment contains a single set of samples, the coverage index is
always equal to the sample index.
If the fragment shading rate is set, the coverage index j is determined as a function of the pixel index p, the sample index i, and the number of rasterization samples r as:

j = i + r × ((f_{w} × f_{h})  1  p)
where the pixel index p is determined as a function of the pixel’s framebuffer location (x,y) and the fragment size (f_{w},f_{h}):

p_{x} = x % f_{w}

p_{y} = y % f_{h}

p = p_{x} + (p_{y} × f_{w})
The table below illustrates the pixel index for multipixel fragments:
1x1  1x2  1x4 

2x1  2x2  2x4 

4x1  4x2  4x4 

The coverage mask includes B bits packed into W words, defined as:

B = n ×
rasterizationSamples

W = ⌈B/32⌉
Bit b in coverage mask word w is 1
if the sample with coverage
index j = 32×w + b is covered, and 0
otherwise.
If the standardSampleLocations
member of VkPhysicalDeviceLimits
is VK_TRUE
, then the sample counts VK_SAMPLE_COUNT_1_BIT
,
VK_SAMPLE_COUNT_2_BIT
, VK_SAMPLE_COUNT_4_BIT
,
VK_SAMPLE_COUNT_8_BIT
, and VK_SAMPLE_COUNT_16_BIT
have sample
locations as listed in the following table, with the ith entry in
the table corresponding to sample index i.
VK_SAMPLE_COUNT_32_BIT
and VK_SAMPLE_COUNT_64_BIT
do not have
standard sample locations.
Locations are defined relative to an origin in the upper left corner of the
fragment.
Sample count  Sample Locations  


(0.5,0.5) 


(0.75,0.75) 


(0.375, 0.125) 


(0.5625, 0.3125) 


(0.5625, 0.5625) 
25.4. Fragment Shading Rates
The features advertised by VkPhysicalDeviceFragmentShadingRateFeaturesKHR allow an application to control the shading rate of a given fragment shader invocation.
The fragment shading rate strongly interacts with Multisampling, and the set of available rates for an implementation may be restricted by sample rate.
To query available shading rates, call:
// Provided by VK_KHR_fragment_shading_rate
VkResult vkGetPhysicalDeviceFragmentShadingRatesKHR(
VkPhysicalDevice physicalDevice,
uint32_t* pFragmentShadingRateCount,
VkPhysicalDeviceFragmentShadingRateKHR* pFragmentShadingRates);

physicalDevice
is the handle to the physical device whose properties will be queried. 
pFragmentShadingRateCount
is a pointer to an integer related to the number of fragment shading rates available or queried, as described below. 
pFragmentShadingRates
is eitherNULL
or a pointer to an array of VkPhysicalDeviceFragmentShadingRateKHR structures.
If pFragmentShadingRates
is NULL
, then the number of fragment
shading rates available is returned in pFragmentShadingRateCount
.
Otherwise, pFragmentShadingRateCount
must point to a variable set by
the user to the number of elements in the pFragmentShadingRates
array,
and on return the variable is overwritten with the number of structures
actually written to pFragmentShadingRates
.
If pFragmentShadingRateCount
is less than the number of fragment
shading rates available, at most pFragmentShadingRateCount
structures
will be written, and VK_INCOMPLETE
will be returned instead of
VK_SUCCESS
, to indicate that not all the available fragment shading
rates were returned.
The returned array of fragment shading rates must be ordered from largest
fragmentSize.width
value to smallest, and each set of fragment shading
rates with the same fragmentSize.width
value must be ordered from
largest fragmentSize.height
to smallest.
Any two entries in the array must not have the same fragmentSize
values.
For any entry in the array, the following rules also apply:

The value of
fragmentSize.width
must be less than or equal tomaxFragmentSize.width
. 
The value of
fragmentSize.width
must be greater than or equal to1
. 
The value of
fragmentSize.width
must be a poweroftwo. 
The value of
fragmentSize.height
must be less than or equal tomaxFragmentSize.height
. 
The value of
fragmentSize.height
must be greater than or equal to1
. 
The value of
fragmentSize.height
must be a poweroftwo. 
The highest sample count in
sampleCounts
must be less than or equal tomaxFragmentShadingRateRasterizationSamples
. 
The product of
fragmentSize.width
,fragmentSize.height
, and the highest sample count insampleCounts
must be less than or equal tomaxFragmentShadingRateCoverageSamples
.
Implementations must support at least the following shading rates:
sampleCounts 
fragmentSize 


{2,2} 

{2,1} 
~0 
{1,1} 
If framebufferColorSampleCounts
, includes VK_SAMPLE_COUNT_2_BIT
,
the required rates must also include VK_SAMPLE_COUNT_2_BIT
.
Note
Including the {1,1} fragment size is done for completeness; it has no actual effect on the support of rendering without setting the fragment size. All sample counts are supported for this rate. 
The VkPhysicalDeviceFragmentShadingRateKHR
structure is defined as
// Provided by VK_KHR_fragment_shading_rate
typedef struct VkPhysicalDeviceFragmentShadingRateKHR {
VkStructureType sType;
void* pNext;
VkSampleCountFlags sampleCounts;
VkExtent2D fragmentSize;
} VkPhysicalDeviceFragmentShadingRateKHR;

sType
is a VkStructureType value identifying this structure. 
pNext
isNULL
or a pointer to a structure extending this structure. 
sampleCounts
is a bitmask of sample counts for which the shading rate described byfragmentSize
is supported. 
fragmentSize
is a VkExtent2D describing the width and height of a supported shading rate.
Fragment shading rates can be set at three points, with the three rates combined to determine the final shading rate.
25.4.1. Pipeline Fragment Shading Rate
The pipeline fragment shading rate can be set on a perdraw basis by either setting the rate in a graphics pipeline, or dynamically via vkCmdSetFragmentShadingRateKHR.
The VkPipelineFragmentShadingRateStateCreateInfoKHR
structure is
defined as:
// Provided by VK_KHR_fragment_shading_rate
typedef struct VkPipelineFragmentShadingRateStateCreateInfoKHR {
VkStructureType sType;
const void* pNext;
VkExtent2D fragmentSize;
VkFragmentShadingRateCombinerOpKHR combinerOps[2];
} VkPipelineFragmentShadingRateStateCreateInfoKHR;

sType
is a VkStructureType value identifying this structure. 
pNext
isNULL
or a pointer to a structure extending this structure. 
fragmentSize
specifies a VkExtent2D structure containing the fragment size used to define the pipeline fragment shading rate for drawing commands using this pipeline. 
combinerOps
specifies a VkFragmentShadingRateCombinerOpKHR value determining how the pipeline, primitive, and attachment shading rates are combined for fragments generated by drawing commands using the created pipeline.
If the pNext
chain of VkGraphicsPipelineCreateInfo includes a
VkPipelineFragmentShadingRateStateCreateInfoKHR
structure, then that
structure includes parameters controlling the pipeline fragment shading
rate.
If this structure is not present, fragmentSize
is considered to be
equal to (1,1), and both elements of combinerOps
are considered
to be equal to VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR
.
To dynamically set the pipeline fragment shading rate and combiner operation, call:
// Provided by VK_KHR_fragment_shading_rate
void vkCmdSetFragmentShadingRateKHR(
VkCommandBuffer commandBuffer,
const VkExtent2D* pFragmentSize,
const VkFragmentShadingRateCombinerOpKHR combinerOps[2]);

commandBuffer
is the command buffer into which the command will be recorded. 
pFragmentSize
specifies the pipeline fragment shading rate for subsequent drawing commands. 
combinerOps
specifies a VkFragmentShadingRateCombinerOpKHR determining how the pipeline, primitive, and attachment shading rates are combined for fragments generated by subsequent drawing commands.
This command sets the pipeline fragment shading rate and combiner operation
for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with
VK_DYNAMIC_STATE_FRAGMENT_SHADING_RATE_KHR
set in
VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineFragmentShadingRateStateCreateInfoKHR values used to create
the currently active pipeline.
25.4.2. Primitive Fragment Shading Rate
The primitive fragment shading rate can be set via the
PrimitiveShadingRateKHR
builtin in the last active
prerasterization shader
stage.
The
rate associated with a given primitive is sourced from the value written to
PrimitiveShadingRateKHR
by that primitive’s
provoking vertex.
25.4.3. Attachment Fragment Shading Rate
The attachment shading rate can be set by including VkFragmentShadingRateAttachmentInfoKHR in a subpass to define a fragment shading rate attachment. Each pixel in the framebuffer is assigned an attachment fragment shading rate by the corresponding texel in the fragment shading rate attachment, according to:

x' = floor(x / region_{x})

y' = floor(y / region_{y})
where x' and y' are the coordinates of a texel in the fragment
shading rate attachment, x and y are the coordinates of the
pixel in the framebuffer, and region_{x} and region_{y} are the
size of the region each texel corresponds to, as defined by the
shadingRateAttachmentTexelSize
member of
VkFragmentShadingRateAttachmentInfoKHR.
If multiview is enabled and the shading
rate attachment has multiple layers, the shading rate attachment texel is
selected from the layer determined by the
ViewIndex
builtin.
If multiview is disabled, and both the
shading rate attachment and the framebuffer have multiple layers, the
shading rate attachment texel is selected from the layer determined by the
Layer
builtin.
Otherwise, the texel is unconditionally selected from the first layer of the
attachment.
The fragment size is encoded into the first component of the identified texel as follows:

size_{w} = 2^((texel / 4) & 3)^

size_{h} = 2^(texel & 3)^
where texel is the value in the first component of the identified texel, and size_{w} and size_{h} are the width and height of the fragment size, decoded from the texel.
If no fragment shading rate attachment is specified, this size is calculated as size_{w} = size_{h} = 1. Applications must not specify a width or height greater than 4 by this method.
The Fragment Shading Rate enumeration in SPIRV adheres to the above encoding.
25.4.4. Combining the Fragment Shading Rates
The final rate (C_{xy}') used for fragment shading must be one of the rates returned by vkGetPhysicalDeviceFragmentShadingRatesKHR for the sample count used by rasterization.
If any of the following conditions are met, C_{xy}' must be set to {1,1}:

If Sample Shading is enabled.

The
fragmentShadingRateWithSampleMask
limit is not supported, and VkPipelineMultisampleStateCreateInfo::pSampleMask
contains a zero value in any bit used by fragment operations. 
The
fragmentShadingRateWithShaderSampleMask
is not supported, and the fragment shader hasSampleMask
in the input or output interface. 
The
fragmentShadingRateWithShaderDepthStencilWrites
limit is not supported, and the fragment shader declares theFragDepth
builtin. 
The fragment shader declares any of the
TileImageColorReadAccessEXT
,TileImageDepthReadAccessEXT
, orTileImageStencilReadAccessEXT
capabilities.
Otherwise, each of the specified shading rates are combined and then used to derive the value of C_{xy}'. As there are three ways to specify shading rates, two combiner operations are specified  between the pipeline and primitive shading rates, and between the result of that and the attachment shading rate.
The equation used for each combiner operation is defined by
VkFragmentShadingRateCombinerOpKHR
:
// Provided by VK_KHR_fragment_shading_rate
typedef enum VkFragmentShadingRateCombinerOpKHR {
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR = 0,
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_KHR = 1,
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_KHR = 2,
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_KHR = 3,
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR = 4,
} VkFragmentShadingRateCombinerOpKHR;

VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR
specifies a combiner operation of combine(A_{xy},B_{xy}) = A_{xy}. 
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_KHR
specifies a combiner operation of combine(A_{xy},B_{xy}) = B_{xy}. 
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_KHR
specifies a combiner operation of combine(A_{xy},B_{xy}) = min(A_{xy},B_{xy}). 
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_KHR
specifies a combiner operation of combine(A_{xy},B_{xy}) = max(A_{xy},B_{xy}). 
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR
specifies a combiner operation of combine(A_{xy},B_{xy}) = A_{xy}*B_{xy}.
where combine(A_{xy},B_{xy}) is the combine operation, and A_{xy} and B_{xy} are the inputs to the operation.
If fragmentShadingRateStrictMultiplyCombiner
is VK_FALSE
, using
VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR
with values of 1 for both
A and B in the same dimension results in the value 2 being produced for that
dimension.
See the definition of fragmentShadingRateStrictMultiplyCombiner
for more information.
These operations are performed in a componentwise fashion.
This is used to generate a combined fragment area using the equation:

C_{xy} = combine(A_{xy},B_{xy})
where C_{xy} is the combined fragment area result, and A_{xy} and B_{xy} are the fragment areas of the fragment shading rates being combined.
Two combine operations are performed, first with A_{xy} equal to the
pipeline fragment shading rate
and B_{xy} equal to the primitive fragment shading rate, with the combine() operation
selected by combinerOps[0].
A second combination is then performed, with A_{xy} equal to the result
of the first combination and B_{xy} equal to the
attachment fragment shading
rate, with the combine() operation selected by combinerOps[1].
The result of the second combination is used as the final fragment shading
rate, reported via the ShadingRateKHR
builtin.
Implementations should clamp the inputs to the combiner operations A_{xy} and B_{xy}, and must clamp the result of the second combiner operation.
A fragment shading rate R_{xy} representing any of A_{xy}, B_{xy} or C_{xy} is clamped as follows. If R_{xy} is one of the rates returned by vkGetPhysicalDeviceFragmentShadingRatesKHR for the sample count used by rasterization, the clamped shading rate R_{xy}' is R_{xy}. Otherwise, the clamped shading rate is selected from the rates returned by vkGetPhysicalDeviceFragmentShadingRatesKHR for the sample count used by rasterization. From this list of supported rates, the following steps are applied in order, to select a single value:

Keep only rates where R_{x}' ≤ R_{x} and R_{y}' ≤ R_{y}.

Implementations may also keep rates where R_{x}' ≤ R_{y} and R_{y}' ≤ R_{x}.


Keep only rates with the highest area (R_{x}' × R_{y}').

Keep only rates with the lowest aspect ratio (R_{x}' + R_{y}').

In cases where a wide (e.g. 4x1) and tall (e.g. 1x4) rate remain, the implementation may choose either rate. However, it must choose this rate consistently for the same shading rates, and combiner operations for the lifetime of the VkDevice.
25.5. Sample Shading
Sample shading can be used to specify a minimum number of unique samples to
process for each fragment.
If sample shading is enabled, an implementation must invoke the fragment
shader at least max(⌈
VkPipelineMultisampleStateCreateInfo::minSampleShading
×
VkPipelineMultisampleStateCreateInfo::rasterizationSamples
⌉, 1) times per fragment.
If VkPipelineMultisampleStateCreateInfo::sampleShadingEnable
is
set to VK_TRUE
, sample shading is enabled.
If a fragment shader entry point statically uses an
input variable decorated with a BuiltIn
of SampleId
or
SamplePosition
, sample shading is enabled and a value of 1.0
is used
instead of minSampleShading
.
If a fragment shader entry point statically uses an
input variable decorated with Sample
, sample shading may be enabled
and a value of 1.0
will be used instead of minSampleShading
if it
is.
Note
If a shader decorates an input variable with 
If there are fewer fragment invocations than covered samples, implementations may include those samples in fragment shader invocations in any manner as long as covered samples are all shaded at least once, and each invocation that is not a helper invocation covers at least one sample.
25.6. Barycentric Interpolation
When the fragmentShaderBarycentric
feature is enabled, the
PerVertexKHR
interpolation
decoration can be used with fragment shader inputs to indicate that the
decorated inputs do not have associated data in the fragment.
Such inputs can only be accessed in a fragment shader using an array index
whose value (0, 1, or 2) identifies one of the vertices of the primitive
that produced the fragment.
Reads of pervertex values for missing vertices, such as the third vertex of
a line primitive, will return values from the valid vertex with the highest
index.
This means that the pervertex values of indices 1 and 2 for point
primitives will be equal to those of index 0, and the pervertex values of
index 2 for line primitives will be equal to those of index 1.
When tessellation and geometry shading
are not active, fragment shader inputs decorated with PerVertexKHR
will
take values from one of the vertices of the primitive that produced the
fragment, identified by the extra index provided in SPIRV code accessing
the input.
If the n vertices passed to a draw call are numbered 0 through n1, and
the point, line, and triangle primitives produced by the draw call are
numbered with consecutive integers beginning with zero, the following table
indicates the original vertex numbers used
for index values of 0, 1, and 2.
If an input decorated with PerVertexKHR
is accessed with any other
vertex index value, or is accessed while rasterizing a polygon when the
VkPipelineRasterizationStateCreateInfo::polygonMode
property of
the currently active pipeline is not VK_POLYGON_MODE_FILL
, an
undefined value is returned.
Primitive Topology  Vertex 0  Vertex 1  Vertex 2 


i 
i 
i 

2i 
2i+1 
2i+1 

i 
i+1 
i+1 

3i 
3i+1 
3i+2 

i 
i+1 
i+2 

i 
i+2 
i+1 

i+1 
i+2 
0 

4i+1 
4i+2 
4i+2 

i+1 
i+2 
i+2 

6i 
6i+2 
6i+4 

2i 
2i+2 
2i+4 

2i 
2i+4 
2i+2 
When geometry
shading is active, primitives processed by fragment shaders are assembled
from the vertices emitted by the geometry
shader.
In this case, the vertices used for fragment shader inputs decorated with
PerVertexKHR
are derived by treating the primitives produced by the
shader as though they were specified by a draw call and consulting
the table above.
When using tessellation without geometry shading, the tessellator produces
primitives in an implementationdependent manner.
While there is no defined vertex ordering for inputs decorated with
PerVertexKHR
, the vertex ordering used in this case will be consistent
with the ordering used to derive the values of inputs decorated with
BaryCoordKHR
or BaryCoordNoPerspKHR
.
Fragment shader inputs decorated with BaryCoordKHR
or
BaryCoordNoPerspKHR
hold threecomponent vectors with barycentric
weights that indicate the location of the fragment relative to the
screenspace locations of vertices of its primitive.
For point primitives, such variables are always assigned the value
(1,0,0).
For line primitives, the builtins are obtained
by interpolating an attribute whose values for the vertices numbered 0 and 1
are (1,0,0) and (0,1,0), respectively.
For polygon primitives, the builtins are
obtained by interpolating an attribute whose values for the vertices
numbered 0, 1, and 2 are (1,0,0), (0,1,0), and (0,0,1),
respectively.
For BaryCoordKHR
, the values are obtained using perspective
interpolation.
For BaryCoordNoPerspKHR
, the values are obtained using linear
interpolation.
The values of BaryCoordKHR
and BaryCoordNoPerspKHR
are undefined
while rasterizing a polygon when the
VkPipelineRasterizationStateCreateInfo::polygonMode
property of
the currently active pipeline is not VK_POLYGON_MODE_FILL
.
25.7. Points
A point is drawn by generating a set of fragments in the shape of a square
centered around the vertex of the point.
Each vertex has an associated point size controlling the width/height of
that square.
The point size is taken from the (potentially clipped) shader builtin
PointSize
written by:

the geometry shader, if active;

the tessellation evaluation shader, if active and no geometry shader is active;

the vertex shader, otherwise
and clamped to the implementationdependent point size range
[pointSizeRange
[0],pointSizeRange
[1]].
The value written to PointSize
must be greater than zero.
If maintenance5
is enabled, and a value is
not written to PointSize
, the point size takes a default value of 1.0.
Not all point sizes need be supported, but the size 1.0 must be supported.
The range of supported sizes and the size of evenlyspaced gradations within
that range are implementationdependent.
The range and gradations are obtained from the pointSizeRange
and
pointSizeGranularity
members of VkPhysicalDeviceLimits.
If, for instance, the size range is from 0.1 to 2.0 and the gradation size
is 0.1, then the sizes 0.1, 0.2, …, 1.9, 2.0 are supported.
Additional point sizes may also be supported.
There is no requirement that these sizes be equally spaced.
If an unsupported size is requested, the nearest supported size is used
instead.
25.7.1. Basic Point Rasterization
Point rasterization produces a fragment for each fragment area group of
framebuffer pixels with one or more sample points that intersect a region
centered at the point’s (x_{f},y_{f}).
This region is a square with side equal to the current point size.
Coverage bits that correspond to sample points that intersect the region are
1, other coverage bits are 0.
All fragments produced in rasterizing a point are assigned the same
associated data, which are those of the vertex corresponding to the point.
However, the fragment shader builtin PointCoord
contains point sprite
texture coordinates.
The s and t point sprite texture coordinates vary from zero to
one across the point horizontally lefttoright and vertically
toptobottom, respectively.
The following formulas are used to evaluate s and t:
where size is the point’s size; (x_{p},y_{p}) is the location at which the point sprite coordinates are evaluated  this may be the framebuffer coordinates of the fragment center, or the location of a sample; and (x_{f},y_{f}) is the exact, unrounded framebuffer coordinate of the vertex for the point.
25.8. Line Segments
To dynamically set the line width, call:
// Provided by VK_VERSION_1_0
void vkCmdSetLineWidth(
VkCommandBuffer commandBuffer,
float lineWidth);

commandBuffer
is the command buffer into which the command will be recorded. 
lineWidth
is the width of rasterized line segments.
This command sets the line width for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with VK_DYNAMIC_STATE_LINE_WIDTH
set in VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineRasterizationStateCreateInfo::lineWidth
value used to
create the currently active pipeline.
Not all line widths need be supported for line segment rasterization, but
width 1.0 antialiased segments must be provided.
The range and gradations are obtained from the lineWidthRange
and
lineWidthGranularity
members of VkPhysicalDeviceLimits.
If, for instance, the size range is from 0.1 to 2.0 and the gradation size
is 0.1, then the sizes 0.1, 0.2, …, 1.9, 2.0 are supported.
Additional line widths may also be supported.
There is no requirement that these widths be equally spaced.
If an unsupported width is requested, the nearest supported width is used
instead.
25.8.1. Basic Line Segment Rasterization
Rasterized line segments produce fragments which intersect a rectangle centered on the line segment. Two of the edges are parallel to the specified line segment; each is at a distance of onehalf the current width from that segment in directions perpendicular to the direction of the line. The other two edges pass through the line endpoints and are perpendicular to the direction of the specified line segment. Coverage bits that correspond to sample points that intersect the rectangle are 1, other coverage bits are 0.
Next we specify how the data associated with each rasterized fragment are
obtained.
Let p_{r} = (x_{d}, y_{d}) be the framebuffer coordinates at which
associated data are evaluated.
This may be the center of a fragment or the location of a sample within the
fragment.
When rasterizationSamples
is VK_SAMPLE_COUNT_1_BIT
, the fragment
center must be used.
Let p_{a} = (x_{a}, y_{a}) and p_{b} = (x_{b},y_{b}) be
initial and final endpoints of the line segment, respectively.
Set
(Note that t = 0 at p_{a} and t = 1 at p_{b}. Also note that this calculation projects the vector from p_{a} to p_{r} onto the line, and thus computes the normalized distance of the fragment along the line.)
If strictLines
is VK_TRUE
, line segments
are rasterized using perspective or linear interpolation.
Perspective interpolation for a line segment interpolates two values in a manner that is correct when taking the perspective of the viewport into consideration, by way of the line segment’s clip coordinates. An interpolated value f can be determined by
where f_{a} and f_{b} are the data associated with the starting and ending endpoints of the segment, respectively; w_{a} and w_{b} are the clip w coordinates of the starting and ending endpoints of the segment, respectively.
Linear interpolation for a line segment directly interpolates two values, and an interpolated value f can be determined by

f = (1  t) f_{a} + t f_{b}
where f_{a} and f_{b} are the data associated with the starting and ending endpoints of the segment, respectively.
The clip coordinate w for a sample is determined using perspective interpolation. The depth value z for a sample is determined using linear interpolation. Interpolation of fragment shader input values are determined by Interpolation decorations.
The above description documents the preferred method of line rasterization,
and must be used when
the implementation advertises the strictLines
limit in
VkPhysicalDeviceLimits as VK_TRUE
.
By default, when
strictLines
is VK_FALSE
,
the edges of the lines are generated as a parallelogram surrounding the
original line.
The major axis is chosen by noting the axis in which there is the greatest
distance between the line start and end points.
If the difference is equal in both directions then the X axis is chosen as
the major axis.
Edges 2 and 3 are aligned to the minor axis and are centered on the
endpoints of the line as in Non strict lines, and each is
lineWidth
long.
Edges 0 and 1 are parallel to the line and connect the endpoints of edges 2
and 3.
Coverage bits that correspond to sample points that intersect the
parallelogram are 1, other coverage bits are 0.
Samples that fall exactly on the edge of the parallelogram follow the polygon rasterization rules.
Interpolation occurs as if the parallelogram was decomposed into two triangles where each pair of vertices at each end of the line has identical attributes.
Only when
strictLines
is VK_FALSE
implementations may deviate from the nonstrict line algorithm described
above in the following ways:

Implementations may instead interpolate each fragment according to the formula in Basic Line Segment Rasterization using the original line segment endpoints.

Rasterization of nonantialiased nonstrict line segments may be performed using the rules defined in Bresenham Line Segment Rasterization.
If
VkPhysicalDeviceMaintenance5PropertiesKHR
::nonStrictSinglePixelWideLinesUseParallelogram
is VK_TRUE
,
and strictLines
is VK_FALSE
, nonstrict lines of width 1.0 are
rasterized as parallelograms, otherwise they are rasterized using
Bresenham’s algorithm.
If
VkPhysicalDeviceMaintenance5PropertiesKHR
::nonStrictWideLinesUseParallelogram
is VK_TRUE
,
and strictLines
is VK_FALSE
, nonstrict lines of width greater
than 1.0 are rasterized as parallelograms, otherwise they are rasterized
using Bresenham’s algorithm.
25.8.2. Bresenham Line Segment Rasterization
Nonstrict lines may also follow these rasterization rules for nonantialiased lines.
Line segment rasterization begins by characterizing the segment as either xmajor or ymajor. xmajor line segments have slope in the closed interval [1,1]; all other line segments are ymajor (slope is determined by the segment’s endpoints). We specify rasterization only for xmajor segments except in cases where the modifications for ymajor segments are not selfevident.
Ideally, Vulkan uses a diamondexit rule to determine those fragments that are produced by rasterizing a line segment. For each fragment f with center at framebuffer coordinates x_{f} and y_{f}, define a diamondshaped region that is the intersection of four half planes:
Essentially, a line segment starting at p_{a} and ending at p_{b} produces those fragments f for which the segment intersects R_{f}, except if p_{b} is contained in R_{f}.
To avoid difficulties when an endpoint lies on a boundary of R_{f} we (in principle) perturb the supplied endpoints by a tiny amount. Let p_{a} and p_{b} have framebuffer coordinates (x_{a}, y_{a}) and (x_{b}, y_{b}), respectively. Obtain the perturbed endpoints p_{a}' given by (x_{a}, y_{a})  (ε, ε^{2}) and p_{b}' given by (x_{b}, y_{b})  (ε, ε^{2}). Rasterizing the line segment starting at p_{a} and ending at p_{b} produces those fragments f for which the segment starting at p_{a}' and ending on p_{b}' intersects R_{f}, except if p_{b}' is contained in R_{f}. ε is chosen to be so small that rasterizing the line segment produces the same fragments when δ is substituted for ε for any 0 < δ ≤ ε.
When p_{a} and p_{b} lie on fragment centers, this characterization of fragments reduces to Bresenham’s algorithm with one modification: lines produced in this description are “halfopen”, meaning that the final fragment (corresponding to p_{b}) is not drawn. This means that when rasterizing a series of connected line segments, shared endpoints will be produced only once rather than twice (as would occur with Bresenham’s algorithm).
Implementations may use other line segment rasterization algorithms, subject to the following rules:

The coordinates of a fragment produced by the algorithm must not deviate by more than one unit in either x or y framebuffer coordinates from a corresponding fragment produced by the diamondexit rule.

The total number of fragments produced by the algorithm must not differ from that produced by the diamondexit rule by more than one.

For an xmajor line, two fragments that lie in the same framebuffercoordinate column must not be produced (for a ymajor line, two fragments that lie in the same framebuffercoordinate row must not be produced).

If two line segments share a common endpoint, and both segments are either xmajor (both lefttoright or both righttoleft) or ymajor (both bottomtotop or both toptobottom), then rasterizing both segments must not produce duplicate fragments. Fragments also must not be omitted so as to interrupt continuity of the connected segments.
The actual width w of Bresenham lines is determined by rounding the
line width to the nearest integer, clamping it to the
implementationdependent lineWidthRange
(with both values rounded to
the nearest integer), then clamping it to be no less than 1.
Bresenham line segments of width other than one are rasterized by offsetting them in the minor direction (for an xmajor line, the minor direction is y, and for a ymajor line, the minor direction is x) and producing a row or column of fragments in the minor direction. If the line segment has endpoints given by (x_{0}, y_{0}) and (x_{1}, y_{1}) in framebuffer coordinates, the segment with endpoints $(x_{0},y_{0}−2w−1 )$ and $(x_{1},y_{1}−2w−1 )$ is rasterized, but instead of a single fragment, a column of fragments of height w (a row of fragments of length w for a ymajor segment) is produced at each x (y for ymajor) location. The lowest fragment of this column is the fragment that would be produced by rasterizing the segment of width 1 with the modified coordinates.
The preferred method of attribute interpolation for a wide line is to
generate the same attribute values for all fragments in the row or column
described above, as if the adjusted line was used for interpolation and
those values replicated to the other fragments, except for FragCoord
which is interpolated as usual.
Implementations may instead interpolate each fragment according to the
formula in Basic Line Segment Rasterization, using
the original line segment endpoints.
When Bresenham lines are being rasterized, sample locations may all be treated as being at the pixel center (this may affect attribute and depth interpolation).
Note
The sample locations described above are not used for determining coverage, they are only used for things like attribute interpolation. The rasterization rules that determine coverage are defined in terms of whether the line intersects pixels, as opposed to the point sampling rules used for other primitive types. So these rules are independent of the sample locations. One consequence of this is that Bresenham lines cover the same pixels regardless of the number of rasterization samples, and cover all samples in those pixels (unless masked out or killed). 
25.9. Polygons
A polygon results from the decomposition of a triangle strip, triangle fan or a series of independent triangles. Like points and line segments, polygon rasterization is controlled by several variables in the VkPipelineRasterizationStateCreateInfo structure.
25.9.1. Basic Polygon Rasterization
The first step of polygon rasterization is to determine whether the triangle is backfacing or frontfacing. This determination is made based on the sign of the (clipped or unclipped) polygon’s area computed in framebuffer coordinates. One way to compute this area is:
where $x_{f}$ and $y_{f}$ are the x and y framebuffer coordinates of the ith vertex of the nvertex polygon (vertices are numbered starting at zero for the purposes of this computation) and i ⊕ 1 is (i + 1) mod n.
The interpretation of the sign of a is determined by the
VkPipelineRasterizationStateCreateInfo::frontFace
property of
the currently active pipeline.
Possible values are:
// Provided by VK_VERSION_1_0
typedef enum VkFrontFace {
VK_FRONT_FACE_COUNTER_CLOCKWISE = 0,
VK_FRONT_FACE_CLOCKWISE = 1,
} VkFrontFace;

VK_FRONT_FACE_COUNTER_CLOCKWISE
specifies that a triangle with positive area is considered frontfacing. 
VK_FRONT_FACE_CLOCKWISE
specifies that a triangle with negative area is considered frontfacing.
Any triangle which is not frontfacing is backfacing, including zeroarea triangles.
To dynamically set the front face orientation, call:
// Provided by VK_VERSION_1_3
void vkCmdSetFrontFace(
VkCommandBuffer commandBuffer,
VkFrontFace frontFace);
or the equivalent command
// Provided by VK_EXT_shader_object
void vkCmdSetFrontFaceEXT(
VkCommandBuffer commandBuffer,
VkFrontFace frontFace);

commandBuffer
is the command buffer into which the command will be recorded. 
frontFace
is a VkFrontFace value specifying the frontfacing triangle orientation to be used for culling.
This command sets the front face orientation for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with VK_DYNAMIC_STATE_FRONT_FACE
set in VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineRasterizationStateCreateInfo::frontFace
value used to
create the currently active pipeline.
Once the orientation of triangles is determined, they are culled according
to the VkPipelineRasterizationStateCreateInfo::cullMode
property
of the currently active pipeline.
Possible values are:
// Provided by VK_VERSION_1_0
typedef enum VkCullModeFlagBits {
VK_CULL_MODE_NONE = 0,
VK_CULL_MODE_FRONT_BIT = 0x00000001,
VK_CULL_MODE_BACK_BIT = 0x00000002,
VK_CULL_MODE_FRONT_AND_BACK = 0x00000003,
} VkCullModeFlagBits;

VK_CULL_MODE_NONE
specifies that no triangles are discarded 
VK_CULL_MODE_FRONT_BIT
specifies that frontfacing triangles are discarded 
VK_CULL_MODE_BACK_BIT
specifies that backfacing triangles are discarded 
VK_CULL_MODE_FRONT_AND_BACK
specifies that all triangles are discarded.
Following culling, fragments are produced for any triangles which have not been discarded.
// Provided by VK_VERSION_1_0
typedef VkFlags VkCullModeFlags;
VkCullModeFlags
is a bitmask type for setting a mask of zero or more
VkCullModeFlagBits.
To dynamically set the cull mode, call:
// Provided by VK_VERSION_1_3
void vkCmdSetCullMode(
VkCommandBuffer commandBuffer,
VkCullModeFlags cullMode);
or the equivalent command
// Provided by VK_EXT_shader_object
void vkCmdSetCullModeEXT(
VkCommandBuffer commandBuffer,
VkCullModeFlags cullMode);

commandBuffer
is the command buffer into which the command will be recorded. 
cullMode
specifies the cull mode property to use for drawing.
This command sets the cull mode for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with VK_DYNAMIC_STATE_CULL_MODE
set in VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineRasterizationStateCreateInfo::cullMode
value used to
create the currently active pipeline.
The rule for determining which fragments are produced by polygon rasterization is called point sampling. The twodimensional projection obtained by taking the x and y framebuffer coordinates of the polygon’s vertices is formed. Fragments are produced for any fragment area groups of pixels for which any sample points lie inside of this polygon. Coverage bits that correspond to sample points that satisfy the point sampling criteria are 1, other coverage bits are 0. Special treatment is given to a sample whose sample location lies on a polygon edge. In such a case, if two polygons lie on either side of a common edge (with identical endpoints) on which a sample point lies, then exactly one of the polygons must result in a covered sample for that fragment during rasterization. As for the data associated with each fragment produced by rasterizing a polygon, we begin by specifying how these values are produced for fragments in a triangle.
Barycentric coordinates are a set of three numbers, a, b, and c, each in the range [0,1], with a + b + c = 1. These coordinates uniquely specify any point p within the triangle or on the triangle’s boundary as

p = a p_{a} + b p_{b} + c p_{c}
where p_{a}, p_{b}, and p_{c} are the vertices of the triangle. a, b, and c are determined by:
where A(lmn) denotes the area in framebuffer coordinates of the triangle with vertices l, m, and n.
Denote an associated datum at p_{a}, p_{b}, or p_{c} as f_{a}, f_{b}, or f_{c}, respectively.
Perspective interpolation for a triangle interpolates three values in a manner that is correct when taking the perspective of the viewport into consideration, by way of the triangle’s clip coordinates. An interpolated value f can be determined by
where w_{a}, w_{b}, and w_{c} are the clip w coordinates of p_{a}, p_{b}, and p_{c}, respectively. a, b, and c are the barycentric coordinates of the location at which the data are produced.
Linear interpolation for a triangle directly interpolates three values, and an interpolated value f can be determined by

f = a f_{a} + b f_{b} + c f_{c}
where f_{a}, f_{b}, and f_{c} are the data associated with p_{a}, p_{b}, and p_{c}, respectively.
The clip coordinate w for a sample is determined using perspective interpolation. The depth value z for a sample is determined using linear interpolation. Interpolation of fragment shader input values are determined by Interpolation decorations.
For a polygon with more than three edges, such as are produced by clipping a triangle, a convex combination of the values of the datum at the polygon’s vertices must be used to obtain the value assigned to each fragment produced by the rasterization algorithm. That is, it must be the case that at every fragment
where n is the number of vertices in the polygon and f_{i} is the value of f at vertex i. For each i, 0 ≤ a_{i} ≤ 1 and $∑_{i=1}a_{i}=1$. The values of a_{i} may differ from fragment to fragment, but at vertex i, a_{i} = 1 and a_{j} = 0 for j ≠ i.
Note
One algorithm that achieves the required behavior is to triangulate a polygon (without adding any vertices) and then treat each triangle individually as already discussed. A scanline rasterizer that linearly interpolates data along each edge and then linearly interpolates data across each horizontal span from edge to edge also satisfies the restrictions (in this case the numerator and denominator of perspective interpolation are iterated independently, and a division is performed for each fragment). 
25.9.2. Polygon Mode
Possible values of the
VkPipelineRasterizationStateCreateInfo::polygonMode
property of
the currently active pipeline, specifying the method of rasterization for
polygons, are:
// Provided by VK_VERSION_1_0
typedef enum VkPolygonMode {
VK_POLYGON_MODE_FILL = 0,
VK_POLYGON_MODE_LINE = 1,
VK_POLYGON_MODE_POINT = 2,
} VkPolygonMode;

VK_POLYGON_MODE_POINT
specifies that polygon vertices are drawn as points. 
VK_POLYGON_MODE_LINE
specifies that polygon edges are drawn as line segments. 
VK_POLYGON_MODE_FILL
specifies that polygons are rendered using the polygon rasterization rules in this section.
These modes affect only the final rasterization of polygons: in particular, a polygon’s vertices are shaded and the polygon is clipped and possibly culled before these modes are applied.
If
VkPhysicalDeviceMaintenance5PropertiesKHR
::polygonModePointSize
is set to VK_TRUE
, the point size of the final rasterization of
polygons is taken from PointSize
when polygon
mode is VK_POLYGON_MODE_POINT
.
Otherwise, if
VkPhysicalDeviceMaintenance5PropertiesKHR
::polygonModePointSize
is set to VK_FALSE
, the point size of the final rasterization of
polygons is 1.0 when polygon mode is
VK_POLYGON_MODE_POINT
.
To dynamically set the polygon mode, call:
// Provided by VK_EXT_extended_dynamic_state3, VK_EXT_shader_object
void vkCmdSetPolygonModeEXT(
VkCommandBuffer commandBuffer,
VkPolygonMode polygonMode);

commandBuffer
is the command buffer into which the command will be recorded. 
polygonMode
specifies polygon mode.
This command sets the polygon mode for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with
VK_DYNAMIC_STATE_POLYGON_MODE_EXT
set in
VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineRasterizationStateCreateInfo::polygonMode
value used
to create the currently active pipeline.
25.9.3. Depth Bias
The depth values of all fragments generated by the rasterization of a polygon can be biased (offset) by a single depth bias value $o$ that is computed for that polygon.
Depth Bias Enable
The depth bias computation is enabled by the
depthBiasEnable
set with vkCmdSetDepthBiasEnable
or the corresponding
VkPipelineRasterizationStateCreateInfo::depthBiasEnable
value
used to create the currently active pipeline.
If the depth bias enable is VK_FALSE
, no bias is applied and the
fragment’s depth values are unchanged.
To dynamically enable whether to bias fragment depth values, call:
// Provided by VK_VERSION_1_3
void vkCmdSetDepthBiasEnable(
VkCommandBuffer commandBuffer,
VkBool32 depthBiasEnable);
or the equivalent command
// Provided by VK_EXT_shader_object
void vkCmdSetDepthBiasEnableEXT(
VkCommandBuffer commandBuffer,
VkBool32 depthBiasEnable);

commandBuffer
is the command buffer into which the command will be recorded. 
depthBiasEnable
controls whether to bias fragment depth values.
This command sets the depth bias enable for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with
VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE
set in
VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the
VkPipelineRasterizationStateCreateInfo::depthBiasEnable
value
used to create the currently active pipeline.
Depth Bias Computation
The depth bias depends on three parameters:

depthBiasSlopeFactor
scales the maximum depth slope m of the polygon 
depthBiasConstantFactor
scales the parameter r of the depth attachment 
the scaled terms are summed to produce a value which is then clamped to a minimum or maximum value specified by
depthBiasClamp
depthBiasSlopeFactor
, depthBiasConstantFactor
, and
depthBiasClamp
can each be positive, negative, or zero.
These parameters are set as described for vkCmdSetDepthBias
and vkCmdSetDepthBias2EXT
below.
The maximum depth slope m of a triangle is
where (x_{f}, y_{f}, z_{f}) is a point on the triangle. m may be approximated as
In a pipeline with a depth bias representation of
VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT
, r, for the given
primitive is defined as

r = 1
Otherwise
r is the minimum resolvable difference that depends on the depth
attachment representation.
If VkDepthBiasRepresentationInfoEXT
::depthBiasExact
is
VK_FALSE
it
is the smallest difference in framebuffer coordinate z values that is
guaranteed to remain distinct throughout polygon rasterization and in the
depth attachment.
All pairs of fragments generated by the rasterization of two polygons with
otherwise identical vertices, but z
_{f} values that differ by
r, will have distinct depth values.
For fixedpoint depth attachment representations,
or in a pipeline with a depth bias representation of
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT
,
r is constant throughout the range of the entire depth attachment.
If VkDepthBiasRepresentationInfoEXT
::depthBiasExact
is
VK_TRUE
, then its value must be

r = 2^{n}
Otherwise its value is implementationdependent but must be at most

r = 2 × 2^{n}
where n is the number of bits used for the depth aspect when using a fixedpoint attachment, or the number of mantissa bits plus one when using a floatingpoint attachment.
Otherwise for floatingpoint depth attachment, there is no single minimum resolvable difference. In this case, the minimum resolvable difference for a given polygon is dependent on the maximum exponent, e, in the range of z values spanned by the primitive. If n is the number of bits in the floatingpoint mantissa, the minimum resolvable difference, r, for the given primitive is defined as

r = 2^{en}
If no depth attachment is present, r is undefined.
The bias value o for a polygon is
m is computed as described above. If the depth attachment uses a fixedpoint representation, m is a function of depth values in the range [0,1], and o is applied to depth values in the same range.
Depth bias is applied to triangle topology primitives received by the rasterizer regardless of polygon mode. Depth bias may also be applied to line and point topology primitives received by the rasterizer.
To dynamically set the depth bias parameters, call:
// Provided by VK_VERSION_1_0
void vkCmdSetDepthBias(
VkCommandBuffer commandBuffer,
float depthBiasConstantFactor,
float depthBiasClamp,
float depthBiasSlopeFactor);

commandBuffer
is the command buffer into which the command will be recorded. 
depthBiasConstantFactor
is a scalar factor controlling the constant depth value added to each fragment. 
depthBiasClamp
is the maximum (or minimum) depth bias of a fragment. 
depthBiasSlopeFactor
is a scalar factor applied to a fragment’s slope in depth bias calculations.
This command sets the depth bias parameters for subsequent drawing commands
when drawing using shader objects, or
when the graphics pipeline is created with VK_DYNAMIC_STATE_DEPTH_BIAS
set in VkPipelineDynamicStateCreateInfo::pDynamicStates
.
Otherwise, this state is specified by the corresponding
VkPipelineRasterizationStateCreateInfo::depthBiasConstantFactor
,
depthBiasClamp
, and depthBiasSlopeFactor
values used to create
the currently active pipeline.
Calling this function is equivalent to calling vkCmdSetDepthBias2EXT
without a VkDepthBiasRepresentationInfoEXT
in the pNext chain of
VkDepthBiasInfoEXT
.
The VkDepthBiasRepresentationInfoEXT
structure is defined as:
// Provided by VK_EXT_depth_bias_control
typedef struct VkDepthBiasRepresentationInfoEXT {
VkStructureType sType;
const void* pNext;
VkDepthBiasRepresentationEXT depthBiasRepresentation;
VkBool32 depthBiasExact;
} VkDepthBiasRepresentationInfoEXT;

sType
is a VkStructureType value identifying this structure. 
pNext
isNULL
or a pointer to a structure extending this structure. 
depthBiasRepresentation
is a VkDepthBiasRepresentationEXT value specifying the depth bias representation. 
depthBiasExact
specifies that the implementation is not allowed to scale the depth bias value to ensure a minimum resolvable distance.
Possible values of
VkDepthBiasRepresentationInfoEXT::depthBiasRepresentation
,
specifying the depth bias representation are:
// Provided by VK_EXT_depth_bias_control
typedef enum VkDepthBiasRepresentationEXT {
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT = 0,
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT = 1,
VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT = 2,
} VkDepthBiasRepresentationEXT;

VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT
specifies that the depth bias representation is a factor of the format’s r as described in Depth Bias Computation. 
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT
specifies that the depth bias representation is a factor of a constant r defined by the bitsize or mantissa of the format as described in Depth Bias Computation. 
VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT
specifies that the depth bias representation is a factor of constant r equal to 1.
The VkDepthBiasInfoEXT
structure is defined as:
// Provided by VK_EXT_depth_bias_control
typedef struct VkDepthBiasInfoEXT {
VkStructureType sType;
const void* pNext;
float depthBiasConstantFactor;
float depthBiasClamp;
float depthBiasSlopeFactor;
} VkDepthBiasInfoEXT;

sType
is a VkStructureType value identifying this structure. 
pNext
isNULL
or a pointer to a structure extending this structure. 
depthBiasConstantFactor
is a scalar factor controlling the constant depth value added to each fragment. 
depthBiasClamp
is the maximum (or minimum) depth bias of a fragment. 
depthBiasSlopeFactor
is a scalar factor applied to a fragment’s slope in depth bias calculations.
If pNext
does not contain a VkDepthBiasRepresentationInfoEXT
structure, then this command is equivalent to including a
VkDepthBiasRepresentationInfoEXT with depthBiasExact
set to
VK_FALSE
and depthBiasRepresentation
set to
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT
.
To dynamically set the depth bias parameters, call:
// Provided by VK_EXT_depth_bias_control
void vkCmdSetDepthBias2EXT(
VkCommandBuffer commandBuffer,
const VkDepthBiasInfoEXT* pDepthBiasInfo);

commandBuffer
is the command buffer into which the command will be recorded. 
pDepthBiasInfo
is a pointer to a VkDepthBiasInfoEXT structure specifying depth bias parameters.
This command is functionally identical to vkCmdSetDepthBias, but
includes extensible substructures that include sType
and pNext
parameters, allowing them to be more easily extended.