[virglrenderer-devel] [PATCH 1/2] vrend_shader: add sampler array functionality in emit_sampler_decl
Gurchetan Singh
gurchetansingh at chromium.org
Thu Jul 12 01:17:34 UTC 2018
Sampler arrays don't work with shadow textures. Let's move sampler
array functionality into emit_sampler_decl to de-deuplicate logic.
---
src/vrend_shader.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 8e6b72d768..ac9b72f3bc 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -3440,32 +3440,25 @@ static char get_return_type_prefix(enum tgsi_return_type type)
return ' ';
}
-static void *emit_sampler_decl(struct dump_ctx *ctx, char *glsl_hdr,
- uint32_t i)
+static void *emit_sampler_decl(struct dump_ctx *ctx, char *glsl_hdr, uint32_t i,
+ uint32_t range, uint32_t return_type, uint32_t texture_type)
{
- char buf[255];
+ char buf[255], ptc;
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);
+ const char *sname, *precision, *stc;
sname = tgsi_proc_to_prefix(ctx->prog_type);
- if (ctx->cfg->use_gles) {
- precision = "highp ";
- } else {
- precision = " ";
- }
+ precision = (ctx->cfg->use_gles) ? "highp " : " ";
+
+ ptc = vrend_shader_samplerreturnconv(return_type);
+ stc = vrend_shader_samplertypeconv(texture_type, &is_shad);
- /* 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"))
+ /* GLES does not support 1D textures -- we use a 2D texture and set the parameter set to 0.5 */
+ if (ctx->cfg->use_gles && texture_type == TGSI_TEXTURE_1D)
snprintf(buf, 255, "uniform %csampler2D %ssamp%d;\n", ptc, sname, i);
+ else if (range)
+ snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d[%d];\n", precision, ptc, stc, sname, i, range);
else
snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision, ptc, stc, sname, i);
@@ -3477,6 +3470,7 @@ static void *emit_sampler_decl(struct dump_ctx *ctx, char *glsl_hdr,
STRCAT_WITH_RET(glsl_hdr, buf);
ctx->shadow_samp_mask |= (1 << i);
}
+
return glsl_hdr;
}
@@ -3879,7 +3873,8 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
if ((ctx->samplers_used & (1 << i)) == 0)
continue;
- glsl_hdr = emit_sampler_decl(ctx, glsl_hdr, i);
+ glsl_hdr = emit_sampler_decl(ctx, glsl_hdr, i, 0, ctx->samplers[i].tgsi_sampler_return,
+ ctx->samplers[i].tgsi_sampler_type);
if (!glsl_hdr)
return NULL;
}
--
2.18.0.203.gfac676dfb9-goog
More information about the virglrenderer-devel
mailing list