glsl: Optionally lower TCS gl_PatchVerticesIn to a uniform.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 27 May 2016 03:21:58 +0000 (20:21 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 15 Jun 2016 19:47:37 +0000 (12:47 -0700)
i965 has no special hardware for this, so the best way to implement
this is to pass it in via a uniform.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Cc: mesa-stable@lists.freedesktop.org
src/compiler/glsl/builtin_variables.cpp
src/mesa/main/mtypes.h
src/mesa/program/prog_statevars.c
src/mesa/program/prog_statevars.h

index e5e738021262f3f93d72f6f3c5cb006cbaae7e04..e1a95e3bf8cddc1fb07ff5857e2ab005a7212ca8 100644 (file)
@@ -37,6 +37,11 @@ static const struct gl_builtin_uniform_element gl_NumSamples_elements[] = {
    {NULL, {STATE_NUM_SAMPLES, 0, 0}, SWIZZLE_XXXX}
 };
 
+/* only for TCS */
+static const struct gl_builtin_uniform_element gl_PatchVerticesIn_elements[] = {
+   {NULL, {STATE_INTERNAL, STATE_TCS_PATCH_VERTICES_IN}, SWIZZLE_XXXX}
+};
+
 static const struct gl_builtin_uniform_element gl_DepthRange_elements[] = {
    {"near", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_XXXX},
    {"far", {STATE_DEPTH_RANGE, 0, 0}, SWIZZLE_YYYY},
@@ -234,6 +239,7 @@ static const struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = {
 #define STATEVAR(name) {#name, name ## _elements, ARRAY_SIZE(name ## _elements)}
 
 static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = {
+   STATEVAR(gl_PatchVerticesIn),
    STATEVAR(gl_NumSamples),
    STATEVAR(gl_DepthRange),
    STATEVAR(gl_ClipPlane),
@@ -1029,9 +1035,14 @@ void
 builtin_variable_generator::generate_tcs_special_vars()
 {
    add_system_value(SYSTEM_VALUE_PRIMITIVE_ID, int_t, "gl_PrimitiveID");
-   add_system_value(SYSTEM_VALUE_VERTICES_IN, int_t, "gl_PatchVerticesIn");
    add_system_value(SYSTEM_VALUE_INVOCATION_ID, int_t, "gl_InvocationID");
 
+   if (state->ctx->Const.LowerTCSPatchVerticesIn) {
+      add_uniform(int_t, "gl_PatchVerticesIn");
+   } else {
+      add_system_value(SYSTEM_VALUE_VERTICES_IN, int_t, "gl_PatchVerticesIn");
+   }
+
    add_output(VARYING_SLOT_TESS_LEVEL_OUTER, array(float_t, 4),
               "gl_TessLevelOuter")->data.patch = 1;
    add_output(VARYING_SLOT_TESS_LEVEL_INNER, array(float_t, 2),
index 85ef22db9c265b1a4e23dd2e9d5a17a351652b1e..4d2fdb9f4a0e3b2ef7cdd680e211d3533bdecb93 100644 (file)
@@ -3762,6 +3762,7 @@ struct gl_constants
    GLuint MaxTessPatchComponents;
    GLuint MaxTessControlTotalOutputComponents;
    bool LowerTessLevel; /**< Lower gl_TessLevel* from float[n] to vecn? */
+   bool LowerTCSPatchVerticesIn; /**< Lower gl_PatchVerticesIn to a uniform */
    bool LowerTESPatchVerticesIn; /**< Lower gl_PatchVerticesIn to a uniform */
    bool PrimitiveRestartForPatches;
    bool LowerCsDerivedVariables;    /**< Lower gl_GlobalInvocationID and
index 23e3015146f1db9fbc47597ecccc3cff8822ecaa..8dddc0b86a920eab7e0dc749d65f93a08dfaf2f9 100644 (file)
@@ -598,6 +598,10 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
          }
          return;
 
+      case STATE_TCS_PATCH_VERTICES_IN:
+         val[0].i = ctx->TessCtrlProgram.patch_vertices;
+         return;
+
       case STATE_TES_PATCH_VERTICES_IN:
          if (ctx->TessCtrlProgram._Current)
             val[0].i = ctx->TessCtrlProgram._Current->VerticesOut;
index 4b27527b1f919d4da925ba996dbe38082496909a..e716d9070a22c47f9a0a4953a22ca4c4a03b33cb 100644 (file)
@@ -128,6 +128,7 @@ typedef enum gl_state_index_ {
    STATE_PT_BIAS,               /**< Pixel transfer RGBA bias */
    STATE_FB_SIZE,               /**< (width-1, height-1, 0, 0) */
    STATE_FB_WPOS_Y_TRANSFORM,   /**< (1, 0, -1, height) if a FBO is bound, (-1, height, 1, 0) otherwise */
+   STATE_TCS_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TCS (integer) */
    STATE_TES_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TES (integer) */
    STATE_INTERNAL_DRIVER       /* first available state index for drivers (must be last) */
 } gl_state_index;