From 1c9c21dc1c1058f9061d67423c1f37c3cd80f61d Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sat, 26 Jun 2021 12:20:36 -0500 Subject: [PATCH] Rebase against 542175ab10420953920779f3c64eb310dd3aa258. --- ...ined3d_resource-and-sub-resource-ind.patch | 208 ++++++++ ...-validation-to-wined3d_device_contex.patch | 53 ++ ...-byte-count-of-1-for-WINED3DFMT_UNKN.patch | 28 ++ ...d3d_buffer_copy_bo_address-in-wined3.patch | 114 +++++ ...ined3d_const_bo_address-to-wined3d_c.patch | 76 +++ ...e-a-prepare_upload_bo-device-context.patch | 181 +++++++ ...t-wined3d_deferred_context_prepare_u.patch | 207 ++++++++ ...-types-other-than-DISCARD-and-NOOVER.patch | 29 ++ ...ext-ops-prepare_upload_bo-in-wined3d.patch | 350 +++++++++++++ ...t-NOOVERWITE-maps-in-wined3d_deferre.patch | 113 +++++ ...message-when-forcing-CS-serializatio.patch | 27 + ...t-wined3d_deferred_context_update_su.patch | 92 ---- ...plement-wined3d_deferred_context_map.patch | 461 ------------------ ...Move-some-tests-to-a-new-sync.c-file.patch | 6 +- patches/patchinstall.sh | 42 +- patches/wined3d-CSMT_Main/definition | 3 + staging/upstream-commit | 2 +- 17 files changed, 1407 insertions(+), 585 deletions(-) create mode 100644 patches/d3d11-Deferred_Context/0001-wined3d-Pass-a-wined3d_resource-and-sub-resource-ind.patch create mode 100644 patches/d3d11-Deferred_Context/0002-wined3d-Move-box-validation-to-wined3d_device_contex.patch create mode 100644 patches/d3d11-Deferred_Context/0003-wined3d-Report-a-byte-count-of-1-for-WINED3DFMT_UNKN.patch create mode 100644 patches/d3d11-Deferred_Context/0004-wined3d-Use-wined3d_buffer_copy_bo_address-in-wined3.patch create mode 100644 patches/d3d11-Deferred_Context/0005-wined3d-Pass-a-wined3d_const_bo_address-to-wined3d_c.patch create mode 100644 patches/d3d11-Deferred_Context/0006-wined3d-Introduce-a-prepare_upload_bo-device-context.patch create mode 100644 patches/d3d11-Deferred_Context/0007-wined3d-Implement-wined3d_deferred_context_prepare_u.patch create mode 100644 patches/d3d11-Deferred_Context/0008-d3d11-Forbid-map-types-other-than-DISCARD-and-NOOVER.patch create mode 100644 patches/d3d11-Deferred_Context/0009-wined3d-Use-context-ops-prepare_upload_bo-in-wined3d.patch create mode 100644 patches/d3d11-Deferred_Context/0010-wined3d-Implement-NOOVERWITE-maps-in-wined3d_deferre.patch create mode 100644 patches/d3d11-Deferred_Context/0011-wined3d-Print-a-message-when-forcing-CS-serializatio.patch delete mode 100644 patches/d3d11-Deferred_Context/0013-wined3d-Implement-wined3d_deferred_context_update_su.patch delete mode 100644 patches/d3d11-Deferred_Context/0014-wined3d-Implement-wined3d_deferred_context_map.patch diff --git a/patches/d3d11-Deferred_Context/0001-wined3d-Pass-a-wined3d_resource-and-sub-resource-ind.patch b/patches/d3d11-Deferred_Context/0001-wined3d-Pass-a-wined3d_resource-and-sub-resource-ind.patch new file mode 100644 index 00000000..543b14e1 --- /dev/null +++ b/patches/d3d11-Deferred_Context/0001-wined3d-Pass-a-wined3d_resource-and-sub-resource-ind.patch @@ -0,0 +1,208 @@ +From eb98e2cffac9434f3c3afc97e7a90e6fb3058c2d Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Wed, 23 Jun 2021 15:49:58 -0500 +Subject: [PATCH] wined3d: Pass a wined3d_resource and sub-resource index to + wined3d_texture_check_box_dimensions(). + +Signed-off-by: Zebediah Figura +--- + 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; +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0002-wined3d-Move-box-validation-to-wined3d_device_contex.patch b/patches/d3d11-Deferred_Context/0002-wined3d-Move-box-validation-to-wined3d_device_contex.patch new file mode 100644 index 00000000..d46f2ead --- /dev/null +++ b/patches/d3d11-Deferred_Context/0002-wined3d-Move-box-validation-to-wined3d_device_contex.patch @@ -0,0 +1,53 @@ +From ffd6adde2136c44bae66146c3f852c9520b1d9e1 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Tue, 22 Jun 2021 18:05:18 -0500 +Subject: [PATCH] wined3d: Move box validation to wined3d_device_context_map(). + +Signed-off-by: Zebediah Figura +--- + 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) + { +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0003-wined3d-Report-a-byte-count-of-1-for-WINED3DFMT_UNKN.patch b/patches/d3d11-Deferred_Context/0003-wined3d-Report-a-byte-count-of-1-for-WINED3DFMT_UNKN.patch new file mode 100644 index 00000000..a15de1d1 --- /dev/null +++ b/patches/d3d11-Deferred_Context/0003-wined3d-Report-a-byte-count-of-1-for-WINED3DFMT_UNKN.patch @@ -0,0 +1,28 @@ +From ff92a7d4d6430af59d5ed8d0f33b3bf958eb8726 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Wed, 23 Jun 2021 18:19:29 -0500 +Subject: [PATCH] wined3d: Report a byte count of 1 for WINED3DFMT_UNKNOWN. + +Allow things like wined3d_format_copy_data() to work on buffers. + +Signed-off-by: Zebediah Figura +--- + 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}, +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0004-wined3d-Use-wined3d_buffer_copy_bo_address-in-wined3.patch b/patches/d3d11-Deferred_Context/0004-wined3d-Use-wined3d_buffer_copy_bo_address-in-wined3.patch new file mode 100644 index 00000000..1ce21217 --- /dev/null +++ b/patches/d3d11-Deferred_Context/0004-wined3d-Use-wined3d_buffer_copy_bo_address-in-wined3.patch @@ -0,0 +1,114 @@ +From fbb780271175048fb723ec19a9a6c24d0b6dcf81 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Thu, 17 Jun 2021 21:56:24 -0500 +Subject: [PATCH] wined3d: Use wined3d_buffer_copy_bo_address() in + wined3d_cs_exec_update_sub_resource(). + +Signed-off-by: Zebediah Figura +--- + 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, +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0005-wined3d-Pass-a-wined3d_const_bo_address-to-wined3d_c.patch b/patches/d3d11-Deferred_Context/0005-wined3d-Pass-a-wined3d_const_bo_address-to-wined3d_c.patch new file mode 100644 index 00000000..e34fb72f --- /dev/null +++ b/patches/d3d11-Deferred_Context/0005-wined3d-Pass-a-wined3d_const_bo_address-to-wined3d_c.patch @@ -0,0 +1,76 @@ +From 5188d3e4779ee56dc8d7a9b07074095a41a4331b Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Thu, 17 Jun 2021 22:14:58 -0500 +Subject: [PATCH] wined3d: Pass a wined3d_const_bo_address to + wined3d_cs_exec_update_sub_resource(). + +Signed-off-by: Zebediah Figura +--- + 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); + +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0006-wined3d-Introduce-a-prepare_upload_bo-device-context.patch b/patches/d3d11-Deferred_Context/0006-wined3d-Introduce-a-prepare_upload_bo-device-context.patch new file mode 100644 index 00000000..92cd2f61 --- /dev/null +++ b/patches/d3d11-Deferred_Context/0006-wined3d-Introduce-a-prepare_upload_bo-device-context.patch @@ -0,0 +1,181 @@ +From e5d31156ca6648bd60221943163142e6d3d7fcf2 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Thu, 17 Jun 2021 22:37:49 -0500 +Subject: [PATCH] wined3d: Introduce a prepare_upload_bo device context + operation and use it to upload sub-resource data. + +Signed-off-by: Zebediah Figura +--- + dlls/wined3d/buffer.c | 2 +- + dlls/wined3d/cs.c | 54 ++++++++++++++++++++++++++++++++++ + dlls/wined3d/device.c | 3 +- + dlls/wined3d/texture.c | 2 +- + dlls/wined3d/wined3d_private.h | 6 ++++ + 5 files changed, 64 insertions(+), 3 deletions(-) + +diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c +index 7fc150878f0..554331051f1 100644 +--- a/dlls/wined3d/buffer.c ++++ b/dlls/wined3d/buffer.c +@@ -1063,7 +1063,7 @@ static void wined3d_buffer_init_data(struct wined3d_buffer *buffer, + if (buffer->flags & WINED3D_BUFFER_USE_BO) + { + wined3d_box_set(&box, 0, 0, resource->size, 1, 0, 1); +- device->cs->c.ops->update_sub_resource(&device->cs->c, resource, ++ wined3d_device_context_emit_update_sub_resource(&device->cs->c, resource, + 0, &box, data->data, data->row_pitch, data->slice_pitch); + } + else +diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c +index 47bc36d4cc0..a3124a229e1 100644 +--- a/dlls/wined3d/cs.c ++++ b/dlls/wined3d/cs.c +@@ -2649,6 +2649,40 @@ done: + wined3d_resource_release(resource); + } + ++void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context, ++ struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, ++ const void *data, unsigned int row_pitch, unsigned int slice_pitch) ++{ ++ struct wined3d_const_bo_address src_addr; ++ void *map_ptr; ++ ++ if ((map_ptr = context->ops->prepare_upload_bo(context, resource, sub_resource_idx, box, ++ row_pitch, slice_pitch, WINED3D_MAP_WRITE, &src_addr))) ++ { ++ struct wined3d_cs_update_sub_resource *op; ++ ++ wined3d_format_copy_data(resource->format, data, row_pitch, slice_pitch, map_ptr, row_pitch, slice_pitch, ++ box->right - box->left, box->bottom - box->top, box->back - box->front); ++ ++ op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); ++ op->opcode = WINED3D_CS_OP_UPDATE_SUB_RESOURCE; ++ op->resource = resource; ++ op->sub_resource_idx = sub_resource_idx; ++ op->box = *box; ++ op->addr = src_addr; ++ op->row_pitch = row_pitch; ++ op->slice_pitch = slice_pitch; ++ ++ wined3d_device_context_acquire_resource(context, resource); ++ ++ wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); ++ } ++ else ++ { ++ context->ops->update_sub_resource(context, resource, sub_resource_idx, box, data, row_pitch, slice_pitch); ++ } ++} ++ + static void wined3d_cs_update_sub_resource(struct wined3d_device_context *context, + struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, + const void *data, unsigned int row_pitch, unsigned int slice_pitch) +@@ -2946,12 +2980,21 @@ static void wined3d_cs_st_finish(struct wined3d_device_context *context, enum wi + { + } + ++static void *wined3d_cs_prepare_upload_bo(struct wined3d_device_context *context, struct wined3d_resource *resource, ++ unsigned int sub_resource_idx, const struct wined3d_box *box, unsigned int row_pitch, ++ unsigned int slice_pitch, uint32_t flags, struct wined3d_const_bo_address *address) ++{ ++ /* FIXME: We would like to return mapped or newly allocated memory here. */ ++ return NULL; ++} ++ + static const struct wined3d_device_context_ops wined3d_cs_st_ops = + { + wined3d_cs_st_require_space, + wined3d_cs_st_submit, + wined3d_cs_st_finish, + wined3d_cs_st_push_constants, ++ wined3d_cs_prepare_upload_bo, + wined3d_cs_map, + wined3d_cs_unmap, + wined3d_cs_update_sub_resource, +@@ -3080,6 +3123,7 @@ static const struct wined3d_device_context_ops wined3d_cs_mt_ops = + wined3d_cs_mt_submit, + wined3d_cs_mt_finish, + wined3d_cs_mt_push_constants, ++ wined3d_cs_prepare_upload_bo, + wined3d_cs_map, + wined3d_cs_unmap, + wined3d_cs_update_sub_resource, +@@ -3353,6 +3397,15 @@ 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); + } + ++static void *wined3d_deferred_context_prepare_upload_bo(struct wined3d_device_context *context, ++ struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, ++ unsigned int row_pitch, unsigned int slice_pitch, uint32_t flags, struct wined3d_const_bo_address *address) ++{ ++ FIXME("context %p, resource %p, sub_resource_idx %u, box %p, flags %#x, address %p, stub!\n", ++ context, resource, sub_resource_idx, box, flags, address); ++ return false; ++} ++ + static HRESULT wined3d_deferred_context_map(struct wined3d_device_context *context, struct wined3d_resource *resource, + unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags) + { +@@ -3430,6 +3483,7 @@ static const struct wined3d_device_context_ops wined3d_deferred_context_ops = + wined3d_deferred_context_submit, + wined3d_deferred_context_finish, + wined3d_deferred_context_push_constants, ++ wined3d_deferred_context_prepare_upload_bo, + wined3d_deferred_context_map, + wined3d_deferred_context_unmap, + wined3d_deferred_context_update_sub_resource, +diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c +index 96657141419..e37bf46594c 100644 +--- a/dlls/wined3d/device.c ++++ b/dlls/wined3d/device.c +@@ -4679,7 +4679,8 @@ void CDECL wined3d_device_context_update_sub_resource(struct wined3d_device_cont + return; + } + +- context->ops->update_sub_resource(context, resource, sub_resource_idx, box, data, row_pitch, depth_pitch); ++ wined3d_device_context_emit_update_sub_resource(context, resource, ++ sub_resource_idx, box, data, row_pitch, depth_pitch); + } + + void CDECL wined3d_device_context_resolve_sub_resource(struct wined3d_device_context *context, +diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c +index 62f38a1d592..c1247fbc56b 100644 +--- a/dlls/wined3d/texture.c ++++ b/dlls/wined3d/texture.c +@@ -4350,7 +4350,7 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct + for (i = 0; i < sub_count; ++i) + { + wined3d_texture_get_level_box(*texture, i % (*texture)->level_count, &box); +- device->cs->c.ops->update_sub_resource(&device->cs->c, &(*texture)->resource, ++ wined3d_device_context_emit_update_sub_resource(&device->cs->c, &(*texture)->resource, + i, &box, data[i].data, data[i].row_pitch, data[i].slice_pitch); + } + } +diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h +index 87c83d555e4..d85720e48b2 100644 +--- a/dlls/wined3d/wined3d_private.h ++++ b/dlls/wined3d/wined3d_private.h +@@ -4700,6 +4700,9 @@ struct wined3d_device_context_ops + void (*finish)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id); + void (*push_constants)(struct wined3d_device_context *context, enum wined3d_push_constants p, + unsigned int start_idx, unsigned int count, const void *constants); ++ void *(*prepare_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource, ++ unsigned int sub_resource_idx, const struct wined3d_box *box, unsigned int row_pitch, ++ unsigned int slice_pitch, uint32_t flags, struct wined3d_const_bo_address *address); + HRESULT (*map)(struct wined3d_device_context *context, struct wined3d_resource *resource, + unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags); + HRESULT (*unmap)(struct wined3d_device_context *context, struct wined3d_resource *resource, +@@ -4851,6 +4854,9 @@ void wined3d_device_context_emit_set_vertex_declaration(struct wined3d_device_co + struct wined3d_vertex_declaration *declaration) DECLSPEC_HIDDEN; + void wined3d_device_context_emit_set_viewports(struct wined3d_device_context *context, unsigned int viewport_count, + const struct wined3d_viewport *viewports) DECLSPEC_HIDDEN; ++void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context, ++ struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, ++ const void *data, unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN; + + static inline void wined3d_resource_wait_idle(struct wined3d_resource *resource) + { +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0007-wined3d-Implement-wined3d_deferred_context_prepare_u.patch b/patches/d3d11-Deferred_Context/0007-wined3d-Implement-wined3d_deferred_context_prepare_u.patch new file mode 100644 index 00000000..784f1a1a --- /dev/null +++ b/patches/d3d11-Deferred_Context/0007-wined3d-Implement-wined3d_deferred_context_prepare_u.patch @@ -0,0 +1,207 @@ +From 2df1209afb01d15b18a6c34a6c4450d9b0ca9ffe Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Wed, 23 Jun 2021 17:44:22 -0500 +Subject: [PATCH] wined3d: Implement + wined3d_deferred_context_prepare_upload_bo(). + +Signed-off-by: Zebediah Figura +--- + dlls/wined3d/cs.c | 64 ++++++++++++++++++++++++++++++++-- + dlls/wined3d/resource.c | 30 +++++++++------- + dlls/wined3d/wined3d_private.h | 3 ++ + 3 files changed, 81 insertions(+), 16 deletions(-) + +diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c +index a3124a229e1..80636943069 100644 +--- a/dlls/wined3d/cs.c ++++ b/dlls/wined3d/cs.c +@@ -26,6 +26,13 @@ WINE_DECLARE_DEBUG_CHANNEL(fps); + + #define WINED3D_INITIAL_CS_SIZE 4096 + ++struct wined3d_deferred_upload ++{ ++ struct wined3d_resource *resource; ++ unsigned int sub_resource_idx; ++ void *sysmem; ++}; ++ + struct wined3d_command_list + { + LONG refcount; +@@ -38,6 +45,9 @@ struct wined3d_command_list + SIZE_T resource_count; + struct wined3d_resource **resources; + ++ SIZE_T upload_count; ++ struct wined3d_deferred_upload *uploads; ++ + /* List of command lists queued for execution on this command list. We might + * be the only thing holding a pointer to another command list, so we need + * to hold a reference here (and in wined3d_deferred_context) as well. */ +@@ -48,9 +58,13 @@ struct wined3d_command_list + static void wined3d_command_list_destroy_object(void *object) + { + struct wined3d_command_list *list = object; ++ SIZE_T i; + + TRACE("list %p.\n", list); + ++ for (i = 0; i < list->upload_count; ++i) ++ wined3d_free_sysmem(list->uploads[i].sysmem); ++ + heap_free(list->resources); + heap_free(list->data); + heap_free(list); +@@ -3343,6 +3357,9 @@ struct wined3d_deferred_context + SIZE_T resource_count, resources_capacity; + struct wined3d_resource **resources; + ++ SIZE_T upload_count, uploads_capacity; ++ struct wined3d_deferred_upload *uploads; ++ + /* List of command lists queued for execution on this context. A command + * list can be the only thing holding a pointer to another command list, so + * we need to hold a reference here and in wined3d_command_list as well. */ +@@ -3401,9 +3418,44 @@ static void *wined3d_deferred_context_prepare_upload_bo(struct wined3d_device_co + struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, + unsigned int row_pitch, unsigned int slice_pitch, uint32_t flags, struct wined3d_const_bo_address *address) + { +- FIXME("context %p, resource %p, sub_resource_idx %u, box %p, flags %#x, address %p, stub!\n", +- context, resource, sub_resource_idx, box, flags, address); +- return false; ++ struct wined3d_deferred_context *deferred = wined3d_deferred_context_from_context(context); ++ const struct wined3d_format *format = resource->format; ++ struct wined3d_deferred_upload *upload; ++ void *sysmem; ++ size_t size; ++ ++ size = (box->back - box->front - 1) * slice_pitch ++ + ((box->bottom - box->top - 1) / format->block_height) * row_pitch ++ + ((box->right - box->left + format->block_width - 1) / format->block_width) * format->block_byte_count; ++ ++ if (!(flags & WINED3D_MAP_WRITE)) ++ { ++ WARN("Flags %#x are not valid on a deferred context.\n", flags); ++ return NULL; ++ } ++ ++ if (flags & ~(WINED3D_MAP_WRITE | WINED3D_MAP_DISCARD)) ++ { ++ FIXME("Unhandled flags %#x.\n", flags); ++ return NULL; ++ } ++ ++ if (!wined3d_array_reserve((void **)&deferred->uploads, &deferred->uploads_capacity, ++ deferred->upload_count + 1, sizeof(*deferred->uploads))) ++ return NULL; ++ ++ if (!(sysmem = wined3d_allocate_sysmem(size))) ++ return NULL; ++ ++ upload = &deferred->uploads[deferred->upload_count++]; ++ upload->resource = resource; ++ wined3d_resource_incref(resource); ++ upload->sub_resource_idx = sub_resource_idx; ++ upload->sysmem = sysmem; ++ ++ address->buffer_object = 0; ++ address->addr = sysmem; ++ return sysmem; + } + + static HRESULT wined3d_deferred_context_map(struct wined3d_device_context *context, struct wined3d_resource *resource, +@@ -3527,6 +3579,12 @@ void CDECL wined3d_deferred_context_destroy(struct wined3d_device_context *conte + + for (i = 0; i < deferred->resource_count; ++i) + wined3d_resource_decref(deferred->resources[i]); ++ ++ for (i = 0; i < deferred->upload_count; ++i) ++ { ++ wined3d_resource_decref(deferred->uploads[i].resource); ++ wined3d_free_sysmem(deferred->uploads[i].sysmem); ++ } + heap_free(deferred->resources); + + wined3d_state_destroy(deferred->c.state); +diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c +index f37c313e023..8e4be0e0315 100644 +--- a/dlls/wined3d/resource.c ++++ b/dlls/wined3d/resource.c +@@ -334,24 +334,33 @@ void CDECL wined3d_resource_preload(struct wined3d_resource *resource) + wined3d_cs_emit_preload_resource(resource->device->cs, resource); + } + +-static BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) ++void *wined3d_allocate_sysmem(SIZE_T size) + { + void **p; +- SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p); ++ static const SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p); + void *mem; + +- if (!(mem = heap_alloc_zero(resource->size + align))) ++ if (!(mem = heap_alloc_zero(size + align))) + { + ERR("Failed to allocate system memory.\n"); +- return FALSE; ++ return NULL; + } + ++ TRACE("Allocated %lu bytes at %p.\n", size, mem); + p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1; + *p = mem; + +- resource->heap_memory = ++p; ++ return ++p; ++} + +- return TRUE; ++void wined3d_free_sysmem(void *mem) ++{ ++ void **p = mem; ++ ++ if (!p) ++ return; ++ ++ heap_free(*(--p)); + } + + BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) +@@ -359,17 +368,12 @@ BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) + if (resource->heap_memory) + return TRUE; + +- return wined3d_resource_allocate_sysmem(resource); ++ return !!(resource->heap_memory = wined3d_allocate_sysmem(resource->size)); + } + + void wined3d_resource_free_sysmem(struct wined3d_resource *resource) + { +- void **p = resource->heap_memory; +- +- if (!p) +- return; +- +- heap_free(*(--p)); ++ wined3d_free_sysmem(resource->heap_memory); + resource->heap_memory = NULL; + } + +diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h +index d85720e48b2..074927a9e99 100644 +--- a/dlls/wined3d/wined3d_private.h ++++ b/dlls/wined3d/wined3d_private.h +@@ -4151,6 +4151,9 @@ void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DEC + #define RESOURCE_ALIGNMENT 16 + #define WINED3D_CONSTANT_BUFFER_ALIGNMENT 16 + ++void *wined3d_allocate_sysmem(SIZE_T size) DECLSPEC_HIDDEN; ++void wined3d_free_sysmem(void *mem) DECLSPEC_HIDDEN; ++ + #define WINED3D_LOCATION_DISCARDED 0x00000001 + #define WINED3D_LOCATION_SYSMEM 0x00000002 + #define WINED3D_LOCATION_BUFFER 0x00000008 +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0008-d3d11-Forbid-map-types-other-than-DISCARD-and-NOOVER.patch b/patches/d3d11-Deferred_Context/0008-d3d11-Forbid-map-types-other-than-DISCARD-and-NOOVER.patch new file mode 100644 index 00000000..61dfbb57 --- /dev/null +++ b/patches/d3d11-Deferred_Context/0008-d3d11-Forbid-map-types-other-than-DISCARD-and-NOOVER.patch @@ -0,0 +1,29 @@ +From 6fcb4ea61ecad68704e7793e56d69c5144e96716 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Wed, 23 Jun 2021 17:32:26 -0500 +Subject: [PATCH] d3d11: Forbid map types other than DISCARD and NOOVERWRITE on + a deferred context. + +Signed-off-by: Zebediah Figura +--- + dlls/d3d11/device.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c +index 56f34c70ea1..d043af7051a 100644 +--- a/dlls/d3d11/device.c ++++ b/dlls/d3d11/device.c +@@ -744,6 +744,10 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_context_Map(ID3D11DeviceContext1 * + if (map_flags) + FIXME("Ignoring map_flags %#x.\n", map_flags); + ++ if (context->type != D3D11_DEVICE_CONTEXT_IMMEDIATE ++ && map_type != D3D11_MAP_WRITE_DISCARD && map_type != D3D11_MAP_WRITE_NO_OVERWRITE) ++ return E_INVALIDARG; ++ + wined3d_resource = wined3d_resource_from_d3d11_resource(resource); + + wined3d_mutex_lock(); +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0009-wined3d-Use-context-ops-prepare_upload_bo-in-wined3d.patch b/patches/d3d11-Deferred_Context/0009-wined3d-Use-context-ops-prepare_upload_bo-in-wined3d.patch new file mode 100644 index 00000000..cb51d9fa --- /dev/null +++ b/patches/d3d11-Deferred_Context/0009-wined3d-Use-context-ops-prepare_upload_bo-in-wined3d.patch @@ -0,0 +1,350 @@ +From 9cdb51692c64f5837504751096fe5af065c34473 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Wed, 23 Jun 2021 17:05:09 -0500 +Subject: [PATCH] wined3d: Use context->ops->prepare_upload_bo() in + wined3d_device_context_map() if possible. + +This has the notable effect of implementing maps on deferred contexts. + +Signed-off-by: Zebediah Figura +--- + dlls/d3d11/tests/d3d11.c | 57 +++++++++++++------------- + dlls/wined3d/cs.c | 73 +++++++++++++++++++++++++++------- + dlls/wined3d/device.c | 38 ++++++++++++++++-- + dlls/wined3d/wined3d_private.h | 5 +++ + 4 files changed, 126 insertions(+), 47 deletions(-) + +diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c +index 67ac37703e4..8442191b83c 100644 +--- a/dlls/d3d11/tests/d3d11.c ++++ b/dlls/d3d11/tests/d3d11.c +@@ -33059,21 +33059,13 @@ static void test_deferred_context_map(void) + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc); +- todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); ++ ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); + todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc); +- todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); +- if (hr != S_OK) +- { +- ID3D11Buffer_Release(buffer2); +- ID3D11Buffer_Release(buffer); +- ID3D11DeviceContext_Release(deferred); +- release_test_context(&test_context); +- return; +- } ++ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + map_data = map_desc.pData; + /* The previous contents of map_data are undefined and may in practice be + * uninitialized garbage. */ +@@ -33122,13 +33114,14 @@ static void test_deferred_context_map(void) + ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); +- ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr); ++ todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + map_data = map_desc.pData; + for (i = 0; i < ARRAY_SIZE(data); ++i) + map_data[i] = 2 * i; ++ memcpy(data, map_data, sizeof(data)); + ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc); +@@ -33141,32 +33134,38 @@ static void test_deferred_context_map(void) + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); +- ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ++ todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + +- map_data = map_desc.pData; +- for (i = 0; i < ARRAY_SIZE(data); ++i) ++ if (hr == S_OK) + { +- ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i); +- if (i % 2) +- map_data[i] = 3 * i; +- } +- memcpy(data, map_data, sizeof(data)); ++ map_data = map_desc.pData; ++ for (i = 0; i < ARRAY_SIZE(data); ++i) ++ { ++ ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i); ++ if (i % 2) ++ map_data[i] = 3 * i; ++ } ++ memcpy(data, map_data, sizeof(data)); + +- ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); ++ ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); ++ } + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); +- ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ++ todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + +- map_data = map_desc.pData; +- for (i = 0; i < ARRAY_SIZE(data); ++i) ++ if (hr == S_OK) + { +- ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i); +- if (i % 3) +- map_data[i] = 4 * i; +- } +- memcpy(data, map_data, sizeof(data)); ++ map_data = map_desc.pData; ++ for (i = 0; i < ARRAY_SIZE(data); ++i) ++ { ++ ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i); ++ if (i % 3) ++ map_data[i] = 4 * i; ++ } ++ memcpy(data, map_data, sizeof(data)); + +- ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); ++ ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); ++ } + + hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list); + ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr); +diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c +index 80636943069..c70606ad036 100644 +--- a/dlls/wined3d/cs.c ++++ b/dlls/wined3d/cs.c +@@ -31,6 +31,7 @@ struct wined3d_deferred_upload + struct wined3d_resource *resource; + unsigned int sub_resource_idx; + void *sysmem; ++ struct wined3d_box box; + }; + + struct wined3d_command_list +@@ -2663,6 +2664,29 @@ done: + wined3d_resource_release(resource); + } + ++void wined3d_device_context_upload_bo(struct wined3d_device_context *context, ++ struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, ++ const struct wined3d_const_bo_address *addr, unsigned int row_pitch, unsigned int slice_pitch) ++{ ++ struct wined3d_cs_update_sub_resource *op; ++ ++ TRACE("context %p, resource %p, sub_resource_idx %u, box %s, addr %s, row_pitch %u, slice_pitch %u.\n", ++ context, resource, sub_resource_idx, debug_box(box), debug_const_bo_address(addr), row_pitch, slice_pitch); ++ ++ op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); ++ op->opcode = WINED3D_CS_OP_UPDATE_SUB_RESOURCE; ++ op->resource = resource; ++ op->sub_resource_idx = sub_resource_idx; ++ op->box = *box; ++ op->addr = *addr; ++ op->row_pitch = row_pitch; ++ op->slice_pitch = slice_pitch; ++ ++ wined3d_device_context_acquire_resource(context, resource); ++ ++ wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); ++} ++ + void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context, + struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, + const void *data, unsigned int row_pitch, unsigned int slice_pitch) +@@ -2673,23 +2697,9 @@ void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_conte + if ((map_ptr = context->ops->prepare_upload_bo(context, resource, sub_resource_idx, box, + row_pitch, slice_pitch, WINED3D_MAP_WRITE, &src_addr))) + { +- struct wined3d_cs_update_sub_resource *op; +- + wined3d_format_copy_data(resource->format, data, row_pitch, slice_pitch, map_ptr, row_pitch, slice_pitch, + box->right - box->left, box->bottom - box->top, box->back - box->front); +- +- op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); +- op->opcode = WINED3D_CS_OP_UPDATE_SUB_RESOURCE; +- op->resource = resource; +- op->sub_resource_idx = sub_resource_idx; +- op->box = *box; +- op->addr = src_addr; +- op->row_pitch = row_pitch; +- op->slice_pitch = slice_pitch; +- +- wined3d_device_context_acquire_resource(context, resource); +- +- wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); ++ wined3d_device_context_upload_bo(context, resource, sub_resource_idx, box, &src_addr, row_pitch, slice_pitch); + } + else + { +@@ -3002,6 +3012,12 @@ static void *wined3d_cs_prepare_upload_bo(struct wined3d_device_context *context + return NULL; + } + ++static bool wined3d_cs_get_upload_bo(struct wined3d_device_context *context, struct wined3d_resource *resource, ++ unsigned int sub_resource_idx, struct wined3d_box *box, struct wined3d_const_bo_address *address) ++{ ++ return false; ++} ++ + static const struct wined3d_device_context_ops wined3d_cs_st_ops = + { + wined3d_cs_st_require_space, +@@ -3009,6 +3025,7 @@ static const struct wined3d_device_context_ops wined3d_cs_st_ops = + wined3d_cs_st_finish, + wined3d_cs_st_push_constants, + wined3d_cs_prepare_upload_bo, ++ wined3d_cs_get_upload_bo, + wined3d_cs_map, + wined3d_cs_unmap, + wined3d_cs_update_sub_resource, +@@ -3138,6 +3155,7 @@ static const struct wined3d_device_context_ops wined3d_cs_mt_ops = + wined3d_cs_mt_finish, + wined3d_cs_mt_push_constants, + wined3d_cs_prepare_upload_bo, ++ wined3d_cs_get_upload_bo, + wined3d_cs_map, + wined3d_cs_unmap, + wined3d_cs_update_sub_resource, +@@ -3452,12 +3470,36 @@ static void *wined3d_deferred_context_prepare_upload_bo(struct wined3d_device_co + wined3d_resource_incref(resource); + upload->sub_resource_idx = sub_resource_idx; + upload->sysmem = sysmem; ++ upload->box = *box; + + address->buffer_object = 0; + address->addr = sysmem; + return sysmem; + } + ++static bool wined3d_deferred_context_get_upload_bo(struct wined3d_device_context *context, ++ struct wined3d_resource *resource, unsigned int sub_resource_idx, ++ struct wined3d_box *box, struct wined3d_const_bo_address *address) ++{ ++ struct wined3d_deferred_context *deferred = wined3d_deferred_context_from_context(context); ++ int i = deferred->upload_count; ++ ++ while (i--) ++ { ++ struct wined3d_deferred_upload *upload = &deferred->uploads[i]; ++ ++ if (upload->resource == resource && upload->sub_resource_idx == sub_resource_idx) ++ { ++ *box = upload->box; ++ address->buffer_object = 0; ++ address->addr = upload->sysmem; ++ return true; ++ } ++ } ++ ++ return false; ++} ++ + static HRESULT wined3d_deferred_context_map(struct wined3d_device_context *context, struct wined3d_resource *resource, + unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags) + { +@@ -3536,6 +3578,7 @@ static const struct wined3d_device_context_ops wined3d_deferred_context_ops = + wined3d_deferred_context_finish, + wined3d_deferred_context_push_constants, + wined3d_deferred_context_prepare_upload_bo, ++ wined3d_deferred_context_get_upload_bo, + wined3d_deferred_context_map, + wined3d_deferred_context_unmap, + wined3d_deferred_context_update_sub_resource, +diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c +index e37bf46594c..774c77d1374 100644 +--- a/dlls/wined3d/device.c ++++ b/dlls/wined3d/device.c +@@ -4833,7 +4833,10 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context, + struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags) + { + struct wined3d_sub_resource_desc desc; ++ struct wined3d_const_bo_address addr; ++ unsigned int row_pitch, slice_pitch; + struct wined3d_box b; ++ void *map_ptr; + HRESULT hr; + + TRACE("context %p, resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", +@@ -4878,18 +4881,47 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context, + return WINED3DERR_INVALIDCALL; + } + ++ wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch); ++ ++ if ((map_ptr = context->ops->prepare_upload_bo(context, resource, ++ sub_resource_idx, box, row_pitch, slice_pitch, flags, &addr))) ++ { ++ TRACE("Returning upload bo %s, data %p, row pitch %u, slice pitch %u.\n", ++ debug_const_bo_address(&addr), map_ptr, row_pitch, slice_pitch); ++ map_desc->data = map_ptr; ++ map_desc->row_pitch = row_pitch; ++ map_desc->slice_pitch = slice_pitch; ++ return WINED3D_OK; ++ } ++ + 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); ++ { ++ map_desc->row_pitch = row_pitch; ++ map_desc->slice_pitch = slice_pitch; ++ } + return hr; + } + + HRESULT CDECL wined3d_device_context_unmap(struct wined3d_device_context *context, + struct wined3d_resource *resource, unsigned int sub_resource_idx) + { ++ struct wined3d_const_bo_address addr; ++ struct wined3d_box box; ++ + TRACE("context %p, resource %p, sub_resource_idx %u.\n", context, resource, sub_resource_idx); + +- return context->ops->unmap(context, resource, sub_resource_idx); ++ if (context->ops->get_upload_bo(context, resource, sub_resource_idx, &box, &addr)) ++ { ++ unsigned int row_pitch, slice_pitch; ++ ++ wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch); ++ wined3d_device_context_upload_bo(context, resource, sub_resource_idx, &box, &addr, row_pitch, slice_pitch); ++ return WINED3D_OK; ++ } ++ else ++ { ++ return context->ops->unmap(context, resource, sub_resource_idx); ++ } + } + + void CDECL wined3d_device_context_issue_query(struct wined3d_device_context *context, +diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h +index 074927a9e99..e10a2d48f23 100644 +--- a/dlls/wined3d/wined3d_private.h ++++ b/dlls/wined3d/wined3d_private.h +@@ -4706,6 +4706,8 @@ struct wined3d_device_context_ops + void *(*prepare_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource, + unsigned int sub_resource_idx, const struct wined3d_box *box, unsigned int row_pitch, + unsigned int slice_pitch, uint32_t flags, struct wined3d_const_bo_address *address); ++ bool (*get_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource, ++ unsigned int sub_resource_idx, struct wined3d_box *box, struct wined3d_const_bo_address *address); + HRESULT (*map)(struct wined3d_device_context *context, struct wined3d_resource *resource, + unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, unsigned int flags); + HRESULT (*unmap)(struct wined3d_device_context *context, struct wined3d_resource *resource, +@@ -4860,6 +4862,9 @@ void wined3d_device_context_emit_set_viewports(struct wined3d_device_context *co + void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context, + struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, + const void *data, unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN; ++void wined3d_device_context_upload_bo(struct wined3d_device_context *context, ++ struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, ++ const struct wined3d_const_bo_address *addr, unsigned int row_pitch, unsigned int slice_pitch); + + static inline void wined3d_resource_wait_idle(struct wined3d_resource *resource) + { +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0010-wined3d-Implement-NOOVERWITE-maps-in-wined3d_deferre.patch b/patches/d3d11-Deferred_Context/0010-wined3d-Implement-NOOVERWITE-maps-in-wined3d_deferre.patch new file mode 100644 index 00000000..1c3d144c --- /dev/null +++ b/patches/d3d11-Deferred_Context/0010-wined3d-Implement-NOOVERWITE-maps-in-wined3d_deferre.patch @@ -0,0 +1,113 @@ +From 95d7fb8450b3f407e5f794537ca3263cf0c63164 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Wed, 23 Jun 2021 19:19:58 -0500 +Subject: [PATCH] wined3d: Implement NOOVERWITE maps in + wined3d_deferred_context_prepare_upload_bo(). + +Signed-off-by: Zebediah Figura +--- + dlls/d3d11/tests/d3d11.c | 42 +++++++++++++++++----------------------- + dlls/wined3d/cs.c | 21 +++++++++++++++++++- + 2 files changed, 38 insertions(+), 25 deletions(-) + +diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c +index 8442191b83c..82da0c38784 100644 +--- a/dlls/d3d11/tests/d3d11.c ++++ b/dlls/d3d11/tests/d3d11.c +@@ -33134,38 +33134,32 @@ static void test_deferred_context_map(void) + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); +- todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ++ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + +- if (hr == S_OK) ++ map_data = map_desc.pData; ++ for (i = 0; i < ARRAY_SIZE(data); ++i) + { +- map_data = map_desc.pData; +- for (i = 0; i < ARRAY_SIZE(data); ++i) +- { +- ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i); +- if (i % 2) +- map_data[i] = 3 * i; +- } +- memcpy(data, map_data, sizeof(data)); +- +- ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); ++ ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i); ++ if (i % 2) ++ map_data[i] = 3 * i; + } ++ memcpy(data, map_data, sizeof(data)); ++ ++ ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); + + hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); +- todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ++ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + +- if (hr == S_OK) ++ map_data = map_desc.pData; ++ for (i = 0; i < ARRAY_SIZE(data); ++i) + { +- map_data = map_desc.pData; +- for (i = 0; i < ARRAY_SIZE(data); ++i) +- { +- ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i); +- if (i % 3) +- map_data[i] = 4 * i; +- } +- memcpy(data, map_data, sizeof(data)); +- +- ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); ++ ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i); ++ if (i % 3) ++ map_data[i] = 4 * i; + } ++ memcpy(data, map_data, sizeof(data)); ++ ++ ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0); + + hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list); + ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr); +diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c +index c70606ad036..51fb4eefcd9 100644 +--- a/dlls/wined3d/cs.c ++++ b/dlls/wined3d/cs.c +@@ -3452,12 +3452,31 @@ static void *wined3d_deferred_context_prepare_upload_bo(struct wined3d_device_co + return NULL; + } + +- if (flags & ~(WINED3D_MAP_WRITE | WINED3D_MAP_DISCARD)) ++ if (flags & ~(WINED3D_MAP_WRITE | WINED3D_MAP_DISCARD | WINED3D_MAP_NOOVERWRITE)) + { + FIXME("Unhandled flags %#x.\n", flags); + return NULL; + } + ++ if (flags & WINED3D_MAP_NOOVERWRITE) ++ { ++ int i = deferred->upload_count; ++ ++ while (i--) ++ { ++ struct wined3d_deferred_upload *upload = &deferred->uploads[i]; ++ ++ if (upload->resource == resource && upload->sub_resource_idx == sub_resource_idx) ++ { ++ address->buffer_object = 0; ++ address->addr = upload->sysmem; ++ return upload->sysmem; ++ } ++ } ++ ++ return NULL; ++ } ++ + if (!wined3d_array_reserve((void **)&deferred->uploads, &deferred->uploads_capacity, + deferred->upload_count + 1, sizeof(*deferred->uploads))) + return NULL; +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0011-wined3d-Print-a-message-when-forcing-CS-serializatio.patch b/patches/d3d11-Deferred_Context/0011-wined3d-Print-a-message-when-forcing-CS-serializatio.patch new file mode 100644 index 00000000..3f214024 --- /dev/null +++ b/patches/d3d11-Deferred_Context/0011-wined3d-Print-a-message-when-forcing-CS-serializatio.patch @@ -0,0 +1,27 @@ +From ecdb057520bc11f91ffc18d362f5e5df69593fd1 Mon Sep 17 00:00:00 2001 +From: Zebediah Figura +Date: Fri, 25 Jun 2021 18:04:47 -0500 +Subject: [PATCH] wined3d: Print a message when forcing CS serialization. + +Signed-off-by: Zebediah Figura +--- + dlls/wined3d/cs.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c +index 51fb4eefcd9..b696c130192 100644 +--- a/dlls/wined3d/cs.c ++++ b/dlls/wined3d/cs.c +@@ -3303,6 +3303,9 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device, + cs->c.device = device; + cs->serialize_commands = TRACE_ON(d3d_sync) || wined3d_settings.cs_multithreaded & WINED3D_CSMT_SERIALIZE; + ++ if (cs->serialize_commands) ++ ERR_(d3d_sync)("Forcing serialization of all command streams.\n"); ++ + state_init(&cs->state, d3d_info, WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT, cs->c.state->feature_level); + + cs->data_size = WINED3D_INITIAL_CS_SIZE; +-- +2.30.2 + diff --git a/patches/d3d11-Deferred_Context/0013-wined3d-Implement-wined3d_deferred_context_update_su.patch b/patches/d3d11-Deferred_Context/0013-wined3d-Implement-wined3d_deferred_context_update_su.patch deleted file mode 100644 index 1c6fd946..00000000 --- a/patches/d3d11-Deferred_Context/0013-wined3d-Implement-wined3d_deferred_context_update_su.patch +++ /dev/null @@ -1,92 +0,0 @@ -From f0cfa1dc94330d07589e09ae5961956364adac4d Mon Sep 17 00:00:00 2001 -From: Zebediah Figura -Date: Fri, 14 May 2021 15:51:55 -0500 -Subject: [PATCH] wined3d: Implement - wined3d_deferred_context_update_sub_resource(). - -Needed by Wolcen: Lords of Mayhem. - -Signed-off-by: Zebediah Figura ---- - dlls/wined3d/cs.c | 37 +++++++++++++++++++++++++++++++++---- - 1 file changed, 33 insertions(+), 4 deletions(-) - -diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c -index 50a08334dab..e6f84134795 100644 ---- a/dlls/wined3d/cs.c -+++ b/dlls/wined3d/cs.c -@@ -490,6 +490,7 @@ struct wined3d_cs_update_sub_resource - unsigned int sub_resource_idx; - struct wined3d_box box; - struct wined3d_sub_resource_data data; -+ /* If data.data is NULL, the structure is followed by the data in memory. */ - }; - - struct wined3d_cs_add_dirty_texture_region -@@ -2597,6 +2598,7 @@ void wined3d_device_context_emit_blt_sub_resource(struct wined3d_device_context - static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const void *data) - { - const struct wined3d_cs_update_sub_resource *op = data; -+ const void *src_data = op->data.data ? op->data.data : (const BYTE *)(op + 1); - struct wined3d_resource *resource = op->resource; - const struct wined3d_box *box = &op->box; - unsigned int width, height, depth, level; -@@ -2617,7 +2619,7 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi - goto done; - } - -- wined3d_buffer_upload_data(buffer, context, box, op->data.data); -+ wined3d_buffer_upload_data(buffer, context, box, src_data); - wined3d_buffer_invalidate_location(buffer, ~WINED3D_LOCATION_BUFFER); - goto done; - } -@@ -2630,7 +2632,7 @@ static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs *cs, const voi - depth = wined3d_texture_get_level_depth(texture, level); - - addr.buffer_object = 0; -- addr.addr = op->data.data; -+ addr.addr = src_data; - - /* Only load the sub-resource for partial updates. */ - if (!box->left && !box->top && !box->front -@@ -3375,8 +3377,35 @@ static void wined3d_deferred_context_update_sub_resource(struct wined3d_device_c - struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, - const void *data, unsigned int row_pitch, unsigned int slice_pitch) - { -- FIXME("context %p, resource %p, sub_resource_idx %u, box %s, data %p, row_pitch %u, slice_pitch %u, stub!\n", -- context, resource, sub_resource_idx, debug_box(box), data, row_pitch, slice_pitch); -+ struct wined3d_cs_update_sub_resource *op; -+ size_t data_size; -+ -+ if (resource->type == WINED3D_RTYPE_BUFFER) -+ { -+ data_size = box->right - box->left; -+ } -+ else -+ { -+ const struct wined3d_format *format = resource->format; -+ -+ data_size = (box->back - box->front - 1) * slice_pitch -+ + ((box->bottom - box->top - 1) / format->block_height) * row_pitch -+ + ((box->right - box->left + format->block_width - 1) / format->block_width) * format->block_byte_count; -+ } -+ -+ op = wined3d_device_context_require_space(context, sizeof(*op) + data_size, WINED3D_CS_QUEUE_DEFAULT); -+ op->opcode = WINED3D_CS_OP_UPDATE_SUB_RESOURCE; -+ 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 = NULL; -+ memcpy(op + 1, data, data_size); -+ -+ wined3d_device_context_acquire_resource(context, resource); -+ -+ wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); - } - - static void wined3d_deferred_context_issue_query(struct wined3d_device_context *context, --- -2.30.2 - diff --git a/patches/d3d11-Deferred_Context/0014-wined3d-Implement-wined3d_deferred_context_map.patch b/patches/d3d11-Deferred_Context/0014-wined3d-Implement-wined3d_deferred_context_map.patch deleted file mode 100644 index 8a26926e..00000000 --- a/patches/d3d11-Deferred_Context/0014-wined3d-Implement-wined3d_deferred_context_map.patch +++ /dev/null @@ -1,461 +0,0 @@ -From cff68ab6407f62fa76e00d28532f741aa6498ad1 Mon Sep 17 00:00:00 2001 -From: Zebediah Figura -Date: Wed, 19 May 2021 19:00:56 -0500 -Subject: [PATCH] wined3d: Implement wined3d_deferred_context_map(). - -Signed-off-by: Zebediah Figura ---- - dlls/d3d11/tests/d3d11.c | 15 +--- - dlls/wined3d/buffer.c | 14 ++++ - dlls/wined3d/cs.c | 136 ++++++++++++++++++++++++++++++--- - dlls/wined3d/resource.c | 29 +++---- - dlls/wined3d/texture.c | 25 ++++++ - dlls/wined3d/wined3d_private.h | 5 ++ - 6 files changed, 189 insertions(+), 35 deletions(-) - -diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c -index 408c0492cd2..a2fdc116e61 100644 ---- a/dlls/d3d11/tests/d3d11.c -+++ b/dlls/d3d11/tests/d3d11.c -@@ -32735,21 +32735,14 @@ static void test_deferred_context_map(void) - ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); - - hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc); -- todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); -+ ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); - - hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc); -- todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr); -+ ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr); - - hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc); -- todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); -- if (hr != S_OK) -- { -- ID3D11Buffer_Release(buffer2); -- ID3D11Buffer_Release(buffer); -- ID3D11DeviceContext_Release(deferred); -- release_test_context(&test_context); -- return; -- } -+ ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); -+ - map_data = map_desc.pData; - /* The previous contents of map_data are undefined and may in practice be - * uninitialized garbage. */ -diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c -index 12d038c0120..12b90cb54c2 100644 ---- a/dlls/wined3d/buffer.c -+++ b/dlls/wined3d/buffer.c -@@ -826,6 +826,19 @@ struct wined3d_resource * CDECL wined3d_buffer_get_resource(struct wined3d_buffe - return &buffer->resource; - } - -+static HRESULT buffer_resource_sub_resource_get_size(struct wined3d_resource *resource, -+ unsigned int sub_resource_idx, unsigned int *size, unsigned int *row_pitch, unsigned int *slice_pitch) -+{ -+ if (sub_resource_idx) -+ { -+ WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx); -+ return E_INVALIDARG; -+ } -+ -+ *size = *row_pitch = *slice_pitch = 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) - { -@@ -1084,6 +1097,7 @@ static const struct wined3d_resource_ops buffer_resource_ops = - buffer_resource_decref, - buffer_resource_preload, - buffer_resource_unload, -+ buffer_resource_sub_resource_get_size, - buffer_resource_sub_resource_map, - buffer_resource_sub_resource_unmap, - }; -diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c -index e6f84134795..1f7213232fa 100644 ---- a/dlls/wined3d/cs.c -+++ b/dlls/wined3d/cs.c -@@ -26,6 +26,13 @@ WINE_DECLARE_DEBUG_CHANNEL(fps); - - #define WINED3D_INITIAL_CS_SIZE 4096 - -+struct wined3d_acquired_resource -+{ -+ struct wined3d_resource *resource; -+ unsigned int sub_resource_idx; -+ void *sysmem; -+}; -+ - struct wined3d_command_list - { - LONG refcount; -@@ -36,7 +43,7 @@ struct wined3d_command_list - void *data; - - SIZE_T resource_count; -- struct wined3d_resource **resources; -+ struct wined3d_acquired_resource *resources; - - /* List of command lists queued for execution on this command list. We might - * be the only thing holding a pointer to another command list, so we need -@@ -48,9 +55,13 @@ struct wined3d_command_list - static void wined3d_command_list_destroy_object(void *object) - { - struct wined3d_command_list *list = object; -+ SIZE_T i; - - TRACE("list %p.\n", list); - -+ for (i = 0; i < list->resource_count; ++i) -+ wined3d_free_sysmem(list->resources[i].sysmem); -+ - heap_free(list->resources); - heap_free(list->data); - heap_free(list); -@@ -79,7 +90,7 @@ ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list) - for (i = 0; i < list->command_list_count; ++i) - wined3d_command_list_decref(list->command_lists[i]); - for (i = 0; i < list->resource_count; ++i) -- wined3d_resource_decref(list->resources[i]); -+ wined3d_resource_decref(list->resources[i].resource); - - wined3d_cs_destroy_object(device->cs, wined3d_command_list_destroy_object, list); - } -@@ -139,6 +150,7 @@ enum wined3d_cs_op - WINED3D_CS_OP_COPY_UAV_COUNTER, - WINED3D_CS_OP_GENERATE_MIPMAPS, - WINED3D_CS_OP_EXECUTE_COMMAND_LIST, -+ WINED3D_CS_OP_UPLOAD_SUB_RESOURCE, - WINED3D_CS_OP_STOP, - }; - -@@ -469,6 +481,15 @@ struct wined3d_cs_unmap - HRESULT *hr; - }; - -+struct wined3d_cs_upload_sub_resource -+{ -+ enum wined3d_cs_op opcode; -+ struct wined3d_resource *resource; -+ unsigned int sub_resource_idx; -+ unsigned int size; -+ const void *data; -+}; -+ - struct wined3d_cs_blt_sub_resource - { - enum wined3d_cs_op opcode; -@@ -616,6 +637,7 @@ static const char *debug_cs_op(enum wined3d_cs_op op) - WINED3D_TO_STR(WINED3D_CS_OP_COPY_UAV_COUNTER); - WINED3D_TO_STR(WINED3D_CS_OP_GENERATE_MIPMAPS); - WINED3D_TO_STR(WINED3D_CS_OP_EXECUTE_COMMAND_LIST); -+ WINED3D_TO_STR(WINED3D_CS_OP_UPLOAD_SUB_RESOURCE); - WINED3D_TO_STR(WINED3D_CS_OP_STOP); - #undef WINED3D_TO_STR - } -@@ -2342,7 +2364,7 @@ static void wined3d_cs_execute_command_list(struct wined3d_device_context *conte - op->list = list; - - for (i = 0; i < list->resource_count; ++i) -- wined3d_resource_acquire(list->resources[i]); -+ wined3d_resource_acquire(list->resources[i].resource); - - wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); - -@@ -2463,6 +2485,28 @@ static HRESULT wined3d_cs_unmap(struct wined3d_device_context *context, struct w - return hr; - } - -+static void wined3d_cs_exec_upload_sub_resource(struct wined3d_cs *cs, const void *data) -+{ -+ const struct wined3d_cs_upload_sub_resource *op = data; -+ struct wined3d_resource *resource = op->resource; -+ unsigned int sub_resource_idx = op->sub_resource_idx; -+ struct wined3d_map_desc map_desc; -+ HRESULT hr; -+ -+ if (FAILED(hr = resource->resource_ops->resource_sub_resource_map(resource, -+ sub_resource_idx, &map_desc, NULL, WINED3D_MAP_WRITE | WINED3D_MAP_DISCARD))) -+ { -+ ERR("Failed to map resource, hr %#x.\n", hr); -+ return; -+ } -+ -+ memcpy(map_desc.data, op->data, op->size); -+ -+ resource->resource_ops->resource_sub_resource_unmap(resource, sub_resource_idx); -+ -+ wined3d_resource_release(resource); -+} -+ - static void wined3d_cs_exec_blt_sub_resource(struct wined3d_cs *cs, const void *data) - { - const struct wined3d_cs_blt_sub_resource *op = data; -@@ -2870,6 +2914,7 @@ static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void - /* WINED3D_CS_OP_COPY_UAV_COUNTER */ wined3d_cs_exec_copy_uav_counter, - /* WINED3D_CS_OP_GENERATE_MIPMAPS */ wined3d_cs_exec_generate_mipmaps, - /* WINED3D_CS_OP_EXECUTE_COMMAND_LIST */ wined3d_cs_exec_execute_command_list, -+ /* WINED3D_CS_OP_UPLOAD_SUB_RESOURCE */ wined3d_cs_exec_upload_sub_resource, - }; - - static void wined3d_cs_exec_execute_command_list(struct wined3d_cs *cs, const void *data) -@@ -3301,7 +3346,7 @@ struct wined3d_deferred_context - void *data; - - SIZE_T resource_count, resources_capacity; -- struct wined3d_resource **resources; -+ struct wined3d_acquired_resource *resources; - - /* List of command lists queued for execution on this context. A command - * list can be the only thing holding a pointer to another command list, so -@@ -3361,16 +3406,78 @@ static HRESULT wined3d_deferred_context_map(struct wined3d_device_context *conte - struct wined3d_resource *resource, unsigned int sub_resource_idx, - 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", -- context, resource, sub_resource_idx, map_desc, box, flags); -- return E_NOTIMPL; -+ struct wined3d_deferred_context *deferred = wined3d_deferred_context_from_context(context); -+ struct wined3d_acquired_resource *acquired_resource; -+ unsigned int size; -+ HRESULT hr; -+ -+ if (box) -+ { -+ ERR("Unexpected box.\n"); -+ return E_INVALIDARG; -+ } -+ -+ if (FAILED(hr = resource->resource_ops->resource_sub_resource_get_size(resource, -+ sub_resource_idx, &size, &map_desc->row_pitch, &map_desc->slice_pitch))) -+ return E_INVALIDARG; -+ -+ if (flags & WINED3D_MAP_DISCARD) -+ { -+ struct wined3d_cs_upload_sub_resource *op; -+ void *sysmem; -+ -+ if (!(sysmem = wined3d_allocate_sysmem(size))) -+ return E_OUTOFMEMORY; -+ -+ if (!wined3d_array_reserve((void **)&deferred->resources, &deferred->resources_capacity, -+ deferred->resource_count + 1, sizeof(*deferred->resources))) -+ return E_OUTOFMEMORY; -+ -+ acquired_resource = &deferred->resources[deferred->resource_count++]; -+ acquired_resource->resource = resource; -+ wined3d_resource_incref(resource); -+ acquired_resource->sub_resource_idx = sub_resource_idx; -+ acquired_resource->sysmem = sysmem; -+ -+ op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); -+ op->opcode = WINED3D_CS_OP_UPLOAD_SUB_RESOURCE; -+ op->resource = resource; -+ op->sub_resource_idx = sub_resource_idx; -+ op->size = size; -+ op->data = sysmem; -+ -+ map_desc->data = sysmem; -+ return S_OK; -+ } -+ else if (flags & WINED3D_MAP_NOOVERWRITE) -+ { -+ int i = deferred->resource_count; -+ -+ while (i--) -+ { -+ acquired_resource = &deferred->resources[i]; -+ -+ if (acquired_resource->resource == resource -+ && acquired_resource->sub_resource_idx == sub_resource_idx && acquired_resource->sysmem) -+ { -+ map_desc->data = acquired_resource->sysmem; -+ return S_OK; -+ } -+ } -+ -+ return D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD; -+ } -+ else -+ { -+ WARN("Invalid flags %#x, returning E_INVALIDARG.\n", flags); -+ return E_INVALIDARG; -+ } - } - - static HRESULT wined3d_deferred_context_unmap(struct wined3d_device_context *context, - struct wined3d_resource *resource, unsigned int sub_resource_idx) - { -- FIXME("context %p, resource %p, sub_resource_idx %u, stub!\n", context, resource, sub_resource_idx); -- return E_NOTIMPL; -+ return S_OK; - } - - static void wined3d_deferred_context_update_sub_resource(struct wined3d_device_context *context, -@@ -3423,13 +3530,17 @@ static void wined3d_deferred_context_acquire_resource(struct wined3d_device_cont - struct wined3d_resource *resource) - { - struct wined3d_deferred_context *deferred = wined3d_deferred_context_from_context(context); -+ struct wined3d_acquired_resource *acquired_resource; - - if (!wined3d_array_reserve((void **)&deferred->resources, &deferred->resources_capacity, - deferred->resource_count + 1, sizeof(*deferred->resources))) - return; - -- deferred->resources[deferred->resource_count++] = resource; -+ acquired_resource = &deferred->resources[deferred->resource_count++]; -+ acquired_resource->resource = resource; - wined3d_resource_incref(resource); -+ acquired_resource->sub_resource_idx = 0; -+ acquired_resource->sysmem = NULL; - } - - static void wined3d_deferred_context_execute_command_list(struct wined3d_device_context *context, -@@ -3504,7 +3615,10 @@ void CDECL wined3d_deferred_context_destroy(struct wined3d_device_context *conte - TRACE("context %p.\n", context); - - for (i = 0; i < deferred->resource_count; ++i) -- wined3d_resource_decref(deferred->resources[i]); -+ { -+ wined3d_resource_decref(deferred->resources[i].resource); -+ wined3d_free_sysmem(deferred->resources[i].sysmem); -+ } - heap_free(deferred->resources); - - wined3d_state_destroy(deferred->c.state); -diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c -index 58e3e5c77fd..42e45a2745c 100644 ---- a/dlls/wined3d/resource.c -+++ b/dlls/wined3d/resource.c -@@ -334,24 +334,32 @@ void CDECL wined3d_resource_preload(struct wined3d_resource *resource) - wined3d_cs_emit_preload_resource(resource->device->cs, resource); - } - --static BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) -+void *wined3d_allocate_sysmem(SIZE_T size) - { - void **p; -- SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p); -+ static const SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p); - void *mem; - -- if (!(mem = heap_alloc_zero(resource->size + align))) -+ if (!(mem = heap_alloc_zero(size + align))) - { - ERR("Failed to allocate system memory.\n"); -- return FALSE; -+ return NULL; - } - - p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1; - *p = mem; - -- resource->heap_memory = ++p; -+ return ++p; -+} - -- return TRUE; -+void wined3d_free_sysmem(void *mem) -+{ -+ void **p = mem; -+ -+ if (!p) -+ return; -+ -+ heap_free(*(--p)); - } - - BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) -@@ -359,17 +367,12 @@ BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) - if (resource->heap_memory) - return TRUE; - -- return wined3d_resource_allocate_sysmem(resource); -+ return !!(resource->heap_memory = wined3d_allocate_sysmem(resource->size)); - } - - void wined3d_resource_free_sysmem(struct wined3d_resource *resource) - { -- void **p = resource->heap_memory; -- -- if (!p) -- return; -- -- heap_free(*(--p)); -+ wined3d_free_sysmem(resource->heap_memory); - resource->heap_memory = NULL; - } - -diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c -index c7a9b4da3e1..663503bdf39 100644 ---- a/dlls/wined3d/texture.c -+++ b/dlls/wined3d/texture.c -@@ -3506,6 +3506,30 @@ static void texture_resource_unload(struct wined3d_resource *resource) - resource_unload(&texture->resource); - } - -+static HRESULT texture_resource_sub_resource_get_size(struct wined3d_resource *resource, -+ unsigned int sub_resource_idx, unsigned int *size, unsigned int *row_pitch, unsigned int *slice_pitch) -+{ -+ struct wined3d_texture *texture = texture_from_resource(resource); -+ unsigned int texture_level = sub_resource_idx % texture->level_count; -+ struct wined3d_texture_sub_resource *sub_resource; -+ -+ if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx))) -+ return E_INVALIDARG; -+ -+ if (resource->format_flags & WINED3DFMT_FLAG_BROKEN_PITCH) -+ { -+ *row_pitch = wined3d_texture_get_level_width(texture, texture_level) * resource->format->byte_count; -+ *slice_pitch = wined3d_texture_get_level_height(texture, texture_level) * (*row_pitch); -+ } -+ else -+ { -+ wined3d_texture_get_pitch(texture, texture_level, row_pitch, slice_pitch); -+ } -+ -+ *size = sub_resource->size; -+ return S_OK; -+} -+ - 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 +3716,7 @@ static const struct wined3d_resource_ops texture_resource_ops = - texture_resource_decref, - texture_resource_preload, - texture_resource_unload, -+ texture_resource_sub_resource_get_size, - 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 8e3efccffc2..db6e1619e8f 100644 ---- a/dlls/wined3d/wined3d_private.h -+++ b/dlls/wined3d/wined3d_private.h -@@ -4048,6 +4048,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_size)(struct wined3d_resource *resource, unsigned int sub_resource_idx, -+ unsigned int *size, unsigned int *row_pitch, unsigned int *slice_pitch); - 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); -@@ -4131,6 +4133,9 @@ void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DEC - #define RESOURCE_ALIGNMENT 16 - #define WINED3D_CONSTANT_BUFFER_ALIGNMENT 16 - -+void *wined3d_allocate_sysmem(SIZE_T size) DECLSPEC_HIDDEN; -+void wined3d_free_sysmem(void *mem) DECLSPEC_HIDDEN; -+ - #define WINED3D_LOCATION_DISCARDED 0x00000001 - #define WINED3D_LOCATION_SYSMEM 0x00000002 - #define WINED3D_LOCATION_BUFFER 0x00000008 --- -2.30.2 - diff --git a/patches/ntdll-NtAlertThreadByThreadId/0001-ntdll-tests-Move-some-tests-to-a-new-sync.c-file.patch b/patches/ntdll-NtAlertThreadByThreadId/0001-ntdll-tests-Move-some-tests-to-a-new-sync.c-file.patch index 030eb75c..92df17bd 100644 --- a/patches/ntdll-NtAlertThreadByThreadId/0001-ntdll-tests-Move-some-tests-to-a-new-sync.c-file.patch +++ b/patches/ntdll-NtAlertThreadByThreadId/0001-ntdll-tests-Move-some-tests-to-a-new-sync.c-file.patch @@ -1,4 +1,4 @@ -From 414a6313d1562ce78fd2700d5ee1aeac14e87868 Mon Sep 17 00:00:00 2001 +From 9d8e065b5e001715aa96cfee3fb9fcd89cc77674 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 9 Jan 2020 13:44:01 -0600 Subject: [PATCH] ntdll/tests: Move some tests to a new sync.c file. @@ -12,7 +12,7 @@ Signed-off-by: Zebediah Figura create mode 100644 dlls/ntdll/tests/sync.c diff --git a/dlls/ntdll/tests/Makefile.in b/dlls/ntdll/tests/Makefile.in -index ed15c51339f..9a99c01bd7c 100644 +index 7ad39e0992c..8c6a86fb965 100644 --- a/dlls/ntdll/tests/Makefile.in +++ b/dlls/ntdll/tests/Makefile.in @@ -21,6 +21,7 @@ C_SRCS = \ @@ -22,7 +22,7 @@ index ed15c51339f..9a99c01bd7c 100644 + sync.c \ threadpool.c \ time.c \ - virtual.c + virtual.c \ diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c index 82f8188d176..9a9536f4639 100644 --- a/dlls/ntdll/tests/om.c diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index ec106707..4f3a1b77 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -51,7 +51,7 @@ usage() # Get the upstream commit sha upstream_commit() { - echo "ad03df1222c2bb22e991641dcc0d9e4ed684158b" + echo "542175ab10420953920779f3c64eb310dd3aa258" } # Show version information @@ -250,7 +250,6 @@ patch_enable_all () enable_winecfg_Libraries="$1" enable_winecfg_Staging="$1" enable_wined3d_Accounting="$1" - enable_wined3d_CSMT_Main="$1" enable_wined3d_Indexed_Vertex_Blending="$1" enable_wined3d_SWVP_shaders="$1" enable_wined3d_Silence_FIXMEs="$1" @@ -796,9 +795,6 @@ patch_enable () wined3d-Accounting) enable_wined3d_Accounting="$2" ;; - wined3d-CSMT_Main) - enable_wined3d_CSMT_Main="$2" - ;; wined3d-Indexed_Vertex_Blending) enable_wined3d_Indexed_Vertex_Blending="$2" ;; @@ -1272,13 +1268,6 @@ if test "$enable_wined3d_Indexed_Vertex_Blending" -eq 1; then enable_wined3d_SWVP_shaders=1 fi -if test "$enable_wined3d_CSMT_Main" -eq 1; then - if test "$enable_d3d11_Deferred_Context" -gt 1; then - abort "Patchset d3d11-Deferred_Context disabled, but wined3d-CSMT_Main depends on that." - fi - enable_d3d11_Deferred_Context=1 -fi - if test "$enable_user32_rawinput_mouse_experimental" -eq 1; then if test "$enable_user32_rawinput_mouse" -gt 1; then abort "Patchset user32-rawinput-mouse disabled, but user32-rawinput-mouse-experimental depends on that." @@ -1640,12 +1629,21 @@ fi # | Death of the Outsider, Pro Evolution Soccer 2019, Shantae and the Pirate's Curse, Space Engineers) # | # | Modified files: -# | * dlls/d3d11/tests/d3d11.c, dlls/wined3d/buffer.c, dlls/wined3d/cs.c, dlls/wined3d/resource.c, dlls/wined3d/texture.c, -# | dlls/wined3d/wined3d_private.h +# | * dlls/d3d11/device.c, dlls/d3d11/tests/d3d11.c, dlls/wined3d/buffer.c, dlls/wined3d/cs.c, dlls/wined3d/device.c, +# | dlls/wined3d/resource.c, dlls/wined3d/texture.c, dlls/wined3d/utils.c, dlls/wined3d/wined3d_private.h # | if test "$enable_d3d11_Deferred_Context" -eq 1; then - patch_apply d3d11-Deferred_Context/0013-wined3d-Implement-wined3d_deferred_context_update_su.patch - patch_apply d3d11-Deferred_Context/0014-wined3d-Implement-wined3d_deferred_context_map.patch + patch_apply d3d11-Deferred_Context/0001-wined3d-Pass-a-wined3d_resource-and-sub-resource-ind.patch + patch_apply d3d11-Deferred_Context/0002-wined3d-Move-box-validation-to-wined3d_device_contex.patch + patch_apply d3d11-Deferred_Context/0003-wined3d-Report-a-byte-count-of-1-for-WINED3DFMT_UNKN.patch + patch_apply d3d11-Deferred_Context/0004-wined3d-Use-wined3d_buffer_copy_bo_address-in-wined3.patch + patch_apply d3d11-Deferred_Context/0005-wined3d-Pass-a-wined3d_const_bo_address-to-wined3d_c.patch + patch_apply d3d11-Deferred_Context/0006-wined3d-Introduce-a-prepare_upload_bo-device-context.patch + patch_apply d3d11-Deferred_Context/0007-wined3d-Implement-wined3d_deferred_context_prepare_u.patch + patch_apply d3d11-Deferred_Context/0008-d3d11-Forbid-map-types-other-than-DISCARD-and-NOOVER.patch + patch_apply d3d11-Deferred_Context/0009-wined3d-Use-context-ops-prepare_upload_bo-in-wined3d.patch + patch_apply d3d11-Deferred_Context/0010-wined3d-Implement-NOOVERWITE-maps-in-wined3d_deferre.patch + patch_apply d3d11-Deferred_Context/0011-wined3d-Print-a-message-when-forcing-CS-serializatio.patch fi # Patchset d3drm-IDirect3D3-support @@ -3890,18 +3888,6 @@ if test "$enable_wined3d_Accounting" -eq 1; then patch_apply wined3d-Accounting/0001-wined3d-Use-real-values-for-memory-accounting-on-NVI.patch fi -# Patchset wined3d-CSMT_Main -# | -# | This patchset has the following (direct or indirect) dependencies: -# | * d3d11-Deferred_Context -# | -# | Modified files: -# | * dlls/wined3d/cs.c, dlls/wined3d/wined3d_private.h -# | -if test "$enable_wined3d_CSMT_Main" -eq 1; then - patch_apply wined3d-CSMT_Main/0045-wined3d-Improve-wined3d_cs_emit_update_sub_resource.patch -fi - # Patchset wined3d-SWVP-shaders # | # | This patchset fixes the following Wine bugs: diff --git a/patches/wined3d-CSMT_Main/definition b/patches/wined3d-CSMT_Main/definition index 631f40e5..9757a55e 100644 --- a/patches/wined3d-CSMT_Main/definition +++ b/patches/wined3d-CSMT_Main/definition @@ -1 +1,4 @@ Depends: d3d11-Deferred_Context +# Disabling this for now. Needs to be changed again to match the approach taken +# for deferred contexts; we'll rebase it once that's been finally fixed upstream. +Disabled: true \ No newline at end of file diff --git a/staging/upstream-commit b/staging/upstream-commit index bea644a0..d7c9dc05 100644 --- a/staging/upstream-commit +++ b/staging/upstream-commit @@ -1 +1 @@ -ad03df1222c2bb22e991641dcc0d9e4ed684158b +542175ab10420953920779f3c64eb310dd3aa258