~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/gallium/drivers/r300/r300_fs.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "util/u_memory.h"
27
27
 
28
28
#include "tgsi/tgsi_dump.h"
 
29
#include "tgsi/tgsi_ureg.h"
29
30
 
 
31
#include "r300_cb.h"
30
32
#include "r300_context.h"
 
33
#include "r300_emit.h"
31
34
#include "r300_screen.h"
32
35
#include "r300_fs.h"
 
36
#include "r300_reg.h"
33
37
#include "r300_tgsi_to_rc.h"
34
38
 
35
39
#include "radeon_code.h"
68
72
                fs_inputs->wpos = i;
69
73
                break;
70
74
 
 
75
            case TGSI_SEMANTIC_FACE:
 
76
                assert(index == 0);
 
77
                fs_inputs->face = i;
 
78
                break;
 
79
 
71
80
            default:
72
 
                assert(0);
 
81
                fprintf(stderr, "r300: FP: Unknown input semantic: %i\n",
 
82
                        info->input_semantic_name[i]);
73
83
        }
74
84
    }
75
85
}
76
86
 
77
87
static void find_output_registers(struct r300_fragment_program_compiler * compiler,
78
 
                                  struct r300_fragment_shader * fs)
 
88
                                  struct r300_fragment_shader_code *shader)
79
89
{
80
90
    unsigned i, colorbuf_count = 0;
81
91
 
82
92
    /* Mark the outputs as not present initially */
83
 
    compiler->OutputColor[0] = fs->info.num_outputs;
84
 
    compiler->OutputColor[1] = fs->info.num_outputs;
85
 
    compiler->OutputColor[2] = fs->info.num_outputs;
86
 
    compiler->OutputColor[3] = fs->info.num_outputs;
87
 
    compiler->OutputDepth = fs->info.num_outputs;
 
93
    compiler->OutputColor[0] = shader->info.num_outputs;
 
94
    compiler->OutputColor[1] = shader->info.num_outputs;
 
95
    compiler->OutputColor[2] = shader->info.num_outputs;
 
96
    compiler->OutputColor[3] = shader->info.num_outputs;
 
97
    compiler->OutputDepth = shader->info.num_outputs;
88
98
 
89
99
    /* Now see where they really are. */
90
 
    for(i = 0; i < fs->info.num_outputs; ++i) {
91
 
        switch(fs->info.output_semantic_name[i]) {
 
100
    for(i = 0; i < shader->info.num_outputs; ++i) {
 
101
        switch(shader->info.output_semantic_name[i]) {
92
102
            case TGSI_SEMANTIC_COLOR:
93
103
                compiler->OutputColor[colorbuf_count] = i;
94
104
                colorbuf_count++;
115
125
            allocate(mydata, inputs->color[i], reg++);
116
126
        }
117
127
    }
 
128
    if (inputs->face != ATTR_UNUSED) {
 
129
        allocate(mydata, inputs->face, reg++);
 
130
    }
118
131
    for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
119
132
        if (inputs->generic[i] != ATTR_UNUSED) {
120
133
            allocate(mydata, inputs->generic[i], reg++);
128
141
    }
129
142
}
130
143
 
131
 
static void get_compare_state(
 
144
static void get_external_state(
132
145
    struct r300_context* r300,
133
 
    struct r300_fragment_program_external_state* state,
134
 
    unsigned shadow_samplers)
 
146
    struct r300_fragment_program_external_state* state)
135
147
{
136
 
    struct r300_textures_state *texstate =
137
 
        (struct r300_textures_state*)r300->textures_state.state;
138
 
 
139
 
    memset(state, 0, sizeof(*state));
140
 
 
141
 
    for (int i = 0; i < texstate->sampler_count; i++) {
 
148
    struct r300_textures_state *texstate = r300->textures_state.state;
 
149
    unsigned i;
 
150
    unsigned char *swizzle;
 
151
 
 
152
    for (i = 0; i < texstate->sampler_state_count; i++) {
142
153
        struct r300_sampler_state* s = texstate->sampler_states[i];
143
154
 
144
 
        if (s && s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
145
 
            /* XXX Gallium doesn't provide us with any information regarding
146
 
             * this mode, so we are screwed. I'm setting 0 = LUMINANCE. */
147
 
            state->unit[i].depth_texture_mode = 0;
 
155
        if (!s) {
 
156
            continue;
 
157
        }
 
158
 
 
159
        if (s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
 
160
            state->unit[i].compare_mode_enabled = 1;
 
161
 
 
162
            /* Pass depth texture swizzling to the compiler. */
 
163
            if (texstate->sampler_views[i]) {
 
164
                swizzle = texstate->sampler_views[i]->swizzle;
 
165
 
 
166
                state->unit[i].depth_texture_swizzle =
 
167
                    RC_MAKE_SWIZZLE(swizzle[0], swizzle[1],
 
168
                                    swizzle[2], swizzle[3]);
 
169
            } else {
 
170
                state->unit[i].depth_texture_swizzle = RC_SWIZZLE_XYZW;
 
171
            }
148
172
 
149
173
            /* Fortunately, no need to translate this. */
150
174
            state->unit[i].texture_compare_func = s->state.compare_func;
151
175
        }
 
176
 
 
177
        state->unit[i].non_normalized_coords = !s->state.normalized_coords;
 
178
 
 
179
        if (texstate->sampler_views[i]) {
 
180
            struct r300_texture *t;
 
181
            t = (struct r300_texture*)texstate->sampler_views[i]->base.texture;
 
182
 
 
183
            /* XXX this should probably take into account STR, not just S. */
 
184
            if (t->desc.is_npot) {
 
185
                switch (s->state.wrap_s) {
 
186
                    case PIPE_TEX_WRAP_REPEAT:
 
187
                        state->unit[i].wrap_mode = RC_WRAP_REPEAT;
 
188
                        state->unit[i].fake_npot = TRUE;
 
189
                        break;
 
190
 
 
191
                    case PIPE_TEX_WRAP_MIRROR_REPEAT:
 
192
                        state->unit[i].wrap_mode = RC_WRAP_MIRRORED_REPEAT;
 
193
                        state->unit[i].fake_npot = TRUE;
 
194
                        break;
 
195
 
 
196
                    case PIPE_TEX_WRAP_MIRROR_CLAMP:
 
197
                    case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
 
198
                    case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
 
199
                        state->unit[i].wrap_mode = RC_WRAP_MIRRORED_CLAMP;
 
200
                        state->unit[i].fake_npot = TRUE;
 
201
                        break;
 
202
 
 
203
                    default:
 
204
                        state->unit[i].wrap_mode = RC_WRAP_NONE;
 
205
                        break;
 
206
                }
 
207
            }
 
208
        }
152
209
    }
153
210
}
154
211
 
155
212
static void r300_translate_fragment_shader(
156
213
    struct r300_context* r300,
 
214
    struct r300_fragment_shader_code* shader,
 
215
    const struct tgsi_token *tokens);
 
216
 
 
217
static void r300_dummy_fragment_shader(
 
218
    struct r300_context* r300,
157
219
    struct r300_fragment_shader_code* shader)
158
220
{
159
 
    struct r300_fragment_shader* fs = r300->fs;
 
221
    struct pipe_shader_state state;
 
222
    struct ureg_program *ureg;
 
223
    struct ureg_dst out;
 
224
    struct ureg_src imm;
 
225
 
 
226
    /* Make a simple fragment shader which outputs (0, 0, 0, 1) */
 
227
    ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
 
228
    out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0);
 
229
    imm = ureg_imm4f(ureg, 0, 0, 0, 1);
 
230
 
 
231
    ureg_MOV(ureg, out, imm);
 
232
    ureg_END(ureg);
 
233
 
 
234
    state.tokens = ureg_finalize(ureg);
 
235
 
 
236
    shader->dummy = TRUE;
 
237
    r300_translate_fragment_shader(r300, shader, state.tokens);
 
238
 
 
239
    ureg_destroy(ureg);
 
240
}
 
241
 
 
242
static void r300_emit_fs_code_to_buffer(
 
243
    struct r300_context *r300,
 
244
    struct r300_fragment_shader_code *shader)
 
245
{
 
246
    struct rX00_fragment_program_code *generic_code = &shader->code;
 
247
    unsigned imm_count = shader->immediates_count;
 
248
    unsigned imm_first = shader->externals_count;
 
249
    unsigned imm_end = generic_code->constants.Count;
 
250
    struct rc_constant *constants = generic_code->constants.Constants;
 
251
    unsigned i;
 
252
    CB_LOCALS;
 
253
 
 
254
    if (r300->screen->caps.is_r500) {
 
255
        struct r500_fragment_program_code *code = &generic_code->code.r500;
 
256
 
 
257
        shader->cb_code_size = 19 +
 
258
                               ((code->inst_end + 1) * 6) +
 
259
                               imm_count * 7 +
 
260
                               code->int_constant_count * 2;
 
261
 
 
262
        NEW_CB(shader->cb_code, shader->cb_code_size);
 
263
        OUT_CB_REG(R500_US_CONFIG, R500_ZERO_TIMES_ANYTHING_EQUALS_ZERO);
 
264
        OUT_CB_REG(R500_US_PIXSIZE, code->max_temp_idx);
 
265
        OUT_CB_REG(R500_US_FC_CTRL, code->us_fc_ctrl);
 
266
        for(i = 0; i < code->int_constant_count; i++){
 
267
                OUT_CB_REG(R500_US_FC_INT_CONST_0 + (i * 4),
 
268
                                                code->int_constants[i]);
 
269
        }
 
270
        OUT_CB_REG(R500_US_CODE_RANGE,
 
271
                   R500_US_CODE_RANGE_ADDR(0) | R500_US_CODE_RANGE_SIZE(code->inst_end));
 
272
        OUT_CB_REG(R500_US_CODE_OFFSET, 0);
 
273
        OUT_CB_REG(R500_US_CODE_ADDR,
 
274
                   R500_US_CODE_START_ADDR(0) | R500_US_CODE_END_ADDR(code->inst_end));
 
275
 
 
276
        OUT_CB_REG(R500_GA_US_VECTOR_INDEX, R500_GA_US_VECTOR_INDEX_TYPE_INSTR);
 
277
        OUT_CB_ONE_REG(R500_GA_US_VECTOR_DATA, (code->inst_end + 1) * 6);
 
278
        for (i = 0; i <= code->inst_end; i++) {
 
279
            OUT_CB(code->inst[i].inst0);
 
280
            OUT_CB(code->inst[i].inst1);
 
281
            OUT_CB(code->inst[i].inst2);
 
282
            OUT_CB(code->inst[i].inst3);
 
283
            OUT_CB(code->inst[i].inst4);
 
284
            OUT_CB(code->inst[i].inst5);
 
285
        }
 
286
 
 
287
        /* Emit immediates. */
 
288
        if (imm_count) {
 
289
            for(i = imm_first; i < imm_end; ++i) {
 
290
                if (constants[i].Type == RC_CONSTANT_IMMEDIATE) {
 
291
                    const float *data = constants[i].u.Immediate;
 
292
 
 
293
                    OUT_CB_REG(R500_GA_US_VECTOR_INDEX,
 
294
                               R500_GA_US_VECTOR_INDEX_TYPE_CONST |
 
295
                               (i & R500_GA_US_VECTOR_INDEX_MASK));
 
296
                    OUT_CB_ONE_REG(R500_GA_US_VECTOR_DATA, 4);
 
297
                    OUT_CB_TABLE(data, 4);
 
298
                }
 
299
            }
 
300
        }
 
301
    } else { /* r300 */
 
302
        struct r300_fragment_program_code *code = &generic_code->code.r300;
 
303
 
 
304
        shader->cb_code_size = 19 +
 
305
                               (r300->screen->caps.is_r400 ? 2 : 0) +
 
306
                               code->alu.length * 4 +
 
307
                               (code->tex.length ? (1 + code->tex.length) : 0) +
 
308
                               imm_count * 5;
 
309
 
 
310
        NEW_CB(shader->cb_code, shader->cb_code_size);
 
311
 
 
312
        if (r300->screen->caps.is_r400)
 
313
            OUT_CB_REG(R400_US_CODE_BANK, 0);
 
314
 
 
315
        OUT_CB_REG(R300_US_CONFIG, code->config);
 
316
        OUT_CB_REG(R300_US_PIXSIZE, code->pixsize);
 
317
        OUT_CB_REG(R300_US_CODE_OFFSET, code->code_offset);
 
318
 
 
319
        OUT_CB_REG_SEQ(R300_US_CODE_ADDR_0, 4);
 
320
        OUT_CB_TABLE(code->code_addr, 4);
 
321
 
 
322
        OUT_CB_REG_SEQ(R300_US_ALU_RGB_INST_0, code->alu.length);
 
323
        for (i = 0; i < code->alu.length; i++)
 
324
            OUT_CB(code->alu.inst[i].rgb_inst);
 
325
 
 
326
        OUT_CB_REG_SEQ(R300_US_ALU_RGB_ADDR_0, code->alu.length);
 
327
        for (i = 0; i < code->alu.length; i++)
 
328
            OUT_CB(code->alu.inst[i].rgb_addr);
 
329
 
 
330
        OUT_CB_REG_SEQ(R300_US_ALU_ALPHA_INST_0, code->alu.length);
 
331
        for (i = 0; i < code->alu.length; i++)
 
332
            OUT_CB(code->alu.inst[i].alpha_inst);
 
333
 
 
334
        OUT_CB_REG_SEQ(R300_US_ALU_ALPHA_ADDR_0, code->alu.length);
 
335
        for (i = 0; i < code->alu.length; i++)
 
336
            OUT_CB(code->alu.inst[i].alpha_addr);
 
337
 
 
338
        if (code->tex.length) {
 
339
            OUT_CB_REG_SEQ(R300_US_TEX_INST_0, code->tex.length);
 
340
            OUT_CB_TABLE(code->tex.inst, code->tex.length);
 
341
        }
 
342
 
 
343
        /* Emit immediates. */
 
344
        if (imm_count) {
 
345
            for(i = imm_first; i < imm_end; ++i) {
 
346
                if (constants[i].Type == RC_CONSTANT_IMMEDIATE) {
 
347
                    const float *data = constants[i].u.Immediate;
 
348
 
 
349
                    OUT_CB_REG_SEQ(R300_PFS_PARAM_0_X + i * 16, 4);
 
350
                    OUT_CB(pack_float24(data[0]));
 
351
                    OUT_CB(pack_float24(data[1]));
 
352
                    OUT_CB(pack_float24(data[2]));
 
353
                    OUT_CB(pack_float24(data[3]));
 
354
                }
 
355
            }
 
356
        }
 
357
    }
 
358
 
 
359
    OUT_CB_REG(R300_FG_DEPTH_SRC, shader->fg_depth_src);
 
360
    OUT_CB_REG(R300_US_W_FMT, shader->us_out_w);
 
361
    END_CB;
 
362
}
 
363
 
 
364
static void r300_translate_fragment_shader(
 
365
    struct r300_context* r300,
 
366
    struct r300_fragment_shader_code* shader,
 
367
    const struct tgsi_token *tokens)
 
368
{
160
369
    struct r300_fragment_program_compiler compiler;
161
370
    struct tgsi_to_rc ttr;
162
 
    int wpos = fs->inputs.wpos;
 
371
    int wpos, face;
 
372
    unsigned i;
 
373
 
 
374
    tgsi_scan_shader(tokens, &shader->info);
 
375
    r300_shader_read_fs_inputs(&shader->info, &shader->inputs);
 
376
 
 
377
    wpos = shader->inputs.wpos;
 
378
    face = shader->inputs.face;
163
379
 
164
380
    /* Setup the compiler. */
165
381
    memset(&compiler, 0, sizeof(compiler));
168
384
 
169
385
    compiler.code = &shader->code;
170
386
    compiler.state = shader->compare_state;
171
 
    compiler.is_r500 = r300_screen(r300->context.screen)->caps->is_r500;
 
387
    compiler.Base.is_r500 = r300->screen->caps.is_r500;
 
388
    compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT);
 
389
    compiler.Base.has_half_swizzles = TRUE;
 
390
    compiler.Base.max_temp_regs = compiler.Base.is_r500 ? 128 : 32;
 
391
    compiler.Base.max_constants = compiler.Base.is_r500 ? 256 : 32;
 
392
    compiler.Base.max_alu_insts = compiler.Base.is_r500 ? 512 : 64;
 
393
    compiler.Base.remove_unused_constants = TRUE;
172
394
    compiler.AllocateHwInputs = &allocate_hardware_inputs;
173
 
    compiler.UserData = &fs->inputs;
 
395
    compiler.UserData = &shader->inputs;
174
396
 
175
 
    find_output_registers(&compiler, fs);
 
397
    find_output_registers(&compiler, shader);
176
398
 
177
399
    if (compiler.Base.Debug) {
178
 
        debug_printf("r300: Initial fragment program\n");
179
 
        tgsi_dump(fs->state.tokens, 0);
 
400
        DBG(r300, DBG_FP, "r300: Initial fragment program\n");
 
401
        tgsi_dump(tokens, 0);
180
402
    }
181
403
 
182
404
    /* Translate TGSI to our internal representation */
183
405
    ttr.compiler = &compiler.Base;
184
 
    ttr.info = &fs->info;
 
406
    ttr.info = &shader->info;
185
407
    ttr.use_half_swizzles = TRUE;
186
408
 
187
 
    r300_tgsi_to_rc(&ttr, fs->state.tokens);
188
 
 
189
 
    fs->shadow_samplers = compiler.Base.Program.ShadowSamplers;
 
409
    r300_tgsi_to_rc(&ttr, tokens);
190
410
 
191
411
    /**
192
412
     * Transform the program to support WPOS.
200
420
        rc_transform_fragment_wpos(&compiler.Base, wpos, wpos, TRUE);
201
421
    }
202
422
 
 
423
    if (face != ATTR_UNUSED) {
 
424
        rc_transform_fragment_face(&compiler.Base, face);
 
425
    }
 
426
 
203
427
    /* Invoke the compiler */
204
428
    r3xx_compile_fragment_program(&compiler);
 
429
 
205
430
    if (compiler.Base.Error) {
206
 
        /* XXX failover maybe? */
207
 
        DBG(r300, DBG_FP, "r300: Error compiling fragment program: %s\n",
208
 
            compiler.Base.ErrorMsg);
209
 
        assert(0);
 
431
        fprintf(stderr, "r300 FP: Compiler Error:\n%sUsing a dummy shader"
 
432
                " instead.\n", compiler.Base.ErrorMsg);
 
433
 
 
434
        if (shader->dummy) {
 
435
            fprintf(stderr, "r300 FP: Cannot compile the dummy shader! "
 
436
                    "Giving up...\n");
 
437
            abort();
 
438
        }
 
439
 
 
440
        rc_destroy(&compiler.Base);
 
441
        r300_dummy_fragment_shader(r300, shader);
 
442
        return;
 
443
    }
 
444
 
 
445
    /* Shaders with zero instructions are invalid,
 
446
     * use the dummy shader instead. */
 
447
    if (shader->code.code.r500.inst_end == -1) {
 
448
        rc_destroy(&compiler.Base);
 
449
        r300_dummy_fragment_shader(r300, shader);
 
450
        return;
 
451
    }
 
452
 
 
453
    /* Initialize numbers of constants for each type. */
 
454
    shader->externals_count = 0;
 
455
    for (i = 0;
 
456
         i < shader->code.constants.Count &&
 
457
         shader->code.constants.Constants[i].Type == RC_CONSTANT_EXTERNAL; i++) {
 
458
        shader->externals_count = i+1;
 
459
    }
 
460
    shader->immediates_count = 0;
 
461
    shader->rc_state_count = 0;
 
462
 
 
463
    for (i = shader->externals_count; i < shader->code.constants.Count; i++) {
 
464
        switch (shader->code.constants.Constants[i].Type) {
 
465
            case RC_CONSTANT_IMMEDIATE:
 
466
                ++shader->immediates_count;
 
467
                break;
 
468
            case RC_CONSTANT_STATE:
 
469
                ++shader->rc_state_count;
 
470
                break;
 
471
            default:
 
472
                assert(0);
 
473
        }
 
474
    }
 
475
 
 
476
    /* Setup shader depth output. */
 
477
    if (shader->code.writes_depth) {
 
478
        shader->fg_depth_src = R300_FG_DEPTH_SRC_SHADER;
 
479
        shader->us_out_w = R300_W_FMT_W24 | R300_W_SRC_US;
 
480
    } else {
 
481
        shader->fg_depth_src = R300_FG_DEPTH_SRC_SCAN;
 
482
        shader->us_out_w = R300_W_FMT_W0 | R300_W_SRC_US;
210
483
    }
211
484
 
212
485
    /* And, finally... */
213
486
    rc_destroy(&compiler.Base);
 
487
 
 
488
    /* Build the command buffer. */
 
489
    r300_emit_fs_code_to_buffer(r300, shader);
214
490
}
215
491
 
216
492
boolean r300_pick_fragment_shader(struct r300_context* r300)
217
493
{
218
 
    struct r300_fragment_shader* fs = r300->fs;
219
 
    struct r300_fragment_program_external_state state;
 
494
    struct r300_fragment_shader* fs = r300_fs(r300);
 
495
    struct r300_fragment_program_external_state state = {{{ 0 }}};
220
496
    struct r300_fragment_shader_code* ptr;
221
497
 
 
498
    get_external_state(r300, &state);
 
499
 
222
500
    if (!fs->first) {
223
501
        /* Build the fragment shader for the first time. */
224
502
        fs->first = fs->shader = CALLOC_STRUCT(r300_fragment_shader_code);
225
503
 
226
 
        /* BTW shadow samplers will be known after the first translation,
227
 
         * therefore we set ~0, which means it should look at all sampler
228
 
         * states. This choice doesn't have any impact on the correctness. */
229
 
        get_compare_state(r300, &fs->shader->compare_state, ~0);
230
 
        r300_translate_fragment_shader(r300, fs->shader);
 
504
        memcpy(&fs->shader->compare_state, &state,
 
505
            sizeof(struct r300_fragment_program_external_state));
 
506
        r300_translate_fragment_shader(r300, fs->shader, fs->state.tokens);
231
507
        return TRUE;
232
508
 
233
 
    } else if (fs->shadow_samplers) {
234
 
        get_compare_state(r300, &state, fs->shadow_samplers);
235
 
 
 
509
    } else {
236
510
        /* Check if the currently-bound shader has been compiled
237
511
         * with the texture-compare state we need. */
238
512
        if (memcmp(&fs->shader->compare_state, &state, sizeof(state)) != 0) {
240
514
            ptr = fs->first;
241
515
            while (ptr) {
242
516
                if (memcmp(&ptr->compare_state, &state, sizeof(state)) == 0) {
243
 
                    fs->shader = ptr;
244
 
                    return TRUE;
 
517
                    if (fs->shader != ptr) {
 
518
                        fs->shader = ptr;
 
519
                        return TRUE;
 
520
                    }
 
521
                    /* The currently-bound one is OK. */
 
522
                    return FALSE;
245
523
                }
246
524
                ptr = ptr->next;
247
525
            }
252
530
            fs->first = fs->shader = ptr;
253
531
 
254
532
            ptr->compare_state = state;
255
 
            r300_translate_fragment_shader(r300, ptr);
 
533
            r300_translate_fragment_shader(r300, ptr, fs->state.tokens);
256
534
            return TRUE;
257
535
        }
258
536
    }