xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/lavapipe/lvp_conv.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 MESA_PRIM_POINTS;
68    case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
69       return MESA_PRIM_LINES;
70    case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
71       return MESA_PRIM_LINE_STRIP;
72    case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
73       return MESA_PRIM_TRIANGLES;
74    case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
75       return MESA_PRIM_TRIANGLE_STRIP;
76    case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
77       return MESA_PRIM_TRIANGLE_FAN;
78    case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
79       return MESA_PRIM_LINES_ADJACENCY;
80    case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
81       return MESA_PRIM_LINE_STRIP_ADJACENCY;
82    case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
83       return MESA_PRIM_TRIANGLES_ADJACENCY;
84    case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
85       return MESA_PRIM_TRIANGLE_STRIP_ADJACENCY;
86    case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
87       return MESA_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_swizzle(VkComponentSwizzle swiz,enum pipe_swizzle identity)113 static inline enum pipe_swizzle vk_conv_swizzle(VkComponentSwizzle swiz,
114                                                 enum pipe_swizzle identity)
115 {
116    switch (swiz) {
117    case VK_COMPONENT_SWIZZLE_ZERO:
118       return PIPE_SWIZZLE_0;
119    case VK_COMPONENT_SWIZZLE_ONE:
120       return PIPE_SWIZZLE_1;
121    case VK_COMPONENT_SWIZZLE_R:
122       return PIPE_SWIZZLE_X;
123    case VK_COMPONENT_SWIZZLE_G:
124       return PIPE_SWIZZLE_Y;
125    case VK_COMPONENT_SWIZZLE_B:
126       return PIPE_SWIZZLE_Z;
127    case VK_COMPONENT_SWIZZLE_A:
128       return PIPE_SWIZZLE_W;
129    case VK_COMPONENT_SWIZZLE_IDENTITY:
130       return identity;
131    default:
132       unreachable("Invalid VkComponentSwizzle value");
133    }
134 }
135