Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d8/buffer.c | 4 ++++ dlls/d3d8/device.c | 2 ++ dlls/d3d8/texture.c | 6 ++++++ dlls/d3d9/buffer.c | 4 ++++ dlls/d3d9/device.c | 2 ++ dlls/d3d9/texture.c | 6 ++++++ dlls/ddraw/surface.c | 1 + dlls/wined3d/buffer.c | 2 +- dlls/wined3d/device.c | 10 ++++++---- dlls/wined3d/resource.c | 3 ++- dlls/wined3d/texture.c | 10 ++++++---- dlls/wined3d/utils.c | 2 ++ dlls/wined3d/wined3d_private.h | 5 ----- include/wine/wined3d.h | 3 ++- 14 files changed, 44 insertions(+), 16 deletions(-)
diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c index fb6b7bc1e92..93917d4fdcf 100644 --- a/dlls/d3d8/buffer.c +++ b/dlls/d3d8/buffer.c @@ -288,6 +288,8 @@ HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *
desc.byte_width = size; desc.usage = usage & WINED3DUSAGE_MASK; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; @@ -577,6 +579,8 @@ HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *de desc.usage = (usage & WINED3DUSAGE_MASK) | WINED3DUSAGE_STATICDECL; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.bind_flags = WINED3D_BIND_INDEX_BUFFER; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 12d02538351..cf158daab17 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -1165,6 +1165,8 @@ static HRESULT d3d8_device_create_surface(struct d3d8_device *device, UINT width desc.usage = usage & WINED3DUSAGE_MASK; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.width = width; diff --git a/dlls/d3d8/texture.c b/dlls/d3d8/texture.c index f7ccdc7e34b..f7e8fd36b9f 100644 --- a/dlls/d3d8/texture.c +++ b/dlls/d3d8/texture.c @@ -1110,6 +1110,8 @@ HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device, desc.usage |= WINED3DUSAGE_TEXTURE; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.width = width; @@ -1158,6 +1160,8 @@ HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *devic desc.usage |= WINED3DUSAGE_LEGACY_CUBEMAP | WINED3DUSAGE_TEXTURE; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.width = edge_length; @@ -1205,6 +1209,8 @@ HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *dev desc.usage |= WINED3DUSAGE_TEXTURE; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage); desc.width = width; desc.height = height; diff --git a/dlls/d3d9/buffer.c b/dlls/d3d9/buffer.c index 36a6ae3f902..b12167eb8be 100644 --- a/dlls/d3d9/buffer.c +++ b/dlls/d3d9/buffer.c @@ -289,6 +289,8 @@ HRESULT vertexbuffer_init(struct d3d9_vertexbuffer *buffer, struct d3d9_device *
desc.byte_width = size; desc.usage = usage & WINED3DUSAGE_MASK; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.bind_flags = WINED3D_BIND_VERTEX_BUFFER; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; @@ -576,6 +578,8 @@ HRESULT indexbuffer_init(struct d3d9_indexbuffer *buffer, struct d3d9_device *de desc.usage = (usage & WINED3DUSAGE_MASK) | WINED3DUSAGE_STATICDECL; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.bind_flags = WINED3D_BIND_INDEX_BUFFER; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index a3f410a7b97..39281330aa1 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1392,6 +1392,8 @@ static HRESULT d3d9_device_create_surface(struct d3d9_device *device, UINT width desc.usage = usage & WINED3DUSAGE_MASK; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.width = width; diff --git a/dlls/d3d9/texture.c b/dlls/d3d9/texture.c index 0858be99220..52cefbf9e28 100644 --- a/dlls/d3d9/texture.c +++ b/dlls/d3d9/texture.c @@ -1314,6 +1314,8 @@ HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device, desc.usage |= WINED3DUSAGE_TEXTURE; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.width = width; @@ -1399,6 +1401,8 @@ HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *devic desc.usage |= WINED3DUSAGE_LEGACY_CUBEMAP | WINED3DUSAGE_TEXTURE; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage) | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; desc.width = edge_length; @@ -1470,6 +1474,8 @@ HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *dev desc.usage |= WINED3DUSAGE_TEXTURE; if (pool == D3DPOOL_SCRATCH) desc.usage |= WINED3DUSAGE_SCRATCH; + if (pool == D3DPOOL_MANAGED) + desc.usage |= WINED3DUSAGE_MANAGED; desc.access = wined3daccess_from_d3dpool(pool, usage); desc.width = width; desc.height = height; diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index d201d9d4146..c1d5646c09d 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -6176,6 +6176,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_ | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W; /* Managed textures have the system memory flag set. */ desc->ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; + wined3d_desc.usage |= WINED3DUSAGE_MANAGED; } else if (desc->ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) { diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 5b3419d29e0..940fc4c2c0d 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1386,7 +1386,7 @@ static HRESULT wined3d_buffer_init(struct wined3d_buffer *buffer, struct wined3d debug_d3dformat(buffer->resource.format->id), buffer->resource.heap_memory);
if (device->create_parms.flags & WINED3DCREATE_SOFTWARE_VERTEXPROCESSING - || wined3d_resource_access_is_managed(desc->access)) + || desc->usage & WINED3DUSAGE_MANAGED) { /* SWvp and managed buffers always return the same pointer in buffer * maps and retain data in DISCARD maps. Keep a system memory copy of diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index b50d6677ab2..f98c02d99c0 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -3805,10 +3805,12 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, return WINED3DERR_INVALIDCALL; }
- if (src_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU - || src_texture->resource.usage & WINED3DUSAGE_SCRATCH) + if ((src_texture->resource.access & (WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU)) + == WINED3D_RESOURCE_ACCESS_GPU + || src_texture->resource.usage & WINED3DUSAGE_SCRATCH + || src_texture->resource.usage & WINED3DUSAGE_MANAGED) { - WARN("Source resource is GPU accessible or a scratch resource.\n"); + WARN("Source resource doesn't allow both CPU and GPU access or is a managed resource.\n"); return WINED3DERR_INVALIDCALL; } if (dst_texture->resource.access & WINED3D_RESOURCE_ACCESS_CPU) @@ -4742,7 +4744,7 @@ void CDECL wined3d_device_evict_managed_resources(struct wined3d_device *device) { TRACE("Checking resource %p for eviction.\n", resource);
- if (wined3d_resource_access_is_managed(resource->access) && !resource->map_count) + if (resource->usage & WINED3DUSAGE_MANAGED && !resource->map_count) { TRACE("Evicting %p.\n", resource); wined3d_cs_emit_unload_resource(device->cs, resource); diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c index 9df0a0923b2..8669100f138 100644 --- a/dlls/wined3d/resource.c +++ b/dlls/wined3d/resource.c @@ -37,6 +37,7 @@ static void resource_check_usage(DWORD usage) | WINED3DUSAGE_STATICDECL | WINED3DUSAGE_OVERLAY | WINED3DUSAGE_SCRATCH + | WINED3DUSAGE_MANAGED | WINED3DUSAGE_PRIVATE | WINED3DUSAGE_LEGACY_CUBEMAP | WINED3DUSAGE_TEXTURE @@ -253,7 +254,7 @@ DWORD CDECL wined3d_resource_set_priority(struct wined3d_resource *resource, DWO { DWORD prev;
- if (!wined3d_resource_access_is_managed(resource->access)) + if (~resource->usage & WINED3DUSAGE_MANAGED) { WARN("Called on non-managed resource %p, ignoring.\n", resource); return 0; diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index a3d834e8f53..283f35cd525 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1389,16 +1389,18 @@ void CDECL wined3d_texture_get_pitch(const struct wined3d_texture *texture,
DWORD CDECL wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod) { + unsigned int access = texture->resource.access; + unsigned int usage = texture->resource.usage; DWORD old = texture->lod;
TRACE("texture %p, lod %u.\n", texture, lod);
/* The d3d9:texture test shows that SetLOD is ignored on non-managed * textures. The call always returns 0, and GetLOD always returns 0. */ - if (!wined3d_resource_access_is_managed(texture->resource.access)) + if (~usage & WINED3DUSAGE_MANAGED) { - TRACE("Ignoring LOD on texture with resource access %s.\n", - wined3d_debug_resource_access(texture->resource.access)); + TRACE("Ignoring LOD on texture with resource access %s, usage %s.\n", + wined3d_debug_resource_access(access), debug_d3dusage(usage)); return 0; }
@@ -2896,7 +2898,7 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc } format = wined3d_get_format(device->adapter, desc->format, desc->usage);
- if (desc->usage & WINED3DUSAGE_DYNAMIC && (wined3d_resource_access_is_managed(desc->access) + if (desc->usage & WINED3DUSAGE_DYNAMIC && (desc->usage & WINED3DUSAGE_MANAGED || desc->usage & WINED3DUSAGE_SCRATCH)) { WARN("Attempted to create a dynamic texture with access %s and usage %s.\n", diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 6e60c5ae3db..373a3087344 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -4525,6 +4525,8 @@ const char *debug_d3dusage(DWORD usage) WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE); WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP); WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI); + WINED3DUSAGE_TO_STR(WINED3DUSAGE_MANAGED); + WINED3DUSAGE_TO_STR(WINED3DUSAGE_PRIVATE); WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP); WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTURE); WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 33d248fcfdd..b780020b071 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3072,11 +3072,6 @@ const char *wined3d_debug_bind_flags(DWORD bind_flags) DECLSPEC_HIDDEN; const char *wined3d_debug_view_desc(const struct wined3d_view_desc *d, const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
-static inline BOOL wined3d_resource_access_is_managed(unsigned int access) -{ - return !(~access & (WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU)); -} - struct wined3d_resource_ops { ULONG (*resource_incref)(struct wined3d_resource *resource); diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 1b3a46e6567..d8322ef017e 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -928,9 +928,10 @@ enum wined3d_shader_type #define WINED3DUSAGE_RESTRICT_SHARED_RESOURCE 0x00002000 #define WINED3DUSAGE_DMAP 0x00004000 #define WINED3DUSAGE_TEXTAPI 0x10000000 -#define WINED3DUSAGE_MASK 0x10007bff +#define WINED3DUSAGE_MASK 0x10007bfb
#define WINED3DUSAGE_SCRATCH 0x00200000 +#define WINED3DUSAGE_MANAGED 0x00000004 #define WINED3DUSAGE_PRIVATE 0x00400000 #define WINED3DUSAGE_LEGACY_CUBEMAP 0x00800000 #define WINED3DUSAGE_TEXTURE 0x01000000