vrend: try to emit texture levels only when really needed

Fixes e5fabecbe0
  vrend: pass texture levels per shader on GLES as uniform

v2: - only emit texlod uniform when textureQueryLevels is called
    - initialize uniform location to -1 if the mask shows that
      the texture lod levels arenot needed and ony test this when
      uploading the data
      (all suggested in a way by Chia-I Wu)

Closes: #237

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
Gert Wollny 3 years ago
parent ee9db8b048
commit bc6f87c13c
  1. 17
      src/vrend_renderer.c
  2. 10
      src/vrend_shader.c
  3. 1
      src/vrend_shader.h

@ -429,6 +429,8 @@ struct vrend_linked_shader_program {
int32_t tex_levels_uniform_id[PIPE_SHADER_TYPES];
struct vrend_sub_context *ref_context;
uint32_t gles_use_query_texturelevel_mask;
};
struct vrend_shader {
@ -4643,6 +4645,7 @@ vrend_select_program(struct vrend_sub_context *sub_ctx, const struct pipe_draw_i
vrend_shader_select(sub_ctx, shaders[PIPE_SHADER_VERTEX], &vs_dirty);
sub_ctx->drawing = false;
uint8_t gles_emulate_query_texture_levels_mask = 0;
for (uint i = 0; i < PIPE_SHADER_TYPES; i++) {
struct vrend_shader_selector *sel = shaders[i];
@ -4659,6 +4662,8 @@ vrend_select_program(struct vrend_sub_context *sub_ctx, const struct pipe_draw_i
return -1;
}
}
if (vrend_state.use_gles && sel->sinfo.gles_use_tex_query_level)
gles_emulate_query_texture_levels_mask |= 1 << i;
}
if (!shaders[PIPE_SHADER_VERTEX]->current ||
@ -4695,6 +4700,7 @@ vrend_select_program(struct vrend_sub_context *sub_ctx, const struct pipe_draw_i
tes_id ? sub_ctx->shaders[PIPE_SHADER_TESS_EVAL]->current : NULL);
if (!prog)
return false;
prog->gles_use_query_texturelevel_mask = gles_emulate_query_texture_levels_mask;
}
sub_ctx->last_shader_idx = sub_ctx->shaders[PIPE_SHADER_TESS_EVAL] ? PIPE_SHADER_TESS_EVAL : (sub_ctx->shaders[PIPE_SHADER_GEOMETRY] ? PIPE_SHADER_GEOMETRY : PIPE_SHADER_FRAGMENT);
@ -4807,9 +4813,14 @@ int vrend_draw_vbo(struct vrend_context *ctx,
/* PIPE_SHADER and TGSI_SHADER have different ordering, so use two
* different prefix arrays */
for (unsigned i = PIPE_SHADER_VERTEX; i < PIPE_SHADER_COMPUTE; ++i) {
char loc_name[32];
snprintf(loc_name, 32, "%s_texlod[0]", pipe_shader_to_prefix(i));
sub_ctx->prog->tex_levels_uniform_id[i] = glGetUniformLocation(sub_ctx->prog->id, loc_name);
if (sub_ctx->prog->gles_use_query_texturelevel_mask & (1 << i)) {
char loc_name[32];
snprintf(loc_name, 32, "%s_texlod[0]", pipe_shader_to_prefix(i));
sub_ctx->prog->tex_levels_uniform_id[i] = glGetUniformLocation(sub_ctx->prog->id, loc_name);
} else {
sub_ctx->prog->tex_levels_uniform_id[i] = -1;
}
}
}

@ -275,6 +275,7 @@ struct dump_ctx {
bool has_file_memory;
bool force_color_two_side;
bool winsys_adjust_y_emitted;
bool gles_use_tex_query_level;
int tcs_vertices_out;
int tes_prim_mode;
@ -2361,14 +2362,16 @@ static void emit_txq(struct dump_ctx *ctx,
if (inst->Dst[0].Register.WriteMask & 0x7)
twm = TGSI_WRITEMASK_W;
if (!ctx->cfg->use_gles)
if (!ctx->cfg->use_gles) {
emit_buff(&ctx->glsl_strbufs, "%s%s = %s(textureQueryLevels(%s));\n", dst,
get_wm_string(twm), get_string(dtypeprefix),
srcs[sampler_index]);
else
} else {
emit_buff(&ctx->glsl_strbufs, "%s%s = %s(%s_texlod[%s]);\n", dst, get_wm_string(twm),
get_string(dtypeprefix), tgsi_proc_to_prefix(ctx->info.processor),
srcs[sampler_index]);
ctx->gles_use_tex_query_level = true;
}
}
if (inst->Dst[0].Register.WriteMask & 0x7) {
@ -6033,7 +6036,7 @@ static int emit_ios_common(const struct dump_ctx *ctx,
}
}
if (ctx->cfg->use_gles && n_samplers)
if (ctx->cfg->use_gles && ctx->gles_use_tex_query_level)
emit_hdrf(glsl_strbufs, "uniform int %s_texlod[%d];\n", tgsi_proc_to_prefix(ctx->info.processor), n_samplers);
if (ctx->info.indirect_files & (1 << TGSI_FILE_IMAGE)) {
@ -7032,6 +7035,7 @@ static void fill_sinfo(const struct dump_ctx *ctx, struct vrend_shader_info *sin
if (ctx->outputs[i].invariant)
sinfo->invariant_outputs |= 1ull << ctx->outputs[i].sid;
}
sinfo->gles_use_tex_query_level = ctx->gles_use_tex_query_level;
}
static bool allocate_strbuffers(struct vrend_glsl_strbufs* glsl_strbufs)

@ -130,6 +130,7 @@ struct vrend_shader_info {
uint8_t ubo_indirect : 1;
uint8_t tes_point_mode : 1;
uint8_t gles_use_tex_query_level : 1;
};
struct vrend_shader_key {

Loading…
Cancel
Save