*/
static const struct st_tracked_state *compute_atoms[] =
{
- /* will be updated in the next commit */
+ &st_update_cp,
};
extern const struct st_tracked_state st_update_tep;
extern const struct st_tracked_state st_update_tcp;
extern const struct st_tracked_state st_update_vp;
+extern const struct st_tracked_state st_update_cp;
extern const struct st_tracked_state st_update_rasterizer;
extern const struct st_tracked_state st_update_polygon_stipple;
extern const struct st_tracked_state st_update_viewport;
},
update_tep /* update */
};
+
+
+
+static void
+update_cp( struct st_context *st )
+{
+ struct st_compute_program *stcp;
+
+ if (!st->ctx->ComputeProgram._Current) {
+ cso_set_compute_shader_handle(st->cso_context, NULL);
+ return;
+ }
+
+ stcp = st_compute_program(st->ctx->ComputeProgram._Current);
+ assert(stcp->Base.Base.Target == GL_COMPUTE_PROGRAM_NV);
+
+ st->cp_variant = st_get_cp_variant(st, &stcp->tgsi, &stcp->variants);
+
+ st_reference_compprog(st, &st->cp, stcp);
+
+ cso_set_compute_shader_handle(st->cso_context,
+ st->cp_variant->driver_shader);
+}
+
+const struct st_tracked_state st_update_cp = {
+ "st_update_cp", /* name */
+ { /* dirty */
+ 0, /* mesa */
+ ST_NEW_COMPUTE_PROGRAM /* st */
+ },
+ update_cp /* update */
+};
case GL_TESS_EVALUATION_PROGRAM_NV:
st->dirty.st |= ST_NEW_TESSEVAL_PROGRAM;
break;
+ case GL_COMPUTE_PROGRAM_NV:
+ st->dirty_cp.st |= ST_NEW_COMPUTE_PROGRAM;
+ break;
}
}
st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM;
st->dirty.st |= ST_NEW_TESSCTRL_PROGRAM;
st->dirty.st |= ST_NEW_TESSEVAL_PROGRAM;
+ st->dirty_cp.st |= ST_NEW_COMPUTE_PROGRAM;
}
struct st_tesseval_program *prog = ST_CALLOC_STRUCT(st_tesseval_program);
return _mesa_init_gl_program(&prog->Base.Base, target, id);
}
+ case GL_COMPUTE_PROGRAM_NV: {
+ struct st_compute_program *prog = ST_CALLOC_STRUCT(st_compute_program);
+ return _mesa_init_gl_program(&prog->Base.Base, target, id);
+ }
default:
assert(0);
return NULL;
free_glsl_to_tgsi_visitor(sttep->glsl_to_tgsi);
}
break;
+ case GL_COMPUTE_PROGRAM_NV:
+ {
+ struct st_compute_program *stcp =
+ (struct st_compute_program *) prog;
+
+ st_release_cp_variants(st, stcp);
+
+ if (stcp->glsl_to_tgsi)
+ free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
+ }
+ break;
default:
assert(0); /* problem */
}
if (st->tep == sttep)
st->dirty.st |= ST_NEW_TESSEVAL_PROGRAM;
}
+ else if (target == GL_COMPUTE_PROGRAM_NV) {
+ struct st_compute_program *stcp =
+ (struct st_compute_program *) prog;
+
+ st_release_cp_variants(st, stcp);
+ if (!st_translate_compute_program(st, stcp))
+ return false;
+
+ if (st->cp == stcp)
+ st->dirty_cp.st |= ST_NEW_COMPUTE_PROGRAM;
+ }
if (ST_DEBUG & DEBUG_PRECOMPILE ||
st->shader_has_one_variant[stage])
st_reference_vertprog(st, &st->vp, NULL);
st_reference_tesscprog(st, &st->tcp, NULL);
st_reference_tesseprog(st, &st->tep, NULL);
+ st_reference_compprog(st, &st->cp, NULL);
/* release framebuffer surfaces */
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
#define ST_NEW_SAMPLER_VIEWS (1 << 11)
#define ST_NEW_ATOMIC_BUFFER (1 << 12)
#define ST_NEW_STORAGE_BUFFER (1 << 13)
+#define ST_NEW_COMPUTE_PROGRAM (1 << 14)
struct st_state_flags {
struct st_geometry_program *gp; /**< Currently bound geometry program */
struct st_tessctrl_program *tcp; /**< Currently bound tess control program */
struct st_tesseval_program *tep; /**< Currently bound tess eval program */
+ struct st_compute_program *cp; /**< Currently bound compute program */
struct st_vp_variant *vp_variant;
struct st_fp_variant *fp_variant;
struct st_basic_variant *gp_variant;
struct st_basic_variant *tcp_variant;
struct st_basic_variant *tep_variant;
+ struct st_basic_variant *cp_variant;
struct gl_texture_object *default_texture;
pc = &c->Program[MESA_SHADER_TESS_EVAL];
options = &c->ShaderCompilerOptions[MESA_SHADER_TESS_EVAL];
break;
+ case PIPE_SHADER_COMPUTE:
+ pc = &c->Program[MESA_SHADER_COMPUTE];
+ options = &c->ShaderCompilerOptions[MESA_SHADER_COMPUTE];
+ break;
default:
- /* compute shader, etc. */
- continue;
+ assert(0);
}
pc->MaxTextureImageUnits =
case GL_GEOMETRY_PROGRAM_NV:
cso_delete_geometry_shader(st->cso_context, v->driver_shader);
break;
+ case GL_COMPUTE_PROGRAM_NV:
+ cso_delete_compute_shader(st->cso_context, v->driver_shader);
+ break;
default:
assert(!"this shouldn't occur");
}
}
+/**
+ * Free all variants of a compute program.
+ */
+void
+st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp)
+{
+ struct st_basic_variant **variants = &stcp->variants;
+ struct st_basic_variant *v;
+
+ for (v = *variants; v; ) {
+ struct st_basic_variant *next = v->next;
+ delete_basic_variant(st, v, stcp->Base.Base.Target);
+ v = next;
+ }
+
+ *variants = NULL;
+
+ if (stcp->tgsi.prog) {
+ ureg_free_tokens(stcp->tgsi.prog);
+ stcp->tgsi.prog = NULL;
+ }
+}
+
+
/**
* Translate a vertex program.
*/
}
+/**
+ * Translate a compute program to create a new variant.
+ */
+bool
+st_translate_compute_program(struct st_context *st,
+ struct st_compute_program *stcp)
+{
+ return false; /* will be updated in the next commit */
+}
+
+
+/**
+ * Get/create compute program variant.
+ */
+struct st_basic_variant *
+st_get_cp_variant(struct st_context *st,
+ struct pipe_compute_state *tgsi,
+ struct st_basic_variant **variants)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct st_basic_variant *v;
+ struct st_basic_variant_key key;
+
+ memset(&key, 0, sizeof(key));
+ key.st = st->has_shareable_shaders ? NULL : st;
+
+ /* Search for existing variant */
+ for (v = *variants; v; v = v->next) {
+ if (memcmp(&v->key, &key, sizeof(key)) == 0) {
+ break;
+ }
+ }
+
+ if (!v) {
+ /* create new */
+ v = CALLOC_STRUCT(st_basic_variant);
+ if (v) {
+ /* fill in new variant */
+ v->driver_shader = pipe->create_compute_state(pipe, tgsi);
+ v->key = key;
+
+ /* insert into list */
+ v->next = *variants;
+ *variants = v;
+ }
+ }
+
+ return v;
+}
+
+
/**
* Vert/Geom/Frag programs have per-context variants. Free all the
* variants attached to the given program which match the given context.
case GL_GEOMETRY_PROGRAM_NV:
case GL_TESS_CONTROL_PROGRAM_NV:
case GL_TESS_EVALUATION_PROGRAM_NV:
+ case GL_COMPUTE_PROGRAM_NV:
{
struct st_geometry_program *gp = (struct st_geometry_program*)target;
struct st_tessctrl_program *tcp = (struct st_tessctrl_program*)target;
struct st_tesseval_program *tep = (struct st_tesseval_program*)target;
+ struct st_compute_program *cp = (struct st_compute_program*)target;
struct st_basic_variant **variants =
target->Target == GL_GEOMETRY_PROGRAM_NV ? &gp->variants :
target->Target == GL_TESS_CONTROL_PROGRAM_NV ? &tcp->variants :
target->Target == GL_TESS_EVALUATION_PROGRAM_NV ? &tep->variants :
+ target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants :
NULL;
struct st_basic_variant *v, **prevPtr = variants;
case GL_GEOMETRY_SHADER:
case GL_TESS_CONTROL_SHADER:
case GL_TESS_EVALUATION_SHADER:
+ case GL_COMPUTE_SHADER:
{
destroy_program_variants(st, shader->Program);
}
break;
}
+ case GL_COMPUTE_PROGRAM_NV: {
+ struct st_compute_program *p = (struct st_compute_program *)prog;
+ st_get_cp_variant(st, &p->tgsi, &p->variants);
+ break;
+ }
+
default:
assert(0);
}
};
+/**
+ * Derived from Mesa gl_compute_program:
+ */
+struct st_compute_program
+{
+ struct gl_compute_program Base; /**< The Mesa compute program */
+ struct pipe_compute_state tgsi;
+ struct glsl_to_tgsi_visitor* glsl_to_tgsi;
+
+ struct st_basic_variant *variants;
+};
+
static inline struct st_fragment_program *
st_fragment_program( struct gl_fragment_program *fp )
return (struct st_tesseval_program *)tep;
}
+static inline struct st_compute_program *
+st_compute_program( struct gl_compute_program *cp )
+{
+ return (struct st_compute_program *)cp;
+}
+
static inline void
st_reference_vertprog(struct st_context *st,
struct st_vertex_program **ptr,
(struct gl_program *) prog);
}
+static inline void
+st_reference_compprog(struct st_context *st,
+ struct st_compute_program **ptr,
+ struct st_compute_program *prog)
+{
+ _mesa_reference_program(st->ctx,
+ (struct gl_program **) ptr,
+ (struct gl_program *) prog);
+}
+
/**
* This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
*/
struct st_fragment_program *stfp,
const struct st_fp_variant_key *key);
+extern struct st_basic_variant *
+st_get_cp_variant(struct st_context *st,
+ struct pipe_compute_state *tgsi,
+ struct st_basic_variant **variants);
+
extern struct st_basic_variant *
st_get_basic_variant(struct st_context *st,
unsigned pipe_shader,
st_release_fp_variants( struct st_context *st,
struct st_fragment_program *stfp );
+extern void
+st_release_cp_variants(struct st_context *st,
+ struct st_compute_program *stcp);
+
extern void
st_release_basic_variants(struct st_context *st, GLenum target,
struct st_basic_variant **variants,
st_translate_tesseval_program(struct st_context *st,
struct st_tesseval_program *sttep);
+extern bool
+st_translate_compute_program(struct st_context *st,
+ struct st_compute_program *stcp);
+
extern void
st_print_current_vertex_program(void);