1// Copyright (c) 2015-2018 Khronos Group. This work is licensed under a 2// Creative Commons Attribution 4.0 International License; see 3// http://creativecommons.org/licenses/by/4.0/ 4 5[[fragops]] 6= Fragment Operations 7 8Fragment operations execute on a per-fragment or per-sample basis, affecting 9whether or how a fragment or sample is written to the framebuffer. 10Some operations execute <<fragops-early, before fragment shading>>, and 11others <<fragops-late, after>>. 12Fragment operations always adhere to <<primrast-order,rasterization order>>. 13 14 15[[fragops-early]] 16== Early Per-Fragment Tests 17 18Once fragments are produced by rasterization, a number of per-fragment 19operations are performed prior to fragment shader execution. 20If a fragment is discarded during any of these operations, it will not be 21processed by any subsequent stage, including fragment shader execution. 22 23The <<fragops-scissor, scissor test>> and <<fragops-samplemask, sample mask 24generation>> are both always performed during early fragment tests. 25 26Fragment operations are performed in the following order: 27 28ifdef::VK_EXT_discard_rectangles[] 29 * the discard rectangles test (see <<fragops-discard-rectangles,Discard 30 Rectangles Test>>) 31endif::VK_EXT_discard_rectangles[] 32 * the scissor test (see <<fragops-scissor,Scissor Test>>) 33 * multisample fragment operations (see <<fragops-samplemask,Sample Mask>>) 34 35If early per-fragment operations are <<shaders-fragment-earlytest,enabled by 36the fragment shader>>, these operations are also performed: 37 38 * <<fragops-dbt, Depth bounds test>> 39 * <<fragops-stencil, Stencil test>> 40 * <<fragops-depth, Depth test>> 41 * <<fragops-samplecount, Sample counting>> for <<queries-occlusion, 42 occlusion queries>> 43 44ifdef::VK_EXT_post_depth_coverage[] 45If post-depth coverage operation is 46<<shaders-fragment-earlytest-postdepthcoverage,enabled by the fragment 47shader>>, the <<interfaces-builtin-variables-samplemask,code:SampleMask>> 48coverage is determined after the early stencil and depth tests. 49endif::VK_EXT_post_depth_coverage[] 50 51ifdef::VK_EXT_discard_rectangles[] 52[[fragops-discard-rectangles]] 53== Discard Rectangles Test 54 55[open,refpage='VkPipelineDiscardRectangleStateCreateInfoEXT',desc='Structure specifying discard rectangle',type='structs'] 56-- 57 58The discard rectangles test determines if fragment's framebuffer coordinates 59[eq]#(x~f~,y~f~)# are inclusive or exclusive to a set of discard-space 60rectangles. 61The discard rectangles are set with the 62sname:VkPipelineDiscardRectangleStateCreateInfoEXT pipeline state, which is 63defined as: 64 65include::../api/structs/VkPipelineDiscardRectangleStateCreateInfoEXT.txt[] 66 67 * pname:sType is the type of this structure. 68 * pname:pNext is `NULL` or a pointer to an extension-specific structure. 69 * pname:flags is reserved for future use. 70 * pname:discardRectangleMode is the mode used to determine whether 71 fragments that lie within the discard rectangle are discarded or not. 72 * pname:discardRectangleCount is the number of discard rectangles used by 73 the pipeline. 74 * pname:pDiscardRectangles is a pointer to an array of slink:VkRect2D 75 structures, defining the discard rectangles. 76 If the discard rectangle state is dynamic, this member is ignored. 77 78.Valid Usage 79**** 80 * [[VUID-VkPipelineDiscardRectangleStateCreateInfoEXT-discardRectangleCount-00582]] 81 pname:discardRectangleCount must: be between `0` and 82 sname:VkPhysicalDeviceDiscardRectanglePropertiesEXT::pname:maxDiscardRectangles, 83 inclusive 84**** 85 86include::../validity/structs/VkPipelineDiscardRectangleStateCreateInfoEXT.txt[] 87-- 88 89[open,refpage='VkPipelineDiscardRectangleStateCreateFlagsEXT',desc='Reserved for future use',type='enums'] 90-- 91include::../api/flags/VkPipelineDiscardRectangleStateCreateFlagsEXT.txt[] 92 93sname:VkPipelineDiscardRectangleStateCreateFlagsEXT is a bitmask type for 94setting a mask, but is currently reserved for future use. 95-- 96 97The sname:VkPipelineDiscardRectangleStateCreateInfoEXT state is set by 98adding an instance of this structure to the pname:pNext chain of an instance 99of the sname:VkGraphicsPipelineCreateInfo structure and setting the graphics 100pipeline state with flink:vkCreateGraphicsPipelines. 101 102If the bound pipeline state object was not created with the 103ename:VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT dynamic state enabled, discard 104rectangles are specified using the pname:pDiscardRectangles member of 105sname:VkPipelineDiscardRectangleStateCreateInfoEXT linked to the pipeline 106state object. 107 108[open,refpage='vkCmdSetDiscardRectangleEXT',desc='Set discard rectangles dynamically',type='protos'] 109-- 110 111If the pipeline state object was created with the 112ename:VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT dynamic state enabled, the 113discard rectangles are dynamically set and changed with the command: 114 115include::../api/protos/vkCmdSetDiscardRectangleEXT.txt[] 116 117 * pname:commandBuffer is the command buffer into which the command will be 118 recorded. 119 * pname:firstDiscardRectangle is the index of the first discard rectangle 120 whose state is updated by the command. 121 * pname:discardRectangleCount is the number of discard rectangles whose 122 state are updated by the command. 123 * pname:pDiscardRectangles is a pointer to an array of slink:VkRect2D 124 structures specifying discard rectangles. 125 126The discard rectangle taken from element [eq]#i# of pname:pDiscardRectangles 127replace the current state for the discard rectangle index 128[eq]#pname:firstDiscardRectangle {plus} i#, for [eq]#i# in [eq]#[0, 129pname:discardRectangleCount)#. 130 131.Valid Usage 132**** 133 * [[VUID-vkCmdSetDiscardRectangleEXT-None-00583]] 134 The bound graphics pipeline must: have been created with the 135 ename:VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT dynamic state enabled 136 * [[VUID-vkCmdSetDiscardRectangleEXT-firstDiscardRectangle-00585]] 137 The sum of pname:firstDiscardRectangle and pname:discardRectangleCount 138 must: be less than or equal to 139 slink:VkPhysicalDeviceDiscardRectanglePropertiesEXT::pname:maxDiscardRectangles 140 * [[VUID-vkCmdSetDiscardRectangleEXT-x-00587]] 141 The pname:x and pname:y member of pname:offset in each slink:VkRect2D 142 element of pname:pDiscardRectangles must: be greater than or equal to 143 `0` 144 * [[VUID-vkCmdSetDiscardRectangleEXT-offset-00588]] 145 Evaluation of [eq]#(pname:offset.x {plus} pname:extent.width)# in each 146 slink:VkRect2D element of pname:pDiscardRectangles must: not cause a 147 signed integer addition overflow 148 * [[VUID-vkCmdSetDiscardRectangleEXT-offset-00589]] 149 Evaluation of [eq]#(pname:offset.y {plus} pname:extent.height)# in each 150 slink:VkRect2D element of pname:pDiscardRectangles must: not cause a 151 signed integer addition overflow 152**** 153 154include::../validity/protos/vkCmdSetDiscardRectangleEXT.txt[] 155-- 156 157The sname:VkOffset2D::pname:x and sname:VkOffset2D::pname:y values of the 158discard rectangle sname:VkRect2D specify the upper-left origin of the 159discard rectangle box. 160The lower-right corner of the discard rectangle box is specified as the 161sname:VkExtent2D::pname:width and sname:VkExtent2D::pname:height from the 162upper-left origin. 163 164If [eq]#pname:offset.x {leq} x~f~ < pname:offset.x {plus} 165pname:extent.width# and [eq]#pname:offset.y {leq} y~f~ < pname:offset.y 166{plus} pname:extent.height# for the selected discard rectangle, then the 167fragment is within the discard rectangle box. 168When the discard rectangle mode is 169ename:VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT a fragment within at least one 170of the active discard rectangle boxes passes the discard rectangle test; 171otherwise the fragment fails the discard rectangle test and is discarded. 172When the discard rectangle mode is 173ename:VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT a fragment within at least one 174of the active discard rectangle boxes fails the discard rectangle test, and 175the fragment is discarded; otherwise the fragment passes the discard 176rectangles test. 177The discard rectangles test only applies to <<drawing, drawing commands>>, 178not to other commands like clears or copies. 179 180[open,refpage='VkDiscardRectangleModeEXT',desc='Specify the discard rectangle mode',type='enums'] 181-- 182 183Possible values of 184slink:VkPipelineDiscardRectangleStateCreateInfoEXT::pname:discardRectangleMode, 185specifying the behavior of the discard rectangle test, are: 186 187include::../api/enums/VkDiscardRectangleModeEXT.txt[] 188 189 * ename:VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT specifies that a fragment 190 within any discard rectangle satisfies the test. 191 * ename:VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT specifies that a fragment 192 not within any of the discard rectangles satisfies the test. 193 194-- 195 196endif::VK_EXT_discard_rectangles[] 197 198 199[[fragops-scissor]] 200== Scissor Test 201 202[open,refpage='vkCmdSetScissor',desc='Set the dynamic scissor rectangles on a command buffer',type='protos'] 203-- 204 205The scissor test determines if a fragment's framebuffer coordinates 206[eq]#(x~f~,y~f~)# lie within the scissor rectangle corresponding to the 207viewport index (see <<vertexpostproc-viewport,Controlling the Viewport>>) 208used by the primitive that generated the fragment. 209If the pipeline state object is created without 210ename:VK_DYNAMIC_STATE_SCISSOR enabled then the scissor rectangles are set 211by the slink:VkPipelineViewportStateCreateInfo state of the pipeline state 212object. 213Otherwise, to dynamically set the scissor rectangles call: 214 215include::../api/protos/vkCmdSetScissor.txt[] 216 217 * pname:commandBuffer is the command buffer into which the command will be 218 recorded. 219 * pname:firstScissor is the index of the first scissor whose state is 220 updated by the command. 221 * pname:scissorCount is the number of scissors whose rectangles are 222 updated by the command. 223 * pname:pScissors is a pointer to an array of slink:VkRect2D structures 224 defining scissor rectangles. 225 226The scissor rectangles taken from element [eq]#i# of pname:pScissors replace 227the current state for the scissor index [eq]#pname:firstScissor {plus} i#, 228for [eq]#i# in [eq]#[0, pname:scissorCount)#. 229 230Each scissor rectangle is described by a slink:VkRect2D structure, with the 231pname:offset.x and pname:offset.y values determining the upper left corner 232of the scissor rectangle, and the pname:extent.width and pname:extent.height 233values determining the size in pixels. 234 235.Valid Usage 236**** 237 * [[VUID-vkCmdSetScissor-None-00590]] 238 The bound graphics pipeline must: have been created with the 239 ename:VK_DYNAMIC_STATE_SCISSOR dynamic state enabled 240 * [[VUID-vkCmdSetScissor-firstScissor-00591]] 241 pname:firstScissor must: be less than 242 sname:VkPhysicalDeviceLimits::pname:maxViewports 243 * [[VUID-vkCmdSetScissor-firstScissor-00592]] 244 The sum of pname:firstScissor and pname:scissorCount must: be between 245 `1` and sname:VkPhysicalDeviceLimits::pname:maxViewports, inclusive 246 * [[VUID-vkCmdSetScissor-firstScissor-00593]] 247 If the <<features-features-multiViewport,multiple viewports>> feature is 248 not enabled, pname:firstScissor must: be `0` 249 * [[VUID-vkCmdSetScissor-scissorCount-00594]] 250 If the <<features-features-multiViewport,multiple viewports>> feature is 251 not enabled, pname:scissorCount must: be `1` 252 * [[VUID-vkCmdSetScissor-x-00595]] 253 The pname:x and pname:y members of pname:offset must: be greater than or 254 equal to `0` 255 * [[VUID-vkCmdSetScissor-offset-00596]] 256 Evaluation of [eq]#(pname:offset.x {plus} pname:extent.width)# must: not 257 cause a signed integer addition overflow 258 * [[VUID-vkCmdSetScissor-offset-00597]] 259 Evaluation of [eq]#(pname:offset.y {plus} pname:extent.height)# must: 260 not cause a signed integer addition overflow 261**** 262 263include::../validity/protos/vkCmdSetScissor.txt[] 264-- 265 266If [eq]#pname:offset.x {leq} x~f~ < pname:offset.x {plus} 267pname:extent.width# and [eq]#pname:offset.y {leq} y~f~ < pname:offset.y 268{plus} pname:extent.height# for the selected scissor rectangle, then the 269scissor test passes. 270Otherwise, the test fails and the fragment is discarded. 271For points, lines, and polygons, the scissor rectangle for a primitive is 272selected in the same manner as the viewport (see 273<<vertexpostproc-viewport,Controlling the Viewport>>). 274The scissor rectangles test only applies to <<drawing, drawing commands>>, 275not to other commands like clears or copies. 276 277It is legal for [eq]#pname:offset.x {plus} pname:extent.width# or 278[eq]#pname:offset.y {plus} pname:extent.height# to exceed the dimensions of 279the framebuffer - the scissor test still applies as defined above. 280Rasterization does not produce fragments outside of the framebuffer, so such 281fragments never have the scissor test performed on them. 282 283The scissor test is always performed. 284Applications can: effectively disable the scissor test by specifying a 285scissor rectangle that encompasses the entire framebuffer. 286 287 288[[fragops-samplemask]] 289== Sample Mask 290 291This step modifies fragment coverage values based on the values in the 292pname:pSampleMask array member of 293slink:VkPipelineMultisampleStateCreateInfo, as described previously in 294section <<pipelines-graphics>>. 295 296pname:pSampleMask contains an array of static coverage information that is 297code:ANDed with the coverage information generated during rasterization. 298Bits that are zero disable coverage for the corresponding sample. 299Bit [eq]#B# of mask word [eq]#M# corresponds to sample [eq]#32 {times} M 300{plus} B#. 301The array is sized to a length of [eq]#{lceil} pname:rasterizationSamples / 30232 {rceil}# words. 303If pname:pSampleMask is `NULL`, it is treated as if the mask has all bits 304enabled, i.e. no coverage is removed from fragments. 305 306[open,refpage='VkSampleMask',desc='Mask of sample coverage information',type='basetypes',xrefs='VkPipelineMultisampleStateCreateInfo'] 307-- 308 309The elements of the sample mask array are of type basetype:VkSampleMask, 310each representing 32 bits of coverage information: 311 312include::../api/basetypes/VkSampleMask.txt[] 313 314-- 315 316 317[[fragops-early-mode]] 318== Early Fragment Test Mode 319 320The depth bounds test, stencil test, depth test, and occlusion query sample 321counting are performed before fragment shading if and only if early fragment 322tests are enabled by the fragment shader (see 323<<shaders-fragment-earlytest,Early Fragment Tests>>). 324When early per-fragment operations are enabled, these operations are 325performed prior to fragment shader execution, and the stencil buffer, depth 326buffer, and occlusion query sample counts will be updated accordingly; these 327operations will not be performed again after fragment shader execution. 328 329If a pipeline's fragment shader has early fragment tests disabled, these 330operations are performed only after fragment program execution, in the order 331described below. 332If a pipeline does not contain a fragment shader, these operations are 333performed only once. 334 335If early fragment tests are enabled, any depth value computed by the 336fragment shader has no effect. 337Additionally, the depth test (including depth writes), stencil test 338(including stencil writes) and sample counting operations are performed even 339for fragments or samples that would be discarded after fragment shader 340execution due to per-fragment operations such as alpha-to-coverage tests, or 341due to the fragment being discarded by the shader itself. 342 343 344[[fragops-late]] 345== Late Per-Fragment Tests 346 347After programmable fragment processing, per-fragment operations are 348performed before blending and color output to the framebuffer. 349 350A fragment is produced by rasterization with framebuffer coordinates of 351[eq]#(x~f~,y~f~)# and depth [eq]#z#, as described in 352<<primsrast,Rasterization>>. 353The fragment is then modified by programmable fragment processing, which 354adds associated data as described in <<shaders,Shaders>>. 355The fragment is then further modified, and possibly discarded by the late 356per-fragment operations described in this chapter. 357Finally, if the fragment was not discarded, it is used to update the 358framebuffer at the fragment's framebuffer coordinates for any samples that 359remain covered. 360 361The depth bounds test, stencil test, and depth test are performed for each 362pixel sample, rather than just once for each fragment. 363Stencil and depth operations are performed for a pixel sample only if that 364sample's fragment coverage bit is a value of 1 when the fragment executes 365the corresponding stage of the graphics pipeline. 366If the corresponding coverage bit is 0, no operations are performed for that 367sample. 368Failure of the depth bounds, stencil, or depth test results in termination 369of the processing of that sample by means of disabling coverage for that 370sample, rather than discarding of the fragment. 371If, at any point, a fragment's coverage becomes zero for all samples, then 372the fragment is discarded. 373All operations are performed on the depth and stencil values stored in the 374depth/stencil attachment of the framebuffer. 375The contents of the color attachments are not modified at this point. 376 377The depth bounds test, stencil test, depth test, and occlusion query 378operations described in <<fragops-dbt,Depth Bounds Test>>, 379<<fragops-stencil,Stencil Test>>, <<fragops-depth,Depth Test>>, 380<<fragops-samplecount,Sample Counting>> are instead performed prior to 381fragment processing, as described in <<fragops-early-mode,Early Fragment 382Test Mode>>, if requested by the fragment shader. 383 384 385ifdef::VK_AMD_mixed_attachment_samples[] 386 387[[fragops-mixed-attachment-samples]] 388== Mixed attachment samples 389 390Special rules apply to per-fragment operations when the number of samples of 391the color attachments differs from the number of samples of the 392depth/stencil attachment used in a subpass. 393 394Let [eq]#C# be the number of color attachment samples and [eq]#D# be the 395number of depth/stencil attachment samples used by a given subpass. 396 397If [eq]#C < D# then only the first [eq]#C# number of samples are guaranteed 398to have a corresponding fragment shader invocation and thus a corresponding 399color output value, unless the fragment shaders produce inputs to the late 400per-fragment tests (e.g. by outputting to a variable decorated with the 401code:FragDepth built-in decoration). 402Implementations are allowed to produce fragment shader invocations for 403samples with indices greater than or equal to [eq]#C# but (other than 404potential side effects) the color outputs of fragment shader invocations 405corresponding to such samples are discarded. 406 407endif::VK_AMD_mixed_attachment_samples[] 408 409 410[[fragops-covg]] 411== Multisample Coverage 412 413ifndef::VK_NV_sample_mask_override_coverage[] 414If a fragment shader is active and its entry point's interface includes a 415built-in output variable decorated with code:SampleMask, the fragment 416coverage is code:ANDed with the bits of the sample mask to generate a new 417fragment coverage value. 418endif::VK_NV_sample_mask_override_coverage[] 419ifdef::VK_NV_sample_mask_override_coverage[] 420If a fragment shader is active and its entry point's interface includes a 421built-in output variable decorated with code:SampleMask and also decorated 422with code:OverrideCoverageNV the fragment coverage is replaced with the 423sample mask bits set in the shader. 424Otherwise if the built-in output variable decorated with code:SampleMask is 425not also decorated with code:OverrideCoverageNV then the fragment coverage 426is code:ANDed with the bits of the sample mask to generate a new fragment 427coverage value. 428endif::VK_NV_sample_mask_override_coverage[] 429If such a fragment shader did not assign a value to code:SampleMask due to 430flow of control, the value code:ANDed with the fragment coverage is 431undefined. 432If no fragment shader is active, or if the active fragment shader does not 433include code:SampleMask in its interface, the fragment coverage is not 434modified. 435 436Next, the fragment alpha and coverage values are modified based on the 437pname:alphaToCoverageEnable and pname:alphaToOneEnable members of the 438slink:VkPipelineMultisampleStateCreateInfo structure. 439 440All alpha values in this section refer only to the alpha component of the 441fragment shader output that has a code:Location and code:Index decoration of 442zero (see the <<interfaces-fragmentoutput,Fragment Output Interface>> 443section). 444If that shader output has an integer or unsigned integer type, then these 445operations are skipped. 446 447If pname:alphaToCoverageEnable is enabled, a temporary coverage value with 448pname:rasterizationSamples bits is generated where each bit is determined by 449the fragment's alpha value. 450The temporary coverage value is then ANDed with the fragment coverage value 451to generate a new fragment coverage value. 452 453No specific algorithm is specified for converting the alpha value to a 454temporary coverage mask. 455It is intended that the number of 1's in this value be proportional to the 456alpha value (clamped to [eq]#[0,1]#), with all 1's corresponding to a value 457of 1.0 and all 0's corresponding to 0.0. 458The algorithm may: be different at different pixel locations. 459 460[NOTE] 461.Note 462==== 463Using different algorithms at different pixel location may: help to avoid 464artifacts caused by regular coverage sample locations. 465==== 466 467Next, if pname:alphaToOneEnable is enabled, each alpha value is replaced by 468the maximum representable alpha value for fixed-point color buffers, or by 4691.0 for floating-point buffers. 470Otherwise, the alpha values are not changed. 471 472 473[[fragops-ds-state]] 474== Depth and Stencil Operations 475 476Pipeline state controlling the <<fragops-dbt,depth bounds tests>>, 477<<fragops-stencil,stencil test>>, and <<fragops-depth,depth test>> is 478specified through the members of the 479sname:VkPipelineDepthStencilStateCreateInfo structure. 480 481[open,refpage='VkPipelineDepthStencilStateCreateInfo',desc='Structure specifying parameters of a newly created pipeline depth stencil state',type='structs'] 482-- 483 484The sname:VkPipelineDepthStencilStateCreateInfo structure is defined as: 485 486include::../api/structs/VkPipelineDepthStencilStateCreateInfo.txt[] 487 488 * pname:sType is the type of this structure. 489 * pname:pNext is `NULL` or a pointer to an extension-specific structure. 490 * pname:flags is reserved for future use. 491 * pname:depthTestEnable controls whether <<fragops-depth,depth testing>> 492 is enabled. 493 * pname:depthWriteEnable controls whether <<fragops-depth-write,depth 494 writes>> are enabled when pname:depthTestEnable is ename:VK_TRUE. 495 Depth writes are always disabled when pname:depthTestEnable is 496 ename:VK_FALSE. 497 * pname:depthCompareOp is the comparison operator used in the 498 <<fragops-depth,depth test>>. 499 * pname:depthBoundsTestEnable controls whether <<fragops-dbt,depth bounds 500 testing>> is enabled. 501 * pname:stencilTestEnable controls whether <<fragops-stencil,stencil 502 testing>> is enabled. 503 * pname:front and pname:back control the parameters of the 504 <<fragops-stencil,stencil test>>. 505 * pname:minDepthBounds and pname:maxDepthBounds define the range of values 506 used in the <<fragops-dbt,depth bounds test>>. 507 508.Valid Usage 509**** 510 * [[VUID-VkPipelineDepthStencilStateCreateInfo-depthBoundsTestEnable-00598]] 511 If the <<features-features-depthBounds,depth bounds testing>> feature is 512 not enabled, pname:depthBoundsTestEnable must: be ename:VK_FALSE 513**** 514 515include::../validity/structs/VkPipelineDepthStencilStateCreateInfo.txt[] 516-- 517 518[open,refpage='VkPipelineDepthStencilStateCreateFlags',desc='Reserved for future use',type='enums'] 519-- 520include::../api/flags/VkPipelineDepthStencilStateCreateFlags.txt[] 521 522sname:VkPipelineDepthStencilStateCreateFlags is a bitmask type for setting a 523mask, but is currently reserved for future use. 524-- 525 526 527[[fragops-dbt]] 528== Depth Bounds Test 529 530[open,refpage='vkCmdSetDepthBounds',desc='Set the depth bounds test values for a command buffer',type='protos'] 531-- 532 533The depth bounds test conditionally disables coverage of a sample based on 534the outcome of a comparison between the value [eq]#z~a~# in the depth 535attachment at location [eq]#(x~f~,y~f~)# (for the appropriate sample) and a 536range of values. 537The test is enabled or disabled by the pname:depthBoundsTestEnable member of 538slink:VkPipelineDepthStencilStateCreateInfo: If the pipeline state object is 539created without the ename:VK_DYNAMIC_STATE_DEPTH_BOUNDS dynamic state 540enabled then the range of values used in the depth bounds test are defined 541by the pname:minDepthBounds and pname:maxDepthBounds members of the 542slink:VkPipelineDepthStencilStateCreateInfo structure. 543Otherwise, to dynamically set the depth bounds range values call: 544 545include::../api/protos/vkCmdSetDepthBounds.txt[] 546 547 * pname:commandBuffer is the command buffer into which the command will be 548 recorded. 549 * pname:minDepthBounds is the lower bound of the range of depth values 550 used in the depth bounds test. 551 * pname:maxDepthBounds is the upper bound of the range. 552 553.Valid Usage 554**** 555 * [[VUID-vkCmdSetDepthBounds-None-00599]] 556 The bound graphics pipeline must: have been created with the 557 ename:VK_DYNAMIC_STATE_DEPTH_BOUNDS dynamic state enabled 558ifdef::VK_EXT_depth_range_unrestricted[] 559 * [[VUID-vkCmdSetDepthBounds-minDepthBounds-00600]] 560 Unless the `<<VK_EXT_depth_range_unrestricted>>` extension is enabled 561 pname:minDepthBounds must: be between `0.0` and `1.0`, inclusive 562endif::VK_EXT_depth_range_unrestricted[] 563ifndef::VK_EXT_depth_range_unrestricted[] 564 * [[VUID-vkCmdSetDepthBounds-minDepthBounds-00600]] 565 pname:minDepthBounds must: be between `0.0` and `1.0`, inclusive 566endif::VK_EXT_depth_range_unrestricted[] 567ifdef::VK_EXT_depth_range_unrestricted[] 568 * [[VUID-vkCmdSetDepthBounds-maxDepthBounds-00601]] 569 Unless the `<<VK_EXT_depth_range_unrestricted>>` extension is enabled 570 pname:maxDepthBounds must: be between `0.0` and `1.0`, inclusive 571endif::VK_EXT_depth_range_unrestricted[] 572ifndef::VK_EXT_depth_range_unrestricted[] 573 * [[VUID-vkCmdSetDepthBounds-maxDepthBounds-00601]] 574 pname:maxDepthBounds must: be between `0.0` and `1.0`, inclusive 575endif::VK_EXT_depth_range_unrestricted[] 576**** 577 578include::../validity/protos/vkCmdSetDepthBounds.txt[] 579-- 580 581If [eq]#pname:minDepthBounds {leq} z~a~ {leq} pname:maxDepthBounds}#, then 582the depth bounds test passes. 583Otherwise, the test fails and the sample's coverage bit is cleared in the 584fragment. 585If there is no depth framebuffer attachment or if the depth bounds test is 586disabled, it is as if the depth bounds test always passes. 587 588 589[[fragops-stencil]] 590== Stencil Test 591 592The stencil test conditionally disables coverage of a sample based on the 593outcome of a comparison between the stencil value in the depth/stencil 594attachment at location [eq]#(x~f~,y~f~)# (for the appropriate sample) and a 595reference value. 596The stencil test also updates the value in the stencil attachment, depending 597on the test state, the stencil value and the stencil write masks. 598The test is enabled or disabled by the pname:stencilTestEnable member of 599slink:VkPipelineDepthStencilStateCreateInfo. 600 601When disabled, the stencil test and associated modifications are not made, 602and the sample's coverage is not modified. 603 604The stencil test is controlled with the pname:front and pname:back members 605of sname:VkPipelineDepthStencilStateCreateInfo which are of type 606sname:VkStencilOpState. 607 608[open,refpage='VkStencilOpState',desc='Structure specifying stencil operation state',type='structs'] 609-- 610 611The sname:VkStencilOpState structure is defined as: 612 613include::../api/structs/VkStencilOpState.txt[] 614 615 * pname:failOp is a elink:VkStencilOp value specifying the action 616 performed on samples that fail the stencil test. 617 * pname:passOp is a elink:VkStencilOp value specifying the action 618 performed on samples that pass both the depth and stencil tests. 619 * pname:depthFailOp is a elink:VkStencilOp value specifying the action 620 performed on samples that pass the stencil test and fail the depth test. 621 * pname:compareOp is a elink:VkCompareOp value specifying the comparison 622 operator used in the stencil test. 623 * pname:compareMask selects the bits of the unsigned integer stencil 624 values participating in the stencil test. 625 * pname:writeMask selects the bits of the unsigned integer stencil values 626 updated by the stencil test in the stencil framebuffer attachment. 627 * pname:reference is an integer reference value that is used in the 628 unsigned stencil comparison. 629 630include::../validity/structs/VkStencilOpState.txt[] 631-- 632 633There are two sets of stencil-related state, the front stencil state set and 634the back stencil state set. 635Stencil tests and writes use the front set of stencil state when processing 636front-facing fragments and use the back set of stencil state when processing 637back-facing fragments. 638Fragments rasterized from non-polygon primitives (points and lines) are 639always considered front-facing. 640Fragments rasterized from polygon primitives inherit their facingness from 641the polygon, even if the polygon is rasterized as points or lines due to the 642current elink:VkPolygonMode. 643Whether a polygon is front- or back-facing is determined in the same manner 644used for face culling (see <<primsrast-polygons-basic,Basic Polygon 645Rasterization>>). 646 647The operation of the stencil test is also affected by the pname:compareMask, 648pname:writeMask, and pname:reference members of sname:VkStencilOpState set 649in the pipeline state object if the pipeline state object is created without 650the ename:VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK, 651ename:VK_DYNAMIC_STATE_STENCIL_WRITE_MASK, and 652ename:VK_DYNAMIC_STATE_STENCIL_REFERENCE dynamic states enabled, 653respectively. 654 655[open,refpage='vkCmdSetStencilCompareMask',desc='Set the stencil compare mask dynamic state',type='protos'] 656-- 657 658If the pipeline state object is created with the 659ename:VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK dynamic state enabled, then to 660dynamically set the stencil compare mask call: 661 662include::../api/protos/vkCmdSetStencilCompareMask.txt[] 663 664 * pname:commandBuffer is the command buffer into which the command will be 665 recorded. 666 * pname:faceMask is a bitmask of elink:VkStencilFaceFlagBits specifying 667 the set of stencil state for which to update the compare mask. 668 * pname:compareMask is the new value to use as the stencil compare mask. 669 670.Valid Usage 671**** 672 * [[VUID-vkCmdSetStencilCompareMask-None-00602]] 673 The bound graphics pipeline must: have been created with the 674 ename:VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK dynamic state enabled 675**** 676 677include::../validity/protos/vkCmdSetStencilCompareMask.txt[] 678-- 679 680[open,refpage='VkStencilFaceFlagBits',desc='Bitmask specifying sets of stencil state for which to update the compare mask',type='enums'] 681-- 682 683Bits which can: be set in the 684flink:vkCmdSetStencilCompareMask::pname:faceMask parameter, and similar 685parameters of other commands specifying which stencil state to update 686stencil masks for, are: 687 688include::../api/enums/VkStencilFaceFlagBits.txt[] 689 690 * ename:VK_STENCIL_FACE_FRONT_BIT specifies that only the front set of 691 stencil state is updated. 692 * ename:VK_STENCIL_FACE_BACK_BIT specifies that only the back set of 693 stencil state is updated. 694 * ename:VK_STENCIL_FRONT_AND_BACK is the combination of 695 ename:VK_STENCIL_FACE_FRONT_BIT and ename:VK_STENCIL_FACE_BACK_BIT, and 696 specifies that both sets of stencil state are updated. 697 698-- 699 700[open,refpage='VkStencilFaceFlags',desc='Bitmask of VkStencilFaceFlagBits',type='enums'] 701-- 702include::../api/flags/VkStencilFaceFlags.txt[] 703 704sname:VkStencilFaceFlags is a bitmask type for setting a mask of zero or 705more slink:VkStencilFaceFlagBits. 706-- 707 708[open,refpage='vkCmdSetStencilWriteMask',desc='Set the stencil write mask dynamic state',type='protos'] 709-- 710 711If the pipeline state object is created with the 712ename:VK_DYNAMIC_STATE_STENCIL_WRITE_MASK dynamic state enabled, then to 713dynamically set the stencil write mask call: 714 715include::../api/protos/vkCmdSetStencilWriteMask.txt[] 716 717 * pname:commandBuffer is the command buffer into which the command will be 718 recorded. 719 * pname:faceMask is a bitmask of elink:VkStencilFaceFlagBits specifying 720 the set of stencil state for which to update the write mask, as 721 described above for flink:vkCmdSetStencilCompareMask. 722 * pname:writeMask is the new value to use as the stencil write mask. 723 724.Valid Usage 725**** 726 * [[VUID-vkCmdSetStencilWriteMask-None-00603]] 727 The bound graphics pipeline must: have been created with the 728 ename:VK_DYNAMIC_STATE_STENCIL_WRITE_MASK dynamic state enabled 729**** 730 731include::../validity/protos/vkCmdSetStencilWriteMask.txt[] 732-- 733 734[open,refpage='vkCmdSetStencilReference',desc='Set the stencil reference dynamic state',type='protos'] 735-- 736 737If the pipeline state object is created with the 738ename:VK_DYNAMIC_STATE_STENCIL_REFERENCE dynamic state enabled, then to 739dynamically set the stencil reference value call: 740 741include::../api/protos/vkCmdSetStencilReference.txt[] 742 743 * pname:commandBuffer is the command buffer into which the command will be 744 recorded. 745 * pname:faceMask is a bitmask of elink:VkStencilFaceFlagBits specifying 746 the set of stencil state for which to update the reference value, as 747 described above for flink:vkCmdSetStencilCompareMask. 748 * pname:reference is the new value to use as the stencil reference value. 749 750.Valid Usage 751**** 752 * [[VUID-vkCmdSetStencilReference-None-00604]] 753 The bound graphics pipeline must: have been created with the 754 ename:VK_DYNAMIC_STATE_STENCIL_REFERENCE dynamic state enabled 755**** 756 757include::../validity/protos/vkCmdSetStencilReference.txt[] 758-- 759 760pname:reference is an integer reference value that is used in the unsigned 761stencil comparison. 762The reference value used by stencil comparison must be within the range 763[eq]#[0,2^s^-1]# , where [eq]#s# is the number of bits in the stencil 764framebuffer attachment, otherwise the reference value is considered 765undefined. 766The [eq]#s# least significant bits of pname:compareMask are bitwise 767code:ANDed with both the reference and the stored stencil value, and the 768resulting masked values are those that participate in the comparison 769controlled by pname:compareOp. 770Let [eq]#R# be the masked reference value and [eq]#S# be the masked stored 771stencil value. 772 773[open,refpage='VkCompareOp',desc='Stencil comparison function',type='enums'] 774-- 775 776Possible values of slink:VkStencilOpState::pname:compareOp, specifying the 777stencil comparison function, are: 778 779include::../api/enums/VkCompareOp.txt[] 780 781 * ename:VK_COMPARE_OP_NEVER specifies that the test never passes. 782 * ename:VK_COMPARE_OP_LESS specifies that the test passes when [eq]#R < 783 S#. 784 * ename:VK_COMPARE_OP_EQUAL specifies that the test passes when [eq]#R = 785 S#. 786 * ename:VK_COMPARE_OP_LESS_OR_EQUAL specifies that the test passes when 787 [eq]#R {leq} S#. 788 * ename:VK_COMPARE_OP_GREATER specifies that the test passes when [eq]#R > 789 S#. 790 * ename:VK_COMPARE_OP_NOT_EQUAL specifies that the test passes when [eq]#R 791 {neq} S#. 792 * ename:VK_COMPARE_OP_GREATER_OR_EQUAL specifies that the test passes when 793 [eq]#R {geq} S#. 794 * ename:VK_COMPARE_OP_ALWAYS specifies that the test always passes. 795 796-- 797 798[open,refpage='VkStencilOp',desc='Stencil comparison function',type='enums'] 799-- 800 801Possible values of the pname:failOp, pname:passOp, and pname:depthFailOp 802members of slink:VkStencilOpState, specifying what happens to the stored 803stencil value if this or certain subsequent tests fail or pass, are: 804 805include::../api/enums/VkStencilOp.txt[] 806 807 * ename:VK_STENCIL_OP_KEEP keeps the current value. 808 * ename:VK_STENCIL_OP_ZERO sets the value to 0. 809 * ename:VK_STENCIL_OP_REPLACE sets the value to pname:reference. 810 * ename:VK_STENCIL_OP_INCREMENT_AND_CLAMP increments the current value and 811 clamps to the maximum representable unsigned value. 812 * ename:VK_STENCIL_OP_DECREMENT_AND_CLAMP decrements the current value and 813 clamps to 0. 814 * ename:VK_STENCIL_OP_INVERT bitwise-inverts the current value. 815 * ename:VK_STENCIL_OP_INCREMENT_AND_WRAP increments the current value and 816 wraps to 0 when the maximum value would have been exceeded. 817 * ename:VK_STENCIL_OP_DECREMENT_AND_WRAP decrements the current value and 818 wraps to the maximum possible value when the value would go below 0. 819 820For purposes of increment and decrement, the stencil bits are considered as 821an unsigned integer. 822 823If the stencil test fails, the sample's coverage bit is cleared in the 824fragment. 825If there is no stencil framebuffer attachment, stencil modification cannot: 826occur, and it is as if the stencil tests always pass. 827 828If the stencil test passes, the pname:writeMask member of the 829slink:VkStencilOpState structures controls how the updated stencil value is 830written to the stencil framebuffer attachment. 831 832The least significant [eq]#s# bits of pname:writeMask, where [eq]#s# is the 833number of bits in the stencil framebuffer attachment, specify an integer 834mask. 835Where a [eq]#1# appears in this mask, the corresponding bit in the stencil 836value in the depth/stencil attachment is written; where a [eq]#0# appears, 837the bit is not written. 838The pname:writeMask value uses either the front-facing or back-facing state 839based on the facingness of the fragment. 840Fragments generated by front-facing primitives use the front mask and 841fragments generated by back-facing primitives use the back mask. 842 843-- 844 845 846[[fragops-depth]] 847== Depth Test 848 849The depth test conditionally disables coverage of a sample based on the 850outcome of a comparison between the fragment's depth value at the sample 851location and the sample's depth value in the depth/stencil attachment at 852location [eq]#(x~f~,y~f~)#. 853The comparison is enabled or disabled with the pname:depthTestEnable member 854of the slink:VkPipelineDepthStencilStateCreateInfo structure. 855When disabled, the depth comparison and subsequent possible updates to the 856value of the depth component of the depth/stencil attachment are bypassed 857and the fragment is passed to the next operation. 858The stencil value, however, can: be modified as indicated above as if the 859depth test passed. 860If enabled, the comparison takes place and the depth/stencil attachment 861value can: subsequently be modified. 862 863The comparison is specified with the pname:depthCompareOp member of 864slink:VkPipelineDepthStencilStateCreateInfo. 865Let [eq]#pname:z~f~# be the incoming fragment's depth value for a sample, 866and let [eq]#z~a~# be the depth/stencil attachment value in memory for that 867sample. 868The depth test passes under the following conditions: 869 870 * ename:VK_COMPARE_OP_NEVER: the test never passes. 871 * ename:VK_COMPARE_OP_LESS: the test passes when [eq]#z~f~ < z~a~#. 872 * ename:VK_COMPARE_OP_EQUAL: the test passes when [eq]#z~f~ = z~a~#. 873 * ename:VK_COMPARE_OP_LESS_OR_EQUAL: the test passes when [eq]#z~f~ {leq} 874 z~a~#. 875 * ename:VK_COMPARE_OP_GREATER: the test passes when [eq]#z~f~ > z~a~#. 876 * ename:VK_COMPARE_OP_NOT_EQUAL: the test passes when [eq]#z~f~ {neq} 877 z~a~#. 878 * ename:VK_COMPARE_OP_GREATER_OR_EQUAL: the test passes when [eq]#z~f~ 879 {geq} z~a~#. 880 * ename:VK_COMPARE_OP_ALWAYS: the test always passes. 881 882If slink:VkPipelineRasterizationStateCreateInfo::pname:depthClampEnable is 883enabled, before the incoming fragment's [eq]#pname:z~f~# is compared to 884[eq]#pname:z~a~#, [eq]#pname:z~f~# is clamped to [eq]#[min(n,f),max(n,f)]#, 885where [eq]#n# and [eq]#f# are the pname:minDepth and pname:maxDepth depth 886range values of the viewport used by this fragment, respectively. 887 888If the depth test fails, the sample's coverage bit is cleared in the 889fragment. 890The stencil value at the sample's location is updated according to the 891function currently in effect for depth test failure. 892 893[[fragops-depth-write]] 894If the depth test passes, the sample's (possibly clamped) [eq]#pname:z~f~# 895value is conditionally written to the depth framebuffer attachment based on 896the pname:depthWriteEnable member of 897slink:VkPipelineDepthStencilStateCreateInfo. 898If pname:depthWriteEnable is ename:VK_TRUE the value is written, and if it 899is ename:VK_FALSE the value is not written. 900ifdef::VK_EXT_depth_range_unrestricted[] 901If the depth framebuffer attachment is a fixed-point format and the depth 902value is outside of the `0.0` to `1.0` range the depth value is clamped 903between `0.0` and `1.0` inclusive before writing. 904endif::VK_EXT_depth_range_unrestricted[] 905The stencil value at the sample's location is updated according to the 906function currently in effect for depth test success. 907 908If there is no depth framebuffer attachment, it is as if the depth test 909always passes. 910 911 912[[fragops-samplecount]] 913== Sample Counting 914 915Occlusion queries use query pool entries to track the number of samples that 916pass all the per-fragment tests. 917The mechanism of collecting an occlusion query value is described in 918<<queries-occlusion,Occlusion Queries>>. 919 920The occlusion query sample counter increments by one for each sample with a 921coverage value of 1 in each fragment that survives all the per-fragment 922tests, including scissor, sample mask, alpha to coverage, stencil, and depth 923tests. 924 925ifdef::VK_NV_fragment_coverage_to_color[] 926 927[[fragops-coverage-to-color]] 928== Fragment Coverage To Color 929 930[open,refpage='VkPipelineCoverageToColorStateCreateInfoNV',desc='Structure specifying whether fragment coverage replaces a color',type='structs'] 931-- 932 933If the pname:pNext chain of slink:VkPipelineMultisampleStateCreateInfo 934includes a sname:VkPipelineCoverageToColorStateCreateInfoNV structure, then 935that structure controls whether the fragment coverage is substituted for a 936fragment color output and, if so, which output is replaced. 937 938The sname:VkPipelineCoverageToColorStateCreateInfoNV structure is defined 939as: 940 941include::../api/structs/VkPipelineCoverageToColorStateCreateInfoNV.txt[] 942 943 * pname:sType is the type of this structure 944 * pname:pNext is `NULL` or a pointer to an extension-specific structure 945 * pname:flags is reserved for future use. 946 * pname:coverageToColorEnable controls whether the fragment coverage value 947 replaces a fragment color output. 948 * pname:coverageToColorLocation controls which fragment shader color 949 output value is replaced. 950 951If pname:coverageToColorEnable is ename:VK_TRUE, the fragment coverage 952information is treated as a bitmask with one bit for each sample (as in the 953<<fragops-samplemask,Sample Mask>> section), and this bitmask replaces the 954first component of the color value corresponding to the fragment shader 955output location with code:Location equal to pname:coverageToColorLocation 956and code:Index equal to zero. 957If the color attachment format has fewer bits than the sample coverage, the 958low bits of the sample coverage bitmask are taken without any clamping. 959If the color attachment format has more bits than the sample coverage, the 960high bits of the sample coverage bitmask are filled with zeros. 961 962If <<primsrast-sampleshading,Sample Shading>> is in use, the coverage 963bitmask only has bits set for samples that correspond to the fragment shader 964invocation that shades those samples. 965 966This pipeline stage occurs after sample counting and before blending, and is 967always performed after fragment shading regardless of the setting of 968code:EarlyFragmentTests. 969 970If pname:coverageToColorEnable is ename:VK_FALSE, these operations are 971skipped. 972If this structure is not present, it is as if pname:coverageToColorEnable is 973ename:VK_FALSE. 974 975.Valid Usage 976**** 977 * [[VUID-VkPipelineCoverageToColorStateCreateInfoNV-coverageToColorEnable-01404]] 978 If pname:coverageToColorEnable is ename:VK_TRUE, then the render pass 979 subpass indicated by 980 slink:VkGraphicsPipelineCreateInfo::pname:renderPass and 981 slink:VkGraphicsPipelineCreateInfo::pname:subpass must: have a color 982 attachment at the location selected by pname:coverageToColorLocation, 983 with a elink:VkFormat of ename:VK_FORMAT_R8_UINT, 984 ename:VK_FORMAT_R8_SINT, ename:VK_FORMAT_R16_UINT, 985 ename:VK_FORMAT_R16_SINT, ename:VK_FORMAT_R32_UINT, or 986 ename:VK_FORMAT_R32_SINT 987**** 988 989include::../validity/structs/VkPipelineCoverageToColorStateCreateInfoNV.txt[] 990-- 991 992[open,refpage='VkPipelineCoverageToColorStateCreateFlagsNV',desc='Reserved for future use',type='enums'] 993-- 994include::../api/flags/VkPipelineCoverageToColorStateCreateFlagsNV.txt[] 995 996sname:VkPipelineCoverageToColorStateCreateFlagsNV is a bitmask type for 997setting a mask, but is currently reserved for future use. 998-- 999 1000endif::VK_NV_fragment_coverage_to_color[] 1001 1002 1003[[fragops-coverage-reduction]] 1004== Coverage Reduction 1005 1006Coverage reduction generates a _color sample mask_ from the coverage mask, 1007with one bit for each sample in the color attachment(s) for the subpass. 1008If a bit in the color sample mask is 0, then blending and writing to the 1009framebuffer are not performed for that sample. 1010 1011ifndef::VK_NV_framebuffer_mixed_samples[] 1012 1013Each color sample is associated with a unique rasterization sample, and the 1014value of the coverage mask is assigned to the color sample mask. 1015 1016endif::VK_NV_framebuffer_mixed_samples[] 1017 1018ifdef::VK_NV_framebuffer_mixed_samples[] 1019 1020If the pipeline's 1021slink:VkPipelineMultisampleStateCreateInfo::pname:rasterizationSamples is 1022greater than one and the slink:VkAttachmentDescription::pname:samples of the 1023color attachments is one, then the fragment's coverage is reduced from 1024pname:rasterizationSamples bits to a single bit, where the color sample mask 1025is 1 if any bit in the fragment's coverage is on, and 0 otherwise. 1026 1027If the pipeline's 1028slink:VkPipelineMultisampleStateCreateInfo::pname:rasterizationSamples is 1029greater than the slink:VkAttachmentDescription::pname:samples of the color 1030attachments in the subpass, then the fragment's coverage is reduced from 1031pname:rasterizationSamples bits to a color sample mask with 1032slink:VkAttachmentDescription::pname:samples bits. 1033There is an implementation-dependent association of raster samples to color 1034samples. 1035The reduced color sample mask is computed such that the bit for each color 1036sample is 1 if any of the associated bits in the fragment's coverage is on, 1037and 0 otherwise. 1038 1039 1040[[fragops-coverage-modulation]] 1041=== Coverage Modulation 1042 1043[open,refpage='VkPipelineCoverageModulationStateCreateInfoNV',desc='Structure specifying parameters controlling coverage modulation',type='structs'] 1044-- 1045 1046As part of coverage reduction, fragment color values can: also be modulated 1047(multiplied) by a value that is a function of fraction of covered 1048rasterization samples associated with that color sample. 1049 1050Pipeline state controlling coverage reduction is specified through the 1051members of the sname:VkPipelineCoverageModulationStateCreateInfoNV 1052structure. 1053 1054The sname:VkPipelineCoverageModulationStateCreateInfoNV structure is defined 1055as: 1056 1057include::../api/structs/VkPipelineCoverageModulationStateCreateInfoNV.txt[] 1058 1059 * pname:sType is the type of this structure. 1060 * pname:pNext is `NULL` or a pointer to an extension-specific structure. 1061 * pname:flags is reserved for future use. 1062 * pname:coverageModulationMode controls which color components are 1063 modulated and is of type elink:VkCoverageModulationModeNV. 1064 * pname:coverageModulationTableEnable controls whether the modulation 1065 factor is looked up from a table in pname:pCoverageModulationTable. 1066 * pname:coverageModulationTableCount is the number of elements in 1067 pname:pCoverageModulationTable. 1068 * pname:pCoverageModulationTable is a table of modulation factors 1069 containing a value for each number of covered samples. 1070 1071If pname:coverageModulationTableEnable is ename:VK_FALSE, then for each 1072color sample the associated bits of the fragment's coverage are counted and 1073divided by the number of associated bits to produce a modulation factor 1074[eq]#R# in the range [eq]#(0,1]# (a value of zero would have been killed due 1075to a color coverage of 0). 1076Specifically: 1077 1078 * [eq]#N# = value of pname:rasterizationSamples 1079 * [eq]#M# = value of slink:VkAttachmentDescription::pname:samples for any 1080 color attachments 1081 * [eq]#R = popcount(associated coverage bits) / (N / M)# 1082 1083If pname:coverageModulationTableEnable is ename:VK_TRUE, the value [eq]#R# 1084is computed using a programmable lookup table. 1085The lookup table has [eq]#N / M# elements, and the element of the table is 1086selected by: 1087 1088 * [eq]#R = pname:pCoverageModulationTable[popcount(associated coverage 1089 bits)-1]# 1090 1091Note that the table does not have an entry for [eq]#popcount(associated 1092coverage bits) = 0#, because such samples would have been killed. 1093 1094The values of pname:pCoverageModulationTable may: be rounded to an 1095implementation-dependent precision, which is at least as fine as [eq]#1 / 1096N#, and clamped to [eq]#[0,1]#. 1097 1098For each color attachment with a floating point or normalized color format, 1099each fragment output color value is replicated to [eq]#M# values which can: 1100each be modulated (multiplied) by that color sample's associated value of 1101[eq]#R#. 1102Which components are modulated is controlled by 1103pname:coverageModulationMode. 1104 1105If this structure is not present, it is as if coverageModulationMode is 1106ename:VK_COVERAGE_MODULATION_MODE_NONE_NV. 1107 1108.Valid Usage 1109**** 1110 * [[VUID-VkPipelineCoverageModulationStateCreateInfoNV-coverageModulationTableEnable-01405]] 1111 If pname:coverageModulationTableEnable is ename:VK_TRUE, 1112 pname:coverageModulationTableCount must: be equal to the number of 1113 rasterization samples divided by the number of color samples in the 1114 subpass. 1115**** 1116 1117include::../validity/structs/VkPipelineCoverageModulationStateCreateInfoNV.txt[] 1118-- 1119 1120[open,refpage='VkPipelineCoverageModulationStateCreateFlagsNV',desc='Reserved for future use',type='enums'] 1121-- 1122include::../api/flags/VkPipelineCoverageModulationStateCreateFlagsNV.txt[] 1123 1124sname:VkPipelineCoverageModulationStateCreateFlagsNV is a bitmask type for 1125setting a mask, but is currently reserved for future use. 1126-- 1127 1128[open,refpage='VkCoverageModulationModeNV',desc='Specify the discard rectangle mode',type='enums'] 1129-- 1130Possible values of 1131slink:VkPipelineCoverageModulationStateCreateInfoNV::pname:coverageModulationMode, 1132specifying which color components are modulated, are: 1133 1134include::../api/enums/VkCoverageModulationModeNV.txt[] 1135 1136 * ename:VK_COVERAGE_MODULATION_MODE_NONE_NV specifies that no components 1137 are multiplied by the modulation factor. 1138 * ename:VK_COVERAGE_MODULATION_MODE_RGB_NV specifies that the red, green, 1139 and blue components are multiplied by the modulation factor. 1140 * ename:VK_COVERAGE_MODULATION_MODE_ALPHA_NV specifies that the alpha 1141 component is multiplied by the modulation factor. 1142 * ename:VK_COVERAGE_MODULATION_MODE_RGBA_NV specifies that all components 1143 are multiplied by the modulation factor. 1144-- 1145 1146endif::VK_NV_framebuffer_mixed_samples[] 1147