## 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

• $\lnot$ is bitwise invert,
• $\land$ is bitwise and,
• $\lor$ is bitwise or,
• $\oplus$ is bitwise exclusive or,
• $s$ is the fragment’s $R_{s0}, G_{s0}, B_{s0}$ or $A_{s0}$ component value for the fragment output corresponding to the color attachment being updated, and
• $d$ is the color attachment’s $R, G, B$ or $A$ component value:

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.