aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-10-31 12:45:32 -0600
committerBrian <[email protected]>2007-10-31 12:45:32 -0600
commitf4a5ea2ccb472958a4635c606e9510011bceaa3d (patch)
treedfa06910da217c6b5b9ccf3a40ee8a17a47f7a61 /src/mesa/main
parenta35a2fc0d3aaa795a0088bfc390b98a033fc28de (diff)
Update texenvprogram.c code to use prog_cache.c routines.
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/mtypes.h14
-rw-r--r--src/mesa/main/texenvprogram.c135
-rw-r--r--src/mesa/main/texenvprogram.h11
-rw-r--r--src/mesa/main/texstate.c4
4 files changed, 9 insertions, 155 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b435c29793b..8e49431a8fb 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1557,17 +1557,6 @@ struct gl_texture_unit
/*@}*/
};
-struct texenvprog_cache_item {
- GLuint hash;
- void *key;
- struct gl_fragment_program *data;
- struct texenvprog_cache_item *next;
-};
-
-struct texenvprog_cache {
- struct texenvprog_cache_item **items;
- GLuint size, n_items;
-};
/**
* Texture attribute group (GL_TEXTURE_BIT).
@@ -1599,9 +1588,6 @@ struct gl_texture_attrib
/** GL_EXT_shared_texture_palette */
GLboolean SharedPalette;
struct gl_color_table Palette;
-
- /** Cached texenv fragment programs */
- struct texenvprog_cache env_fp_cache;
};
diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c
index cf92503c34a..efb3b35f6a2 100644
--- a/src/mesa/main/texenvprogram.c
+++ b/src/mesa/main/texenvprogram.c
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -29,6 +29,7 @@
#include "macros.h"
#include "enums.h"
#include "shader/prog_parameter.h"
+#include "shader/prog_cache.h"
#include "shader/prog_instruction.h"
#include "shader/prog_print.h"
#include "shader/prog_statevars.h"
@@ -1131,109 +1132,6 @@ create_new_program(GLcontext *ctx, struct state_key *key,
}
-static struct gl_fragment_program *
-search_cache(const struct texenvprog_cache *cache,
- GLuint hash,
- const void *key,
- GLuint keysize)
-{
- struct texenvprog_cache_item *c;
-
- for (c = cache->items[hash % cache->size]; c; c = c->next) {
- if (c->hash == hash && memcmp(c->key, key, keysize) == 0)
- return (struct gl_fragment_program *) c->data;
- }
-
- return NULL;
-}
-
-static void rehash( struct texenvprog_cache *cache )
-{
- struct texenvprog_cache_item **items;
- struct texenvprog_cache_item *c, *next;
- GLuint size, i;
-
- size = cache->size * 3;
- items = (struct texenvprog_cache_item**) _mesa_malloc(size * sizeof(*items));
- _mesa_memset(items, 0, size * sizeof(*items));
-
- for (i = 0; i < cache->size; i++)
- for (c = cache->items[i]; c; c = next) {
- next = c->next;
- c->next = items[c->hash % size];
- items[c->hash % size] = c;
- }
-
- _mesa_free(cache->items);
- cache->items = items;
- cache->size = size;
-}
-
-static void clear_cache( GLcontext *ctx, struct texenvprog_cache *cache )
-{
- struct texenvprog_cache_item *c, *next;
- GLuint i;
-
- for (i = 0; i < cache->size; i++) {
- for (c = cache->items[i]; c; c = next) {
- next = c->next;
- _mesa_free(c->key);
- ctx->Driver.DeleteProgram(ctx, (struct gl_program *) c->data);
- _mesa_free(c);
- }
- cache->items[i] = NULL;
- }
-
-
- cache->n_items = 0;
-}
-
-
-static void cache_item( GLcontext *ctx,
- struct texenvprog_cache *cache,
- GLuint hash,
- const struct state_key *key,
- void *data )
-{
- struct texenvprog_cache_item *c
- = (struct texenvprog_cache_item *) MALLOC(sizeof(*c));
- c->hash = hash;
-
- c->key = _mesa_malloc(sizeof(*key));
- memcpy(c->key, key, sizeof(*key));
-
- c->data = (struct gl_fragment_program *) data;
-
- if (cache->n_items > cache->size * 1.5) {
- if (cache->size < 1000)
- rehash(cache);
- else
- clear_cache(ctx, cache);
- }
-
- cache->n_items++;
- c->next = cache->items[hash % cache->size];
- cache->items[hash % cache->size] = c;
-}
-
-static GLuint hash_key( const struct state_key *key )
-{
- GLuint *ikey = (GLuint *)key;
- GLuint hash = 0, i;
-
- /* Make a slightly better attempt at a hash function:
- */
- for (i = 0; i < sizeof(*key)/sizeof(*ikey); i++)
- {
- hash += ikey[i];
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
-
- return hash;
-}
-
-
/**
* Return a fragment program which implements the current
* fixed-function texture, fog and color-sum operations.
@@ -1243,23 +1141,21 @@ _mesa_get_fixed_func_fragment_program(GLcontext *ctx)
{
struct gl_fragment_program *prog;
struct state_key key;
- GLuint hash;
make_state_key(ctx, &key);
- hash = hash_key(&key);
- prog = search_cache(&ctx->Texture.env_fp_cache, hash, &key, sizeof(key));
+ prog = (struct gl_fragment_program *)
+ _mesa_search_program_cache(ctx->FragmentProgram.Cache,
+ &key, sizeof(key));
if (!prog) {
- if (0)
- _mesa_printf("Building new texenv proggy for key %x\n", hash);
-
prog = (struct gl_fragment_program *)
ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
create_new_program(ctx, &key, prog);
- cache_item(ctx, &ctx->Texture.env_fp_cache, hash, &key, prog);
+ _mesa_program_cache_insert(ctx, ctx->FragmentProgram.Cache,
+ &key, sizeof(key), &prog->Base);
}
return prog;
@@ -1297,20 +1193,3 @@ _mesa_UpdateTexEnvProgram( GLcontext *ctx )
(struct gl_program *) ctx->FragmentProgram._Current);
}
}
-
-
-void _mesa_TexEnvProgramCacheInit( GLcontext *ctx )
-{
- ctx->Texture.env_fp_cache.size = 17;
- ctx->Texture.env_fp_cache.n_items = 0;
- ctx->Texture.env_fp_cache.items = (struct texenvprog_cache_item **)
- _mesa_calloc(ctx->Texture.env_fp_cache.size *
- sizeof(struct texenvprog_cache_item));
-}
-
-
-void _mesa_TexEnvProgramCacheDestroy( GLcontext *ctx )
-{
- clear_cache(ctx, &ctx->Texture.env_fp_cache);
- _mesa_free(ctx->Texture.env_fp_cache.items);
-}
diff --git a/src/mesa/main/texenvprogram.h b/src/mesa/main/texenvprogram.h
index ac73910cb52..a7aa60cf374 100644
--- a/src/mesa/main/texenvprogram.h
+++ b/src/mesa/main/texenvprogram.h
@@ -1,13 +1,8 @@
-/**
- * \file texenvprogram.h
- * Texture state management.
- */
-
/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 7.1
*
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul 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"),
@@ -38,7 +33,5 @@ extern struct gl_fragment_program *
_mesa_get_fixed_func_fragment_program(GLcontext *ctx);
extern void _mesa_UpdateTexEnvProgram( GLcontext *ctx );
-extern void _mesa_TexEnvProgramCacheInit( GLcontext *ctx );
-extern void _mesa_TexEnvProgramCacheDestroy( GLcontext *ctx );
#endif
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index c9f8a0656e8..cb7da39b512 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -3210,8 +3210,6 @@ _mesa_init_texture(GLcontext *ctx)
ctx->Texture.SharedPalette = GL_FALSE;
_mesa_init_colortable(&ctx->Texture.Palette);
- _mesa_TexEnvProgramCacheInit( ctx );
-
/* Allocate proxy textures */
if (!alloc_proxy_textures( ctx ))
return GL_FALSE;
@@ -3239,6 +3237,4 @@ _mesa_free_texture_data(GLcontext *ctx)
for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
_mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable );
-
- _mesa_TexEnvProgramCacheDestroy( ctx );
}