break;
case ST_PIPELINE_COMPUTE: {
- struct st_compute_program *old_cp = st->cp;
+ struct st_common_program *old_cp = st->cp;
struct gl_program *new_cp = ctx->ComputeProgram._Current;
if (new_cp != &old_cp->Base) {
if (old_cp)
st->dirty |= old_cp->affected_states;
assert(new_cp);
- st->dirty |= st_compute_program(new_cp)->affected_states;
+ st->dirty |= st_common_program(new_cp)->affected_states;
}
st->compute_shader_may_be_dirty = false;
void
st_update_cs_constants(struct st_context *st)
{
- struct st_compute_program *cp = st->cp;
+ struct st_common_program *cp = st->cp;
if (cp)
st_upload_constants(st, &cp->Base);
void
st_update_cp( struct st_context *st )
{
- struct st_compute_program *stcp;
+ struct st_common_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);
+ stcp = st_common_program(st->ctx->ComputeProgram._Current);
assert(stcp->Base.Target == GL_COMPUTE_PROGRAM_NV);
void *shader;
shader = stcp->variants->driver_shader;
} else {
shader = st_get_cp_variant(st, &stcp->tgsi,
+ stcp->Base.info.cs.shared_size,
&stcp->variants)->driver_shader;
}
}
case GL_TESS_CONTROL_PROGRAM_NV:
case GL_TESS_EVALUATION_PROGRAM_NV:
- case GL_GEOMETRY_PROGRAM_NV: {
+ case GL_GEOMETRY_PROGRAM_NV:
+ case GL_COMPUTE_PROGRAM_NV: {
struct st_common_program *prog = rzalloc(NULL,
struct st_common_program);
return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
}
- case GL_COMPUTE_PROGRAM_NV: {
- struct st_compute_program *prog = rzalloc(NULL,
- struct st_compute_program);
- return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
- }
default:
assert(0);
return NULL;
case GL_TESS_CONTROL_PROGRAM_NV:
case GL_TESS_EVALUATION_PROGRAM_NV:
case GL_GEOMETRY_PROGRAM_NV:
+ case GL_COMPUTE_PROGRAM_NV:
{
struct st_common_program *p = st_common_program(prog);
free_glsl_to_tgsi_visitor(stfp->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 */
}
st->dirty |= sttep->affected_states;
}
else if (target == GL_COMPUTE_PROGRAM_NV) {
- struct st_compute_program *stcp =
- (struct st_compute_program *) prog;
+ struct st_common_program *stcp =
+ (struct st_common_program *) prog;
- st_release_cp_variants(st, stcp);
+ st_release_basic_variants(st, stcp);
if (!st_translate_compute_program(st, stcp))
return false;
case MESA_SHADER_TESS_CTRL:
case MESA_SHADER_TESS_EVAL:
case MESA_SHADER_GEOMETRY:
+ case MESA_SHADER_COMPUTE:
if (st_common_program(linked->Program)->variants)
sh = st_common_program(linked->Program)->variants->driver_shader;
break;
- case MESA_SHADER_COMPUTE:
- if (st_compute_program(linked->Program)->variants)
- sh = st_compute_program(linked->Program)->variants->driver_shader;
- break;
}
unsigned type = pipe_shader_type_from_mesa(i);
st_common_program(ctx->GeometryProgram._Current);
struct st_fragment_program *fp =
st_fragment_program(ctx->FragmentProgram._Current);
- struct st_compute_program *cp =
- st_compute_program(ctx->ComputeProgram._Current);
+ struct st_common_program *cp =
+ st_common_program(ctx->ComputeProgram._Current);
uint64_t active_shader_states = 0;
if (vp)
struct st_common_program *gp; /**< Currently bound geometry program */
struct st_common_program *tcp; /**< Currently bound tess control program */
struct st_common_program *tep; /**< Currently bound tess eval program */
- struct st_compute_program *cp; /**< Currently bound compute program */
+ struct st_common_program *cp; /**< Currently bound compute program */
struct st_vp_variant *vp_variant;
struct st_vertex_program *stvp;
struct st_common_program *stp;
struct st_fragment_program *stfp;
- struct st_compute_program *stcp;
switch (prog->info.stage) {
case MESA_SHADER_VERTEX:
case MESA_SHADER_GEOMETRY:
case MESA_SHADER_TESS_CTRL:
case MESA_SHADER_TESS_EVAL:
+ case MESA_SHADER_COMPUTE:
stp = (struct st_common_program *)prog;
stp->shader_program = shader_program;
stp->tgsi.type = PIPE_SHADER_IR_NIR;
stfp->tgsi.type = PIPE_SHADER_IR_NIR;
stfp->tgsi.ir.nir = nir;
break;
- case MESA_SHADER_COMPUTE:
- stcp = (struct st_compute_program *)prog;
- stcp->shader_program = shader_program;
- stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
- stcp->tgsi.prog = nir;
- break;
default:
unreachable("unknown shader stage");
}
struct st_vertex_program *stvp;
struct st_fragment_program *stfp;
struct st_common_program *stp;
- struct st_compute_program *stcp;
switch (shader->Stage) {
case MESA_SHADER_VERTEX:
case MESA_SHADER_TESS_CTRL:
case MESA_SHADER_TESS_EVAL:
case MESA_SHADER_GEOMETRY:
+ case MESA_SHADER_COMPUTE:
stp = st_common_program(prog);
stp->glsl_to_tgsi = v;
break;
- case MESA_SHADER_COMPUTE:
- stcp = (struct st_compute_program *)prog;
- stcp->glsl_to_tgsi = v;
- break;
default:
assert(!"should not be reached");
return NULL;
break;
case MESA_SHADER_COMPUTE:
- states = &((struct st_compute_program*)prog)->affected_states;
+ states = &((struct st_common_program*)prog)->affected_states;
*states = ST_NEW_CS_STATE;
static void
delete_ir(struct pipe_shader_state *ir)
{
- if (ir->tokens)
+ if (ir->tokens) {
ureg_free_tokens(ir->tokens);
+ ir->tokens = NULL;
+ }
/* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on
* it has resulted in the driver taking ownership of the NIR. Those
}
-/**
- * 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.Target);
- v = next;
- }
-
- *variants = NULL;
-
- if (stcp->tgsi.prog) {
- switch (stcp->tgsi.ir_type) {
- case PIPE_SHADER_IR_TGSI:
- ureg_free_tokens(stcp->tgsi.prog);
- stcp->tgsi.prog = NULL;
- break;
- case PIPE_SHADER_IR_NIR:
- /* pipe driver took ownership of prog */
- break;
- case PIPE_SHADER_IR_NATIVE:
- /* ??? */
- stcp->tgsi.prog = NULL;
- break;
- case PIPE_SHADER_IR_NIR_SERIALIZED:
- unreachable("serialized nirs aren't passed through st/mesa");
- break;
- }
- }
-}
-
/**
* Translate ARB (asm) program to NIR
*/
output_semantic_name,
output_semantic_index);
- if (tgsi_processor == PIPE_SHADER_COMPUTE) {
- struct st_compute_program *stcp = (struct st_compute_program *) prog;
- out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
- stcp->tgsi.prog = out_state->tokens;
- } else {
- struct st_common_program *stcp = (struct st_common_program *) prog;
- out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
- }
+ struct st_common_program *stcp = (struct st_common_program *) prog;
+ out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
+
ureg_destroy(ureg);
st_translate_stream_output_info(prog->sh.LinkedTransformFeedback,
*/
bool
st_translate_compute_program(struct st_context *st,
- struct st_compute_program *stcp)
+ struct st_common_program *stcp)
{
struct ureg_program *ureg;
- struct pipe_shader_state prog;
-
- stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size;
if (stcp->shader_program) {
/* no compute variants: */
st_finalize_nir(st, &stcp->Base, stcp->shader_program,
- (struct nir_shader *) stcp->tgsi.prog);
+ (struct nir_shader *) stcp->tgsi.ir.nir);
st_store_ir_in_disk_cache(st, &stcp->Base, true);
return true;
}
return false;
st_translate_program_common(st, &stcp->Base, stcp->glsl_to_tgsi, ureg,
- PIPE_SHADER_COMPUTE, &prog);
-
- stcp->tgsi.ir_type = PIPE_SHADER_IR_TGSI;
- stcp->tgsi.req_private_mem = 0;
- stcp->tgsi.req_input_mem = 0;
+ PIPE_SHADER_COMPUTE, &stcp->tgsi);
free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
stcp->glsl_to_tgsi = NULL;
*/
struct st_basic_variant *
st_get_cp_variant(struct st_context *st,
- struct pipe_compute_state *tgsi,
+ struct pipe_shader_state *tgsi,
+ unsigned shared_size,
struct st_basic_variant **variants)
{
struct pipe_context *pipe = st->pipe;
v = CALLOC_STRUCT(st_basic_variant);
if (v) {
/* fill in new variant */
- struct pipe_compute_state cs = *tgsi;
- if (tgsi->ir_type == PIPE_SHADER_IR_NIR)
- cs.prog = nir_shader_clone(NULL, tgsi->prog);
+ struct pipe_compute_state cs = {0};
+
+ cs.ir_type = tgsi->type;
+ cs.req_local_mem = shared_size;
+
+ if (tgsi->type == PIPE_SHADER_IR_NIR)
+ cs.prog = nir_shader_clone(NULL, tgsi->ir.nir);
+ else
+ cs.prog = tgsi->tokens;
+
v->driver_shader = pipe->create_compute_state(pipe, &cs);
v->key = key;
case GL_COMPUTE_PROGRAM_NV:
{
struct st_common_program *p = st_common_program(target);
- struct st_compute_program *cp = (struct st_compute_program*)target;
- struct st_basic_variant **variants =
- target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants :
- &p->variants;
- struct st_basic_variant *v, **prevPtr = variants;
+ struct st_basic_variant *v, **prevPtr = &p->variants;
- for (v = *variants; v; ) {
+ for (v = p->variants; v; ) {
struct st_basic_variant *next = v->next;
if (v->key.st == st) {
/* unlink from list */
}
case GL_COMPUTE_PROGRAM_NV: {
- struct st_compute_program *p = (struct st_compute_program *)prog;
- st_get_cp_variant(st, &p->tgsi, &p->variants);
+ struct st_common_program *p = (struct st_common_program *)prog;
+ st_get_cp_variant(st, &p->tgsi, prog->info.cs.shared_size, &p->variants);
break;
}
};
-/**
- * Derived from Mesa gl_program:
- */
-struct st_compute_program
-{
- struct gl_program Base; /**< The Mesa compute program */
- struct pipe_compute_state tgsi;
- struct glsl_to_tgsi_visitor* glsl_to_tgsi;
- uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
-
- /* used when bypassing glsl_to_tgsi: */
- struct gl_shader_program *shader_program;
-
- struct st_basic_variant *variants;
-
- /** SHA1 hash of linked tgsi shader program, used for on-disk cache */
- unsigned char sha1[20];
-
- /* Used by the shader cache and ARB_get_program_binary */
- unsigned num_tgsi_tokens;
-};
-
-
static inline struct st_fragment_program *
st_fragment_program( struct gl_program *fp )
{
}
static inline struct st_common_program *
-st_common_program( struct gl_program *gp )
-{
- return (struct st_common_program *)gp;
-}
-
-static inline struct st_compute_program *
-st_compute_program( struct gl_program *cp )
+st_common_program( struct gl_program *cp )
{
- return (struct st_compute_program *)cp;
+ return (struct st_common_program *)cp;
}
static inline void
static inline void
st_reference_compprog(struct st_context *st,
- struct st_compute_program **ptr,
- struct st_compute_program *prog)
+ struct st_common_program **ptr,
+ struct st_common_program *prog)
{
_mesa_reference_program(st->ctx,
(struct gl_program **) ptr,
extern struct st_basic_variant *
st_get_cp_variant(struct st_context *st,
- struct pipe_compute_state *tgsi,
+ struct pipe_shader_state *tgsi,
+ unsigned shared_size,
struct st_basic_variant **variants);
extern struct st_basic_variant *
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, struct st_common_program *p);
extern bool
st_translate_compute_program(struct st_context *st,
- struct st_compute_program *stcp);
+ struct st_common_program *stcp);
extern void
st_print_current_vertex_program(void);
}
case MESA_SHADER_TESS_CTRL:
case MESA_SHADER_TESS_EVAL:
- case MESA_SHADER_GEOMETRY: {
+ case MESA_SHADER_GEOMETRY:
+ case MESA_SHADER_COMPUTE: {
struct st_common_program *stcp = (struct st_common_program *) prog;
if (prog->info.stage == MESA_SHADER_TESS_EVAL ||
stfp->num_tgsi_tokens);
break;
}
- case MESA_SHADER_COMPUTE: {
- struct st_compute_program *stcp = (struct st_compute_program *) prog;
-
- if (nir)
- write_nir_to_cache(&blob, prog);
- else
- write_tgsi_to_cache(&blob, stcp->tgsi.prog, prog,
- stcp->num_tgsi_tokens);
- break;
- }
default:
unreachable("Unsupported stage");
}
break;
}
case MESA_SHADER_COMPUTE: {
- struct st_compute_program *stcp = (struct st_compute_program *) prog;
+ struct st_common_program *stcp = (struct st_common_program *) prog;
- st_release_cp_variants(st, stcp);
+ st_release_basic_variants(st, stcp);
if (nir) {
- stcp->tgsi.ir_type = PIPE_SHADER_IR_NIR;
+ stcp->tgsi.type = PIPE_SHADER_IR_NIR;
+ stcp->tgsi.ir.nir = nir_deserialize(NULL, options, &blob_reader);
stcp->shader_program = shProg;
- stcp->tgsi.prog = nir_deserialize(NULL, options, &blob_reader);
- prog->nir = (nir_shader *) stcp->tgsi.prog;
+ prog->nir = (nir_shader *) stcp->tgsi.ir.nir;
} else {
- read_tgsi_from_cache(&blob_reader,
- (const struct tgsi_token**) &stcp->tgsi.prog,
+ read_tgsi_from_cache(&blob_reader, &stcp->tgsi.tokens,
&stcp->num_tgsi_tokens);
}
- stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size;
- stcp->tgsi.req_private_mem = 0;
- stcp->tgsi.req_input_mem = 0;
-
if (st->cp == stcp)
st->dirty |= stcp->affected_states;