Commit 1124edd2 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3d11: Fail OMSetRenderTargets() if any of the views have the wrong binding flags.

parent 086212ba
......@@ -1071,29 +1071,33 @@ static void STDMETHODCALLTYPE d3d11_device_context_GSSetSamplers(ID3D11DeviceCon
}
static void STDMETHODCALLTYPE d3d11_device_context_OMSetRenderTargets(ID3D11DeviceContext1 *iface,
UINT render_target_view_count, ID3D11RenderTargetView *const *render_target_views,
ID3D11DepthStencilView *depth_stencil_view)
UINT rtv_count, ID3D11RenderTargetView *const *rtvs, ID3D11DepthStencilView *depth_stencil_view)
{
struct wined3d_rendertarget_view *wined3d_rtvs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
struct d3d11_device_context *context = impl_from_ID3D11DeviceContext1(iface);
struct d3d_depthstencil_view *dsv;
unsigned int i;
TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
iface, render_target_view_count, render_target_views, depth_stencil_view);
TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
wined3d_mutex_lock();
for (i = 0; i < render_target_view_count; ++i)
if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
{
struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(render_target_views[i]);
wined3d_device_context_set_rendertarget_view(context->wined3d_context, i,
rtv ? rtv->wined3d_view : NULL, FALSE);
WARN("View count %u exceeds limit.\n", rtv_count);
rtv_count = ARRAY_SIZE(wined3d_rtvs);
}
for (; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
for (i = 0; i < rtv_count; ++i)
{
wined3d_device_context_set_rendertarget_view(context->wined3d_context, i, NULL, FALSE);
struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D11RenderTargetView(rtvs[i]);
wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
}
dsv = unsafe_impl_from_ID3D11DepthStencilView(depth_stencil_view);
wined3d_mutex_lock();
wined3d_device_context_set_rendertarget_views(context->wined3d_context, 0,
ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, FALSE);
wined3d_device_context_set_depth_stencil_view(context->wined3d_context, dsv ? dsv->wined3d_view : NULL);
wined3d_mutex_unlock();
}
......@@ -4873,30 +4877,33 @@ static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
}
static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
ID3D10DepthStencilView *depth_stencil_view)
UINT rtv_count, ID3D10RenderTargetView *const *rtvs, ID3D10DepthStencilView *depth_stencil_view)
{
struct wined3d_rendertarget_view *wined3d_rtvs[D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0};
struct d3d_device *device = impl_from_ID3D10Device(iface);
struct d3d_depthstencil_view *dsv;
unsigned int i;
TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
iface, render_target_view_count, render_target_views, depth_stencil_view);
TRACE("iface %p, rtv_count %u, rtvs %p, depth_stencil_view %p.\n", iface, rtv_count, rtvs, depth_stencil_view);
wined3d_mutex_lock();
for (i = 0; i < render_target_view_count; ++i)
if (rtv_count > ARRAY_SIZE(wined3d_rtvs))
{
struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i,
rtv ? rtv->wined3d_view : NULL, FALSE);
WARN("View count %u exceeds limit.\n", rtv_count);
rtv_count = ARRAY_SIZE(wined3d_rtvs);
}
for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
for (i = 0; i < rtv_count; ++i)
{
wined3d_device_context_set_rendertarget_view(device->immediate_context.wined3d_context, i, NULL, FALSE);
struct d3d_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(rtvs[i]);
wined3d_rtvs[i] = rtv ? rtv->wined3d_view : NULL;
}
dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
wined3d_mutex_lock();
wined3d_device_context_set_rendertarget_views(device->immediate_context.wined3d_context, 0,
ARRAY_SIZE(wined3d_rtvs), wined3d_rtvs, FALSE);
wined3d_device_context_set_depth_stencil_view(device->immediate_context.wined3d_context,
dsv ? dsv->wined3d_view : NULL);
wined3d_mutex_unlock();
......
......@@ -1544,7 +1544,8 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
rtv = render_target ? d3d8_surface_acquire_rendertarget_view(rt_impl) : NULL;
if (render_target)
{
if (SUCCEEDED(hr = wined3d_device_context_set_rendertarget_view(device->immediate_context, 0, rtv, TRUE)))
if (SUCCEEDED(hr = wined3d_device_context_set_rendertarget_views(device->immediate_context,
0, 1, &rtv, TRUE)))
device_reset_viewport_state(device);
else
wined3d_device_context_set_depth_stencil_view(device->immediate_context, original_dsv);
......
......@@ -2028,7 +2028,7 @@ static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWO
wined3d_mutex_lock();
rtv = surface_impl ? d3d9_surface_acquire_rendertarget_view(surface_impl) : NULL;
hr = wined3d_device_context_set_rendertarget_view(device->immediate_context, idx, rtv, TRUE);
hr = wined3d_device_context_set_rendertarget_views(device->immediate_context, idx, 1, &rtv, TRUE);
d3d9_surface_release_rendertarget_view(surface_impl, rtv);
if (SUCCEEDED(hr))
{
......
......@@ -958,7 +958,7 @@ static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window,
if (rtv)
{
wined3d_device_context_set_rendertarget_view(ddraw->immediate_context, 0, rtv, FALSE);
wined3d_device_context_set_rendertarget_views(ddraw->immediate_context, 0, 1, &rtv, FALSE);
wined3d_rendertarget_view_decref(rtv);
}
......
......@@ -270,6 +270,7 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
* wined3d device when the render target is released. */
if (!ref)
{
static struct wined3d_rendertarget_view *const null_rtv;
DWORD i;
struct list *vp_entry, *vp_entry2;
......@@ -283,7 +284,7 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
if (This->vertex_buffer)
wined3d_buffer_decref(This->vertex_buffer);
wined3d_device_context_set_rendertarget_view(This->immediate_context, 0, NULL, FALSE);
wined3d_device_context_set_rendertarget_views(This->immediate_context, 0, 1, &null_rtv, FALSE);
wined3d_stateblock_decref(This->state);
if (This->recording)
......@@ -1848,6 +1849,7 @@ static BOOL validate_surface_palette(struct ddraw_surface *surface)
static HRESULT d3d_device_set_render_target(struct d3d_device *device,
struct ddraw_surface *target, IUnknown *rt_iface)
{
struct wined3d_rendertarget_view *rtv;
HRESULT hr;
if (device->rt_iface == rt_iface)
......@@ -1861,8 +1863,8 @@ static HRESULT d3d_device_set_render_target(struct d3d_device *device,
return DDERR_INVALIDPARAMS;
}
if (FAILED(hr = wined3d_device_context_set_rendertarget_view(device->immediate_context,
0, ddraw_surface_get_rendertarget_view(target), FALSE)))
rtv = ddraw_surface_get_rendertarget_view(target);
if (FAILED(hr = wined3d_device_context_set_rendertarget_views(device->immediate_context, 0, 1, &rtv, FALSE)))
return hr;
IUnknown_AddRef(rt_iface);
......@@ -6994,6 +6996,7 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw, c
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
struct wined3d_rendertarget_view *rtv;
HRESULT hr;
if (ddraw->cooperative_level & DDSCL_FPUPRESERVE)
......@@ -7043,8 +7046,8 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw, c
wined3d_stateblock_incref(ddraw->state);
/* Render to the back buffer */
if (FAILED(hr = wined3d_device_context_set_rendertarget_view(device->immediate_context,
0, ddraw_surface_get_rendertarget_view(target), TRUE)))
rtv = ddraw_surface_get_rendertarget_view(target);
if (FAILED(hr = wined3d_device_context_set_rendertarget_views(device->immediate_context, 0, 1, &rtv, TRUE)))
{
ERR("Failed to set render target, hr %#x.\n", hr);
wined3d_stateblock_decref(device->state);
......
......@@ -1369,7 +1369,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface1_Flip(IDirectDrawSurface *
src_rtv = ddraw_surface_get_rendertarget_view(src_impl);
if (rtv == dst_impl->wined3d_rtv)
wined3d_device_context_set_rendertarget_view(dst_impl->ddraw->immediate_context, 0, src_rtv, FALSE);
wined3d_device_context_set_rendertarget_views(dst_impl->ddraw->immediate_context, 0, 1, &src_rtv, FALSE);
wined3d_rendertarget_view_set_parent(src_rtv, dst_impl);
dst_impl->wined3d_rtv = src_rtv;
wined3d_texture_set_sub_resource_parent(src_impl->wined3d_texture, 0, dst_impl);
......@@ -1406,7 +1406,8 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface1_Flip(IDirectDrawSurface *
src_impl = impl_from_IDirectDrawSurface(current);
src_rtv = ddraw_surface_get_rendertarget_view(src_impl);
if (rtv == dst_impl->wined3d_rtv)
wined3d_device_context_set_rendertarget_view(dst_impl->ddraw->immediate_context, 0, src_rtv, FALSE);
wined3d_device_context_set_rendertarget_views(dst_impl->ddraw->immediate_context,
0, 1, &src_rtv, FALSE);
wined3d_rendertarget_view_set_parent(src_rtv, dst_impl);
dst_impl->wined3d_rtv = src_rtv;
wined3d_texture_set_sub_resource_parent(src_impl->wined3d_texture, 0, dst_impl);
......@@ -1429,7 +1430,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH ddraw_surface1_Flip(IDirectDrawSurface *
/* We don't have to worry about potential texture bindings, since
* flippable surfaces can never be textures. */
if (rtv == src_impl->wined3d_rtv)
wined3d_device_context_set_rendertarget_view(dst_impl->ddraw->immediate_context, 0, tmp_rtv, FALSE);
wined3d_device_context_set_rendertarget_views(dst_impl->ddraw->immediate_context, 0, 1, &tmp_rtv, FALSE);
wined3d_rendertarget_view_set_parent(tmp_rtv, src_impl);
src_impl->wined3d_rtv = tmp_rtv;
wined3d_texture_set_sub_resource_parent(texture, 0, src_impl);
......
......@@ -932,16 +932,14 @@ void CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
static void device_init_swapchain_state(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
{
struct wined3d_rendertarget_view *views[WINED3D_MAX_RENDER_TARGETS] = {0};
BOOL ds_enable = swapchain->state.desc.enable_auto_depth_stencil;
struct wined3d_device_context *context = &device->cs->c;
unsigned int i;
for (i = 0; i < device->adapter->d3d_info.limits.max_rt_count; ++i)
{
wined3d_device_context_set_rendertarget_view(context, i, NULL, FALSE);
}
if (device->back_buffer_view)
wined3d_device_context_set_rendertarget_view(context, 0, device->back_buffer_view, TRUE);
views[0] = device->back_buffer_view;
wined3d_device_context_set_rendertarget_views(context, 0,
device->adapter->d3d_info.limits.max_rt_count, views, !!device->back_buffer_view);
wined3d_device_context_set_depth_stencil_view(context, ds_enable ? device->auto_depth_stencil_view : NULL);
}
......@@ -2099,68 +2097,76 @@ static void wined3d_device_context_unbind_srv_for_rtv(struct wined3d_device_cont
}
}
HRESULT CDECL wined3d_device_context_set_rendertarget_view(struct wined3d_device_context *context,
unsigned int view_idx, struct wined3d_rendertarget_view *view, BOOL set_viewport)
HRESULT CDECL wined3d_device_context_set_rendertarget_views(struct wined3d_device_context *context,
unsigned int start_idx, unsigned int count, struct wined3d_rendertarget_view *const *views, BOOL set_viewport)
{
struct wined3d_state *state = context->state;
struct wined3d_rendertarget_view *prev;
unsigned int max_rt_count;
unsigned int i, max_rt_count;
TRACE("context %p, view_idx %u, view %p, set_viewport %#x.\n",
context, view_idx, view, set_viewport);
TRACE("context %p, start_idx %u, count %u, views %p, set_viewport %#x.\n",
context, start_idx, count, views, set_viewport);
max_rt_count = context->device->adapter->d3d_info.limits.max_rt_count;
if (view_idx >= max_rt_count)
if (start_idx >= max_rt_count)
{
WARN("Only %u render targets are supported.\n", max_rt_count);
return WINED3DERR_INVALIDCALL;
}
count = min(count, max_rt_count - start_idx);
if (view && !(view->resource->bind_flags & WINED3D_BIND_RENDER_TARGET))
for (i = 0; i < count; ++i)
{
WARN("View resource %p doesn't have render target bind flags.\n", view->resource);
return WINED3DERR_INVALIDCALL;
if (views[i] && !(views[i]->resource->bind_flags & WINED3D_BIND_RENDER_TARGET))
{
WARN("View resource %p doesn't have render target bind flags.\n", views[i]->resource);
return WINED3DERR_INVALIDCALL;
}
}
/* Set the viewport and scissor rectangles, if requested. Tests show that
* stateblock recording is ignored, the change goes directly into the
* primary stateblock. */
if (!view_idx && set_viewport)
if (!start_idx && set_viewport)
{
state->viewports[0].x = 0;
state->viewports[0].y = 0;
state->viewports[0].width = view->width;
state->viewports[0].height = view->height;
state->viewports[0].width = views[0]->width;
state->viewports[0].height = views[0]->height;
state->viewports[0].min_z = 0.0f;
state->viewports[0].max_z = 1.0f;
state->viewport_count = 1;
wined3d_device_context_emit_set_viewports(context, 1, state->viewports);
SetRect(&state->scissor_rects[0], 0, 0, view->width, view->height);
SetRect(&state->scissor_rects[0], 0, 0, views[0]->width, views[0]->height);
state->scissor_rect_count = 1;
wined3d_device_context_emit_set_scissor_rects(context, 1, state->scissor_rects);
}
prev = state->fb.render_targets[view_idx];
if (view == prev)
if (!memcmp(views, &state->fb.render_targets[start_idx], count * sizeof(*views)))
return WINED3D_OK;
if (view)
{
wined3d_rendertarget_view_incref(view);
wined3d_rtv_bind_count_inc(view);
}
state->fb.render_targets[view_idx] = view;
wined3d_device_context_emit_set_rendertarget_view(context, view_idx, view);
/* Release after the assignment, to prevent device_resource_released()
* from seeing the surface as still in use. */
if (prev)
for (i = 0; i < count; ++i)
{
wined3d_rtv_bind_count_dec(prev);
wined3d_rendertarget_view_decref(prev);
}
struct wined3d_rendertarget_view *prev = state->fb.render_targets[start_idx + i];
struct wined3d_rendertarget_view *view = views[i];
if (view)
{
wined3d_rendertarget_view_incref(view);
wined3d_rtv_bind_count_inc(view);
}
state->fb.render_targets[start_idx + i] = view;
wined3d_device_context_emit_set_rendertarget_view(context, start_idx + i, view);
/* Release after the assignment, to prevent device_resource_released()
* from seeing the resource as still in use. */
if (prev)
{
wined3d_rtv_bind_count_dec(prev);
wined3d_rendertarget_view_decref(prev);
}
wined3d_device_context_unbind_srv_for_rtv(context, view, FALSE);
wined3d_device_context_unbind_srv_for_rtv(context, view, FALSE);
}
return WINED3D_OK;
}
......@@ -5188,6 +5194,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
const struct wined3d_swapchain_desc *swapchain_desc, const struct wined3d_display_mode *mode,
wined3d_device_reset_cb callback, BOOL reset_state)
{
static struct wined3d_rendertarget_view *const views[WINED3D_MAX_RENDER_TARGETS];
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
struct wined3d_device_context *context = &device->cs->c;
struct wined3d_swapchain_state *swapchain_state;
......@@ -5229,10 +5236,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
state_unbind_resources(state);
}
for (i = 0; i < d3d_info->limits.max_rt_count; ++i)
{
wined3d_device_context_set_rendertarget_view(context, i, NULL, FALSE);
}
wined3d_device_context_set_rendertarget_views(context, 0, d3d_info->limits.max_rt_count, views, FALSE);
wined3d_device_context_set_depth_stencil_view(context, NULL);
if (reset_state)
......@@ -5455,7 +5459,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
else
{
if ((view = device->back_buffer_view))
wined3d_device_context_set_rendertarget_view(context, 0, view, FALSE);
wined3d_device_context_set_rendertarget_views(context, 0, 1, &view, FALSE);
if ((view = device->auto_depth_stencil_view))
wined3d_device_context_set_depth_stencil_view(context, view);
}
......
......@@ -130,7 +130,7 @@
@ cdecl wined3d_device_context_set_predication(ptr ptr long)
@ cdecl wined3d_device_context_set_primitive_type(ptr long long)
@ cdecl wined3d_device_context_set_rasterizer_state(ptr ptr)
@ cdecl wined3d_device_context_set_rendertarget_view(ptr long ptr long)
@ cdecl wined3d_device_context_set_rendertarget_views(ptr long long ptr long)
@ cdecl wined3d_device_context_set_samplers(ptr long long long ptr)
@ cdecl wined3d_device_context_set_scissor_rects(ptr long ptr)
@ cdecl wined3d_device_context_set_shader(ptr long ptr)
......
......@@ -2517,8 +2517,8 @@ void __cdecl wined3d_device_context_set_primitive_type(struct wined3d_device_con
enum wined3d_primitive_type primitive_topology, unsigned int patch_vertex_count);
void __cdecl wined3d_device_context_set_rasterizer_state(struct wined3d_device_context *context,
struct wined3d_rasterizer_state *rasterizer_state);
HRESULT __cdecl wined3d_device_context_set_rendertarget_view(struct wined3d_device_context *context,
unsigned int view_idx, struct wined3d_rendertarget_view *view, BOOL set_viewport);
HRESULT __cdecl wined3d_device_context_set_rendertarget_views(struct wined3d_device_context *context,
unsigned int start_idx, unsigned int count, struct wined3d_rendertarget_view *const *views, BOOL set_viewport);
void __cdecl wined3d_device_context_set_samplers(struct wined3d_device_context *context, enum wined3d_shader_type type,
unsigned int start_idx, unsigned int count, struct wined3d_sampler *const *samplers);
void __cdecl wined3d_device_context_set_scissor_rects(struct wined3d_device_context *context, unsigned int rect_count,
......
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