1 /*
2 * Copyright © 2019 Red Hat.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #pragma once
25
vk_cull_to_pipe(uint32_t vk_cull)26 static inline unsigned vk_cull_to_pipe(uint32_t vk_cull)
27 {
28 /* these correspond */
29 return vk_cull;
30 }
31
vk_polygon_mode_to_pipe(uint32_t vk_poly_mode)32 static inline unsigned vk_polygon_mode_to_pipe(uint32_t vk_poly_mode)
33 {
34 /* these correspond */
35 return vk_poly_mode;
36 }
37
vk_conv_stencil_op(uint32_t vk_stencil_op)38 static inline unsigned vk_conv_stencil_op(uint32_t vk_stencil_op)
39 {
40 switch (vk_stencil_op) {
41 case VK_STENCIL_OP_KEEP:
42 return PIPE_STENCIL_OP_KEEP;
43 case VK_STENCIL_OP_ZERO:
44 return PIPE_STENCIL_OP_ZERO;
45 case VK_STENCIL_OP_REPLACE:
46 return PIPE_STENCIL_OP_REPLACE;
47 case VK_STENCIL_OP_INCREMENT_AND_CLAMP:
48 return PIPE_STENCIL_OP_INCR;
49 case VK_STENCIL_OP_DECREMENT_AND_CLAMP:
50 return PIPE_STENCIL_OP_DECR;
51 case VK_STENCIL_OP_INVERT:
52 return PIPE_STENCIL_OP_INVERT;
53 case VK_STENCIL_OP_INCREMENT_AND_WRAP:
54 return PIPE_STENCIL_OP_INCR_WRAP;
55 case VK_STENCIL_OP_DECREMENT_AND_WRAP:
56 return PIPE_STENCIL_OP_DECR_WRAP;
57 default:
58 assert(0);
59 return 0;
60 }
61 }
62
vk_conv_topology(VkPrimitiveTopology topology)63 static inline unsigned vk_conv_topology(VkPrimitiveTopology topology)
64 {
65 switch (topology) {
66 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
67 return PIPE_PRIM_POINTS;
68 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
69 return PIPE_PRIM_LINES;
70 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
71 return PIPE_PRIM_LINE_STRIP;
72 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
73 return PIPE_PRIM_TRIANGLES;
74 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
75 return PIPE_PRIM_TRIANGLE_STRIP;
76 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
77 return PIPE_PRIM_TRIANGLE_FAN;
78 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
79 return PIPE_PRIM_LINES_ADJACENCY;
80 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
81 return PIPE_PRIM_LINE_STRIP_ADJACENCY;
82 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
83 return PIPE_PRIM_TRIANGLES_ADJACENCY;
84 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
85 return PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY;
86 case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
87 return PIPE_PRIM_PATCHES;
88 default:
89 assert(0);
90 return 0;
91 }
92 }
93
vk_conv_wrap_mode(enum VkSamplerAddressMode addr_mode)94 static inline unsigned vk_conv_wrap_mode(enum VkSamplerAddressMode addr_mode)
95 {
96 switch (addr_mode) {
97 case VK_SAMPLER_ADDRESS_MODE_REPEAT:
98 return PIPE_TEX_WRAP_REPEAT;
99 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT:
100 return PIPE_TEX_WRAP_MIRROR_REPEAT;
101 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE:
102 return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
103 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER:
104 return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
105 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE:
106 return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
107 default:
108 assert(0);
109 return 0;
110 }
111 }
112
vk_conv_blend_factor(enum VkBlendFactor vk_factor)113 static inline unsigned vk_conv_blend_factor(enum VkBlendFactor vk_factor)
114 {
115 switch (vk_factor) {
116 case VK_BLEND_FACTOR_ZERO:
117 return PIPE_BLENDFACTOR_ZERO;
118 case VK_BLEND_FACTOR_ONE:
119 return PIPE_BLENDFACTOR_ONE;
120 case VK_BLEND_FACTOR_SRC_COLOR:
121 return PIPE_BLENDFACTOR_SRC_COLOR;
122 case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
123 return PIPE_BLENDFACTOR_INV_SRC_COLOR;
124 case VK_BLEND_FACTOR_DST_COLOR:
125 return PIPE_BLENDFACTOR_DST_COLOR;
126 case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
127 return PIPE_BLENDFACTOR_INV_DST_COLOR;
128 case VK_BLEND_FACTOR_SRC_ALPHA:
129 return PIPE_BLENDFACTOR_SRC_ALPHA;
130 case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
131 return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
132 case VK_BLEND_FACTOR_DST_ALPHA:
133 return PIPE_BLENDFACTOR_DST_ALPHA;
134 case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
135 return PIPE_BLENDFACTOR_INV_DST_ALPHA;
136 case VK_BLEND_FACTOR_CONSTANT_COLOR:
137 return PIPE_BLENDFACTOR_CONST_COLOR;
138 case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
139 return PIPE_BLENDFACTOR_INV_CONST_COLOR;
140 case VK_BLEND_FACTOR_CONSTANT_ALPHA:
141 return PIPE_BLENDFACTOR_CONST_ALPHA;
142 case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
143 return PIPE_BLENDFACTOR_INV_CONST_ALPHA;
144 case VK_BLEND_FACTOR_SRC1_COLOR:
145 return PIPE_BLENDFACTOR_SRC1_COLOR;
146 case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
147 return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
148 case VK_BLEND_FACTOR_SRC1_ALPHA:
149 return PIPE_BLENDFACTOR_SRC1_ALPHA;
150 case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
151 return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
152 case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE:
153 return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
154 default:
155 assert(0);
156 return 0;
157 }
158 }
159
vk_conv_blend_func(enum VkBlendOp op)160 static inline unsigned vk_conv_blend_func(enum VkBlendOp op)
161 {
162 switch (op) {
163 case VK_BLEND_OP_ADD:
164 return PIPE_BLEND_ADD;
165 case VK_BLEND_OP_SUBTRACT:
166 return PIPE_BLEND_SUBTRACT;
167 case VK_BLEND_OP_REVERSE_SUBTRACT:
168 return PIPE_BLEND_REVERSE_SUBTRACT;
169 case VK_BLEND_OP_MIN:
170 return PIPE_BLEND_MIN;
171 case VK_BLEND_OP_MAX:
172 return PIPE_BLEND_MAX;
173 default:
174 assert(0);
175 return 0;
176 }
177 }
178
vk_conv_swizzle(VkComponentSwizzle swiz)179 static inline enum pipe_swizzle vk_conv_swizzle(VkComponentSwizzle swiz)
180 {
181 switch (swiz) {
182 case VK_COMPONENT_SWIZZLE_ZERO:
183 return PIPE_SWIZZLE_0;
184 case VK_COMPONENT_SWIZZLE_ONE:
185 return PIPE_SWIZZLE_1;
186 case VK_COMPONENT_SWIZZLE_R:
187 return PIPE_SWIZZLE_X;
188 case VK_COMPONENT_SWIZZLE_G:
189 return PIPE_SWIZZLE_Y;
190 case VK_COMPONENT_SWIZZLE_B:
191 return PIPE_SWIZZLE_Z;
192 case VK_COMPONENT_SWIZZLE_A:
193 return PIPE_SWIZZLE_W;
194 case VK_COMPONENT_SWIZZLE_IDENTITY:
195 default:
196 return PIPE_SWIZZLE_NONE;
197 }
198 }
199