Mesa (master): r300-gallium: Take care of various bad dereferences in shader setup.

Corbin Simpson csimpson at kemper.freedesktop.org
Fri Feb 13 08:54:39 UTC 2009


Module: Mesa
Branch: master
Commit: 8a2d0005af34cfaf88b2d70168fdfb2c91e79045
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8a2d0005af34cfaf88b2d70168fdfb2c91e79045

Author: Corbin Simpson <MostAwesomeDude at gmail.com>
Date:   Thu Feb 12 23:36:21 2009 -0800

r300-gallium: Take care of various bad dereferences in shader setup.

Unbreaks glxinfo.

---

 src/gallium/drivers/r300/r300_state.c        |   11 +++++------
 src/gallium/drivers/r300/r300_state_shader.c |   24 ++++++++++++++++++++----
 src/gallium/drivers/r300/r300_state_shader.h |    1 -
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 5fe2b8e..2c0906a 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -424,7 +424,10 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
     struct r300_context* r300 = r300_context(pipe);
     struct r3xx_fragment_shader* fs = (struct r3xx_fragment_shader*)shader;
 
-    if (!fs->translated) {
+    if (fs == NULL) {
+        r300->fs = NULL;
+        return;
+    } else if (!fs->translated) {
         if (r300_screen(r300->context.screen)->caps->is_r500) {
             r500_translate_shader(r300, fs);
         } else {
@@ -432,11 +435,7 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
         }
     }
 
-    if (!fs->translated) {
-        debug_printf("r300: Couldn't assemble fragment shader...\n");
-        /* XXX exit here */
-    }
-
+    fs->translated = true;
     r300->fs = fs;
 
     r300->dirty_state |= R300_NEW_FRAGMENT_SHADER;
diff --git a/src/gallium/drivers/r300/r300_state_shader.c b/src/gallium/drivers/r300/r300_state_shader.c
index 352cb62..cb606c4 100644
--- a/src/gallium/drivers/r300/r300_state_shader.c
+++ b/src/gallium/drivers/r300/r300_state_shader.c
@@ -22,16 +22,32 @@
 
 #include "r300_state_shader.h"
 
+static void r300_copy_passthrough_shader(struct r300_fragment_shader* fs)
+{
+    struct r300_fragment_shader* pt = &r300_passthrough_fragment_shader;
+    fs->shader.stack_size = pt->shader.stack_size;
+    fs->alu_instruction_count = pt->alu_instruction_count;
+    fs->tex_instruction_count = pt->tex_instruction_count;
+    fs->indirections = pt->indirections;
+    fs->instructions[0] = pt->instructions[0];
+}
+
+static void r500_copy_passthrough_shader(struct r500_fragment_shader* fs)
+{
+    struct r500_fragment_shader* pt = &r500_passthrough_fragment_shader;
+    fs->shader.stack_size = pt->shader.stack_size;
+    fs->instruction_count = pt->instruction_count;
+    fs->instructions[0] = pt->instructions[0];
+}
+
 void r300_translate_shader(struct r300_context* r300,
                            struct r300_fragment_shader* fs)
 {
-    /* XXX fix this at some point */
-    *fs = r300_passthrough_fragment_shader;
+    r300_copy_passthrough_shader(fs);
 }
 
 void r500_translate_shader(struct r300_context* r300,
                            struct r500_fragment_shader* fs)
 {
-    /* XXX fix this at some point */
-    *fs = r500_passthrough_fragment_shader;
+    r500_copy_passthrough_shader(fs);
 }
diff --git a/src/gallium/drivers/r300/r300_state_shader.h b/src/gallium/drivers/r300/r300_state_shader.h
index a5f03b9..108f5ec 100644
--- a/src/gallium/drivers/r300/r300_state_shader.h
+++ b/src/gallium/drivers/r300/r300_state_shader.h
@@ -83,7 +83,6 @@ static const struct r500_fragment_shader r500_passthrough_fragment_shader = {
         R500_ALU_RGBA_OP_CMP | R500_ALU_RGBA_R_SWIZ_0 |
         R500_ALU_RGBA_G_SWIZ_0 | R500_ALU_RGBA_B_SWIZ_0 |
         R500_ALU_RGBA_A_SWIZ_0,
-    .shader.translated = TRUE,
 };
 
 #endif /* R300_STATE_SHADER_H */




More information about the mesa-commit mailing list