r300-gallium: r500-fs: Setup immediates.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Mon, 16 Mar 2009 06:04:49 +0000 (23:04 -0700)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Mon, 16 Mar 2009 06:07:31 +0000 (23:07 -0700)
Textures still not working. RS block shenanigans expected.

src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_state_shader.c
src/gallium/drivers/r300/r300_state_shader.h
src/gallium/drivers/r300/r300_surface.c

index 1affcbfdf4183040fb0fc6bd3d3e3bf33e4e44bd..df7f85b937133e102863b9c0564b7ad8800034c1 100644 (file)
@@ -59,7 +59,6 @@ static boolean r300_draw_range_elements(struct pipe_context* pipe,
             r300->shader_constants[PIPE_SHADER_VERTEX].user_count *
                 (sizeof(float) * 4));
 
-    /* Abandon all hope, ye who enter here. */
     draw_arrays(r300->draw, mode, start, count);
 
     for (i = 0; i < r300->vertex_buffer_count; i++) {
index c2ad3ac6f5d2b65ebed3f659b0780cde9ee15f36..3b580b7d51b4d92a660213c46544c72b64e1fc1c 100644 (file)
@@ -115,17 +115,19 @@ void r500_emit_fragment_shader(struct r300_context* r300,
                                struct r500_fragment_shader* fs)
 {
     CS_LOCALS(r300);
+    struct r300_constant_buffer* constants =
+        &r300->shader_constants[PIPE_SHADER_FRAGMENT];
     int i;
 
-    BEGIN_CS(9 + (fs->instruction_count * 6));
+    BEGIN_CS(9 + (fs->instruction_count * 6) + (constants->count ? 3 : 0) +
+            (constants->count * 4));
     OUT_CS_REG(R500_US_CONFIG, R500_ZERO_TIMES_ANYTHING_EQUALS_ZERO);
     OUT_CS_REG(R500_US_PIXSIZE, fs->shader.stack_size);
     OUT_CS_REG(R500_US_CODE_ADDR, R500_US_CODE_START_ADDR(0) |
-        R500_US_CODE_END_ADDR(fs->instruction_count));
+            R500_US_CODE_END_ADDR(fs->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,
-        fs->instruction_count * 6);
+    OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA, fs->instruction_count * 6);
     for (i = 0; i < fs->instruction_count; i++) {
         OUT_CS(fs->instructions[i].inst0);
         OUT_CS(fs->instructions[i].inst1);
@@ -134,6 +136,19 @@ void r500_emit_fragment_shader(struct r300_context* r300,
         OUT_CS(fs->instructions[i].inst4);
         OUT_CS(fs->instructions[i].inst5);
     }
+
+    if (constants->count) {
+        OUT_CS_REG(R500_GA_US_VECTOR_INDEX,
+                R500_GA_US_VECTOR_INDEX_TYPE_CONST);
+        OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA, constants->count * 4);
+        for (i = 0; i < constants->count; i++) {
+            OUT_CS(constants->constants[i][0]);
+            OUT_CS(constants->constants[i][1]);
+            OUT_CS(constants->constants[i][2]);
+            OUT_CS(constants->constants[i][3]);
+        }
+    }
+
     END_CS;
 }
 
@@ -229,6 +244,7 @@ void r300_emit_rs_block_state(struct r300_context* r300,
     }
     for (i = 0; i < 8; i++) {
         OUT_CS(rs->ip[i]);
+        //debug_printf("ip %d: 0x%08x\n", i, rs->ip[i]);
     }
 
     OUT_CS_REG_SEQ(R300_RS_COUNT, 2);
@@ -242,8 +258,12 @@ void r300_emit_rs_block_state(struct r300_context* r300,
     }
     for (i = 0; i < 8; i++) {
         OUT_CS(rs->inst[i]);
+        //debug_printf("inst %d: 0x%08x\n", i, rs->inst[i]);
     }
 
+    /* debug_printf("count: 0x%08x inst_count: 0x%08x\n", rs->count,
+            rs->inst_count); */
+
     END_CS;
 }
 
index 06dd6842ed8daa16910f98683b1d7b3b14238835..519879114a9270f950574626a81c562e7db68b36 100644 (file)
@@ -82,6 +82,13 @@ static INLINE unsigned r300_fs_src(struct r300_fs_asm* assembler,
         case TGSI_FILE_TEMPORARY:
             return src->Index + assembler->temp_offset;
             break;
+        case TGSI_FILE_IMMEDIATE:
+            return src->Index + assembler->imm_offset | (1 << 8);
+            break;
+        case TGSI_FILE_CONSTANT:
+            /* XXX magic */
+            return src->Index | (1 << 8);
+            break;
         default:
             debug_printf("r300: fs: Unimplemented src %d\n", src->File);
             break;
@@ -269,11 +276,13 @@ void r300_translate_fragment_shader(struct r300_context* r300,
 void r500_translate_fragment_shader(struct r300_context* r300,
                                     struct r500_fragment_shader* fs)
 {
+    struct tgsi_parse_context parser;
+    int i, imm_const_offset;
+
     struct r300_fs_asm* assembler = CALLOC_STRUCT(r300_fs_asm);
     if (assembler == NULL) {
         return;
     }
-    struct tgsi_parse_context parser;
 
     tgsi_parse_init(&parser, fs->shader.state.tokens);
 
@@ -288,9 +297,24 @@ void r500_translate_fragment_shader(struct r300_context* r300,
                  * of the program. */
                 r300_fs_declare(assembler, &parser.FullToken.FullDeclaration);
                 break;
+            case TGSI_TOKEN_TYPE_IMMEDIATE:
+                assembler->imm_offset++;
+                imm_const_offset = assembler->imm_offset +
+                    r300->shader_constants[PIPE_SHADER_FRAGMENT].user_count;
+                /* I am not amused by the length of these. */
+                for (i = 0; i < 4; i++) {
+                    r300->shader_constants[PIPE_SHADER_FRAGMENT].constants
+                        [imm_const_offset][i] =
+                        parser.FullToken.FullImmediate.u.ImmediateFloat32[i]
+                        .Float;
+                }
+                r300->shader_constants[PIPE_SHADER_FRAGMENT].count =
+                    imm_const_offset;
+                break;
             case TGSI_TOKEN_TYPE_INSTRUCTION:
                 r500_fs_instruction(fs, assembler,
                         &parser.FullToken.FullInstruction);
+                break;
         }
 
     }
index 87a5c99648e74894d59844dc959fd8cafbd24345..8011e1f53802c9d50b9da83a4aad5a743470fc3f 100644 (file)
@@ -60,6 +60,8 @@
 /* Temporary struct used to hold assembly state while putting together
  * fragment programs. */
 struct r300_fs_asm {
+    /* Pipe context. */
+    struct r300_context* r300;
     /* Number of colors. */
     unsigned color_count;
     /* Number of texcoords. */
@@ -70,6 +72,10 @@ struct r300_fs_asm {
     unsigned temp_offset;
     /* Number of requested temporary registers. */
     unsigned temp_count;
+    /* Offset for immediate constants. Neither R300 nor R500 can do four
+     * inline constants per source, so instead we copy immediates into the
+     * constant buffer. */
+    unsigned imm_offset;
 };
 
 void r300_translate_fragment_shader(struct r300_context* r300,
index a49bec9910114d6633cc1daf271540dd6ac887d2..744d60364bd9c484459eb2d49cbce0fdfd2c13d3 100644 (file)
@@ -36,9 +36,9 @@ static void r300_surface_fill(struct pipe_context* pipe,
     struct r300_capabilities* caps = r300_screen(pipe->screen)->caps;
     struct r300_texture* tex = (struct r300_texture*)dest->texture;
     int i;
-
-    float r, g, b, a;
+    float r, g, b, a, depth;
     unsigned pixpitch = tex->stride / tex->tex.block.size;
+
     r = (float)((color >> 16) & 0xff) / 255.0f;
     g = (float)((color >>  8) & 0xff) / 255.0f;
     b = (float)((color >>  0) & 0xff) / 255.0f;