r300g: pick a new fragment shader when either a sampler state or view is changed
authorMarek Olšák <maraeo@gmail.com>
Thu, 15 Apr 2010 07:26:07 +0000 (09:26 +0200)
committerMarek Olšák <maraeo@gmail.com>
Thu, 15 Apr 2010 08:10:28 +0000 (10:10 +0200)
src/gallium/drivers/r300/r300_fs.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_derived.c

index dab57fdcc77e73d2a489b81b2785f0d00646f8b3..ecba8b0d80468a5257299b3e715b6ed31cc16f0b 100644 (file)
@@ -342,8 +342,12 @@ boolean r300_pick_fragment_shader(struct r300_context* r300)
             ptr = fs->first;
             while (ptr) {
                 if (memcmp(&ptr->compare_state, &state, sizeof(state)) == 0) {
-                    fs->shader = ptr;
-                    return TRUE;
+                    if (fs->shader != ptr) {
+                        fs->shader = ptr;
+                        return TRUE;
+                    }
+                    /* The currently-bound one is OK. */
+                    return FALSE;
                 }
                 ptr = ptr->next;
             }
index a10953c04aeb05694da67c77febca3a98f20e8e5..371e52d2089ded7454caa4cfa7fe5dfb7e10b904 100644 (file)
@@ -36,6 +36,7 @@
 #include "r300_reg.h"
 #include "r300_screen.h"
 #include "r300_screen_buffer.h"
+#include "r300_state.h"
 #include "r300_state_inlines.h"
 #include "r300_fs.h"
 #include "r300_texture.h"
@@ -683,7 +684,7 @@ static void* r300_create_fs_state(struct pipe_context* pipe,
     return (void*)fs;
 }
 
-static void r300_mark_fs_code_dirty(struct r300_context *r300)
+void r300_mark_fs_code_dirty(struct r300_context *r300)
 {
     struct r300_fragment_shader* fs = r300_fs(r300);
 
@@ -982,13 +983,6 @@ static void r300_bind_sampler_states(struct pipe_context* pipe,
     state->sampler_state_count = count;
 
     r300->textures_state.dirty = TRUE;
-
-    /* Pick a fragment shader based on the texture compare state. */
-    if (r300->fs.state && count) {
-        if (r300_pick_fragment_shader(r300)) {
-            r300_mark_fs_code_dirty(r300);
-        }
-    }
 }
 
 static void r300_lacks_vertex_textures(struct pipe_context* pipe,
@@ -1012,7 +1006,6 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
     struct r300_texture *texture;
     unsigned i;
     unsigned tex_units = r300->screen->caps.num_tex_units;
-    boolean is_r500 = r300->screen->caps.is_r500;
     boolean dirty_tex = FALSE;
 
     if (count > tex_units) {
@@ -1032,9 +1025,10 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
             /* A new sampler view (= texture)... */
             dirty_tex = TRUE;
 
-            /* R300-specific - set the texrect factor in the fragment shader */
+            /* Set the texrect factor in the fragment shader.
+             * Needed for RECT and NPOT fallback. */
             texture = r300_texture(views[i]->texture);
-            if (!is_r500 && texture->uses_pitch) {
+            if (texture->uses_pitch) {
                 r300->fs_rc_constant_state.dirty = TRUE;
             }
         }
index ddf7285731ef6c279dbf7b2062af6a9122bcf2f6..a36cff98c38ad0afbd5c1ecde688711a248b5d5e 100644 (file)
@@ -30,6 +30,7 @@
 #include "r300_fs.h"
 #include "r300_screen.h"
 #include "r300_shader_semantics.h"
+#include "r300_state.h"
 #include "r300_state_derived.h"
 #include "r300_state_inlines.h"
 #include "r300_vs.h"
@@ -550,18 +551,26 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
     }
 
     r300->textures_state.size = size;
+
+    /* Pick a fragment shader based on either the texture compare state
+     * or the uses_pitch flag. */
+    if (r300->fs.state && count) {
+        if (r300_pick_fragment_shader(r300)) {
+            r300_mark_fs_code_dirty(r300);
+        }
+    }
 }
 
 void r300_update_derived_state(struct r300_context* r300)
 {
-    if (r300->rs_block_state.dirty) {
-        r300_update_derived_shader_state(r300);
-    }
-
     if (r300->textures_state.dirty) {
         r300_merge_textures_and_samplers(r300);
     }
 
+    if (r300->rs_block_state.dirty) {
+        r300_update_derived_shader_state(r300);
+    }
+
     if (r300->draw) {
         memset(&r300->vertex_info, 0, sizeof(struct vertex_info));
         r300_draw_emit_all_attribs(r300);