gallium: added tgsi_shader_field to sp_fragment_shader
authorBrian <brian.paul@tungstengraphics.com>
Tue, 26 Feb 2008 17:13:39 +0000 (10:13 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 26 Feb 2008 17:13:39 +0000 (10:13 -0700)
Use the shader semantic info from there, instead of from pipe_shader_state.
Carry this idea to draw module and other drivers...

src/gallium/drivers/softpipe/sp_fs_llvm.c
src/gallium/drivers/softpipe/sp_prim_setup.c
src/gallium/drivers/softpipe/sp_quad.c
src/gallium/drivers/softpipe/sp_quad_fs.c
src/gallium/drivers/softpipe/sp_state.h
src/gallium/drivers/softpipe/sp_state_derived.c
src/gallium/drivers/softpipe/sp_state_fs.c

index 34b2b7d4e243db53c519a322eee84d5e6033495e..07d058155f22939363a02a532ec65eb5a5002d3f 100644 (file)
@@ -96,7 +96,7 @@ shade_quad_llvm(struct quad_stage *qs,
    if (qss->colorOutSlot >= 0) {
       unsigned i;
       /* XXX need to handle multiple color outputs someday */
-      allvmrt(qss->stage.softpipe->fs->shader.output_semantic_name[qss->colorOutSlot]
+      allvmrt(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot]
              == TGSI_SEMANTIC_COLOR);
       for (i = 0; i < QUAD_SIZE; ++i) {
          quad->outputs.color[0][i] = dests[i][qss->colorOutSlot][0];
index b6a3fddb29c9acc1fd42ec02f9c6c03e91dbb9d2..17284539b007f18d22d6525fb975961f9bb03c50 100644 (file)
@@ -514,7 +514,7 @@ setup_fragcoord_coeff(struct setup_stage *setup, uint slot)
 static void setup_tri_coefficients( struct setup_stage *setup )
 {
    struct softpipe_context *softpipe = setup->softpipe;
-   const struct pipe_shader_state *fs = &softpipe->fs->shader;
+   const struct sp_fragment_shader *spfs = softpipe->fs;
    const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe);
    uint fragSlot;
 
@@ -525,7 +525,7 @@ static void setup_tri_coefficients( struct setup_stage *setup )
 
    /* setup interpolation for all the remaining attributes:
     */
-   for (fragSlot = 0; fragSlot < fs->num_inputs; fragSlot++) {
+   for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) {
       const uint vertSlot = vinfo->src_index[fragSlot];
       uint j;
 
@@ -549,7 +549,7 @@ static void setup_tri_coefficients( struct setup_stage *setup )
          assert(0);
       }
 
-      if (fs->input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
+      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
          /* FOG.y = front/back facing  XXX fix this */
          setup->coef[fragSlot].a0[1] = 1.0f - setup->quad.facing;
          setup->coef[fragSlot].dadx[1] = 0.0;
@@ -757,7 +757,7 @@ static INLINE void
 setup_line_coefficients(struct setup_stage *setup, struct prim_header *prim)
 {
    struct softpipe_context *softpipe = setup->softpipe;
-   const struct pipe_shader_state *fs = &setup->softpipe->fs->shader;
+   const struct sp_fragment_shader *spfs = softpipe->fs;
    const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe);
    uint fragSlot;
 
@@ -779,7 +779,7 @@ setup_line_coefficients(struct setup_stage *setup, struct prim_header *prim)
 
    /* setup interpolation for all the remaining attributes:
     */
-   for (fragSlot = 0; fragSlot < fs->num_inputs; fragSlot++) {
+   for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) {
       const uint vertSlot = vinfo->src_index[fragSlot];
       uint j;
 
@@ -803,7 +803,7 @@ setup_line_coefficients(struct setup_stage *setup, struct prim_header *prim)
          assert(0);
       }
 
-      if (fs->input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
+      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
          /* FOG.y = front/back facing  XXX fix this */
          setup->coef[fragSlot].a0[1] = 1.0f - setup->quad.facing;
          setup->coef[fragSlot].dadx[1] = 0.0;
@@ -967,7 +967,7 @@ setup_point(struct draw_stage *stage, struct prim_header *prim)
 {
    struct setup_stage *setup = setup_stage( stage );
    struct softpipe_context *softpipe = setup->softpipe;
-   const struct pipe_shader_state *fs = &softpipe->fs->shader;
+   const struct sp_fragment_shader *spfs = softpipe->fs;
    const struct vertex_header *v0 = prim->v[0];
    const int sizeAttr = setup->softpipe->psize_slot;
    const float size
@@ -1002,7 +1002,7 @@ setup_point(struct draw_stage *stage, struct prim_header *prim)
    const_coeff(setup, &setup->posCoef, 0, 2);
    const_coeff(setup, &setup->posCoef, 0, 3);
 
-   for (fragSlot = 0; fragSlot < fs->num_inputs; fragSlot++) {
+   for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) {
       const uint vertSlot = vinfo->src_index[fragSlot];
       uint j;
 
@@ -1025,7 +1025,7 @@ setup_point(struct draw_stage *stage, struct prim_header *prim)
          assert(0);
       }
 
-      if (fs->input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
+      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
          /* FOG.y = front/back facing  XXX fix this */
          setup->coef[fragSlot].a0[1] = 1.0f - setup->quad.facing;
          setup->coef[fragSlot].dadx[1] = 0.0;
index 142dbcc77106c97cffed3772287ff892362aeaaa..0aaf94021f8759cf5996695f8238cd5921e4b256 100644 (file)
@@ -61,7 +61,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp)
                sp->framebuffer.zsbuf &&
                !sp->depth_stencil->alpha.enabled &&
                !sp->fs->uses_kill &&
-               !sp->fs->writes_z;
+               !sp->fs->info.writes_z;
 
    /* build up the pipeline in reverse order... */
 
index 2f40e09d5c202d82e90fec6dc6295c240370a892..1794fb5a616f0a7abf540d332aa45bede17d5485 100644 (file)
@@ -91,7 +91,7 @@ shade_quad(
    /* store result color */
    if (qss->colorOutSlot >= 0) {
       /* XXX need to handle multiple color outputs someday */
-      assert(qss->stage.softpipe->fs->shader.output_semantic_name[qss->colorOutSlot]
+      assert(qss->stage.softpipe->fs->info.output_semantic_name[qss->colorOutSlot]
              == TGSI_SEMANTIC_COLOR);
       memcpy(
              quad->outputs.color,
@@ -149,7 +149,7 @@ static void shade_begin(struct quad_stage *qs)
    qss->colorOutSlot = -1;
    qss->depthOutSlot = -1;
    for (i = 0; i < qss->stage.softpipe->fs->shader.num_outputs; i++) {
-      switch (qss->stage.softpipe->fs->shader.output_semantic_name[i]) {
+      switch (qss->stage.softpipe->fs->info.output_semantic_name[i]) {
       case TGSI_SEMANTIC_POSITION:
          qss->depthOutSlot = i;
          break;
index 5aaa9e346bcfb5d94d9752e5b6f728faf0e373cd..b1070e185a2501967b5d62a5c4a0a69e0c355356 100644 (file)
@@ -32,6 +32,7 @@
 #define SP_STATE_H
 
 #include "pipe/p_state.h"
+#include "tgsi/util/tgsi_scan.h"
 
 
 #define SP_NEW_VIEWPORT      0x1
@@ -61,10 +62,11 @@ struct tgsi_exec_machine;
  * This is starting to look an awful lot like a quad pipeline stage...
  */
 struct sp_fragment_shader {
-   struct pipe_shader_state   shader;
+   struct pipe_shader_state shader;
+
+   struct tgsi_shader_info info;
 
    boolean uses_kill;
-   boolean writes_z;
 
    void (*prepare)( const struct sp_fragment_shader *shader,
                    struct tgsi_exec_machine *machine,
index 4c6313001f4c5ddeba51f0d8170d74c6da3d8fef..68702eafcf3e7ca49c26257a21c05b5d40ad00a3 100644 (file)
@@ -62,6 +62,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
    if (vinfo->num_attribs == 0) {
       /* compute vertex layout now */
       const struct pipe_shader_state *vs = &softpipe->vs->shader;
+      const struct sp_fragment_shader *spfs = softpipe->fs;
       const struct pipe_shader_state *fs = &softpipe->fs->shader;
       const enum interp_mode colorInterp
          = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
@@ -83,9 +84,9 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
        * from the vertex shader.
        */
       vinfo->num_attribs = 0;
-      for (i = 0; i < fs->num_inputs; i++) {
+      for (i = 0; i < spfs->info.num_inputs; i++) {
          int src;
-         switch (fs->input_semantic_name[i]) {
+         switch (spfs->info.input_semantic_name[i]) {
          case TGSI_SEMANTIC_POSITION:
             src = draw_find_vs_output(softpipe->draw,
                                       TGSI_SEMANTIC_POSITION, 0);
@@ -94,7 +95,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
 
          case TGSI_SEMANTIC_COLOR:
             src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_COLOR, 
-                                 fs->input_semantic_index[i]);
+                                 spfs->info.input_semantic_index[i]);
             draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
             break;
 
@@ -106,7 +107,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
          case TGSI_SEMANTIC_GENERIC:
             /* this includes texcoords and varying vars */
             src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_GENERIC,
-                                 fs->input_semantic_index[i]);
+                                      spfs->info.input_semantic_index[i]);
             draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
             break;
 
index b184ac61bb9957f0b775063ce893e5b03a05fe1a..2715dca0f0956862139d12cd324e39e3960af67b 100644 (file)
@@ -45,13 +45,12 @@ softpipe_create_fs_state(struct pipe_context *pipe,
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
    struct sp_fragment_shader *state;
-   struct tgsi_shader_info info;
-
-   tgsi_scan_shader(templ->tokens, &info);
 
+   /* debug */
    if (softpipe->dump_fs) 
       tgsi_dump(templ->tokens, 0);
 
+   /* codegen */
    state = softpipe_create_fs_llvm( softpipe, templ );
    if (!state) {
       state = softpipe_create_fs_sse( softpipe, templ );
@@ -59,10 +58,15 @@ softpipe_create_fs_state(struct pipe_context *pipe,
          state = softpipe_create_fs_exec( softpipe, templ );
       }
    }
+
    assert(state);
-   state->uses_kill = (info.opcode_count[TGSI_OPCODE_KIL] ||
-                       info.opcode_count[TGSI_OPCODE_KILP]);
-   state->writes_z = info.writes_z;
+
+   /* get/save the summary info for this shader */
+   tgsi_scan_shader(templ->tokens, &state->info);
+
+   /* convenience field */
+   state->uses_kill = (state->info.opcode_count[TGSI_OPCODE_KIL] ||
+                       state->info.opcode_count[TGSI_OPCODE_KILP]);
    return state;
 }