1/*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24#ifndef PVR_CSB_ENUM_HELPERS_H
25#define PVR_CSB_ENUM_HELPERS_H
26
27#include <stdint.h>
28#include <vulkan/vulkan_core.h>
29
30#include "pvr_csb.h"
31#include "rogue/rogue.h"
32#include "util/macros.h"
33
34/******************************************************************************
35   CR
36 ******************************************************************************/
37
38/* TODO: Use VkSampleCountFlagBits as param type? */
39/* clang-format off */
40static inline enum PVRX(CR_ISP_AA_MODE_TYPE)
41pvr_cr_isp_aa_mode_type(uint32_t samples)
42/* clang-format on */
43{
44   switch (samples) {
45   case 1:
46      return PVRX(CR_ISP_AA_MODE_TYPE_AA_NONE);
47   case 2:
48      return PVRX(CR_ISP_AA_MODE_TYPE_AA_2X);
49   case 4:
50      return PVRX(CR_ISP_AA_MODE_TYPE_AA_4X);
51   case 8:
52      return PVRX(CR_ISP_AA_MODE_TYPE_AA_8X);
53   default:
54      unreachable("Unsupported number of samples");
55   }
56}
57
58/******************************************************************************
59   PDS
60 ******************************************************************************/
61
62/* clang-format off */
63static inline enum PVRX(PDSINST_DOUTU_SAMPLE_RATE)
64pvr_pdsinst_doutu_sample_rate_from_rogue(enum rogue_msaa_mode msaa_mode)
65/* clang-format on */
66{
67   switch (msaa_mode) {
68   case ROGUE_MSAA_MODE_PIXEL:
69      return PVRX(PDSINST_DOUTU_SAMPLE_RATE_INSTANCE);
70   case ROGUE_MSAA_MODE_SELECTIVE:
71      return PVRX(PDSINST_DOUTU_SAMPLE_RATE_SELECTIVE);
72   case ROGUE_MSAA_MODE_FULL:
73      return PVRX(PDSINST_DOUTU_SAMPLE_RATE_FULL);
74   default:
75      unreachable("Undefined MSAA mode.");
76   }
77}
78
79/******************************************************************************
80   TA
81 ******************************************************************************/
82
83static inline enum PVRX(TA_CMPMODE) pvr_ta_cmpmode(VkCompareOp op)
84{
85   /* enum values are identical, so we can just cast the input directly. */
86   return (enum PVRX(TA_CMPMODE))op;
87}
88
89static inline enum PVRX(TA_ISPB_STENCILOP) pvr_ta_stencilop(VkStencilOp op)
90{
91   /* enum values are identical, so we can just cast the input directly. */
92   return (enum PVRX(TA_ISPB_STENCILOP))op;
93}
94
95/* clang-format off */
96static inline enum PVRX(TA_OBJTYPE)
97pvr_ta_objtype(VkPrimitiveTopology topology)
98/* clang-format on */
99{
100   switch (topology) {
101   case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
102      return PVRX(TA_OBJTYPE_SPRITE_01UV);
103
104   case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
105   case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
106   case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
107   case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
108      return PVRX(TA_OBJTYPE_LINE);
109
110   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
111   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
112   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
113   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
114   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
115      return PVRX(TA_OBJTYPE_TRIANGLE);
116
117   default:
118      unreachable("Invalid topology.");
119      return 0;
120   }
121}
122
123/******************************************************************************
124   TEXSTATE
125 ******************************************************************************/
126
127static inline enum PVRX(TEXSTATE_CMP_MODE) pvr_texstate_cmpmode(VkCompareOp op)
128{
129   /* enum values are identical, so we can just cast the input directly. */
130   return (enum PVRX(TEXSTATE_CMP_MODE))op;
131}
132
133#endif /* PVR_CSB_ENUM_HELPERS_H */
134