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)
Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/wined3d/context.c | 3 ++- dlls/wined3d/device.c | 5 ++++- dlls/wined3d/wined3d_private.h | 13 ------------- 3 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 3a263e1f6bd..08c6e27922c 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -347,7 +347,8 @@ static void context_preload_texture(struct wined3d_context *context, if (!(texture = state->textures[idx])) return;
- if (wined3d_resource_check_fbo_attached(state, &texture->resource, NULL)) + if (texture->resource.rtv_bind_count_device || (state->fb.depth_stencil + && state->fb.depth_stencil->resource == &texture->resource)) context->uses_fbo_attached_resources = 1;
wined3d_texture_load(texture, context, is_srgb_enabled(state->sampler_states[idx])); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 036ff8f81c6..8327ef17dc8 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1952,6 +1952,7 @@ struct wined3d_buffer * CDECL wined3d_device_get_constant_buffer(const struct wi static void wined3d_device_set_shader_resource_view(struct wined3d_device *device, enum wined3d_shader_type type, UINT idx, struct wined3d_shader_resource_view *view) { + const struct wined3d_rendertarget_view *dsv; struct wined3d_shader_resource_view *prev;
if (idx >= MAX_SHADER_RESOURCE_VIEWS) @@ -1964,7 +1965,9 @@ static void wined3d_device_set_shader_resource_view(struct wined3d_device *devic if (view == prev) return;
- if (view && wined3d_resource_check_fbo_attached(&device->state, view->resource, view->format)) + if (view && (view->resource->rtv_bind_count_device + || ((dsv = device->state.fb.depth_stencil) + && dsv->resource == view->resource && wined3d_dsv_srv_conflict(dsv, view->format)))) { WARN("Application is trying to bind resource which is attached as render target.\n"); view = NULL; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 147832ad771..05ac6949ca3 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -5997,19 +5997,6 @@ static inline BOOL wined3d_dsv_srv_conflict(const struct wined3d_rendertarget_vi || (srv_format->green_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_STENCIL)); }
-static inline BOOL wined3d_resource_check_fbo_attached(const struct wined3d_state *state, - const struct wined3d_resource *resource, const struct wined3d_format *srv_format) -{ - const struct wined3d_rendertarget_view *dsv; - - 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; - - return resource->rtv_bind_count_device; -} - static inline void wined3d_inc_rtv_bind_count(struct wined3d_rendertarget_view *rt) { ++rt->resource->rtv_bind_count_device;
Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 70 ++++++++++++++++++++++--- dlls/wined3d/device.c | 30 +++++++++-- dlls/wined3d/stateblock.c | 2 +- dlls/wined3d/wined3d_private.h | 96 ++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 12 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 67d843ae9e5..afdb3a085c7 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -29453,12 +29453,13 @@ static void test_desktop_window(void)
static void test_sample_attached_rtv(void) { - ID3D11ShaderResourceView *srv, *srv_test, *srv_ds; + ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds; + D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc; ID3D11Texture2D *texture, *texture2, *dstexture; - D3D11_SHADER_RESOURCE_VIEW_DESC srvds_desc; + ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2]; D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc; struct d3d11_test_context test_context; - ID3D11RenderTargetView *rtv, *rtvs[2]; + D3D11_RENDER_TARGET_VIEW_DESC rtv_desc; D3D11_TEXTURE2D_DESC texture_desc; D3D_FEATURE_LEVEL feature_level; D3D11_SAMPLER_DESC sampler_desc; @@ -29472,6 +29473,7 @@ static void test_sample_attached_rtv(void) ID3D11Device *device; unsigned int x, y; unsigned int i; + D3D11_BOX box; DWORD color; HRESULT hr;
@@ -29574,7 +29576,7 @@ static void test_sample_attached_rtv(void)
texture_desc.Width = 64; texture_desc.Height = 64; - texture_desc.MipLevels = 1; + texture_desc.MipLevels = 2; texture_desc.ArraySize = 1; texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
@@ -29598,7 +29600,15 @@ static void test_sample_attached_rtv(void)
ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
- hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, NULL, &rtv); + memset(&rtv_desc, 0, sizeof(rtv_desc)); + rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + U(rtv_desc).Texture2D.MipSlice = 0; + + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + U(rtv_desc).Texture2D.MipSlice = 1; + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
rtvs[0] = test_context.backbuffer_rtv; @@ -29606,12 +29616,20 @@ static void test_sample_attached_rtv(void)
ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
- hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv); + memset(&srv_desc, 0, sizeof(srv_desc)); + srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + U(srv_desc).Texture2D.MipLevels = 1; + + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
draw_quad(&test_context);
+ set_box(&box, 0, 0, 0, 320, 240, 1); + ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box); + get_texture_readback(texture2, 0, &rb); for (y = 0; y < 4; ++y) { @@ -29623,12 +29641,29 @@ static void test_sample_attached_rtv(void) } } release_resource_readback(&rb); + get_texture_readback(texture2, 1, &rb); + for (y = 0; y < 4; ++y) + { + for (x = 0; x < 4; ++x) + { + color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0); + ok(compare_color(color, 0x40404040, 2), + "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y); + } + } + release_resource_readback(&rb);
ID3D11ShaderResourceView_Release(srv); + ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
- hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, NULL, &srv); + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + + U(srv_desc).Texture2D.MostDetailedMip = 1; + U(srv_desc).Texture2D.MipLevels = 1; + hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
memset(&blend_desc, 0, sizeof(blend_desc)); @@ -29705,6 +29740,25 @@ static void test_sample_attached_rtv(void) ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test); ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
+ ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2); + ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL); + ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test); + ok(!!srv_test, "Unexpected SRV %p.\n", srv_test); + ID3D11ShaderResourceView_Release(srv_test); + + draw_quad(&test_context); + get_texture_readback(test_context.backbuffer, 0, &rb); + for (y = 0; y < 4; ++y) + { + for (x = 0; x < 4; ++x) + { + color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0); + ok(compare_color(color, 0x80808080, 2), + "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y); + } + } + release_resource_readback(&rb); + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL; memset(&dsview_desc, 0, sizeof(dsview_desc)); dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; @@ -29762,7 +29816,9 @@ static void test_sample_attached_rtv(void)
ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
+ ID3D11RenderTargetView_Release(rtv2); ID3D11RenderTargetView_Release(rtv); + ID3D11ShaderResourceView_Release(srv2); ID3D11ShaderResourceView_Release(srv); ID3D11SamplerState_Release(sampler); ID3D11PixelShader_Release(ps); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 8327ef17dc8..6828c20acc0 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1965,7 +1965,7 @@ static void wined3d_device_set_shader_resource_view(struct wined3d_device *devic if (view == prev) return;
- if (view && (view->resource->rtv_bind_count_device + if (view && (wined3d_is_srv_rtv_bound(view) || ((dsv = device->state.fb.depth_stencil) && dsv->resource == view->resource && wined3d_dsv_srv_conflict(dsv, view->format)))) { @@ -1976,14 +1976,14 @@ static void wined3d_device_set_shader_resource_view(struct wined3d_device *devic if (view) { wined3d_shader_resource_view_incref(view); - ++view->resource->srv_bind_count_device; + wined3d_inc_srv_bind_count(view); }
device->state.shader_resource_view[type][idx] = view; wined3d_cs_emit_set_shader_resource_view(device->cs, type, idx, view); if (prev) { - --prev->resource->srv_bind_count_device; + wined3d_dec_srv_bind_count(prev); wined3d_shader_resource_view_decref(prev); } } @@ -4817,19 +4817,41 @@ struct wined3d_rendertarget_view * CDECL wined3d_device_get_depth_stencil_view(c static void wined3d_unbind_srv_for_rtv(struct wined3d_device *device, const struct wined3d_rendertarget_view *view, BOOL dsv) { - if (view && view->resource->srv_bind_count_device) + if (view && wined3d_is_rtv_srv_bound(view)) { const struct wined3d_resource *resource = view->resource; const struct wined3d_shader_resource_view *srv; + unsigned int level, start_layer, layer_count; unsigned int i, j;
WARN("Application sets bound resource as render target.\n");
+ if (resource->type != WINED3D_RTYPE_BUFFER) + { + struct wined3d_texture *texture = texture_from_resource(view->resource); + + level = view->sub_resource_idx % texture->level_count; + start_layer = view->sub_resource_idx / texture->level_count; + layer_count = view->layer_count; + } + else + { + level = start_layer = layer_count = 0; + } + for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i) for (j = 0; j < MAX_SHADER_RESOURCE_VIEWS; ++j) if ((srv = device->state.shader_resource_view[i][j]) && srv->resource == resource && (!dsv || wined3d_dsv_srv_conflict(view, srv->format))) + { + if (resource->type != WINED3D_RTYPE_BUFFER && (level < srv->desc.u.texture.level_idx + || level >= srv->desc.u.texture.level_idx + srv->desc.u.texture.level_count + || start_layer >= srv->desc.u.texture.layer_idx + srv->desc.u.texture.layer_count + || start_layer + layer_count <= srv->desc.u.texture.layer_idx)) + continue; + wined3d_device_set_shader_resource_view(device, i, j, NULL); + } } }
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index e7deb2464db..e83f43dd354 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -450,7 +450,7 @@ void state_unbind_resources(struct wined3d_state *state) if ((srv = state->shader_resource_view[i][j])) { state->shader_resource_view[i][j] = NULL; - --srv->resource->srv_bind_count_device; + wined3d_dec_srv_bind_count(srv); wined3d_shader_resource_view_decref(srv); } } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 05ac6949ca3..f895da00d63 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4152,6 +4152,8 @@ struct wined3d_texture struct wined3d_bo_gl bo;
void *user_memory; + LONG srv_bind_count_device; + LONG rtv_bind_count_device; } *sub_resources; };
@@ -5997,14 +5999,108 @@ static inline BOOL wined3d_dsv_srv_conflict(const struct wined3d_rendertarget_vi || (srv_format->green_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_STENCIL)); }
+static inline void wined3d_inc_srv_bind_count(struct wined3d_shader_resource_view *srv) +{ + struct wined3d_texture *texture; + unsigned int level, layer; + + ++srv->resource->srv_bind_count_device; + + if (srv->resource->type == WINED3D_RTYPE_BUFFER) + return; + + texture = texture_from_resource(srv->resource); + + for (layer = 0; layer < srv->desc.u.texture.layer_count; ++layer) + for (level = 0; level < srv->desc.u.texture.level_count; ++level) + ++texture->sub_resources[(layer + srv->desc.u.texture.layer_idx) * texture->level_count + + srv->desc.u.texture.level_idx + level].srv_bind_count_device; +} + +static inline void wined3d_dec_srv_bind_count(struct wined3d_shader_resource_view *srv) +{ + struct wined3d_texture *texture; + unsigned int level, layer; + + --srv->resource->srv_bind_count_device; + + if (srv->resource->type == WINED3D_RTYPE_BUFFER) + return; + + texture = texture_from_resource(srv->resource); + + for (layer = 0; layer < srv->desc.u.texture.layer_count; ++layer) + for (level = 0; level < srv->desc.u.texture.level_count; ++level) + --texture->sub_resources[(layer + srv->desc.u.texture.layer_idx) * texture->level_count + + srv->desc.u.texture.level_idx + level].srv_bind_count_device; +} + static inline void wined3d_inc_rtv_bind_count(struct wined3d_rendertarget_view *rt) { + struct wined3d_texture *texture; + unsigned int layer; + ++rt->resource->rtv_bind_count_device; + + if (rt->resource->type == WINED3D_RTYPE_BUFFER) + return; + + texture = texture_from_resource(rt->resource); + + for (layer = 0; layer < rt->layer_count; ++layer) + ++texture->sub_resources[rt->sub_resource_idx + layer * texture->level_count].rtv_bind_count_device; }
static inline void wined3d_dec_rtv_bind_count(struct wined3d_rendertarget_view *rt) { + struct wined3d_texture *texture; + unsigned int layer; + --rt->resource->rtv_bind_count_device; + + if (rt->resource->type == WINED3D_RTYPE_BUFFER) + return; + + texture = texture_from_resource(rt->resource); + + for (layer = 0; layer < rt->layer_count; ++layer) + --texture->sub_resources[rt->sub_resource_idx + layer * texture->level_count].rtv_bind_count_device; +} + +static inline BOOL wined3d_is_srv_rtv_bound(const struct wined3d_shader_resource_view *srv) +{ + struct wined3d_texture *texture; + unsigned int level, layer; + + if (!srv->resource->rtv_bind_count_device || srv->resource->type == WINED3D_RTYPE_BUFFER) + return srv->resource->rtv_bind_count_device; + + texture = texture_from_resource(srv->resource); + + for (layer = 0; layer < srv->desc.u.texture.layer_count; ++layer) + for (level = 0; level < srv->desc.u.texture.level_count; ++level) + if (texture->sub_resources[(layer + srv->desc.u.texture.layer_idx) * texture->level_count + + srv->desc.u.texture.level_idx + level].rtv_bind_count_device) + return TRUE; + + return FALSE; +} + +static inline BOOL wined3d_is_rtv_srv_bound(const struct wined3d_rendertarget_view *rt) +{ + struct wined3d_texture *texture; + unsigned int layer; + + if (!rt->resource->srv_bind_count_device || rt->resource->type == WINED3D_RTYPE_BUFFER) + return rt->resource->srv_bind_count_device; + + texture = texture_from_resource(rt->resource); + + for (layer = 0; layer < rt->layer_count; ++layer) + if (texture->sub_resources[rt->sub_resource_idx + layer * texture->level_count].srv_bind_count_device) + return TRUE; + + return FALSE; }
static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *vp, float *min_z, float *max_z)
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=79159
Your paranoid android.
=== w10pro64_2scr (32 bit report) ===
d3d11: d3d11.c:5804: Test failed: Got unexpected IAVertices count: 0. d3d11.c:5805: Test failed: Got unexpected IAPrimitives count: 0. d3d11.c:5806: Test failed: Got unexpected VSInvocations count: 0. d3d11.c:5809: Test failed: Got unexpected CInvocations count: 0. d3d11.c:5810: Test failed: Got unexpected CPrimitives count: 0.
=== debiant (build log) ===
Task: WineTest did not produce the wow32 report