Commit 76085f20 authored by Marek Olšák's avatar Marek Olšák

st/mesa: generate blend state according to the number of enabled color buffers

Non-MRT cases always translate blend state for 1 color buffer only.
MRT cases only check and translate blend state for enabled color buffers.

This also avoids an assertion failure in translate_blend for:
  dEQP-GLES31.functional.draw_buffers_indexed.overwrite_common.common_advanced_blend_eq_buffer_blend_eq
Reviewed-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
parent c446dd79
......@@ -112,23 +112,26 @@ translate_blend(GLenum blend)
* Figure out if colormasks are different per rt.
*/
static GLboolean
colormask_per_rt(const struct gl_context *ctx)
colormask_per_rt(const struct gl_context *ctx, unsigned num_cb)
{
GLbitfield full_mask = _mesa_replicate_colormask(0xf, num_cb);
GLbitfield repl_mask0 =
_mesa_replicate_colormask(GET_COLORMASK(ctx->Color.ColorMask, 0),
ctx->Const.MaxDrawBuffers);
num_cb);
return ctx->Color.ColorMask != repl_mask0;
return (ctx->Color.ColorMask & full_mask) != repl_mask0;
}
/**
* Figure out if blend enables/state are different per rt.
*/
static GLboolean
blend_per_rt(const struct gl_context *ctx)
blend_per_rt(const struct gl_context *ctx, unsigned num_cb)
{
if (ctx->Color.BlendEnabled &&
(ctx->Color.BlendEnabled != ((1U << ctx->Const.MaxDrawBuffers) - 1))) {
GLbitfield cb_mask = u_bit_consecutive(0, num_cb);
GLbitfield blend_enabled = ctx->Color.BlendEnabled & cb_mask;
if (blend_enabled && blend_enabled != cb_mask) {
/* This can only happen if GL_EXT_draw_buffers2 is enabled */
return GL_TRUE;
}
......@@ -144,13 +147,15 @@ st_update_blend( struct st_context *st )
{
struct pipe_blend_state *blend = &st->state.blend;
const struct gl_context *ctx = st->ctx;
unsigned num_cb = st->state.fb_num_cb;
unsigned num_state = 1;
unsigned i, j;
memset(blend, 0, sizeof(*blend));
if (blend_per_rt(ctx) || colormask_per_rt(ctx)) {
num_state = ctx->Const.MaxDrawBuffers;
if (num_cb > 1 &&
(blend_per_rt(ctx, num_cb) || colormask_per_rt(ctx, num_cb))) {
num_state = num_cb;
blend->independent_blend_enable = 1;
}
......
......@@ -216,4 +216,5 @@ st_update_framebuffer_state( struct st_context *st )
st->state.fb_height = framebuffer.height;
st->state.fb_num_samples = util_framebuffer_get_num_samples(&framebuffer);
st->state.fb_num_layers = util_framebuffer_get_num_layers(&framebuffer);
st->state.fb_num_cb = framebuffer.nr_cbufs;
}
......@@ -10,7 +10,6 @@ ST_STATE(ST_NEW_VS_STATE, st_update_vp)
ST_STATE(ST_NEW_POLY_STIPPLE, st_update_polygon_stipple)
ST_STATE(ST_NEW_WINDOW_RECTANGLES, st_update_window_rectangles)
ST_STATE(ST_NEW_BLEND, st_update_blend)
ST_STATE(ST_NEW_BLEND_COLOR, st_update_blend_color)
ST_STATE(ST_NEW_VS_SAMPLER_VIEWS, st_update_vertex_textures)
......@@ -33,6 +32,7 @@ ST_STATE(ST_NEW_GS_IMAGES, st_bind_gs_images)
ST_STATE(ST_NEW_FS_IMAGES, st_bind_fs_images)
ST_STATE(ST_NEW_FB_STATE, st_update_framebuffer_state) /* depends on update_*_texture and bind_*_images */
ST_STATE(ST_NEW_BLEND, st_update_blend) /* depends on update_framebuffer_state */
ST_STATE(ST_NEW_RASTERIZER, st_update_rasterizer) /* depends on update_framebuffer_state */
ST_STATE(ST_NEW_SAMPLE_MASK, st_update_sample_mask) /* depends on update_framebuffer_state */
ST_STATE(ST_NEW_SAMPLE_SHADING, st_update_sample_shading)
......
......@@ -164,6 +164,7 @@ struct st_context
unsigned fb_height;
unsigned fb_num_samples;
unsigned fb_num_layers;
unsigned fb_num_cb;
unsigned num_viewports;
struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS];
......
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