wined3d: Prefer mapping a BO if the buffer has WINED3D_BUFFER_USE_BO set.
Instead of checking whether a BO already exists. This will end up allocating a BO earlier in some cases. This is not particularly impactful by itself, since we already would have sysmem available and thus could use it without a performance penalty. However, we would like to avoid ever allocating sysmem where not necessary, in particular by deferring allocation of any location at all until the resource is written to. This also has the side effect of fixing test_map_synchronization() on 64-bit architectures, broken since194b47b4fd
. The test creates a buffer, maps it once, then maps it again with NOOVERWRITE while the GPU is still drawing, expecting the new data to be read by the GPU during the draw. On 32-bit machines, and 64-bit machines before the offending commit, we do the following: First map: uses SYSMEM since the BO is not created yet Draw: upload to VBO Second map: map the existing VBO with GL_MAP_UNSYNCHRONIZED_BIT After194b47b4fd
, we don't use GL_MAP_UNSYNCHRONIZED_BIT since the buffer has READ access, which means that the second map will be synchronized and wait for the draw to complete. After this patch, we do the following: First map: create and map a VBO (not unsynchronized, but coherent and persistently mapped) Draw: use mapped VBO Second map: write to existing (coherent) VBO, which is unsynchronized Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
287bfc7758
commit
6b96021a1c
|
@ -911,25 +911,21 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc
|
||||||
void **map_ptr, const struct wined3d_box *box, uint32_t flags)
|
void **map_ptr, const struct wined3d_box *box, uint32_t flags)
|
||||||
{
|
{
|
||||||
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
||||||
|
unsigned int offset, size, dirty_offset, dirty_size;
|
||||||
struct wined3d_device *device = resource->device;
|
struct wined3d_device *device = resource->device;
|
||||||
struct wined3d_context *context;
|
struct wined3d_context *context;
|
||||||
unsigned int offset, size;
|
struct wined3d_bo_address addr;
|
||||||
uint8_t *base;
|
uint8_t *base;
|
||||||
LONG count;
|
LONG count;
|
||||||
|
|
||||||
TRACE("resource %p, sub_resource_idx %u, map_ptr %p, box %s, flags %#x.\n",
|
TRACE("resource %p, sub_resource_idx %u, map_ptr %p, box %s, flags %#x.\n",
|
||||||
resource, sub_resource_idx, map_ptr, debug_box(box), flags);
|
resource, sub_resource_idx, map_ptr, debug_box(box), flags);
|
||||||
|
|
||||||
offset = box->left;
|
dirty_offset = offset = box->left;
|
||||||
size = box->right - box->left;
|
dirty_size = size = box->right - box->left;
|
||||||
|
|
||||||
count = ++resource->map_count;
|
count = ++resource->map_count;
|
||||||
|
|
||||||
if (buffer->buffer_object)
|
|
||||||
{
|
|
||||||
unsigned int dirty_offset = offset, dirty_size = size;
|
|
||||||
struct wined3d_bo_address addr;
|
|
||||||
|
|
||||||
/* DISCARD invalidates the entire buffer, regardless of the specified
|
/* DISCARD invalidates the entire buffer, regardless of the specified
|
||||||
* offset and size. Some applications also depend on the entire buffer
|
* offset and size. Some applications also depend on the entire buffer
|
||||||
* being uploaded in that case. Two such applications are Port Royale
|
* being uploaded in that case. Two such applications are Port Royale
|
||||||
|
@ -942,7 +938,8 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc
|
||||||
|
|
||||||
if (((flags & WINED3D_MAP_WRITE) && !(flags & (WINED3D_MAP_NOOVERWRITE | WINED3D_MAP_DISCARD)))
|
if (((flags & WINED3D_MAP_WRITE) && !(flags & (WINED3D_MAP_NOOVERWRITE | WINED3D_MAP_DISCARD)))
|
||||||
|| (!(flags & WINED3D_MAP_WRITE) && (buffer->locations & WINED3D_LOCATION_SYSMEM))
|
|| (!(flags & WINED3D_MAP_WRITE) && (buffer->locations & WINED3D_LOCATION_SYSMEM))
|
||||||
|| buffer->flags & WINED3D_BUFFER_PIN_SYSMEM)
|
|| buffer->flags & WINED3D_BUFFER_PIN_SYSMEM
|
||||||
|
|| !(buffer->flags & WINED3D_BUFFER_USE_BO))
|
||||||
{
|
{
|
||||||
if (!(buffer->locations & WINED3D_LOCATION_SYSMEM))
|
if (!(buffer->locations & WINED3D_LOCATION_SYSMEM))
|
||||||
{
|
{
|
||||||
|
@ -959,9 +956,18 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc
|
||||||
context = context_acquire(device, NULL, 0);
|
context = context_acquire(device, NULL, 0);
|
||||||
|
|
||||||
if (flags & WINED3D_MAP_DISCARD)
|
if (flags & WINED3D_MAP_DISCARD)
|
||||||
|
{
|
||||||
|
if (!wined3d_buffer_prepare_location(buffer, context, WINED3D_LOCATION_BUFFER))
|
||||||
|
{
|
||||||
|
context_release(context);
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
}
|
||||||
wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER);
|
wined3d_buffer_validate_location(buffer, WINED3D_LOCATION_BUFFER);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
|
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & WINED3D_MAP_WRITE)
|
if (flags & WINED3D_MAP_WRITE)
|
||||||
{
|
{
|
||||||
|
@ -1010,7 +1016,6 @@ static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resourc
|
||||||
|
|
||||||
context_release(context);
|
context_release(context);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
base = buffer->map_ptr ? buffer->map_ptr : resource->heap_memory;
|
base = buffer->map_ptr ? buffer->map_ptr : resource->heap_memory;
|
||||||
*map_ptr = base + offset;
|
*map_ptr = base + offset;
|
||||||
|
|
Loading…
Reference in New Issue