Commit e2755048 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wined3d: Use a wined3d_resource operation to retrieve the resource dimensions in…

wined3d: Use a wined3d_resource operation to retrieve the resource dimensions in wined3d_device_context_update_sub_resource(). Signed-off-by: 's avatarZebediah Figura <z.figura12@gmail.com> Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 5f54ff0b
No related merge requests found
......@@ -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,
};
......
......@@ -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;
......
......@@ -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,
};
......
......@@ -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,
......
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