wined3d: Move the blend enable state to wined3d_blend_state.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2020-03-09 23:07:28 -05:00 committed by Alexandre Julliard
parent a6d74b0545
commit 04453496a2
8 changed files with 40 additions and 44 deletions

View File

@ -721,7 +721,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi
{ {
wined3d_device_set_blend_state(device->wined3d_device, NULL, wined3d_device_set_blend_state(device->wined3d_device, NULL,
(const struct wined3d_color *)blend_factor); (const struct wined3d_color *)blend_factor);
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
wined3d_device_set_render_state(device->wined3d_device, wined3d_device_set_render_state(device->wined3d_device,
WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL); WINED3D_RS_COLORWRITEENABLE, D3D11_COLOR_WRITE_ENABLE_ALL);
wined3d_device_set_render_state(device->wined3d_device, wined3d_device_set_render_state(device->wined3d_device,
@ -737,8 +736,6 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_OMSetBlendState(ID3D11Devi
wined3d_device_set_blend_state(device->wined3d_device, blend_state_impl->wined3d_state, wined3d_device_set_blend_state(device->wined3d_device, blend_state_impl->wined3d_state,
(const struct wined3d_color *)blend_factor); (const struct wined3d_color *)blend_factor);
desc = &blend_state_impl->desc; desc = &blend_state_impl->desc;
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE,
desc->RenderTarget[0].BlendEnable);
if (desc->RenderTarget[0].BlendEnable) if (desc->RenderTarget[0].BlendEnable)
{ {
const D3D11_RENDER_TARGET_BLEND_DESC *d = &desc->RenderTarget[0]; const D3D11_RENDER_TARGET_BLEND_DESC *d = &desc->RenderTarget[0];

View File

@ -389,6 +389,7 @@ HRESULT d3d_blend_state_create(struct d3d_device *device, const D3D11_BLEND_DESC
} }
wined3d_desc.alpha_to_coverage = desc->AlphaToCoverageEnable; wined3d_desc.alpha_to_coverage = desc->AlphaToCoverageEnable;
wined3d_desc.enable = desc->RenderTarget[0].BlendEnable;
/* We cannot fail after creating a wined3d_blend_state object. It /* We cannot fail after creating a wined3d_blend_state object. It
* would lead to double free. */ * would lead to double free. */

View File

@ -3148,7 +3148,7 @@ void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl,
gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST); gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZENABLE)); context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ZENABLE));
gl_info->gl_ops.gl.p_glDisable(GL_BLEND); gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); context_invalidate_state(context, STATE_BLEND);
gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE); gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST); gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
context_invalidate_state(context, STATE_RASTERIZER); context_invalidate_state(context, STATE_RASTERIZER);
@ -3426,7 +3426,7 @@ BOOL wined3d_context_gl_apply_clear_state(struct wined3d_context_gl *context_gl,
} }
checkGLcall("setting up state for clear"); checkGLcall("setting up state for clear");
context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); context_invalidate_state(&context_gl->c, STATE_BLEND);
context_invalidate_state(&context_gl->c, STATE_RASTERIZER); context_invalidate_state(&context_gl->c, STATE_RASTERIZER);
context_invalidate_state(&context_gl->c, STATE_SCISSORRECT); context_invalidate_state(&context_gl->c, STATE_SCISSORRECT);
@ -4458,7 +4458,7 @@ static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_g
* the alpha blend state changes with different render target formats. */ * the alpha blend state changes with different render target formats. */
if (!context_gl->c.current_rt.texture) if (!context_gl->c.current_rt.texture)
{ {
context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); context_invalidate_state(&context_gl->c, STATE_BLEND);
} }
else else
{ {
@ -4470,12 +4470,12 @@ static void wined3d_context_gl_setup_target(struct wined3d_context_gl *context_g
/* Disable blending when the alpha mask has changed and when a format doesn't support blending. */ /* Disable blending when the alpha mask has changed and when a format doesn't support blending. */
if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size) if ((old->alpha_size && !new->alpha_size) || (!old->alpha_size && new->alpha_size)
|| !(texture->resource.format_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)) || !(texture->resource.format_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE)); context_invalidate_state(&context_gl->c, STATE_BLEND);
/* Update sRGB writing when switching between formats that do/do not support sRGB writing */ /* Update sRGB writing when switching between formats that do/do not support sRGB writing */
if ((context_gl->c.current_rt.texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE) if ((context_gl->c.current_rt.texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)
!= (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE)) != (texture->resource.format_flags & WINED3DFMT_FLAG_SRGB_WRITE))
context_invalidate_state(&context_gl->c, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE)); context_invalidate_state(&context_gl->c, STATE_BLEND);
} }
/* When switching away from an offscreen render target, and we're not /* When switching away from an offscreen render target, and we're not

View File

@ -3581,6 +3581,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
switch (idx) switch (idx)
{ {
case WINED3D_RS_BLENDFACTOR: case WINED3D_RS_BLENDFACTOR:
case WINED3D_RS_ALPHABLENDENABLE:
set_blend_state = TRUE; set_blend_state = TRUE;
break; break;
@ -3651,6 +3652,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
desc.alpha_to_coverage = state->alpha_to_coverage; desc.alpha_to_coverage = state->alpha_to_coverage;
if (state->rs[WINED3D_RS_ADAPTIVETESS_Y] == WINED3DFMT_ATOC) if (state->rs[WINED3D_RS_ADAPTIVETESS_Y] == WINED3DFMT_ATOC)
desc.alpha_to_coverage = TRUE; desc.alpha_to_coverage = TRUE;
desc.enable = state->rs[WINED3D_RS_ALPHABLENDENABLE];
if (wined3d_bitmap_is_set(changed->renderState, WINED3D_RS_BLENDFACTOR)) if (wined3d_bitmap_is_set(changed->renderState, WINED3D_RS_BLENDFACTOR))
wined3d_color_from_d3dcolor(&colour, state->rs[WINED3D_RS_BLENDFACTOR]); wined3d_color_from_d3dcolor(&colour, state->rs[WINED3D_RS_BLENDFACTOR]);

View File

@ -3909,7 +3909,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
static unsigned int warned = 0; static unsigned int warned = 0;
args->srgb_correction = 1; args->srgb_correction = 1;
if (state->render_states[WINED3D_RS_ALPHABLENDENABLE] && !warned++) if (state->blend_state && state->blend_state->desc.enable && !warned++)
WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB " WARN("Blending into a sRGB render target with no GL_ARB_framebuffer_sRGB "
"support, expect rendering artifacts.\n"); "support, expect rendering artifacts.\n");
} }

View File

@ -525,15 +525,16 @@ static void gl_blend_from_d3d(GLenum *src_blend, GLenum *dst_blend,
} }
} }
static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) static void state_blend(struct wined3d_context *context, const struct wined3d_state *state)
{ {
const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
const struct wined3d_blend_state *b = state->blend_state;
const struct wined3d_format *rt_format; const struct wined3d_format *rt_format;
GLenum src_blend, dst_blend; GLenum src_blend, dst_blend;
unsigned int rt_fmt_flags; unsigned int rt_fmt_flags;
BOOL enable_blend; BOOL enable_blend;
enable_blend = state->fb->render_targets[0] && state->render_states[WINED3D_RS_ALPHABLENDENABLE]; enable_blend = state->fb->render_targets[0] && b && b->desc.enable;
if (enable_blend) if (enable_blend)
{ {
rt_format = state->fb->render_targets[0]->format; rt_format = state->fb->render_targets[0]->format;
@ -589,8 +590,8 @@ static void state_blend(struct wined3d_context *context, const struct wined3d_st
checkGLcall("glBlendFunc"); checkGLcall("glBlendFunc");
} }
/* Colorkey fixup for stage 0 alphaop depends on /* Colorkey fixup for stage 0 alphaop depends on blend state, so it may need
* WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */ * updating. */
if (state->render_states[WINED3D_RS_COLORKEYENABLE]) if (state->render_states[WINED3D_RS_COLORKEYENABLE])
context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP)); context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
} }
@ -611,26 +612,21 @@ static void state_blend_factor(struct wined3d_context *context, const struct win
checkGLcall("glBlendColor"); checkGLcall("glBlendColor");
} }
static void state_blend_object(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) static void blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info; const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
BOOL alpha_to_coverage = FALSE; const struct wined3d_blend_state *b = state->blend_state;
if (!gl_info->supported[ARB_MULTISAMPLE]) if (gl_info->supported[ARB_MULTISAMPLE])
return;
if (state->blend_state)
{ {
struct wined3d_blend_state_desc *desc = &state->blend_state->desc; if (b && b->desc.alpha_to_coverage)
alpha_to_coverage = desc->alpha_to_coverage;
}
if (alpha_to_coverage)
gl_info->gl_ops.gl.p_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); gl_info->gl_ops.gl.p_glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
else else
gl_info->gl_ops.gl.p_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); gl_info->gl_ops.gl.p_glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
checkGLcall("glEnable GL_SAMPLE_ALPHA_TO_COVERAGE");
}
checkGLcall("blend state"); state_blend(context, state);
} }
void state_alpha_test(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) void state_alpha_test(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
@ -3222,10 +3218,9 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
* SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the * SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the
* game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of * game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of
* color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels * color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels
* fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha * fail alpha test). To get around this, blend state is checked: if the app enables alpha blending,
* blending, it can be expected to provide meaningful values in diffuse alpha, so it should be * it can be expected to provide meaningful values in diffuse alpha, so it should be modulated with
* modulated with texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture * texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture alpha.
* alpha.
* *
* What to do with multitexturing? So far no app has been found that uses color keying with * What to do with multitexturing? So far no app has been found that uses color keying with
* multitexturing */ * multitexturing */
@ -3236,7 +3231,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
} }
else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE) else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE)
{ {
if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) if (state->blend_state && state->blend_state->desc.enable)
{ {
arg2 = WINED3DTA_TEXTURE; arg2 = WINED3DTA_TEXTURE;
op = WINED3D_TOP_MODULATE; op = WINED3D_TOP_MODULATE;
@ -3245,7 +3240,7 @@ void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *st
} }
else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE) else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE)
{ {
if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) if (state->blend_state && state->blend_state->desc.enable)
{ {
arg1 = WINED3DTA_TEXTURE; arg1 = WINED3DTA_TEXTURE;
op = WINED3D_TOP_MODULATE; op = WINED3D_TOP_MODULATE;
@ -4509,16 +4504,15 @@ const struct wined3d_state_entry_template misc_state_template[] =
{ STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE }, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, { STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, state_uav_warn }, WINED3D_GL_EXT_NONE },
{ STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so, }, WINED3D_GL_VERSION_3_2 }, { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so, }, WINED3D_GL_VERSION_3_2 },
{ STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so_warn, }, WINED3D_GL_EXT_NONE }, { STATE_STREAM_OUTPUT, { STATE_STREAM_OUTPUT, state_so_warn, }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_SRCBLEND), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_DESTBLEND), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), state_blend }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), state_line_antialias}, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS), state_line_antialias}, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_BLENDOPALPHA), { STATE_BLEND, NULL }, WINED3D_GL_EXT_NONE },
{ STATE_BLEND, { STATE_BLEND, state_blend_object }, WINED3D_GL_EXT_NONE }, { STATE_BLEND, { STATE_BLEND, blend }, WINED3D_GL_EXT_NONE },
{ STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor }, EXT_BLEND_COLOR }, { STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor }, EXT_BLEND_COLOR },
{ STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor_w}, WINED3D_GL_EXT_NONE }, { STATE_BLEND_FACTOR, { STATE_BLEND_FACTOR, state_blend_factor_w}, WINED3D_GL_EXT_NONE },
{ STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE }, { STATE_STREAMSRC, { STATE_STREAMSRC, streamsrc }, WINED3D_GL_EXT_NONE },
@ -5427,6 +5421,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table)
{ 8, 8}, { 8, 8},
{ 17, 18}, { 17, 18},
{ 21, 22}, { 21, 22},
{ 27, 27},
{ 42, 45}, { 42, 45},
{ 47, 47}, { 47, 47},
{ 61, 127}, { 61, 127},

View File

@ -6134,7 +6134,7 @@ void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d
} }
else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE) else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE)
{ {
if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) if (state->blend_state && state->blend_state->desc.enable)
{ {
aarg2 = WINED3DTA_TEXTURE; aarg2 = WINED3DTA_TEXTURE;
aop = WINED3D_TOP_MODULATE; aop = WINED3D_TOP_MODULATE;
@ -6143,7 +6143,7 @@ void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d
} }
else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE) else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE)
{ {
if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]) if (state->blend_state && state->blend_state->desc.enable)
{ {
aarg1 = WINED3DTA_TEXTURE; aarg1 = WINED3DTA_TEXTURE;
aop = WINED3D_TOP_MODULATE; aop = WINED3D_TOP_MODULATE;

View File

@ -2029,6 +2029,7 @@ struct wined3d_buffer_desc
struct wined3d_blend_state_desc struct wined3d_blend_state_desc
{ {
BOOL alpha_to_coverage; BOOL alpha_to_coverage;
BOOL enable;
}; };
struct wined3d_rasterizer_state_desc struct wined3d_rasterizer_state_desc