From: Daniel Ansorregui Subject: [PATCH v2 5/6] wined3d: Remove WINED3D_RS_BLENDFACTOR use blend_state instead Message-Id: <20181017003938.30823-1-mailszeros@gmail.com> Date: Wed, 17 Oct 2018 01:39:38 +0100 In-Reply-To: <20181015191720.1981-5-mailszeros@gmail.com> References: <20181015191720.1981-5-mailszeros@gmail.com> * This patch is unifying the d3d 9/10/11 blend_factors Adding blend factor to savedstate so it passes all d3d9 tests Signed-off-by: Daniel Ansorregui --- dlls/d3d9/device.c | 26 ++++++++++++++++++++++++-- dlls/wined3d/device.c | 6 +++++- dlls/wined3d/state.c | 20 +------------------- dlls/wined3d/stateblock.c | 24 ++++++++++++++++++++++-- dlls/wined3d/utils.c | 1 - dlls/wined3d/wined3d_private.h | 3 ++- include/wine/wined3d.h | 1 - 7 files changed, 54 insertions(+), 27 deletions(-) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index a31360886b..3e3e643c1f 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -2221,7 +2221,18 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_SetRenderState(IDirect3DDevi TRACE("iface %p, state %#x, value %#x.\n", iface, state, value); wined3d_mutex_lock(); - wined3d_device_set_render_state(device->wined3d_device, state, value); + switch (state) + { + case D3DRS_BLENDFACTOR: + { + struct wined3d_color factor; + wined3d_color_from_d3dcolor(&factor, value); + wined3d_device_set_blend_state(device->wined3d_device, NULL, &factor); + break; + } + default: + wined3d_device_set_render_state(device->wined3d_device, state, value); + } wined3d_mutex_unlock(); return D3D_OK; @@ -2235,7 +2246,18 @@ static HRESULT WINAPI d3d9_device_GetRenderState(IDirect3DDevice9Ex *iface, TRACE("iface %p, state %#x, value %p.\n", iface, state, value); wined3d_mutex_lock(); - *value = wined3d_device_get_render_state(device->wined3d_device, state); + switch (state) + { + case D3DRS_BLENDFACTOR: + { + struct wined3d_color factor; + wined3d_device_get_blend_factor(device->wined3d_device, &factor); + *value = d3dcolor_from_wined3d_color(factor); + break; + } + default: + *value = wined3d_device_get_render_state(device->wined3d_device, state); + } wined3d_mutex_unlock(); return D3D_OK; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 365a46e9d6..9970078ac7 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1982,6 +1982,9 @@ void CDECL wined3d_device_set_blend_state(struct wined3d_device *device, struct TRACE("device %p, blend_state %p, blend_factor %s.\n", device, blend_state, debug_color(blend_factor)); + if (device->recording) + device->recording->changed.blendState = TRUE; + prev = device->update_state->blend_state; if (prev == blend_state && !memcmp(blend_factor, &device->update_state->blend_factor, sizeof(*blend_factor))) return; @@ -1990,7 +1993,8 @@ void CDECL wined3d_device_set_blend_state(struct wined3d_device *device, struct wined3d_blend_state_incref(blend_state); device->update_state->blend_state = blend_state; device->update_state->blend_factor = *blend_factor; - wined3d_cs_emit_set_blend_state(device->cs, blend_state, blend_factor); + if (!device->recording) + wined3d_cs_emit_set_blend_state(device->cs, blend_state, blend_factor); if (prev) wined3d_blend_state_decref(prev); } diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index bbc2ddc9e1..38331a0df4 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -597,23 +597,6 @@ static void state_blend(struct wined3d_context *context, const struct wined3d_st context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP)); } -static void state_blendfactor_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) -{ - WARN("Unsupported in local OpenGL implementation: glBlendColor.\n"); -} - -static void state_blendfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) -{ - const struct wined3d_gl_info *gl_info = context->gl_info; - struct wined3d_color color; - - TRACE("Setting blend factor to %#x.\n", state->render_states[WINED3D_RS_BLENDFACTOR]); - - wined3d_color_from_d3dcolor(&color, state->render_states[WINED3D_RS_BLENDFACTOR]); - GL_EXTCALL(glBlendColor(color.r, color.g, color.b, color.a)); - checkGLcall("glBlendColor"); -} - static void state_blend_object(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) { const struct wined3d_gl_info *gl_info = context->gl_info; @@ -4699,8 +4682,6 @@ const struct StateEntryTemplate misc_state_template[] = { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), state_colorwrite3 }, EXT_DRAW_BUFFERS2 }, { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3), { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE), NULL }, WINED3D_GL_EXT_NONE }, - { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor }, EXT_BLEND_COLOR }, - { STATE_RENDER(WINED3D_RS_BLENDFACTOR), { STATE_RENDER(WINED3D_RS_BLENDFACTOR), state_blendfactor_w }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_DEPTHBIAS), { STATE_RENDER(WINED3D_RS_DEPTHBIAS), state_depthbias }, WINED3D_GL_EXT_NONE }, { STATE_RENDER(WINED3D_RS_ZVISIBLE), { STATE_RENDER(WINED3D_RS_ZVISIBLE), state_zvisible }, WINED3D_GL_EXT_NONE }, /* Samplers */ @@ -5463,6 +5444,7 @@ static void validate_state_table(struct StateEntry *state_table) {149, 150}, {169, 169}, {177, 177}, + {193, 193}, {196, 197}, { 0, 0}, }; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 213b120752..f9f55249f6 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -35,7 +35,6 @@ static const DWORD pixel_states_render[] = WINED3D_RS_ALPHAREF, WINED3D_RS_ALPHATESTENABLE, WINED3D_RS_ANTIALIASEDLINEENABLE, - WINED3D_RS_BLENDFACTOR, WINED3D_RS_BLENDOP, WINED3D_RS_BLENDOPALPHA, WINED3D_RS_BACK_STENCILFAIL, @@ -209,6 +208,7 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states, states->pixelShader = 1; states->vertexShader = 1; states->scissorRect = 1; + states->blendState = 1; /* Fixed size arrays */ states->streamSource = 0xffff; @@ -236,6 +236,7 @@ static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *states unsigned int i; states->pixelShader = 1; + states->blendState = 1; for (i = 0; i < ARRAY_SIZE(pixel_states_render); ++i) { @@ -839,6 +840,21 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) SetRectEmpty(stateblock->state.scissor_rects); } + if (stateblock->changed.blendState + && (src_state->blend_state != stateblock->state.blend_state + || memcmp(&src_state->blend_factor, &stateblock->state.blend_factor, + sizeof(stateblock->state.blend_factor)))) + { + TRACE("Updating blend state.\n"); + + if (src_state->blend_state) + wined3d_blend_state_incref(src_state->blend_state); + if (stateblock->state.blend_state) + wined3d_blend_state_decref(stateblock->state.blend_state); + stateblock->state.blend_state = src_state->blend_state; + stateblock->state.blend_factor = src_state->blend_factor; + } + map = stateblock->changed.streamSource; for (i = 0; map; map >>= 1, ++i) { @@ -1074,6 +1090,11 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock) wined3d_device_set_scissor_rects(device, stateblock->state.scissor_rect_count, stateblock->state.scissor_rects); + if (stateblock->changed.blendState){ + wined3d_device_set_blend_state(device, stateblock->state.blend_state, + &stateblock->state.blend_factor); + } + map = stateblock->changed.streamSource; for (i = 0; map; map >>= 1, ++i) { @@ -1255,7 +1276,6 @@ static void state_init_default(struct wined3d_state *state, const struct wined3d state->render_states[WINED3D_RS_COLORWRITEENABLE1] = 0x0000000f; state->render_states[WINED3D_RS_COLORWRITEENABLE2] = 0x0000000f; state->render_states[WINED3D_RS_COLORWRITEENABLE3] = 0x0000000f; - state->render_states[WINED3D_RS_BLENDFACTOR] = 0xffffffff; state->render_states[WINED3D_RS_SRGBWRITEENABLE] = 0; state->render_states[WINED3D_RS_DEPTHBIAS] = 0; state->render_states[WINED3D_RS_WRAP8] = 0; diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index da01bbb0b6..3bae059a88 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -4762,7 +4762,6 @@ const char *debug_d3drenderstate(enum wined3d_render_state state) D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1); D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2); D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3); - D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR); D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE); D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS); D3DSTATE_TO_STR(WINED3D_RS_WRAP8); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index dbcf17e26c..7bd7681666 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3492,7 +3492,8 @@ struct wined3d_saved_states DWORD pixelShader : 1; DWORD vertexShader : 1; DWORD scissorRect : 1; - DWORD padding : 5; + DWORD blendState : 1; + DWORD padding : 4; }; struct StageState { diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 3441fee16a..e8901a9568 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -388,7 +388,6 @@ enum wined3d_render_state WINED3D_RS_COLORWRITEENABLE1 = 190, WINED3D_RS_COLORWRITEENABLE2 = 191, WINED3D_RS_COLORWRITEENABLE3 = 192, - WINED3D_RS_BLENDFACTOR = 193, WINED3D_RS_SRGBWRITEENABLE = 194, WINED3D_RS_DEPTHBIAS = 195, WINED3D_RS_WRAP8 = 198, -- 2.17.1