~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/auxiliary/util/u_prim.h

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 * Decompose a primitive that is a loop, a strip, or a fan.  Return the
49
49
 * original primitive if it is already decomposed.
50
50
 */
51
 
static inline enum pipe_prim_type
52
 
u_decomposed_prim(enum pipe_prim_type prim)
 
51
static inline enum mesa_prim
 
52
u_decomposed_prim(enum mesa_prim prim)
53
53
{
54
54
   switch (prim) {
55
 
   case PIPE_PRIM_LINE_LOOP:
56
 
   case PIPE_PRIM_LINE_STRIP:
57
 
      return PIPE_PRIM_LINES;
58
 
   case PIPE_PRIM_TRIANGLE_STRIP:
59
 
   case PIPE_PRIM_TRIANGLE_FAN:
60
 
      return PIPE_PRIM_TRIANGLES;
61
 
   case PIPE_PRIM_QUAD_STRIP:
62
 
      return PIPE_PRIM_QUADS;
63
 
   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
64
 
      return PIPE_PRIM_LINES_ADJACENCY;
65
 
   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
66
 
      return PIPE_PRIM_TRIANGLES_ADJACENCY;
 
55
   case MESA_PRIM_LINE_LOOP:
 
56
   case MESA_PRIM_LINE_STRIP:
 
57
      return MESA_PRIM_LINES;
 
58
   case MESA_PRIM_TRIANGLE_STRIP:
 
59
   case MESA_PRIM_TRIANGLE_FAN:
 
60
      return MESA_PRIM_TRIANGLES;
 
61
   case MESA_PRIM_QUAD_STRIP:
 
62
      return MESA_PRIM_QUADS;
 
63
   case MESA_PRIM_LINE_STRIP_ADJACENCY:
 
64
      return MESA_PRIM_LINES_ADJACENCY;
 
65
   case MESA_PRIM_TRIANGLE_STRIP_ADJACENCY:
 
66
      return MESA_PRIM_TRIANGLES_ADJACENCY;
67
67
   default:
68
68
      return prim;
69
69
   }
70
70
}
71
71
 
72
72
/**
73
 
 * Reduce a primitive to one of PIPE_PRIM_POINTS, PIPE_PRIM_LINES, and
74
 
 * PIPE_PRIM_TRIANGLES.
 
73
 * Reduce a primitive to one of MESA_PRIM_POINTS, MESA_PRIM_LINES, and
 
74
 * MESA_PRIM_TRIANGLES.
75
75
 */
76
 
static inline enum pipe_prim_type
77
 
u_reduced_prim(enum pipe_prim_type prim)
 
76
static inline enum mesa_prim
 
77
u_reduced_prim(enum mesa_prim prim)
78
78
{
79
79
   switch (prim) {
80
 
   case PIPE_PRIM_POINTS:
81
 
      return PIPE_PRIM_POINTS;
82
 
   case PIPE_PRIM_LINES:
83
 
   case PIPE_PRIM_LINE_LOOP:
84
 
   case PIPE_PRIM_LINE_STRIP:
85
 
   case PIPE_PRIM_LINES_ADJACENCY:
86
 
   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
87
 
      return PIPE_PRIM_LINES;
 
80
   case MESA_PRIM_POINTS:
 
81
      return MESA_PRIM_POINTS;
 
82
   case MESA_PRIM_LINES:
 
83
   case MESA_PRIM_LINE_LOOP:
 
84
   case MESA_PRIM_LINE_STRIP:
 
85
   case MESA_PRIM_LINES_ADJACENCY:
 
86
   case MESA_PRIM_LINE_STRIP_ADJACENCY:
 
87
      return MESA_PRIM_LINES;
88
88
   default:
89
 
      return PIPE_PRIM_TRIANGLES;
 
89
      return MESA_PRIM_TRIANGLES;
90
90
   }
91
91
}
92
92
 
93
93
/**
94
94
 * Re-assemble a primitive to remove its adjacency.
95
95
 */
96
 
static inline enum pipe_prim_type
97
 
u_assembled_prim(enum pipe_prim_type prim)
 
96
static inline enum mesa_prim
 
97
u_assembled_prim(enum mesa_prim prim)
98
98
{
99
99
   switch (prim) {
100
 
   case PIPE_PRIM_LINES_ADJACENCY:
101
 
   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
102
 
      return PIPE_PRIM_LINES;
103
 
   case PIPE_PRIM_TRIANGLES_ADJACENCY:
104
 
   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
105
 
      return PIPE_PRIM_TRIANGLES;
 
100
   case MESA_PRIM_LINES_ADJACENCY:
 
101
   case MESA_PRIM_LINE_STRIP_ADJACENCY:
 
102
      return MESA_PRIM_LINES;
 
103
   case MESA_PRIM_TRIANGLES_ADJACENCY:
 
104
   case MESA_PRIM_TRIANGLE_STRIP_ADJACENCY:
 
105
      return MESA_PRIM_TRIANGLES;
106
106
   default:
107
107
      return prim;
108
108
   }
116
116
 * expected because of the use of a table.
117
117
 */
118
118
static inline const struct u_prim_vertex_count *
119
 
u_prim_vertex_count(enum pipe_prim_type prim)
 
119
u_prim_vertex_count(enum mesa_prim prim)
120
120
{
121
 
   static const struct u_prim_vertex_count prim_table[PIPE_PRIM_MAX] = {
122
 
      { 1, 1 }, /* PIPE_PRIM_POINTS */
123
 
      { 2, 2 }, /* PIPE_PRIM_LINES */
124
 
      { 2, 1 }, /* PIPE_PRIM_LINE_LOOP */
125
 
      { 2, 1 }, /* PIPE_PRIM_LINE_STRIP */
126
 
      { 3, 3 }, /* PIPE_PRIM_TRIANGLES */
127
 
      { 3, 1 }, /* PIPE_PRIM_TRIANGLE_STRIP */
128
 
      { 3, 1 }, /* PIPE_PRIM_TRIANGLE_FAN */
129
 
      { 4, 4 }, /* PIPE_PRIM_QUADS */
130
 
      { 4, 2 }, /* PIPE_PRIM_QUAD_STRIP */
131
 
      { 3, 1 }, /* PIPE_PRIM_POLYGON */
132
 
      { 4, 4 }, /* PIPE_PRIM_LINES_ADJACENCY */
133
 
      { 4, 1 }, /* PIPE_PRIM_LINE_STRIP_ADJACENCY */
134
 
      { 6, 6 }, /* PIPE_PRIM_TRIANGLES_ADJACENCY */
135
 
      { 6, 2 }, /* PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY */
 
121
   static const struct u_prim_vertex_count prim_table[MESA_PRIM_COUNT] = {
 
122
      { 1, 1 }, /* MESA_PRIM_POINTS */
 
123
      { 2, 2 }, /* MESA_PRIM_LINES */
 
124
      { 2, 1 }, /* MESA_PRIM_LINE_LOOP */
 
125
      { 2, 1 }, /* MESA_PRIM_LINE_STRIP */
 
126
      { 3, 3 }, /* MESA_PRIM_TRIANGLES */
 
127
      { 3, 1 }, /* MESA_PRIM_TRIANGLE_STRIP */
 
128
      { 3, 1 }, /* MESA_PRIM_TRIANGLE_FAN */
 
129
      { 4, 4 }, /* MESA_PRIM_QUADS */
 
130
      { 4, 2 }, /* MESA_PRIM_QUAD_STRIP */
 
131
      { 3, 1 }, /* MESA_PRIM_POLYGON */
 
132
      { 4, 4 }, /* MESA_PRIM_LINES_ADJACENCY */
 
133
      { 4, 1 }, /* MESA_PRIM_LINE_STRIP_ADJACENCY */
 
134
      { 6, 6 }, /* MESA_PRIM_TRIANGLES_ADJACENCY */
 
135
      { 6, 2 }, /* MESA_PRIM_TRIANGLE_STRIP_ADJACENCY */
136
136
   };
137
137
 
138
 
   return (likely(prim < PIPE_PRIM_MAX)) ? &prim_table[prim] : NULL;
 
138
   return (likely(prim < MESA_PRIM_COUNT)) ? &prim_table[prim] : NULL;
139
139
}
140
140
 
141
141
/**
143
143
 * For polygons, return the number of triangles.
144
144
 */
145
145
static inline unsigned
146
 
u_prims_for_vertices(enum pipe_prim_type prim, unsigned num)
 
146
u_prims_for_vertices(enum mesa_prim prim, unsigned num)
147
147
{
148
148
   const struct u_prim_vertex_count *info = u_prim_vertex_count(prim);
149
149
 
156
156
   return 1 + ((num - info->min) / info->incr);
157
157
}
158
158
 
159
 
static inline boolean
160
 
u_validate_pipe_prim(enum pipe_prim_type pipe_prim, unsigned nr)
 
159
static inline bool
 
160
u_validate_pipe_prim(enum mesa_prim pipe_prim, unsigned nr)
161
161
{
162
162
   const struct u_prim_vertex_count *count = u_prim_vertex_count(pipe_prim);
163
163
 
165
165
}
166
166
 
167
167
 
168
 
static inline boolean
169
 
u_trim_pipe_prim(enum pipe_prim_type pipe_prim, unsigned *nr)
 
168
static inline bool
 
169
u_trim_pipe_prim(enum mesa_prim pipe_prim, unsigned *nr)
170
170
{
171
171
   const struct u_prim_vertex_count *count = u_prim_vertex_count(pipe_prim);
172
172
 
173
173
   if (count && *nr >= count->min) {
174
174
      if (count->incr > 1)
175
175
         *nr -= (*nr % count->incr);
176
 
      return TRUE;
 
176
      return true;
177
177
   }
178
178
   else {
179
179
      *nr = 0;
180
 
      return FALSE;
 
180
      return false;
181
181
   }
182
182
}
183
183
 
184
184
static inline unsigned
185
 
u_vertices_per_prim(enum pipe_prim_type primitive)
 
185
u_vertices_per_prim(enum mesa_prim primitive)
186
186
{
187
187
   switch(primitive) {
188
 
   case PIPE_PRIM_POINTS:
 
188
   case MESA_PRIM_POINTS:
189
189
      return 1;
190
 
   case PIPE_PRIM_LINES:
191
 
   case PIPE_PRIM_LINE_LOOP:
192
 
   case PIPE_PRIM_LINE_STRIP:
 
190
   case MESA_PRIM_LINES:
 
191
   case MESA_PRIM_LINE_LOOP:
 
192
   case MESA_PRIM_LINE_STRIP:
193
193
      return 2;
194
 
   case PIPE_PRIM_TRIANGLES:
195
 
   case PIPE_PRIM_TRIANGLE_STRIP:
196
 
   case PIPE_PRIM_TRIANGLE_FAN:
 
194
   case MESA_PRIM_TRIANGLES:
 
195
   case MESA_PRIM_TRIANGLE_STRIP:
 
196
   case MESA_PRIM_TRIANGLE_FAN:
197
197
      return 3;
198
 
   case PIPE_PRIM_LINES_ADJACENCY:
199
 
   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
 
198
   case MESA_PRIM_LINES_ADJACENCY:
 
199
   case MESA_PRIM_LINE_STRIP_ADJACENCY:
200
200
      return 4;
201
 
   case PIPE_PRIM_TRIANGLES_ADJACENCY:
202
 
   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
 
201
   case MESA_PRIM_TRIANGLES_ADJACENCY:
 
202
   case MESA_PRIM_TRIANGLE_STRIP_ADJACENCY:
203
203
      return 6;
204
204
 
205
 
   case PIPE_PRIM_QUADS:
206
 
   case PIPE_PRIM_QUAD_STRIP:
 
205
   case MESA_PRIM_QUADS:
 
206
   case MESA_PRIM_QUAD_STRIP:
207
207
      /* these won't be seen from geometry shaders
208
208
         but prim assembly might for prim id. */
209
209
      return 4;
211
211
   /* following primitives should never be used
212
212
    * with geometry shaders abd their size is
213
213
    * undefined */
214
 
   case PIPE_PRIM_POLYGON:
 
214
   case MESA_PRIM_POLYGON:
215
215
   default:
216
216
      debug_printf("Unrecognized geometry shader primitive");
217
217
      return 3;
228
228
 * primitives for a set of vertices.
229
229
 */
230
230
static inline unsigned
231
 
u_decomposed_prims_for_vertices(enum pipe_prim_type primitive, int vertices)
 
231
u_decomposed_prims_for_vertices(enum mesa_prim primitive, int vertices)
232
232
{
233
233
   switch (primitive) {
234
 
   case PIPE_PRIM_POINTS:
 
234
   case MESA_PRIM_POINTS:
235
235
      return vertices;
236
 
   case PIPE_PRIM_LINES:
 
236
   case MESA_PRIM_LINES:
237
237
      return vertices / 2;
238
 
   case PIPE_PRIM_LINE_LOOP:
 
238
   case MESA_PRIM_LINE_LOOP:
239
239
      return (vertices >= 2) ? vertices : 0;
240
 
   case PIPE_PRIM_LINE_STRIP:
 
240
   case MESA_PRIM_LINE_STRIP:
241
241
      return (vertices >= 2) ? vertices - 1 : 0;
242
 
   case PIPE_PRIM_TRIANGLES:
 
242
   case MESA_PRIM_TRIANGLES:
243
243
      return vertices / 3;
244
 
   case PIPE_PRIM_TRIANGLE_STRIP:
245
 
      return (vertices >= 3) ? vertices - 2 : 0;
246
 
   case PIPE_PRIM_TRIANGLE_FAN:
247
 
      return (vertices >= 3) ? vertices - 2 : 0;
248
 
   case PIPE_PRIM_LINES_ADJACENCY:
 
244
   case MESA_PRIM_TRIANGLE_STRIP:
 
245
      return (vertices >= 3) ? vertices - 2 : 0;
 
246
   case MESA_PRIM_TRIANGLE_FAN:
 
247
      return (vertices >= 3) ? vertices - 2 : 0;
 
248
   case MESA_PRIM_LINES_ADJACENCY:
249
249
      return vertices / 4;
250
 
   case PIPE_PRIM_LINE_STRIP_ADJACENCY:
 
250
   case MESA_PRIM_LINE_STRIP_ADJACENCY:
251
251
      return (vertices >= 4) ? vertices - 3 : 0;
252
 
   case PIPE_PRIM_TRIANGLES_ADJACENCY:
 
252
   case MESA_PRIM_TRIANGLES_ADJACENCY:
253
253
      return vertices / 6;
254
 
   case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
 
254
   case MESA_PRIM_TRIANGLE_STRIP_ADJACENCY:
255
255
      return (vertices >= 6) ? 1 + (vertices - 6) / 2 : 0;
256
 
   case PIPE_PRIM_QUADS:
 
256
   case MESA_PRIM_QUADS:
257
257
      return vertices / 4;
258
 
   case PIPE_PRIM_QUAD_STRIP:
 
258
   case MESA_PRIM_QUAD_STRIP:
259
259
      return (vertices >= 4) ? (vertices - 2) / 2 : 0;
260
260
   /* Polygons can't be decomposed
261
261
    * because the number of their vertices isn't known so
262
262
    * for them and whatever else we don't recognize just
263
263
    * return 1 if the number of vertices is greater than
264
264
    * or equal to 3 and zero otherwise */
265
 
   case PIPE_PRIM_POLYGON:
 
265
   case MESA_PRIM_POLYGON:
266
266
   default:
267
267
      debug_printf("Invalid decomposition primitive!\n");
268
268
      return (vertices >= 3) ? 1 : 0;
275
275
 * triangle fans.
276
276
 */
277
277
static inline unsigned
278
 
u_reduced_prims_for_vertices(enum pipe_prim_type primitive, int vertices)
 
278
u_reduced_prims_for_vertices(enum mesa_prim primitive, int vertices)
279
279
{
280
280
   switch (primitive) {
281
 
   case PIPE_PRIM_QUADS:
282
 
   case PIPE_PRIM_QUAD_STRIP:
 
281
   case MESA_PRIM_QUADS:
 
282
   case MESA_PRIM_QUAD_STRIP:
283
283
      return u_decomposed_prims_for_vertices(primitive, vertices) * 2;
284
 
   case PIPE_PRIM_POLYGON:
285
 
      primitive = PIPE_PRIM_TRIANGLE_FAN;
 
284
   case MESA_PRIM_POLYGON:
 
285
      primitive = MESA_PRIM_TRIANGLE_FAN;
286
286
      FALLTHROUGH;
287
287
   default:
288
288
      return u_decomposed_prims_for_vertices(primitive, vertices);
289
289
   }
290
290
}
291
291
 
292
 
static inline enum pipe_prim_type
293
 
u_base_prim_type(enum pipe_prim_type prim_type)
 
292
static inline enum mesa_prim
 
293
u_base_prim_type(enum mesa_prim prim_type)
294
294
{
295
295
   switch(prim_type) {
296
 
      case PIPE_PRIM_POINTS:
297
 
         return PIPE_PRIM_POINTS;
298
 
      case PIPE_PRIM_LINES:
299
 
      case PIPE_PRIM_LINE_LOOP:
300
 
      case PIPE_PRIM_LINE_STRIP:
301
 
      case PIPE_PRIM_LINES_ADJACENCY:
302
 
      case PIPE_PRIM_LINE_STRIP_ADJACENCY:
303
 
         return PIPE_PRIM_LINES;
304
 
      case PIPE_PRIM_TRIANGLES:
305
 
      case PIPE_PRIM_TRIANGLE_STRIP:
306
 
      case PIPE_PRIM_TRIANGLE_FAN:
307
 
      case PIPE_PRIM_TRIANGLES_ADJACENCY:
308
 
      case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
309
 
         return PIPE_PRIM_TRIANGLES;
310
 
      case PIPE_PRIM_QUADS:
311
 
      case PIPE_PRIM_QUAD_STRIP:
312
 
         return PIPE_PRIM_QUADS;
 
296
      case MESA_PRIM_POINTS:
 
297
         return MESA_PRIM_POINTS;
 
298
      case MESA_PRIM_LINES:
 
299
      case MESA_PRIM_LINE_LOOP:
 
300
      case MESA_PRIM_LINE_STRIP:
 
301
      case MESA_PRIM_LINES_ADJACENCY:
 
302
      case MESA_PRIM_LINE_STRIP_ADJACENCY:
 
303
         return MESA_PRIM_LINES;
 
304
      case MESA_PRIM_TRIANGLES:
 
305
      case MESA_PRIM_TRIANGLE_STRIP:
 
306
      case MESA_PRIM_TRIANGLE_FAN:
 
307
      case MESA_PRIM_TRIANGLES_ADJACENCY:
 
308
      case MESA_PRIM_TRIANGLE_STRIP_ADJACENCY:
 
309
         return MESA_PRIM_TRIANGLES;
 
310
      case MESA_PRIM_QUADS:
 
311
      case MESA_PRIM_QUAD_STRIP:
 
312
         return MESA_PRIM_QUADS;
313
313
      default:
314
314
         return prim_type;
315
315
   }
316
316
}
317
317
 
318
 
static inline enum pipe_prim_type
 
318
static inline enum mesa_prim
319
319
u_tess_prim_from_shader(enum tess_primitive_mode shader_mode)
320
320
{
321
321
   switch (shader_mode) {
322
322
   case TESS_PRIMITIVE_TRIANGLES:
323
 
      return PIPE_PRIM_TRIANGLES;
 
323
      return MESA_PRIM_TRIANGLES;
324
324
   case TESS_PRIMITIVE_QUADS:
325
 
      return PIPE_PRIM_QUADS;
 
325
      return MESA_PRIM_QUADS;
326
326
   case TESS_PRIMITIVE_ISOLINES:
327
 
      return PIPE_PRIM_LINES;
 
327
      return MESA_PRIM_LINES;
328
328
   default:
329
 
      return PIPE_PRIM_POINTS;
 
329
      return MESA_PRIM_POINTS;
330
330
   }
331
331
}
332
332
 
333
333
static inline unsigned
334
 
u_vertices_for_prims(enum pipe_prim_type prim_type, int count)
 
334
u_vertices_for_prims(enum mesa_prim prim_type, int count)
335
335
{
336
336
   if (count <= 0)
337
337
      return 0;
340
340
    * if we are using basic primitives (so no loops, strips, fans, etc).
341
341
    */
342
342
   assert(prim_type == u_base_prim_type(prim_type) &&
343
 
          prim_type != PIPE_PRIM_PATCHES && prim_type != PIPE_PRIM_POLYGON);
 
343
          prim_type != MESA_PRIM_PATCHES && prim_type != MESA_PRIM_POLYGON);
344
344
 
345
345
   const struct u_prim_vertex_count *info = u_prim_vertex_count(prim_type);
346
346
   assert(info);
354
354
 */
355
355
 
356
356
static inline unsigned
357
 
u_stream_outputs_for_vertices(enum pipe_prim_type primitive, unsigned nr)
 
357
u_stream_outputs_for_vertices(enum mesa_prim primitive, unsigned nr)
358
358
{
359
359
   /* Extraneous vertices don't contribute to stream outputs */
360
360
   u_trim_pipe_prim(primitive, &nr);
363
363
    * vertices. In this case, we just have an output for each vertex (after
364
364
    * trimming) */
365
365
 
366
 
   if (primitive == PIPE_PRIM_POLYGON)
 
366
   if (primitive == MESA_PRIM_POLYGON)
367
367
      return nr;
368
368
 
369
369
   /* Normally, consider how many primitives are actually generated */
370
370
   unsigned prims = u_decomposed_prims_for_vertices(primitive, nr);
371
371
 
372
372
   /* One output per vertex after decomposition */
373
 
   enum pipe_prim_type base = u_base_prim_type(primitive);
 
373
   enum mesa_prim base = u_base_prim_type(primitive);
374
374
 
375
375
   /* The GL 4.6 compatibility spec says
376
376
    *
381
381
    * Further, quads and polygons are always provided as TRIANGLES. So
382
382
    * tessellate quads into triangles.
383
383
    */
384
 
   if (base == PIPE_PRIM_QUADS) {
385
 
      base = PIPE_PRIM_TRIANGLES;
 
384
   if (base == MESA_PRIM_QUADS) {
 
385
      base = MESA_PRIM_TRIANGLES;
386
386
      prims *= 2;
387
387
   }
388
388
 
389
389
   return u_vertices_for_prims(base, prims);
390
390
}
391
391
 
392
 
const char *u_prim_name(enum pipe_prim_type pipe_prim);
 
392
const char *u_prim_name(enum mesa_prim pipe_prim);
393
393
 
394
394
 
395
395
#ifdef __cplusplus