[virglrenderer-devel] [PATCH 1/2] vrend_shader: split out sampler declaration emission logic
Gurchetan Singh
gurchetansingh at chromium.org
Fri Jun 29 03:31:26 UTC 2018
Sampler arrays don't work with shadow textures. Let's have a
separate emission function that we can use with sampler arrays and
normal samplers.
v2: Split out in separate function, initialize shadow variable to
zero
---
src/vrend_shader.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index f7bf853c46..f0dc49cbbf 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -3409,6 +3409,40 @@ static char get_return_type_prefix(enum tgsi_return_type type)
return ' ';
}
+/* i represents the i-th sampler array or i-th sampler. */
+static void emit_sampler_declaration(struct dump_ctx *ctx, char *glsl_hdr, uint32_t i,
+ uint32_t range, uint32_t texture_type, uint32_t return_type)
+{
+ int shadow;
+ char buf[255], ret_type;
+ const char *sname, *precision, *tex_type;
+
+ shadow = 0;
+ sname = tgsi_proc_to_prefix(ctx->prog_type);
+ precision = (ctx->cfg->use_gles) ? "highp " : " ";
+
+ tex_type = vrend_shader_samplertypeconv(texture_type, &shadow);
+ ret_type = vrend_shader_samplerreturnconv(return_type);
+
+ /* 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", ret_type, sname, i);
+ else if (range)
+ snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d[%d];\n", precision, ret_type, tex_type, sname, i, range);
+ else
+ snprintf(buf, 255, "uniform %s%csampler%s %ssamp%d;\n", precision, ret_type, tex_type, sname, i);
+
+ strcat_realloc(glsl_hdr, buf);
+
+ if (shadow) {
+ snprintf(buf, 255, "uniform %svec4 %sshadmask%d;\n", precision, sname, i);
+ strcat_realloc(glsl_hdr, buf);
+ snprintf(buf, 255, "uniform %svec4 %sshadadd%d;\n", precision, sname, i);
+ strcat_realloc(glsl_hdr, buf);
+ ctx->shadow_samp_mask |= (1 << i);
+ }
+}
+
static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
{
uint32_t i;
--
2.18.0.rc2.346.g013aa6912e-goog
More information about the virglrenderer-devel
mailing list