D.3. Invariance Rules

For a given instantiation of an Vulkan rendering context:

Rule 1For any given Vulkan and framebuffer state vector, and for any
given Vulkan command, the resulting Vulkan and framebuffer state must
be identical each time the command is executed on that initial Vulkan and
framebuffer state.

Rule 2Changes to the following state values have no side effects (the
use of any other state value is not affected by the change):

Required:

Framebuffer contents (all bitplanes)

The color buffers enabled for writing

Scissor parameters (other than enable)

Writemasks (color, depth, stencil)

Clear values (color, depth, stencil)

Strongly suggested:

Stencil Parameters (other than enable)

Depth test parameters (other than enable)

Blend parameters (other than enable)

Logical operation parameters (other than enable)

Pixel storage state

Corollary 1Fragment generation is invariant with respect to the state
values listed in Rule 2.

Rule 3The arithmetic of each per-fragment operation is invariant except
with respect to parameters that directly control it.

Corollary 2Images rendered into different color buffers sharing the same
framebuffer, either simultaneously or separately using the same command
sequence, are pixel identical.

Rule 4The same vertex or fragment shader will produce the same result
when run multiple times with the same input. The wording “the same shader”
means a program object that is populated with the same SPIR-V binary, which
is used to create pipelines, possibly multiple times, and which program
object is then executed using the same Vulkan state vector. Invariance is
relaxed for shaders with side effects, such as performing stores or
atomics.

Rule 5All fragment shaders that either conditionally or unconditionally
assignFragCoord.z toFragDepthare depth-invariant with
respect to each other, for those fragments where the assignment toFragDepthactually is done.

If a sequence of Vulkan commands specifies primitives to be rendered with
shaders containing side effects (image and buffer variable stores and atomic
operations), invariance rules are relaxed. In particular, rule 1, corollary
2, and rule 4 do not apply in the presence of shader side effects.

The following weaker versions of rules 1 and 4 apply to Vulkan commands
involving shader side effects:

Rule 6For any given Vulkan and framebuffer state vector, and for any
given Vulkan command, the contents of any framebuffer state not directly
or indirectly affected by results of shader image or buffer variable stores
or atomic operations must be identical each time the command is executed on
that initial Vulkan and framebuffer state.

Rule 7The same vertex or fragment shader will produce the same result
when run multiple times with the same input as long as:

shader invocations do not use image atomic operations;

no framebuffer memory is written to more than once by image stores,
unless all such stores write the same value; and

no shader invocation, or other operation performed to process the
sequence of commands, reads memory written to by an image store.

When any sequence of Vulkan commands triggers shader invocations that
perform image stores or atomic operations, and subsequent Vulkan commands
read the memory written by those shader invocations, these operations must
be explicitly synchronized.