[Mesa-dev] [PATCH 04/24] st/mesa: don't search through shader variants if there is only one
Marek Olšák
maraeo at gmail.com
Mon Jun 12 18:18:35 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/state_tracker/st_atom_shader.c | 141 ++++++++++++++++++++------------
1 file changed, 90 insertions(+), 51 deletions(-)
diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 37aee83..b6b3222 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -96,46 +96,55 @@ get_texture_target(struct gl_context *ctx, const unsigned unit)
void
st_update_fp( struct st_context *st )
{
struct st_fragment_program *stfp;
struct st_fp_variant_key key;
assert(st->ctx->FragmentProgram._Current);
stfp = st_fragment_program(st->ctx->FragmentProgram._Current);
assert(stfp->Base.Target == GL_FRAGMENT_PROGRAM_ARB);
- memset(&key, 0, sizeof(key));
- key.st = st->has_shareable_shaders ? NULL : st;
-
- /* _NEW_FRAG_CLAMP */
- key.clamp_color = st->clamp_frag_color_in_shader &&
- st->ctx->Color._ClampFragmentColor;
-
- /* _NEW_MULTISAMPLE | _NEW_BUFFERS */
- key.persample_shading =
- st->force_persample_in_shader &&
- _mesa_is_multisample_enabled(st->ctx) &&
- st->ctx->Multisample.SampleShading &&
- st->ctx->Multisample.MinSampleShadingValue *
- _mesa_geometric_samples(st->ctx->DrawBuffer) > 1;
-
- if (stfp->ati_fs) {
- key.fog = st->ctx->Fog._PackedEnabledMode;
-
- for (unsigned u = 0; u < MAX_NUM_FRAGMENT_REGISTERS_ATI; u++) {
- key.texture_targets[u] = get_texture_target(st->ctx, u);
+ 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 */
+ stfp->variants) {
+ shader = stfp->variants->driver_shader;
+ } else {
+ memset(&key, 0, sizeof(key));
+ key.st = st->has_shareable_shaders ? NULL : st;
+
+ /* _NEW_FRAG_CLAMP */
+ key.clamp_color = st->clamp_frag_color_in_shader &&
+ st->ctx->Color._ClampFragmentColor;
+
+ /* _NEW_MULTISAMPLE | _NEW_BUFFERS */
+ key.persample_shading =
+ st->force_persample_in_shader &&
+ _mesa_is_multisample_enabled(st->ctx) &&
+ st->ctx->Multisample.SampleShading &&
+ st->ctx->Multisample.MinSampleShadingValue *
+ _mesa_geometric_samples(st->ctx->DrawBuffer) > 1;
+
+ if (stfp->ati_fs) {
+ key.fog = st->ctx->Fog._PackedEnabledMode;
+
+ for (unsigned u = 0; u < MAX_NUM_FRAGMENT_REGISTERS_ATI; u++) {
+ key.texture_targets[u] = get_texture_target(st->ctx, u);
+ }
}
- }
- key.external = st_get_external_sampler_key(st, &stfp->Base);
+ key.external = st_get_external_sampler_key(st, &stfp->Base);
- void *shader = st_get_fp_variant(st, stfp, &key)->driver_shader;
+ shader = st_get_fp_variant(st, stfp, &key)->driver_shader;
+ }
st_reference_fragprog(st, &st->fp, stfp);
cso_set_fragment_shader_handle(st->cso_context, shader);
}
/**
* Update vertex program state/atom. This involves translating the
* Mesa vertex program into a gallium fragment program and binding it.
@@ -146,40 +155,46 @@ st_update_vp( struct st_context *st )
struct st_vertex_program *stvp;
struct st_vp_variant_key key;
/* find active shader and params -- Should be covered by
* ST_NEW_VERTEX_PROGRAM
*/
assert(st->ctx->VertexProgram._Current);
stvp = st_vertex_program(st->ctx->VertexProgram._Current);
assert(stvp->Base.Target == GL_VERTEX_PROGRAM_ARB);
- memset(&key, 0, sizeof key);
- key.st = st->has_shareable_shaders ? NULL : st;
-
- /* When this is true, we will add an extra input to the vertex
- * shader translation (for edgeflags), an extra output with
- * edgeflag semantics, and extend the vertex shader to pass through
- * the input to the output. We'll need to use similar logic to set
- * up the extra vertex_element input for edgeflags.
- */
- key.passthrough_edgeflags = st->vertdata_edgeflags;
-
- key.clamp_color = st->clamp_vert_color_in_shader &&
- st->ctx->Light._ClampVertexColor &&
- (stvp->Base.info.outputs_written &
- (VARYING_SLOT_COL0 |
- VARYING_SLOT_COL1 |
- VARYING_SLOT_BFC0 |
- VARYING_SLOT_BFC1));
-
- st->vp_variant = st_get_vp_variant(st, stvp, &key);
+ if (st->shader_has_one_variant[MESA_SHADER_VERTEX] &&
+ stvp->variants &&
+ stvp->variants->key.passthrough_edgeflags == st->vertdata_edgeflags) {
+ st->vp_variant = stvp->variants;
+ } else {
+ memset(&key, 0, sizeof key);
+ key.st = st->has_shareable_shaders ? NULL : st;
+
+ /* When this is true, we will add an extra input to the vertex
+ * shader translation (for edgeflags), an extra output with
+ * edgeflag semantics, and extend the vertex shader to pass through
+ * the input to the output. We'll need to use similar logic to set
+ * up the extra vertex_element input for edgeflags.
+ */
+ key.passthrough_edgeflags = st->vertdata_edgeflags;
+
+ key.clamp_color = st->clamp_vert_color_in_shader &&
+ st->ctx->Light._ClampVertexColor &&
+ (stvp->Base.info.outputs_written &
+ (VARYING_SLOT_COL0 |
+ VARYING_SLOT_COL1 |
+ VARYING_SLOT_BFC0 |
+ VARYING_SLOT_BFC1));
+
+ st->vp_variant = st_get_vp_variant(st, stvp, &key);
+ }
st_reference_vertprog(st, &st->vp, stvp);
cso_set_vertex_shader_handle(st->cso_context,
st->vp_variant->driver_shader);
}
void
st_update_gp( struct st_context *st )
@@ -188,22 +203,28 @@ st_update_gp( struct st_context *st )
if (!st->ctx->GeometryProgram._Current) {
cso_set_geometry_shader_handle(st->cso_context, NULL);
st_reference_prog(st, &st->gp, NULL);
return;
}
stgp = st_common_program(st->ctx->GeometryProgram._Current);
assert(stgp->Base.Target == GL_GEOMETRY_PROGRAM_NV);
- void *shader = st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, &stgp->tgsi,
- &stgp->variants)->driver_shader;
+ void *shader;
+
+ if (st->shader_has_one_variant[MESA_SHADER_GEOMETRY] && stgp->variants) {
+ shader = stgp->variants->driver_shader;
+ } else {
+ shader = st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, &stgp->tgsi,
+ &stgp->variants)->driver_shader;
+ }
st_reference_prog(st, &st->gp, stgp);
cso_set_geometry_shader_handle(st->cso_context, shader);
}
void
st_update_tcp( struct st_context *st )
{
@@ -211,22 +232,28 @@ st_update_tcp( struct st_context *st )
if (!st->ctx->TessCtrlProgram._Current) {
cso_set_tessctrl_shader_handle(st->cso_context, NULL);
st_reference_prog(st, &st->tcp, NULL);
return;
}
sttcp = st_common_program(st->ctx->TessCtrlProgram._Current);
assert(sttcp->Base.Target == GL_TESS_CONTROL_PROGRAM_NV);
- void *shader = st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, &sttcp->tgsi,
- &sttcp->variants)->driver_shader;
+ void *shader;
+
+ if (st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] && sttcp->variants) {
+ shader = sttcp->variants->driver_shader;
+ } else {
+ shader = st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, &sttcp->tgsi,
+ &sttcp->variants)->driver_shader;
+ }
st_reference_prog(st, &st->tcp, sttcp);
cso_set_tessctrl_shader_handle(st->cso_context, shader);
}
void
st_update_tep( struct st_context *st )
{
@@ -234,22 +261,28 @@ st_update_tep( struct st_context *st )
if (!st->ctx->TessEvalProgram._Current) {
cso_set_tesseval_shader_handle(st->cso_context, NULL);
st_reference_prog(st, &st->tep, NULL);
return;
}
sttep = st_common_program(st->ctx->TessEvalProgram._Current);
assert(sttep->Base.Target == GL_TESS_EVALUATION_PROGRAM_NV);
- void *shader = st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, &sttep->tgsi,
- &sttep->variants)->driver_shader;
+ void *shader;
+
+ if (st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] && sttep->variants) {
+ shader = sttep->variants->driver_shader;
+ } else {
+ shader = st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, &sttep->tgsi,
+ &sttep->variants)->driver_shader;
+ }
st_reference_prog(st, &st->tep, sttep);
cso_set_tesseval_shader_handle(st->cso_context, shader);
}
void
st_update_cp( struct st_context *st )
{
@@ -257,17 +290,23 @@ st_update_cp( struct st_context *st )
if (!st->ctx->ComputeProgram._Current) {
cso_set_compute_shader_handle(st->cso_context, NULL);
st_reference_compprog(st, &st->cp, NULL);
return;
}
stcp = st_compute_program(st->ctx->ComputeProgram._Current);
assert(stcp->Base.Target == GL_COMPUTE_PROGRAM_NV);
- void *shader = st_get_cp_variant(st, &stcp->tgsi,
- &stcp->variants)->driver_shader;
+ void *shader;
+
+ if (st->shader_has_one_variant[MESA_SHADER_COMPUTE] && stcp->variants) {
+ shader = stcp->variants->driver_shader;
+ } else {
+ shader = st_get_cp_variant(st, &stcp->tgsi,
+ &stcp->variants)->driver_shader;
+ }
st_reference_compprog(st, &st->cp, stcp);
cso_set_compute_shader_handle(st->cso_context, shader);
}
--
2.7.4
More information about the mesa-dev
mailing list