summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/draw/draw_pt_middle_fse.c
blob: 643ea151c1436da78740dacf51f4ffae00533ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/**************************************************************************
 * 
 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

 /*
  * Authors:
  *   Keith Whitwell <keith@tungstengraphics.com>
  */


#include "pipe/p_util.h"
#include "draw/draw_context.h"
#include "draw/draw_private.h"
#include "draw/draw_vbuf.h"
#include "draw/draw_vertex.h"
#include "draw/draw_pt.h"
#include "draw/draw_vs.h"

#include "translate/translate.h"

struct fetch_shade_emit;

struct fse_shader {
   struct translate_key key;

   void (*run_linear)( const struct fetch_shade_emit *fse,
                       unsigned start,
                       unsigned count,
                       char *buffer );

   void (*run_elts)( const struct fetch_shade_emit *fse,
                     const unsigned *fetch_elts,
                     unsigned fetch_count,
                     char *buffer );

};

/* Prototype fetch, shade, emit-hw-verts all in one go.
 */
struct fetch_shade_emit {
   struct draw_pt_middle_end base;
   struct draw_context *draw;

   struct translate_key key;

   /* Temporaries:
    */
   const float *constants;
   unsigned pitch[PIPE_MAX_ATTRIBS];
   const ubyte *src[PIPE_MAX_ATTRIBS];
   unsigned prim;

   /* Points to one of the three hardwired example shaders, below:
    */
   struct fse_shader *active;

   /* Temporary: A list of hard-wired shaders.  Of course the plan
    * would be to generate these for a given (vertex-shader,
    * translate-key) pair...
    */
   struct fse_shader shader[10];
   int nr_shaders;
};



/* Not quite passthrough yet -- we're still running the 'shader' here,
 * inlined into the vertex fetch function.
 */
static void shader0_run_linear( const struct fetch_shade_emit *fse,
                                   unsigned start,
                                   unsigned count,
                                   char *buffer )
{
   unsigned i;

   const float *m = fse->constants;
   const ubyte *xyz = fse->src[0] + start * fse->pitch[0];
   const ubyte *rgb = fse->src[1] + start * fse->pitch[1];
   const ubyte *st = fse->src[2] + start * fse->pitch[2];
   
   float *out = (float *)buffer;

   /* loop over vertex attributes (vertex shader inputs)
    */
   for (i = 0; i < count; i++) {
      {
	 const float *in = (const float *)xyz;
	 const float ix = in[0], iy = in[1], iz = in[2];

	 out[0] = m[0] * ix + m[4] * iy + m[8]  * iz + m[12];
	 out[1] = m[1] * ix + m[5] * iy + m[9]  * iz + m[13];
	 out[2] = m[2] * ix + m[6] * iy + m[10] * iz + m[14];
	 out[3] = m[3] * ix + m[7] * iy + m[11] * iz + m[15];
	 xyz += fse->pitch[0];
      }

      {
	 const float *in = (const float *)rgb;
	 out[4] = in[0];
	 out[5] = in[1];
	 out[6] = in[2];
 	 out[7] = 1.0f;
         rgb += fse->pitch[1];
      }

      {
	 const float *in = (const float *)st; 
	 out[8] = in[0];
	 out[9] = in[1];
	 out[10] = 0.0f;
 	 out[11] = 1.0f;
         st += fse->pitch[2];
      }

      out += 12;
   }
}



static void shader1_run_linear( const struct fetch_shade_emit *fse,
			   unsigned start,
			   unsigned count,
                           char *buffer )
{
   unsigned i;
   const float *m = (const float *)fse->constants;
   const ubyte *xyz = fse->src[0] + start * fse->pitch[0];
   const ubyte *rgb = fse->src[1] + start * fse->pitch[1];
   float *out = (float *)buffer;

//   debug_printf("rgb %f %f %f\n", rgb[0], rgb[1], rgb[2]);


   for (i = 0; i < count; i++) {
      {
	 const float *in = (const float *)xyz;
	 const float ix = in[0], iy = in[1], iz = in[2];

	 out[0] = m[0] * ix + m[4] * iy + m[8]  * iz + m[12];
	 out[1] = m[1] * ix + m[5] * iy + m[9]  * iz + m[13];
	 out[2] = m[2] * ix + m[6] * iy + m[10] * iz + m[14];
	 out[3] = m[3] * ix + m[7] * iy + m[11] * iz + m[15];
	 xyz += fse->pitch[0];
      }

      {
	 const float *in = (const float *)rgb;
	 out[4] = in[0];
	 out[5] = in[1];
	 out[6] = in[2];
 	 out[7] = 1.0f;
         rgb += fse->pitch[1];
      }

      out += 8;
   }
}




static void shader2_run_linear( const struct fetch_shade_emit *fse,
				unsigned start,
				unsigned count,
                                char *buffer )
{
   unsigned i;
   const float *m = (const float *)fse->constants;
   const ubyte *xyz = fse->src[0] + start * fse->pitch[0];
   const ubyte *rgb = fse->src[1] + start * fse->pitch[1];
   const float psiz = 1.0;
   float *out = (float *)buffer;


   assert(fse->pitch[1] == 0);

   for (i = 0; i < count; i++) {
      {
	 const float *in = (const float *)xyz;
	 const float ix = in[0], iy = in[1], iz = in[2];

	 out[0] = m[0] * ix + m[4] * iy + m[8]  * iz + m[12];
	 out[1] = m[1] * ix + m[5] * iy + m[9]  * iz + m[13];
	 out[2] = m[2] * ix + m[6] * iy + m[10] * iz + m[14];
	 out[3] = m[3] * ix + m[7] * iy + m[11] * iz + m[15];
	 xyz += fse->pitch[0];
      }

      {
	 const float *in = (const float *)rgb;
	 out[4] = in[0];
	 out[5] = in[1];
	 out[6] = in[2];
 	 out[7] = 1.0f;
         rgb += fse->pitch[1];
      }

      {
	 out[8] = psiz;
      }

      out += 9;
   }
}




static void shader0_run_elts( const struct fetch_shade_emit *fse,
                              const unsigned *elts,
                              unsigned count,
                              char *buffer )
{
   unsigned i;
   const float *m = fse->constants;
   float *out = (float *)buffer;


   /* loop over vertex attributes (vertex shader inputs)
    */
   for (i = 0; i < count; i++) {
      unsigned elt = elts[i];
      {
         const ubyte *xyz = fse->src[0] + elt * fse->pitch[0];
	 const float *in = (const float *)xyz;
	 const float ix = in[0], iy = in[1], iz = in[2];

	 out[0] = m[0] * ix + m[4] * iy + m[8]  * iz + m[12];
	 out[1] = m[1] * ix + m[5] * iy + m[9]  * iz + m[13];
	 out[2] = m[2] * ix + m[6] * iy + m[10] * iz + m[14];
	 out[3] = m[3] * ix + m[7] * iy + m[11] * iz + m[15];
      }

      {
         const ubyte *rgb = fse->src[1] + elt * fse->pitch[1];
	 const float *in = (const float *)rgb;
	 out[4] = in[0];
	 out[5] = in[1];
	 out[6] = in[2];
 	 out[7] = 1.0f;
      }

      {
         const ubyte *st = fse->src[2] + elt * fse->pitch[2];
	 const float *in = (const float *)st;
	 out[8] = in[0];
	 out[9] = in[1];
	 out[10] = 0.0f;
 	 out[11] = 1.0f;
      }

      out += 12;
   }
}



static void shader1_run_elts( const struct fetch_shade_emit *fse,
                              const unsigned *elts,
                              unsigned count,
                              char *buffer )
{
   unsigned i;
   const float *m = (const float *)fse->constants;
   float *out = (float *)buffer;

   for (i = 0; i < count; i++) {
      unsigned elt = elts[i];

      {
         const ubyte *xyz = fse->src[0] + elt * fse->pitch[0];
	 const float *in = (const float *)xyz;
	 const float ix = in[0], iy = in[1], iz = in[2];

	 out[0] = m[0] * ix + m[4] * iy + m[8]  * iz + m[12];
	 out[1] = m[1] * ix + m[5] * iy + m[9]  * iz + m[13];
	 out[2] = m[2] * ix + m[6] * iy + m[10] * iz + m[14];
	 out[3] = m[3] * ix + m[7] * iy + m[11] * iz + m[15];
	 xyz += fse->pitch[0];
      }

      {
         const ubyte *rgb = fse->src[1] + elt * fse->pitch[1];
	 const float *in = (const float *)rgb;
	 out[4] = in[0];
	 out[5] = in[1];
	 out[6] = in[2];
 	 out[7] = 1.0f;
         rgb += fse->pitch[1];
      }

      out += 8;
   }
}




static void shader2_run_elts( const struct fetch_shade_emit *fse,
                              const unsigned *elts,
                              unsigned count,
                              char *buffer )
{
   unsigned i;
   const float *m = (const float *)fse->constants;
   const float psiz = 1.0;
   float *out = (float *)buffer;

   for (i = 0; i < count; i++) {
      unsigned elt = elts[i];
      {
         const ubyte *xyz = fse->src[0] + elt * fse->pitch[0];
	 const float *in = (const float *)xyz;
	 const float ix = in[0], iy = in[1], iz = in[2];

	 out[0] = m[0] * ix + m[4] * iy + m[8]  * iz + m[12];
	 out[1] = m[1] * ix + m[5] * iy + m[9]  * iz + m[13];
	 out[2] = m[2] * ix + m[6] * iy + m[10] * iz + m[14];
	 out[3] = m[3] * ix + m[7] * iy + m[11] * iz + m[15];
      }

      {
         const ubyte *rgb = fse->src[1] + elt * fse->pitch[1];
	 out[4] = rgb[0];
	 out[5] = rgb[1];
	 out[6] = rgb[2];
 	 out[7] = 1.0f;
      }

      {
	 out[8] = psiz;
      }

      out += 9;
   }
}


			       
static void fse_prepare( struct draw_pt_middle_end *middle,
                         unsigned prim, 
                         unsigned opt )
{
   struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle;
   struct draw_context *draw = fse->draw;
   unsigned num_vs_inputs = draw->vs.vertex_shader->info.num_inputs;
   unsigned num_vs_outputs = draw->vs.vertex_shader->info.num_outputs;
   const struct vertex_info *vinfo;
   unsigned i;
   boolean need_psize = 0;
   

   if (draw->pt.user.elts) {
      assert(0);
      return ;
   }

   if (!draw->render->set_primitive( draw->render, 
                                     prim )) {
      assert(0);
      return;
   }

   /* Must do this after set_primitive() above:
    */
   vinfo = draw->render->get_vertex_info(draw->render);
   


   fse->key.nr_elements = MAX2(num_vs_outputs,     /* outputs - translate to hw format */
                               num_vs_inputs);     /* inputs - fetch from api format */

   fse->key.output_stride = vinfo->size * 4;
   memset(fse->key.element, 0, 
          fse->key.nr_elements * sizeof(fse->key.element[0]));

   for (i = 0; i < num_vs_inputs; i++) {
      const struct pipe_vertex_element *src = &draw->pt.vertex_element[i];
      fse->key.element[i].input_format = src->src_format;

      /* Consider ignoring these at this point, ie make generated
       * programs independent of this state:
       */
      fse->key.element[i].input_buffer = 0; //src->vertex_buffer_index;
      fse->key.element[i].input_offset = 0; //src->src_offset;
   }
   

   {
      unsigned dst_offset = 0;

      for (i = 0; i < vinfo->num_attribs; i++) {
         unsigned emit_sz = 0;
         unsigned output_format = PIPE_FORMAT_NONE;
         unsigned vs_output = vinfo->src_index[i];

         switch (vinfo->emit[i]) {
         case EMIT_4F:
            output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
            emit_sz = 4 * sizeof(float);
            break;
         case EMIT_3F:
            output_format = PIPE_FORMAT_R32G32B32_FLOAT;
            emit_sz = 3 * sizeof(float);
            break;
         case EMIT_2F:
            output_format = PIPE_FORMAT_R32G32_FLOAT;
            emit_sz = 2 * sizeof(float);
            break;
         case EMIT_1F:
            output_format = PIPE_FORMAT_R32_FLOAT;
            emit_sz = 1 * sizeof(float);
            break;
         case EMIT_1F_PSIZE:
            need_psize = 1;
            output_format = PIPE_FORMAT_R32_FLOAT;
            emit_sz = 1 * sizeof(float);
            vs_output = num_vs_outputs + 1;
         
            break;
         default:
            assert(0);
            break;
         }

         /* The elements in the key correspond to vertex shader output
          * numbers, not to positions in the hw vertex description --
          * that's handled by the output_offset field.
          */
         fse->key.element[vs_output].output_format = output_format;
         fse->key.element[vs_output].output_offset = dst_offset;
      
         dst_offset += emit_sz;
         assert(fse->key.output_stride >= dst_offset);
      }
   }

   /* To make psize work, really need to tell the vertex shader to
    * copy that value from input->output.  For 'translate' this was
    * implicit for all elements.
    */
#if 0
   if (need_psize) {
      unsigned input = num_vs_inputs + 1;
      const struct pipe_vertex_element *src = &draw->pt.vertex_element[i];
      fse->key.element[i].input_format = PIPE_FORMAT_R32_FLOAT;
      fse->key.element[i].input_buffer = 0; //nr_buffers + 1;
      fse->key.element[i].input_offset = 0; 

      fse->key.nr_elements += 1;
      
   }
#endif
   
   fse->constants = draw->pt.user.constants;

   /* Would normally look up a vertex shader and peruse its list of
    * varients somehow.  We omitted that step and put all the
    * hardcoded "shaders" into an array.  We're just making the
    * assumption that this happens to be a matching shader...  ie
    * you're running isosurf, aren't you?
    */
   fse->active = NULL;
   for (i = 0; i < fse->nr_shaders; i++) {
      if (translate_key_compare( &fse->key, &fse->shader[i].key) == 0)
         fse->active = &fse->shader[i];
   }

   if (!fse->active) {
      assert(0);
      return ;
   }

   /* Now set buffer pointers:
    */
   for (i = 0; i < num_vs_inputs; i++) {
      unsigned buf = draw->pt.vertex_element[i].vertex_buffer_index;

      fse->src[i] = ((const ubyte *) draw->pt.user.vbuffer[buf] + 
                     draw->pt.vertex_buffer[buf].buffer_offset + 
                     draw->pt.vertex_element[i].src_offset);

      fse->pitch[i] = draw->pt.vertex_buffer[buf].pitch;

   }

   
   //return TRUE;
}







static void fse_run_linear( struct draw_pt_middle_end *middle, 
                            unsigned start, 
                            unsigned count )
{
   struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle;
   struct draw_context *draw = fse->draw;

   char *hw_verts;

   /* XXX: need to flush to get prim_vbuf.c to release its allocation??
    */
   draw_do_flush( draw, DRAW_FLUSH_BACKEND );

   hw_verts = draw->render->allocate_vertices( draw->render,
                                               (ushort)fse->key.output_stride,
                                               (ushort)count );

   if (!hw_verts) {
      assert(0);
      return;
   }

   /* Single routine to fetch vertices, run shader and emit HW verts.
    * Clipping and viewport transformation are done elsewhere --
    * either by the API or on hardware, or for some other reason not
    * required...
    */
   fse->active->run_linear( fse, 
                            start, count,
                            hw_verts );

   /* Draw arrays path to avoid re-emitting index list again and
    * again.
    */
   draw->render->draw_arrays( draw->render,
                              0,
                              count );
   

   draw->render->release_vertices( draw->render, 
				   hw_verts, 
				   fse->key.output_stride, 
				   count );
}


static void
fse_run(struct draw_pt_middle_end *middle,
        const unsigned *fetch_elts,
        unsigned fetch_count,
        const ushort *draw_elts,
        unsigned draw_count )
{
   struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle;
   struct draw_context *draw = fse->draw;
   void *hw_verts;
   
   /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 
    */
   draw_do_flush( draw, DRAW_FLUSH_BACKEND );

   hw_verts = draw->render->allocate_vertices( draw->render,
                                               (ushort)fse->key.output_stride,
                                               (ushort)fetch_count );
   if (!hw_verts) {
      assert(0);
      return;
   }
         
					
   /* Single routine to fetch vertices, run shader and emit HW verts.
    */
   fse->active->run_elts( fse, 
                           fetch_elts,
                           fetch_count,
                           hw_verts );

   draw->render->draw( draw->render, 
                       draw_elts, 
                       draw_count );

   draw->render->release_vertices( draw->render, 
                                   hw_verts, 
                                   fse->key.output_stride, 
                                   fetch_count );

}


static void fse_finish( struct draw_pt_middle_end *middle )
{
}


static void
fse_destroy( struct draw_pt_middle_end *middle ) 
{
   FREE(middle);
}

struct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw )
{
   struct fetch_shade_emit *fse = CALLOC_STRUCT(fetch_shade_emit);
   if (!fse)
      return NULL;

   fse->base.prepare = fse_prepare;
   fse->base.run = fse_run;
   fse->base.run_linear = fse_run_linear;
   fse->base.finish = fse_finish;
   fse->base.destroy = fse_destroy;
   fse->draw = draw;

   fse->shader[0].run_linear = shader0_run_linear;
   fse->shader[0].run_elts = shader0_run_elts;
   fse->shader[0].key.nr_elements = 3;
   fse->shader[0].key.output_stride = 12 * sizeof(float);

   fse->shader[0].key.element[0].input_format = PIPE_FORMAT_R32G32B32_FLOAT;
   fse->shader[0].key.element[0].input_buffer = 0; 
   fse->shader[0].key.element[0].input_offset = 0; 
   fse->shader[0].key.element[0].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[0].key.element[0].output_offset = 0; 

   fse->shader[0].key.element[1].input_format = PIPE_FORMAT_R32G32B32_FLOAT;
   fse->shader[0].key.element[1].input_buffer = 0; 
   fse->shader[0].key.element[1].input_offset = 0; 
   fse->shader[0].key.element[1].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[0].key.element[1].output_offset = 16; 

   fse->shader[0].key.element[1].input_format = PIPE_FORMAT_R32G32_FLOAT;
   fse->shader[0].key.element[1].input_buffer = 0; 
   fse->shader[0].key.element[1].input_offset = 0; 
   fse->shader[0].key.element[1].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[0].key.element[1].output_offset = 32; 

   fse->shader[1].run_linear = shader1_run_linear;
   fse->shader[1].run_elts = shader1_run_elts;
   fse->shader[1].key.nr_elements = 2;
   fse->shader[1].key.output_stride = 8 * sizeof(float);

   fse->shader[1].key.element[0].input_format = PIPE_FORMAT_R32G32B32_FLOAT;
   fse->shader[1].key.element[0].input_buffer = 0; 
   fse->shader[1].key.element[0].input_offset = 0; 
   fse->shader[1].key.element[0].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[1].key.element[0].output_offset = 0; 

   fse->shader[1].key.element[1].input_format = PIPE_FORMAT_R32G32B32_FLOAT;
   fse->shader[1].key.element[1].input_buffer = 0; 
   fse->shader[1].key.element[1].input_offset = 0; 
   fse->shader[1].key.element[1].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[1].key.element[1].output_offset = 16; 

   fse->shader[2].run_linear = shader2_run_linear;
   fse->shader[2].run_elts = shader2_run_elts;
   fse->shader[2].key.nr_elements = 3;
   fse->shader[2].key.output_stride = 9 * sizeof(float);

   fse->shader[2].key.element[0].input_format = PIPE_FORMAT_R32G32B32_FLOAT;
   fse->shader[2].key.element[0].input_buffer = 0; 
   fse->shader[2].key.element[0].input_offset = 0; 
   fse->shader[2].key.element[0].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[2].key.element[0].output_offset = 0; 

   fse->shader[2].key.element[1].input_format = PIPE_FORMAT_R32G32B32_FLOAT;
   fse->shader[2].key.element[1].input_buffer = 0; 
   fse->shader[2].key.element[1].input_offset = 0; 
   fse->shader[2].key.element[1].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
   fse->shader[2].key.element[1].output_offset = 16; 

   /* psize is special 
    *    -- effectively add it here as another input!?! 
    *    -- who knows how to add it as a buffer?
    */
   fse->shader[2].key.element[2].input_format = PIPE_FORMAT_R32_FLOAT;
   fse->shader[2].key.element[2].input_buffer = 0; 
   fse->shader[2].key.element[2].input_offset = 0; 
   fse->shader[2].key.element[2].output_format = PIPE_FORMAT_R32_FLOAT;
   fse->shader[2].key.element[2].output_offset = 32; 

   fse->nr_shaders = 3;

   return &fse->base;
}