Commit 61024aa1 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wined3d: Return the map pitch in wined3d_device_context_map().

parent 236afee0
...@@ -862,8 +862,14 @@ static HRESULT buffer_resource_sub_resource_get_desc(struct wined3d_resource *re ...@@ -862,8 +862,14 @@ static HRESULT buffer_resource_sub_resource_get_desc(struct wined3d_resource *re
return S_OK; return S_OK;
} }
static void buffer_resource_sub_resource_get_map_pitch(struct wined3d_resource *resource,
unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
{
*row_pitch = *slice_pitch = resource->size;
}
static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, 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) void **map_ptr, const struct wined3d_box *box, uint32_t flags)
{ {
struct wined3d_buffer *buffer = buffer_from_resource(resource); struct wined3d_buffer *buffer = buffer_from_resource(resource);
struct wined3d_device *device = resource->device; struct wined3d_device *device = resource->device;
...@@ -872,14 +878,12 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc ...@@ -872,14 +878,12 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc
uint8_t *base; uint8_t *base;
LONG count; LONG count;
TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", TRACE("resource %p, sub_resource_idx %u, map_ptr %p, box %s, flags %#x.\n",
resource, sub_resource_idx, map_desc, debug_box(box), flags); resource, sub_resource_idx, map_ptr, debug_box(box), flags);
offset = box->left; offset = box->left;
size = box->right - box->left; size = box->right - box->left;
map_desc->row_pitch = map_desc->slice_pitch = resource->size;
count = ++resource->map_count; count = ++resource->map_count;
if (buffer->buffer_object) if (buffer->buffer_object)
...@@ -965,9 +969,9 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc ...@@ -965,9 +969,9 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc
} }
base = buffer->map_ptr ? buffer->map_ptr : resource->heap_memory; base = buffer->map_ptr ? buffer->map_ptr : resource->heap_memory;
map_desc->data = base + offset; *map_ptr = base + offset;
TRACE("Returning memory at %p (base %p, offset %u).\n", map_desc->data, base, offset); TRACE("Returning memory at %p (base %p, offset %u).\n", *map_ptr, base, offset);
return WINED3D_OK; return WINED3D_OK;
} }
...@@ -1115,6 +1119,7 @@ static const struct wined3d_resource_ops buffer_resource_ops = ...@@ -1115,6 +1119,7 @@ static const struct wined3d_resource_ops buffer_resource_ops =
buffer_resource_preload, buffer_resource_preload,
buffer_resource_unload, buffer_resource_unload,
buffer_resource_sub_resource_get_desc, buffer_resource_sub_resource_get_desc,
buffer_resource_sub_resource_get_map_pitch,
buffer_resource_sub_resource_map, buffer_resource_sub_resource_map,
buffer_resource_sub_resource_unmap, buffer_resource_sub_resource_unmap,
}; };
......
...@@ -455,7 +455,7 @@ struct wined3d_cs_map ...@@ -455,7 +455,7 @@ struct wined3d_cs_map
enum wined3d_cs_op opcode; enum wined3d_cs_op opcode;
struct wined3d_resource *resource; struct wined3d_resource *resource;
unsigned int sub_resource_idx; unsigned int sub_resource_idx;
struct wined3d_map_desc *map_desc; void **map_ptr;
const struct wined3d_box *box; const struct wined3d_box *box;
DWORD flags; DWORD flags;
HRESULT *hr; HRESULT *hr;
...@@ -2402,12 +2402,11 @@ static void wined3d_cs_exec_map(struct wined3d_cs *cs, const void *data) ...@@ -2402,12 +2402,11 @@ static void wined3d_cs_exec_map(struct wined3d_cs *cs, const void *data)
struct wined3d_resource *resource = op->resource; struct wined3d_resource *resource = op->resource;
*op->hr = resource->resource_ops->resource_sub_resource_map(resource, *op->hr = resource->resource_ops->resource_sub_resource_map(resource,
op->sub_resource_idx, op->map_desc, op->box, op->flags); op->sub_resource_idx, op->map_ptr, op->box, op->flags);
} }
static HRESULT wined3d_cs_map(struct wined3d_device_context *context, struct wined3d_resource *resource, static HRESULT wined3d_cs_map(struct wined3d_device_context *context, struct wined3d_resource *resource,
unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags)
unsigned int flags)
{ {
struct wined3d_cs *cs = wined3d_cs_from_context(context); struct wined3d_cs *cs = wined3d_cs_from_context(context);
struct wined3d_cs_map *op; struct wined3d_cs_map *op;
...@@ -2423,7 +2422,7 @@ static HRESULT wined3d_cs_map(struct wined3d_device_context *context, struct win ...@@ -2423,7 +2422,7 @@ static HRESULT wined3d_cs_map(struct wined3d_device_context *context, struct win
op->opcode = WINED3D_CS_OP_MAP; op->opcode = WINED3D_CS_OP_MAP;
op->resource = resource; op->resource = resource;
op->sub_resource_idx = sub_resource_idx; op->sub_resource_idx = sub_resource_idx;
op->map_desc = map_desc; op->map_ptr = map_ptr;
op->box = box; op->box = box;
op->flags = flags; op->flags = flags;
op->hr = &hr; op->hr = &hr;
...@@ -3357,12 +3356,11 @@ static void wined3d_deferred_context_push_constants(struct wined3d_device_contex ...@@ -3357,12 +3356,11 @@ static void wined3d_deferred_context_push_constants(struct wined3d_device_contex
FIXME("context %p, p %#x, start_idx %u, count %u, constants %p, stub!\n", context, p, start_idx, count, constants); FIXME("context %p, p %#x, start_idx %u, count %u, constants %p, stub!\n", context, p, start_idx, count, constants);
} }
static HRESULT wined3d_deferred_context_map(struct wined3d_device_context *context, static HRESULT wined3d_deferred_context_map(struct wined3d_device_context *context, struct wined3d_resource *resource,
struct wined3d_resource *resource, unsigned int sub_resource_idx, unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags)
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags)
{ {
FIXME("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %p, flags %#x, stub!\n", FIXME("context %p, resource %p, sub_resource_idx %u, map_ptr %p, box %p, flags %#x, stub!\n",
context, resource, sub_resource_idx, map_desc, box, flags); context, resource, sub_resource_idx, map_ptr, box, flags);
return E_NOTIMPL; return E_NOTIMPL;
} }
......
...@@ -4836,6 +4836,7 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context, ...@@ -4836,6 +4836,7 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
{ {
struct wined3d_sub_resource_desc desc; struct wined3d_sub_resource_desc desc;
struct wined3d_box b; struct wined3d_box b;
HRESULT hr;
TRACE("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", TRACE("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
context, resource, sub_resource_idx, map_desc, debug_box(box), flags); context, resource, sub_resource_idx, map_desc, debug_box(box), flags);
...@@ -4869,7 +4870,10 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context, ...@@ -4869,7 +4870,10 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
box = &b; box = &b;
} }
return context->ops->map(context, resource, sub_resource_idx, map_desc, box, flags); if (SUCCEEDED(hr = context->ops->map(context, resource, sub_resource_idx, &map_desc->data, box, flags)))
wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx,
&map_desc->row_pitch, &map_desc->slice_pitch);
return hr;
} }
HRESULT CDECL wined3d_device_context_unmap(struct wined3d_device_context *context, HRESULT CDECL wined3d_device_context_unmap(struct wined3d_device_context *context,
......
...@@ -3514,13 +3514,31 @@ static HRESULT texture_resource_sub_resource_get_desc(struct wined3d_resource *r ...@@ -3514,13 +3514,31 @@ static HRESULT texture_resource_sub_resource_get_desc(struct wined3d_resource *r
return wined3d_texture_get_sub_resource_desc(texture, sub_resource_idx, desc); return wined3d_texture_get_sub_resource_desc(texture, sub_resource_idx, desc);
} }
static void texture_resource_sub_resource_get_map_pitch(struct wined3d_resource *resource,
unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
{
const struct wined3d_texture *texture = texture_from_resource(resource);
unsigned int level = sub_resource_idx % texture->level_count;
if (resource->format_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
{
*row_pitch = wined3d_texture_get_level_width(texture, level) * resource->format->byte_count;
*slice_pitch = wined3d_texture_get_level_height(texture, level) * (*row_pitch);
}
else
{
wined3d_texture_get_pitch(texture, level, row_pitch, slice_pitch);
}
}
static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, 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) void **map_ptr, const struct wined3d_box *box, DWORD flags)
{ {
const struct wined3d_format *format = resource->format; const struct wined3d_format *format = resource->format;
struct wined3d_texture_sub_resource *sub_resource; struct wined3d_texture_sub_resource *sub_resource;
struct wined3d_device *device = resource->device; struct wined3d_device *device = resource->device;
unsigned int fmt_flags = resource->format_flags; unsigned int fmt_flags = resource->format_flags;
unsigned int row_pitch, slice_pitch;
struct wined3d_context *context; struct wined3d_context *context;
struct wined3d_texture *texture; struct wined3d_texture *texture;
struct wined3d_bo_address data; struct wined3d_bo_address data;
...@@ -3528,8 +3546,8 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour ...@@ -3528,8 +3546,8 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
BYTE *base_memory; BYTE *base_memory;
BOOL ret; BOOL ret;
TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", TRACE("resource %p, sub_resource_idx %u, map_ptr %p, box %s, flags %#x.\n",
resource, sub_resource_idx, map_desc, debug_box(box), flags); resource, sub_resource_idx, map_ptr, debug_box(box), flags);
texture = texture_from_resource(resource); texture = texture_from_resource(resource);
sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx); sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx);
...@@ -3594,30 +3612,22 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour ...@@ -3594,30 +3612,22 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
context_release(context); context_release(context);
if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH) texture_resource_sub_resource_get_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
{
map_desc->row_pitch = wined3d_texture_get_level_width(texture, texture_level) * format->byte_count;
map_desc->slice_pitch = wined3d_texture_get_level_height(texture, texture_level) * map_desc->row_pitch;
}
else
{
wined3d_texture_get_pitch(texture, texture_level, &map_desc->row_pitch, &map_desc->slice_pitch);
}
if ((fmt_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS) if ((fmt_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
{ {
/* Compressed textures are block based, so calculate the offset of /* Compressed textures are block based, so calculate the offset of
* the block that contains the top-left pixel of the mapped box. */ * the block that contains the top-left pixel of the mapped box. */
map_desc->data = base_memory *map_ptr = base_memory
+ (box->front * map_desc->slice_pitch) + (box->front * slice_pitch)
+ ((box->top / format->block_height) * map_desc->row_pitch) + ((box->top / format->block_height) * row_pitch)
+ ((box->left / format->block_width) * format->block_byte_count); + ((box->left / format->block_width) * format->block_byte_count);
} }
else else
{ {
map_desc->data = base_memory *map_ptr = base_memory
+ (box->front * map_desc->slice_pitch) + (box->front * slice_pitch)
+ (box->top * map_desc->row_pitch) + (box->top * row_pitch)
+ (box->left * format->byte_count); + (box->left * format->byte_count);
} }
...@@ -3632,8 +3642,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour ...@@ -3632,8 +3642,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour
++resource->map_count; ++resource->map_count;
++sub_resource->map_count; ++sub_resource->map_count;
TRACE("Returning memory %p, row pitch %u, slice pitch %u.\n", TRACE("Returning memory %p.\n", *map_ptr);
map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
return WINED3D_OK; return WINED3D_OK;
} }
...@@ -3690,6 +3699,7 @@ static const struct wined3d_resource_ops texture_resource_ops = ...@@ -3690,6 +3699,7 @@ static const struct wined3d_resource_ops texture_resource_ops =
texture_resource_preload, texture_resource_preload,
texture_resource_unload, texture_resource_unload,
texture_resource_sub_resource_get_desc, texture_resource_sub_resource_get_desc,
texture_resource_sub_resource_get_map_pitch,
texture_resource_sub_resource_map, texture_resource_sub_resource_map,
texture_resource_sub_resource_unmap, texture_resource_sub_resource_unmap,
}; };
......
...@@ -4052,8 +4052,10 @@ struct wined3d_resource_ops ...@@ -4052,8 +4052,10 @@ struct wined3d_resource_ops
void (*resource_unload)(struct wined3d_resource *resource); void (*resource_unload)(struct wined3d_resource *resource);
HRESULT (*resource_sub_resource_get_desc)(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); unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc);
void (*resource_sub_resource_get_map_pitch)(struct wined3d_resource *resource,
unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch);
HRESULT (*resource_sub_resource_map)(struct wined3d_resource *resource, unsigned int sub_resource_idx, 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); void **map_ptr, const struct wined3d_box *box, DWORD flags);
HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx); HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
}; };
...@@ -4118,6 +4120,12 @@ static inline HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_reso ...@@ -4118,6 +4120,12 @@ static inline HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_reso
return resource->resource_ops->resource_sub_resource_get_desc(resource, sub_resource_idx, desc); return resource->resource_ops->resource_sub_resource_get_desc(resource, sub_resource_idx, desc);
} }
static inline void wined3d_resource_get_sub_resource_map_pitch(struct wined3d_resource *resource,
unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
{
resource->resource_ops->resource_sub_resource_get_map_pitch(resource, sub_resource_idx, row_pitch, slice_pitch);
}
void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN; void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device, HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
enum wined3d_resource_type type, const struct wined3d_format *format, enum wined3d_resource_type type, const struct wined3d_format *format,
...@@ -4693,8 +4701,7 @@ struct wined3d_device_context_ops ...@@ -4693,8 +4701,7 @@ struct wined3d_device_context_ops
void (*push_constants)(struct wined3d_device_context *context, enum wined3d_push_constants p, void (*push_constants)(struct wined3d_device_context *context, enum wined3d_push_constants p,
unsigned int start_idx, unsigned int count, const void *constants); unsigned int start_idx, unsigned int count, const void *constants);
HRESULT (*map)(struct wined3d_device_context *context, struct wined3d_resource *resource, HRESULT (*map)(struct wined3d_device_context *context, struct wined3d_resource *resource,
unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags);
unsigned int flags);
HRESULT (*unmap)(struct wined3d_device_context *context, struct wined3d_resource *resource, HRESULT (*unmap)(struct wined3d_device_context *context, struct wined3d_resource *resource,
unsigned int sub_resource_idx); unsigned int sub_resource_idx);
void (*update_sub_resource)(struct wined3d_device_context *context, struct wined3d_resource *resource, void (*update_sub_resource)(struct wined3d_device_context *context, struct wined3d_resource *resource,
......
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