wined3d: Track SRV to RTV aliasing on sub resource level.
Signed-off-by: Paul Gofman <pgofman@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
774e4b2ea3
commit
61e02c5e4f
|
@ -29441,12 +29441,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;
|
||||
|
@ -29460,6 +29461,7 @@ static void test_sample_attached_rtv(void)
|
|||
ID3D11Device *device;
|
||||
unsigned int x, y;
|
||||
unsigned int i;
|
||||
D3D11_BOX box;
|
||||
DWORD color;
|
||||
HRESULT hr;
|
||||
|
||||
|
@ -29562,7 +29564,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;
|
||||
|
||||
|
@ -29586,7 +29588,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;
|
||||
|
@ -29594,12 +29604,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)
|
||||
{
|
||||
|
@ -29611,12 +29629,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));
|
||||
|
@ -29693,6 +29728,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;
|
||||
|
@ -29750,7 +29804,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);
|
||||
|
|
|
@ -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_srv_bind_count_inc(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_srv_bind_count_dec(prev);
|
||||
wined3d_shader_resource_view_decref(prev);
|
||||
}
|
||||
}
|
||||
|
@ -4793,7 +4793,7 @@ 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;
|
||||
|
@ -4804,7 +4804,8 @@ static void wined3d_unbind_srv_for_rtv(struct wined3d_device *device,
|
|||
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)))
|
||||
&& ((!dsv && wined3d_is_srv_rtv_bound(srv))
|
||||
|| (dsv && wined3d_dsv_srv_conflict(view, srv->format))))
|
||||
wined3d_device_set_shader_resource_view(device, i, j, NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,6 +233,7 @@ static void wined3d_resource_destroy_object(void *object)
|
|||
{
|
||||
struct wined3d_resource *resource = object;
|
||||
|
||||
heap_free(resource->sub_resource_bind_counts_device);
|
||||
wined3d_resource_free_sysmem(resource);
|
||||
context_resource_released(resource->device, resource);
|
||||
wined3d_resource_release(resource);
|
||||
|
|
|
@ -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_srv_bind_count_dec(srv);
|
||||
wined3d_shader_resource_view_decref(srv);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3932,6 +3932,9 @@ struct wined3d_resource_ops
|
|||
HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
|
||||
};
|
||||
|
||||
#define WINED3D_SUB_RESOURCES_BIND_SRV 1
|
||||
#define WINED3D_SUB_RESOURCES_BIND_RTV 2
|
||||
|
||||
struct wined3d_resource
|
||||
{
|
||||
LONG ref;
|
||||
|
@ -3964,6 +3967,14 @@ struct wined3d_resource
|
|||
const struct wined3d_resource_ops *resource_ops;
|
||||
|
||||
struct list resource_list_entry;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t srv;
|
||||
uint32_t rtv;
|
||||
}
|
||||
*sub_resource_bind_counts_device;
|
||||
uint32_t sub_resource_bind_flags;
|
||||
};
|
||||
|
||||
static inline ULONG wined3d_resource_incref(struct wined3d_resource *resource)
|
||||
|
@ -5973,14 +5984,168 @@ 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_srv_all_subresources(const struct wined3d_shader_resource_view *srv)
|
||||
{
|
||||
struct wined3d_texture *texture;
|
||||
|
||||
if (srv->resource->type == WINED3D_RTYPE_BUFFER)
|
||||
return TRUE;
|
||||
|
||||
if (srv->desc.u.texture.layer_idx || srv->desc.u.texture.level_idx)
|
||||
return FALSE;
|
||||
|
||||
texture = texture_from_resource(srv->resource);
|
||||
return srv->desc.u.texture.level_count == texture->level_count
|
||||
&& srv->desc.u.texture.layer_count == texture->layer_count;
|
||||
}
|
||||
|
||||
static inline bool wined3d_rtv_all_subresources(const struct wined3d_rendertarget_view *rtv)
|
||||
{
|
||||
struct wined3d_texture *texture;
|
||||
|
||||
if (rtv->resource->type == WINED3D_RTYPE_BUFFER)
|
||||
return TRUE;
|
||||
|
||||
if (rtv->sub_resource_idx)
|
||||
return FALSE;
|
||||
|
||||
texture = texture_from_resource(rtv->resource);
|
||||
return texture->level_count == 1 && rtv->layer_count == texture->layer_count;
|
||||
}
|
||||
|
||||
static inline void wined3d_srv_bind_count_inc(struct wined3d_shader_resource_view *srv)
|
||||
{
|
||||
struct wined3d_resource *resource = srv->resource;
|
||||
struct wined3d_texture *texture;
|
||||
unsigned int level, layer;
|
||||
|
||||
++resource->srv_bind_count_device;
|
||||
|
||||
if (wined3d_srv_all_subresources(srv))
|
||||
return;
|
||||
|
||||
texture = texture_from_resource(resource);
|
||||
|
||||
if (!resource->sub_resource_bind_counts_device
|
||||
&& !(resource->sub_resource_bind_counts_device = heap_alloc_zero(texture->level_count
|
||||
* texture->layer_count * sizeof(*resource->sub_resource_bind_counts_device))))
|
||||
return;
|
||||
|
||||
for (layer = 0; layer < srv->desc.u.texture.layer_count; ++layer)
|
||||
for (level = 0; level < srv->desc.u.texture.level_count; ++level)
|
||||
++resource->sub_resource_bind_counts_device[(layer + srv->desc.u.texture.layer_idx)
|
||||
* texture->level_count + srv->desc.u.texture.level_idx + level].srv;
|
||||
|
||||
resource->sub_resource_bind_flags |= WINED3D_SUB_RESOURCES_BIND_SRV;
|
||||
}
|
||||
|
||||
static inline void wined3d_srv_bind_count_dec(struct wined3d_shader_resource_view *srv)
|
||||
{
|
||||
struct wined3d_resource *resource = srv->resource;
|
||||
unsigned int level, layer, count;
|
||||
struct wined3d_texture *texture;
|
||||
|
||||
--resource->srv_bind_count_device;
|
||||
|
||||
if (wined3d_srv_all_subresources(srv))
|
||||
return;
|
||||
|
||||
texture = texture_from_resource(resource);
|
||||
|
||||
count = 0;
|
||||
for (layer = 0; layer < srv->desc.u.texture.layer_count; ++layer)
|
||||
for (level = 0; level < srv->desc.u.texture.level_count; ++level)
|
||||
count += --resource->sub_resource_bind_counts_device[(layer + srv->desc.u.texture.layer_idx)
|
||||
* texture->level_count + srv->desc.u.texture.level_idx + level].srv;
|
||||
|
||||
if (!count)
|
||||
resource->sub_resource_bind_flags &= ~WINED3D_SUB_RESOURCES_BIND_SRV;
|
||||
}
|
||||
|
||||
static inline void wined3d_rtv_bind_count_inc(struct wined3d_rendertarget_view *rtv)
|
||||
{
|
||||
++rtv->resource->rtv_bind_count_device;
|
||||
struct wined3d_resource *resource = rtv->resource;
|
||||
struct wined3d_texture *texture;
|
||||
unsigned int layer;
|
||||
|
||||
++resource->rtv_bind_count_device;
|
||||
|
||||
if (wined3d_rtv_all_subresources(rtv))
|
||||
return;
|
||||
|
||||
texture = texture_from_resource(resource);
|
||||
|
||||
if (!resource->sub_resource_bind_counts_device
|
||||
&& !(resource->sub_resource_bind_counts_device = heap_alloc_zero(texture->level_count
|
||||
* texture->layer_count * sizeof(*resource->sub_resource_bind_counts_device))))
|
||||
return;
|
||||
|
||||
for (layer = 0; layer < rtv->layer_count; ++layer)
|
||||
++resource->sub_resource_bind_counts_device[rtv->sub_resource_idx + layer * texture->level_count].rtv;
|
||||
|
||||
resource->sub_resource_bind_flags |= WINED3D_SUB_RESOURCES_BIND_RTV;
|
||||
}
|
||||
|
||||
static inline void wined3d_rtv_bind_count_dec(struct wined3d_rendertarget_view *rtv)
|
||||
{
|
||||
--rtv->resource->rtv_bind_count_device;
|
||||
struct wined3d_resource *resource = rtv->resource;
|
||||
struct wined3d_texture *texture;
|
||||
unsigned int layer, count;
|
||||
|
||||
--resource->rtv_bind_count_device;
|
||||
|
||||
if (wined3d_rtv_all_subresources(rtv))
|
||||
return;
|
||||
|
||||
texture = texture_from_resource(rtv->resource);
|
||||
|
||||
count = 0;
|
||||
for (layer = 0; layer < rtv->layer_count; ++layer)
|
||||
count += --resource->sub_resource_bind_counts_device[rtv->sub_resource_idx
|
||||
+ layer * texture->level_count].rtv;
|
||||
|
||||
if (!count)
|
||||
resource->sub_resource_bind_flags &= ~WINED3D_SUB_RESOURCES_BIND_RTV;
|
||||
}
|
||||
|
||||
static inline bool wined3d_is_srv_rtv_bound(const struct wined3d_shader_resource_view *srv)
|
||||
{
|
||||
struct wined3d_resource *resource = srv->resource;
|
||||
struct wined3d_texture *texture;
|
||||
unsigned int level, layer;
|
||||
|
||||
if (!resource->rtv_bind_count_device || !(resource->sub_resource_bind_flags & WINED3D_SUB_RESOURCES_BIND_RTV)
|
||||
|| wined3d_srv_all_subresources(srv))
|
||||
return resource->rtv_bind_count_device;
|
||||
|
||||
texture = texture_from_resource(resource);
|
||||
|
||||
for (layer = 0; layer < srv->desc.u.texture.layer_count; ++layer)
|
||||
for (level = 0; level < srv->desc.u.texture.level_count; ++level)
|
||||
if (resource->sub_resource_bind_counts_device[(layer + srv->desc.u.texture.layer_idx)
|
||||
* texture->level_count + srv->desc.u.texture.level_idx + level].rtv)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline bool wined3d_is_rtv_srv_bound(const struct wined3d_rendertarget_view *rtv)
|
||||
{
|
||||
struct wined3d_resource *resource = rtv->resource;
|
||||
struct wined3d_texture *texture;
|
||||
unsigned int layer;
|
||||
|
||||
if (!resource->srv_bind_count_device || !(resource->sub_resource_bind_flags & WINED3D_SUB_RESOURCES_BIND_SRV)
|
||||
|| wined3d_rtv_all_subresources(rtv))
|
||||
return resource->srv_bind_count_device;
|
||||
|
||||
texture = texture_from_resource(resource);
|
||||
|
||||
for (layer = 0; layer < rtv->layer_count; ++layer)
|
||||
if (resource->sub_resource_bind_counts_device[rtv->sub_resource_idx + layer * texture->level_count].srv)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *vp, float *min_z, float *max_z)
|
||||
|
|
Loading…
Reference in New Issue