draw: only fill in / compare the part of the translate key we're using.
authorKeith Whitwell <keith@tungstengraphics.com>
Thu, 8 May 2008 21:13:21 +0000 (22:13 +0100)
committerKeith Whitwell <keith@tungstengraphics.com>
Thu, 8 May 2008 21:15:00 +0000 (22:15 +0100)
It's quite a big struct & we examine it a lot (too much).  Reduce
the impact of this by just looking at the active part where possible.

src/gallium/auxiliary/draw/draw_pt_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch.c
src/gallium/auxiliary/translate/translate.h

index f9ac167..671abc2 100644 (file)
@@ -49,6 +49,7 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
    const struct vertex_info *vinfo;
    unsigned dst_offset;
    struct translate_key hw_key;
+   unsigned keysize;
    unsigned i;
    boolean ok;
 
@@ -58,12 +59,10 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
       return;
    }
 
-   memset(&hw_key, 0, sizeof(hw_key));
-
    /* Must do this after set_primitive() above:
     */
    vinfo = draw->render->get_vertex_info(draw->render);
-
+   keysize = 2*4 + vinfo->num_attribs * sizeof(hw_key.element[0]);
 
    /* Translate from pipeline vertices to hw vertices.
     */
@@ -122,8 +121,9 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
    hw_key.output_stride = vinfo->size * 4;
 
    if (!emit->translate ||
-       memcmp(&emit->translate->key, &hw_key, sizeof(hw_key)) != 0)
+       memcmp(&emit->translate->key, &hw_key, keysize) != 0)
    {
+      memset((char *)&hw_key + keysize, 0, sizeof(hw_key) - keysize);
       emit->translate = translate_cache_find(emit->cache, &hw_key);
    }
 }
index 1f765b7..a5bebb4 100644 (file)
@@ -62,10 +62,11 @@ void draw_pt_fetch_prepare( struct pt_fetch *fetch,
    unsigned i, nr = 0;
    unsigned dst_offset = 0;
    struct translate_key key;
+   unsigned keysize;
 
    fetch->vertex_size = vertex_size;
-
-   memset(&key, 0, sizeof(key));
+   keysize = (2*4 + 
+              (draw->pt.nr_vertex_elements + 1) * sizeof(key.element[0]));
 
    /* Always emit/leave space for a vertex header.
     *
@@ -110,8 +111,9 @@ void draw_pt_fetch_prepare( struct pt_fetch *fetch,
 
 
    if (!fetch->translate ||
-       memcmp(&fetch->translate->key, &key, sizeof(key)) != 0)
+       memcmp(&fetch->translate->key, &key, keysize) != 0)
    {
+      memset((char *)&key + keysize, 0, sizeof(key) - keysize);
       fetch->translate = translate_cache_find(fetch->cache, &key);
 
       {
index 6c15d7e..de6f09d 100644 (file)
 struct translate_element 
 {
    enum pipe_format input_format;
-   unsigned input_buffer;
-   unsigned input_offset;
-
    enum pipe_format output_format;
+   unsigned input_buffer;
+   unsigned input_offset;       /* can't really reduce the size of these */
    unsigned output_offset;
 };