00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "util/u_memory.h"
00034 #include "pipe/p_state.h"
00035 #include "translate.h"
00036
00037
00038 #define DRAW_DBG 0
00039
00040 typedef void (*fetch_func)(const void *ptr, float *attrib);
00041 typedef void (*emit_func)(const float *attrib, void *ptr);
00042
00043
00044
00045 struct translate_generic {
00046 struct translate translate;
00047
00048 struct {
00049 fetch_func fetch;
00050 unsigned buffer;
00051 unsigned input_offset;
00052
00053 emit_func emit;
00054 unsigned output_offset;
00055
00056 char *input_ptr;
00057 unsigned input_stride;
00058
00059 } attrib[PIPE_MAX_ATTRIBS];
00060
00061 unsigned nr_attrib;
00062 };
00063
00064
00065 static struct translate_generic *translate_generic( struct translate *translate )
00066 {
00067 return (struct translate_generic *)translate;
00068 }
00069
00077 #define ATTRIB( NAME, SZ, TYPE, FROM, TO ) \
00078 static void \
00079 fetch_##NAME(const void *ptr, float *attrib) \
00080 { \
00081 const float defaults[4] = { 0.0f,0.0f,0.0f,1.0f }; \
00082 unsigned i; \
00083 \
00084 for (i = 0; i < SZ; i++) { \
00085 attrib[i] = FROM(i); \
00086 } \
00087 \
00088 for (; i < 4; i++) { \
00089 attrib[i] = defaults[i]; \
00090 } \
00091 } \
00092 \
00093 static void \
00094 emit_##NAME(const float *attrib, void *ptr) \
00095 { \
00096 unsigned i; \
00097 TYPE *out = (TYPE *)ptr; \
00098 \
00099 for (i = 0; i < SZ; i++) { \
00100 out[i] = TO(attrib[i]); \
00101 } \
00102 }
00103
00104
00105 #define FROM_64_FLOAT(i) ((float) ((double *) ptr)[i])
00106 #define FROM_32_FLOAT(i) (((float *) ptr)[i])
00107
00108 #define FROM_8_USCALED(i) ((float) ((unsigned char *) ptr)[i])
00109 #define FROM_16_USCALED(i) ((float) ((unsigned short *) ptr)[i])
00110 #define FROM_32_USCALED(i) ((float) ((unsigned int *) ptr)[i])
00111
00112 #define FROM_8_SSCALED(i) ((float) ((char *) ptr)[i])
00113 #define FROM_16_SSCALED(i) ((float) ((short *) ptr)[i])
00114 #define FROM_32_SSCALED(i) ((float) ((int *) ptr)[i])
00115
00116 #define FROM_8_UNORM(i) ((float) ((unsigned char *) ptr)[i] / 255.0f)
00117 #define FROM_16_UNORM(i) ((float) ((unsigned short *) ptr)[i] / 65535.0f)
00118 #define FROM_32_UNORM(i) ((float) ((unsigned int *) ptr)[i] / 4294967295.0f)
00119
00120 #define FROM_8_SNORM(i) ((float) ((char *) ptr)[i] / 127.0f)
00121 #define FROM_16_SNORM(i) ((float) ((short *) ptr)[i] / 32767.0f)
00122 #define FROM_32_SNORM(i) ((float) ((int *) ptr)[i] / 2147483647.0f)
00123
00124 #define FROM_32_FIXED(i) (((int *) ptr)[i] / 65536.0f)
00125
00126 #define TO_64_FLOAT(x) ((double) x)
00127 #define TO_32_FLOAT(x) (x)
00128
00129 #define TO_8_USCALED(x) ((unsigned char) x)
00130 #define TO_16_USCALED(x) ((unsigned short) x)
00131 #define TO_32_USCALED(x) ((unsigned int) x)
00132
00133 #define TO_8_SSCALED(x) ((char) x)
00134 #define TO_16_SSCALED(x) ((short) x)
00135 #define TO_32_SSCALED(x) ((int) x)
00136
00137 #define TO_8_UNORM(x) ((unsigned char) (x * 255.0f))
00138 #define TO_16_UNORM(x) ((unsigned short) (x * 65535.0f))
00139 #define TO_32_UNORM(x) ((unsigned int) (x * 4294967295.0f))
00140
00141 #define TO_8_SNORM(x) ((char) (x * 127.0f))
00142 #define TO_16_SNORM(x) ((short) (x * 32767.0f))
00143 #define TO_32_SNORM(x) ((int) (x * 2147483647.0f))
00144
00145 #define TO_32_FIXED(x) ((int) (x * 65536.0f))
00146
00147
00148
00149 ATTRIB( R64G64B64A64_FLOAT, 4, double, FROM_64_FLOAT, TO_64_FLOAT )
00150 ATTRIB( R64G64B64_FLOAT, 3, double, FROM_64_FLOAT, TO_64_FLOAT )
00151 ATTRIB( R64G64_FLOAT, 2, double, FROM_64_FLOAT, TO_64_FLOAT )
00152 ATTRIB( R64_FLOAT, 1, double, FROM_64_FLOAT, TO_64_FLOAT )
00153
00154 ATTRIB( R32G32B32A32_FLOAT, 4, float, FROM_32_FLOAT, TO_32_FLOAT )
00155 ATTRIB( R32G32B32_FLOAT, 3, float, FROM_32_FLOAT, TO_32_FLOAT )
00156 ATTRIB( R32G32_FLOAT, 2, float, FROM_32_FLOAT, TO_32_FLOAT )
00157 ATTRIB( R32_FLOAT, 1, float, FROM_32_FLOAT, TO_32_FLOAT )
00158
00159 ATTRIB( R32G32B32A32_USCALED, 4, unsigned, FROM_32_USCALED, TO_32_USCALED )
00160 ATTRIB( R32G32B32_USCALED, 3, unsigned, FROM_32_USCALED, TO_32_USCALED )
00161 ATTRIB( R32G32_USCALED, 2, unsigned, FROM_32_USCALED, TO_32_USCALED )
00162 ATTRIB( R32_USCALED, 1, unsigned, FROM_32_USCALED, TO_32_USCALED )
00163
00164 ATTRIB( R32G32B32A32_SSCALED, 4, int, FROM_32_SSCALED, TO_32_SSCALED )
00165 ATTRIB( R32G32B32_SSCALED, 3, int, FROM_32_SSCALED, TO_32_SSCALED )
00166 ATTRIB( R32G32_SSCALED, 2, int, FROM_32_SSCALED, TO_32_SSCALED )
00167 ATTRIB( R32_SSCALED, 1, int, FROM_32_SSCALED, TO_32_SSCALED )
00168
00169 ATTRIB( R32G32B32A32_UNORM, 4, unsigned, FROM_32_UNORM, TO_32_UNORM )
00170 ATTRIB( R32G32B32_UNORM, 3, unsigned, FROM_32_UNORM, TO_32_UNORM )
00171 ATTRIB( R32G32_UNORM, 2, unsigned, FROM_32_UNORM, TO_32_UNORM )
00172 ATTRIB( R32_UNORM, 1, unsigned, FROM_32_UNORM, TO_32_UNORM )
00173
00174 ATTRIB( R32G32B32A32_SNORM, 4, int, FROM_32_SNORM, TO_32_SNORM )
00175 ATTRIB( R32G32B32_SNORM, 3, int, FROM_32_SNORM, TO_32_SNORM )
00176 ATTRIB( R32G32_SNORM, 2, int, FROM_32_SNORM, TO_32_SNORM )
00177 ATTRIB( R32_SNORM, 1, int, FROM_32_SNORM, TO_32_SNORM )
00178
00179 ATTRIB( R16G16B16A16_USCALED, 4, ushort, FROM_16_USCALED, TO_16_USCALED )
00180 ATTRIB( R16G16B16_USCALED, 3, ushort, FROM_16_USCALED, TO_16_USCALED )
00181 ATTRIB( R16G16_USCALED, 2, ushort, FROM_16_USCALED, TO_16_USCALED )
00182 ATTRIB( R16_USCALED, 1, ushort, FROM_16_USCALED, TO_16_USCALED )
00183
00184 ATTRIB( R16G16B16A16_SSCALED, 4, short, FROM_16_SSCALED, TO_16_SSCALED )
00185 ATTRIB( R16G16B16_SSCALED, 3, short, FROM_16_SSCALED, TO_16_SSCALED )
00186 ATTRIB( R16G16_SSCALED, 2, short, FROM_16_SSCALED, TO_16_SSCALED )
00187 ATTRIB( R16_SSCALED, 1, short, FROM_16_SSCALED, TO_16_SSCALED )
00188
00189 ATTRIB( R16G16B16A16_UNORM, 4, ushort, FROM_16_UNORM, TO_16_UNORM )
00190 ATTRIB( R16G16B16_UNORM, 3, ushort, FROM_16_UNORM, TO_16_UNORM )
00191 ATTRIB( R16G16_UNORM, 2, ushort, FROM_16_UNORM, TO_16_UNORM )
00192 ATTRIB( R16_UNORM, 1, ushort, FROM_16_UNORM, TO_16_UNORM )
00193
00194 ATTRIB( R16G16B16A16_SNORM, 4, short, FROM_16_SNORM, TO_16_SNORM )
00195 ATTRIB( R16G16B16_SNORM, 3, short, FROM_16_SNORM, TO_16_SNORM )
00196 ATTRIB( R16G16_SNORM, 2, short, FROM_16_SNORM, TO_16_SNORM )
00197 ATTRIB( R16_SNORM, 1, short, FROM_16_SNORM, TO_16_SNORM )
00198
00199 ATTRIB( R8G8B8A8_USCALED, 4, ubyte, FROM_8_USCALED, TO_8_USCALED )
00200 ATTRIB( R8G8B8_USCALED, 3, ubyte, FROM_8_USCALED, TO_8_USCALED )
00201 ATTRIB( R8G8_USCALED, 2, ubyte, FROM_8_USCALED, TO_8_USCALED )
00202 ATTRIB( R8_USCALED, 1, ubyte, FROM_8_USCALED, TO_8_USCALED )
00203
00204 ATTRIB( R8G8B8A8_SSCALED, 4, char, FROM_8_SSCALED, TO_8_SSCALED )
00205 ATTRIB( R8G8B8_SSCALED, 3, char, FROM_8_SSCALED, TO_8_SSCALED )
00206 ATTRIB( R8G8_SSCALED, 2, char, FROM_8_SSCALED, TO_8_SSCALED )
00207 ATTRIB( R8_SSCALED, 1, char, FROM_8_SSCALED, TO_8_SSCALED )
00208
00209 ATTRIB( R8G8B8A8_UNORM, 4, ubyte, FROM_8_UNORM, TO_8_UNORM )
00210 ATTRIB( R8G8B8_UNORM, 3, ubyte, FROM_8_UNORM, TO_8_UNORM )
00211 ATTRIB( R8G8_UNORM, 2, ubyte, FROM_8_UNORM, TO_8_UNORM )
00212 ATTRIB( R8_UNORM, 1, ubyte, FROM_8_UNORM, TO_8_UNORM )
00213
00214 ATTRIB( R8G8B8A8_SNORM, 4, char, FROM_8_SNORM, TO_8_SNORM )
00215 ATTRIB( R8G8B8_SNORM, 3, char, FROM_8_SNORM, TO_8_SNORM )
00216 ATTRIB( R8G8_SNORM, 2, char, FROM_8_SNORM, TO_8_SNORM )
00217 ATTRIB( R8_SNORM, 1, char, FROM_8_SNORM, TO_8_SNORM )
00218
00219 ATTRIB( A8R8G8B8_UNORM, 4, ubyte, FROM_8_UNORM, TO_8_UNORM )
00220
00221
00222 ATTRIB( R32G32B32A32_FIXED, 4, int, FROM_32_FIXED, TO_32_FIXED )
00223 ATTRIB( R32G32B32_FIXED, 3, int, FROM_32_FIXED, TO_32_FIXED )
00224 ATTRIB( R32G32_FIXED, 2, int, FROM_32_FIXED, TO_32_FIXED )
00225 ATTRIB( R32_FIXED, 1, int, FROM_32_FIXED, TO_32_FIXED )
00226
00227
00228
00229 static void
00230 fetch_B8G8R8A8_UNORM(const void *ptr, float *attrib)
00231 {
00232 attrib[2] = FROM_8_UNORM(0);
00233 attrib[1] = FROM_8_UNORM(1);
00234 attrib[0] = FROM_8_UNORM(2);
00235 attrib[3] = FROM_8_UNORM(3);
00236 }
00237
00238 static void
00239 emit_B8G8R8A8_UNORM( const float *attrib, void *ptr)
00240 {
00241 ubyte *out = (ubyte *)ptr;
00242 out[2] = TO_8_UNORM(attrib[0]);
00243 out[1] = TO_8_UNORM(attrib[1]);
00244 out[0] = TO_8_UNORM(attrib[2]);
00245 out[3] = TO_8_UNORM(attrib[3]);
00246 }
00247
00248 static void
00249 fetch_NULL( const void *ptr, float *attrib )
00250 {
00251 attrib[0] = 0;
00252 attrib[1] = 0;
00253 attrib[2] = 0;
00254 attrib[3] = 1;
00255 }
00256
00257 static void
00258 emit_NULL( const float *attrib, void *ptr )
00259 {
00260
00261 }
00262
00263 static fetch_func get_fetch_func( enum pipe_format format )
00264 {
00265 switch (format) {
00266 case PIPE_FORMAT_R64_FLOAT:
00267 return &fetch_R64_FLOAT;
00268 case PIPE_FORMAT_R64G64_FLOAT:
00269 return &fetch_R64G64_FLOAT;
00270 case PIPE_FORMAT_R64G64B64_FLOAT:
00271 return &fetch_R64G64B64_FLOAT;
00272 case PIPE_FORMAT_R64G64B64A64_FLOAT:
00273 return &fetch_R64G64B64A64_FLOAT;
00274
00275 case PIPE_FORMAT_R32_FLOAT:
00276 return &fetch_R32_FLOAT;
00277 case PIPE_FORMAT_R32G32_FLOAT:
00278 return &fetch_R32G32_FLOAT;
00279 case PIPE_FORMAT_R32G32B32_FLOAT:
00280 return &fetch_R32G32B32_FLOAT;
00281 case PIPE_FORMAT_R32G32B32A32_FLOAT:
00282 return &fetch_R32G32B32A32_FLOAT;
00283
00284 case PIPE_FORMAT_R32_UNORM:
00285 return &fetch_R32_UNORM;
00286 case PIPE_FORMAT_R32G32_UNORM:
00287 return &fetch_R32G32_UNORM;
00288 case PIPE_FORMAT_R32G32B32_UNORM:
00289 return &fetch_R32G32B32_UNORM;
00290 case PIPE_FORMAT_R32G32B32A32_UNORM:
00291 return &fetch_R32G32B32A32_UNORM;
00292
00293 case PIPE_FORMAT_R32_USCALED:
00294 return &fetch_R32_USCALED;
00295 case PIPE_FORMAT_R32G32_USCALED:
00296 return &fetch_R32G32_USCALED;
00297 case PIPE_FORMAT_R32G32B32_USCALED:
00298 return &fetch_R32G32B32_USCALED;
00299 case PIPE_FORMAT_R32G32B32A32_USCALED:
00300 return &fetch_R32G32B32A32_USCALED;
00301
00302 case PIPE_FORMAT_R32_SNORM:
00303 return &fetch_R32_SNORM;
00304 case PIPE_FORMAT_R32G32_SNORM:
00305 return &fetch_R32G32_SNORM;
00306 case PIPE_FORMAT_R32G32B32_SNORM:
00307 return &fetch_R32G32B32_SNORM;
00308 case PIPE_FORMAT_R32G32B32A32_SNORM:
00309 return &fetch_R32G32B32A32_SNORM;
00310
00311 case PIPE_FORMAT_R32_SSCALED:
00312 return &fetch_R32_SSCALED;
00313 case PIPE_FORMAT_R32G32_SSCALED:
00314 return &fetch_R32G32_SSCALED;
00315 case PIPE_FORMAT_R32G32B32_SSCALED:
00316 return &fetch_R32G32B32_SSCALED;
00317 case PIPE_FORMAT_R32G32B32A32_SSCALED:
00318 return &fetch_R32G32B32A32_SSCALED;
00319
00320 case PIPE_FORMAT_R16_UNORM:
00321 return &fetch_R16_UNORM;
00322 case PIPE_FORMAT_R16G16_UNORM:
00323 return &fetch_R16G16_UNORM;
00324 case PIPE_FORMAT_R16G16B16_UNORM:
00325 return &fetch_R16G16B16_UNORM;
00326 case PIPE_FORMAT_R16G16B16A16_UNORM:
00327 return &fetch_R16G16B16A16_UNORM;
00328
00329 case PIPE_FORMAT_R16_USCALED:
00330 return &fetch_R16_USCALED;
00331 case PIPE_FORMAT_R16G16_USCALED:
00332 return &fetch_R16G16_USCALED;
00333 case PIPE_FORMAT_R16G16B16_USCALED:
00334 return &fetch_R16G16B16_USCALED;
00335 case PIPE_FORMAT_R16G16B16A16_USCALED:
00336 return &fetch_R16G16B16A16_USCALED;
00337
00338 case PIPE_FORMAT_R16_SNORM:
00339 return &fetch_R16_SNORM;
00340 case PIPE_FORMAT_R16G16_SNORM:
00341 return &fetch_R16G16_SNORM;
00342 case PIPE_FORMAT_R16G16B16_SNORM:
00343 return &fetch_R16G16B16_SNORM;
00344 case PIPE_FORMAT_R16G16B16A16_SNORM:
00345 return &fetch_R16G16B16A16_SNORM;
00346
00347 case PIPE_FORMAT_R16_SSCALED:
00348 return &fetch_R16_SSCALED;
00349 case PIPE_FORMAT_R16G16_SSCALED:
00350 return &fetch_R16G16_SSCALED;
00351 case PIPE_FORMAT_R16G16B16_SSCALED:
00352 return &fetch_R16G16B16_SSCALED;
00353 case PIPE_FORMAT_R16G16B16A16_SSCALED:
00354 return &fetch_R16G16B16A16_SSCALED;
00355
00356 case PIPE_FORMAT_R8_UNORM:
00357 return &fetch_R8_UNORM;
00358 case PIPE_FORMAT_R8G8_UNORM:
00359 return &fetch_R8G8_UNORM;
00360 case PIPE_FORMAT_R8G8B8_UNORM:
00361 return &fetch_R8G8B8_UNORM;
00362 case PIPE_FORMAT_R8G8B8A8_UNORM:
00363 return &fetch_R8G8B8A8_UNORM;
00364
00365 case PIPE_FORMAT_R8_USCALED:
00366 return &fetch_R8_USCALED;
00367 case PIPE_FORMAT_R8G8_USCALED:
00368 return &fetch_R8G8_USCALED;
00369 case PIPE_FORMAT_R8G8B8_USCALED:
00370 return &fetch_R8G8B8_USCALED;
00371 case PIPE_FORMAT_R8G8B8A8_USCALED:
00372 return &fetch_R8G8B8A8_USCALED;
00373
00374 case PIPE_FORMAT_R8_SNORM:
00375 return &fetch_R8_SNORM;
00376 case PIPE_FORMAT_R8G8_SNORM:
00377 return &fetch_R8G8_SNORM;
00378 case PIPE_FORMAT_R8G8B8_SNORM:
00379 return &fetch_R8G8B8_SNORM;
00380 case PIPE_FORMAT_R8G8B8A8_SNORM:
00381 return &fetch_R8G8B8A8_SNORM;
00382
00383 case PIPE_FORMAT_R8_SSCALED:
00384 return &fetch_R8_SSCALED;
00385 case PIPE_FORMAT_R8G8_SSCALED:
00386 return &fetch_R8G8_SSCALED;
00387 case PIPE_FORMAT_R8G8B8_SSCALED:
00388 return &fetch_R8G8B8_SSCALED;
00389 case PIPE_FORMAT_R8G8B8A8_SSCALED:
00390 return &fetch_R8G8B8A8_SSCALED;
00391
00392 case PIPE_FORMAT_A8R8G8B8_UNORM:
00393 return &fetch_A8R8G8B8_UNORM;
00394
00395 case PIPE_FORMAT_B8G8R8A8_UNORM:
00396 return &fetch_B8G8R8A8_UNORM;
00397
00398 case PIPE_FORMAT_R32_FIXED:
00399 return &fetch_R32_FIXED;
00400 case PIPE_FORMAT_R32G32_FIXED:
00401 return &fetch_R32G32_FIXED;
00402 case PIPE_FORMAT_R32G32B32_FIXED:
00403 return &fetch_R32G32B32_FIXED;
00404 case PIPE_FORMAT_R32G32B32A32_FIXED:
00405 return &fetch_R32G32B32A32_FIXED;
00406
00407 default:
00408 assert(0);
00409 return &fetch_NULL;
00410 }
00411 }
00412
00413
00414
00415
00416 static emit_func get_emit_func( enum pipe_format format )
00417 {
00418
00419 (void) emit_R32G32B32A32_FIXED;
00420 (void) emit_R32G32B32_FIXED;
00421 (void) emit_R32G32_FIXED;
00422 (void) emit_R32_FIXED;
00423
00424 switch (format) {
00425 case PIPE_FORMAT_R64_FLOAT:
00426 return &emit_R64_FLOAT;
00427 case PIPE_FORMAT_R64G64_FLOAT:
00428 return &emit_R64G64_FLOAT;
00429 case PIPE_FORMAT_R64G64B64_FLOAT:
00430 return &emit_R64G64B64_FLOAT;
00431 case PIPE_FORMAT_R64G64B64A64_FLOAT:
00432 return &emit_R64G64B64A64_FLOAT;
00433
00434 case PIPE_FORMAT_R32_FLOAT:
00435 return &emit_R32_FLOAT;
00436 case PIPE_FORMAT_R32G32_FLOAT:
00437 return &emit_R32G32_FLOAT;
00438 case PIPE_FORMAT_R32G32B32_FLOAT:
00439 return &emit_R32G32B32_FLOAT;
00440 case PIPE_FORMAT_R32G32B32A32_FLOAT:
00441 return &emit_R32G32B32A32_FLOAT;
00442
00443 case PIPE_FORMAT_R32_UNORM:
00444 return &emit_R32_UNORM;
00445 case PIPE_FORMAT_R32G32_UNORM:
00446 return &emit_R32G32_UNORM;
00447 case PIPE_FORMAT_R32G32B32_UNORM:
00448 return &emit_R32G32B32_UNORM;
00449 case PIPE_FORMAT_R32G32B32A32_UNORM:
00450 return &emit_R32G32B32A32_UNORM;
00451
00452 case PIPE_FORMAT_R32_USCALED:
00453 return &emit_R32_USCALED;
00454 case PIPE_FORMAT_R32G32_USCALED:
00455 return &emit_R32G32_USCALED;
00456 case PIPE_FORMAT_R32G32B32_USCALED:
00457 return &emit_R32G32B32_USCALED;
00458 case PIPE_FORMAT_R32G32B32A32_USCALED:
00459 return &emit_R32G32B32A32_USCALED;
00460
00461 case PIPE_FORMAT_R32_SNORM:
00462 return &emit_R32_SNORM;
00463 case PIPE_FORMAT_R32G32_SNORM:
00464 return &emit_R32G32_SNORM;
00465 case PIPE_FORMAT_R32G32B32_SNORM:
00466 return &emit_R32G32B32_SNORM;
00467 case PIPE_FORMAT_R32G32B32A32_SNORM:
00468 return &emit_R32G32B32A32_SNORM;
00469
00470 case PIPE_FORMAT_R32_SSCALED:
00471 return &emit_R32_SSCALED;
00472 case PIPE_FORMAT_R32G32_SSCALED:
00473 return &emit_R32G32_SSCALED;
00474 case PIPE_FORMAT_R32G32B32_SSCALED:
00475 return &emit_R32G32B32_SSCALED;
00476 case PIPE_FORMAT_R32G32B32A32_SSCALED:
00477 return &emit_R32G32B32A32_SSCALED;
00478
00479 case PIPE_FORMAT_R16_UNORM:
00480 return &emit_R16_UNORM;
00481 case PIPE_FORMAT_R16G16_UNORM:
00482 return &emit_R16G16_UNORM;
00483 case PIPE_FORMAT_R16G16B16_UNORM:
00484 return &emit_R16G16B16_UNORM;
00485 case PIPE_FORMAT_R16G16B16A16_UNORM:
00486 return &emit_R16G16B16A16_UNORM;
00487
00488 case PIPE_FORMAT_R16_USCALED:
00489 return &emit_R16_USCALED;
00490 case PIPE_FORMAT_R16G16_USCALED:
00491 return &emit_R16G16_USCALED;
00492 case PIPE_FORMAT_R16G16B16_USCALED:
00493 return &emit_R16G16B16_USCALED;
00494 case PIPE_FORMAT_R16G16B16A16_USCALED:
00495 return &emit_R16G16B16A16_USCALED;
00496
00497 case PIPE_FORMAT_R16_SNORM:
00498 return &emit_R16_SNORM;
00499 case PIPE_FORMAT_R16G16_SNORM:
00500 return &emit_R16G16_SNORM;
00501 case PIPE_FORMAT_R16G16B16_SNORM:
00502 return &emit_R16G16B16_SNORM;
00503 case PIPE_FORMAT_R16G16B16A16_SNORM:
00504 return &emit_R16G16B16A16_SNORM;
00505
00506 case PIPE_FORMAT_R16_SSCALED:
00507 return &emit_R16_SSCALED;
00508 case PIPE_FORMAT_R16G16_SSCALED:
00509 return &emit_R16G16_SSCALED;
00510 case PIPE_FORMAT_R16G16B16_SSCALED:
00511 return &emit_R16G16B16_SSCALED;
00512 case PIPE_FORMAT_R16G16B16A16_SSCALED:
00513 return &emit_R16G16B16A16_SSCALED;
00514
00515 case PIPE_FORMAT_R8_UNORM:
00516 return &emit_R8_UNORM;
00517 case PIPE_FORMAT_R8G8_UNORM:
00518 return &emit_R8G8_UNORM;
00519 case PIPE_FORMAT_R8G8B8_UNORM:
00520 return &emit_R8G8B8_UNORM;
00521 case PIPE_FORMAT_R8G8B8A8_UNORM:
00522 return &emit_R8G8B8A8_UNORM;
00523
00524 case PIPE_FORMAT_R8_USCALED:
00525 return &emit_R8_USCALED;
00526 case PIPE_FORMAT_R8G8_USCALED:
00527 return &emit_R8G8_USCALED;
00528 case PIPE_FORMAT_R8G8B8_USCALED:
00529 return &emit_R8G8B8_USCALED;
00530 case PIPE_FORMAT_R8G8B8A8_USCALED:
00531 return &emit_R8G8B8A8_USCALED;
00532
00533 case PIPE_FORMAT_R8_SNORM:
00534 return &emit_R8_SNORM;
00535 case PIPE_FORMAT_R8G8_SNORM:
00536 return &emit_R8G8_SNORM;
00537 case PIPE_FORMAT_R8G8B8_SNORM:
00538 return &emit_R8G8B8_SNORM;
00539 case PIPE_FORMAT_R8G8B8A8_SNORM:
00540 return &emit_R8G8B8A8_SNORM;
00541
00542 case PIPE_FORMAT_R8_SSCALED:
00543 return &emit_R8_SSCALED;
00544 case PIPE_FORMAT_R8G8_SSCALED:
00545 return &emit_R8G8_SSCALED;
00546 case PIPE_FORMAT_R8G8B8_SSCALED:
00547 return &emit_R8G8B8_SSCALED;
00548 case PIPE_FORMAT_R8G8B8A8_SSCALED:
00549 return &emit_R8G8B8A8_SSCALED;
00550
00551 case PIPE_FORMAT_A8R8G8B8_UNORM:
00552 return &emit_A8R8G8B8_UNORM;
00553
00554 case PIPE_FORMAT_B8G8R8A8_UNORM:
00555 return &emit_B8G8R8A8_UNORM;
00556
00557 default:
00558 assert(0);
00559 return &emit_NULL;
00560 }
00561 }
00562
00563
00564
00568 static void PIPE_CDECL generic_run_elts( struct translate *translate,
00569 const unsigned *elts,
00570 unsigned count,
00571 void *output_buffer )
00572 {
00573 struct translate_generic *tg = translate_generic(translate);
00574 char *vert = output_buffer;
00575 unsigned nr_attrs = tg->nr_attrib;
00576 unsigned attr;
00577 unsigned i;
00578
00579
00580
00581 for (i = 0; i < count; i++) {
00582 unsigned elt = *elts++;
00583
00584 for (attr = 0; attr < nr_attrs; attr++) {
00585 float data[4];
00586
00587 const char *src = (tg->attrib[attr].input_ptr +
00588 tg->attrib[attr].input_stride * elt);
00589
00590 char *dst = (vert +
00591 tg->attrib[attr].output_offset);
00592
00593 tg->attrib[attr].fetch( src, data );
00594
00595 if (0) debug_printf("vert %d/%d attr %d: %f %f %f %f\n",
00596 i, elt, attr, data[0], data[1], data[2], data[3]);
00597
00598 tg->attrib[attr].emit( data, dst );
00599 }
00600
00601 vert += tg->translate.key.output_stride;
00602 }
00603 }
00604
00605
00606
00607 static void PIPE_CDECL generic_run( struct translate *translate,
00608 unsigned start,
00609 unsigned count,
00610 void *output_buffer )
00611 {
00612 struct translate_generic *tg = translate_generic(translate);
00613 char *vert = output_buffer;
00614 unsigned nr_attrs = tg->nr_attrib;
00615 unsigned attr;
00616 unsigned i;
00617
00618
00619
00620 for (i = 0; i < count; i++) {
00621 unsigned elt = start + i;
00622
00623 for (attr = 0; attr < nr_attrs; attr++) {
00624 float data[4];
00625
00626 const char *src = (tg->attrib[attr].input_ptr +
00627 tg->attrib[attr].input_stride * elt);
00628
00629 char *dst = (vert +
00630 tg->attrib[attr].output_offset);
00631
00632 tg->attrib[attr].fetch( src, data );
00633
00634 if (0) debug_printf("vert %d attr %d: %f %f %f %f\n",
00635 i, attr, data[0], data[1], data[2], data[3]);
00636
00637 tg->attrib[attr].emit( data, dst );
00638 }
00639
00640 vert += tg->translate.key.output_stride;
00641 }
00642 }
00643
00644
00645
00646 static void generic_set_buffer( struct translate *translate,
00647 unsigned buf,
00648 const void *ptr,
00649 unsigned stride )
00650 {
00651 struct translate_generic *tg = translate_generic(translate);
00652 unsigned i;
00653
00654 for (i = 0; i < tg->nr_attrib; i++) {
00655 if (tg->attrib[i].buffer == buf) {
00656 tg->attrib[i].input_ptr = ((char *)ptr +
00657 tg->attrib[i].input_offset);
00658 tg->attrib[i].input_stride = stride;
00659 }
00660 }
00661 }
00662
00663
00664 static void generic_release( struct translate *translate )
00665 {
00666
00667
00668 FREE(translate);
00669 }
00670
00671 struct translate *translate_generic_create( const struct translate_key *key )
00672 {
00673 struct translate_generic *tg = CALLOC_STRUCT(translate_generic);
00674 unsigned i;
00675
00676 if (tg == NULL)
00677 return NULL;
00678
00679 tg->translate.key = *key;
00680 tg->translate.release = generic_release;
00681 tg->translate.set_buffer = generic_set_buffer;
00682 tg->translate.run_elts = generic_run_elts;
00683 tg->translate.run = generic_run;
00684
00685 for (i = 0; i < key->nr_elements; i++) {
00686
00687 tg->attrib[i].fetch = get_fetch_func(key->element[i].input_format);
00688 tg->attrib[i].buffer = key->element[i].input_buffer;
00689 tg->attrib[i].input_offset = key->element[i].input_offset;
00690
00691 tg->attrib[i].emit = get_emit_func(key->element[i].output_format);
00692 tg->attrib[i].output_offset = key->element[i].output_offset;
00693
00694 }
00695
00696 tg->nr_attrib = key->nr_elements;
00697
00698
00699 return &tg->translate;
00700 }