summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker/st_cache.c
diff options
context:
space:
mode:
authorZack Rusin <[email protected]>2007-09-20 07:50:33 -0400
committerZack Rusin <[email protected]>2007-09-20 07:50:33 -0400
commitdaf5b0f41baa50951e7c2f9ea5cd90b119085a7f (patch)
treed273c4ae95a8cb617412c9f7a1b943dc4364420f /src/mesa/state_tracker/st_cache.c
parent37cf13ed9a429c755f121daa1776b1b30a985ab3 (diff)
Switch fragment/vertex shaders to the new caching semantics.
Allow driver custom allocation within cached objects. The shaders are currently twiced (by cso layer and by the program itself).
Diffstat (limited to 'src/mesa/state_tracker/st_cache.c')
-rw-r--r--src/mesa/state_tracker/st_cache.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c
index 0f233cea588..e5ba0592cfb 100644
--- a/src/mesa/state_tracker/st_cache.c
+++ b/src/mesa/state_tracker/st_cache.c
@@ -115,9 +115,9 @@ const struct cso_rasterizer* st_cached_rasterizer_state(
return (struct cso_rasterizer*)(cso_hash_iter_data(iter));
}
-struct pipe_shader_state * st_cached_fs_state(
- struct st_context *st,
- const struct pipe_shader_state *templ)
+const struct cso_fragment_shader *
+st_cached_fs_state(struct st_context *st,
+ const struct pipe_shader_state *templ)
{
unsigned hash_key = cso_construct_key((void*)templ,
sizeof(struct pipe_shader_state));
@@ -125,17 +125,19 @@ struct pipe_shader_state * st_cached_fs_state(
hash_key, CSO_FRAGMENT_SHADER,
(void*)templ);
if (cso_hash_iter_is_null(iter)) {
- const struct pipe_shader_state *created_state =
- st->pipe->create_fs_state(st->pipe, templ);
- iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER,
- (void*)created_state);
+ struct cso_fragment_shader *cso = malloc(sizeof(struct cso_fragment_shader));
+ memcpy(&cso->state, templ, sizeof(struct pipe_shader_state));
+ cso->data = st->pipe->create_fs_state(st->pipe, templ);
+ if (!cso->data)
+ cso->data = &cso->state;
+ iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER, cso);
}
- return (struct pipe_shader_state*)(cso_hash_iter_data(iter));
+ return (struct cso_fragment_shader*)(cso_hash_iter_data(iter));
}
-struct pipe_shader_state * st_cached_vs_state(
- struct st_context *st,
- const struct pipe_shader_state *templ)
+const struct cso_vertex_shader *
+st_cached_vs_state(struct st_context *st,
+ const struct pipe_shader_state *templ)
{
unsigned hash_key = cso_construct_key((void*)templ,
sizeof(struct pipe_shader_state));
@@ -143,10 +145,12 @@ struct pipe_shader_state * st_cached_vs_state(
hash_key, CSO_VERTEX_SHADER,
(void*)templ);
if (cso_hash_iter_is_null(iter)) {
- const struct pipe_shader_state *created_state =
- st->pipe->create_vs_state(st->pipe, templ);
- iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER,
- (void*)created_state);
+ struct cso_vertex_shader *cso = malloc(sizeof(struct cso_vertex_shader));
+ memcpy(&cso->state, templ, sizeof(struct pipe_shader_state));
+ cso->data = st->pipe->create_vs_state(st->pipe, templ);
+ if (!cso->data)
+ cso->data = &cso->state;
+ iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER, cso);
}
- return (struct pipe_shader_state*)(cso_hash_iter_data(iter));
+ return (struct cso_vertex_shader*)(cso_hash_iter_data(iter));
}