Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/device.c | 9 ++---- dlls/wined3d/resource.c | 38 ++++++++++++++++++++++++++ dlls/wined3d/texture.c | 50 +++------------------------------- dlls/wined3d/wined3d_private.h | 4 +-- 4 files changed, 47 insertions(+), 54 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 2af705b10e3..5b2bd7ae03b 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4608,7 +4608,7 @@ HRESULT CDECL wined3d_device_context_copy_sub_resource_region(struct wined3d_dev wined3d_box_set(&b, 0, 0, min(src_w, dst_w), min(src_h, dst_h), 0, min(src_d, dst_d)); src_box = &b; } - else if (FAILED(wined3d_texture_check_box_dimensions(src_texture, src_level, src_box))) + else if (FAILED(wined3d_resource_check_box_dimensions(src_resource, src_sub_resource_idx, src_box))) { WARN("Invalid source box %s.\n", debug_box(src_box)); return WINED3DERR_INVALIDCALL; @@ -4631,8 +4631,7 @@ HRESULT CDECL wined3d_device_context_copy_sub_resource_region(struct wined3d_dev dst_y + (src_row_count * dst_resource->format->block_height), dst_z, dst_z + (src_box->back - src_box->front)); } - if (FAILED(wined3d_texture_check_box_dimensions(dst_texture, - dst_sub_resource_idx % dst_texture->level_count, &dst_box))) + if (FAILED(wined3d_resource_check_box_dimensions(dst_resource, dst_sub_resource_idx, &dst_box))) { WARN("Invalid destination box %s.\n", debug_box(&dst_box)); return WINED3DERR_INVALIDCALL; @@ -4760,11 +4759,9 @@ HRESULT CDECL wined3d_device_context_clear_rendertarget_view(struct wined3d_devi else { struct wined3d_box b = {rect->left, rect->top, rect->right, rect->bottom, 0, 1}; - struct wined3d_texture *texture = texture_from_resource(view->resource); HRESULT hr;
- if (FAILED(hr = wined3d_texture_check_box_dimensions(texture, - view->sub_resource_idx % texture->level_count, &b))) + if (FAILED(hr = wined3d_resource_check_box_dimensions(resource, view->sub_resource_idx, &b))) return hr; }
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c index 58e3e5c77fd..f37c313e023 100644 --- a/dlls/wined3d/resource.c +++ b/dlls/wined3d/resource.c @@ -501,6 +501,44 @@ unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *re return resource->multisample_type; }
+HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource, + unsigned int sub_resource_idx, const struct wined3d_box *box) +{ + const struct wined3d_format *format = resource->format; + struct wined3d_sub_resource_desc desc; + unsigned int width_mask, height_mask; + + wined3d_resource_get_sub_resource_desc(resource, sub_resource_idx, &desc); + + 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("Box %s is invalid.\n", debug_box(box)); + return WINEDDERR_INVALIDRECT; + } + + if (resource->format_flags & WINED3DFMT_FLAG_BLOCKS) + { + /* This assumes power of two block sizes, but NPOT block sizes would + * be silly anyway. + * + * This also assumes that the format's block depth is 1. */ + width_mask = format->block_width - 1; + height_mask = format->block_height - 1; + + if ((box->left & width_mask) || (box->top & height_mask) + || (box->right & width_mask && box->right != desc.width) + || (box->bottom & height_mask && box->bottom != desc.height)) + { + WARN("Box %s is misaligned for %ux%u blocks.\n", debug_box(box), format->block_width, format->block_height); + return WINED3DERR_INVALIDCALL; + } + } + + return WINED3D_OK; +} + VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags) { VkAccessFlags flags = 0; diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 5876f580e0d..0f753e66704 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -1653,46 +1653,6 @@ void * CDECL wined3d_texture_get_parent(const struct wined3d_texture *texture) return texture->resource.parent; }
-HRESULT wined3d_texture_check_box_dimensions(const struct wined3d_texture *texture, - unsigned int level, const struct wined3d_box *box) -{ - const struct wined3d_format *format = texture->resource.format; - unsigned int width_mask, height_mask, width, height, depth; - - 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 (box->left >= box->right || box->right > width - || box->top >= box->bottom || box->bottom > height - || box->front >= box->back || box->back > depth) - { - WARN("Box %s is invalid.\n", debug_box(box)); - return WINEDDERR_INVALIDRECT; - } - - if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS) - { - /* This assumes power of two block sizes, but NPOT block sizes would - * be silly anyway. - * - * This also assumes that the format's block depth is 1. */ - width_mask = format->block_width - 1; - height_mask = format->block_height - 1; - - if ((box->left & width_mask) || (box->top & height_mask) - || (box->right & width_mask && box->right != width) - || (box->bottom & height_mask && box->bottom != height)) - { - WARN("Box %s is misaligned for %ux%u blocks.\n", - debug_box(box), format->block_width, format->block_height); - return WINED3DERR_INVALIDCALL; - } - } - - return WINED3D_OK; -} - void CDECL wined3d_texture_get_pitch(const struct wined3d_texture *texture, unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch) { @@ -2250,7 +2210,7 @@ HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, return WINED3DERR_INVALIDCALL; }
- if (dirty_region && FAILED(wined3d_texture_check_box_dimensions(texture, 0, dirty_region))) + if (dirty_region && FAILED(wined3d_resource_check_box_dimensions(&texture->resource, 0, dirty_region))) { WARN("Invalid dirty_region %s specified.\n", debug_box(dirty_region)); return WINED3DERR_INVALIDCALL; @@ -3553,7 +3513,7 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx);
texture_level = sub_resource_idx % texture->level_count; - if (FAILED(wined3d_texture_check_box_dimensions(texture, texture_level, box))) + if (FAILED(wined3d_resource_check_box_dimensions(resource, sub_resource_idx, box))) { WARN("Map box is invalid.\n"); if (((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !(resource->access & WINED3D_RESOURCE_ACCESS_CPU)) @@ -4024,12 +3984,10 @@ HRESULT CDECL wined3d_device_context_blt(struct wined3d_device_context *context, && filter != WINED3D_TEXF_LINEAR) return WINED3DERR_INVALIDCALL;
- if (FAILED(hr = wined3d_texture_check_box_dimensions(dst_texture, - dst_sub_resource_idx % dst_texture->level_count, &dst_box))) + if (FAILED(hr = wined3d_resource_check_box_dimensions(&dst_texture->resource, dst_sub_resource_idx, &dst_box))) return hr;
- if (FAILED(hr = wined3d_texture_check_box_dimensions(src_texture, - src_sub_resource_idx % src_texture->level_count, &src_box))) + if (FAILED(hr = wined3d_resource_check_box_dimensions(&src_texture->resource, src_sub_resource_idx, &src_box))) return hr;
if (dst_texture->sub_resources[dst_sub_resource_idx].map_count diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 84dad38f0c9..6700302b481 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4134,6 +4134,8 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN; void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN; +HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource, + unsigned int sub_resource_idx, const struct wined3d_box *box) DECLSPEC_HIDDEN; void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN; const struct wined3d_format *wined3d_resource_get_decompress_format( const struct wined3d_resource *resource) DECLSPEC_HIDDEN; @@ -4358,8 +4360,6 @@ void texture2d_load_fb_texture(struct wined3d_texture_gl *texture_gl, unsigned i void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD src_location, DWORD dst_location) DECLSPEC_HIDDEN;
-HRESULT wined3d_texture_check_box_dimensions(const struct wined3d_texture *texture, - unsigned int level, const struct wined3d_box *box) DECLSPEC_HIDDEN; void wined3d_texture_cleanup(struct wined3d_texture *texture) DECLSPEC_HIDDEN; void wined3d_texture_download_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx) DECLSPEC_HIDDEN;
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/device.c | 10 ++++++++++ dlls/wined3d/texture.c | 7 ------- 2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 5b2bd7ae03b..96657141419 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -4866,6 +4866,16 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context, wined3d_box_set(&b, 0, 0, desc.width, desc.height, 0, desc.depth); box = &b; } + else if (FAILED(wined3d_resource_check_box_dimensions(resource, sub_resource_idx, box))) + { + WARN("Map box is invalid.\n"); + + if (resource->type != WINED3D_RTYPE_BUFFER && resource->type != WINED3D_RTYPE_TEXTURE_2D) + return WINED3DERR_INVALIDCALL; + + if ((resource->format_flags & WINED3DFMT_FLAG_BLOCKS) && !(resource->access & WINED3D_RESOURCE_ACCESS_CPU)) + return WINED3DERR_INVALIDCALL; + }
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, diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 0f753e66704..62f38a1d592 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -3513,13 +3513,6 @@ static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resour sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx);
texture_level = sub_resource_idx % texture->level_count; - if (FAILED(wined3d_resource_check_box_dimensions(resource, sub_resource_idx, box))) - { - WARN("Map box is invalid.\n"); - if (((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && !(resource->access & WINED3D_RESOURCE_ACCESS_CPU)) - || resource->type != WINED3D_RTYPE_TEXTURE_2D) - return WINED3DERR_INVALIDCALL; - }
if (texture->flags & WINED3D_TEXTURE_DC_IN_USE) {
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Allow things like wined3d_format_copy_data() to work on buffers.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 4019dd4d812..83d939e291f 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -83,7 +83,7 @@ static const struct wined3d_format_channels formats[] = { /* size offset * format id r g b a r g b a bpp depth stencil */ - {WINED3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {WINED3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, /* FourCC formats */ {WINED3DFMT_UYVY, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0}, {WINED3DFMT_YUY2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
On Sat, 26 Jun 2021 at 01:21, Zebediah Figura z.figura12@gmail.com wrote:
Allow things like wined3d_format_copy_data() to work on buffers.
That seems a little fragile. If this is just for buffer resources, it may be preferable to just use e.g. R8_UINT for those.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/buffer.c | 21 +-------------------- dlls/wined3d/cs.c | 15 ++++----------- dlls/wined3d/wined3d_private.h | 4 ++-- 3 files changed, 7 insertions(+), 33 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 00d219a49f2..7fc150878f0 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -108,7 +108,7 @@ static void wined3d_buffer_validate_location(struct wined3d_buffer *buffer, DWOR TRACE("New locations flags are %s.\n", wined3d_debug_location(buffer->locations)); }
-static void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, +void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, unsigned int offset, unsigned int size) { TRACE("buffer %p, location %s, offset %u, size %u.\n", @@ -1054,25 +1054,6 @@ void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_off context_release(context); }
-void wined3d_buffer_upload_data(struct wined3d_buffer *buffer, struct wined3d_context *context, - const struct wined3d_box *box, const void *data) -{ - struct wined3d_range range; - - if (box) - { - range.offset = box->left; - range.size = box->right - box->left; - } - else - { - range.offset = 0; - range.size = buffer->resource.size; - } - - buffer->buffer_ops->buffer_upload_ranges(buffer, context, data, range.offset, 1, &range); -} - static void wined3d_buffer_init_data(struct wined3d_buffer *buffer, struct wined3d_device *device, const struct wined3d_sub_resource_data *data) { diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index 4adfa18f5f7..022c0acbd0a 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -2613,18 +2613,14 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi
context = context_acquire(cs->c.device, NULL, 0);
+ addr.buffer_object = 0; + addr.addr = op->data.data; + if (resource->type == WINED3D_RTYPE_BUFFER) { struct wined3d_buffer *buffer = buffer_from_resource(resource);
- if (!wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER)) - { - ERR("Failed to load buffer location.\n"); - goto done; - } - - wined3d_buffer_upload_data(buffer, context, box, op->data.data); - wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER); + wined3d_buffer_copy_bo_address(buffer, context, box->left, &addr, box->right - box->left); goto done; }
@@ -2635,9 +2631,6 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi height = wined3d_texture_get_level_height(texture, level); depth = wined3d_texture_get_level_depth(texture, level);
- addr.buffer_object = 0; - addr.addr = op->data.data; - /* Only load the sub-resource for partial updates. */ if (!box->left && !box->top && !box->front && box->right == width && box->bottom == height && box->back == depth) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 6700302b481..87c83d555e4 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4919,6 +4919,8 @@ void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wi DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context, struct wined3d_bo_address *data) DECLSPEC_HIDDEN; void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, DWORD location) DECLSPEC_HIDDEN; +void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, + unsigned int offset, unsigned int size) DECLSPEC_HIDDEN; void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN; BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, @@ -4926,8 +4928,6 @@ BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN; BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, struct wined3d_context *context, unsigned int location) DECLSPEC_HIDDEN; -void wined3d_buffer_upload_data(struct wined3d_buffer *buffer, struct wined3d_context *context, - const struct wined3d_box *box, const void *data) DECLSPEC_HIDDEN;
HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device, const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
On Sat, 26 Jun 2021 at 01:22, Zebediah Figura z.figura12@gmail.com wrote:
-static void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, +void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, unsigned int offset, unsigned int size) {
This change doesn't seem required by the rest of the patch.
On 6/28/21 10:12 AM, Henri Verbeet wrote:
On Sat, 26 Jun 2021 at 01:22, Zebediah Figura z.figura12@gmail.com wrote:
-static void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, +void wined3d_buffer_invalidate_range(struct wined3d_buffer *buffer, DWORD location, unsigned int offset, unsigned int size) {
This change doesn't seem required by the rest of the patch.
Oops, that was left over from an earlier version :-(
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/wined3d/cs.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index 022c0acbd0a..47bc36d4cc0 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -489,7 +489,8 @@ struct wined3d_cs_update_sub_resource struct wined3d_resource *resource; unsigned int sub_resource_idx; struct wined3d_box box; - struct wined3d_sub_resource_data data; + struct wined3d_const_bo_address addr; + unsigned int row_pitch, slice_pitch; };
struct wined3d_cs_add_dirty_texture_region @@ -2606,21 +2607,17 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi struct wined3d_resource *resource = op->resource; const struct wined3d_box *box = &op->box; unsigned int width, height, depth, level; - struct wined3d_const_bo_address addr; struct wined3d_context *context; struct wined3d_texture *texture; struct wined3d_box src_box;
context = context_acquire(cs->c.device, NULL, 0);
- addr.buffer_object = 0; - addr.addr = op->data.data; - if (resource->type == WINED3D_RTYPE_BUFFER) { struct wined3d_buffer *buffer = buffer_from_resource(resource);
- wined3d_buffer_copy_bo_address(buffer, context, box->left, &addr, box->right - box->left); + wined3d_buffer_copy_bo_address(buffer, context, box->left, &op->addr, box->right - box->left); goto done; }
@@ -2639,8 +2636,8 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi wined3d_texture_load_location(texture, op->sub_resource_idx, context, WINED3D_LOCATION_TEXTURE_RGB);
wined3d_box_set(&src_box, 0, 0, box->right - box->left, box->bottom - box->top, 0, box->back - box->front); - texture->texture_ops->texture_upload_data(context, &addr, texture->resource.format, &src_box, - op->data.row_pitch, op->data.slice_pitch, texture, op->sub_resource_idx, + texture->texture_ops->texture_upload_data(context, &op->addr, texture->resource.format, &src_box, + op->row_pitch, op->slice_pitch, texture, op->sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB, box->left, box->top, box->front);
wined3d_texture_validate_location(texture, op->sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB); @@ -2665,9 +2662,10 @@ static void wined3d_cs_update_sub_resource(struct wined3d_device_context *contex op->resource = resource; op->sub_resource_idx = sub_resource_idx; op->box = *box; - op->data.row_pitch = row_pitch; - op->data.slice_pitch = slice_pitch; - op->data.data = data; + op->addr.buffer_object = 0; + op->addr.addr = data; + op->row_pitch = row_pitch; + op->slice_pitch = slice_pitch;
wined3d_device_context_acquire_resource(context, resource);