r300g: adapt to new vertex element cso
authorRoland Scheidegger <sroland@vmware.com>
Mon, 1 Mar 2010 17:46:49 +0000 (18:46 +0100)
committerRoland Scheidegger <sroland@vmware.com>
Mon, 1 Mar 2010 17:46:49 +0000 (18:46 +0100)
src/gallium/drivers/r300/r300_blit.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_derived.c

index eb9b0beeb5a9589b803b1fb2796e3f2a90f1fa83..2f9650df1b75b0a63ef45512e60a14a07ca75965 100644 (file)
@@ -34,6 +34,7 @@ static void r300_blitter_save_states(struct r300_context* r300)
     util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state);
     util_blitter_save_fragment_shader(r300->blitter, r300->fs);
     util_blitter_save_vertex_shader(r300->blitter, r300->vs);
+    util_blitter_save_vertex_elements(r300->blitter, r300->vs);
 }
 
 /* Clear currently bound buffers. */
index 1eba8a8ed12e2abba8f79aa2dc52e6f6a915a040..0ee0ab47a6bfac9df80411f38594e12075ef983a 100644 (file)
@@ -247,6 +247,11 @@ struct r300_vertex_info {
     uint32_t vap_prog_stream_cntl_ext[8];
 };
 
+struct r300_velems_state {
+    unsigned count;
+    struct pipe_vertex_element velem[];
+};
+
 extern struct pipe_viewport_state r300_viewport_identity;
 
 struct r300_context {
@@ -317,8 +322,7 @@ struct r300_context {
     struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
     int vertex_buffer_count;
     /* Vertex elements for Gallium. */
-    struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
-    int vertex_element_count;
+    struct r300_velems_state *velems;
 
     struct pipe_stencil_ref stencil_ref;
 
index 88fe166359b371e0c2a7bcd8a56ba313465aa9e7..fa3df9a23b62419b3e2c1624b746354e24ffec46 100644 (file)
@@ -776,9 +776,9 @@ void r300_emit_texture(struct r300_context* r300,
 void r300_emit_aos(struct r300_context* r300, unsigned offset)
 {
     struct pipe_vertex_buffer *vb1, *vb2, *vbuf = r300->vertex_buffer;
-    struct pipe_vertex_element *velem = r300->vertex_element;
+    struct pipe_vertex_element *velem = r300->velems->velem;
     int i;
-    unsigned size1, size2, aos_count = r300->vertex_element_count;
+    unsigned size1, size2, aos_count = r300->velems->count;
     unsigned packet_size = (aos_count * 3 + 1) / 2;
     CS_LOCALS(r300);
 
index cd4971ae1364d449d99b180d309684f967fed89c..1850a6f247ac3a3da3b2cc0e6cb1b40327aabbf8 100644 (file)
@@ -128,7 +128,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
 {
     struct pipe_vertex_element* velem;
     struct pipe_vertex_buffer* vbuf;
-    unsigned vertex_element_count = r300->vertex_element_count;
+    unsigned vertex_element_count = r300->velems->count;
     unsigned i, v, vbi, dw, elem_offset;
 
     /* Size of the vertex, in dwords. */
@@ -151,7 +151,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
 
     /* Calculate the vertex size, offsets, strides etc. and map the buffers. */
     for (i = 0; i < vertex_element_count; i++) {
-        velem = &r300->vertex_element[i];
+        velem = &r300->velems->velem[i];
         offset[i] = velem->src_offset / 4;
         size[i] = util_format_get_blocksize(velem->src_format) / 4;
         vertex_size += size[i];
@@ -183,7 +183,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
     /* Emit vertices. */
     for (v = 0; v < count; v++) {
         for (i = 0; i < vertex_element_count; i++) {
-            velem = &r300->vertex_element[i];
+            velem = &r300->velems->velem[i];
             vbi = velem->vertex_buffer_index;
             elem_offset = offset[i] + stride[vbi] * (v + start);
 
@@ -196,7 +196,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
 
     /* Unmap buffers. */
     for (i = 0; i < vertex_element_count; i++) {
-        vbi = r300->vertex_element[i].vertex_buffer_index;
+        vbi = r300->velems->velem[i].vertex_buffer_index;
 
         if (map[vbi]) {
             vbuf = &r300->vertex_buffer[vbi];
@@ -278,11 +278,11 @@ static void r300_emit_draw_elements(struct r300_context *r300,
 static boolean r300_setup_vertex_buffers(struct r300_context *r300)
 {
     struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
-    struct pipe_vertex_element *velem = r300->vertex_element;
+    struct pipe_vertex_element *velem = r300->velems->velem;
     struct pipe_buffer *pbuf;
 
 validate:
-    for (int i = 0; i < r300->vertex_element_count; i++) {
+    for (int i = 0; i < r300->velems->count; i++) {
         pbuf = vbuf[velem[i].vertex_buffer_index].buffer;
 
         if (!r300->winsys->add_buffer(r300->winsys, pbuf,
index 34bf81c1930cb05b0fa023fdd6904a4c208742f5..ceac690fc46d9a3a97f5e0511d93c7eee0e0a37e 100644 (file)
@@ -1044,11 +1044,11 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
 static boolean r300_validate_aos(struct r300_context *r300)
 {
     struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
-    struct pipe_vertex_element *velem = r300->vertex_element;
+    struct pipe_vertex_element *velem = r300->velems->velem;
     int i;
 
     /* Check if formats and strides are aligned to the size of DWORD. */
-    for (i = 0; i < r300->vertex_element_count; i++) {
+    for (i = 0; i < r300->velems->count; i++) {
         if (vbuf[velem[i].vertex_buffer_index].stride % 4 != 0 ||
             util_format_get_blocksize(velem[i].src_format) % 4 != 0) {
             return FALSE;
@@ -1057,20 +1057,32 @@ static boolean r300_validate_aos(struct r300_context *r300)
     return TRUE;
 }
 
-static void r300_set_vertex_elements(struct pipe_context* pipe,
-                                    unsigned count,
-                                    const struct pipe_vertex_element* elements)
+static void* r300_create_vertex_elements_state(struct pipe_context* pipe,
+                                               unsigned count,
+                                               const struct pipe_vertex_element* attribs)
 {
-    struct r300_context* r300 = r300_context(pipe);
+   /*XXX could precalculate state here instead of later */
+    struct r300_velems_state *velems;
+    assert(count <= PIPE_MAX_ATTRIBS);
+    velems = (struct r300_velems_state *) MALLOC(sizeof(struct r300_velems_state) + count * sizeof(*attribs));
+    if (velems) {
+       velems->count = count;
+       memcpy(velems->velem, attribs, sizeof(*attribs) * count);
+    }
+    return velems;
+}
+
+static void r300_bind_vertex_elements_state(struct pipe_context *pipe,
+                                            void *velems)
+{
+    struct r300_context *r300 = r300_context(pipe);
+    struct r300_velems_state *r300_velems = (struct r300_velems_state *) velems;
 
-    memcpy(r300->vertex_element,
-           elements,
-           sizeof(struct pipe_vertex_element) * count);
-    r300->vertex_element_count = count;
+    r300->velems = r300_velems;
 
     if (r300->draw) {
         draw_flush(r300->draw);
-        draw_set_vertex_elements(r300->draw, count, elements);
+        draw_set_vertex_elements(r300->draw, r300_velems->count, r300_velems->velem);
     }
 
     if (!r300_validate_aos(r300)) {
@@ -1080,6 +1092,11 @@ static void r300_set_vertex_elements(struct pipe_context* pipe,
     }
 }
 
+static void r300_delete_vertex_elements_state(struct pipe_context *pipe, void *velems)
+{
+   FREE( velems );
+}
+
 static void* r300_create_vs_state(struct pipe_context* pipe,
                                   const struct pipe_shader_state* shader)
 {
@@ -1241,7 +1258,10 @@ void r300_init_state_functions(struct r300_context* r300)
     r300->context.set_viewport_state = r300_set_viewport_state;
 
     r300->context.set_vertex_buffers = r300_set_vertex_buffers;
-    r300->context.set_vertex_elements = r300_set_vertex_elements;
+
+    r300->context.create_vertex_elements_state = r300_create_vertex_elements_state;
+    r300->context.bind_vertex_elements_state = r300_bind_vertex_elements_state;
+    r300->context.delete_vertex_elements_state = r300_delete_vertex_elements_state;
 
     r300->context.create_vs_state = r300_create_vs_state;
     r300->context.bind_vs_state = r300_bind_vs_state;
index 2cbce9210a7e35ae48205558297e66979935cba0..c43a93601cbc87227e2e869403c5c8bf1f2a2ea8 100644 (file)
@@ -128,10 +128,10 @@ static void r300_vertex_psc(struct r300_context* r300)
     DBG(r300, DBG_DRAW, "r300: vs expects %d attribs, routing %d elements"
             " in psc\n",
             r300->vs->info.num_inputs,
-            r300->vertex_element_count);
+            r300->velems->count);
 
-    for (i = 0; i < r300->vertex_element_count; i++) {
-        format = r300->vertex_element[i].src_format;
+    for (i = 0; i < r300->velems->count; i++) {
+        format = r300->velems->velem[i].src_format;
 
         type = r300_translate_vertex_data_type(format) |
             (stream_tab[i] << R300_DST_VEC_LOC_SHIFT);