r300-gallium: Add r500 passthrough shader assembly.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Fri, 13 Feb 2009 00:53:06 +0000 (16:53 -0800)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Fri, 13 Feb 2009 02:09:14 +0000 (18:09 -0800)
This allows a simple passthrough fragment shader to be provided on r500.

src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_cs_inlines.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_reg.h
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_shader.c
src/gallium/drivers/r300/r300_state_shader.h

index 376c57639d8abc5cfa8f623baf0b33232c427a00..a29201eabafbcae95f071f67c6709ad47d9988a4 100644 (file)
@@ -107,6 +107,12 @@ struct r3xx_fragment_shader {
 
     /* Has this shader been translated yet? */
     boolean translated;
+
+    /* Number of used instructions */
+    int instruction_count;
+
+    /* Pixel stack size */
+    int stack_size;
 };
 
 struct r300_fragment_shader {
@@ -117,6 +123,16 @@ struct r300_fragment_shader {
 struct r500_fragment_shader {
     /* Parent class */
     struct r3xx_fragment_shader shader;
+
+    /* Machine instructions */
+    struct {
+        uint32_t inst0;
+        uint32_t inst1;
+        uint32_t inst2;
+        uint32_t inst3;
+        uint32_t inst4;
+        uint32_t inst5;
+    } instructions[256]; /*< XXX magic number */
 };
 
 struct r300_texture {
index 71e6623699125c2e8c362c94efb91e8af71978f9..b7c04fde1a819a543eb959631a12e1a0ae68ad57 100644 (file)
 
 #ifdef R300_CS_H
 
+#define RADEON_ONE_REG_WR        (1 << 15)
+
+#define CS_OUT_ONE_REG(register, count) \
+    OUT_CS_REG_SEQ(register, (count | RADEON_ONE_REG_WR))
+
 #define R300_PACIFY do { \
     OUT_CS_REG(R300_SC_SCREENDOOR, 0x0); \
     OUT_CS_REG(RADEON_WAIT_UNTIL, (1 << 15) | (1 << 17) | \
index 585a9e729d79350492977a92f1d7e4ed5dbe4137..4d1b10de230a45b838d4fad5d1a3342a13d76442 100644 (file)
@@ -79,6 +79,39 @@ void r300_emit_dsa_state(struct r300_context* r300,
     END_CS;
 }
 
+void r300_emit_fragment_shader(struct r300_context* r300,
+                               struct r300_fragment_shader* shader)
+{
+    CS_LOCALS(r300);
+}
+
+void r500_emit_fragment_shader(struct r300_context* r300,
+                               struct r500_fragment_shader* shader)
+{
+    CS_LOCALS(r300);
+    int i = 0;
+
+    BEGIN_CS(8 + (shader->shader.instruction_count * 6) + 6);
+    OUT_CS_REG(R500_US_CONFIG, R500_ZERO_TIMES_ANYTHING_EQUALS_ZERO);
+    OUT_CS_REG(R500_US_PIXSIZE, shader->shader.stack_size);
+    OUT_CS_REG(R500_US_CODE_ADDR, R500_US_CODE_START_ADDR(0) |
+        R500_US_CODE_END_ADDR(shader->shader.instruction_count));
+
+    OUT_CS_REG(R500_GA_US_VECTOR_INDEX, R500_GA_US_VECTOR_INDEX_TYPE_INSTR);
+    OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA,
+        shader->shader.instruction_count * 6);
+    for (i = 0; i < shader->shader.instruction_count; i++) {
+        CS_OUT(shader->instructions[i].inst0);
+        CS_OUT(shader->instructions[i].inst1);
+        CS_OUT(shader->instructions[i].inst2);
+        CS_OUT(shader->instructions[i].inst3);
+        CS_OUT(shader->instructions[i].inst4);
+        CS_OUT(shader->instructions[i].inst5);
+    }
+    R300_PACIFY;
+    END_CS;
+}
+
 /* XXX add pitch, stride, z/stencil buf */
 void r300_emit_fb_state(struct r300_context* r300,
                         struct pipe_framebuffer_state* fb)
index dbd0cc28e239a87e9bfe971f61113a53dc1b9f80..9e86423efbd5a7ff4deeae483f5a36608cbb4d87 100644 (file)
@@ -2973,6 +2973,7 @@ enum {
 #   define R500_INST_RGB_OMASK_R                       (1 << 15)
 #   define R500_INST_RGB_OMASK_G                       (1 << 16)
 #   define R500_INST_RGB_OMASK_B                       (1 << 17)
+#   define R500_INST_RGB_OMASK_RGB                     (7 << 15)
 #   define R500_INST_ALPHA_OMASK                       (1 << 18)
 #   define R500_INST_RGB_CLAMP                         (1 << 19)
 #   define R500_INST_ALPHA_CLAMP                       (1 << 20)
index 9392d7234279ab4a2760d6fdaefd9c1ea115f18e..5fe2b8ea3efe8bbb73e7b81167169a5c4dc0c3fd 100644 (file)
@@ -432,6 +432,11 @@ 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 */
+    }
+
     r300->fs = fs;
 
     r300->dirty_state |= R300_NEW_FRAGMENT_SHADER;
index e87172128faa2e36c28a5e4e0bb7f566447e2bea..710b7ee0a60a5b89299c69dc9df397750e35fbe7 100644 (file)
 
 #include "r300_state_shader.h"
 
+void r300_make_passthrough_fragment_shader(struct r300_fragment_shader* fs)
+{
+}
+
+void r500_make_passthrough_fragment_shader(struct r500_fragment_shader* fs)
+{
+    fs->shader.instruction_count = 1;
+    fs->shader.stack_size = 0;
+
+    fs->instructions[0].inst0 = R500_INST_TYPE_OUT |
+        R500_INST_TEX_SEM_WAIT |
+        R500_INST_LAST |
+        R500_INST_RGB_OMASK_RGB | R500_INST_ALPHA_OMASK |
+        R500_INST_RGB_CLAMP | R500_INST_ALPHA_CLAMP;
+    fs->instructions[0].inst1 =
+        R500_RGB_ADDR0(0) | R500_RGB_ADDR1(0) | R500_RGB_ADDR1_CONST |
+        R500_RGB_ADDR2(0) | R500_RGB_ADDR2_CONST;
+    fs->instructions[0].inst2 =
+        R500_ALPHA_ADDR0(0) | R500_ALPHA_ADDR1(0) | R500_ALPHA_ADDR1_CONST |
+        R500_ALPHA_ADDR2(0) | R500_ALPHA_ADDR2_CONST;
+    fs->instructions[0].inst3 =
+        R500_ALU_RGB_SEL_A_SRC0 | R500_ALU_RGB_R_SWIZ_A_R |
+        R500_ALU_RGB_G_SWIZ_A_G | R500_ALU_RGB_B_SWIZ_A_B |
+        R500_ALU_RGB_SEL_B_SRC0 | R500_ALU_RGB_R_SWIZ_B_R |
+        R500_ALU_RGB_B_SWIZ_B_G | R500_ALU_RGB_G_SWIZ_B_B;
+    fs->instructions[0].inst4 =
+        R500_ALPHA_OP_CMP | R500_ALPHA_SWIZ_A_A | R500_ALPHA_SWIZ_B_A;
+    fs->instructions[0].inst5 =
+        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;
+
+    fs->shader.translated = true;
+}
+
 void r300_translate_shader(struct r300_context* r300,
                            struct r300_fragment_shader* fs)
 {
+    r300_make_passthrough_fragment_shader(fs);
 }
 
 void r500_translate_shader(struct r300_context* r300,
                            struct r500_fragment_shader* fs)
 {
+    r500_make_passthrough_fragment_shader(fs);
 }
index a20bd4276c6f7f65bbf4906cd498ee71c199bc3f..030ecaa56eeaaa98e78b46be01056f25ec2ff860 100644 (file)
@@ -24,6 +24,7 @@
 #define R300_STATE_SHADER_H
 
 #include "r300_context.h"
+#include "r300_reg.h"
 #include "r300_screen.h"
 
 void r300_translate_shader(struct r300_context* r300,