st/mesa: add compute shader states
Changes from v2: - use as much common code as possible (eg. st_basic_variant) Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Reviewed-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
This commit is contained in:
@@ -158,6 +158,9 @@ delete_basic_variant(struct st_context *st, struct st_basic_variant *v,
|
||||
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");
|
||||
}
|
||||
@@ -192,6 +195,30 @@ st_release_basic_variants(struct st_context *st, GLenum target,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1394,6 +1421,57 @@ st_translate_tesseval_program(struct st_context *st,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -1449,14 +1527,17 @@ destroy_program_variants(struct st_context *st, struct gl_program *target)
|
||||
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;
|
||||
|
||||
@@ -1513,6 +1594,7 @@ destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
|
||||
case GL_GEOMETRY_SHADER:
|
||||
case GL_TESS_CONTROL_SHADER:
|
||||
case GL_TESS_EVALUATION_SHADER:
|
||||
case GL_COMPUTE_SHADER:
|
||||
{
|
||||
destroy_program_variants(st, shader->Program);
|
||||
}
|
||||
@@ -1629,6 +1711,12 @@ st_precompile_shader_variant(struct st_context *st,
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user