Mesa (master): mesa: Add a helper function _mesa_get_min_invocations_per_fragment()

Anuj Phogat aphogat at kemper.freedesktop.org
Sat Nov 2 00:06:23 UTC 2013


Module: Mesa
Branch: master
Commit: 627b2692e916060f1cb72d5e254b63927961687d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=627b2692e916060f1cb72d5e254b63927961687d

Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Wed Oct 16 17:22:18 2013 -0700

mesa: Add a helper function _mesa_get_min_invocations_per_fragment()

This function is used to test if we need to do per sample shading or
per fragment shading.

V2: Use MAX2() to make sure the function returns a number >= 1.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Paul Berry <stereotype441 at gmail.com>

---

 src/mesa/program/program.c |   32 ++++++++++++++++++++++++++++++++
 src/mesa/program/program.h |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
index 093d372..a102ec1 100644
--- a/src/mesa/program/program.c
+++ b/src/mesa/program/program.c
@@ -32,6 +32,7 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/hash.h"
+#include "main/macros.h"
 #include "program.h"
 #include "prog_cache.h"
 #include "prog_parameter.h"
@@ -1024,3 +1025,34 @@ _mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog)
 
    }
 }
+
+/* Gets the minimum number of shader invocations per fragment.
+ * This function is useful to determine if we need to do per
+ * sample shading or per fragment shading.
+ */
+GLint
+_mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
+                                       const struct gl_fragment_program *prog)
+{
+   /* From ARB_sample_shading specification:
+    * "Using gl_SampleID in a fragment shader causes the entire shader
+    *  to be evaluated per-sample."
+    *
+    * "Using gl_SamplePosition in a fragment shader causes the entire
+    *  shader to be evaluated per-sample."
+    *
+    * "If MULTISAMPLE or SAMPLE_SHADING_ARB is disabled, sample shading
+    *  has no effect."
+    */
+   if (ctx->Multisample.Enabled) {
+      if (prog->Base.SystemValuesRead & (SYSTEM_BIT_SAMPLE_ID |
+                                         SYSTEM_BIT_SAMPLE_POS))
+         return MAX2(ctx->DrawBuffer->Visual.samples, 1);
+      else if (ctx->Multisample.SampleShading)
+         return MAX2(ceil(ctx->Multisample.MinSampleShadingValue *
+                          ctx->DrawBuffer->Visual.samples), 1);
+      else
+         return 1;
+   }
+   return 1;
+}
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index 34965ab..353ccab 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -187,6 +187,9 @@ _mesa_valid_register_index(const struct gl_context *ctx,
 extern void
 _mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog);
 
+extern GLint
+_mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
+                                       const struct gl_fragment_program *prog);
 
 static inline GLuint
 _mesa_program_target_to_index(GLenum v)




More information about the mesa-commit mailing list