Commit 87871e75 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Validate that the view resource has depth/stencil bind flags in…

wined3d: Validate that the view resource has depth/stencil bind flags in wined3d_device_set_depth_stencil_view(). Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 081602c4
...@@ -1438,12 +1438,15 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface, ...@@ -1438,12 +1438,15 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
original_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device); original_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device);
rtv = ds_impl ? d3d8_surface_acquire_rendertarget_view(ds_impl) : NULL; rtv = ds_impl ? d3d8_surface_acquire_rendertarget_view(ds_impl) : NULL;
wined3d_device_set_depth_stencil_view(device->wined3d_device, rtv); hr = wined3d_device_set_depth_stencil_view(device->wined3d_device, rtv);
d3d8_surface_release_rendertarget_view(ds_impl, rtv); d3d8_surface_release_rendertarget_view(ds_impl, rtv);
rtv = render_target ? d3d8_surface_acquire_rendertarget_view(rt_impl) : NULL; if (SUCCEEDED(hr))
if (render_target && FAILED(hr = wined3d_device_set_rendertarget_view(device->wined3d_device, 0, rtv, TRUE))) {
wined3d_device_set_depth_stencil_view(device->wined3d_device, original_dsv); rtv = render_target ? d3d8_surface_acquire_rendertarget_view(rt_impl) : NULL;
d3d8_surface_release_rendertarget_view(rt_impl, rtv); if (render_target && FAILED(hr = wined3d_device_set_rendertarget_view(device->wined3d_device, 0, rtv, TRUE)))
wined3d_device_set_depth_stencil_view(device->wined3d_device, original_dsv);
d3d8_surface_release_rendertarget_view(rt_impl, rtv);
}
wined3d_mutex_unlock(); wined3d_mutex_unlock();
......
...@@ -9069,9 +9069,8 @@ static void test_resource_access(void) ...@@ -9069,9 +9069,8 @@ static void test_resource_access(void)
ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr); ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, surface); hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, surface);
todo_wine_if(!(surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL)) ok(hr == (surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL ? D3D_OK : D3DERR_INVALIDCALL),
ok(hr == (surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL ? D3D_OK : D3DERR_INVALIDCALL), "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
"Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil); hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr); ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
......
...@@ -1903,16 +1903,17 @@ static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *ifa ...@@ -1903,16 +1903,17 @@ static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *ifa
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct d3d9_surface *ds_impl = unsafe_impl_from_IDirect3DSurface9(depth_stencil); struct d3d9_surface *ds_impl = unsafe_impl_from_IDirect3DSurface9(depth_stencil);
struct wined3d_rendertarget_view *rtv; struct wined3d_rendertarget_view *rtv;
HRESULT hr;
TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil); TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
wined3d_mutex_lock(); wined3d_mutex_lock();
rtv = ds_impl ? d3d9_surface_acquire_rendertarget_view(ds_impl) : NULL; rtv = ds_impl ? d3d9_surface_acquire_rendertarget_view(ds_impl) : NULL;
wined3d_device_set_depth_stencil_view(device->wined3d_device, rtv); hr = wined3d_device_set_depth_stencil_view(device->wined3d_device, rtv);
d3d9_surface_release_rendertarget_view(ds_impl, rtv); d3d9_surface_release_rendertarget_view(ds_impl, rtv);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return D3D_OK; return hr;
} }
static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 **depth_stencil) static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 **depth_stencil)
......
...@@ -12902,9 +12902,8 @@ static void test_resource_access(void) ...@@ -12902,9 +12902,8 @@ static void test_resource_access(void)
ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr); ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
hr = IDirect3DDevice9_SetDepthStencilSurface(device, surface); hr = IDirect3DDevice9_SetDepthStencilSurface(device, surface);
todo_wine_if(!(surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL)) ok(hr == (surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL ? D3D_OK : D3DERR_INVALIDCALL),
ok(hr == (surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL ? D3D_OK : D3DERR_INVALIDCALL), "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
"Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
hr = IDirect3DDevice9_SetDepthStencilSurface(device, depth_stencil); hr = IDirect3DDevice9_SetDepthStencilSurface(device, depth_stencil);
ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr); ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
......
...@@ -4504,17 +4504,25 @@ HRESULT CDECL wined3d_device_set_rendertarget_view(struct wined3d_device *device ...@@ -4504,17 +4504,25 @@ HRESULT CDECL wined3d_device_set_rendertarget_view(struct wined3d_device *device
return WINED3D_OK; return WINED3D_OK;
} }
void CDECL wined3d_device_set_depth_stencil_view(struct wined3d_device *device, struct wined3d_rendertarget_view *view) HRESULT CDECL wined3d_device_set_depth_stencil_view(struct wined3d_device *device,
struct wined3d_rendertarget_view *view)
{ {
struct wined3d_rendertarget_view *prev; struct wined3d_rendertarget_view *prev;
TRACE("device %p, view %p.\n", device, view); TRACE("device %p, view %p.\n", device, view);
if (view && !(view->resource->bind_flags & WINED3D_BIND_DEPTH_STENCIL))
{
WARN("View resource %p has incompatible %s bind flags.\n",
view->resource, wined3d_debug_bind_flags(view->resource->bind_flags));
return WINED3DERR_INVALIDCALL;
}
prev = device->fb.depth_stencil; prev = device->fb.depth_stencil;
if (prev == view) if (prev == view)
{ {
TRACE("Trying to do a NOP SetRenderTarget operation.\n"); TRACE("Trying to do a NOP SetRenderTarget operation.\n");
return; return WINED3D_OK;
} }
if ((device->fb.depth_stencil = view)) if ((device->fb.depth_stencil = view))
...@@ -4522,6 +4530,8 @@ void CDECL wined3d_device_set_depth_stencil_view(struct wined3d_device *device, ...@@ -4522,6 +4530,8 @@ void CDECL wined3d_device_set_depth_stencil_view(struct wined3d_device *device,
wined3d_cs_emit_set_depth_stencil_view(device->cs, view); wined3d_cs_emit_set_depth_stencil_view(device->cs, view);
if (prev) if (prev)
wined3d_rendertarget_view_decref(prev); wined3d_rendertarget_view_decref(prev);
return WINED3D_OK;
} }
static struct wined3d_texture *wined3d_device_create_cursor_texture(struct wined3d_device *device, static struct wined3d_texture *wined3d_device_create_cursor_texture(struct wined3d_device *device,
......
...@@ -2399,7 +2399,7 @@ void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device, ...@@ -2399,7 +2399,7 @@ void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device,
int x_screen_space, int y_screen_space, DWORD flags); int x_screen_space, int y_screen_space, DWORD flags);
HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device, HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device,
UINT x_hotspot, UINT y_hotspot, struct wined3d_texture *texture, unsigned int sub_resource_idx); UINT x_hotspot, UINT y_hotspot, struct wined3d_texture *texture, unsigned int sub_resource_idx);
void __cdecl wined3d_device_set_depth_stencil_view(struct wined3d_device *device, HRESULT __cdecl wined3d_device_set_depth_stencil_view(struct wined3d_device *device,
struct wined3d_rendertarget_view *view); struct wined3d_rendertarget_view *view);
HRESULT __cdecl wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs); HRESULT __cdecl wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs);
void __cdecl wined3d_device_set_domain_shader(struct wined3d_device *device, struct wined3d_shader *shader); void __cdecl wined3d_device_set_domain_shader(struct wined3d_device *device, struct wined3d_shader *shader);
......
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