[PATCH v2 2/5] wined3d: Implement wined3d_deferred_context_prepare_upload_bo().

Henri Verbeet hverbeet at gmail.com
Wed Jun 30 07:14:40 CDT 2021


On Wed, 30 Jun 2021 at 06:33, Zebediah Figura <z.figura12 at gmail.com> wrote:
> @@ -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;
>  }
>
Do we need to use wined3d_allocate_sysmem() here? We could also do
something like the following:

    upload->sysmem = heap_alloc(size + alignment - 1);
    [...]
    return address->addr = upload->sysmem & ~(alignment - 1)

(And note that not all callers of
wined3d_deferred_context_prepare_upload_bo() will necessarily need an
allocation aligned to RESOURCE_ALIGNMENT.)

> -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;
> +}
>
If we're turning this into a generic helper, perhaps it would be more
appropriate in utils.c, and we may want to consider naming it
something like e.g. wined3d_allocate_aligned().



More information about the wine-devel mailing list