[PATCH v2 2/5] d3d9: Apply the device state before executing a draw call.

Matteo Bruni matteo.mystral at gmail.com
Wed Jan 22 09:51:24 CST 2020


On Wed, Dec 11, 2019 at 4:46 AM Zebediah Figura <z.figura12 at gmail.com> wrote:
>
> Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
> ---
>  dlls/d3d9/device.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
> index 82fba25ce7..be9c2a9d5a 100644
> --- a/dlls/d3d9/device.c
> +++ b/dlls/d3d9/device.c
> @@ -1821,6 +1821,7 @@ static HRESULT WINAPI d3d9_device_ColorFill(IDirect3DDevice9Ex *iface,
>          return D3DERR_INVALIDCALL;
>      }
>
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      rtv = d3d9_surface_acquire_rendertarget_view(surface_impl);
>      hr = wined3d_device_clear_rendertarget_view(device->wined3d_device,
>              rtv, rect, WINED3DCLEAR_TARGET, &c, 0.0f, 0);
> @@ -2071,6 +2072,7 @@ static HRESULT WINAPI d3d9_device_Clear(IDirect3DDevice9Ex *iface, DWORD rect_co
>
>      wined3d_color_from_d3dcolor(&c, color);
>      wined3d_mutex_lock();
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
>      if (SUCCEEDED(hr))
>          d3d9_rts_flag_auto_gen_mipmap(device);
> @@ -2654,6 +2656,7 @@ static HRESULT WINAPI d3d9_device_ValidateDevice(IDirect3DDevice9Ex *iface, DWOR
>      TRACE("iface %p, pass_count %p.\n", iface, pass_count);
>
>      wined3d_mutex_lock();
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
>      wined3d_mutex_unlock();
>
> @@ -2885,6 +2888,7 @@ static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
>          WARN("Called without a valid vertex declaration set.\n");
>          return D3DERR_INVALIDCALL;
>      }
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      vertex_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
>      d3d9_device_upload_sysmem_vertex_buffers(device, 0, start_vertex, vertex_count);
>      d3d9_generate_auto_mipmaps(device);
> @@ -2917,6 +2921,7 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface
>          WARN("Called without a valid vertex declaration set.\n");
>          return D3DERR_INVALIDCALL;
>      }
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      index_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
>      d3d9_device_upload_sysmem_vertex_buffers(device, base_vertex_idx, min_vertex_idx, vertex_count);
>      d3d9_device_upload_sysmem_index_buffer(device, start_idx, index_count);
> @@ -3003,6 +3008,7 @@ static HRESULT WINAPI d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex *iface,
>          return D3DERR_INVALIDCALL;
>      }
>
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      hr = d3d9_device_prepare_vertex_buffer(device, size);
>      if (FAILED(hr))
>          goto done;
> @@ -3119,6 +3125,7 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *ifa
>          return D3DERR_INVALIDCALL;
>      }
>
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
>      hr = d3d9_device_prepare_vertex_buffer(device, vtx_size);
>      if (FAILED(hr))
>          goto done;
> @@ -3203,6 +3210,8 @@ static HRESULT WINAPI d3d9_device_ProcessVertices(IDirect3DDevice9Ex *iface,
>
>      wined3d_mutex_lock();
>
> +    wined3d_device_apply_stateblock(device->wined3d_device, device->state);
> +
>      /* Note that an alternative approach would be to simply create these
>       * buffers with WINED3D_RESOURCE_ACCESS_MAP_R and update them here like we
>       * do for draws. In some regards that would be easier, but it seems less
> --
> 2.24.0

FWIW, this looks more like it. We might want to improve
wined3d_device_apply_stateblock() before switching to it for all the
<= d3d9 applications to avoid performance regressions (if there are).
As an added benefit it might also help applications explicitly using
stateblocks. I have some WIP patches in the area.



More information about the wine-devel mailing list