~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/gallium/drivers/softpipe/sp_state_derived.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * 
26
26
 **************************************************************************/
27
27
 
 
28
#include "util/u_inlines.h"
28
29
#include "util/u_math.h"
29
30
#include "util/u_memory.h"
 
31
#include "util/u_pstipple.h"
30
32
#include "pipe/p_shader_tokens.h"
31
33
#include "draw/draw_context.h"
32
34
#include "draw/draw_vertex.h"
64
66
 
65
67
   if (vinfo->num_attribs == 0) {
66
68
      /* compute vertex layout now */
67
 
      const struct sp_fragment_shader *spfs = softpipe->fs;
 
69
      const struct tgsi_shader_info *fsInfo = &softpipe->fs_variant->info;
68
70
      struct vertex_info *vinfo_vbuf = &softpipe->vertex_info_vbuf;
69
71
      const uint num = draw_num_shader_outputs(softpipe->draw);
70
72
      uint i;
84
86
       * from the vertex shader.
85
87
       */
86
88
      vinfo->num_attribs = 0;
87
 
      for (i = 0; i < spfs->info.num_inputs; i++) {
 
89
      for (i = 0; i < fsInfo->num_inputs; i++) {
88
90
         int src;
89
91
         enum interp_mode interp;
90
92
 
91
 
         switch (spfs->info.input_interpolate[i]) {
 
93
         switch (fsInfo->input_interpolate[i]) {
92
94
         case TGSI_INTERPOLATE_CONSTANT:
93
95
            interp = INTERP_CONSTANT;
94
96
            break;
98
100
         case TGSI_INTERPOLATE_PERSPECTIVE:
99
101
            interp = INTERP_PERSPECTIVE;
100
102
            break;
 
103
         case TGSI_INTERPOLATE_COLOR:
 
104
            assert(fsInfo->input_semantic_name[i] == TGSI_SEMANTIC_COLOR);
 
105
            break;
101
106
         default:
102
107
            assert(0);
103
108
            interp = INTERP_LINEAR;
104
109
         }
105
110
 
106
 
         switch (spfs->info.input_semantic_name[i]) {
 
111
         switch (fsInfo->input_semantic_name[i]) {
107
112
         case TGSI_SEMANTIC_POSITION:
108
113
            interp = INTERP_POS;
109
114
            break;
110
115
 
111
116
         case TGSI_SEMANTIC_COLOR:
112
 
            if (softpipe->rasterizer->flatshade) {
113
 
               interp = INTERP_CONSTANT;
 
117
            if (fsInfo->input_interpolate[i] == TGSI_INTERPOLATE_COLOR) {
 
118
               if (softpipe->rasterizer->flatshade)
 
119
                  interp = INTERP_CONSTANT;
 
120
               else
 
121
                  interp = INTERP_PERSPECTIVE;
114
122
            }
115
123
            break;
116
124
         }
117
125
 
118
126
         /* this includes texcoords and varying vars */
119
127
         src = draw_find_shader_output(softpipe->draw,
120
 
                                       spfs->info.input_semantic_name[i],
121
 
                                       spfs->info.input_semantic_index[i]);
 
128
                                       fsInfo->input_semantic_name[i],
 
129
                                       fsInfo->input_semantic_index[i]);
 
130
         if (fsInfo->input_semantic_name[i] == TGSI_SEMANTIC_COLOR && src == 0)
 
131
           /* try and find a bcolor */
 
132
           src = draw_find_shader_output(softpipe->draw,
 
133
                                         TGSI_SEMANTIC_BCOLOR, fsInfo->input_semantic_index[i]);
 
134
 
122
135
         draw_emit_vertex_attr(vinfo, EMIT_4F, interp, src);
123
136
      }
124
137
 
241
254
}
242
255
 
243
256
 
 
257
static void
 
258
update_fragment_shader(struct softpipe_context *softpipe, unsigned prim)
 
259
{
 
260
   struct sp_fragment_shader_variant_key key;
 
261
 
 
262
   memset(&key, 0, sizeof(key));
 
263
 
 
264
   if (prim == PIPE_PRIM_TRIANGLES)
 
265
      key.polygon_stipple = softpipe->rasterizer->poly_stipple_enable;
 
266
 
 
267
   if (softpipe->fs) {
 
268
      softpipe->fs_variant = softpipe_find_fs_variant(softpipe,
 
269
                                                      softpipe->fs, &key);
 
270
   }
 
271
   else {
 
272
      softpipe->fs_variant = NULL;
 
273
   }
 
274
 
 
275
   /* This would be the logical place to pass the fragment shader
 
276
    * to the draw module.  However, doing this here, during state
 
277
    * validation, causes problems with the 'draw' module helpers for
 
278
    * wide/AA/stippled lines.
 
279
    * In principle, the draw's fragment shader should be per-variant
 
280
    * but that doesn't work.  So we use a single draw fragment shader
 
281
    * per fragment shader, not per variant.
 
282
    */
 
283
#if 0
 
284
   if (softpipe->fs_variant) {
 
285
      draw_bind_fragment_shader(softpipe->draw,
 
286
                                softpipe->fs_variant->draw_shader);
 
287
   }
 
288
   else {
 
289
      draw_bind_fragment_shader(softpipe->draw, NULL);
 
290
   }
 
291
#endif
 
292
}
 
293
 
 
294
 
 
295
/**
 
296
 * This should be called when the polygon stipple pattern changes.
 
297
 * We create a new texture from the stipple pattern and create a new
 
298
 * sampler view.
 
299
 */
 
300
static void
 
301
update_polygon_stipple_pattern(struct softpipe_context *softpipe)
 
302
{
 
303
   struct pipe_resource *tex;
 
304
   struct pipe_sampler_view *view;
 
305
 
 
306
   tex = util_pstipple_create_stipple_texture(&softpipe->pipe,
 
307
                                              softpipe->poly_stipple.stipple);
 
308
   pipe_resource_reference(&softpipe->pstipple.texture, tex);
 
309
   pipe_resource_reference(&tex, NULL);
 
310
 
 
311
   view = util_pstipple_create_sampler_view(&softpipe->pipe,
 
312
                                            softpipe->pstipple.texture);
 
313
   pipe_sampler_view_reference(&softpipe->pstipple.sampler_view, view);
 
314
   pipe_sampler_view_reference(&view, NULL);
 
315
}
 
316
 
 
317
 
 
318
/**
 
319
 * Should be called when polygon stipple is enabled/disabled or when
 
320
 * the fragment shader changes.
 
321
 * We add/update the fragment sampler and sampler views to sample from
 
322
 * the polygon stipple texture.  The texture unit that we use depends on
 
323
 * the fragment shader (we need to use a unit not otherwise used by the
 
324
 * shader).
 
325
 */
 
326
static void
 
327
update_polygon_stipple_enable(struct softpipe_context *softpipe, unsigned prim)
 
328
{
 
329
   if (prim == PIPE_PRIM_TRIANGLES &&
 
330
       softpipe->fs_variant->key.polygon_stipple) {
 
331
      const unsigned unit = softpipe->fs_variant->stipple_sampler_unit;
 
332
 
 
333
      assert(unit >= softpipe->num_fragment_samplers);
 
334
 
 
335
      /* sampler state */
 
336
      softpipe->fragment_samplers[unit] = softpipe->pstipple.sampler;
 
337
 
 
338
      /* sampler view */
 
339
      pipe_sampler_view_reference(&softpipe->fragment_sampler_views[unit],
 
340
                                  softpipe->pstipple.sampler_view);
 
341
 
 
342
      sp_tex_tile_cache_set_sampler_view(softpipe->fragment_tex_cache[unit],
 
343
                                         softpipe->pstipple.sampler_view);
 
344
 
 
345
      softpipe->dirty |= SP_NEW_SAMPLER;
 
346
   }
 
347
}
 
348
 
 
349
 
244
350
/* Hopefully this will remain quite simple, otherwise need to pull in
245
351
 * something like the state tracker mechanism.
246
352
 */
247
 
void softpipe_update_derived( struct softpipe_context *softpipe )
 
353
void
 
354
softpipe_update_derived(struct softpipe_context *softpipe, unsigned prim)
248
355
{
249
356
   struct softpipe_screen *sp_screen = softpipe_screen(softpipe->pipe.screen);
250
357
 
254
361
      softpipe->tex_timestamp = sp_screen->timestamp;
255
362
      softpipe->dirty |= SP_NEW_TEXTURE;
256
363
   }
257
 
      
 
364
 
 
365
#if DO_PSTIPPLE_IN_HELPER_MODULE
 
366
   if (softpipe->dirty & SP_NEW_STIPPLE)
 
367
      /* before updating samplers! */
 
368
      update_polygon_stipple_pattern(softpipe);
 
369
#endif
 
370
 
 
371
   if (softpipe->dirty & (SP_NEW_RASTERIZER |
 
372
                          SP_NEW_FS))
 
373
      update_fragment_shader(softpipe, prim);
 
374
 
 
375
#if DO_PSTIPPLE_IN_HELPER_MODULE
 
376
   if (softpipe->dirty & (SP_NEW_RASTERIZER |
 
377
                          SP_NEW_STIPPLE |
 
378
                          SP_NEW_FS))
 
379
      update_polygon_stipple_enable(softpipe, prim);
 
380
#endif
 
381
 
258
382
   if (softpipe->dirty & (SP_NEW_SAMPLER |
259
383
                          SP_NEW_TEXTURE |
260
384
                          SP_NEW_FS |