Create a sharable translate_cache and use it.

This commit is contained in:
Zack Rusin
2008-04-23 14:00:13 -04:00
parent ba47aabc98
commit 5fcd84ab39
8 changed files with 173 additions and 123 deletions
+2 -2
View File
@@ -106,12 +106,12 @@ struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter);
/**
* Convenience routine to iterate over the collision list while doing a memory
* Convenience routine to iterate over the collision list while doing a memory
* comparison to see which entry in the list is a direct copy of our template
* and returns that entry.
*/
void *cso_hash_find_data_from_template( struct cso_hash *hash,
unsigned hash_key,
unsigned hash_key,
void *templ,
int size );
+6 -59
View File
@@ -32,66 +32,16 @@
#include "draw/draw_vertex.h"
#include "draw/draw_pt.h"
#include "translate/translate.h"
#include "cso_cache/cso_cache.h"
#include "cso_cache/cso_hash.h"
#include "translate/translate_cache.h"
struct pt_emit {
struct draw_context *draw;
struct translate *translate;
struct cso_hash *hash;
struct translate_cache *cache;
};
static INLINE unsigned translate_hash_key_size(struct translate_key *key)
{
unsigned size = sizeof(struct translate_key) -
sizeof(struct translate_element) * (PIPE_MAX_ATTRIBS - key->nr_elements);
return size;
}
static INLINE unsigned create_key(struct translate_key *key)
{
unsigned hash_key;
unsigned size = translate_hash_key_size(key);
/*debug_printf("key size = %d, (els = %d)\n",
size, key->nr_elements);*/
hash_key = cso_construct_key(key, size);
return hash_key;
}
static struct translate *cached_translate(struct pt_emit *emit,
struct translate_key *key)
{
unsigned hash_key = create_key(key);
struct translate *translate = (struct translate*)
cso_hash_find_data_from_template(emit->hash,
hash_key,
key, sizeof(*key));
if (!translate) {
/* create/insert */
translate = translate_create(key);
cso_hash_insert(emit->hash, hash_key, translate);
}
return translate;
}
static INLINE void delete_translates(struct pt_emit *emit)
{
struct cso_hash *hash = emit->hash;
struct cso_hash_iter iter = cso_hash_first_node(hash);
while (!cso_hash_iter_is_null(iter)) {
struct translate *state = (struct translate*)cso_hash_iter_data(iter);
iter = cso_hash_iter_next(iter);
if (state) {
state->release(state);
}
}
}
void draw_pt_emit_prepare( struct pt_emit *emit,
unsigned prim )
{
@@ -169,12 +119,10 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
hw_key.nr_elements = vinfo->num_attribs;
hw_key.output_stride = vinfo->size * 4;
/* Don't bother with caching at this stage:
*/
if (!emit->translate ||
memcmp(&emit->translate->key, &hw_key, sizeof(hw_key)) != 0)
memcmp(&emit->translate->key, &hw_key, sizeof(hw_key)) != 0)
{
emit->translate = cached_translate(emit, &hw_key);
emit->translate = translate_cache_find(emit->cache, &hw_key);
}
}
@@ -236,15 +184,14 @@ struct pt_emit *draw_pt_emit_create( struct draw_context *draw )
return NULL;
emit->draw = draw;
emit->hash = cso_hash_create();
emit->cache = translate_cache_create();
return emit;
}
void draw_pt_emit_destroy( struct pt_emit *emit )
{
delete_translates(emit);
cso_hash_delete(emit->hash);
translate_cache_destroy(emit->cache);
FREE(emit);
}
+8 -60
View File
@@ -32,9 +32,8 @@
#include "draw/draw_vertex.h"
#include "draw/draw_pt.h"
#include "translate/translate.h"
#include "translate/translate_cache.h"
#include "cso_cache/cso_cache.h"
#include "cso_cache/cso_hash.h"
struct pt_fetch {
struct draw_context *draw;
@@ -43,57 +42,9 @@ struct pt_fetch {
unsigned vertex_size;
struct cso_hash *hash;
struct translate_cache *cache;
};
static INLINE unsigned translate_hash_key_size(struct translate_key *key)
{
unsigned size = sizeof(struct translate_key) -
sizeof(struct translate_element) * (PIPE_MAX_ATTRIBS - key->nr_elements);
return size;
}
static INLINE unsigned create_key(struct translate_key *key)
{
unsigned hash_key;
unsigned size = translate_hash_key_size(key);
/*debug_printf("key size = %d, (els = %d)\n",
size, key->nr_elements);*/
hash_key = cso_construct_key(key, size);
return hash_key;
}
static struct translate *cached_translate(struct pt_fetch *fetch,
struct translate_key *key)
{
unsigned hash_key = create_key(key);
struct translate *translate = (struct translate*)
cso_hash_find_data_from_template(fetch->hash,
hash_key,
key, sizeof(*key));
if (!translate) {
/* create/insert */
translate = translate_create(key);
cso_hash_insert(fetch->hash, hash_key, translate);
}
return translate;
}
static INLINE void delete_translates(struct pt_fetch *fetch)
{
struct cso_hash *hash = fetch->hash;
struct cso_hash_iter iter = cso_hash_first_node(hash);
while (!cso_hash_iter_is_null(iter)) {
struct translate *state = (struct translate*)cso_hash_iter_data(iter);
iter = cso_hash_iter_next(iter);
if (state) {
state->release(state);
}
}
}
/* Perform the fetch from API vertex elements & vertex buffers, to a
* contiguous set of float[4] attributes as required for the
* vertex_shader->run_linear() method.
@@ -157,17 +108,15 @@ void draw_pt_fetch_prepare( struct pt_fetch *fetch,
key.output_stride = vertex_size;
/* Don't bother with caching at this stage:
*/
if (!fetch->translate ||
memcmp(&fetch->translate->key, &key, sizeof(key)) != 0)
memcmp(&fetch->translate->key, &key, sizeof(key)) != 0)
{
fetch->translate = cached_translate(fetch, &key);
fetch->translate = translate_cache_find(fetch->cache, &key);
{
static struct vertex_header vh = { 0, 0, 0, 0xffff };
fetch->translate->set_buffer(fetch->translate,
draw->pt.nr_vertex_buffers,
fetch->translate->set_buffer(fetch->translate,
draw->pt.nr_vertex_buffers,
&vh,
0);
}
@@ -208,14 +157,13 @@ struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw )
return NULL;
fetch->draw = draw;
fetch->hash = cso_hash_create();
fetch->cache = translate_cache_create();
return fetch;
}
void draw_pt_fetch_destroy( struct pt_fetch *fetch )
{
delete_translates(fetch);
cso_hash_delete(fetch->hash);
translate_cache_destroy(fetch->cache);
FREE(fetch);
}
+2 -1
View File
@@ -6,7 +6,8 @@ LIBNAME = translate
C_SOURCES = \
translate_generic.c \
translate_sse.c \
translate.c
translate.c \
translate_cache.c
include ../../Makefile.template
@@ -6,6 +6,7 @@ translate = env.ConvenienceLibrary(
'translate_generic.c',
'translate_sse.c',
'translate.c',
'translate_cache.c',
])
auxiliaries.insert(0, translate)
@@ -96,7 +96,6 @@ struct translate *translate_lookup_or_create( struct translate_context *tctx,
struct translate *translate_create( const struct translate_key *key );
/*******************************************************************************
* Private:
*/
@@ -0,0 +1,100 @@
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "pipe/p_util.h"
#include "pipe/p_state.h"
#include "translate.h"
#include "cso_cache/cso_cache.h"
#include "cso_cache/cso_hash.h"
struct translate_cache {
struct cso_hash *hash;
};
struct translate_cache * translate_cache_create()
{
struct translate_cache *cache = MALLOC_STRUCT(translate_cache);
cache->hash = cso_hash_create();
}
static INLINE void delete_translates(struct translate_cache *cache)
{
struct cso_hash *hash = cache->hash;
struct cso_hash_iter iter = cso_hash_first_node(hash);
while (!cso_hash_iter_is_null(iter)) {
struct translate *state = (struct translate*)cso_hash_iter_data(iter);
iter = cso_hash_iter_next(iter);
if (state) {
state->release(state);
}
}
}
void translate_cache_destroy(struct translate_cache *cache)
{
delete_translates(cache);
cso_hash_delete(cache->hash);
FREE(cache);
}
static INLINE unsigned translate_hash_key_size(struct translate_key *key)
{
unsigned size = sizeof(struct translate_key) -
sizeof(struct translate_element) * (PIPE_MAX_ATTRIBS - key->nr_elements);
return size;
}
static INLINE unsigned create_key(struct translate_key *key)
{
unsigned hash_key;
unsigned size = translate_hash_key_size(key);
/*debug_printf("key size = %d, (els = %d)\n",
size, key->nr_elements);*/
hash_key = cso_construct_key(key, size);
return hash_key;
}
struct translate * translate_cache_find(struct translate_cache *cache,
struct translate_key *key)
{
unsigned hash_key = create_key(key);
struct translate *translate = (struct translate*)
cso_hash_find_data_from_template(cache->hash,
hash_key,
key, sizeof(*key));
if (!translate) {
/* create/insert */
translate = translate_create(key);
cso_hash_insert(cache->hash, hash_key, translate);
}
return translate;
}
@@ -0,0 +1,54 @@
/*
* Copyright 2008 Tungsten Graphics, inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _TRANSLATE_CACHE_H
#define _TRANSLATE_CACHE_H
/*******************************************************************************
* Translate cache.
* Simply used to cache created translates. Avoids unecessary creation of
* translate's if one suitable for a given translate_key has already been
* created.
*
* Note: this functionality depends and requires the CSO module.
*/
struct translate_cache;
struct translate_key;
struct translate;
struct translate_cache *translate_cache_create();
void translate_cache_destroy(struct translate_cache *cache);
/**
* Will try to find a translate structure matched by the given key.
* If such a structure doesn't exist in the cache the function
* will automatically create it, insert it in the cache and
* return the created version.
*
*/
struct translate *translate_cache_find(struct translate_cache *cache,
struct translate_key *key);
#endif