mesa/st: collapse st_program into gl_program object.
Remove the subclass for this. Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14700>
This commit is contained in:
parent
8db5937f94
commit
3faa21bda7
|
@ -39,6 +39,8 @@
|
|||
#include "compiler/glsl/list.h"
|
||||
#include "compiler/glsl/ir_uniform.h"
|
||||
|
||||
#include "pipe/p_state.h"
|
||||
|
||||
/**
|
||||
* Shader information needed by both gl_shader and gl_linked shader.
|
||||
*/
|
||||
|
@ -559,6 +561,19 @@ struct gl_program
|
|||
/** Map from sampler unit to texture unit (set by glUniform1i()) */
|
||||
GLubyte SamplerUnits[MAX_SAMPLERS];
|
||||
|
||||
struct pipe_shader_state state;
|
||||
struct glsl_to_tgsi_visitor* glsl_to_tgsi;
|
||||
struct ati_fragment_shader *ati_fs;
|
||||
uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
|
||||
|
||||
void *serialized_nir;
|
||||
unsigned serialized_nir_size;
|
||||
|
||||
/* used when bypassing glsl_to_tgsi: */
|
||||
struct gl_shader_program *shader_program;
|
||||
|
||||
struct st_variant *variants;
|
||||
|
||||
union {
|
||||
/** Fields used by GLSL programs */
|
||||
struct {
|
||||
|
|
|
@ -722,8 +722,8 @@ get_shader_program_completion_status(struct gl_context *ctx,
|
|||
if (!linked || !linked->Program)
|
||||
continue;
|
||||
|
||||
if (st_program(linked->Program)->variants)
|
||||
sh = st_program(linked->Program)->variants->driver_shader;
|
||||
if (linked->Program->variants)
|
||||
sh = linked->Program->variants->driver_shader;
|
||||
|
||||
unsigned type = pipe_shader_type_from_mesa(i);
|
||||
|
||||
|
|
|
@ -536,8 +536,7 @@ void
|
|||
st_init_atifs_prog(struct gl_context *ctx, struct gl_program *prog)
|
||||
{
|
||||
/* we know this is st_fragment_program, because of st_new_ati_fs() */
|
||||
struct st_program *stfp = (struct st_program *) prog;
|
||||
struct ati_fragment_shader *atifs = stfp->ati_fs;
|
||||
struct ati_fragment_shader *atifs = prog->ati_fs;
|
||||
|
||||
unsigned pass, i, r, optype, arg;
|
||||
|
||||
|
|
|
@ -77,11 +77,11 @@ void st_destroy_atoms( struct st_context *st )
|
|||
static void check_program_state( struct st_context *st )
|
||||
{
|
||||
struct gl_context *ctx = st->ctx;
|
||||
struct st_program *old_vp = st->vp;
|
||||
struct st_program *old_tcp = st->tcp;
|
||||
struct st_program *old_tep = st->tep;
|
||||
struct st_program *old_gp = st->gp;
|
||||
struct st_program *old_fp = st->fp;
|
||||
struct gl_program *old_vp = st->vp;
|
||||
struct gl_program *old_tcp = st->tcp;
|
||||
struct gl_program *old_tep = st->tep;
|
||||
struct gl_program *old_gp = st->gp;
|
||||
struct gl_program *old_fp = st->fp;
|
||||
|
||||
struct gl_program *new_vp = ctx->VertexProgram._Current;
|
||||
struct gl_program *new_tcp = ctx->TessCtrlProgram._Current;
|
||||
|
@ -94,40 +94,40 @@ static void check_program_state( struct st_context *st )
|
|||
/* Flag states used by both new and old shaders to unbind shader resources
|
||||
* properly when transitioning to shaders that don't use them.
|
||||
*/
|
||||
if (unlikely(new_vp != (old_vp ? &old_vp->Base : NULL))) {
|
||||
if (unlikely(new_vp != old_vp)) {
|
||||
ctx->Array.NewVertexElements = true;
|
||||
if (old_vp)
|
||||
dirty |= old_vp->affected_states;
|
||||
if (new_vp)
|
||||
dirty |= ST_NEW_VERTEX_PROGRAM(st, st_program(new_vp));
|
||||
dirty |= ST_NEW_VERTEX_PROGRAM(st, new_vp);
|
||||
}
|
||||
|
||||
if (unlikely(new_tcp != &old_tcp->Base)) {
|
||||
if (unlikely(new_tcp != old_tcp)) {
|
||||
if (old_tcp)
|
||||
dirty |= old_tcp->affected_states;
|
||||
if (new_tcp)
|
||||
dirty |= st_program(new_tcp)->affected_states;
|
||||
dirty |= new_tcp->affected_states;
|
||||
}
|
||||
|
||||
if (unlikely(new_tep != &old_tep->Base)) {
|
||||
if (unlikely(new_tep != old_tep)) {
|
||||
if (old_tep)
|
||||
dirty |= old_tep->affected_states;
|
||||
if (new_tep)
|
||||
dirty |= st_program(new_tep)->affected_states;
|
||||
dirty |= new_tep->affected_states;
|
||||
}
|
||||
|
||||
if (unlikely(new_gp != &old_gp->Base)) {
|
||||
if (unlikely(new_gp != old_gp)) {
|
||||
if (old_gp)
|
||||
dirty |= old_gp->affected_states;
|
||||
if (new_gp)
|
||||
dirty |= st_program(new_gp)->affected_states;
|
||||
dirty |= new_gp->affected_states;
|
||||
}
|
||||
|
||||
if (unlikely(new_fp != &old_fp->Base)) {
|
||||
if (unlikely(new_fp != old_fp)) {
|
||||
if (old_fp)
|
||||
dirty |= old_fp->affected_states;
|
||||
if (new_fp)
|
||||
dirty |= st_program(new_fp)->affected_states;
|
||||
dirty |= new_fp->affected_states;
|
||||
}
|
||||
|
||||
/* Find out the number of viewports. This determines how many scissors
|
||||
|
@ -162,7 +162,7 @@ void st_update_edgeflags(struct st_context *st, bool per_vertex_edgeflags)
|
|||
|
||||
struct gl_program *vp = st->ctx->VertexProgram._Current;
|
||||
if (vp)
|
||||
st->dirty |= ST_NEW_VERTEX_PROGRAM(st, st_program(vp));
|
||||
st->dirty |= ST_NEW_VERTEX_PROGRAM(st, vp);
|
||||
}
|
||||
|
||||
bool edgeflag_culls_prims = edgeflags_enabled && !vertdata_edgeflags &&
|
||||
|
@ -237,14 +237,14 @@ void st_validate_state( struct st_context *st, enum st_pipeline pipeline )
|
|||
break;
|
||||
|
||||
case ST_PIPELINE_COMPUTE: {
|
||||
struct st_program *old_cp = st->cp;
|
||||
struct gl_program *old_cp = st->cp;
|
||||
struct gl_program *new_cp = ctx->ComputeProgram._Current;
|
||||
|
||||
if (new_cp != &old_cp->Base) {
|
||||
if (new_cp != old_cp) {
|
||||
if (old_cp)
|
||||
st->dirty |= old_cp->affected_states;
|
||||
assert(new_cp);
|
||||
st->dirty |= st_program(new_cp)->affected_states;
|
||||
st->dirty |= new_cp->affected_states;
|
||||
}
|
||||
|
||||
st->compute_shader_may_be_dirty = false;
|
||||
|
|
|
@ -189,7 +189,7 @@ st_setup_arrays(struct st_context *st,
|
|||
struct gl_context *ctx = st->ctx;
|
||||
|
||||
setup_arrays<POPCNT_NO, UPDATE_ALL>
|
||||
(st, ctx->Array._DrawVAO, vp->Base.Base.DualSlotInputs,
|
||||
(st, ctx->Array._DrawVAO, vp->Base.DualSlotInputs,
|
||||
vp_variant->vert_attrib_mask, _mesa_draw_nonzero_divisor_bits(ctx),
|
||||
_mesa_draw_array_bits(ctx), _mesa_draw_user_array_bits(ctx),
|
||||
velements, vbuffer, num_vbuffers, has_user_vertex_buffers);
|
||||
|
@ -210,7 +210,7 @@ st_setup_current(struct st_context *st,
|
|||
{
|
||||
struct gl_context *ctx = st->ctx;
|
||||
const GLbitfield inputs_read = vp_variant->vert_attrib_mask;
|
||||
const GLbitfield dual_slot_inputs = vp->Base.Base.DualSlotInputs;
|
||||
const GLbitfield dual_slot_inputs = vp->Base.DualSlotInputs;
|
||||
|
||||
/* Process values that should have better been uniforms in the application */
|
||||
GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx);
|
||||
|
@ -274,7 +274,7 @@ st_setup_current_user(struct st_context *st,
|
|||
{
|
||||
struct gl_context *ctx = st->ctx;
|
||||
const GLbitfield inputs_read = vp_variant->vert_attrib_mask;
|
||||
const GLbitfield dual_slot_inputs = vp->Base.Base.DualSlotInputs;
|
||||
const GLbitfield dual_slot_inputs = vp->Base.DualSlotInputs;
|
||||
|
||||
/* Process values that should have better been uniforms in the application */
|
||||
GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx);
|
||||
|
@ -314,7 +314,7 @@ st_update_array_templ(struct st_context *st)
|
|||
/* ST_NEW_VERTEX_ARRAYS */
|
||||
/* Setup arrays */
|
||||
setup_arrays<POPCNT, UPDATE>
|
||||
(st, ctx->Array._DrawVAO, vp->Base.Base.DualSlotInputs,
|
||||
(st, ctx->Array._DrawVAO, vp->Base.DualSlotInputs,
|
||||
vp_variant->vert_attrib_mask, _mesa_draw_nonzero_divisor_bits(ctx),
|
||||
_mesa_draw_array_bits(ctx), _mesa_draw_user_array_bits(ctx),
|
||||
&velements, vbuffer, &num_vbuffers, &uses_user_vertex_buffers);
|
||||
|
|
|
@ -209,7 +209,7 @@ st_upload_constants(struct st_context *st, struct gl_program *prog, gl_shader_st
|
|||
void
|
||||
st_update_vs_constants(struct st_context *st)
|
||||
{
|
||||
st_upload_constants(st, &st->vp->Base, MESA_SHADER_VERTEX);
|
||||
st_upload_constants(st, st->vp, MESA_SHADER_VERTEX);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,7 +218,7 @@ st_update_vs_constants(struct st_context *st)
|
|||
void
|
||||
st_update_fs_constants(struct st_context *st)
|
||||
{
|
||||
st_upload_constants(st, &st->fp->Base, MESA_SHADER_FRAGMENT);
|
||||
st_upload_constants(st, st->fp, MESA_SHADER_FRAGMENT);
|
||||
}
|
||||
|
||||
|
||||
|
@ -227,7 +227,7 @@ st_update_fs_constants(struct st_context *st)
|
|||
void
|
||||
st_update_gs_constants(struct st_context *st)
|
||||
{
|
||||
st_upload_constants(st, st->gp ? &st->gp->Base : NULL, MESA_SHADER_GEOMETRY);
|
||||
st_upload_constants(st, st->gp, MESA_SHADER_GEOMETRY);
|
||||
}
|
||||
|
||||
/* Tessellation control shader:
|
||||
|
@ -235,7 +235,7 @@ st_update_gs_constants(struct st_context *st)
|
|||
void
|
||||
st_update_tcs_constants(struct st_context *st)
|
||||
{
|
||||
st_upload_constants(st, st->tcp ? &st->tcp->Base : NULL, MESA_SHADER_TESS_CTRL);
|
||||
st_upload_constants(st, st->tcp, MESA_SHADER_TESS_CTRL);
|
||||
}
|
||||
|
||||
/* Tessellation evaluation shader:
|
||||
|
@ -243,7 +243,7 @@ st_update_tcs_constants(struct st_context *st)
|
|||
void
|
||||
st_update_tes_constants(struct st_context *st)
|
||||
{
|
||||
st_upload_constants(st, st->tep ? &st->tep->Base : NULL, MESA_SHADER_TESS_EVAL);
|
||||
st_upload_constants(st, st->tep, MESA_SHADER_TESS_EVAL);
|
||||
}
|
||||
|
||||
/* Compute shader:
|
||||
|
@ -251,7 +251,7 @@ st_update_tes_constants(struct st_context *st)
|
|||
void
|
||||
st_update_cs_constants(struct st_context *st)
|
||||
{
|
||||
st_upload_constants(st, st->cp ? &st->cp->Base : NULL, MESA_SHADER_COMPUTE);
|
||||
st_upload_constants(st, st->cp, MESA_SHADER_COMPUTE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -151,5 +151,5 @@ st_update_sample_shading(struct st_context *st)
|
|||
return;
|
||||
|
||||
cso_set_min_samples(st->cso_context,
|
||||
_mesa_get_min_invocations_per_fragment(st->ctx, &st->fp->Base));
|
||||
_mesa_get_min_invocations_per_fragment(st->ctx, st->fp));
|
||||
}
|
||||
|
|
|
@ -119,18 +119,18 @@ update_gl_clamp(struct st_context *st, struct gl_program *prog, uint32_t *gl_cla
|
|||
void
|
||||
st_update_fp( struct st_context *st )
|
||||
{
|
||||
struct st_program *stfp;
|
||||
struct gl_program *fp;
|
||||
|
||||
assert(st->ctx->FragmentProgram._Current);
|
||||
stfp = st_program(st->ctx->FragmentProgram._Current);
|
||||
assert(stfp->Base.Target == GL_FRAGMENT_PROGRAM_ARB);
|
||||
fp = st->ctx->FragmentProgram._Current;
|
||||
assert(fp->Target == GL_FRAGMENT_PROGRAM_ARB);
|
||||
|
||||
void *shader;
|
||||
|
||||
if (st->shader_has_one_variant[MESA_SHADER_FRAGMENT] &&
|
||||
!stfp->ati_fs && /* ATI_fragment_shader always has multiple variants */
|
||||
!stfp->Base.ExternalSamplersUsed /* external samplers need variants */) {
|
||||
shader = stfp->variants->driver_shader;
|
||||
!fp->ati_fs && /* ATI_fragment_shader always has multiple variants */
|
||||
!fp->ExternalSamplersUsed /* external samplers need variants */) {
|
||||
shader = fp->variants->driver_shader;
|
||||
} else {
|
||||
struct st_fp_variant_key key;
|
||||
|
||||
|
@ -168,7 +168,7 @@ st_update_fp( struct st_context *st )
|
|||
st->ctx->Multisample.MinSampleShadingValue *
|
||||
_mesa_geometric_samples(st->ctx->DrawBuffer) > 1;
|
||||
|
||||
if (stfp->ati_fs) {
|
||||
if (fp->ati_fs) {
|
||||
key.fog = st->ctx->Fog._PackedEnabledMode;
|
||||
|
||||
for (unsigned u = 0; u < MAX_NUM_FRAGMENT_REGISTERS_ATI; u++) {
|
||||
|
@ -176,15 +176,15 @@ st_update_fp( struct st_context *st )
|
|||
}
|
||||
}
|
||||
|
||||
key.external = st_get_external_sampler_key(st, &stfp->Base);
|
||||
key.external = st_get_external_sampler_key(st, fp);
|
||||
update_gl_clamp(st, st->ctx->FragmentProgram._Current, key.gl_clamp);
|
||||
|
||||
simple_mtx_lock(&st->ctx->Shared->Mutex);
|
||||
shader = st_get_fp_variant(st, stfp, &key)->base.driver_shader;
|
||||
shader = st_get_fp_variant(st, fp, &key)->base.driver_shader;
|
||||
simple_mtx_unlock(&st->ctx->Shared->Mutex);
|
||||
}
|
||||
|
||||
st_reference_prog(st, &st->fp, stfp);
|
||||
_mesa_reference_program(st->ctx, &st->fp, fp);
|
||||
|
||||
cso_set_fragment_shader_handle(st->cso_context, shader);
|
||||
}
|
||||
|
@ -197,18 +197,18 @@ st_update_fp( struct st_context *st )
|
|||
void
|
||||
st_update_vp( struct st_context *st )
|
||||
{
|
||||
struct st_program *stvp;
|
||||
struct gl_program *vp;
|
||||
|
||||
/* find active shader and params -- Should be covered by
|
||||
* ST_NEW_VERTEX_PROGRAM
|
||||
*/
|
||||
assert(st->ctx->VertexProgram._Current);
|
||||
stvp = st_program(st->ctx->VertexProgram._Current);
|
||||
assert(stvp->Base.Target == GL_VERTEX_PROGRAM_ARB);
|
||||
vp = st->ctx->VertexProgram._Current;
|
||||
assert(vp->Target == GL_VERTEX_PROGRAM_ARB);
|
||||
|
||||
if (st->shader_has_one_variant[MESA_SHADER_VERTEX] &&
|
||||
!st->vertdata_edgeflags) {
|
||||
st->vp_variant = st_common_variant(stvp->variants);
|
||||
st->vp_variant = st_common_variant(vp->variants);
|
||||
} else {
|
||||
struct st_common_variant_key key;
|
||||
|
||||
|
@ -226,7 +226,7 @@ st_update_vp( struct st_context *st )
|
|||
|
||||
key.clamp_color = st->clamp_vert_color_in_shader &&
|
||||
st->ctx->Light._ClampVertexColor &&
|
||||
(stvp->Base.info.outputs_written &
|
||||
(vp->info.outputs_written &
|
||||
(VARYING_SLOT_COL0 |
|
||||
VARYING_SLOT_COL1 |
|
||||
VARYING_SLOT_BFC0 |
|
||||
|
@ -250,11 +250,11 @@ st_update_vp( struct st_context *st )
|
|||
update_gl_clamp(st, st->ctx->VertexProgram._Current, key.gl_clamp);
|
||||
|
||||
simple_mtx_lock(&st->ctx->Shared->Mutex);
|
||||
st->vp_variant = st_get_common_variant(st, stvp, &key);
|
||||
st->vp_variant = st_get_common_variant(st, vp, &key);
|
||||
simple_mtx_unlock(&st->ctx->Shared->Mutex);
|
||||
}
|
||||
|
||||
st_reference_prog(st, &st->vp, stvp);
|
||||
_mesa_reference_program(st->ctx, &st->vp, vp);
|
||||
|
||||
cso_set_vertex_shader_handle(st->cso_context,
|
||||
st->vp_variant->base.driver_shader);
|
||||
|
@ -263,20 +263,17 @@ st_update_vp( struct st_context *st )
|
|||
|
||||
static void *
|
||||
st_update_common_program(struct st_context *st, struct gl_program *prog,
|
||||
unsigned pipe_shader, struct st_program **dst)
|
||||
unsigned pipe_shader, struct gl_program **dst)
|
||||
{
|
||||
struct st_program *stp;
|
||||
|
||||
if (!prog) {
|
||||
st_reference_prog(st, dst, NULL);
|
||||
_mesa_reference_program(st->ctx, dst, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stp = st_program(prog);
|
||||
st_reference_prog(st, dst, stp);
|
||||
_mesa_reference_program(st->ctx, dst, prog);
|
||||
|
||||
if (st->shader_has_one_variant[prog->info.stage])
|
||||
return stp->variants->driver_shader;
|
||||
return prog->variants->driver_shader;
|
||||
|
||||
struct st_common_variant_key key;
|
||||
|
||||
|
@ -289,7 +286,7 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
|
|||
pipe_shader == PIPE_SHADER_TESS_EVAL) {
|
||||
key.clamp_color = st->clamp_vert_color_in_shader &&
|
||||
st->ctx->Light._ClampVertexColor &&
|
||||
(stp->Base.info.outputs_written &
|
||||
(prog->info.outputs_written &
|
||||
(VARYING_SLOT_COL0 |
|
||||
VARYING_SLOT_COL1 |
|
||||
VARYING_SLOT_BFC0 |
|
||||
|
@ -312,7 +309,7 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
|
|||
update_gl_clamp(st, prog, key.gl_clamp);
|
||||
|
||||
simple_mtx_lock(&st->ctx->Shared->Mutex);
|
||||
void *result = st_get_common_variant(st, stp, &key)->base.driver_shader;
|
||||
void *result = st_get_common_variant(st, prog, &key)->base.driver_shader;
|
||||
simple_mtx_unlock(&st->ctx->Shared->Mutex);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -196,7 +196,7 @@ setup_render_state(struct gl_context *ctx,
|
|||
GLfloat colorSave[4];
|
||||
COPY_4V(colorSave, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
|
||||
COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], color);
|
||||
st_upload_constants(st, &st->fp->Base, MESA_SHADER_FRAGMENT);
|
||||
st_upload_constants(st, st->fp, MESA_SHADER_FRAGMENT);
|
||||
COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave);
|
||||
}
|
||||
|
||||
|
|
|
@ -1353,7 +1353,7 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
|
|||
/* compiling a new fragment shader variant added new state constants
|
||||
* into the constant buffer, we need to update them
|
||||
*/
|
||||
st_upload_constants(st, &st->fp->Base, MESA_SHADER_FRAGMENT);
|
||||
st_upload_constants(st, st->fp, MESA_SHADER_FRAGMENT);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1738,7 +1738,7 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
|
|||
/* compiling a new fragment shader variant added new state constants
|
||||
* into the constant buffer, we need to update them
|
||||
*/
|
||||
st_upload_constants(st, &st->fp->Base, MESA_SHADER_FRAGMENT);
|
||||
st_upload_constants(st, st->fp, MESA_SHADER_FRAGMENT);
|
||||
} else if (type == GL_DEPTH) {
|
||||
rbRead = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
|
||||
driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
|
||||
|
|
|
@ -309,6 +309,6 @@ st_RenderMode(struct gl_context *ctx, GLenum newMode )
|
|||
ctx->Driver.DrawGalliumMultiMode = _mesa_draw_gallium_multimode_fallback;
|
||||
/* need to generate/use a vertex program that emits pos/color/tex */
|
||||
if (vp)
|
||||
st->dirty |= ST_NEW_VERTEX_PROGRAM(st, st_program(vp));
|
||||
st->dirty |= ST_NEW_VERTEX_PROGRAM(st, vp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,18 +57,18 @@ static struct gl_program *
|
|||
st_new_program(struct gl_context *ctx, gl_shader_stage stage, GLuint id,
|
||||
bool is_arb_asm)
|
||||
{
|
||||
struct st_program *prog;
|
||||
struct gl_program *prog;
|
||||
|
||||
switch (stage) {
|
||||
case MESA_SHADER_VERTEX:
|
||||
prog = (struct st_program*)rzalloc(NULL, struct st_vertex_program);
|
||||
prog = (struct gl_program*)rzalloc(NULL, struct st_vertex_program);
|
||||
break;
|
||||
default:
|
||||
prog = rzalloc(NULL, struct st_program);
|
||||
prog = rzalloc(NULL, struct gl_program);
|
||||
break;
|
||||
}
|
||||
|
||||
return _mesa_init_gl_program(&prog->Base, stage, id, is_arb_asm);
|
||||
return _mesa_init_gl_program(prog, stage, id, is_arb_asm);
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,14 +76,13 @@ void
|
|||
st_delete_program(struct gl_context *ctx, struct gl_program *prog)
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct st_program *stp = st_program(prog);
|
||||
|
||||
st_release_variants(st, stp);
|
||||
st_release_variants(st, prog);
|
||||
|
||||
if (stp->glsl_to_tgsi)
|
||||
free_glsl_to_tgsi_visitor(stp->glsl_to_tgsi);
|
||||
if (prog->glsl_to_tgsi)
|
||||
free_glsl_to_tgsi_visitor(prog->glsl_to_tgsi);
|
||||
|
||||
free(stp->serialized_nir);
|
||||
free(prog->serialized_nir);
|
||||
|
||||
/* delete base class */
|
||||
_mesa_delete_program( ctx, prog );
|
||||
|
@ -99,29 +98,28 @@ st_program_string_notify( struct gl_context *ctx,
|
|||
struct gl_program *prog )
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct st_program *stp = (struct st_program *) prog;
|
||||
|
||||
/* GLSL-to-NIR should not end up here. */
|
||||
assert(!stp->shader_program);
|
||||
assert(!prog->shader_program);
|
||||
|
||||
st_release_variants(st, stp);
|
||||
st_release_variants(st, prog);
|
||||
|
||||
if (target == GL_FRAGMENT_PROGRAM_ARB ||
|
||||
target == GL_FRAGMENT_SHADER_ATI) {
|
||||
if (target == GL_FRAGMENT_SHADER_ATI) {
|
||||
assert(stp->ati_fs);
|
||||
assert(stp->ati_fs->Program == prog);
|
||||
assert(prog->ati_fs);
|
||||
assert(prog->ati_fs->Program == prog);
|
||||
|
||||
st_init_atifs_prog(ctx, prog);
|
||||
}
|
||||
|
||||
if (!st_translate_fragment_program(st, stp))
|
||||
if (!st_translate_fragment_program(st, prog))
|
||||
return false;
|
||||
} else if (target == GL_VERTEX_PROGRAM_ARB) {
|
||||
if (!st_translate_vertex_program(st, stp))
|
||||
if (!st_translate_vertex_program(st, prog))
|
||||
return false;
|
||||
} else {
|
||||
if (!st_translate_common_program(st, stp))
|
||||
if (!st_translate_common_program(st, prog))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -137,8 +135,7 @@ st_new_ati_fs(struct gl_context *ctx, struct ati_fragment_shader *curProg)
|
|||
{
|
||||
struct gl_program *prog = st_new_program(ctx, MESA_SHADER_FRAGMENT,
|
||||
curProg->Id, true);
|
||||
struct st_program *stfp = (struct st_program *)prog;
|
||||
stfp->ati_fs = curProg;
|
||||
prog->ati_fs = curProg;
|
||||
return prog;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,18 +74,12 @@ DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE)
|
|||
static uint64_t
|
||||
st_get_active_states(struct gl_context *ctx)
|
||||
{
|
||||
struct st_program *vp =
|
||||
st_program(ctx->VertexProgram._Current);
|
||||
struct st_program *tcp =
|
||||
st_program(ctx->TessCtrlProgram._Current);
|
||||
struct st_program *tep =
|
||||
st_program(ctx->TessEvalProgram._Current);
|
||||
struct st_program *gp =
|
||||
st_program(ctx->GeometryProgram._Current);
|
||||
struct st_program *fp =
|
||||
st_program(ctx->FragmentProgram._Current);
|
||||
struct st_program *cp =
|
||||
st_program(ctx->ComputeProgram._Current);
|
||||
struct gl_program *vp = ctx->VertexProgram._Current;
|
||||
struct gl_program *tcp = ctx->TessCtrlProgram._Current;
|
||||
struct gl_program *tep = ctx->TessEvalProgram._Current;
|
||||
struct gl_program *gp = ctx->GeometryProgram._Current;
|
||||
struct gl_program *fp = ctx->FragmentProgram._Current;
|
||||
struct gl_program *cp = ctx->ComputeProgram._Current;
|
||||
uint64_t active_shader_states = 0;
|
||||
|
||||
if (vp)
|
||||
|
@ -200,9 +194,9 @@ st_invalidate_state(struct gl_context *ctx)
|
|||
ST_NEW_SAMPLERS |
|
||||
ST_NEW_IMAGE_UNITS);
|
||||
if (ctx->FragmentProgram._Current) {
|
||||
struct st_program *stfp = st_program(ctx->FragmentProgram._Current);
|
||||
struct gl_program *fp = ctx->FragmentProgram._Current;
|
||||
|
||||
if (stfp->Base.ExternalSamplersUsed || stfp->ati_fs)
|
||||
if (fp->ExternalSamplersUsed || fp->ati_fs)
|
||||
st->dirty |= ST_NEW_FS_STATE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -255,12 +255,12 @@ struct st_context
|
|||
|
||||
union {
|
||||
struct {
|
||||
struct st_program *vp; /**< Currently bound vertex program */
|
||||
struct st_program *tcp; /**< Currently bound tess control program */
|
||||
struct st_program *tep; /**< Currently bound tess eval program */
|
||||
struct st_program *gp; /**< Currently bound geometry program */
|
||||
struct st_program *fp; /**< Currently bound fragment program */
|
||||
struct st_program *cp; /**< Currently bound compute program */
|
||||
struct gl_program *vp; /**< Currently bound vertex program */
|
||||
struct gl_program *tcp; /**< Currently bound tess control program */
|
||||
struct gl_program *tep; /**< Currently bound tess eval program */
|
||||
struct gl_program *gp; /**< Currently bound geometry program */
|
||||
struct gl_program *fp; /**< Currently bound fragment program */
|
||||
struct gl_program *cp; /**< Currently bound compute program */
|
||||
};
|
||||
struct gl_program *current_program[MESA_SHADER_STAGES];
|
||||
};
|
||||
|
|
|
@ -222,7 +222,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
|
|||
}
|
||||
|
||||
/* set constant buffer 0 */
|
||||
struct gl_program_parameter_list *params = st->vp->Base.Parameters;
|
||||
struct gl_program_parameter_list *params = st->vp->Parameters;
|
||||
|
||||
/* Update the constants which come from fixed-function state, such as
|
||||
* transformation matrices, fog factors, etc.
|
||||
|
@ -239,7 +239,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
|
|||
params->NumParameterValues * 4);
|
||||
|
||||
/* set uniform buffers */
|
||||
const struct gl_program *prog = &vp->Base.Base;
|
||||
const struct gl_program *prog = &vp->Base;
|
||||
struct pipe_transfer *ubo_transfer[PIPE_MAX_CONSTANT_BUFFERS] = {0};
|
||||
assert(prog->info.num_ubos <= ARRAY_SIZE(ubo_transfer));
|
||||
|
||||
|
|
|
@ -184,10 +184,10 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
|
|||
for (uint32_t i = 0; i < MESA_SHADER_STAGES; ++i) {
|
||||
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
|
||||
if (shader) {
|
||||
struct st_program *stp = st_program(shader->Program);
|
||||
if (stp && stp->variants) {
|
||||
struct gl_program *p = shader->Program;
|
||||
if (p && p->variants) {
|
||||
enum pipe_shader_type type = pipe_shader_type_from_mesa(shader->Stage);
|
||||
driver_handles[type] = stp->variants->driver_shader;
|
||||
driver_handles[type] = p->variants->driver_shader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -743,13 +743,12 @@ st_link_nir(struct gl_context *ctx,
|
|||
const nir_shader_compiler_options *options =
|
||||
st->ctx->Const.ShaderCompilerOptions[shader->Stage].NirOptions;
|
||||
struct gl_program *prog = shader->Program;
|
||||
struct st_program *stp = (struct st_program *)prog;
|
||||
|
||||
_mesa_copy_linked_program_data(shader_program, shader);
|
||||
|
||||
assert(!prog->nir);
|
||||
stp->shader_program = shader_program;
|
||||
stp->state.type = PIPE_SHADER_IR_NIR;
|
||||
prog->shader_program = shader_program;
|
||||
prog->state.type = PIPE_SHADER_IR_NIR;
|
||||
|
||||
/* Parameters will be filled during NIR linking. */
|
||||
prog->Parameters = _mesa_new_parameter_list();
|
||||
|
@ -908,7 +907,6 @@ st_link_nir(struct gl_context *ctx,
|
|||
for (unsigned i = 0; i < num_shaders; i++) {
|
||||
struct gl_linked_shader *shader = linked_shader[i];
|
||||
struct gl_program *prog = shader->Program;
|
||||
struct st_program *stp = st_program(prog);
|
||||
|
||||
/* Make sure that prog->info is in sync with nir->info, but st/mesa
|
||||
* expects some of the values to be from before lowering.
|
||||
|
@ -925,7 +923,7 @@ st_link_nir(struct gl_context *ctx,
|
|||
|
||||
/* Initialize st_vertex_program members. */
|
||||
if (shader->Stage == MESA_SHADER_VERTEX)
|
||||
st_prepare_vertex_program(stp, NULL);
|
||||
st_prepare_vertex_program(prog, NULL);
|
||||
|
||||
/* Get pipe_stream_output_info. */
|
||||
if (shader->Stage == MESA_SHADER_VERTEX ||
|
||||
|
@ -935,7 +933,7 @@ st_link_nir(struct gl_context *ctx,
|
|||
|
||||
st_store_ir_in_disk_cache(st, prog, true);
|
||||
|
||||
st_release_variants(st, stp);
|
||||
st_release_variants(st, prog);
|
||||
st_finalize_program(st, prog);
|
||||
|
||||
/* The GLSL IR won't be needed anymore. */
|
||||
|
|
|
@ -7391,7 +7391,8 @@ get_mesa_program_tgsi(struct gl_context *ctx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
st_program(prog)->glsl_to_tgsi = v;
|
||||
|
||||
prog->glsl_to_tgsi = v;
|
||||
|
||||
PRINT_STATS(v->print_stats());
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
|
|||
|
||||
switch (prog->info.stage) {
|
||||
case MESA_SHADER_VERTEX:
|
||||
states = &((struct st_program*)prog)->affected_states;
|
||||
states = &prog->affected_states;
|
||||
|
||||
*states = ST_NEW_VS_STATE |
|
||||
ST_NEW_RASTERIZER |
|
||||
|
@ -130,7 +130,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
|
|||
break;
|
||||
|
||||
case MESA_SHADER_TESS_CTRL:
|
||||
states = &(st_program(prog))->affected_states;
|
||||
states = &prog->affected_states;
|
||||
|
||||
*states = ST_NEW_TCS_STATE;
|
||||
|
||||
|
@ -145,7 +145,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
|
|||
break;
|
||||
|
||||
case MESA_SHADER_TESS_EVAL:
|
||||
states = &(st_program(prog))->affected_states;
|
||||
states = &prog->affected_states;
|
||||
|
||||
*states = ST_NEW_TES_STATE |
|
||||
ST_NEW_RASTERIZER;
|
||||
|
@ -161,7 +161,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
|
|||
break;
|
||||
|
||||
case MESA_SHADER_GEOMETRY:
|
||||
states = &(st_program(prog))->affected_states;
|
||||
states = &prog->affected_states;
|
||||
|
||||
*states = ST_NEW_GS_STATE |
|
||||
ST_NEW_RASTERIZER;
|
||||
|
@ -177,7 +177,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
|
|||
break;
|
||||
|
||||
case MESA_SHADER_FRAGMENT:
|
||||
states = &((struct st_program*)prog)->affected_states;
|
||||
states = &prog->affected_states;
|
||||
|
||||
/* gl_FragCoord and glDrawPixels always use constants. */
|
||||
*states = ST_NEW_FS_STATE |
|
||||
|
@ -195,7 +195,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
|
|||
break;
|
||||
|
||||
case MESA_SHADER_COMPUTE:
|
||||
states = &((struct st_program*)prog)->affected_states;
|
||||
states = &prog->affected_states;
|
||||
|
||||
*states = ST_NEW_CS_STATE;
|
||||
|
||||
|
@ -268,10 +268,10 @@ delete_variant(struct st_context *st, struct st_variant *v, GLenum target)
|
|||
}
|
||||
|
||||
static void
|
||||
st_unbind_program(struct st_context *st, struct st_program *p)
|
||||
st_unbind_program(struct st_context *st, struct gl_program *p)
|
||||
{
|
||||
/* Unbind the shader in cso_context and re-bind in st/mesa. */
|
||||
switch (p->Base.info.stage) {
|
||||
switch (p->info.stage) {
|
||||
case MESA_SHADER_VERTEX:
|
||||
cso_set_vertex_shader_handle(st->cso_context, NULL);
|
||||
st->dirty |= ST_NEW_VS_STATE;
|
||||
|
@ -305,7 +305,7 @@ st_unbind_program(struct st_context *st, struct st_program *p)
|
|||
* Free all basic program variants.
|
||||
*/
|
||||
void
|
||||
st_release_variants(struct st_context *st, struct st_program *p)
|
||||
st_release_variants(struct st_context *st, struct gl_program *p)
|
||||
{
|
||||
struct st_variant *v;
|
||||
|
||||
|
@ -317,7 +317,7 @@ st_release_variants(struct st_context *st, struct st_program *p)
|
|||
|
||||
for (v = p->variants; v; ) {
|
||||
struct st_variant *next = v->next;
|
||||
delete_variant(st, v, p->Base.Target);
|
||||
delete_variant(st, v, p->Target);
|
||||
v = next;
|
||||
}
|
||||
|
||||
|
@ -342,13 +342,13 @@ st_release_variants(struct st_context *st, struct st_program *p)
|
|||
* Free all basic program variants and unref program.
|
||||
*/
|
||||
void
|
||||
st_release_program(struct st_context *st, struct st_program **p)
|
||||
st_release_program(struct st_context *st, struct gl_program **p)
|
||||
{
|
||||
if (!*p)
|
||||
return;
|
||||
|
||||
destroy_program_variants(st, &((*p)->Base));
|
||||
st_reference_prog(st, p, NULL);
|
||||
destroy_program_variants(st, *p);
|
||||
_mesa_reference_program(st->ctx, p, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -422,9 +422,9 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog,
|
|||
* input index.
|
||||
*/
|
||||
void
|
||||
st_prepare_vertex_program(struct st_program *stp, uint8_t *out_attrib_to_index)
|
||||
st_prepare_vertex_program(struct gl_program *prog, uint8_t *out_attrib_to_index)
|
||||
{
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)prog;
|
||||
uint8_t attrib_to_index[VERT_ATTRIB_MAX] = {0};
|
||||
|
||||
stvp->num_inputs = 0;
|
||||
|
@ -435,7 +435,7 @@ st_prepare_vertex_program(struct st_program *stp, uint8_t *out_attrib_to_index)
|
|||
* and TGSI generic input indexes, plus input attrib semantic info.
|
||||
*/
|
||||
for (unsigned attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
|
||||
if ((stp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
|
||||
if ((prog->info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
|
||||
attrib_to_index[attr] = stvp->num_inputs;
|
||||
stvp->vert_attrib_mask |= BITFIELD_BIT(attr);
|
||||
stvp->num_inputs++;
|
||||
|
@ -448,7 +448,7 @@ st_prepare_vertex_program(struct st_program *stp, uint8_t *out_attrib_to_index)
|
|||
/* Compute mapping of vertex program outputs to slots. */
|
||||
unsigned num_outputs = 0;
|
||||
for (unsigned attr = 0; attr < VARYING_SLOT_MAX; attr++) {
|
||||
if (stp->Base.info.outputs_written & BITFIELD64_BIT(attr))
|
||||
if (prog->info.outputs_written & BITFIELD64_BIT(attr))
|
||||
stvp->result_to_output[attr] = num_outputs++;
|
||||
}
|
||||
/* pre-setup potentially unused edgeflag output */
|
||||
|
@ -477,7 +477,7 @@ st_translate_stream_output_info(struct gl_program *prog)
|
|||
|
||||
/* Translate stream output info. */
|
||||
struct pipe_stream_output_info *so_info =
|
||||
&((struct st_program*)prog)->state.stream_output;
|
||||
&prog->state.stream_output;
|
||||
|
||||
for (unsigned i = 0; i < info->NumOutputs; i++) {
|
||||
so_info->output[i].register_index =
|
||||
|
@ -579,7 +579,7 @@ st_create_nir_shader(struct st_context *st, struct pipe_shader_state *state)
|
|||
*/
|
||||
bool
|
||||
st_translate_vertex_program(struct st_context *st,
|
||||
struct st_program *stp)
|
||||
struct gl_program *prog)
|
||||
{
|
||||
struct ureg_program *ureg;
|
||||
enum pipe_error error;
|
||||
|
@ -589,45 +589,45 @@ st_translate_vertex_program(struct st_context *st,
|
|||
ubyte output_semantic_index[VARYING_SLOT_MAX] = {0};
|
||||
|
||||
/* ARB_vp: */
|
||||
if (!stp->glsl_to_tgsi) {
|
||||
if (stp->Base.arb.IsPositionInvariant)
|
||||
_mesa_insert_mvp_code(st->ctx, &stp->Base);
|
||||
if (!prog->glsl_to_tgsi) {
|
||||
if (prog->arb.IsPositionInvariant)
|
||||
_mesa_insert_mvp_code(st->ctx, prog);
|
||||
|
||||
_mesa_remove_output_reads(&stp->Base, PROGRAM_OUTPUT);
|
||||
_mesa_remove_output_reads(prog, PROGRAM_OUTPUT);
|
||||
|
||||
/* This determines which states will be updated when the assembly
|
||||
* shader is bound.
|
||||
*/
|
||||
stp->affected_states = ST_NEW_VS_STATE |
|
||||
prog->affected_states = ST_NEW_VS_STATE |
|
||||
ST_NEW_RASTERIZER |
|
||||
ST_NEW_VERTEX_ARRAYS;
|
||||
|
||||
if (stp->Base.Parameters->NumParameters)
|
||||
stp->affected_states |= ST_NEW_VS_CONSTANTS;
|
||||
if (prog->Parameters->NumParameters)
|
||||
prog->affected_states |= ST_NEW_VS_CONSTANTS;
|
||||
|
||||
if (stp->Base.nir)
|
||||
ralloc_free(stp->Base.nir);
|
||||
if (prog->nir)
|
||||
ralloc_free(prog->nir);
|
||||
|
||||
if (stp->serialized_nir) {
|
||||
free(stp->serialized_nir);
|
||||
stp->serialized_nir = NULL;
|
||||
if (prog->serialized_nir) {
|
||||
free(prog->serialized_nir);
|
||||
prog->serialized_nir = NULL;
|
||||
}
|
||||
|
||||
stp->state.type = PIPE_SHADER_IR_NIR;
|
||||
stp->Base.nir = st_translate_prog_to_nir(st, &stp->Base,
|
||||
MESA_SHADER_VERTEX);
|
||||
stp->Base.info = stp->Base.nir->info;
|
||||
prog->state.type = PIPE_SHADER_IR_NIR;
|
||||
prog->nir = st_translate_prog_to_nir(st, prog,
|
||||
MESA_SHADER_VERTEX);
|
||||
prog->info = prog->nir->info;
|
||||
|
||||
st_prepare_vertex_program(stp, NULL);
|
||||
st_prepare_vertex_program(prog, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t input_to_index[VERT_ATTRIB_MAX];
|
||||
st_prepare_vertex_program(stp, input_to_index);
|
||||
st_prepare_vertex_program(prog, input_to_index);
|
||||
|
||||
/* Get semantic names and indices. */
|
||||
for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
|
||||
if (stp->Base.info.outputs_written & BITFIELD64_BIT(attr)) {
|
||||
if (prog->info.outputs_written & BITFIELD64_BIT(attr)) {
|
||||
unsigned slot = num_outputs++;
|
||||
unsigned semantic_name, semantic_index;
|
||||
tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic,
|
||||
|
@ -644,21 +644,21 @@ st_translate_vertex_program(struct st_context *st,
|
|||
if (ureg == NULL)
|
||||
return false;
|
||||
|
||||
ureg_setup_shader_info(ureg, &stp->Base.info);
|
||||
ureg_setup_shader_info(ureg, &prog->info);
|
||||
|
||||
if (ST_DEBUG & DEBUG_MESA) {
|
||||
_mesa_print_program(&stp->Base);
|
||||
_mesa_print_program_parameters(st->ctx, &stp->Base);
|
||||
_mesa_print_program(prog);
|
||||
_mesa_print_program_parameters(st->ctx, prog);
|
||||
debug_printf("\n");
|
||||
}
|
||||
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)prog;
|
||||
|
||||
error = st_translate_program(st->ctx,
|
||||
PIPE_SHADER_VERTEX,
|
||||
ureg,
|
||||
stp->glsl_to_tgsi,
|
||||
&stp->Base,
|
||||
prog->glsl_to_tgsi,
|
||||
prog,
|
||||
/* inputs */
|
||||
stvp->num_inputs,
|
||||
input_to_index,
|
||||
|
@ -672,46 +672,46 @@ st_translate_vertex_program(struct st_context *st,
|
|||
output_semantic_name,
|
||||
output_semantic_index);
|
||||
|
||||
st_translate_stream_output_info(&stp->Base);
|
||||
st_translate_stream_output_info(prog);
|
||||
|
||||
free_glsl_to_tgsi_visitor(stp->glsl_to_tgsi);
|
||||
free_glsl_to_tgsi_visitor(prog->glsl_to_tgsi);
|
||||
|
||||
if (error) {
|
||||
debug_printf("%s: failed to translate GLSL IR program:\n", __func__);
|
||||
_mesa_print_program(&stp->Base);
|
||||
_mesa_print_program(prog);
|
||||
debug_assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
stp->state.tokens = ureg_get_tokens(ureg, NULL);
|
||||
prog->state.tokens = ureg_get_tokens(ureg, NULL);
|
||||
ureg_destroy(ureg);
|
||||
|
||||
stp->glsl_to_tgsi = NULL;
|
||||
st_store_ir_in_disk_cache(st, &stp->Base, false);
|
||||
prog->glsl_to_tgsi = NULL;
|
||||
st_store_ir_in_disk_cache(st, prog, false);
|
||||
|
||||
return stp->state.tokens != NULL;
|
||||
return prog->state.tokens != NULL;
|
||||
}
|
||||
|
||||
static struct nir_shader *
|
||||
get_nir_shader(struct st_context *st, struct st_program *stp)
|
||||
get_nir_shader(struct st_context *st, struct gl_program *prog)
|
||||
{
|
||||
if (stp->Base.nir) {
|
||||
nir_shader *nir = stp->Base.nir;
|
||||
if (prog->nir) {
|
||||
nir_shader *nir = prog->nir;
|
||||
|
||||
/* The first shader variant takes ownership of NIR, so that there is
|
||||
* no cloning. Additional shader variants are always generated from
|
||||
* serialized NIR to save memory.
|
||||
*/
|
||||
stp->Base.nir = NULL;
|
||||
assert(stp->serialized_nir && stp->serialized_nir_size);
|
||||
prog->nir = NULL;
|
||||
assert(prog->serialized_nir && prog->serialized_nir_size);
|
||||
return nir;
|
||||
}
|
||||
|
||||
struct blob_reader blob_reader;
|
||||
const struct nir_shader_compiler_options *options =
|
||||
st_get_nir_compiler_options(st, stp->Base.info.stage);
|
||||
st_get_nir_compiler_options(st, prog->info.stage);
|
||||
|
||||
blob_reader_init(&blob_reader, stp->serialized_nir, stp->serialized_nir_size);
|
||||
blob_reader_init(&blob_reader, prog->serialized_nir, prog->serialized_nir_size);
|
||||
return nir_deserialize(NULL, options, &blob_reader);
|
||||
}
|
||||
|
||||
|
@ -758,8 +758,8 @@ lower_ucp(struct st_context *st,
|
|||
|
||||
static struct st_common_variant *
|
||||
st_create_common_variant(struct st_context *st,
|
||||
struct st_program *stp,
|
||||
const struct st_common_variant_key *key)
|
||||
struct gl_program *prog,
|
||||
const struct st_common_variant_key *key)
|
||||
{
|
||||
struct st_common_variant *v = CALLOC_STRUCT(st_common_variant);
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
|
@ -767,17 +767,17 @@ st_create_common_variant(struct st_context *st,
|
|||
|
||||
static const gl_state_index16 point_size_state[STATE_LENGTH] =
|
||||
{ STATE_POINT_SIZE_CLAMPED, 0 };
|
||||
struct gl_program_parameter_list *params = stp->Base.Parameters;
|
||||
struct gl_program_parameter_list *params = prog->Parameters;
|
||||
|
||||
v->key = *key;
|
||||
|
||||
state.stream_output = stp->state.stream_output;
|
||||
state.stream_output = prog->state.stream_output;
|
||||
|
||||
if (stp->state.type == PIPE_SHADER_IR_NIR) {
|
||||
if (prog->state.type == PIPE_SHADER_IR_NIR) {
|
||||
bool finalize = false;
|
||||
|
||||
state.type = PIPE_SHADER_IR_NIR;
|
||||
state.ir.nir = get_nir_shader(st, stp);
|
||||
state.ir.nir = get_nir_shader(st, prog);
|
||||
const nir_shader_compiler_options *options = ((nir_shader *)state.ir.nir)->options;
|
||||
|
||||
if (key->clamp_color) {
|
||||
|
@ -798,15 +798,15 @@ st_create_common_variant(struct st_context *st,
|
|||
NIR_PASS_V(state.ir.nir, nir_lower_point_size_mov,
|
||||
point_size_state);
|
||||
|
||||
switch (stp->Base.info.stage) {
|
||||
switch (prog->info.stage) {
|
||||
case MESA_SHADER_VERTEX:
|
||||
stp->affected_states |= ST_NEW_VS_CONSTANTS;
|
||||
prog->affected_states |= ST_NEW_VS_CONSTANTS;
|
||||
break;
|
||||
case MESA_SHADER_TESS_EVAL:
|
||||
stp->affected_states |= ST_NEW_TES_CONSTANTS;
|
||||
prog->affected_states |= ST_NEW_TES_CONSTANTS;
|
||||
break;
|
||||
case MESA_SHADER_GEOMETRY:
|
||||
stp->affected_states |= ST_NEW_GS_CONSTANTS;
|
||||
prog->affected_states |= ST_NEW_GS_CONSTANTS;
|
||||
break;
|
||||
default:
|
||||
unreachable("bad shader stage");
|
||||
|
@ -832,7 +832,7 @@ st_create_common_variant(struct st_context *st,
|
|||
}
|
||||
|
||||
if (finalize || !st->allow_st_finalize_nir_twice) {
|
||||
char *msg = st_finalize_nir(st, &stp->Base, stp->shader_program, state.ir.nir,
|
||||
char *msg = st_finalize_nir(st, prog, prog->shader_program, state.ir.nir,
|
||||
true, false);
|
||||
free(msg);
|
||||
|
||||
|
@ -859,7 +859,7 @@ st_create_common_variant(struct st_context *st,
|
|||
}
|
||||
|
||||
state.type = PIPE_SHADER_IR_TGSI;
|
||||
state.tokens = tgsi_dup_tokens(stp->state.tokens);
|
||||
state.tokens = tgsi_dup_tokens(prog->state.tokens);
|
||||
|
||||
/* Emulate features. */
|
||||
if (key->clamp_color || key->passthrough_edgeflags) {
|
||||
|
@ -881,7 +881,7 @@ st_create_common_variant(struct st_context *st,
|
|||
if (ST_DEBUG & DEBUG_PRINT_IR)
|
||||
tgsi_dump(state.tokens, 0);
|
||||
|
||||
switch (stp->Base.info.stage) {
|
||||
switch (prog->info.stage) {
|
||||
case MESA_SHADER_VERTEX:
|
||||
if (key->is_draw_shader)
|
||||
v->base.driver_shader = draw_create_vertex_shader(st->draw, &state);
|
||||
|
@ -900,7 +900,7 @@ st_create_common_variant(struct st_context *st,
|
|||
case MESA_SHADER_COMPUTE: {
|
||||
struct pipe_compute_state cs = {0};
|
||||
cs.ir_type = state.type;
|
||||
cs.req_local_mem = stp->Base.info.shared_size;
|
||||
cs.req_local_mem = prog->info.shared_size;
|
||||
|
||||
if (state.type == PIPE_SHADER_IR_NIR)
|
||||
cs.prog = state.ir.nir;
|
||||
|
@ -944,13 +944,13 @@ st_add_variant(struct st_variant **list, struct st_variant *v)
|
|||
*/
|
||||
struct st_common_variant *
|
||||
st_get_common_variant(struct st_context *st,
|
||||
struct st_program *stp,
|
||||
const struct st_common_variant_key *key)
|
||||
struct gl_program *prog,
|
||||
const struct st_common_variant_key *key)
|
||||
{
|
||||
struct st_common_variant *v;
|
||||
|
||||
/* Search for existing variant */
|
||||
for (v = st_common_variant(stp->variants); v;
|
||||
for (v = st_common_variant(prog->variants); v;
|
||||
v = st_common_variant(v->base.next)) {
|
||||
if (memcmp(&v->key, key, sizeof(*key)) == 0) {
|
||||
break;
|
||||
|
@ -958,10 +958,10 @@ st_get_common_variant(struct st_context *st,
|
|||
}
|
||||
|
||||
if (!v) {
|
||||
if (stp->variants != NULL) {
|
||||
if (prog->variants != NULL) {
|
||||
_mesa_perf_debug(st->ctx, MESA_DEBUG_SEVERITY_MEDIUM,
|
||||
"Compiling %s shader variant (%s%s%s%s%s%s)",
|
||||
_mesa_shader_stage_to_string(stp->Base.info.stage),
|
||||
_mesa_shader_stage_to_string(prog->info.stage),
|
||||
key->passthrough_edgeflags ? "edgeflags," : "",
|
||||
key->clamp_color ? "clamp_color," : "",
|
||||
key->export_point_size ? "point_size," : "",
|
||||
|
@ -971,19 +971,19 @@ st_get_common_variant(struct st_context *st,
|
|||
}
|
||||
|
||||
/* create now */
|
||||
v = st_create_common_variant(st, stp, key);
|
||||
v = st_create_common_variant(st, prog, key);
|
||||
if (v) {
|
||||
v->base.st = key->st;
|
||||
|
||||
if (stp->Base.info.stage == MESA_SHADER_VERTEX) {
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
|
||||
if (prog->info.stage == MESA_SHADER_VERTEX) {
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)prog;
|
||||
|
||||
v->vert_attrib_mask =
|
||||
stvp->vert_attrib_mask |
|
||||
(key->passthrough_edgeflags ? VERT_BIT_EDGEFLAG : 0);
|
||||
}
|
||||
|
||||
st_add_variant(&stp->variants, &v->base);
|
||||
st_add_variant(&prog->variants, &v->base);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -996,47 +996,47 @@ st_get_common_variant(struct st_context *st,
|
|||
*/
|
||||
bool
|
||||
st_translate_fragment_program(struct st_context *st,
|
||||
struct st_program *stfp)
|
||||
struct gl_program *fp)
|
||||
{
|
||||
/* Non-GLSL programs: */
|
||||
if (!stfp->glsl_to_tgsi) {
|
||||
_mesa_remove_output_reads(&stfp->Base, PROGRAM_OUTPUT);
|
||||
if (!fp->glsl_to_tgsi) {
|
||||
_mesa_remove_output_reads(fp, PROGRAM_OUTPUT);
|
||||
if (st->ctx->Const.GLSLFragCoordIsSysVal)
|
||||
_mesa_program_fragment_position_to_sysval(&stfp->Base);
|
||||
_mesa_program_fragment_position_to_sysval(fp);
|
||||
|
||||
/* This determines which states will be updated when the assembly
|
||||
* shader is bound.
|
||||
*
|
||||
* fragment.position and glDrawPixels always use constants.
|
||||
*/
|
||||
stfp->affected_states = ST_NEW_FS_STATE |
|
||||
fp->affected_states = ST_NEW_FS_STATE |
|
||||
ST_NEW_SAMPLE_SHADING |
|
||||
ST_NEW_FS_CONSTANTS;
|
||||
|
||||
if (stfp->ati_fs) {
|
||||
if (fp->ati_fs) {
|
||||
/* Just set them for ATI_fs unconditionally. */
|
||||
stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
|
||||
fp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
|
||||
ST_NEW_FS_SAMPLERS;
|
||||
} else {
|
||||
/* ARB_fp */
|
||||
if (stfp->Base.SamplersUsed)
|
||||
stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
|
||||
if (fp->SamplersUsed)
|
||||
fp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
|
||||
ST_NEW_FS_SAMPLERS;
|
||||
}
|
||||
|
||||
/* Translate to NIR. ATI_fs translates at variant time. */
|
||||
if (!stfp->ati_fs) {
|
||||
if (!fp->ati_fs) {
|
||||
nir_shader *nir =
|
||||
st_translate_prog_to_nir(st, &stfp->Base, MESA_SHADER_FRAGMENT);
|
||||
st_translate_prog_to_nir(st, fp, MESA_SHADER_FRAGMENT);
|
||||
|
||||
if (stfp->Base.nir)
|
||||
ralloc_free(stfp->Base.nir);
|
||||
if (stfp->serialized_nir) {
|
||||
free(stfp->serialized_nir);
|
||||
stfp->serialized_nir = NULL;
|
||||
if (fp->nir)
|
||||
ralloc_free(fp->nir);
|
||||
if (fp->serialized_nir) {
|
||||
free(fp->serialized_nir);
|
||||
fp->serialized_nir = NULL;
|
||||
}
|
||||
stfp->state.type = PIPE_SHADER_IR_NIR;
|
||||
stfp->Base.nir = nir;
|
||||
fp->state.type = PIPE_SHADER_IR_NIR;
|
||||
fp->nir = nir;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1065,7 +1065,7 @@ st_translate_fragment_program(struct st_context *st,
|
|||
/*
|
||||
* Convert Mesa program inputs to TGSI input register semantics.
|
||||
*/
|
||||
inputsRead = stfp->Base.info.inputs_read;
|
||||
inputsRead = fp->info.inputs_read;
|
||||
for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
|
||||
if ((inputsRead & BITFIELD64_BIT(attr)) != 0) {
|
||||
const GLuint slot = fs_num_inputs++;
|
||||
|
@ -1082,13 +1082,13 @@ st_translate_fragment_program(struct st_context *st,
|
|||
case VARYING_SLOT_COL0:
|
||||
input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
|
||||
input_semantic_index[slot] = 0;
|
||||
interpMode[slot] = stfp->glsl_to_tgsi ?
|
||||
interpMode[slot] = fp->glsl_to_tgsi ?
|
||||
TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_COLOR;
|
||||
break;
|
||||
case VARYING_SLOT_COL1:
|
||||
input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
|
||||
input_semantic_index[slot] = 1;
|
||||
interpMode[slot] = stfp->glsl_to_tgsi ?
|
||||
interpMode[slot] = fp->glsl_to_tgsi ?
|
||||
TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_COLOR;
|
||||
break;
|
||||
case VARYING_SLOT_FOGC:
|
||||
|
@ -1165,7 +1165,7 @@ st_translate_fragment_program(struct st_context *st,
|
|||
if (st->needs_texcoord_semantic) {
|
||||
input_semantic_name[slot] = TGSI_SEMANTIC_TEXCOORD;
|
||||
input_semantic_index[slot] = attr - VARYING_SLOT_TEX0;
|
||||
interpMode[slot] = stfp->glsl_to_tgsi ?
|
||||
interpMode[slot] = fp->glsl_to_tgsi ?
|
||||
TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_PERSPECTIVE;
|
||||
break;
|
||||
}
|
||||
|
@ -1189,7 +1189,7 @@ st_translate_fragment_program(struct st_context *st,
|
|||
if (attr == VARYING_SLOT_PNTC)
|
||||
interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
|
||||
else {
|
||||
interpMode[slot] = stfp->glsl_to_tgsi ?
|
||||
interpMode[slot] = fp->glsl_to_tgsi ?
|
||||
TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_PERSPECTIVE;
|
||||
}
|
||||
break;
|
||||
|
@ -1203,7 +1203,7 @@ st_translate_fragment_program(struct st_context *st,
|
|||
/*
|
||||
* Semantics and mapping for outputs
|
||||
*/
|
||||
GLbitfield64 outputsWritten = stfp->Base.info.outputs_written;
|
||||
GLbitfield64 outputsWritten = fp->info.outputs_written;
|
||||
|
||||
/* if z is written, emit that first */
|
||||
if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
|
||||
|
@ -1233,7 +1233,7 @@ st_translate_fragment_program(struct st_context *st,
|
|||
/* handle remaining outputs (color) */
|
||||
for (attr = 0; attr < ARRAY_SIZE(outputMapping); attr++) {
|
||||
const GLbitfield64 written = attr < FRAG_RESULT_MAX ? outputsWritten :
|
||||
stfp->Base.SecondaryOutputsWritten;
|
||||
fp->SecondaryOutputsWritten;
|
||||
const unsigned loc = attr % FRAG_RESULT_MAX;
|
||||
|
||||
if (written & BITFIELD64_BIT(loc)) {
|
||||
|
@ -1275,22 +1275,22 @@ st_translate_fragment_program(struct st_context *st,
|
|||
if (ureg == NULL)
|
||||
return false;
|
||||
|
||||
ureg_setup_shader_info(ureg, &stfp->Base.info);
|
||||
ureg_setup_shader_info(ureg, &fp->info);
|
||||
|
||||
if (ST_DEBUG & DEBUG_MESA) {
|
||||
_mesa_print_program(&stfp->Base);
|
||||
_mesa_print_program_parameters(st->ctx, &stfp->Base);
|
||||
_mesa_print_program(fp);
|
||||
_mesa_print_program_parameters(st->ctx, fp);
|
||||
debug_printf("\n");
|
||||
}
|
||||
if (write_all == GL_TRUE)
|
||||
ureg_property(ureg, TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS, 1);
|
||||
|
||||
if (stfp->glsl_to_tgsi) {
|
||||
if (fp->glsl_to_tgsi) {
|
||||
st_translate_program(st->ctx,
|
||||
PIPE_SHADER_FRAGMENT,
|
||||
ureg,
|
||||
stfp->glsl_to_tgsi,
|
||||
&stfp->Base,
|
||||
fp->glsl_to_tgsi,
|
||||
fp,
|
||||
/* inputs */
|
||||
fs_num_inputs,
|
||||
inputMapping,
|
||||
|
@ -1304,29 +1304,29 @@ st_translate_fragment_program(struct st_context *st,
|
|||
fs_output_semantic_name,
|
||||
fs_output_semantic_index);
|
||||
|
||||
free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
|
||||
free_glsl_to_tgsi_visitor(fp->glsl_to_tgsi);
|
||||
}
|
||||
|
||||
stfp->state.tokens = ureg_get_tokens(ureg, NULL);
|
||||
fp->state.tokens = ureg_get_tokens(ureg, NULL);
|
||||
ureg_destroy(ureg);
|
||||
|
||||
if (stfp->glsl_to_tgsi) {
|
||||
stfp->glsl_to_tgsi = NULL;
|
||||
st_store_ir_in_disk_cache(st, &stfp->Base, false);
|
||||
if (fp->glsl_to_tgsi) {
|
||||
fp->glsl_to_tgsi = NULL;
|
||||
st_store_ir_in_disk_cache(st, fp, false);
|
||||
}
|
||||
|
||||
return stfp->state.tokens != NULL;
|
||||
return fp->state.tokens != NULL;
|
||||
}
|
||||
|
||||
static struct st_fp_variant *
|
||||
st_create_fp_variant(struct st_context *st,
|
||||
struct st_program *stfp,
|
||||
struct gl_program *fp,
|
||||
const struct st_fp_variant_key *key)
|
||||
{
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
struct st_fp_variant *variant = CALLOC_STRUCT(st_fp_variant);
|
||||
struct pipe_shader_state state = {0};
|
||||
struct gl_program_parameter_list *params = stfp->Base.Parameters;
|
||||
struct gl_program_parameter_list *params = fp->Parameters;
|
||||
static const gl_state_index16 texcoord_state[STATE_LENGTH] =
|
||||
{ STATE_CURRENT_ATTRIB, VERT_ATTRIB_TEX0 };
|
||||
static const gl_state_index16 scale_state[STATE_LENGTH] =
|
||||
|
@ -1342,19 +1342,19 @@ st_create_fp_variant(struct st_context *st,
|
|||
/* Translate ATI_fs to NIR at variant time because that's when we have the
|
||||
* texture types.
|
||||
*/
|
||||
if (stfp->ati_fs) {
|
||||
if (fp->ati_fs) {
|
||||
const struct nir_shader_compiler_options *options =
|
||||
st_get_nir_compiler_options(st, MESA_SHADER_FRAGMENT);
|
||||
|
||||
nir_shader *s = st_translate_atifs_program(stfp->ati_fs, key, &stfp->Base, options);
|
||||
nir_shader *s = st_translate_atifs_program(fp->ati_fs, key, fp, options);
|
||||
|
||||
st_prog_to_nir_postprocess(st, s, &stfp->Base);
|
||||
st_prog_to_nir_postprocess(st, s, fp);
|
||||
|
||||
state.type = PIPE_SHADER_IR_NIR;
|
||||
state.ir.nir = s;
|
||||
} else if (stfp->state.type == PIPE_SHADER_IR_NIR) {
|
||||
} else if (fp->state.type == PIPE_SHADER_IR_NIR) {
|
||||
state.type = PIPE_SHADER_IR_NIR;
|
||||
state.ir.nir = get_nir_shader(st, stfp);
|
||||
state.ir.nir = get_nir_shader(st, fp);
|
||||
}
|
||||
|
||||
if (state.type == PIPE_SHADER_IR_NIR) {
|
||||
|
@ -1413,7 +1413,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
if (key->bitmap) {
|
||||
nir_lower_bitmap_options options = {0};
|
||||
|
||||
variant->bitmap_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
|
||||
variant->bitmap_sampler = ffs(~fp->SamplersUsed) - 1;
|
||||
options.sampler = variant->bitmap_sampler;
|
||||
options.swizzle_xxxx = st->bitmap.tex_format == PIPE_FORMAT_R8_UNORM;
|
||||
|
||||
|
@ -1424,7 +1424,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
/* glDrawPixels (color only) */
|
||||
if (key->drawpixels) {
|
||||
nir_lower_drawpixels_options options = {{0}};
|
||||
unsigned samplers_used = stfp->Base.SamplersUsed;
|
||||
unsigned samplers_used = fp->SamplersUsed;
|
||||
|
||||
/* Find the first unused slot. */
|
||||
variant->drawpix_sampler = ffs(~samplers_used) - 1;
|
||||
|
@ -1464,7 +1464,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
key->external.lower_y41x)) {
|
||||
|
||||
st_nir_lower_samplers(st->screen, state.ir.nir,
|
||||
stfp->shader_program, &stfp->Base);
|
||||
fp->shader_program, fp);
|
||||
|
||||
nir_lower_tex_options options = {0};
|
||||
options.lower_y_uv_external = key->external.lower_nv12;
|
||||
|
@ -1482,7 +1482,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
}
|
||||
|
||||
if (finalize || !st->allow_st_finalize_nir_twice) {
|
||||
char *msg = st_finalize_nir(st, &stfp->Base, stfp->shader_program, state.ir.nir,
|
||||
char *msg = st_finalize_nir(st, fp, fp->shader_program, state.ir.nir,
|
||||
false, false);
|
||||
free(msg);
|
||||
}
|
||||
|
@ -1490,7 +1490,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
/* This pass needs to happen *after* nir_lower_sampler */
|
||||
if (unlikely(need_lower_tex_src_plane)) {
|
||||
NIR_PASS_V(state.ir.nir, st_nir_lower_tex_src_plane,
|
||||
~stfp->Base.SamplersUsed,
|
||||
~fp->SamplersUsed,
|
||||
key->external.lower_nv12 | key->external.lower_xy_uxvx |
|
||||
key->external.lower_yx_xuxv,
|
||||
key->external.lower_iyuv);
|
||||
|
@ -1515,7 +1515,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
return variant;
|
||||
}
|
||||
|
||||
state.tokens = stfp->state.tokens;
|
||||
state.tokens = fp->state.tokens;
|
||||
|
||||
assert(!(key->bitmap && key->drawpixels));
|
||||
|
||||
|
@ -1529,7 +1529,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
tokens = tgsi_emulate(state.tokens, flags);
|
||||
|
||||
if (tokens) {
|
||||
if (state.tokens != stfp->state.tokens)
|
||||
if (state.tokens != fp->state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
state.tokens = tokens;
|
||||
} else
|
||||
|
@ -1540,7 +1540,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
if (key->bitmap) {
|
||||
const struct tgsi_token *tokens;
|
||||
|
||||
variant->bitmap_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
|
||||
variant->bitmap_sampler = ffs(~fp->SamplersUsed) - 1;
|
||||
|
||||
tokens = st_get_bitmap_shader(state.tokens,
|
||||
st->internal_target,
|
||||
|
@ -1550,7 +1550,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
PIPE_FORMAT_R8_UNORM);
|
||||
|
||||
if (tokens) {
|
||||
if (state.tokens != stfp->state.tokens)
|
||||
if (state.tokens != fp->state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
state.tokens = tokens;
|
||||
} else
|
||||
|
@ -1563,10 +1563,10 @@ st_create_fp_variant(struct st_context *st,
|
|||
unsigned scale_const = 0, bias_const = 0, texcoord_const = 0;
|
||||
|
||||
/* Find the first unused slot. */
|
||||
variant->drawpix_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
|
||||
variant->drawpix_sampler = ffs(~fp->SamplersUsed) - 1;
|
||||
|
||||
if (key->pixelMaps) {
|
||||
unsigned samplers_used = stfp->Base.SamplersUsed |
|
||||
unsigned samplers_used = fp->SamplersUsed |
|
||||
(1 << variant->drawpix_sampler);
|
||||
|
||||
variant->pixelmap_sampler = ffs(~samplers_used) - 1;
|
||||
|
@ -1588,7 +1588,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
texcoord_const, st->internal_target);
|
||||
|
||||
if (tokens) {
|
||||
if (state.tokens != stfp->state.tokens)
|
||||
if (state.tokens != fp->state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
state.tokens = tokens;
|
||||
} else
|
||||
|
@ -1603,13 +1603,13 @@ st_create_fp_variant(struct st_context *st,
|
|||
assert(!(key->bitmap || key->drawpixels));
|
||||
|
||||
tokens = st_tgsi_lower_yuv(state.tokens,
|
||||
~stfp->Base.SamplersUsed,
|
||||
~fp->SamplersUsed,
|
||||
key->external.lower_nv12 ||
|
||||
key->external.lower_xy_uxvx ||
|
||||
key->external.lower_yx_xuxv,
|
||||
key->external.lower_iyuv);
|
||||
if (tokens) {
|
||||
if (state.tokens != stfp->state.tokens)
|
||||
if (state.tokens != fp->state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
state.tokens = tokens;
|
||||
} else {
|
||||
|
@ -1625,7 +1625,7 @@ st_create_fp_variant(struct st_context *st,
|
|||
variant->base.driver_shader = pipe->create_fs_state(pipe, &state);
|
||||
variant->key = *key;
|
||||
|
||||
if (state.tokens != stfp->state.tokens)
|
||||
if (state.tokens != fp->state.tokens)
|
||||
tgsi_free_tokens(state.tokens);
|
||||
return variant;
|
||||
}
|
||||
|
@ -1635,13 +1635,13 @@ st_create_fp_variant(struct st_context *st,
|
|||
*/
|
||||
struct st_fp_variant *
|
||||
st_get_fp_variant(struct st_context *st,
|
||||
struct st_program *stfp,
|
||||
struct gl_program *fp,
|
||||
const struct st_fp_variant_key *key)
|
||||
{
|
||||
struct st_fp_variant *fpv;
|
||||
|
||||
/* Search for existing variant */
|
||||
for (fpv = st_fp_variant(stfp->variants); fpv;
|
||||
for (fpv = st_fp_variant(fp->variants); fpv;
|
||||
fpv = st_fp_variant(fpv->base.next)) {
|
||||
if (memcmp(&fpv->key, key, sizeof(*key)) == 0) {
|
||||
break;
|
||||
|
@ -1651,7 +1651,7 @@ st_get_fp_variant(struct st_context *st,
|
|||
if (!fpv) {
|
||||
/* create new */
|
||||
|
||||
if (stfp->variants != NULL) {
|
||||
if (fp->variants != NULL) {
|
||||
_mesa_perf_debug(st->ctx, MESA_DEBUG_SEVERITY_MEDIUM,
|
||||
"Compiling fragment shader variant (%s%s%s%s%s%s%s%s%s%s%s%s%s)",
|
||||
key->bitmap ? "bitmap," : "",
|
||||
|
@ -1666,15 +1666,15 @@ st_get_fp_variant(struct st_context *st,
|
|||
key->lower_texcoord_replace ? "texcoord_replace," : "",
|
||||
key->lower_alpha_func ? "alpha_compare," : "",
|
||||
/* skipped ATI_fs targets */
|
||||
stfp->Base.ExternalSamplersUsed ? "external?," : "",
|
||||
fp->ExternalSamplersUsed ? "external?," : "",
|
||||
key->gl_clamp[0] || key->gl_clamp[1] || key->gl_clamp[2] ? "GL_CLAMP," : "");
|
||||
}
|
||||
|
||||
fpv = st_create_fp_variant(st, stfp, key);
|
||||
fpv = st_create_fp_variant(st, fp, key);
|
||||
if (fpv) {
|
||||
fpv->base.st = key->st;
|
||||
|
||||
st_add_variant(&stfp->variants, &fpv->base);
|
||||
st_add_variant(&fp->variants, &fpv->base);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1687,17 +1687,16 @@ st_get_fp_variant(struct st_context *st,
|
|||
*/
|
||||
bool
|
||||
st_translate_common_program(struct st_context *st,
|
||||
struct st_program *stp)
|
||||
struct gl_program *prog)
|
||||
{
|
||||
struct gl_program *prog = &stp->Base;
|
||||
enum pipe_shader_type stage =
|
||||
pipe_shader_type_from_mesa(stp->Base.info.stage);
|
||||
pipe_shader_type_from_mesa(prog->info.stage);
|
||||
struct ureg_program *ureg = ureg_create_with_screen(stage, st->screen);
|
||||
|
||||
if (ureg == NULL)
|
||||
return false;
|
||||
|
||||
ureg_setup_shader_info(ureg, &stp->Base.info);
|
||||
ureg_setup_shader_info(ureg, &prog->info);
|
||||
|
||||
ubyte inputSlotToAttr[VARYING_SLOT_TESS_MAX];
|
||||
ubyte inputMapping[VARYING_SLOT_TESS_MAX];
|
||||
|
@ -1717,7 +1716,7 @@ st_translate_common_program(struct st_context *st,
|
|||
memset(inputSlotToAttr, 0, sizeof(inputSlotToAttr));
|
||||
memset(inputMapping, 0, sizeof(inputMapping));
|
||||
memset(outputMapping, 0, sizeof(outputMapping));
|
||||
memset(&stp->state, 0, sizeof(stp->state));
|
||||
memset(&prog->state, 0, sizeof(prog->state));
|
||||
|
||||
/*
|
||||
* Convert Mesa program inputs to TGSI input register semantics.
|
||||
|
@ -1790,7 +1789,7 @@ st_translate_common_program(struct st_context *st,
|
|||
st_translate_program(st->ctx,
|
||||
stage,
|
||||
ureg,
|
||||
stp->glsl_to_tgsi,
|
||||
prog->glsl_to_tgsi,
|
||||
prog,
|
||||
/* inputs */
|
||||
num_inputs,
|
||||
|
@ -1805,7 +1804,7 @@ st_translate_common_program(struct st_context *st,
|
|||
output_semantic_name,
|
||||
output_semantic_index);
|
||||
|
||||
stp->state.tokens = ureg_get_tokens(ureg, NULL);
|
||||
prog->state.tokens = ureg_get_tokens(ureg, NULL);
|
||||
|
||||
ureg_destroy(ureg);
|
||||
|
||||
|
@ -1816,8 +1815,8 @@ st_translate_common_program(struct st_context *st,
|
|||
if (ST_DEBUG & DEBUG_PRINT_IR && ST_DEBUG & DEBUG_MESA)
|
||||
_mesa_print_program(prog);
|
||||
|
||||
free_glsl_to_tgsi_visitor(stp->glsl_to_tgsi);
|
||||
stp->glsl_to_tgsi = NULL;
|
||||
free_glsl_to_tgsi_visitor(prog->glsl_to_tgsi);
|
||||
prog->glsl_to_tgsi = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1827,12 +1826,11 @@ st_translate_common_program(struct st_context *st,
|
|||
* variants attached to the given program which match the given context.
|
||||
*/
|
||||
static void
|
||||
destroy_program_variants(struct st_context *st, struct gl_program *target)
|
||||
destroy_program_variants(struct st_context *st, struct gl_program *p)
|
||||
{
|
||||
if (!target || target == &_mesa_DummyProgram)
|
||||
if (!p || p == &_mesa_DummyProgram)
|
||||
return;
|
||||
|
||||
struct st_program *p = st_program(target);
|
||||
struct st_variant *v, **prevPtr = &p->variants;
|
||||
bool unbound = false;
|
||||
|
||||
|
@ -1847,7 +1845,7 @@ destroy_program_variants(struct st_context *st, struct gl_program *target)
|
|||
/* unlink from list */
|
||||
*prevPtr = next;
|
||||
/* destroy this variant */
|
||||
delete_variant(st, v, target->Target);
|
||||
delete_variant(st, v, p->Target);
|
||||
}
|
||||
else {
|
||||
prevPtr = &v->next;
|
||||
|
@ -1971,7 +1969,6 @@ st_precompile_shader_variant(struct st_context *st,
|
|||
case GL_TESS_EVALUATION_PROGRAM_NV:
|
||||
case GL_GEOMETRY_PROGRAM_NV:
|
||||
case GL_COMPUTE_PROGRAM_NV: {
|
||||
struct st_program *p = (struct st_program *)prog;
|
||||
struct st_common_variant_key key;
|
||||
|
||||
memset(&key, 0, sizeof(key));
|
||||
|
@ -1992,23 +1989,22 @@ st_precompile_shader_variant(struct st_context *st,
|
|||
key.export_point_size = st->lower_point_size && is_last_vertex_stage(st->ctx, prog);
|
||||
}
|
||||
key.st = st->has_shareable_shaders ? NULL : st;
|
||||
st_get_common_variant(st, p, &key);
|
||||
st_get_common_variant(st, prog, &key);
|
||||
break;
|
||||
}
|
||||
|
||||
case GL_FRAGMENT_PROGRAM_ARB: {
|
||||
struct st_program *p = (struct st_program *)prog;
|
||||
struct st_fp_variant_key key;
|
||||
|
||||
memset(&key, 0, sizeof(key));
|
||||
|
||||
key.st = st->has_shareable_shaders ? NULL : st;
|
||||
key.lower_alpha_func = COMPARE_FUNC_ALWAYS;
|
||||
if (p->ati_fs) {
|
||||
if (prog->ati_fs) {
|
||||
for (int i = 0; i < ARRAY_SIZE(key.texture_index); i++)
|
||||
key.texture_index[i] = TEXTURE_2D_INDEX;
|
||||
}
|
||||
st_get_fp_variant(st, p, &key);
|
||||
st_get_fp_variant(st, prog, &key);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2018,16 +2014,16 @@ st_precompile_shader_variant(struct st_context *st,
|
|||
}
|
||||
|
||||
void
|
||||
st_serialize_nir(struct st_program *stp)
|
||||
st_serialize_nir(struct gl_program *prog)
|
||||
{
|
||||
if (!stp->serialized_nir) {
|
||||
if (!prog->serialized_nir) {
|
||||
struct blob blob;
|
||||
size_t size;
|
||||
|
||||
blob_init(&blob);
|
||||
nir_serialize(&blob, stp->Base.nir, false);
|
||||
blob_finish_get_buffer(&blob, &stp->serialized_nir, &size);
|
||||
stp->serialized_nir_size = size;
|
||||
nir_serialize(&blob, prog->nir, false);
|
||||
blob_finish_get_buffer(&blob, &prog->serialized_nir, &size);
|
||||
prog->serialized_nir_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2037,9 +2033,9 @@ st_finalize_program(struct st_context *st, struct gl_program *prog)
|
|||
if (st->current_program[prog->info.stage] == prog) {
|
||||
if (prog->info.stage == MESA_SHADER_VERTEX) {
|
||||
st->ctx->Array.NewVertexElements = true;
|
||||
st->dirty |= ST_NEW_VERTEX_PROGRAM(st, (struct st_program *)prog);
|
||||
st->dirty |= ST_NEW_VERTEX_PROGRAM(st, prog);
|
||||
} else {
|
||||
st->dirty |= ((struct st_program *)prog)->affected_states;
|
||||
st->dirty |= prog->affected_states;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2050,7 +2046,7 @@ st_finalize_program(struct st_context *st, struct gl_program *prog)
|
|||
* is disabled. If the disk cache is enabled, GLSL programs are
|
||||
* serialized in write_nir_to_cache.
|
||||
*/
|
||||
st_serialize_nir(st_program(prog));
|
||||
st_serialize_nir(prog);
|
||||
}
|
||||
|
||||
/* Always create the default variant of the program. */
|
||||
|
|
|
@ -247,31 +247,9 @@ struct st_common_variant
|
|||
GLbitfield vert_attrib_mask;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Derived from Mesa gl_program:
|
||||
*/
|
||||
struct st_program
|
||||
{
|
||||
struct gl_program Base;
|
||||
struct pipe_shader_state state;
|
||||
struct glsl_to_tgsi_visitor* glsl_to_tgsi;
|
||||
struct ati_fragment_shader *ati_fs;
|
||||
uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
|
||||
|
||||
void *serialized_nir;
|
||||
unsigned serialized_nir_size;
|
||||
|
||||
/* used when bypassing glsl_to_tgsi: */
|
||||
struct gl_shader_program *shader_program;
|
||||
|
||||
struct st_variant *variants;
|
||||
};
|
||||
|
||||
|
||||
struct st_vertex_program
|
||||
{
|
||||
struct st_program Base;
|
||||
struct gl_program Base;
|
||||
|
||||
uint32_t vert_attrib_mask; /**< mask of sourced vertex attribs */
|
||||
ubyte num_inputs;
|
||||
|
@ -280,23 +258,6 @@ struct st_vertex_program
|
|||
ubyte result_to_output[VARYING_SLOT_MAX];
|
||||
};
|
||||
|
||||
|
||||
static inline struct st_program *
|
||||
st_program( struct gl_program *cp )
|
||||
{
|
||||
return (struct st_program *)cp;
|
||||
}
|
||||
|
||||
static inline void
|
||||
st_reference_prog(struct st_context *st,
|
||||
struct st_program **ptr,
|
||||
struct st_program *prog)
|
||||
{
|
||||
_mesa_reference_program(st->ctx,
|
||||
(struct gl_program **) ptr,
|
||||
(struct gl_program *) prog);
|
||||
}
|
||||
|
||||
static inline struct st_common_variant *
|
||||
st_common_variant(struct st_variant *v)
|
||||
{
|
||||
|
@ -325,19 +286,19 @@ st_set_prog_affected_state_flags(struct gl_program *prog);
|
|||
|
||||
extern struct st_fp_variant *
|
||||
st_get_fp_variant(struct st_context *st,
|
||||
struct st_program *stfp,
|
||||
struct gl_program *stfp,
|
||||
const struct st_fp_variant_key *key);
|
||||
|
||||
extern struct st_common_variant *
|
||||
st_get_common_variant(struct st_context *st,
|
||||
struct st_program *p,
|
||||
struct gl_program *p,
|
||||
const struct st_common_variant_key *key);
|
||||
|
||||
extern void
|
||||
st_release_variants(struct st_context *st, struct st_program *p);
|
||||
st_release_variants(struct st_context *st, struct gl_program *p);
|
||||
|
||||
extern void
|
||||
st_release_program(struct st_context *st, struct st_program **p);
|
||||
st_release_program(struct st_context *st, struct gl_program **p);
|
||||
|
||||
extern void
|
||||
st_destroy_program_variants(struct st_context *st);
|
||||
|
@ -346,25 +307,25 @@ extern void
|
|||
st_finalize_nir_before_variants(struct nir_shader *nir);
|
||||
|
||||
extern void
|
||||
st_prepare_vertex_program(struct st_program *stvp, uint8_t *attrib_to_index);
|
||||
st_prepare_vertex_program(struct gl_program *stvp, uint8_t *attrib_to_index);
|
||||
|
||||
extern void
|
||||
st_translate_stream_output_info(struct gl_program *prog);
|
||||
|
||||
extern bool
|
||||
st_translate_vertex_program(struct st_context *st,
|
||||
struct st_program *stvp);
|
||||
struct gl_program *stvp);
|
||||
|
||||
extern bool
|
||||
st_translate_fragment_program(struct st_context *st,
|
||||
struct st_program *stfp);
|
||||
struct gl_program *stfp);
|
||||
|
||||
extern bool
|
||||
st_translate_common_program(struct st_context *st,
|
||||
struct st_program *stp);
|
||||
struct gl_program *stp);
|
||||
|
||||
extern void
|
||||
st_serialize_nir(struct st_program *stp);
|
||||
st_serialize_nir(struct gl_program *stp);
|
||||
|
||||
extern void
|
||||
st_finalize_program(struct st_context *st, struct gl_program *prog);
|
||||
|
|
|
@ -75,12 +75,10 @@ write_tgsi_to_cache(struct blob *blob, const struct tgsi_token *tokens,
|
|||
static void
|
||||
write_nir_to_cache(struct blob *blob, struct gl_program *prog)
|
||||
{
|
||||
struct st_program *stp = (struct st_program *)prog;
|
||||
st_serialize_nir(prog);
|
||||
|
||||
st_serialize_nir(stp);
|
||||
|
||||
blob_write_intptr(blob, stp->serialized_nir_size);
|
||||
blob_write_bytes(blob, stp->serialized_nir, stp->serialized_nir_size);
|
||||
blob_write_intptr(blob, prog->serialized_nir_size);
|
||||
blob_write_bytes(blob, prog->serialized_nir, prog->serialized_nir_size);
|
||||
|
||||
copy_blob_to_driver_cache_blob(blob, prog);
|
||||
}
|
||||
|
@ -92,12 +90,11 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
|
|||
if (prog->driver_cache_blob)
|
||||
return;
|
||||
|
||||
struct st_program *stp = (struct st_program *)prog;
|
||||
struct blob blob;
|
||||
blob_init(&blob);
|
||||
|
||||
if (prog->info.stage == MESA_SHADER_VERTEX) {
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)prog;
|
||||
|
||||
blob_write_uint32(&blob, stvp->num_inputs);
|
||||
blob_write_uint32(&blob, stvp->vert_attrib_mask);
|
||||
|
@ -108,12 +105,12 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
|
|||
if (prog->info.stage == MESA_SHADER_VERTEX ||
|
||||
prog->info.stage == MESA_SHADER_TESS_EVAL ||
|
||||
prog->info.stage == MESA_SHADER_GEOMETRY)
|
||||
write_stream_out_to_cache(&blob, &stp->state);
|
||||
write_stream_out_to_cache(&blob, &prog->state);
|
||||
|
||||
if (nir)
|
||||
write_nir_to_cache(&blob, prog);
|
||||
else
|
||||
write_tgsi_to_cache(&blob, stp->state.tokens, prog);
|
||||
write_tgsi_to_cache(&blob, prog->state.tokens, prog);
|
||||
|
||||
blob_finish(&blob);
|
||||
}
|
||||
|
@ -186,14 +183,13 @@ st_deserialise_ir_program(struct gl_context *ctx,
|
|||
|
||||
assert(prog->driver_cache_blob && prog->driver_cache_blob_size > 0);
|
||||
|
||||
struct st_program *stp = st_program(prog);
|
||||
struct blob_reader blob_reader;
|
||||
blob_reader_init(&blob_reader, buffer, size);
|
||||
|
||||
st_release_variants(st, stp);
|
||||
st_release_variants(st, prog);
|
||||
|
||||
if (prog->info.stage == MESA_SHADER_VERTEX) {
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
|
||||
struct st_vertex_program *stvp = (struct st_vertex_program *)prog;
|
||||
stvp->num_inputs = blob_read_uint32(&blob_reader);
|
||||
stvp->vert_attrib_mask = blob_read_uint32(&blob_reader);
|
||||
blob_copy_bytes(&blob_reader, (uint8_t *) stvp->result_to_output,
|
||||
|
@ -203,19 +199,19 @@ st_deserialise_ir_program(struct gl_context *ctx,
|
|||
if (prog->info.stage == MESA_SHADER_VERTEX ||
|
||||
prog->info.stage == MESA_SHADER_TESS_EVAL ||
|
||||
prog->info.stage == MESA_SHADER_GEOMETRY)
|
||||
read_stream_out_from_cache(&blob_reader, &stp->state);
|
||||
read_stream_out_from_cache(&blob_reader, &prog->state);
|
||||
|
||||
if (nir) {
|
||||
assert(prog->nir == NULL);
|
||||
assert(stp->serialized_nir == NULL);
|
||||
assert(prog->serialized_nir == NULL);
|
||||
|
||||
stp->state.type = PIPE_SHADER_IR_NIR;
|
||||
stp->serialized_nir_size = blob_read_intptr(&blob_reader);
|
||||
stp->serialized_nir = malloc(stp->serialized_nir_size);
|
||||
blob_copy_bytes(&blob_reader, stp->serialized_nir, stp->serialized_nir_size);
|
||||
stp->shader_program = shProg;
|
||||
prog->state.type = PIPE_SHADER_IR_NIR;
|
||||
prog->serialized_nir_size = blob_read_intptr(&blob_reader);
|
||||
prog->serialized_nir = malloc(prog->serialized_nir_size);
|
||||
blob_copy_bytes(&blob_reader, prog->serialized_nir, prog->serialized_nir_size);
|
||||
prog->shader_program = shProg;
|
||||
} else {
|
||||
read_tgsi_from_cache(&blob_reader, &stp->state.tokens);
|
||||
read_tgsi_from_cache(&blob_reader, &prog->state.tokens);
|
||||
}
|
||||
|
||||
/* Make sure we don't try to read more data than we wrote. This should
|
||||
|
|
Loading…
Reference in New Issue