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