[Mesa-dev] [PATCH 02/12] mesa/main: Add support for GL_ARB_cull_distance (v2)

Dave Airlie airlied at gmail.com
Mon Apr 4 02:15:28 UTC 2016


From: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>

airlied:
v2: rename LowerClipDistance to LowerCombinedClipCullDistnace.
I don't think we want any other behaviour with any current hw.

Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann at mni.thm.de>
---
 src/compiler/glsl/link_varyings.cpp       |  2 +-
 src/compiler/glsl/linker.cpp              |  2 +-
 src/compiler/glsl/lower_clip_distance.cpp |  2 +-
 src/mesa/drivers/dri/i965/brw_compiler.c  |  2 +-
 src/mesa/main/extensions_table.h          |  1 +
 src/mesa/main/get.c                       |  1 +
 src/mesa/main/get_hash_params.py          |  4 ++++
 src/mesa/main/mtypes.h                    | 14 +++++++++++++-
 src/mesa/main/shaderapi.c                 |  3 +++
 src/mesa/state_tracker/st_extensions.c    |  2 +-
 10 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index e9d0067..8e74981 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -569,7 +569,7 @@ tfeedback_decl::init(struct gl_context *ctx, const void *mem_ctx,
     * class must behave specially to account for the fact that gl_ClipDistance
     * is converted from a float[8] to a vec4[2].
     */
-   if (ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].LowerClipDistance &&
+   if (ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].LowerCombinedClipCullDistance &&
        strcmp(this->var_name, "gl_ClipDistance") == 0) {
       this->lowered_builtin_array_variable = clip_distance;
    }
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index d9a681c..ed9ef98 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4513,7 +4513,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
       if (!prog->LinkStatus)
 	 goto done;
 
-      if (ctx->Const.ShaderCompilerOptions[i].LowerClipDistance) {
+      if (ctx->Const.ShaderCompilerOptions[i].LowerCombinedClipCullDistance) {
          lower_clip_distance(prog->_LinkedShaders[i]);
       }
 
diff --git a/src/compiler/glsl/lower_clip_distance.cpp b/src/compiler/glsl/lower_clip_distance.cpp
index 1ada215..5d9468d 100644
--- a/src/compiler/glsl/lower_clip_distance.cpp
+++ b/src/compiler/glsl/lower_clip_distance.cpp
@@ -42,7 +42,7 @@
  *
  * Since some hardware may not internally represent gl_ClipDistance as a pair
  * of vec4's, this lowering pass is optional.  To enable it, set the
- * LowerClipDistance flag in gl_shader_compiler_options to true.
+ * LowerCombinedClipCullDistance flag in gl_shader_compiler_options to true.
  */
 
 #include "glsl_symbol_table.h"
diff --git a/src/mesa/drivers/dri/i965/brw_compiler.c b/src/mesa/drivers/dri/i965/brw_compiler.c
index 3da6aac..2c220d3 100644
--- a/src/mesa/drivers/dri/i965/brw_compiler.c
+++ b/src/mesa/drivers/dri/i965/brw_compiler.c
@@ -167,7 +167,7 @@ brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo)
       compiler->glsl_compiler_options[i].EmitNoMainReturn = true;
       compiler->glsl_compiler_options[i].EmitNoIndirectInput = true;
       compiler->glsl_compiler_options[i].EmitNoIndirectUniform = false;
-      compiler->glsl_compiler_options[i].LowerClipDistance = true;
+      compiler->glsl_compiler_options[i].LowerCombinedClipCullDistance = true;
 
       bool is_scalar = compiler->scalar_stage[i];
 
diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h
index 1190390..12e644a 100644
--- a/src/mesa/main/extensions_table.h
+++ b/src/mesa/main/extensions_table.h
@@ -43,6 +43,7 @@ EXT(ARB_conditional_render_inverted         , ARB_conditional_render_inverted
 EXT(ARB_conservative_depth                  , ARB_conservative_depth                 , GLL, GLC,  x ,  x , 2011)
 EXT(ARB_copy_buffer                         , dummy_true                             , GLL, GLC,  x ,  x , 2008)
 EXT(ARB_copy_image                          , ARB_copy_image                         , GLL, GLC,  x ,  x , 2012)
+EXT(ARB_cull_distance                       , ARB_cull_distance                      , GLL, GLC,  x ,  x , 2014)
 EXT(ARB_debug_output                        , dummy_true                             , GLL, GLC,  x ,  x , 2009)
 EXT(ARB_depth_buffer_float                  , ARB_depth_buffer_float                 , GLL, GLC,  x ,  x , 2008)
 EXT(ARB_depth_clamp                         , ARB_depth_clamp                        , GLL, GLC,  x ,  x , 2003)
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 6829c33..e3a0a11 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -465,6 +465,7 @@ EXTRA_EXT(ARB_shader_storage_buffer_object);
 EXTRA_EXT(ARB_indirect_parameters);
 EXTRA_EXT(ATI_meminfo);
 EXTRA_EXT(NVX_gpu_memory_info);
+EXTRA_EXT(ARB_cull_distance);
 
 static const int
 extra_ARB_color_buffer_float_or_glcore[] = {
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index a0cc4f8..d2a66a8 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -878,6 +878,10 @@ descriptor=[
   [ "GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX", "LOC_CUSTOM, TYPE_INT, NO_OFFSET, extra_NVX_gpu_memory_info" ],
   [ "GPU_MEMORY_INFO_EVICTION_COUNT_NVX", "LOC_CUSTOM, TYPE_INT, NO_OFFSET, extra_NVX_gpu_memory_info" ],
   [ "GPU_MEMORY_INFO_EVICTED_MEMORY_NVX", "LOC_CUSTOM, TYPE_INT, NO_OFFSET, extra_NVX_gpu_memory_info" ],
+
+# GL_ARB_cull_distance
+  [ "MAX_CULL_DISTANCES", "CONTEXT_INT(Const.MaxClipPlanes), extra_ARB_cull_distance" ],
+  [ "MAX_COMBINED_CLIP_AND_CULL_DISTANCES", "CONTEXT_INT(Const.MaxClipPlanes), extra_ARB_cull_distance" ],
 ]},
 
 # Enums restricted to OpenGL Core profile
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b2060c2..152b1fb 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1922,6 +1922,7 @@ struct gl_program
     * gl_ClipDistance output.  Ignored for fragment shaders.
     */
    unsigned ClipDistanceArraySize;
+   unsigned CullDistanceArraySize;
 
 
    /** Named parameters, constants, etc. from program text */
@@ -2726,6 +2727,8 @@ struct gl_shader_program
        */
       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
                                          0 if not present. */
+      GLuint CullDistanceArraySize; /**< Size of the gl_CullDistance array, or
+                                         0 if not present. */
    } TessEval;
 
    /**
@@ -2748,6 +2751,8 @@ struct gl_shader_program
        */
       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
                                          0 if not present. */
+      GLuint CullDistanceArraySize; /**< Size of the gl_CullDistance array, or
+                                         0 if not present. */
       bool UsesEndPrimitive;
       bool UsesStreams;
    } Geom;
@@ -2760,6 +2765,8 @@ struct gl_shader_program
        */
       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
                                          0 if not present. */
+      GLuint CullDistanceArraySize; /**< Size of the gl_CullDistance array, or
+                                         0 if not present. */
    } Vert;
 
    /**
@@ -2803,6 +2810,7 @@ struct gl_shader_program
     * stage before the fragment shader.
     */
    unsigned LastClipDistanceArraySize;
+   unsigned LastCullDistanceArraySize;
 
    /**
     * This shader's uniform/ssbo block information.
@@ -2956,7 +2964,10 @@ struct gl_shader_compiler_options
    GLboolean EmitNoNoise;                 /**< Emit NOISE opcodes? */
    GLboolean EmitNoPow;                   /**< Emit POW opcodes? */
    GLboolean EmitNoSat;                   /**< Emit SAT opcodes? */
-   GLboolean LowerClipDistance; /**< Lower gl_ClipDistance from float[8] to vec4[2]? */
+   GLboolean LowerCombinedClipCullDistance; /** Lower gl_ClipDistance and
+                                              * gl_CullDistance together from
+                                              * float[8] to vec4[2]
+                                              **/
 
    /**
     * \name Forms of indirect addressing the driver cannot do.
@@ -3786,6 +3797,7 @@ struct gl_extensions
    GLboolean ARB_conditional_render_inverted;
    GLboolean ARB_conservative_depth;
    GLboolean ARB_copy_image;
+   GLboolean ARB_cull_distance;
    GLboolean ARB_depth_buffer_float;
    GLboolean ARB_depth_clamp;
    GLboolean ARB_depth_texture;
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index ba26072..d79d956 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -2081,6 +2081,7 @@ _mesa_copy_linked_program_data(gl_shader_stage type,
    switch (type) {
    case MESA_SHADER_VERTEX:
       dst->ClipDistanceArraySize = src->Vert.ClipDistanceArraySize;
+      dst->CullDistanceArraySize = src->Vert.CullDistanceArraySize;
       break;
    case MESA_SHADER_TESS_CTRL: {
       struct gl_tess_ctrl_program *dst_tcp =
@@ -2096,6 +2097,7 @@ _mesa_copy_linked_program_data(gl_shader_stage type,
       dst_tep->VertexOrder = src->TessEval.VertexOrder;
       dst_tep->PointMode = src->TessEval.PointMode;
       dst->ClipDistanceArraySize = src->TessEval.ClipDistanceArraySize;
+      dst->CullDistanceArraySize = src->TessEval.CullDistanceArraySize;
       break;
    }
    case MESA_SHADER_GEOMETRY: {
@@ -2106,6 +2108,7 @@ _mesa_copy_linked_program_data(gl_shader_stage type,
       dst_gp->InputType = src->Geom.InputType;
       dst_gp->OutputType = src->Geom.OutputType;
       dst->ClipDistanceArraySize = src->Geom.ClipDistanceArraySize;
+      dst->CullDistanceArraySize = src->Geom.CullDistanceArraySize;
       dst_gp->UsesEndPrimitive = src->Geom.UsesEndPrimitive;
       dst_gp->UsesStreams = src->Geom.UsesStreams;
       break;
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 6c0df8d..8ee127c 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -306,7 +306,7 @@ void st_init_limits(struct pipe_screen *screen,
             screen->get_shader_param(screen, sh,
                                   PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT);
 
-      options->LowerClipDistance = true;
+      options->LowerCombinedClipCullDistance = true;
       options->LowerBufferInterfaceBlocks = true;
 
       if (sh == PIPE_SHADER_COMPUTE)
-- 
2.5.0



More information about the mesa-dev mailing list