[Mesa-dev] [PATCH] st/mesa: emit saturates in the vertex shader if Shader Model 3.0 is supported
Marek Olšák
maraeo at gmail.com
Sun Feb 3 09:25:55 PST 2013
v2: change the requirement from GLSL 1.30 to SM 3.0 (R500 can do this)
---
src/mesa/state_tracker/st_context.c | 1 +
src/mesa/state_tracker/st_context.h | 1 +
src/mesa/state_tracker/st_extensions.c | 1 +
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 22 +++++++++++++++++++---
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index b416319..676fc06 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -182,6 +182,7 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
st->has_stencil_export =
screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT);
+ st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3);
/* GL limits and extensions */
st_init_limits(st);
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 70ee671..726c64d 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -84,6 +84,7 @@ struct st_context
GLboolean clamp_vert_color_in_shader;
boolean has_stencil_export; /**< can do shader stencil export? */
boolean has_time_elapsed;
+ boolean has_shader_model3;
/* On old libGL's for linux we need to invalidate the drawables
* on glViewpport calls, this is set via a option.
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 214588f..4d2d43d 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -597,6 +597,7 @@ void st_init_extensions(struct st_context *st)
/* Extensions that either depend on GLSL 1.30 or are a subset thereof. */
ctx->Extensions.ARB_conservative_depth = GL_TRUE;
ctx->Extensions.ARB_shader_bit_encoding = GL_TRUE;
+ ctx->Extensions.ARB_shading_language_packing = GL_TRUE;
ctx->Extensions.OES_depth_texture_cube_map = GL_TRUE;
} else {
/* Optional integer support for GLSL 1.2. */
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 994a551..33ff235 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1286,11 +1286,12 @@ glsl_to_tgsi_visitor::try_emit_mad_for_and_not(ir_expression *ir, int try_operan
bool
glsl_to_tgsi_visitor::try_emit_sat(ir_expression *ir)
{
- /* Saturates were only introduced to vertex programs in
- * NV_vertex_program3, so don't give them to drivers in the VP.
+ /* Emit saturates in the vertex shader only if GLSL 1.30 is supported.
*/
- if (this->prog->Target == GL_VERTEX_PROGRAM_ARB)
+ if (this->prog->Target == GL_VERTEX_PROGRAM_ARB &&
+ !st_context(this->ctx)->has_shader_model3) {
return false;
+ }
ir_rvalue *sat_src = ir->as_rvalue_to_saturate();
if (!sat_src)
@@ -5153,6 +5154,21 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
options->EmitNoIndirectUniform);
}
+ if (ctx->Extensions.ARB_shading_language_packing) {
+ unsigned lower_inst = LOWER_PACK_SNORM_2x16 |
+ LOWER_UNPACK_SNORM_2x16 |
+ LOWER_PACK_UNORM_2x16 |
+ LOWER_UNPACK_UNORM_2x16 |
+ LOWER_PACK_SNORM_4x8 |
+ LOWER_UNPACK_SNORM_4x8 |
+ LOWER_UNPACK_UNORM_4x8 |
+ LOWER_PACK_UNORM_4x8 |
+ LOWER_PACK_HALF_2x16 |
+ LOWER_UNPACK_HALF_2x16;
+
+ lower_packing_builtins(ir, lower_inst);
+ }
+
do_mat_op_to_vec(ir);
lower_instructions(ir,
MOD_TO_FRACT |
--
1.7.10.4
More information about the mesa-dev
mailing list