[virglrenderer-devel] [PATCH 2/2] emit sample-keyword
Erik Faye-Lund
erik.faye-lund at collabora.com
Tue Jul 3 07:08:45 UTC 2018
If a shader uses TGSI_INTERPOLATE_LOC_SAMPLE, we need to emit
the "sample"-keyword for the input-variable in the fragment
shader.
Since the "sampler"-keyword is a GLSL 4.00 feature, this
requires us to enable GL_ARB_gpu_shader5. Unfortunately, opting
in carefully on this is a bit trickier than for most other
extensions, because we patch up vertex, geometry or tesselation
evaluation shader outputs to match the fragment shader inputs.
Since the previous patch adds padding for the require-statement
directly after the #version string, we can just overwrite that
padding with the require statement.
This fixes the following tests:
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_texture_1
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_texture_2
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_texture_4
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_texture_8
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_texture_16
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_rbo_1
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_rbo_2
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_rbo_4
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_rbo_8
dEQP-GLES31.functional.shaders.multisample_interpolation.sample_qualifier.multisample_rbo_16
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_texture_1
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_texture_2
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_texture_4
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_texture_8
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_texture_16
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_rbo_1
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_rbo_2
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_rbo_4
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_rbo_8
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_sample.at_sample_id.multisample_rbo_16
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_texture_1
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_texture_2
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_texture_4
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_texture_8
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_texture_16
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_rbo_1
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_rbo_2
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_rbo_4
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_rbo_8
dEQP-GLES31.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.multisample_rbo_16
Signed-off-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
---
src/vrend_shader.c | 49 ++++++++++++++++++++++++++++++++++++++--------
src/vrend_shader.h | 3 ++-
2 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 608bed4..0c258be 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -67,7 +67,7 @@ struct vrend_shader_io {
int sid;
unsigned interpolate;
int first;
- bool centroid;
+ unsigned location;
bool invariant;
bool glsl_predefined_no_emit;
bool glsl_no_index;
@@ -230,6 +230,7 @@ struct dump_ctx {
bool vs_has_pervertex;
bool write_mul_temp;
bool early_depth_stencil;
+ bool has_sample_input;
int tcs_vertices_out;
int tes_prim_mode;
@@ -632,13 +633,19 @@ iter_declaration(struct tgsi_iterate_context *iter,
ctx->inputs[i].name = decl->Semantic.Name;
ctx->inputs[i].sid = decl->Semantic.Index;
ctx->inputs[i].interpolate = decl->Interp.Interpolate;
- ctx->inputs[i].centroid = decl->Interp.Location == TGSI_INTERPOLATE_LOC_CENTROID;
+ ctx->inputs[i].location = decl->Interp.Location;
ctx->inputs[i].first = decl->Range.First;
ctx->inputs[i].glsl_predefined_no_emit = false;
ctx->inputs[i].glsl_no_index = false;
ctx->inputs[i].override_no_wm = false;
ctx->inputs[i].glsl_gl_block = false;
+ if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT &&
+ decl->Interp.Interpolate == TGSI_INTERPOLATE_LOC_SAMPLE) {
+ ctx->shader_req_bits |= SHADER_REQ_GPU_SHADER5;
+ ctx->has_sample_input = true;
+ }
+
switch (ctx->inputs[i].name) {
case TGSI_SEMANTIC_COLOR:
if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) {
@@ -661,6 +668,7 @@ iter_declaration(struct tgsi_iterate_context *iter,
ctx->inputs[j].name = TGSI_SEMANTIC_BCOLOR;
ctx->inputs[j].sid = decl->Semantic.Index;
ctx->inputs[j].interpolate = decl->Interp.Interpolate;
+ ctx->inputs[j].location = decl->Interp.Location;
ctx->inputs[j].first = decl->Range.First;
ctx->inputs[j].glsl_predefined_no_emit = false;
ctx->inputs[j].glsl_no_index = false;
@@ -678,7 +686,7 @@ iter_declaration(struct tgsi_iterate_context *iter,
ctx->inputs[k].name = TGSI_SEMANTIC_FACE;
ctx->inputs[k].sid = 0;
ctx->inputs[k].interpolate = 0;
- ctx->inputs[k].centroid = 0;
+ ctx->inputs[k].location = TGSI_INTERPOLATE_LOC_CENTER;
ctx->inputs[k].first = 0;
ctx->inputs[k].override_no_wm = false;
ctx->inputs[k].glsl_predefined_no_emit = true;
@@ -3940,9 +3948,16 @@ static const char *get_interp_string(struct vrend_shader_cfg *cfg, int interpola
}
}
-static const char *get_aux_string(bool centroid)
+static const char *get_aux_string(unsigned location)
{
- return centroid ? "centroid " : "";
+ switch (location) {
+ case TGSI_INTERPOLATE_LOC_CENTER:
+ return "";
+ case TGSI_INTERPOLATE_LOC_CENTROID:
+ return "centroid ";
+ case TGSI_INTERPOLATE_LOC_SAMPLE:
+ return "sample ";
+ }
}
static char get_return_type_prefix(enum tgsi_return_type type)
@@ -4182,7 +4197,7 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
prefix = get_interp_string(ctx->cfg, ctx->inputs[i].interpolate, ctx->key->flatshade);
if (!prefix)
prefix = "";
- auxprefix = get_aux_string(ctx->inputs[i].centroid);
+ auxprefix = get_aux_string(ctx->inputs[i].location);
ctx->num_interps++;
}
@@ -4600,7 +4615,7 @@ static boolean fill_fragment_interpolants(struct dump_ctx *ctx, struct vrend_sha
sinfo->interpinfo[index].semantic_name = ctx->inputs[i].name;
sinfo->interpinfo[index].semantic_index = ctx->inputs[i].sid;
sinfo->interpinfo[index].interpolate = ctx->inputs[i].interpolate;
- sinfo->interpinfo[index].centroid = ctx->inputs[i].centroid;
+ sinfo->interpinfo[index].location = ctx->inputs[i].location;
index++;
}
return TRUE;
@@ -4655,6 +4670,7 @@ char *vrend_convert_shader(struct vrend_shader_cfg *cfg,
ctx.sampler_arrays = NULL;
ctx.last_sampler_array_idx = -1;
ctx.req_local_mem = req_local_mem;
+ ctx.has_sample_input = false;
tgsi_scan_shader(tokens, &ctx.info);
/* if we are in core profile mode we should use GLSL 1.40 */
if (cfg->use_core_profile && cfg->glsl_version >= 140)
@@ -4714,6 +4730,7 @@ char *vrend_convert_shader(struct vrend_shader_cfg *cfg,
free(glsl_hdr);
sinfo->num_ucp = ctx.key->clip_plane_enable ? 8 : 0;
sinfo->has_pervertex_out = ctx.vs_has_pervertex;
+ sinfo->has_sample_input = ctx.has_sample_input;
bool has_prop = (ctx.num_clip_dist_prop + ctx.num_cull_dist_prop) > 0;
sinfo->num_clip_out = has_prop ? ctx.num_clip_dist_prop : (ctx.num_clip_dist ? ctx.num_clip_dist : 8);
sinfo->num_cull_out = has_prop ? ctx.num_cull_dist_prop : 0;
@@ -4781,6 +4798,19 @@ static void replace_interp(char *program,
memcpy(ptr + strlen(pstring), auxstring, strlen(auxstring));
}
+static const char *gpu_shader5_string = "#extension GL_ARB_gpu_shader5 : require\n";
+
+static void require_gpu_shader5(char *program)
+{
+ /* the first line is the #version line */
+ char *ptr = strchr(program, '\n');
+ if (!ptr)
+ return;
+ ptr++;
+
+ memcpy(ptr, gpu_shader5_string, strlen(gpu_shader5_string));
+}
+
bool vrend_patch_vertex_shader_interpolants(struct vrend_shader_cfg *cfg, char *program,
struct vrend_shader_info *vs_info,
struct vrend_shader_info *fs_info, const char *oprefix, bool flatshade)
@@ -4794,12 +4824,15 @@ bool vrend_patch_vertex_shader_interpolants(struct vrend_shader_cfg *cfg, char *
if (!fs_info->interpinfo)
return true;
+ if (fs_info->has_sample_input)
+ require_gpu_shader5(program);
+
for (i = 0; i < fs_info->num_interps; i++) {
pstring = get_interp_string(cfg, fs_info->interpinfo[i].interpolate, flatshade);
if (!pstring)
continue;
- auxstring = get_aux_string(fs_info->interpinfo[i].centroid);
+ auxstring = get_aux_string(fs_info->interpinfo[i].location);
switch (fs_info->interpinfo[i].semantic_name) {
case TGSI_SEMANTIC_COLOR:
diff --git a/src/vrend_shader.h b/src/vrend_shader.h
index cf9ac9c..abd6101 100644
--- a/src/vrend_shader.h
+++ b/src/vrend_shader.h
@@ -33,7 +33,7 @@ struct vrend_interp_info {
int semantic_name;
int semantic_index;
int interpolate;
- bool centroid;
+ unsigned location;
};
struct vrend_sampler_array {
@@ -68,6 +68,7 @@ struct vrend_shader_info {
int num_ucp;
int glsl_ver;
bool has_pervertex_out;
+ bool has_sample_input;
uint8_t num_clip_out;
uint8_t num_cull_out;
uint32_t shadow_samp_mask;
--
2.18.0.rc2
More information about the virglrenderer-devel
mailing list