Commit 53eff53d authored by Erik Faye-Lund 's avatar Erik Faye-Lund

HACK: st/mesa: support lowering two-sided lighting

parent 3c916876
......@@ -138,18 +138,28 @@ nir_lower_two_sided_color_block(nir_block *block,
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
if (intr->intrinsic != nir_intrinsic_load_input)
continue;
int idx;
for (idx = 0; idx < state->colors_count; idx++) {
unsigned drvloc =
state->colors[idx].front->data.driver_location;
if (nir_intrinsic_base(intr) == drvloc) {
assert(nir_src_is_const(intr->src[0]));
break;
if (intr->intrinsic == nir_intrinsic_load_input) {
for (idx = 0; idx < state->colors_count; idx++) {
unsigned drvloc =
state->colors[idx].front->data.driver_location;
if (nir_intrinsic_base(intr) == drvloc) {
assert(nir_src_is_const(intr->src[0]));
break;
}
}
}
} else if (intr->intrinsic == nir_intrinsic_load_deref) {
nir_variable *var = nir_intrinsic_get_var(intr, 0);
if (var->data.mode != nir_var_shader_in)
continue;
for (idx = 0; idx < state->colors_count; idx++) {
unsigned loc = state->colors[idx].front->data.location;
if (var->data.location == loc)
break;
}
} else
continue;
if (idx == state->colors_count)
continue;
......@@ -162,8 +172,14 @@ nir_lower_two_sided_color_block(nir_block *block,
* 32-bit value by default.
*/
nir_ssa_def *face = nir_load_front_face(b, 1);
nir_ssa_def *front = load_input(b, state->colors[idx].front);
nir_ssa_def *back = load_input(b, state->colors[idx].back);
nir_ssa_def *front, *back;
if (intr->intrinsic == nir_intrinsic_load_deref) {
front = nir_load_var(b, state->colors[idx].front);
back = nir_load_var(b, state->colors[idx].back);
} else {
front = load_input(b, state->colors[idx].front);
back = load_input(b, state->colors[idx].back);
}
nir_ssa_def *color = nir_bcsel(b, face, front, back);
assert(intr->dest.is_ssa);
......
......@@ -337,6 +337,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
case PIPE_CAP_LOWER_ALPHA_TEST:
case PIPE_CAP_LOWER_UCP:
case PIPE_CAP_LOWER_POINT_SIZE:
case PIPE_CAP_LOWER_TWO_SIDED_COLOR:
return 0;
case PIPE_CAP_MAX_GS_INVOCATIONS:
......
......@@ -539,6 +539,7 @@ The integer capabilities:
* ``PIPE_CAP_VERTEX_SHADER_SATURATE``: True if the driver supports saturate
modifiers in the vertex shader.
* ``PIPE_CAP_LOWER_FLATSHADE``: Lower flatshading for NIR drivers.
* ``PIPE_CAP_LOWER_TWO_SIDED_COLOR``: Lower two-sided coloring for NIR drivers.
.. _pipe_capf:
......
......@@ -894,6 +894,7 @@ enum pipe_cap
PIPE_CAP_LOWER_ALPHA_TEST,
PIPE_CAP_LOWER_UCP,
PIPE_CAP_LOWER_POINT_SIZE,
PIPE_CAP_LOWER_TWO_SIDED_COLOR,
};
/**
......
......@@ -100,7 +100,8 @@ st_update_rasterizer(struct st_context *st)
GL_FIRST_VERTEX_CONVENTION_EXT;
/* _NEW_LIGHT | _NEW_PROGRAM */
raster->light_twoside = _mesa_vertex_program_two_side_enabled(ctx);
if (!st->lower_two_sided_color)
raster->light_twoside = _mesa_vertex_program_two_side_enabled(ctx);
/*_NEW_LIGHT | _NEW_BUFFERS */
raster->clamp_vertex_color = !st->clamp_vert_color_in_shader &&
......
......@@ -38,6 +38,7 @@
#include "main/imports.h"
#include "main/mtypes.h"
#include "main/framebuffer.h"
#include "main/state.h"
#include "main/texobj.h"
#include "main/texstate.h"
#include "program/program.h"
......@@ -128,6 +129,10 @@ st_update_fp( struct st_context *st )
if (st->lower_alpha_test && _mesa_is_alpha_test_enabled(st->ctx))
key.lower_alpha_func = st->ctx->Color.AlphaFunc;
/* _NEW_LIGHT | _NEW_PROGRAM */
key.lower_two_sided_color = st->lower_two_sided_color &&
_mesa_vertex_program_two_side_enabled(st->ctx);
/* _NEW_FRAG_CLAMP */
key.clamp_color = st->clamp_frag_color_in_shader &&
st->ctx->Color._ClampFragmentColor;
......
......@@ -231,8 +231,9 @@ st_invalidate_state(struct gl_context *ctx)
_NEW_POINT))
st->dirty |= ST_NEW_RASTERIZER;
if ((new_state & _NEW_LIGHT) &&
st->lower_flatshade)
if (((new_state & _NEW_LIGHT) &&
(st->lower_flatshade || st->lower_two_sided_color)) ||
(new_state & _NEW_PROGRAM && st->lower_two_sided_color))
st->dirty |= ST_NEW_FS_STATE;
if (new_state & _NEW_PROJECTION &&
......@@ -667,6 +668,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
screen->get_param(screen, PIPE_CAP_LOWER_UCP);
st->lower_point_size =
screen->get_param(screen, PIPE_CAP_LOWER_POINT_SIZE);
st->lower_two_sided_color =
screen->get_param(screen, PIPE_CAP_LOWER_TWO_SIDED_COLOR);
st->has_hw_atomics =
screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
......
......@@ -149,6 +149,7 @@ struct st_context
boolean lower_alpha_test;
boolean lower_ucp;
boolean lower_point_size;
boolean lower_two_sided_color;
/**
* If a shader can be created when we get its source.
......
......@@ -1194,6 +1194,9 @@ st_create_fp_variant(struct st_context *st,
false, alpha_ref_state);
}
if (key->lower_two_sided_color)
NIR_PASS_V(tgsi.ir.nir, nir_lower_two_sided_color);
if (key->persample_shading) {
nir_shader *shader = tgsi.ir.nir;
nir_foreach_variable(var, &shader->inputs)
......
......@@ -105,6 +105,9 @@ struct st_fp_variant_key
/** needed for ATI_fragment_shader */
GLuint fog:2;
/** for OpenGL 1.0 on modern hardware */
GLuint lower_two_sided_color:1;
/** needed for ATI_fragment_shader */
char texture_targets[MAX_NUM_FRAGMENT_REGISTERS_ATI];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment