void *data;
};
+struct cso_fragment_shader {
+ struct pipe_shader_state state;
+ void *data;
+};
+
+struct cso_vertex_shader {
+ struct pipe_shader_state state;
+ void *data;
+};
+
enum cso_cache_type {
CSO_BLEND,
CSO_SAMPLER,
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_state *depth_stencil;
const struct fo_state *rasterizer;
- const struct pipe_shader_state *fragment_shader;
- const struct pipe_shader_state *vertex_shader;
+ const struct fo_state *fragment_shader;
+ const struct fo_state *vertex_shader;
struct pipe_alpha_test_state alpha_test;
struct pipe_blend_color blend_color;
failover->hw->set_framebuffer_state( failover->hw, framebuffer );
}
+
+static void *
+failover_create_fs_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *templ)
+{
+ struct fo_state *state = malloc(sizeof(struct fo_state));
+ struct failover_context *failover = failover_context(pipe);
+
+ state->sw_state = failover->sw->create_fs_state(pipe, templ);
+ state->hw_state = failover->hw->create_fs_state(pipe, templ);
+
+ return state;
+}
+
static void
failover_bind_fs_state(struct pipe_context *pipe,
- const struct pipe_shader_state *fs)
+ void *fs)
{
struct failover_context *failover = failover_context(pipe);
- failover->fragment_shader = fs;
+ failover->fragment_shader = (struct fo_state *)fs;
failover->dirty |= FO_NEW_FRAGMENT_SHADER;
- failover->hw->bind_fs_state( failover->hw, fs );
+ failover->hw->bind_fs_state(failover->hw, (struct pipe_shader_state *)fs);
+}
+
+static void
+failover_delete_fs_state(struct pipe_context *pipe,
+ void *fs)
+{
+ struct fo_state *state = (struct fo_state*)fs;
+ struct failover_context *failover = failover_context(pipe);
+
+ failover->sw->delete_fs_state(pipe, state->sw_state);
+ failover->hw->delete_fs_state(pipe, state->hw_state);
+ state->sw_state = 0;
+ state->hw_state = 0;
+ free(state);
+}
+
+static void *
+failover_create_vs_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *templ)
+{
+ struct fo_state *state = malloc(sizeof(struct fo_state));
+ struct failover_context *failover = failover_context(pipe);
+
+ state->sw_state = failover->sw->create_vs_state(pipe, templ);
+ state->hw_state = failover->hw->create_vs_state(pipe, templ);
+
+ return state;
}
static void
failover_bind_vs_state(struct pipe_context *pipe,
- const struct pipe_shader_state *vs)
+ void *vs)
{
struct failover_context *failover = failover_context(pipe);
- failover->vertex_shader = vs;
+ failover->vertex_shader = (struct fo_state*)vs;
failover->dirty |= FO_NEW_VERTEX_SHADER;
- failover->hw->bind_vs_state( failover->hw, vs );
+ failover->hw->bind_vs_state(failover->hw, vs);
+}
+
+static void
+failover_delete_vs_state(struct pipe_context *pipe,
+ void *vs)
+{
+ struct fo_state *state = (struct fo_state*)vs;
+ struct failover_context *failover = failover_context(pipe);
+
+ failover->sw->delete_vs_state(pipe, state->sw_state);
+ failover->hw->delete_vs_state(pipe, state->hw_state);
+ state->sw_state = 0;
+ state->hw_state = 0;
+ free(state);
}
static void
failover->pipe.create_rasterizer_state = failover_create_rasterizer_state;
failover->pipe.bind_rasterizer_state = failover_bind_rasterizer_state;
failover->pipe.delete_rasterizer_state = failover_delete_rasterizer_state;
- failover->pipe.bind_fs_state = failover_bind_fs_state;
- failover->pipe.bind_vs_state = failover_bind_vs_state;
+ failover->pipe.create_fs_state = failover_create_fs_state;
+ failover->pipe.bind_fs_state = failover_bind_fs_state;
+ failover->pipe.delete_fs_state = failover_delete_fs_state;
+ failover->pipe.create_vs_state = failover_create_vs_state;
+ failover->pipe.bind_vs_state = failover_bind_vs_state;
+ failover->pipe.delete_vs_state = failover_delete_vs_state;
failover->pipe.set_alpha_test_state = failover_set_alpha_test_state;
failover->pipe.set_blend_color = failover_set_blend_color;
failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer );
if (failover->dirty & FO_NEW_FRAGMENT_SHADER)
- failover->sw->bind_fs_state( failover->sw, failover->fragment_shader );
+ failover->sw->bind_fs_state( failover->sw,
+ failover->fragment_shader->sw_state );
if (failover->dirty & FO_NEW_VERTEX_SHADER)
- failover->sw->bind_vs_state( failover->sw, failover->vertex_shader );
+ failover->sw->bind_vs_state( failover->sw,
+ failover->vertex_shader->sw_state );
if (failover->dirty & FO_NEW_STIPPLE)
failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple );
}
-static const struct pipe_shader_state *
-i915_create_shader_state( struct pipe_context *pipe,
- const struct pipe_shader_state *templ )
+static void *
+i915_create_shader_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *templ)
{
-
- struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state));
- memcpy(shader, templ, sizeof(struct pipe_shader_state));
-
- return shader;
+ return 0;
}
static void i915_bind_fs_state( struct pipe_context *pipe,
- const struct pipe_shader_state *fs )
+ void *fs )
{
struct i915_context *i915 = i915_context(pipe);
- i915->fs = fs;
+ i915->fs = (struct pipe_shader_state *)fs;
i915->dirty |= I915_NEW_FS;
}
-static void i915_bind_vs_state( struct pipe_context *pipe,
- const struct pipe_shader_state *vs )
+static void i915_bind_vs_state(struct pipe_context *pipe,
+ void *vs)
{
struct i915_context *i915 = i915_context(pipe);
/* just pass-through to draw module */
- draw_set_vertex_shader(i915->draw, vs);
+ draw_set_vertex_shader(i915->draw, (const struct pipe_shader_state *)vs);
}
-static void i915_delete_shader_state( struct pipe_context *pipe,
- const struct pipe_shader_state *shader )
+static void i915_delete_shader_state(struct pipe_context *pipe,
+ void *shader)
{
- free((struct pipe_shader_state*)shader);
+ /*do nothing*/
}
static void i915_set_constant_buffer(struct pipe_context *pipe,
void (*delete_depth_stencil_state)(struct pipe_context *,
const struct pipe_depth_stencil_state *);
- const struct pipe_shader_state * (*create_fs_state)(
- struct pipe_context *,
- const struct pipe_shader_state *);
- void (*bind_fs_state)(struct pipe_context *,
- const struct pipe_shader_state *);
- void (*delete_fs_state)(struct pipe_context *,
- const struct pipe_shader_state *);
- const struct pipe_shader_state * (*create_vs_state)(
- struct pipe_context *,
- const struct pipe_shader_state *);
- void (*bind_vs_state)(struct pipe_context *,
- const struct pipe_shader_state *);
- void (*delete_vs_state)(struct pipe_context *,
- const struct pipe_shader_state *);
+ void * (*create_fs_state)(struct pipe_context *,
+ const struct pipe_shader_state *);
+ void (*bind_fs_state)(struct pipe_context *, void *);
+ void (*delete_fs_state)(struct pipe_context *, void *);
+
+ void * (*create_vs_state)(struct pipe_context *,
+ const struct pipe_shader_state *);
+ void (*bind_vs_state)(struct pipe_context *, void *);
+ void (*delete_vs_state)(struct pipe_context *, void *);
void (*set_alpha_test_state)( struct pipe_context *,
const struct pipe_alpha_test_state * );
void softpipe_set_feedback_state( struct pipe_context *,
const struct pipe_feedback_state * );
-const struct pipe_shader_state *
+void *
softpipe_create_shader_state( struct pipe_context *,
const struct pipe_shader_state * );
-void softpipe_bind_fs_state( struct pipe_context *,
- const struct pipe_shader_state * );
-void softpipe_bind_vs_state( struct pipe_context *,
- const struct pipe_shader_state * );
-void softpipe_delete_shader_state( struct pipe_context *,
- const struct pipe_shader_state * );
+void softpipe_bind_fs_state( struct pipe_context *, void * );
+void softpipe_bind_vs_state( struct pipe_context *, void * );
+void softpipe_delete_shader_state( struct pipe_context *, void * );
void softpipe_set_polygon_stipple( struct pipe_context *,
const struct pipe_poly_stipple * );
#include "pipe/draw/draw_context.h"
-const struct pipe_shader_state *
-softpipe_create_shader_state( struct pipe_context *pipe,
- const struct pipe_shader_state *templ )
+void * softpipe_create_shader_state(struct pipe_context *pipe,
+ const struct pipe_shader_state *templ)
{
- struct pipe_shader_state *shader = malloc(sizeof(struct pipe_shader_state));
- memcpy(shader, templ, sizeof(struct pipe_shader_state));
-
- return shader;
+ /* we just want the pipe_shader_state template in the bind calls */
+ return 0;
}
-void softpipe_bind_fs_state( struct pipe_context *pipe,
- const struct pipe_shader_state *fs )
+void softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
- softpipe->fs = fs;
+ softpipe->fs = (struct pipe_shader_state *)fs;
softpipe->dirty |= SP_NEW_FS;
}
-void softpipe_bind_vs_state( struct pipe_context *pipe,
- const struct pipe_shader_state *vs )
+void softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
- softpipe->vs = vs;
+ softpipe->vs = (struct pipe_shader_state *)vs;
softpipe->dirty |= SP_NEW_VS;
- draw_set_vertex_shader(softpipe->draw, vs);
+ draw_set_vertex_shader(softpipe->draw, (struct pipe_shader_state *)vs);
}
void softpipe_delete_shader_state( struct pipe_context *pipe,
- const struct pipe_shader_state *shader )
+ void *shader )
{
- free((struct pipe_shader_state*)shader);
+ /* do nothing */
}
void softpipe_set_constant_buffer(struct pipe_context *pipe,
* Translate a Mesa fragment shader into a TGSI shader.
* \return pointer to cached pipe_shader object.
*/
-struct pipe_shader_state *
+const struct cso_fragment_shader *
st_translate_fragment_shader(struct st_context *st,
struct st_fragment_program *stfp)
{
GLuint outputMapping[FRAG_RESULT_MAX];
GLuint inputMapping[PIPE_MAX_SHADER_INPUTS];
struct pipe_shader_state fs;
- struct pipe_shader_state *cached;
+ const struct cso_fragment_shader *cso;
GLuint interpMode[16]; /* XXX size? */
GLuint i;
GLbitfield inputsRead = stfp->Base.Base.InputsRead;
fs.tokens = &stfp->tokens[0];
- cached = st_cached_fs_state(st, &fs);
- stfp->fs = cached;
+ cso = st_cached_fs_state(st, &fs);
+ stfp->fs = cso;
if (TGSI_DEBUG)
tgsi_dump( stfp->tokens, 0/*TGSI_DUMP_VERBOSE*/ );
stfp->dirty = 0;
- return cached;
+ return cso;
}
if (stfp->dirty)
st->state.fs = st_translate_fragment_shader( st, st->fp );
- st->pipe->bind_fs_state(st->pipe, st->state.fs);
+ st->pipe->bind_fs_state(st->pipe, st->state.fs->data);
}
}
* Translate a Mesa vertex shader into a TGSI shader.
* \return pointer to cached pipe_shader object.
*/
-struct pipe_shader_state *
+const struct cso_vertex_shader *
st_translate_vertex_shader(struct st_context *st,
struct st_vertex_program *stvp)
{
GLuint outputMapping[PIPE_MAX_SHADER_INPUTS];
struct pipe_shader_state vs;
- struct pipe_shader_state *cached;
+ const struct cso_vertex_shader *cso;
GLuint i;
memset(&vs, 0, sizeof(vs));
vs.tokens = &stvp->tokens[0];
- cached = st_cached_vs_state(st, &vs);
- stvp->vs = cached;
+ cso = st_cached_vs_state(st, &vs);
+ stvp->vs = cso;
if (TGSI_DEBUG)
tgsi_dump( stvp->tokens, 0 );
if (stvp->sse2_program.csr == stvp->sse2_program.store)
tgsi_emit_sse2( stvp->tokens, &stvp->sse2_program );
- if (!cached->executable)
- cached->executable = (void *) x86_get_func( &stvp->sse2_program );
+ if (!cso->state.executable)
+ cso->state.executable = (void *) x86_get_func( &stvp->sse2_program );
#endif
stvp->dirty = 0;
- return cached;
+ return cso;
}
/* Bind the vertex program */
st->vp = stvp;
- if (stvp->dirty)
+ if (stvp->dirty)
st->state.vs = st_translate_vertex_shader( st, st->vp );
- st->pipe->bind_vs_state(st->pipe, st->state.vs);
+ st->pipe->bind_vs_state(st->pipe, st->state.vs->data);
}
}
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));
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));
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));
}
st_cached_rasterizer_state(struct st_context *st,
const struct pipe_rasterizer_state *raster);
-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);
-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);
#endif
if (!stfp) {
stfp = make_frag_shader(st);
}
- pipe->bind_fs_state(pipe, stfp->fs);
+ pipe->bind_fs_state(pipe, stfp->fs->data);
}
/* vertex shader state: color/position pass-through */
if (!stvp) {
stvp = make_vertex_shader(st);
}
- pipe->bind_vs_state(pipe, stvp->vs);
+ pipe->bind_vs_state(pipe, stvp->vs->data);
}
/* viewport state: viewport matching window dims */
pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
pipe->bind_blend_state(pipe, st->state.blend->data);
pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil);
- pipe->bind_fs_state(pipe, st->state.fs);
- pipe->bind_vs_state(pipe, st->state.vs);
+ pipe->bind_fs_state(pipe, st->state.fs->data);
+ pipe->bind_vs_state(pipe, st->state.vs->data);
pipe->bind_rasterizer_state(pipe, st->state.rasterizer->data);
pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
/* OR:
if (!stfp) {
stfp = make_fragment_shader(ctx->st);
}
- pipe->bind_fs_state(pipe, stfp->fs);
+ pipe->bind_fs_state(pipe, stfp->fs->data);
}
/* vertex shader state: position + texcoord pass-through */
if (!stvp) {
stvp = make_vertex_shader(ctx->st);
}
- pipe->bind_vs_state(pipe, stvp->vs);
+ pipe->bind_vs_state(pipe, stvp->vs->data);
}
/* texture sampling state: */
/* restore GL state */
pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data);
- pipe->bind_fs_state(pipe, ctx->st->state.fs);
- pipe->bind_vs_state(pipe, ctx->st->state.vs);
+ pipe->bind_fs_state(pipe, ctx->st->state.fs->data);
+ pipe->bind_vs_state(pipe, ctx->st->state.vs->data);
pipe->set_texture_state(pipe, unit, ctx->st->state.texture[unit]);
pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]);
pipe->set_viewport_state(pipe, &ctx->st->state.viewport);
#include "st_context.h"
#include "st_atom.h"
+#include "st_cache.h"
#include "st_draw.h"
#include "st_program.h"
#include "st_cb_rasterpos.h"
setup_feedback(GLcontext *ctx)
{
struct pipe_context *pipe = ctx->st->pipe;
- const struct pipe_shader_state *vs = ctx->st->state.vs;
+ const struct pipe_shader_state *vs = &ctx->st->state.vs->state;
struct pipe_feedback_state feedback;
uint i;
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct pipe_depth_stencil_state *depth_stencil;
const struct cso_rasterizer *rasterizer;
- const struct pipe_shader_state *fs;
- const struct pipe_shader_state *vs;
+ const struct cso_fragment_shader *fs;
+ const struct cso_vertex_shader *vs;
struct pipe_alpha_test_state alpha_test;
struct pipe_blend_color blend_color;
/* must get these after state validation! */
vp = ctx->st->vp;
- vs = ctx->st->state.vs;
+ vs = &ctx->st->state.vs->state;
/* loop over TGSI shader inputs */
for (attr = 0; attr < vs->num_inputs; attr++) {
assert(draw);
draw_set_viewport_state(draw, &st->state.viewport);
draw_set_clip_state(draw, &st->state.clip);
- draw_set_rasterizer_state(draw, st->state.rasterizer->data);
- draw_set_vertex_shader(draw, st->state.vs);
+ draw_set_rasterizer_state(draw, &st->state.rasterizer->state);
+ draw_set_vertex_shader(draw, &st->state.vs->state);
/* XXX need to set vertex info too */
#define ST_FP_MAX_TOKENS 1024
+struct cso_fragment_shader;
+struct cso_vertex_shader;
struct st_fragment_program
{
GLboolean dirty;
/** Pointer to the corresponding cached shader */
- const struct pipe_shader_state *fs;
+ const struct cso_fragment_shader *fs;
GLuint param_state;
};
#endif
/** Pointer to the corresponding cached shader */
- const struct pipe_shader_state *vs;
+ const struct cso_vertex_shader *vs;
GLuint param_state;
};
}
-extern struct pipe_shader_state *
+extern const struct cso_fragment_shader *
st_translate_fragment_shader(struct st_context *st,
struct st_fragment_program *fp);
-extern struct pipe_shader_state *
+extern const struct cso_vertex_shader *
st_translate_vertex_shader(struct st_context *st,
struct st_vertex_program *vp);