Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/microsoft/compiler/dxil_enums.c
4564 views
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
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
default:
47
debug_printf("unexpected type: %s\n", glsl_get_type_name(type));
48
return DXIL_PROG_SIG_COMP_TYPE_UNKNOWN;
49
}
50
}
51
52
enum dxil_component_type dxil_get_comp_type(const struct glsl_type *type)
53
{
54
type = glsl_without_array(type);
55
56
enum glsl_base_type base_type = glsl_get_base_type(type);
57
if (glsl_type_is_sampler(type) || glsl_type_is_image(type))
58
base_type = glsl_get_sampler_result_type(type);
59
switch (base_type) {
60
case GLSL_TYPE_UINT: return DXIL_COMP_TYPE_U32;
61
case GLSL_TYPE_INT: return DXIL_COMP_TYPE_I32;
62
case GLSL_TYPE_FLOAT: return DXIL_COMP_TYPE_F32;
63
case GLSL_TYPE_FLOAT16: return DXIL_COMP_TYPE_F16;
64
case GLSL_TYPE_DOUBLE: return DXIL_COMP_TYPE_F64;
65
case GLSL_TYPE_UINT16: return DXIL_COMP_TYPE_U16;
66
case GLSL_TYPE_INT16: return DXIL_COMP_TYPE_I16;
67
case GLSL_TYPE_UINT64: return DXIL_COMP_TYPE_U64;
68
case GLSL_TYPE_INT64: return DXIL_COMP_TYPE_I64;
69
case GLSL_TYPE_BOOL: return DXIL_COMP_TYPE_I1;
70
71
default:
72
debug_printf("type: %s\n", glsl_get_type_name(type));
73
unreachable("unexpected glsl type");
74
}
75
}
76
77
enum dxil_resource_kind dxil_get_resource_kind(const struct glsl_type *type)
78
{
79
type = glsl_without_array(type);
80
81
/* This looks weird, we strip the arrays but then we still test whether it's
82
* an array, key is the first refers to sampler[] and the second to samplerArray */
83
bool is_array = glsl_sampler_type_is_array(type);
84
85
if (glsl_type_is_sampler(type) || glsl_type_is_image(type)) {
86
switch (glsl_get_sampler_dim(type)) {
87
case GLSL_SAMPLER_DIM_1D:
88
return is_array ? DXIL_RESOURCE_KIND_TEXTURE1D_ARRAY
89
: DXIL_RESOURCE_KIND_TEXTURE1D;
90
case GLSL_SAMPLER_DIM_2D:
91
return is_array ? DXIL_RESOURCE_KIND_TEXTURE2D_ARRAY
92
: DXIL_RESOURCE_KIND_TEXTURE2D;
93
case GLSL_SAMPLER_DIM_3D:
94
return DXIL_RESOURCE_KIND_TEXTURE3D;
95
case GLSL_SAMPLER_DIM_CUBE:
96
return is_array ? DXIL_RESOURCE_KIND_TEXTURECUBE_ARRAY
97
: DXIL_RESOURCE_KIND_TEXTURECUBE;
98
case GLSL_SAMPLER_DIM_RECT:
99
return DXIL_RESOURCE_KIND_TEXTURE2D;
100
case GLSL_SAMPLER_DIM_BUF:
101
return DXIL_RESOURCE_KIND_TYPED_BUFFER;
102
case GLSL_SAMPLER_DIM_MS:
103
return is_array ? DXIL_RESOURCE_KIND_TEXTURE2DMS_ARRAY
104
: DXIL_RESOURCE_KIND_TEXTURE2DMS;
105
106
default:
107
debug_printf("type: %s\n", glsl_get_type_name(type));
108
unreachable("unexpected sampler type");
109
}
110
}
111
112
debug_printf("type: %s\n", glsl_get_type_name(type));
113
unreachable("unexpected glsl type");
114
}
115
116
enum dxil_input_primitive dxil_get_input_primitive(unsigned primitive)
117
{
118
switch (primitive) {
119
case GL_POINTS:
120
return DXIL_INPUT_PRIMITIVE_POINT;
121
case GL_LINES:
122
return DXIL_INPUT_PRIMITIVE_LINE;
123
case GL_LINES_ADJACENCY:
124
return DXIL_INPUT_PRIMITIVE_LINES_ADJENCY;
125
case GL_TRIANGLES:
126
return DXIL_INPUT_PRIMITIVE_TRIANGLE;
127
case GL_TRIANGLES_ADJACENCY:
128
return DXIL_INPUT_PRIMITIVE_TRIANGLES_ADJENCY;
129
default:
130
unreachable("unhandled primitive topology");
131
}
132
}
133
134
enum dxil_primitive_topology dxil_get_primitive_topology(unsigned topology)
135
{
136
switch (topology) {
137
case GL_POINTS:
138
return DXIL_PRIMITIVE_TOPOLOGY_POINT_LIST;
139
case GL_LINES:
140
return DXIL_PRIMITIVE_TOPOLOGY_LINE_LIST;
141
case GL_LINE_STRIP:
142
return DXIL_PRIMITIVE_TOPOLOGY_LINE_STRIP;
143
case GL_TRIANGLE_STRIP:
144
return DXIL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
145
default:
146
unreachable("unhandled primitive topology");
147
}
148
}
149
150
static const char *overload_str[DXIL_NUM_OVERLOADS] = {
151
[DXIL_NONE] = "",
152
[DXIL_I16] = "i16",
153
[DXIL_I32] = "i32",
154
[DXIL_I64] = "i64",
155
[DXIL_F16] = "f16",
156
[DXIL_F32] = "f32",
157
[DXIL_F64] = "f64",
158
};
159
160
const char *dxil_overload_suffix( enum overload_type overload)
161
{
162
assert(overload < DXIL_NUM_OVERLOADS);
163
return overload_str[overload];
164
}
165
166