Commit 65e31e45 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

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: 's avatarZebediah Figura <z.figura12@gmail.com> Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 1e9c094a
......@@ -33052,15 +33052,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. */
......@@ -33109,13 +33101,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);
......@@ -33128,32 +33121,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);
......@@ -31,6 +31,7 @@ struct wined3d_deferred_upload
struct wined3d_resource *resource;
unsigned int sub_resource_idx;
uint8_t *sysmem;
struct wined3d_box box;
};
struct wined3d_command_list
......@@ -2417,6 +2418,29 @@ void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resou
wined3d_device_context_submit(&cs->c, WINED3D_CS_QUEUE_DEFAULT);
}
static 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);
}
static void wined3d_cs_exec_map(struct wined3d_cs *cs, const void *data)
{
const struct wined3d_cs_map *op = data;
......@@ -2426,6 +2450,25 @@ static void wined3d_cs_exec_map(struct wined3d_cs *cs, const void *data)
op->sub_resource_idx, op->map_ptr, op->box, op->flags);
}
HRESULT wined3d_device_context_emit_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)
{
struct wined3d_const_bo_address addr;
unsigned int row_pitch, slice_pitch;
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, map pointer %p, row pitch %u, slice pitch %u.\n",
debug_const_bo_address(&addr), *map_ptr, row_pitch, slice_pitch);
return WINED3D_OK;
}
return context->ops->map(context, resource, sub_resource_idx, map_ptr, box, flags);
}
static HRESULT wined3d_cs_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)
{
......@@ -2462,6 +2505,24 @@ static void wined3d_cs_exec_unmap(struct wined3d_cs *cs, const void *data)
*op->hr = resource->resource_ops->resource_sub_resource_unmap(resource, op->sub_resource_idx);
}
HRESULT wined3d_device_context_emit_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;
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;
}
return context->ops->unmap(context, resource, sub_resource_idx);
}
static HRESULT wined3d_cs_unmap(struct wined3d_device_context *context, struct wined3d_resource *resource,
unsigned int sub_resource_idx)
{
......@@ -2673,23 +2734,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 +3049,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 +3062,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 +3192,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,
......@@ -3414,6 +3469,22 @@ 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 const struct wined3d_deferred_upload *deferred_context_get_upload(struct wined3d_deferred_context *deferred,
struct wined3d_resource *resource, unsigned int sub_resource_idx)
{
SIZE_T 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)
return upload;
}
return NULL;
}
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)
......@@ -3452,6 +3523,7 @@ 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;
map_ptr = (uint8_t *)align((size_t)sysmem, RESOURCE_ALIGNMENT);
......@@ -3459,6 +3531,24 @@ static void *wined3d_deferred_context_prepare_upload_bo(struct wined3d_device_co
return map_ptr;
}
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);
const struct wined3d_deferred_upload *upload;
if ((upload = deferred_context_get_upload(deferred, resource, sub_resource_idx)))
{
*box = upload->box;
address->buffer_object = 0;
address->addr = (uint8_t *)align((size_t)upload->sysmem, RESOURCE_ALIGNMENT);
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)
{
......@@ -3537,6 +3627,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,
......
......@@ -4880,7 +4880,8 @@ HRESULT CDECL wined3d_device_context_map(struct wined3d_device_context *context,
return WINED3DERR_INVALIDCALL;
}
if (SUCCEEDED(hr = context->ops->map(context, resource, sub_resource_idx, &map_desc->data, box, flags)))
if (SUCCEEDED(hr = wined3d_device_context_emit_map(context, resource,
sub_resource_idx, &map_desc->data, box, flags)))
wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx,
&map_desc->row_pitch, &map_desc->slice_pitch);
return hr;
......@@ -4891,7 +4892,7 @@ HRESULT CDECL wined3d_device_context_unmap(struct wined3d_device_context *contex
{
TRACE("context %p, resource %p, sub_resource_idx %u.\n", context, resource, sub_resource_idx);
return context->ops->unmap(context, resource, sub_resource_idx);
return wined3d_device_context_emit_unmap(context, resource, sub_resource_idx);
}
void CDECL wined3d_device_context_issue_query(struct wined3d_device_context *context,
......
......@@ -4712,6 +4712,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,
......@@ -4805,6 +4807,9 @@ void wined3d_device_context_emit_draw(struct wined3d_device_context *context,
bool indexed) DECLSPEC_HIDDEN;
void wined3d_device_context_emit_generate_mipmaps(struct wined3d_device_context *context,
struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
HRESULT wined3d_device_context_emit_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) DECLSPEC_HIDDEN;
void wined3d_device_context_emit_reset_state(struct wined3d_device_context *context, bool invalidate) DECLSPEC_HIDDEN;
void wined3d_device_context_emit_set_blend_state(struct wined3d_device_context *context,
struct wined3d_blend_state *state, const struct wined3d_color *blend_factor,
......@@ -4866,6 +4871,8 @@ 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;
HRESULT wined3d_device_context_emit_unmap(struct wined3d_device_context *context,
struct wined3d_resource *resource, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
static inline void wined3d_resource_wait_idle(struct wined3d_resource *resource)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment