[PATCH 4/5] wined3d: Allocate texture BOs from heap.
Zebediah Figura
zfigura at codeweavers.com
Sun Feb 20 23:22:24 CST 2022
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/wined3d/texture.c | 41 ++++++++++++++++++++++++----------
dlls/wined3d/wined3d_private.h | 7 +-----
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index c1d04ceb119..9b32b9f3d1a 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -845,7 +845,7 @@ void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int su
if (locations & WINED3D_LOCATION_BUFFER)
{
data->addr = NULL;
- data->buffer_object = &sub_resource->bo.b;
+ data->buffer_object = sub_resource->bo;
return;
}
@@ -873,12 +873,13 @@ void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int su
static void wined3d_texture_remove_buffer_object(struct wined3d_texture *texture,
unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl)
{
- struct wined3d_bo_gl *bo = &texture->sub_resources[sub_resource_idx].bo.gl;
+ struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
TRACE("texture %p, sub_resource_idx %u, context_gl %p.\n", texture, sub_resource_idx, context_gl);
- wined3d_context_gl_destroy_bo(context_gl, bo);
+ wined3d_context_gl_destroy_bo(context_gl, wined3d_bo_gl(sub_resource->bo));
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_BUFFER);
+ sub_resource->bo = NULL;
}
static void wined3d_texture_unload_location(struct wined3d_texture *texture,
@@ -2029,16 +2030,23 @@ static void wined3d_texture_gl_prepare_buffer_object(struct wined3d_texture_gl *
struct wined3d_bo_gl *bo;
sub_resource = &texture_gl->t.sub_resources[sub_resource_idx];
- bo = &sub_resource->bo.gl;
- if (bo->id)
+
+ if (sub_resource->bo)
+ return;
+
+ if (!(bo = heap_alloc(sizeof(*bo))))
return;
if (!wined3d_device_gl_create_bo(wined3d_device_gl(texture_gl->t.resource.device),
context_gl, sub_resource->size, GL_PIXEL_UNPACK_BUFFER, GL_STREAM_DRAW, true,
GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_CLIENT_STORAGE_BIT, bo))
+ {
+ heap_free(bo);
return;
+ }
TRACE("Created buffer object %u for texture %p, sub-resource %u.\n", bo->id, texture_gl, sub_resource_idx);
+ sub_resource->bo = &bo->b;
}
static void wined3d_texture_force_reload(struct wined3d_texture *texture)
@@ -3219,7 +3227,7 @@ static BOOL wined3d_texture_gl_load_texture(struct wined3d_texture_gl *texture_g
/* Don't use PBOs for converted surfaces. During PBO conversion we look at
* WINED3D_TEXTURE_CONVERTED but it isn't set (yet) in all cases it is
* getting called. */
- if (conversion && sub_resource->bo.gl.id)
+ if (conversion && sub_resource->bo)
{
TRACE("Removing the pbo attached to texture %p, %u.\n", texture_gl, sub_resource_idx);
@@ -3356,7 +3364,7 @@ static void wined3d_texture_gl_unload_location(struct wined3d_texture *texture,
sub_count = texture->level_count * texture->layer_count;
for (i = 0; i < sub_count; ++i)
{
- if (texture_gl->t.sub_resources[i].bo.gl.id)
+ if (texture_gl->t.sub_resources[i].bo)
wined3d_texture_remove_buffer_object(&texture_gl->t, i, context_gl);
}
break;
@@ -5265,18 +5273,24 @@ static BOOL wined3d_texture_vk_prepare_buffer_object(struct wined3d_texture_vk *
struct wined3d_bo_vk *bo;
sub_resource = &texture_vk->t.sub_resources[sub_resource_idx];
- bo = &sub_resource->bo.vk;
- if (bo->vk_buffer)
+ if (sub_resource->bo)
return TRUE;
+ if (!(bo = heap_alloc(sizeof(*bo))))
+ return FALSE;
+
if (!wined3d_context_vk_create_bo(context_vk, sub_resource->size,
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, bo))
+ {
+ heap_free(bo);
return FALSE;
+ }
/* Texture buffer objects receive a barrier to HOST_READ in wined3d_texture_vk_download_data(),
* so they don't need it when they are mapped for reading. */
bo->host_synced = true;
+ sub_resource->bo = &bo->b;
TRACE("Created buffer object %p for texture %p, sub-resource %u.\n", bo, texture_vk, sub_resource_idx);
return TRUE;
}
@@ -5351,10 +5365,13 @@ static void wined3d_texture_vk_unload_location(struct wined3d_texture *texture,
sub_count = texture->level_count * texture->layer_count;
for (i = 0; i < sub_count; ++i)
{
- if (texture->sub_resources[i].bo.vk.vk_buffer)
+ struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[i];
+
+ if (sub_resource->bo)
{
- wined3d_context_vk_destroy_bo(context_vk, &texture->sub_resources[i].bo.vk);
- texture->sub_resources[i].bo.vk.vk_buffer = VK_NULL_HANDLE;
+ wined3d_context_vk_destroy_bo(context_vk, wined3d_bo_vk(sub_resource->bo));
+ heap_free(sub_resource->bo);
+ sub_resource->bo = NULL;
}
}
break;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 277d5a94fb0..c3a44b3a7bd 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4532,12 +4532,7 @@ struct wined3d_texture
unsigned int map_count;
uint32_t map_flags;
DWORD locations;
- union
- {
- struct wined3d_bo b;
- struct wined3d_bo_gl gl;
- struct wined3d_bo_vk vk;
- } bo;
+ struct wined3d_bo *bo;
void *user_memory;
} *sub_resources;
--
2.34.1
More information about the wine-devel
mailing list