r300g: Make vertex_format into an atom.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 27 Jan 2010 05:49:02 +0000 (21:49 -0800)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 27 Jan 2010 05:49:02 +0000 (21:49 -0800)
Some delicious hax here.

src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_emit.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_derived.c

index 5a689e0bd7f2d11412089da4204059e12c1aab2a..1460778ecee660e8ff0dea555e779012824dc771 100644 (file)
@@ -61,7 +61,7 @@ static void r300_destroy_context(struct pipe_context* context)
     FREE(r300->clip_state.state);
     FREE(r300->rs_block);
     FREE(r300->scissor_state.state);
-    FREE(r300->vertex_info);
+    FREE(r300->vertex_format_state.state);
     FREE(r300->viewport_state.state);
     FREE(r300->ztop_state.state);
     FREE(r300);
@@ -125,6 +125,7 @@ static void r300_setup_atoms(struct r300_context* r300)
     R300_INIT_ATOM(rs, 25);
     R300_INIT_ATOM(scissor, 3);
     R300_INIT_ATOM(viewport, 9);
+    R300_INIT_ATOM(vertex_format, 26);
 }
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
@@ -176,7 +177,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     r300->clip_state.state = CALLOC_STRUCT(pipe_clip_state);
     r300->rs_block = CALLOC_STRUCT(r300_rs_block);
     r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state);
-    r300->vertex_info = CALLOC_STRUCT(r300_vertex_info);
+    r300->vertex_format_state.state = CALLOC_STRUCT(r300_vertex_info);
     r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
     r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
 
index a25e46afaa59bc63455ae4fe1c62fc761fa7628c..407891e17524d0c88235d84d441aa4212b7b2443 100644 (file)
@@ -147,7 +147,6 @@ struct r300_ztop_state {
 #define R300_ANY_NEW_SAMPLERS    0x0001fe00
 #define R300_NEW_TEXTURE         0x00040000
 #define R300_ANY_NEW_TEXTURES    0x03fc0000
-#define R300_NEW_VERTEX_FORMAT   0x04000000
 #define R300_NEW_VERTEX_SHADER   0x08000000
 #define R300_NEW_VERTEX_SHADER_CONSTANTS    0x10000000
 #define R300_NEW_QUERY           0x40000000
@@ -273,7 +272,7 @@ struct r300_context {
     struct r300_query query_list;
 
     /* Vertex formatting information. */
-    struct r300_vertex_info* vertex_info;
+    struct r300_atom vertex_format_state;
 
     /* Various CSO state objects. */
     /* Beginning of atom list. */
index badbf3715c77536642c37af8eab21b04635ce173..8081f1d95692ee4b7f3ad0c44b07d5de6c039757 100644 (file)
@@ -812,38 +812,39 @@ void r300_emit_aos(struct r300_context* r300, unsigned offset)
     END_CS;
 }
 
-void r300_emit_vertex_format_state(struct r300_context* r300)
+void r300_emit_vertex_format_state(struct r300_context* r300, void* state)
 {
-    int i;
+    struct r300_vertex_info* vertex_info = (struct r300_vertex_info*)state;
+    unsigned i;
     CS_LOCALS(r300);
 
     DBG(r300, DBG_DRAW, "r300: VAP/PSC emit:\n");
 
     BEGIN_CS(26);
-    OUT_CS_REG(R300_VAP_VTX_SIZE, r300->vertex_info->vinfo.size);
+    OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_info->vinfo.size);
 
     OUT_CS_REG_SEQ(R300_VAP_VTX_STATE_CNTL, 2);
-    OUT_CS(r300->vertex_info->vinfo.hwfmt[0]);
-    OUT_CS(r300->vertex_info->vinfo.hwfmt[1]);
+    OUT_CS(vertex_info->vinfo.hwfmt[0]);
+    OUT_CS(vertex_info->vinfo.hwfmt[1]);
     OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2);
-    OUT_CS(r300->vertex_info->vinfo.hwfmt[2]);
-    OUT_CS(r300->vertex_info->vinfo.hwfmt[3]);
+    OUT_CS(vertex_info->vinfo.hwfmt[2]);
+    OUT_CS(vertex_info->vinfo.hwfmt[3]);
     for (i = 0; i < 4; i++) {
        DBG(r300, DBG_DRAW, "    : hwfmt%d: 0x%08x\n", i,
-               r300->vertex_info->vinfo.hwfmt[i]);
+               vertex_info->vinfo.hwfmt[i]);
     }
 
     OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, 8);
     for (i = 0; i < 8; i++) {
-        OUT_CS(r300->vertex_info->vap_prog_stream_cntl[i]);
+        OUT_CS(vertex_info->vap_prog_stream_cntl[i]);
         DBG(r300, DBG_DRAW, "    : prog_stream_cntl%d: 0x%08x\n", i,
-               r300->vertex_info->vap_prog_stream_cntl[i]);
+               vertex_info->vap_prog_stream_cntl[i]);
     }
     OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, 8);
     for (i = 0; i < 8; i++) {
-        OUT_CS(r300->vertex_info->vap_prog_stream_cntl_ext[i]);
+        OUT_CS(vertex_info->vap_prog_stream_cntl_ext[i]);
         DBG(r300, DBG_DRAW, "    : prog_stream_cntl_ext%d: 0x%08x\n", i,
-               r300->vertex_info->vap_prog_stream_cntl_ext[i]);
+               vertex_info->vap_prog_stream_cntl_ext[i]);
     }
     END_CS;
 }
@@ -1171,11 +1172,6 @@ void r300_emit_dirty_state(struct r300_context* r300)
         r300_flush_textures(r300);
     }
 
-    if (r300->dirty_state & R300_NEW_VERTEX_FORMAT) {
-        r300_emit_vertex_format_state(r300);
-        r300->dirty_state &= ~R300_NEW_VERTEX_FORMAT;
-    }
-
     if (r300->dirty_state & (R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS)) {
         r300_flush_pvs(r300);
     }
index 2f3d013f5e073eec2f8128af51f794e4c3b49ecc..6788e3d655d40cc34c4c98e4689c302097d56a06 100644 (file)
@@ -73,7 +73,7 @@ void r300_emit_texture(struct r300_context* r300,
 
 void r300_emit_vertex_buffer(struct r300_context* r300);
 
-void r300_emit_vertex_format_state(struct r300_context* r300);
+void r300_emit_vertex_format_state(struct r300_context* r300, void* state);
 
 void r300_emit_vertex_program_code(struct r300_context* r300,
                                    struct r300_vertex_program_code* code);
index dcd0761944fa446dc4e5a2b2a8c3152bc9b61eb7..354f3bb921da69d67b308bea189f23b0390a2cd6 100644 (file)
@@ -556,7 +556,7 @@ r300_render_get_vertex_info(struct vbuf_render* render)
 
     r300_update_derived_state(r300);
 
-    return &r300->vertex_info->vinfo;
+    return (struct vertex_info*)r300->vertex_format_state.state;
 }
 
 static boolean r300_render_allocate_vertices(struct vbuf_render* render,
index 641e95e7fcae90cd49e085b19949a0cb3f4a1be4..7068a5a4ecdda5fe8b4dc9bdd7565fb0a0397ff0 100644 (file)
@@ -552,7 +552,7 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
     r300_pick_fragment_shader(r300);
 
     if (r300->vs && r300_vertex_shader_setup_wpos(r300)) {
-        r300->dirty_state |= R300_NEW_VERTEX_FORMAT;
+        r300->vertex_format_state.dirty = TRUE;
     }
 
     r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS;
@@ -921,7 +921,7 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
         draw_set_vertex_buffers(r300->draw, count, buffers);
     }
 
-    r300->dirty_state |= R300_NEW_VERTEX_FORMAT;
+    r300->vertex_format_state.dirty = TRUE;
 }
 
 static boolean r300_validate_aos(struct r300_context *r300)
@@ -1001,9 +1001,10 @@ static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
             r300_vertex_shader_setup_wpos(r300);
         }
 
+        r300->vertex_format_state.dirty = TRUE;
+
         r300->dirty_state |=
-            R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS |
-            R300_NEW_VERTEX_FORMAT;
+            R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS;
     } else {
         draw_flush(r300->draw);
         draw_bind_vertex_shader(r300->draw,
index 45a3e93df1a9666e444ea54f27c078cc38364256..1a1eabe5fb25c78c4a2259b490f9863497316e29 100644 (file)
@@ -48,7 +48,9 @@ static void r300_draw_emit_attrib(struct r300_context* r300,
     output = draw_find_shader_output(r300->draw,
                                      info->output_semantic_name[index],
                                      info->output_semantic_index[index]);
-    draw_emit_vertex_attr(&r300->vertex_info->vinfo, emit, interp, output);
+    draw_emit_vertex_attr(
+        (struct vertex_info*)r300->vertex_format_state.state,
+        emit, interp, output);
 }
 
 static void r300_draw_emit_all_attribs(struct r300_context* r300)
@@ -104,7 +106,8 @@ static void r300_draw_emit_all_attribs(struct r300_context* r300)
 /* Update the PSC tables. */
 static void r300_vertex_psc(struct r300_context* r300)
 {
-    struct r300_vertex_info *vformat = r300->vertex_info;
+    struct r300_vertex_info *vformat =
+        (struct r300_vertex_info*)r300->vertex_format_state.state;
     uint16_t type, swizzle;
     enum pipe_format format;
     unsigned i;
@@ -156,7 +159,8 @@ static void r300_vertex_psc(struct r300_context* r300)
 /* Update the PSC tables for SW TCL, using Draw. */
 static void r300_swtcl_vertex_psc(struct r300_context* r300)
 {
-    struct r300_vertex_info *vformat = r300->vertex_info;
+    struct r300_vertex_info *vformat =
+        (struct r300_vertex_info*)r300->vertex_format_state.state;
     struct vertex_info* vinfo = &vformat->vinfo;
     uint16_t type, swizzle;
     enum pipe_format format;
@@ -413,11 +417,15 @@ static void r300_update_rs_block(struct r300_context* r300,
 static void r300_update_derived_shader_state(struct r300_context* r300)
 {
     struct r300_screen* r300screen = r300_screen(r300->context.screen);
+    struct r300_vertex_info *vformat =
+        (struct r300_vertex_info*)r300->vertex_format_state.state;
+    struct vertex_info* vinfo = &vformat->vinfo;
 
     /* Reset structures */
     memset(r300->rs_block, 0, sizeof(struct r300_rs_block));
-    memset(r300->vertex_info, 0, sizeof(struct r300_vertex_info));
-    memcpy(r300->vertex_info->vinfo.hwfmt, r300->vs->hwfmt, sizeof(uint)*4);
+    /* Mmm, delicious hax */
+    memset(r300->vertex_format_state.state, 0, sizeof(struct r300_vertex_info));
+    memcpy(vinfo->hwfmt, r300->vs->hwfmt, sizeof(uint)*4);
 
     r300_update_rs_block(r300, &r300->vs->outputs, &r300->fs->inputs);
 
@@ -425,7 +433,8 @@ static void r300_update_derived_shader_state(struct r300_context* r300)
         r300_vertex_psc(r300);
     } else {
         r300_draw_emit_all_attribs(r300);
-        draw_compute_vertex_size(&r300->vertex_info->vinfo);
+        draw_compute_vertex_size(
+            (struct vertex_info*)r300->vertex_format_state.state);
         r300_swtcl_vertex_psc(r300);
     }
 
@@ -507,8 +516,8 @@ void r300_update_derived_state(struct r300_context* r300)
 {
     /* XXX */
     if (r300->dirty_state &
-        (R300_NEW_FRAGMENT_SHADER | R300_NEW_VERTEX_SHADER |
-         R300_NEW_VERTEX_FORMAT) || r300->rs_state.dirty) {
+        (R300_NEW_FRAGMENT_SHADER | R300_NEW_VERTEX_SHADER) ||
+        r300->vertex_format_state.dirty || r300->rs_state.dirty) {
         r300_update_derived_shader_state(r300);
     }