[Mesa-dev] [RFC PATCH 21/56] glsl: Add tessellation shader defines and built-in variables.
Ian Romanick
idr at freedesktop.org
Tue Sep 30 09:43:41 PDT 2014
On 09/20/2014 06:41 PM, Chris Forbes wrote:
> From: Fabian Bieler <fabianbieler at fastmail.fm>
>
> ---
> src/glsl/builtin_variables.cpp | 62 +++++++++++++++++++++++++++++++++++++++++-
> src/glsl/glcpp/glcpp-parse.y | 3 ++
> 2 files changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
> index 5b6f4ae..7ba0fe8 100644
> --- a/src/glsl/builtin_variables.cpp
> +++ b/src/glsl/builtin_variables.cpp
> @@ -343,6 +343,8 @@ public:
> void generate_constants();
> void generate_uniforms();
> void generate_vs_special_vars();
> + void generate_tcs_special_vars();
> + void generate_tes_special_vars();
> void generate_gs_special_vars();
> void generate_fs_special_vars();
> void generate_cs_special_vars();
> @@ -842,6 +844,40 @@ builtin_variable_generator::generate_vs_special_vars()
>
>
> /**
> + * Generate variables which only exist in tessellation control shaders.
> + */
> +void
> +builtin_variable_generator::generate_tcs_special_vars()
> +{
> + add_input(-1, int_t, "gl_PatchVerticesIn");
> + add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID");// XXX: or sysval?
> + add_system_value(SYSTEM_VALUE_INVOCATION_ID, int_t, "gl_InvocationID");
> +
> + add_output(VARYING_SLOT_TESS_LEVEL_OUTER,
> + array(float_t, 4), "gl_TessLevelOuter");
> + add_output(VARYING_SLOT_TESS_LEVEL_INNER,
> + array(float_t, 2), "gl_TessLevelInner");
> +}
> +
> +
> +/**
> + * Generate variables which only exist in tessellation evaluation shaders.
> + */
> +void
> +builtin_variable_generator::generate_tes_special_vars()
> +{
> + add_input(-1, int_t, "gl_PatchVerticesIn");
> + add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID");// XXX: or sysval?
> + add_system_value(SYSTEM_VALUE_TESS_COORD, vec3_t, "gl_TessCoord");
> +
> + add_input(VARYING_SLOT_TESS_LEVEL_OUTER,
> + array(float_t, 4), "gl_TessLevelOuter");
> + add_input(VARYING_SLOT_TESS_LEVEL_INNER,
> + array(float_t, 2), "gl_TessLevelInner");
> +}
> +
> +
> +/**
> * Generate variables which only exist in geometry shaders.
> */
> void
> @@ -964,6 +1000,9 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type,
> const char *name_as_gs_input)
> {
> switch (state->stage) {
> + case MESA_SHADER_TESS_CTRL:
> + case MESA_SHADER_TESS_EVAL:
> + // XXX: is this correct?
> case MESA_SHADER_GEOMETRY:
> this->per_vertex_in.add_field(slot, type, name);
> /* FALLTHROUGH */
> @@ -1016,13 +1055,28 @@ builtin_variable_generator::generate_varyings()
> }
> }
>
> + if (state->stage == MESA_SHADER_TESS_CTRL ||
> + state->stage == MESA_SHADER_TESS_EVAL) {
> + const glsl_type *per_vertex_in_type =
> + this->per_vertex_in.construct_interface_instance();
> + add_variable("gl_in", array(per_vertex_in_type, state->Const.MaxPatchVertices),
This looks wrong, but I believe that it is correct. Maybe add a spec
quotation?
/* Section 7.1 (Built-In Language Variables) of the GLSL 4.00 spec
* says:
*
* "In the tessellation control language, built-in variables are
* intrinsically declared as:
*
* in gl_PerVertex {
* vec4 gl_Position;
* float gl_PointSize;
* float gl_ClipDistance[];
* } gl_in[gl_MaxPatchVertices];"
*/
It may also be worth adding a similar quotation to the
MESA_SHADER_GEOMETRY case below.
> + ir_var_shader_in, -1);
> + }
> if (state->stage == MESA_SHADER_GEOMETRY) {
> const glsl_type *per_vertex_in_type =
> this->per_vertex_in.construct_interface_instance();
> add_variable("gl_in", array(per_vertex_in_type, 0),
> ir_var_shader_in, -1);
> }
> - if (state->stage == MESA_SHADER_VERTEX || state->stage == MESA_SHADER_GEOMETRY) {
> + if (state->stage == MESA_SHADER_TESS_CTRL) {
> + const glsl_type *per_vertex_out_type =
> + this->per_vertex_out.construct_interface_instance();
> + add_variable("gl_out", array(per_vertex_out_type, 0),
> + ir_var_shader_out, -1);
> + }
> + if (state->stage == MESA_SHADER_VERTEX ||
> + state->stage == MESA_SHADER_TESS_EVAL ||
> + state->stage == MESA_SHADER_GEOMETRY) {
> const glsl_type *per_vertex_out_type =
> this->per_vertex_out.construct_interface_instance();
> const glsl_struct_field *fields = per_vertex_out_type->fields.structure;
> @@ -1057,6 +1111,12 @@ _mesa_glsl_initialize_variables(exec_list *instructions,
> case MESA_SHADER_VERTEX:
> gen.generate_vs_special_vars();
> break;
> + case MESA_SHADER_TESS_CTRL:
> + gen.generate_tcs_special_vars();
> + break;
> + case MESA_SHADER_TESS_EVAL:
> + gen.generate_tes_special_vars();
> + break;
> case MESA_SHADER_GEOMETRY:
> gen.generate_gs_special_vars();
> break;
> diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
> index f1119eb..e0ec3b6 100644
> --- a/src/glsl/glcpp/glcpp-parse.y
> +++ b/src/glsl/glcpp/glcpp-parse.y
> @@ -2472,6 +2472,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
>
> if (extensions->ARB_derivative_control)
> add_builtin_define(parser, "GL_ARB_derivative_control", 1);
> +
> + if (extensions->ARB_tessellation_shader)
> + add_builtin_define(parser, "GL_ARB_tessellation_shader", 1);
> }
> }
>
>
More information about the mesa-dev
mailing list