This has the notable effect of implementing maps on deferred contexts.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/d3d11/tests/d3d11.c | 55 +++++++++++++------------ dlls/wined3d/cs.c | 73 +++++++++++++++++++++++++++------- dlls/wined3d/device.c | 38 ++++++++++++++++-- dlls/wined3d/wined3d_private.h | 5 +++ 4 files changed, 125 insertions(+), 46 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index cf51e79b084..df1d5a35c6e 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -33065,15 +33065,7 @@ static void test_deferred_context_map(void) 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 93ec378e06b..2c8cc5771e3 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4710,6 +4710,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, @@ -4864,6 +4866,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) {