Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/wined3d/device.c | 12 +++++++++++- dlls/wined3d/wined3d_private.h | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 7fef322e3d0..036ff8f81c6 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1060,6 +1060,7 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f}; const struct wined3d_swapchain_desc *swapchain_desc; DWORD clear_flags = 0; + unsigned int i; HRESULT hr;
TRACE("device %p, swapchain %p.\n", device, swapchain); @@ -1096,6 +1097,10 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str } device->swapchains[0] = swapchain;
+ for (i = 0; i < ARRAY_SIZE(device->state.fb.render_targets); ++i) + if (device->state.fb.render_targets[i]) + wined3d_dec_rtv_bind_count(device->state.fb.render_targets[i]); + memset(device->state.fb.render_targets, 0, sizeof(device->state.fb.render_targets)); if (FAILED(hr = device->adapter->adapter_ops->adapter_init_3d(device))) goto err_out; @@ -4873,13 +4878,19 @@ HRESULT CDECL wined3d_device_set_rendertarget_view(struct wined3d_device *device return WINED3D_OK;
if (view) + { wined3d_rendertarget_view_incref(view); + wined3d_inc_rtv_bind_count(view); + } device->state.fb.render_targets[view_idx] = view; wined3d_cs_emit_set_rendertarget_view(device->cs, view_idx, view); /* Release after the assignment, to prevent device_resource_released() * from seeing the surface as still in use. */ if (prev) + { + wined3d_dec_rtv_bind_count(prev); wined3d_rendertarget_view_decref(prev); + }
wined3d_unbind_srv_for_rtv(device, view, FALSE);
@@ -4912,7 +4923,6 @@ HRESULT CDECL wined3d_device_set_depth_stencil_view(struct wined3d_device *devic wined3d_cs_emit_set_depth_stencil_view(device->cs, view); if (prev) wined3d_rendertarget_view_decref(prev); - wined3d_unbind_srv_for_rtv(device, view, TRUE);
return WINED3D_OK; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 048c16663f4..147832ad771 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3954,6 +3954,7 @@ struct wined3d_resource LONG ref; LONG bind_count; LONG srv_bind_count_device; + LONG rtv_bind_count_device; LONG map_count; LONG access_count; struct wined3d_device *device; @@ -5999,23 +6000,24 @@ static inline BOOL wined3d_dsv_srv_conflict(const struct wined3d_rendertarget_vi static inline BOOL wined3d_resource_check_fbo_attached(const struct wined3d_state *state, const struct wined3d_resource *resource, const struct wined3d_format *srv_format) { - struct wined3d_rendertarget_view * const *rts = &state->fb.render_targets[0]; const struct wined3d_rendertarget_view *dsv; - unsigned int i;
if ((resource->bind_flags & WINED3D_BIND_DEPTH_STENCIL) && (dsv = state->fb.depth_stencil) && dsv->resource == resource && wined3d_dsv_srv_conflict(dsv, srv_format)) return TRUE;
- if (!(resource->bind_flags & WINED3D_BIND_RENDER_TARGET)) - return FALSE; + return resource->rtv_bind_count_device; +}
- for (i = 0; i < WINED3D_MAX_RENDER_TARGETS; ++i) - if (rts[i] && rts[i]->resource == resource) - return TRUE; +static inline void wined3d_inc_rtv_bind_count(struct wined3d_rendertarget_view *rt) +{ + ++rt->resource->rtv_bind_count_device; +}
- return FALSE; +static inline void wined3d_dec_rtv_bind_count(struct wined3d_rendertarget_view *rt) +{ + --rt->resource->rtv_bind_count_device; }
static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *vp, float *min_z, float *max_z)