1 /*
2 * Copyright © Microsoft Corporation
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 #include "dxil_enums.h"
25
26 #include "nir.h"
27 #include "nir_types.h"
28
29 #include "util/u_debug.h"
30
dxil_get_prog_sig_comp_type(const struct glsl_type * type)31 enum dxil_prog_sig_comp_type dxil_get_prog_sig_comp_type(const struct glsl_type *type)
32 {
33 type = glsl_without_array(type);
34
35 switch (glsl_get_base_type(type)) {
36 case GLSL_TYPE_UINT: return DXIL_PROG_SIG_COMP_TYPE_UINT32;
37 case GLSL_TYPE_INT: return DXIL_PROG_SIG_COMP_TYPE_SINT32;
38 case GLSL_TYPE_FLOAT: return DXIL_PROG_SIG_COMP_TYPE_FLOAT32;
39 case GLSL_TYPE_FLOAT16: return DXIL_PROG_SIG_COMP_TYPE_FLOAT16;
40 case GLSL_TYPE_DOUBLE: return DXIL_PROG_SIG_COMP_TYPE_FLOAT64;
41 case GLSL_TYPE_UINT16: return DXIL_PROG_SIG_COMP_TYPE_UINT16;
42 case GLSL_TYPE_INT16: return DXIL_PROG_SIG_COMP_TYPE_SINT16;
43 case GLSL_TYPE_UINT64: return DXIL_PROG_SIG_COMP_TYPE_UINT64;
44 case GLSL_TYPE_INT64: return DXIL_PROG_SIG_COMP_TYPE_SINT64;
45 case GLSL_TYPE_BOOL: return DXIL_PROG_SIG_COMP_TYPE_UINT32;
46 case GLSL_TYPE_STRUCT: return DXIL_PROG_SIG_COMP_TYPE_UNKNOWN;
47 default:
48 debug_printf("unexpected type: %s\n", glsl_get_type_name(type));
49 return DXIL_PROG_SIG_COMP_TYPE_UNKNOWN;
50 }
51 }
52
dxil_get_comp_type(const struct glsl_type * type)53 enum dxil_component_type dxil_get_comp_type(const struct glsl_type *type)
54 {
55 type = glsl_without_array(type);
56
57 enum glsl_base_type base_type = glsl_get_base_type(type);
58 if (glsl_type_is_texture(type) || glsl_type_is_image(type))
59 base_type = glsl_get_sampler_result_type(type);
60 switch (base_type) {
61 case GLSL_TYPE_UINT: return DXIL_COMP_TYPE_U32;
62 case GLSL_TYPE_INT: return DXIL_COMP_TYPE_I32;
63 case GLSL_TYPE_FLOAT: return DXIL_COMP_TYPE_F32;
64 case GLSL_TYPE_FLOAT16: return DXIL_COMP_TYPE_F16;
65 case GLSL_TYPE_DOUBLE: return DXIL_COMP_TYPE_F64;
66 case GLSL_TYPE_UINT16: return DXIL_COMP_TYPE_U16;
67 case GLSL_TYPE_INT16: return DXIL_COMP_TYPE_I16;
68 case GLSL_TYPE_UINT64: return DXIL_COMP_TYPE_U64;
69 case GLSL_TYPE_INT64: return DXIL_COMP_TYPE_I64;
70 case GLSL_TYPE_BOOL: return DXIL_COMP_TYPE_I1;
71
72 default:
73 debug_printf("type: %s\n", glsl_get_type_name(type));
74 unreachable("unexpected glsl type");
75 }
76 }
77
dxil_get_resource_kind(const struct glsl_type * type)78 enum dxil_resource_kind dxil_get_resource_kind(const struct glsl_type *type)
79 {
80 type = glsl_without_array(type);
81
82 /* This looks weird, we strip the arrays but then we still test whether it's
83 * an array, key is the first refers to sampler[] and the second to samplerArray */
84 bool is_array = glsl_sampler_type_is_array(type);
85
86 if (glsl_type_is_texture(type) || glsl_type_is_image(type)) {
87 switch (glsl_get_sampler_dim(type)) {
88 case GLSL_SAMPLER_DIM_1D:
89 return is_array ? DXIL_RESOURCE_KIND_TEXTURE1D_ARRAY
90 : DXIL_RESOURCE_KIND_TEXTURE1D;
91 case GLSL_SAMPLER_DIM_2D:
92 case GLSL_SAMPLER_DIM_EXTERNAL:
93 case GLSL_SAMPLER_DIM_SUBPASS:
94 return is_array ? DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY
95 : DXIL_RESOURCE_KIND_TEXTURE2D;
96 case GLSL_SAMPLER_DIM_3D:
97 return DXIL_RESOURCE_KIND_TEXTURE3D;
98 case GLSL_SAMPLER_DIM_CUBE:
99 return is_array ? DXIL_RESOURCE_KIND_TEXTURECUBE_ARRAY
100 : DXIL_RESOURCE_KIND_TEXTURECUBE;
101 case GLSL_SAMPLER_DIM_RECT:
102 return DXIL_RESOURCE_KIND_TEXTURE2D;
103 case GLSL_SAMPLER_DIM_BUF:
104 return DXIL_RESOURCE_KIND_TYPED_BUFFER;
105 case GLSL_SAMPLER_DIM_MS:
106 case GLSL_SAMPLER_DIM_SUBPASS_MS:
107 return is_array ? DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY
108 : DXIL_RESOURCE_KIND_TEXTURE2DMS;
109
110 default:
111 debug_printf("type: %s\n", glsl_get_type_name(type));
112 unreachable("unexpected sampler type");
113 }
114 }
115
116 debug_printf("type: %s\n", glsl_get_type_name(type));
117 unreachable("unexpected glsl type");
118 }
119
dxil_get_input_primitive(enum shader_prim primitive)120 enum dxil_input_primitive dxil_get_input_primitive(enum shader_prim primitive)
121 {
122 switch (primitive) {
123 case SHADER_PRIM_POINTS:
124 return DXIL_INPUT_PRIMITIVE_POINT;
125 case SHADER_PRIM_LINES:
126 return DXIL_INPUT_PRIMITIVE_LINE;
127 case SHADER_PRIM_LINES_ADJACENCY:
128 return DXIL_INPUT_PRIMITIVE_LINES_ADJENCY;
129 case SHADER_PRIM_TRIANGLES:
130 return DXIL_INPUT_PRIMITIVE_TRIANGLE;
131 case SHADER_PRIM_TRIANGLES_ADJACENCY:
132 return DXIL_INPUT_PRIMITIVE_TRIANGLES_ADJENCY;
133 default:
134 unreachable("unhandled primitive topology");
135 }
136 }
137
dxil_get_primitive_topology(enum shader_prim topology)138 enum dxil_primitive_topology dxil_get_primitive_topology(enum shader_prim topology)
139 {
140 switch (topology) {
141 case SHADER_PRIM_POINTS:
142 return DXIL_PRIMITIVE_TOPOLOGY_POINT_LIST;
143 case SHADER_PRIM_LINES:
144 return DXIL_PRIMITIVE_TOPOLOGY_LINE_LIST;
145 case SHADER_PRIM_LINE_STRIP:
146 return DXIL_PRIMITIVE_TOPOLOGY_LINE_STRIP;
147 case SHADER_PRIM_TRIANGLE_STRIP:
148 return DXIL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
149 default:
150 unreachable("unhandled primitive topology");
151 }
152 }
153
154 static const char *overload_str[DXIL_NUM_OVERLOADS] = {
155 [DXIL_NONE] = "",
156 [DXIL_I16] = "i16",
157 [DXIL_I32] = "i32",
158 [DXIL_I64] = "i64",
159 [DXIL_F16] = "f16",
160 [DXIL_F32] = "f32",
161 [DXIL_F64] = "f64",
162 };
163
dxil_overload_suffix(enum overload_type overload)164 const char *dxil_overload_suffix( enum overload_type overload)
165 {
166 assert(overload < DXIL_NUM_OVERLOADS);
167 return overload_str[overload];
168 }
169