1 /*
2  * Copyright 2023 Valve Corporation
3  * Copyright 2021 Collabora Ltd.
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #include "vk_blend.h"
8 #include "util/macros.h"
9 
10 enum pipe_logicop
vk_logic_op_to_pipe(VkLogicOp in)11 vk_logic_op_to_pipe(VkLogicOp in)
12 {
13    switch (in) {
14    case VK_LOGIC_OP_CLEAR:
15       return PIPE_LOGICOP_CLEAR;
16    case VK_LOGIC_OP_AND:
17       return PIPE_LOGICOP_AND;
18    case VK_LOGIC_OP_AND_REVERSE:
19       return PIPE_LOGICOP_AND_REVERSE;
20    case VK_LOGIC_OP_COPY:
21       return PIPE_LOGICOP_COPY;
22    case VK_LOGIC_OP_AND_INVERTED:
23       return PIPE_LOGICOP_AND_INVERTED;
24    case VK_LOGIC_OP_NO_OP:
25       return PIPE_LOGICOP_NOOP;
26    case VK_LOGIC_OP_XOR:
27       return PIPE_LOGICOP_XOR;
28    case VK_LOGIC_OP_OR:
29       return PIPE_LOGICOP_OR;
30    case VK_LOGIC_OP_NOR:
31       return PIPE_LOGICOP_NOR;
32    case VK_LOGIC_OP_EQUIVALENT:
33       return PIPE_LOGICOP_EQUIV;
34    case VK_LOGIC_OP_INVERT:
35       return PIPE_LOGICOP_INVERT;
36    case VK_LOGIC_OP_OR_REVERSE:
37       return PIPE_LOGICOP_OR_REVERSE;
38    case VK_LOGIC_OP_COPY_INVERTED:
39       return PIPE_LOGICOP_COPY_INVERTED;
40    case VK_LOGIC_OP_OR_INVERTED:
41       return PIPE_LOGICOP_OR_INVERTED;
42    case VK_LOGIC_OP_NAND:
43       return PIPE_LOGICOP_NAND;
44    case VK_LOGIC_OP_SET:
45       return PIPE_LOGICOP_SET;
46    default:
47       unreachable("Invalid logicop");
48    }
49 }
50 
51 enum pipe_blend_func
vk_blend_op_to_pipe(VkBlendOp in)52 vk_blend_op_to_pipe(VkBlendOp in)
53 {
54    switch (in) {
55    case VK_BLEND_OP_ADD:
56       return PIPE_BLEND_ADD;
57    case VK_BLEND_OP_SUBTRACT:
58       return PIPE_BLEND_SUBTRACT;
59    case VK_BLEND_OP_REVERSE_SUBTRACT:
60       return PIPE_BLEND_REVERSE_SUBTRACT;
61    case VK_BLEND_OP_MIN:
62       return PIPE_BLEND_MIN;
63    case VK_BLEND_OP_MAX:
64       return PIPE_BLEND_MAX;
65    default:
66       unreachable("Invalid blend op");
67    }
68 }
69 
70 enum pipe_blendfactor
vk_blend_factor_to_pipe(enum VkBlendFactor vk_factor)71 vk_blend_factor_to_pipe(enum VkBlendFactor vk_factor)
72 {
73    switch (vk_factor) {
74    case VK_BLEND_FACTOR_ZERO:
75       return PIPE_BLENDFACTOR_ZERO;
76    case VK_BLEND_FACTOR_ONE:
77       return PIPE_BLENDFACTOR_ONE;
78    case VK_BLEND_FACTOR_SRC_COLOR:
79       return PIPE_BLENDFACTOR_SRC_COLOR;
80    case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
81       return PIPE_BLENDFACTOR_INV_SRC_COLOR;
82    case VK_BLEND_FACTOR_DST_COLOR:
83       return PIPE_BLENDFACTOR_DST_COLOR;
84    case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
85       return PIPE_BLENDFACTOR_INV_DST_COLOR;
86    case VK_BLEND_FACTOR_SRC_ALPHA:
87       return PIPE_BLENDFACTOR_SRC_ALPHA;
88    case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
89       return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
90    case VK_BLEND_FACTOR_DST_ALPHA:
91       return PIPE_BLENDFACTOR_DST_ALPHA;
92    case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
93       return PIPE_BLENDFACTOR_INV_DST_ALPHA;
94    case VK_BLEND_FACTOR_CONSTANT_COLOR:
95       return PIPE_BLENDFACTOR_CONST_COLOR;
96    case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
97       return PIPE_BLENDFACTOR_INV_CONST_COLOR;
98    case VK_BLEND_FACTOR_CONSTANT_ALPHA:
99       return PIPE_BLENDFACTOR_CONST_ALPHA;
100    case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
101       return PIPE_BLENDFACTOR_INV_CONST_ALPHA;
102    case VK_BLEND_FACTOR_SRC1_COLOR:
103       return PIPE_BLENDFACTOR_SRC1_COLOR;
104    case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
105       return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
106    case VK_BLEND_FACTOR_SRC1_ALPHA:
107       return PIPE_BLENDFACTOR_SRC1_ALPHA;
108    case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
109       return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
110    case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE:
111       return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
112    default:
113       unreachable("Invalid blend factor");
114    }
115 }
116