Commit 2a2554ee authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Store sub-resource map counts in the sub-resource structure.

parent bcb1ee82
...@@ -477,7 +477,7 @@ static void surface_evict_sysmem(struct wined3d_surface *surface) ...@@ -477,7 +477,7 @@ static void surface_evict_sysmem(struct wined3d_surface *surface)
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface); unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
struct wined3d_texture *texture = surface->container; struct wined3d_texture *texture = surface->container;
if (surface->resource.map_count || texture->download_count > MAXLOCKCOUNT if (texture->sub_resources[sub_resource_idx].map_count || texture->download_count > MAXLOCKCOUNT
|| texture->flags & (WINED3D_TEXTURE_CONVERTED | WINED3D_TEXTURE_PIN_SYSMEM)) || texture->flags & (WINED3D_TEXTURE_CONVERTED | WINED3D_TEXTURE_PIN_SYSMEM))
return; return;
...@@ -1124,6 +1124,7 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w ...@@ -1124,6 +1124,7 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point, const struct wined3d_format *format, const RECT *src_rect, UINT src_pitch, const POINT *dst_point,
BOOL srgb, const struct wined3d_const_bo_address *data) BOOL srgb, const struct wined3d_const_bo_address *data)
{ {
unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
struct wined3d_texture *texture = surface->container; struct wined3d_texture *texture = surface->container;
UINT update_w = src_rect->right - src_rect->left; UINT update_w = src_rect->right - src_rect->left;
UINT update_h = src_rect->bottom - src_rect->top; UINT update_h = src_rect->bottom - src_rect->top;
...@@ -1132,7 +1133,7 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w ...@@ -1132,7 +1133,7 @@ void wined3d_surface_upload_data(struct wined3d_surface *surface, const struct w
surface, gl_info, debug_d3dformat(format->id), wine_dbgstr_rect(src_rect), src_pitch, surface, gl_info, debug_d3dformat(format->id), wine_dbgstr_rect(src_rect), src_pitch,
wine_dbgstr_point(dst_point), srgb, data->buffer_object, data->addr); wine_dbgstr_point(dst_point), srgb, data->buffer_object, data->addr);
if (surface->resource.map_count) if (texture->sub_resources[sub_resource_idx].map_count)
{ {
WARN("Uploading a surface that is currently mapped, setting WINED3D_TEXTURE_PIN_SYSMEM.\n"); WARN("Uploading a surface that is currently mapped, setting WINED3D_TEXTURE_PIN_SYSMEM.\n");
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM; texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM;
...@@ -4178,6 +4179,7 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4178,6 +4179,7 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
struct wined3d_device *device = dst_texture->resource.device; struct wined3d_device *device = dst_texture->resource.device;
struct wined3d_swapchain *src_swapchain, *dst_swapchain; struct wined3d_swapchain *src_swapchain, *dst_swapchain;
struct wined3d_texture *src_texture = NULL; struct wined3d_texture *src_texture = NULL;
unsigned int src_sub_resource_idx = 0;
DWORD src_ds_flags, dst_ds_flags; DWORD src_ds_flags, dst_ds_flags;
BOOL scale, convert; BOOL scale, convert;
...@@ -4207,7 +4209,14 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4207,7 +4209,14 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
fx->src_color_key.color_space_high_value); fx->src_color_key.color_space_high_value);
} }
if (dst_surface->resource.map_count || (src_surface && src_surface->resource.map_count)) if (src_surface)
{
src_texture = src_surface->container;
src_sub_resource_idx = surface_get_sub_resource_idx(src_surface);
}
if (dst_texture->sub_resources[dst_sub_resource_idx].map_count
|| (src_texture && src_texture->sub_resources[src_sub_resource_idx].map_count))
{ {
WARN("Surface is busy, returning WINEDDERR_SURFACEBUSY.\n"); WARN("Surface is busy, returning WINEDDERR_SURFACEBUSY.\n");
return WINEDDERR_SURFACEBUSY; return WINEDDERR_SURFACEBUSY;
...@@ -4223,7 +4232,7 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4223,7 +4232,7 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
return WINEDDERR_INVALIDRECT; return WINEDDERR_INVALIDRECT;
} }
if (src_surface) if (src_texture)
{ {
if (src_rect->left >= src_rect->right || src_rect->top >= src_rect->bottom if (src_rect->left >= src_rect->right || src_rect->top >= src_rect->bottom
|| src_rect->left > src_surface->resource.width || src_rect->left < 0 || src_rect->left > src_surface->resource.width || src_rect->left < 0
...@@ -4234,7 +4243,6 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4234,7 +4243,6 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
WARN("The application gave us a bad source rectangle.\n"); WARN("The application gave us a bad source rectangle.\n");
return WINEDDERR_INVALIDRECT; return WINEDDERR_INVALIDRECT;
} }
src_texture = src_surface->container;
} }
if (!fx || !(fx->fx)) if (!fx || !(fx->fx))
...@@ -4284,7 +4292,7 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4284,7 +4292,7 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
goto fallback; goto fallback;
} }
if (src_surface) if (src_texture)
src_swapchain = src_texture->swapchain; src_swapchain = src_texture->swapchain;
else else
src_swapchain = NULL; src_swapchain = NULL;
...@@ -4302,14 +4310,14 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4302,14 +4310,14 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
goto fallback; goto fallback;
} }
scale = src_surface scale = src_texture
&& (src_rect->right - src_rect->left != dst_rect->right - dst_rect->left && (src_rect->right - src_rect->left != dst_rect->right - dst_rect->left
|| src_rect->bottom - src_rect->top != dst_rect->bottom - dst_rect->top); || src_rect->bottom - src_rect->top != dst_rect->bottom - dst_rect->top);
convert = src_surface && src_texture->resource.format->id != dst_texture->resource.format->id; convert = src_texture && src_texture->resource.format->id != dst_texture->resource.format->id;
dst_ds_flags = dst_texture->resource.format_flags dst_ds_flags = dst_texture->resource.format_flags
& (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL); & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
if (src_surface) if (src_texture)
src_ds_flags = src_texture->resource.format_flags src_ds_flags = src_texture->resource.format_flags
& (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL); & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
else else
...@@ -4348,12 +4356,12 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst ...@@ -4348,12 +4356,12 @@ HRESULT wined3d_surface_blt(struct wined3d_surface *dst_surface, const RECT *dst
const struct blit_shader *blitter; const struct blit_shader *blitter;
dst_sub_resource = surface_get_sub_resource(dst_surface); dst_sub_resource = surface_get_sub_resource(dst_surface);
src_sub_resource = src_surface ? surface_get_sub_resource(src_surface) : NULL; src_sub_resource = src_texture ? &src_texture->sub_resources[src_sub_resource_idx] : NULL;
/* In principle this would apply to depth blits as well, but we don't /* In principle this would apply to depth blits as well, but we don't
* implement those in the CPU blitter at the moment. */ * implement those in the CPU blitter at the moment. */
if ((dst_sub_resource->locations & dst_surface->resource.map_binding) if ((dst_sub_resource->locations & dst_surface->resource.map_binding)
&& (!src_surface || (src_sub_resource->locations & src_surface->resource.map_binding))) && (!src_texture || (src_sub_resource->locations & src_surface->resource.map_binding)))
{ {
if (scale) if (scale)
TRACE("Not doing sysmem blit because of scaling.\n"); TRACE("Not doing sysmem blit because of scaling.\n");
...@@ -4483,8 +4491,8 @@ fallback: ...@@ -4483,8 +4491,8 @@ fallback:
return WINED3D_OK; return WINED3D_OK;
cpu: cpu:
return surface_cpu_blt(dst_texture, surface_get_sub_resource_idx(dst_surface), &dst_box, return surface_cpu_blt(dst_texture, dst_sub_resource_idx, &dst_box,
src_texture, src_texture ? surface_get_sub_resource_idx(src_surface) : 0, &src_box, flags, fx, filter); src_texture, src_sub_resource_idx, &src_box, flags, fx, filter);
} }
HRESULT wined3d_surface_init(struct wined3d_surface *surface, struct wined3d_texture *container, HRESULT wined3d_surface_init(struct wined3d_surface *surface, struct wined3d_texture *container,
......
...@@ -663,7 +663,7 @@ static void swapchain_gdi_frontbuffer_updated(struct wined3d_swapchain *swapchai ...@@ -663,7 +663,7 @@ static void swapchain_gdi_frontbuffer_updated(struct wined3d_swapchain *swapchai
if (swapchain->palette) if (swapchain->palette)
wined3d_palette_apply_to_dc(swapchain->palette, front->hDC); wined3d_palette_apply_to_dc(swapchain->palette, front->hDC);
if (front->resource.map_count) if (front->container->resource.map_count)
ERR("Trying to blit a mapped surface.\n"); ERR("Trying to blit a mapped surface.\n");
TRACE("Copying surface %p to screen.\n", front); TRACE("Copying surface %p to screen.\n", front);
......
...@@ -853,7 +853,7 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT ...@@ -853,7 +853,7 @@ HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT
sub_resource = &texture->sub_resources[0]; sub_resource = &texture->sub_resources[0];
surface = sub_resource->u.surface; surface = sub_resource->u.surface;
if (sub_resource->resource->map_count || (surface->flags & SFLAG_DCINUSE)) if (sub_resource->map_count || (surface->flags & SFLAG_DCINUSE))
{ {
WARN("Surface is mapped or the DC is in use.\n"); WARN("Surface is mapped or the DC is in use.\n");
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
...@@ -1291,7 +1291,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour ...@@ -1291,7 +1291,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
if (sub_resource->resource->map_count) if (sub_resource->map_count)
{ {
WARN("Sub-resource is already mapped.\n"); WARN("Sub-resource is already mapped.\n");
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
...@@ -1409,7 +1409,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour ...@@ -1409,7 +1409,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
} }
++resource->map_count; ++resource->map_count;
++sub_resource->resource->map_count; ++sub_resource->map_count;
TRACE("Returning memory %p, row pitch %u, slice pitch %u.\n", TRACE("Returning memory %p, row pitch %u, slice pitch %u.\n",
map_desc->data, map_desc->row_pitch, map_desc->slice_pitch); map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
...@@ -1430,7 +1430,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso ...@@ -1430,7 +1430,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx))) if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
return E_INVALIDARG; return E_INVALIDARG;
if (!sub_resource->resource->map_count) if (!sub_resource->map_count)
{ {
WARN("Trying to unmap unmapped sub-resource.\n"); WARN("Trying to unmap unmapped sub-resource.\n");
return WINEDDERR_NOTLOCKED; return WINEDDERR_NOTLOCKED;
...@@ -1473,7 +1473,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso ...@@ -1473,7 +1473,7 @@ static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *reso
FIXME("Depth / stencil buffer locking is not implemented.\n"); FIXME("Depth / stencil buffer locking is not implemented.\n");
} }
--sub_resource->resource->map_count; --sub_resource->map_count;
--resource->map_count; --resource->map_count;
return WINED3D_OK; return WINED3D_OK;
...@@ -2237,7 +2237,7 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i ...@@ -2237,7 +2237,7 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i
return WINEDDERR_DCALREADYCREATED; return WINEDDERR_DCALREADYCREATED;
/* Can't GetDC if the surface is locked. */ /* Can't GetDC if the surface is locked. */
if (surface->resource.map_count) if (sub_resource->map_count)
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
if (device->d3d_initialized) if (device->d3d_initialized)
...@@ -2266,7 +2266,7 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i ...@@ -2266,7 +2266,7 @@ HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned i
surface->flags |= SFLAG_DCINUSE; surface->flags |= SFLAG_DCINUSE;
++texture->resource.map_count; ++texture->resource.map_count;
surface->resource.map_count++; ++sub_resource->map_count;
*dc = surface->hDC; *dc = surface->hDC;
TRACE("Returning dc %p.\n", *dc); TRACE("Returning dc %p.\n", *dc);
...@@ -2304,7 +2304,7 @@ HRESULT CDECL wined3d_texture_release_dc(struct wined3d_texture *texture, unsign ...@@ -2304,7 +2304,7 @@ HRESULT CDECL wined3d_texture_release_dc(struct wined3d_texture *texture, unsign
return WINEDDERR_NODC; return WINEDDERR_NODC;
} }
surface->resource.map_count--; --sub_resource->map_count;
--texture->resource.map_count; --texture->resource.map_count;
surface->flags &= ~SFLAG_DCINUSE; surface->flags &= ~SFLAG_DCINUSE;
......
...@@ -2484,6 +2484,7 @@ struct wined3d_texture ...@@ -2484,6 +2484,7 @@ struct wined3d_texture
struct wined3d_volume *volume; struct wined3d_volume *volume;
} u; } u;
unsigned int map_count;
DWORD locations; DWORD locations;
GLuint buffer_object; GLuint buffer_object;
} sub_resources[1]; } sub_resources[1];
......
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