Signed-off-by: Zebediah Figura <z.figura12(a)gmail.com>
---
Potentially we could obviate even this, by storing the level and layer count
inside the wined3d_resource structure. However, it's not immediately clear to me
what's worth taking up memory for.
dlls/wined3d/buffer.c | 23 +++++++++++++++++++
dlls/wined3d/device.c | 40 ++++++----------------------------
dlls/wined3d/texture.c | 9 ++++++++
dlls/wined3d/wined3d_private.h | 8 +++++++
4 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 7b8c8904961..142cce0299f 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -840,6 +840,28 @@ struct wined3d_resource * CDECL wined3d_buffer_get_resource(struct wined3d_buffe
return &buffer->resource;
}
+static HRESULT buffer_resource_sub_resource_get_desc(struct wined3d_resource *resource,
+ unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
+{
+ if (sub_resource_idx)
+ {
+ WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
+ return E_INVALIDARG;
+ }
+
+ desc->format = WINED3DFMT_UNKNOWN;
+ desc->multisample_type = WINED3D_MULTISAMPLE_NONE;
+ desc->multisample_quality = 0;
+ desc->usage = resource->usage;
+ desc->bind_flags = resource->bind_flags;
+ desc->access = resource->access;
+ desc->width = resource->size;
+ desc->height = 1;
+ desc->depth = 1;
+ desc->size = resource->size;
+ return S_OK;
+}
+
static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, uint32_t flags)
{
@@ -1105,6 +1127,7 @@ static const struct wined3d_resource_ops buffer_resource_ops =
buffer_resource_decref,
buffer_resource_preload,
buffer_resource_unload,
+ buffer_resource_sub_resource_get_desc,
buffer_resource_sub_resource_map,
buffer_resource_sub_resource_unmap,
};
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index a11f137729f..6d749269c18 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4649,7 +4649,7 @@ void CDECL wined3d_device_context_update_sub_resource(struct wined3d_device_cont
struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box,
const void *data, unsigned int row_pitch, unsigned int depth_pitch, unsigned int flags)
{
- unsigned int width, height, depth;
+ struct wined3d_sub_resource_desc desc;
struct wined3d_box b;
TRACE("context %p, resource %p, sub_resource_idx %u, box %s, data %p, row_pitch %u, depth_pitch %u, flags %#x.\n",
@@ -4664,43 +4664,17 @@ void CDECL wined3d_device_context_update_sub_resource(struct wined3d_device_cont
return;
}
- if (resource->type == WINED3D_RTYPE_BUFFER)
- {
- if (sub_resource_idx > 0)
- {
- WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
- return;
- }
-
- width = resource->size;
- height = 1;
- depth = 1;
- }
- else
- {
- struct wined3d_texture *texture = texture_from_resource(resource);
- unsigned int level;
-
- if (sub_resource_idx >= texture->level_count * texture->layer_count)
- {
- WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
- return;
- }
-
- level = sub_resource_idx % texture->level_count;
- width = wined3d_texture_get_level_width(texture, level);
- height = wined3d_texture_get_level_height(texture, level);
- depth = wined3d_texture_get_level_depth(texture, level);
- }
+ if (FAILED(wined3d_resource_get_sub_resource_desc(resource, sub_resource_idx, &desc)))
+ return;
if (!box)
{
- wined3d_box_set(&b, 0, 0, width, height, 0, depth);
+ wined3d_box_set(&b, 0, 0, desc.width, desc.height, 0, desc.depth);
box = &b;
}
- else if (box->left >= box->right || box->right > width
- || box->top >= box->bottom || box->bottom > height
- || box->front >= box->back || box->back > depth)
+ else if (box->left >= box->right || box->right > desc.width
+ || box->top >= box->bottom || box->bottom > desc.height
+ || box->front >= box->back || box->back > desc.depth)
{
WARN("Invalid box %s specified.\n", debug_box(box));
return;
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 165d83eb035..5f02bcfed8f 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -3506,6 +3506,14 @@ static void texture_resource_unload(struct wined3d_resource *resource)
resource_unload(&texture->resource);
}
+static HRESULT texture_resource_sub_resource_get_desc(struct wined3d_resource *resource,
+ unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
+{
+ const struct wined3d_texture *texture = texture_from_resource(resource);
+
+ return wined3d_texture_get_sub_resource_desc(texture, sub_resource_idx, desc);
+}
+
static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
{
@@ -3692,6 +3700,7 @@ static const struct wined3d_resource_ops texture_resource_ops =
texture_resource_decref,
texture_resource_preload,
texture_resource_unload,
+ texture_resource_sub_resource_get_desc,
texture_resource_sub_resource_map,
texture_resource_sub_resource_unmap,
};
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index da1cf638606..15b028a00f0 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4050,6 +4050,8 @@ struct wined3d_resource_ops
ULONG (*resource_decref)(struct wined3d_resource *resource);
void (*resource_preload)(struct wined3d_resource *resource);
void (*resource_unload)(struct wined3d_resource *resource);
+ HRESULT (*resource_sub_resource_get_desc)(struct wined3d_resource *resource,
+ unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc);
HRESULT (*resource_sub_resource_map)(struct wined3d_resource *resource, unsigned int sub_resource_idx,
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags);
HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
@@ -4110,6 +4112,12 @@ static inline void wined3d_resource_release(struct wined3d_resource *resource)
InterlockedDecrement(&resource->access_count);
}
+static inline HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_resource *resource,
+ unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
+{
+ return resource->resource_ops->resource_sub_resource_get_desc(resource, sub_resource_idx, desc);
+}
+
void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
enum wined3d_resource_type type, const struct wined3d_format *format,
--
2.30.2