[Mesa-dev] [PATCH 1/8] glsl: optionally declare gl_FragCoord & gl_FrontFacing as system values
Marek Olšák
maraeo at gmail.com
Thu Jan 7 17:29:50 PST 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/glsl/ast_to_hir.cpp | 2 +-
src/glsl/builtin_variables.cpp | 12 ++++++++++--
src/glsl/nir/shader_enums.h | 3 ++-
src/mesa/main/mtypes.h | 4 ++++
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 1 +
5 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index e6aec36..f3966d7 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3517,7 +3517,7 @@ get_variable_being_redeclared(ir_variable *var, YYLTYPE loc,
state->is_version(150, 0))
&& strcmp(var->name, "gl_FragCoord") == 0
&& earlier->type == var->type
- && earlier->data.mode == var->data.mode) {
+ && var->data.mode == ir_var_shader_in) {
/* Allow redeclaration of gl_FragCoord for ARB_fcc layout
* qualifiers.
*/
diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index e82c99e..221aab0 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -1057,8 +1057,16 @@ builtin_variable_generator::generate_fs_special_vars()
{
ir_variable *var;
- add_input(VARYING_SLOT_POS, vec4_t, "gl_FragCoord");
- add_input(VARYING_SLOT_FACE, bool_t, "gl_FrontFacing");
+ if (this->state->ctx->Const.GLSLFragCoordIsSysVal)
+ add_system_value(SYSTEM_VALUE_FRAG_COORD, vec4_t, "gl_FragCoord");
+ else
+ add_input(VARYING_SLOT_POS, vec4_t, "gl_FragCoord");
+
+ if (this->state->ctx->Const.GLSLFrontFacingIsSysVal)
+ add_system_value(SYSTEM_VALUE_FRONT_FACE, bool_t, "gl_FrontFacing");
+ else
+ add_input(VARYING_SLOT_FACE, bool_t, "gl_FrontFacing");
+
if (state->is_version(120, 100))
add_input(VARYING_SLOT_PNTC, vec2_t, "gl_PointCoord");
diff --git a/src/glsl/nir/shader_enums.h b/src/glsl/nir/shader_enums.h
index 0be217c..8a2a81a 100644
--- a/src/glsl/nir/shader_enums.h
+++ b/src/glsl/nir/shader_enums.h
@@ -412,7 +412,8 @@ typedef enum
* \name Fragment shader system values
*/
/*@{*/
- SYSTEM_VALUE_FRONT_FACE, /**< (not done yet) */
+ SYSTEM_VALUE_FRAG_COORD,
+ SYSTEM_VALUE_FRONT_FACE,
SYSTEM_VALUE_SAMPLE_ID,
SYSTEM_VALUE_SAMPLE_POS,
SYSTEM_VALUE_SAMPLE_MASK_IN,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5b9fce8..126b272 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3515,6 +3515,10 @@ struct gl_constants
*/
GLboolean GLSLSkipStrictMaxUniformLimitCheck;
+ /** Whether gl_FragCoord and gl_FrontFacing are system values. */
+ bool GLSLFragCoordIsSysVal;
+ bool GLSLFrontFacingIsSysVal;
+
/**
* Always use the GetTransformFeedbackVertexCount() driver hook, rather
* than passing the transform feedback object to the drawing function.
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6cbc26a..9308eb4 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4459,6 +4459,7 @@ const unsigned _mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
/* Fragment shader
*/
+ TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_FACE,
TGSI_SEMANTIC_SAMPLEID,
TGSI_SEMANTIC_SAMPLEPOS,
--
2.1.4
More information about the mesa-dev
mailing list