[PATCH 2/5] wined3d: Move the multisample antialiasing state to wined3d_rasterizer_state.

Zebediah Figura z.figura12 at gmail.com
Mon Apr 13 09:49:25 CDT 2020


On 4/13/20 2:27 AM, Chip Davis wrote:
> I'm curious as to why Zeb didn't move this with the other rasterizer
> states. Perhaps it's because the default is different in d3d8/9 vs.
> d3d10+.
> 
> Signed-off-by: Chip Davis <cdavis at codeweavers.com>

The problem isn't just that the default state is different, but that 
changing the default state to disabled (even just for d3d11) breaks 
resolve for blits. I don't understand that code very well and I didn't 
want to spend that long trying to find the right places to invalidate it.

I suspect also the preferred solution is to always default to FALSE in 
wined3d and use wined3d_stateblock_set_render_state() in the client 
libraries, as is done for WINED3D_RS_ZENABLE and 
WINED3D_RS_POINTSIZE_MIN in d3d8.

> ---
>   dlls/d3d11/device.c       | 15 +++----------
>   dlls/d3d11/state.c        |  1 +
>   dlls/wined3d/device.c     |  2 ++
>   dlls/wined3d/state.c      | 46 +++++++++++++++++++--------------------
>   dlls/wined3d/stateblock.c |  4 ++++
>   include/wine/wined3d.h    |  1 +
>   6 files changed, 33 insertions(+), 36 deletions(-)
> 
> diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
> index 7544bc86f4b..7c75431780c 100644
> --- a/dlls/d3d11/device.c
> +++ b/dlls/d3d11/device.c
> @@ -896,18 +896,9 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_RSSetState(ID3D11DeviceCon
>       TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
>   
>       wined3d_mutex_lock();
> -    if (!(rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state)))
> -    {
> -        wined3d_device_set_rasterizer_state(device->wined3d_device, NULL);
> -        wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
> -        wined3d_mutex_unlock();
> -        return;
> -    }
> -
> -    wined3d_device_set_rasterizer_state(device->wined3d_device, rasterizer_state_impl->wined3d_state);
> -
> -    desc = &rasterizer_state_impl->desc;
> -    wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
> +    rasterizer_state_impl = unsafe_impl_from_ID3D11RasterizerState(rasterizer_state);
> +    wined3d_device_set_rasterizer_state(device->wined3d_device,
> +            rasterizer_state_impl ? rasterizer_state_impl->wined3d_state : NULL);
>       wined3d_mutex_unlock();
>   }
>   
> diff --git a/dlls/d3d11/state.c b/dlls/d3d11/state.c
> index 32ef44091c4..6d7f70664e7 100644
> --- a/dlls/d3d11/state.c
> +++ b/dlls/d3d11/state.c
> @@ -1118,6 +1118,7 @@ static HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, str
>       wined3d_desc.scale_bias = desc->SlopeScaledDepthBias;
>       wined3d_desc.depth_clip = desc->DepthClipEnable;
>       wined3d_desc.scissor = desc->ScissorEnable;
> +    wined3d_desc.multisample = desc->MultisampleEnable;
>       wined3d_desc.line_antialias = desc->AntialiasedLineEnable;
>   
>       /* We cannot fail after creating a wined3d_rasterizer_state object. It
> diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
> index ee007568d46..8baf9b9df19 100644
> --- a/dlls/wined3d/device.c
> +++ b/dlls/wined3d/device.c
> @@ -3608,6 +3608,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
>                   case WINED3D_RS_SLOPESCALEDEPTHBIAS:
>                   case WINED3D_RS_DEPTHBIAS:
>                   case WINED3D_RS_SCISSORTESTENABLE:
> +                case WINED3D_RS_MULTISAMPLEANTIALIAS:
>                   case WINED3D_RS_ANTIALIASEDLINEENABLE:
>                       set_rasterizer_state = TRUE;
>                       break;
> @@ -3639,6 +3640,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
>           desc.scale_bias = bias.f;
>           desc.depth_clip = TRUE;
>           desc.scissor = state->rs[WINED3D_RS_SCISSORTESTENABLE];
> +        desc.multisample = state->rs[WINED3D_RS_MULTISAMPLEANTIALIAS];
>           desc.line_antialias = state->rs[WINED3D_RS_ANTIALIASEDLINEENABLE];
>   
>           if ((entry = wine_rb_get(&device->rasterizer_states, &desc)))
> diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
> index 1cb9f222eab..d7792f46168 100644
> --- a/dlls/wined3d/state.c
> +++ b/dlls/wined3d/state.c
> @@ -1776,28 +1776,6 @@ static void state_wrap(struct wined3d_context *context, const struct wined3d_sta
>           FIXME("(WINED3D_RS_WRAP0) Texture wrapping not yet supported.\n");
>   }
>   
> -static void state_msaa_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
> -{
> -    if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
> -        WARN("Multisample antialiasing not supported by GL.\n");
> -}
> -
> -static void state_msaa(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;
> -
> -    if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
> -    {
> -        gl_info->gl_ops.gl.p_glEnable(GL_MULTISAMPLE_ARB);
> -        checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
> -    }
> -    else
> -    {
> -        gl_info->gl_ops.gl.p_glDisable(GL_MULTISAMPLE_ARB);
> -        checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
> -    }
> -}
> -
>   static void line_antialias(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info)
>   {
>       if (r && r->desc.line_antialias)
> @@ -4407,6 +4385,25 @@ static void depth_clip(const struct wined3d_rasterizer_state *r, const struct wi
>       checkGLcall("depth clip");
>   }
>   
> +static void multisample(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info)
> +{
> +    if (r && r->desc.multisample)
> +    {
> +        if (gl_info->supported[ARB_MULTISAMPLE])
> +        {
> +            gl_info->gl_ops.gl.p_glEnable(GL_MULTISAMPLE);
> +            checkGLcall("glEnable GL_MULTISAMPLE");
> +        }
> +        else
> +            WARN("Multisample antialiasing not supported by GL.\n");
> +    }
> +    else if (gl_info->supported[ARB_MULTISAMPLE])
> +    {
> +        gl_info->gl_ops.gl.p_glDisable(GL_MULTISAMPLE);
> +        checkGLcall("glDisable GL_MULTISAMPLE");
> +    }
> +}
> +
>   static void rasterizer(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;
> @@ -4424,6 +4421,7 @@ static void rasterizer(struct wined3d_context *context, const struct wined3d_sta
>       cullmode(r, gl_info);
>       depth_clip(r, gl_info);
>       scissor(r, gl_info);
> +    multisample(r, gl_info);
>       line_antialias(r, gl_info);
>   }
>   
> @@ -4442,6 +4440,7 @@ static void rasterizer_cc(struct wined3d_context *context, const struct wined3d_
>       cullmode(r, gl_info);
>       depth_clip(r, gl_info);
>       scissor(r, gl_info);
> +    multisample(r, gl_info);
>       line_antialias(r, gl_info);
>   }
>   
> @@ -4736,8 +4735,6 @@ const struct wined3d_state_entry_template misc_state_template[] =
>       { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W),            { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
>       { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_nvdb          }, EXT_DEPTH_BOUNDS_TEST           },
>       { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_tessellation  }, WINED3D_GL_EXT_NONE             },
> -    { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      state_msaa          }, ARB_MULTISAMPLE                 },
> -    { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      state_msaa_w        }, WINED3D_GL_EXT_NONE             },
>       { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK),           { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK),           state_multisampmask }, WINED3D_GL_EXT_NONE             },
>       { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN),         { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN),         state_debug_monitor }, WINED3D_GL_EXT_NONE             },
>       { STATE_RENDER(WINED3D_RS_ZVISIBLE),                  { STATE_RENDER(WINED3D_RS_ZVISIBLE),                  state_zvisible      }, WINED3D_GL_EXT_NONE             },
> @@ -5505,6 +5502,7 @@ static void validate_state_table(struct wined3d_state_entry *state_table)
>           { 47,  47},
>           { 61, 127},
>           {149, 150},
> +        {161, 161},
>           {168, 169},
>           {171, 171},
>           {174, 177},
> diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
> index 7e97c84c19e..84b64eae7aa 100644
> --- a/dlls/wined3d/stateblock.c
> +++ b/dlls/wined3d/stateblock.c
> @@ -1925,6 +1925,10 @@ static HRESULT stateblock_init(struct wined3d_stateblock *stateblock, const stru
>       if (type == WINED3D_SBT_RECORDED || type == WINED3D_SBT_PRIMARY)
>           return WINED3D_OK;
>   
> +    /* The default multisample state in d3d9 and under is TRUE, but FALSE in d3d10 and up. Force the multisample
> +     * antialiasing state to be marked changed regardless of the stateblock type to ensure it is set correctly. */
> +    stateblock->changed.renderState[WINED3D_RS_MULTISAMPLEANTIALIAS >> 5] |= 1u << (WINED3D_RS_MULTISAMPLEANTIALIAS & 0x1f);
> +
>       TRACE("Updating changed flags appropriate for type %#x.\n", type);
>   
>       switch (type)
> diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
> index d3eb8100cd8..f9a0d9e0f89 100644
> --- a/include/wine/wined3d.h
> +++ b/include/wine/wined3d.h
> @@ -2043,6 +2043,7 @@ struct wined3d_rasterizer_state_desc
>       float scale_bias;
>       BOOL depth_clip;
>       BOOL scissor;
> +    BOOL multisample;
>       BOOL line_antialias;
>   };
>   
> 




More information about the wine-devel mailing list