shader: refactor sampler emission.

This just moves the code to a function, it doesn't change any
of the expected code. It should make it easier to spot fixes.

Reviewed-by: Elie Tournier <elie.tournier@collabora.com>
macos/master
Dave Airlie 6 years ago
parent 0ea74890db
commit 38f80b1bc0
  1. 76
      src/vrend_shader.c

@ -3434,6 +3434,46 @@ static char get_return_type_prefix(enum tgsi_return_type type)
return ' '; return ' ';
} }
static void *emit_sampler_decl(struct dump_ctx *ctx, char *glsl_hdr,
uint32_t i)
{
char buf[255];
int is_shad = 0;
const char *stc;
char ptc;
const char *sname;
const char *precision;
ptc = vrend_shader_samplerreturnconv(ctx->samplers[i].tgsi_sampler_return);
stc = vrend_shader_samplertypeconv(ctx->samplers[i].tgsi_sampler_type, &is_shad);
sname = tgsi_proc_to_prefix(ctx->prog_type);
if (ctx->cfg->use_gles) {
precision = "highp ";
} else {
precision = " ";
}
/* OpenGL ES do not support 1D texture
* so we use a 2D texture with a parameter set to 0.5
*/
if (ctx->cfg->use_gles && !strcmp(stc, "1D"))
snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ptc, sname, i);
else
snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision, ptc, stc, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf);
if (is_shad) {
snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf);
snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf);
ctx->shadow_samp_mask |= (1 << i);
}
return glsl_hdr;
}
static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr) static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
{ {
uint32_t i; uint32_t i;
@ -3829,43 +3869,13 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
} else { } else {
nsamp = util_last_bit(ctx->samplers_used); nsamp = util_last_bit(ctx->samplers_used);
for (i = 0; i < nsamp; i++) { for (i = 0; i < nsamp; i++) {
int is_shad = 0;
const char *stc;
char ptc;
if ((ctx->samplers_used & (1 << i)) == 0) if ((ctx->samplers_used & (1 << i)) == 0)
continue; continue;
const char *sname; glsl_hdr = emit_sampler_decl(ctx, glsl_hdr, i);
const char *precision; if (!glsl_hdr)
return NULL;
ptc = vrend_shader_samplerreturnconv(ctx->samplers[i].tgsi_sampler_return);
stc = vrend_shader_samplertypeconv(ctx->samplers[i].tgsi_sampler_type, &is_shad);
sname = tgsi_proc_to_prefix(ctx->prog_type);
if (ctx->cfg->use_gles) {
precision = "highp ";
} else {
precision = " ";
}
/* OpenGL ES do not support 1D texture
* so we use a 2D texture with a parameter set to 0.5
*/
if (ctx->cfg->use_gles && !strcmp(stc, "1D"))
snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ptc, sname, i);
else
snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision, ptc, stc, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf);
if (is_shad) {
snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf);
snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision, sname, i);
STRCAT_WITH_RET(glsl_hdr, buf);
ctx->shadow_samp_mask |= (1 << i);
}
} }
} }
if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT && if (ctx->prog_type == TGSI_PROCESSOR_FRAGMENT &&

Loading…
Cancel
Save