r300g: fix breakage after the gallium-sampler-view merge
authorMarek Olšák <maraeo@gmail.com>
Fri, 19 Mar 2010 00:13:57 +0000 (01:13 +0100)
committerMarek Olšák <maraeo@gmail.com>
Fri, 19 Mar 2010 03:09:07 +0000 (04:09 +0100)
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_derived.c

index 5522fb306db68b99915a289a1f1f058508841977..c897df628d2ea3cc31f4b641e2171b3c80c23ca8 100644 (file)
@@ -1050,9 +1050,11 @@ validate:
     }
     /* ...textures... */
     for (i = 0; i < texstate->count; i++) {
-        tex = (struct r300_texture*)texstate->fragment_sampler_views[i]->texture;
-        if (!tex || !texstate->sampler_states[i])
+        if (!(texstate->tx_enable & (1 << i))) {
             continue;
+        }
+
+        tex = (struct r300_texture*)texstate->fragment_sampler_views[i]->texture;
         if (!r300_add_texture(r300->rws, tex,
                              RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) {
             r300->context.flush(&r300->context, 0, NULL);
index db7844eef0e5378f98126f2f4c3939a561d6b8b8..bdfe74ed2a046f5f54f5c164b7bea76e3609f884 100644 (file)
@@ -973,6 +973,7 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
     struct r300_context* r300 = r300_context(pipe);
     struct r300_textures_state* state =
         (struct r300_textures_state*)r300->textures_state.state;
+    struct r300_texture *texture;
     unsigned i;
     boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500;
     boolean dirty_tex = FALSE;
@@ -984,15 +985,18 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
 
     for (i = 0; i < count; i++) {
         if (state->fragment_sampler_views[i] != views[i]) {
-            struct r300_texture *texture;
             pipe_sampler_view_reference(&state->fragment_sampler_views[i],
                                         views[i]);
-            dirty_tex = TRUE;
 
-            texture = (struct r300_texture *)views[i]->texture;
+            if (!views[i]) {
+                continue;
+            }
+
+            /* A new sampler view (= texture)... */
+            dirty_tex = TRUE;
 
             /* R300-specific - set the texrect factor in the fragment shader */
+            texture = (struct r300_texture *)views[i]->texture;
             if (!is_r500 && texture->is_npot) {
                 /* XXX It would be nice to re-emit just 1 constant,
                  * XXX not all of them */
index 74663bda514c5a536b101f4b5e49f94c6bcc0fb9..85947353ee921e7c994d0618602d66c053514a03 100644 (file)
@@ -335,20 +335,25 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
         (struct r300_textures_state*)r300->textures_state.state;
     struct r300_texture_sampler_state *texstate;
     struct r300_sampler_state *sampler;
+    struct pipe_sampler_view *view;
     struct r300_texture *tex;
     unsigned min_level, max_level, i, size;
     unsigned count = MIN2(state->texture_count, state->sampler_count);
 
     state->tx_enable = 0;
+    state->count = 0;
     size = 2;
 
     for (i = 0; i < count; i++) {
         if (state->fragment_sampler_views[i] && state->sampler_states[i]) {
             state->tx_enable |= 1 << i;
 
-            tex = (struct r300_texture *)state->fragment_sampler_views[i]->texture;
+            view = state->fragment_sampler_views[i];
+            tex = (struct r300_texture *)view->texture;
             sampler = state->sampler_states[i];
 
+            assert(view->format == tex->tex.format);
+
             texstate = &state->regs[i];
             memcpy(texstate->format, &tex->state, sizeof(uint32_t)*3);
             texstate->filter[0] = sampler->filter0;
@@ -370,8 +375,10 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
             } else {
                 /* determine min/max levels */
                 /* the MAX_MIP level is the largest (finest) one */
-                max_level = MIN2(sampler->max_lod, tex->tex.last_level);
-                min_level = MIN2(sampler->min_lod, max_level);
+                max_level = MIN3(sampler->max_lod, tex->tex.last_level,
+                                 view->last_level);
+                min_level = MIN2(MAX2(sampler->min_lod, view->first_level),
+                                 max_level);
                 texstate->format[0] |= R300_TX_NUM_LEVELS(max_level);
                 texstate->filter[0] |= R300_TX_MAX_MIP_LEVEL(min_level);
             }