26.2. Logical Operations

The application can enable a logical operation between the fragment’s color values and the existing value in the framebuffer attachment. This logical operation is applied prior to updating the framebuffer attachment. Logical operations are applied only for signed and unsigned integer and normalized integer framebuffers. Logical operations are not applied to floating-point or sRGB format color attachments.

Logical operations are controlled by the logicOpEnable and logicOp members of VkPipelineColorBlendStateCreateInfo. If logicOpEnable is VK_TRUE, then a logical operation selected by logicOp is applied between each color attachment and the fragment’s corresponding output value, and blending of all attachments is treated as if it were disabled. Any attachments using color formats for which logical operations are not supported simply pass through the color values unmodified. The logical operation is applied independently for each of the red, green, blue, and alpha components. The logicOp is selected from the following operations:

 

typedef enum VkLogicOp {
    VK_LOGIC_OP_CLEAR = 0,
    VK_LOGIC_OP_AND = 1,
    VK_LOGIC_OP_AND_REVERSE = 2,
    VK_LOGIC_OP_COPY = 3,
    VK_LOGIC_OP_AND_INVERTED = 4,
    VK_LOGIC_OP_NO_OP = 5,
    VK_LOGIC_OP_XOR = 6,
    VK_LOGIC_OP_OR = 7,
    VK_LOGIC_OP_NOR = 8,
    VK_LOGIC_OP_EQUIVALENT = 9,
    VK_LOGIC_OP_INVERT = 10,
    VK_LOGIC_OP_OR_REVERSE = 11,
    VK_LOGIC_OP_COPY_INVERTED = 12,
    VK_LOGIC_OP_OR_INVERTED = 13,
    VK_LOGIC_OP_NAND = 14,
    VK_LOGIC_OP_SET = 15,
} VkLogicOp;

The logical operations supported by Vulkan are summarized in the following table in which

Table 26.3. Logical Operations

Mode Operation

VK_LOGIC_OP_CLEAR

$0$

VK_LOGIC_OP_AND

$s \land d$

VK_LOGIC_OP_AND_REVERSE

$s \land \lnot d$

VK_LOGIC_OP_COPY

$s$

VK_LOGIC_OP_AND_INVERTED

$\lnot s \land d$

VK_LOGIC_OP_NO_OP

$d$

VK_LOGIC_OP_XOR

$s \oplus d$

VK_LOGIC_OP_OR

$s \lor d$

VK_LOGIC_OP_NOR

$\lnot (s \lor d)$

VK_LOGIC_OP_EQUIVALENT

$\lnot (s \oplus d)$

VK_LOGIC_OP_INVERT

$\lnot d$

VK_LOGIC_OP_OR_REVERSE

$s \lor \lnot d$

VK_LOGIC_OP_COPY_INVERTED

$\lnot s$

VK_LOGIC_OP_OR_INVERTED

$\lnot s \lor d$

VK_LOGIC_OP_NAND

$\lnot (s \land d)$

VK_LOGIC_OP_SET

all 1s


The result of the logical operation is then written to the color attachment as controlled by the component write mask, described in Blend Operations.