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

- ¬ is bitwise invert,
- ∧ is bitwise and,
- ∨ is bitwise or,
- ⊕ is bitwise exclusive or,
- s is the fragment’s Rs0, Gs0, Bs0 or As0 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 ∧ d
`VK_LOGIC_OP_AND_REVERSE` | s ∧ ¬ d
`VK_LOGIC_OP_COPY` | s
`VK_LOGIC_OP_AND_INVERTED` | ¬ s ∧ d
`VK_LOGIC_OP_NO_OP` | d
`VK_LOGIC_OP_XOR` | s ⊕ d
`VK_LOGIC_OP_OR` | s ∨ d
`VK_LOGIC_OP_NOR` | ¬ (s ∨ d)
`VK_LOGIC_OP_EQUIVALENT` | ¬ (s ⊕ d)
`VK_LOGIC_OP_INVERT` | ¬ d
`VK_LOGIC_OP_OR_REVERSE` | s ∨ ¬ d
`VK_LOGIC_OP_COPY_INVERTED` | ¬ s
`VK_LOGIC_OP_OR_INVERTED` | ¬ s ∨ d
`VK_LOGIC_OP_NAND` | ¬ (s ∧ 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.