aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/program
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/program')
-rw-r--r--mesalib/src/mesa/program/prog_print.c1
-rw-r--r--mesalib/src/mesa/program/prog_statevars.c11
-rw-r--r--mesalib/src/mesa/program/prog_statevars.h2
-rw-r--r--mesalib/src/mesa/program/program.c32
-rw-r--r--mesalib/src/mesa/program/program.h3
5 files changed, 49 insertions, 0 deletions
diff --git a/mesalib/src/mesa/program/prog_print.c b/mesalib/src/mesa/program/prog_print.c
index cf852132d..fa9063f5b 100644
--- a/mesalib/src/mesa/program/prog_print.c
+++ b/mesalib/src/mesa/program/prog_print.c
@@ -311,6 +311,7 @@ arb_output_attrib_string(GLint index, GLenum progType)
"result.depth", /* FRAG_RESULT_DEPTH */
"result.(one)", /* FRAG_RESULT_STENCIL */
"result.color", /* FRAG_RESULT_COLOR */
+ "result.samplemask", /* FRAG_RESULT_SAMPLE_MASK */
"result.color[0]", /* FRAG_RESULT_DATA0 (named for GLSL's gl_FragData) */
"result.color[1]",
"result.color[2]",
diff --git a/mesalib/src/mesa/program/prog_statevars.c b/mesalib/src/mesa/program/prog_statevars.c
index 145c07c67..f6fd53576 100644
--- a/mesalib/src/mesa/program/prog_statevars.c
+++ b/mesalib/src/mesa/program/prog_statevars.c
@@ -349,6 +349,9 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
}
}
return;
+ case STATE_NUM_SAMPLES:
+ ((int *)value)[0] = ctx->DrawBuffer->Visual.samples;
+ return;
case STATE_DEPTH_RANGE:
value[0] = ctx->Viewport.Near; /* near */
value[1] = ctx->Viewport.Far; /* far */
@@ -665,6 +668,9 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
case STATE_PROGRAM_MATRIX:
return _NEW_TRACK_MATRIX;
+ case STATE_NUM_SAMPLES:
+ return _NEW_BUFFERS;
+
case STATE_DEPTH_RANGE:
return _NEW_VIEWPORT;
@@ -852,6 +858,9 @@ append_token(char *dst, gl_state_index k)
case STATE_TEXENV_COLOR:
append(dst, "texenv");
break;
+ case STATE_NUM_SAMPLES:
+ append(dst, "numsamples");
+ break;
case STATE_DEPTH_RANGE:
append(dst, "depth.range");
break;
@@ -1027,6 +1036,8 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
break;
case STATE_FOG_COLOR:
break;
+ case STATE_NUM_SAMPLES:
+ break;
case STATE_DEPTH_RANGE:
break;
case STATE_FRAGMENT_PROGRAM:
diff --git a/mesalib/src/mesa/program/prog_statevars.h b/mesalib/src/mesa/program/prog_statevars.h
index ec22b7376..23a9f48c3 100644
--- a/mesalib/src/mesa/program/prog_statevars.h
+++ b/mesalib/src/mesa/program/prog_statevars.h
@@ -103,6 +103,8 @@ typedef enum gl_state_index_ {
STATE_TEXENV_COLOR,
+ STATE_NUM_SAMPLES, /* An integer, not a float like the other state vars */
+
STATE_DEPTH_RANGE,
STATE_VERTEX_PROGRAM,
diff --git a/mesalib/src/mesa/program/program.c b/mesalib/src/mesa/program/program.c
index 093d37297..a102ec17a 100644
--- a/mesalib/src/mesa/program/program.c
+++ b/mesalib/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/mesalib/src/mesa/program/program.h b/mesalib/src/mesa/program/program.h
index 34965ab99..353ccab47 100644
--- a/mesalib/src/mesa/program/program.h
+++ b/mesalib/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)