1 /*
2 * Copyright 2017 Advanced Micro Devices, Inc.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "tgsi/tgsi_from_mesa.h"
25
26 #include "pipe/p_compiler.h"
27
28 /**
29 * Determine the semantic index that is used when the given varying is mapped
30 * to TGSI_SEMANTIC_GENERIC.
31 */
32 unsigned
tgsi_get_generic_gl_varying_index(gl_varying_slot attr,bool needs_texcoord_semantic)33 tgsi_get_generic_gl_varying_index(gl_varying_slot attr,
34 bool needs_texcoord_semantic)
35 {
36 if (attr >= VARYING_SLOT_VAR0) {
37 if (needs_texcoord_semantic)
38 return attr - VARYING_SLOT_VAR0;
39 else
40 return 9 + (attr - VARYING_SLOT_VAR0);
41 }
42 if (attr == VARYING_SLOT_PNTC) {
43 assert(!needs_texcoord_semantic);
44 return 8;
45 }
46 if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
47 assert(!needs_texcoord_semantic);
48 return attr - VARYING_SLOT_TEX0;
49 }
50
51 assert(0);
52 return 0;
53 }
54
55 /**
56 * Determine the semantic name and index used for the given varying.
57 */
58 void
tgsi_get_gl_varying_semantic(gl_varying_slot attr,bool needs_texcoord_semantic,unsigned * semantic_name,unsigned * semantic_index)59 tgsi_get_gl_varying_semantic(gl_varying_slot attr,
60 bool needs_texcoord_semantic,
61 unsigned *semantic_name,
62 unsigned *semantic_index)
63 {
64 switch (attr) {
65 case VARYING_SLOT_PRIMITIVE_ID:
66 *semantic_name = TGSI_SEMANTIC_PRIMID;
67 *semantic_index = 0;
68 break;
69 case VARYING_SLOT_POS:
70 *semantic_name = TGSI_SEMANTIC_POSITION;
71 *semantic_index = 0;
72 break;
73 case VARYING_SLOT_COL0:
74 *semantic_name = TGSI_SEMANTIC_COLOR;
75 *semantic_index = 0;
76 break;
77 case VARYING_SLOT_COL1:
78 *semantic_name = TGSI_SEMANTIC_COLOR;
79 *semantic_index = 1;
80 break;
81 case VARYING_SLOT_BFC0:
82 *semantic_name = TGSI_SEMANTIC_BCOLOR;
83 *semantic_index = 0;
84 break;
85 case VARYING_SLOT_BFC1:
86 *semantic_name = TGSI_SEMANTIC_BCOLOR;
87 *semantic_index = 1;
88 break;
89 case VARYING_SLOT_FOGC:
90 *semantic_name = TGSI_SEMANTIC_FOG;
91 *semantic_index = 0;
92 break;
93 case VARYING_SLOT_PSIZ:
94 *semantic_name = TGSI_SEMANTIC_PSIZE;
95 *semantic_index = 0;
96 break;
97 case VARYING_SLOT_CLIP_DIST0:
98 *semantic_name = TGSI_SEMANTIC_CLIPDIST;
99 *semantic_index = 0;
100 break;
101 case VARYING_SLOT_CLIP_DIST1:
102 *semantic_name = TGSI_SEMANTIC_CLIPDIST;
103 *semantic_index = 1;
104 break;
105 case VARYING_SLOT_CULL_DIST0:
106 case VARYING_SLOT_CULL_DIST1:
107 /* these should have been lowered by GLSL */
108 assert(0);
109 break;
110 case VARYING_SLOT_EDGE:
111 *semantic_name = TGSI_SEMANTIC_EDGEFLAG;
112 *semantic_index = 0;
113 break;
114 case VARYING_SLOT_CLIP_VERTEX:
115 *semantic_name = TGSI_SEMANTIC_CLIPVERTEX;
116 *semantic_index = 0;
117 break;
118 case VARYING_SLOT_LAYER:
119 *semantic_name = TGSI_SEMANTIC_LAYER;
120 *semantic_index = 0;
121 break;
122 case VARYING_SLOT_VIEWPORT:
123 *semantic_name = TGSI_SEMANTIC_VIEWPORT_INDEX;
124 *semantic_index = 0;
125 break;
126 case VARYING_SLOT_PNTC:
127 *semantic_name = TGSI_SEMANTIC_PCOORD;
128 *semantic_index = 0;
129 break;
130 case VARYING_SLOT_TESS_LEVEL_OUTER:
131 *semantic_name = TGSI_SEMANTIC_TESSOUTER;
132 *semantic_index = 0;
133 break;
134 case VARYING_SLOT_TESS_LEVEL_INNER:
135 *semantic_name = TGSI_SEMANTIC_TESSINNER;
136 *semantic_index = 0;
137 break;
138
139 case VARYING_SLOT_TEX0:
140 case VARYING_SLOT_TEX1:
141 case VARYING_SLOT_TEX2:
142 case VARYING_SLOT_TEX3:
143 case VARYING_SLOT_TEX4:
144 case VARYING_SLOT_TEX5:
145 case VARYING_SLOT_TEX6:
146 case VARYING_SLOT_TEX7:
147 if (needs_texcoord_semantic) {
148 *semantic_name = TGSI_SEMANTIC_TEXCOORD;
149 *semantic_index = attr - VARYING_SLOT_TEX0;
150 break;
151 }
152 /* fall through */
153 case VARYING_SLOT_VAR0:
154 default:
155 assert(attr >= VARYING_SLOT_VAR0 ||
156 (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7));
157 if (attr >= VARYING_SLOT_PATCH0) {
158 *semantic_name = TGSI_SEMANTIC_PATCH;
159 *semantic_index = attr - VARYING_SLOT_PATCH0;
160 } else {
161 *semantic_name = TGSI_SEMANTIC_GENERIC;
162 *semantic_index =
163 tgsi_get_generic_gl_varying_index(attr, needs_texcoord_semantic);
164 }
165 break;
166 }
167 }
168
169 /**
170 * Determine the semantic name and index used for the given fragment shader
171 * result.
172 */
173 void
tgsi_get_gl_frag_result_semantic(gl_frag_result frag_result,unsigned * semantic_name,unsigned * semantic_index)174 tgsi_get_gl_frag_result_semantic(gl_frag_result frag_result,
175 unsigned *semantic_name,
176 unsigned *semantic_index)
177 {
178 if (frag_result >= FRAG_RESULT_DATA0) {
179 *semantic_name = TGSI_SEMANTIC_COLOR;
180 *semantic_index = frag_result - FRAG_RESULT_DATA0;
181 return;
182 }
183
184 *semantic_index = 0;
185
186 switch (frag_result) {
187 case FRAG_RESULT_DEPTH:
188 *semantic_name = TGSI_SEMANTIC_POSITION;
189 break;
190 case FRAG_RESULT_STENCIL:
191 *semantic_name = TGSI_SEMANTIC_STENCIL;
192 break;
193 case FRAG_RESULT_COLOR:
194 *semantic_name = TGSI_SEMANTIC_COLOR;
195 break;
196 case FRAG_RESULT_SAMPLE_MASK:
197 *semantic_name = TGSI_SEMANTIC_SAMPLEMASK;
198 break;
199 default:
200 assert(false);
201 }
202 }
203