1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/* Helper utility for uploading user buffers & other data, and
29bf215546Sopenharmony_ci * coalescing small buffers into larger ones.
30bf215546Sopenharmony_ci */
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#ifndef U_UPLOAD_MGR_H
33bf215546Sopenharmony_ci#define U_UPLOAD_MGR_H
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "pipe/p_compiler.h"
36bf215546Sopenharmony_ci#include "pipe/p_defines.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct pipe_context;
39bf215546Sopenharmony_cistruct pipe_resource;
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#ifdef __cplusplus
42bf215546Sopenharmony_ciextern "C" {
43bf215546Sopenharmony_ci#endif
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci/**
46bf215546Sopenharmony_ci * Create the upload manager.
47bf215546Sopenharmony_ci *
48bf215546Sopenharmony_ci * \param pipe          Pipe driver.
49bf215546Sopenharmony_ci * \param default_size  Minimum size of the upload buffer, in bytes.
50bf215546Sopenharmony_ci * \param bind          Bitmask of PIPE_BIND_* flags.
51bf215546Sopenharmony_ci * \param usage         PIPE_USAGE_*
52bf215546Sopenharmony_ci * \param flags         bitmask of PIPE_RESOURCE_FLAG_* flags.
53bf215546Sopenharmony_ci */
54bf215546Sopenharmony_cistruct u_upload_mgr *
55bf215546Sopenharmony_ciu_upload_create(struct pipe_context *pipe, unsigned default_size,
56bf215546Sopenharmony_ci                unsigned bind, enum pipe_resource_usage usage, unsigned flags);
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci/**
59bf215546Sopenharmony_ci * Create the default uploader for pipe_context. Only pipe_context::screen
60bf215546Sopenharmony_ci * needs to be set for this to succeed.
61bf215546Sopenharmony_ci */
62bf215546Sopenharmony_cistruct u_upload_mgr *
63bf215546Sopenharmony_ciu_upload_create_default(struct pipe_context *pipe);
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/**
66bf215546Sopenharmony_ci * Create an uploader with identical parameters as another one, but using
67bf215546Sopenharmony_ci * the given pipe_context instead.
68bf215546Sopenharmony_ci */
69bf215546Sopenharmony_cistruct u_upload_mgr *
70bf215546Sopenharmony_ciu_upload_clone(struct pipe_context *pipe, struct u_upload_mgr *upload);
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci/** Whether to avoid persistent mappings where available */
73bf215546Sopenharmony_civoid
74bf215546Sopenharmony_ciu_upload_disable_persistent(struct u_upload_mgr *upload);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci/**
77bf215546Sopenharmony_ci * Destroy the upload manager.
78bf215546Sopenharmony_ci */
79bf215546Sopenharmony_civoid u_upload_destroy( struct u_upload_mgr *upload );
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci/**
82bf215546Sopenharmony_ci * Unmap upload buffer
83bf215546Sopenharmony_ci *
84bf215546Sopenharmony_ci * \param upload           Upload manager
85bf215546Sopenharmony_ci *
86bf215546Sopenharmony_ci * This must usually be called prior to firing the command stream
87bf215546Sopenharmony_ci * which references the upload buffer, as many memory managers either
88bf215546Sopenharmony_ci * don't like firing a mapped buffer or cause subsequent maps of a
89bf215546Sopenharmony_ci * fired buffer to wait.
90bf215546Sopenharmony_ci */
91bf215546Sopenharmony_civoid u_upload_unmap( struct u_upload_mgr *upload );
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci/**
94bf215546Sopenharmony_ci * Sub-allocate new memory from the upload buffer.
95bf215546Sopenharmony_ci *
96bf215546Sopenharmony_ci * \param upload           Upload manager
97bf215546Sopenharmony_ci * \param min_out_offset   Minimum offset that should be returned in out_offset.
98bf215546Sopenharmony_ci * \param size             Size of the allocation.
99bf215546Sopenharmony_ci * \param alignment        Alignment of the suballocation within the buffer
100bf215546Sopenharmony_ci * \param out_offset       Pointer to where the new buffer offset will be returned.
101bf215546Sopenharmony_ci * \param outbuf           Pointer to where the upload buffer will be returned.
102bf215546Sopenharmony_ci * \param ptr              Pointer to the allocated memory that is returned.
103bf215546Sopenharmony_ci */
104bf215546Sopenharmony_civoid u_upload_alloc(struct u_upload_mgr *upload,
105bf215546Sopenharmony_ci                    unsigned min_out_offset,
106bf215546Sopenharmony_ci                    unsigned size,
107bf215546Sopenharmony_ci                    unsigned alignment,
108bf215546Sopenharmony_ci                    unsigned *out_offset,
109bf215546Sopenharmony_ci                    struct pipe_resource **outbuf,
110bf215546Sopenharmony_ci                    void **ptr);
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci/**
114bf215546Sopenharmony_ci * Allocate and write data to the upload buffer.
115bf215546Sopenharmony_ci *
116bf215546Sopenharmony_ci * Same as u_upload_alloc, but in addition to that, it copies "data"
117bf215546Sopenharmony_ci * to the pointer returned from u_upload_alloc.
118bf215546Sopenharmony_ci */
119bf215546Sopenharmony_civoid u_upload_data(struct u_upload_mgr *upload,
120bf215546Sopenharmony_ci                   unsigned min_out_offset,
121bf215546Sopenharmony_ci                   unsigned size,
122bf215546Sopenharmony_ci                   unsigned alignment,
123bf215546Sopenharmony_ci                   const void *data,
124bf215546Sopenharmony_ci                   unsigned *out_offset,
125bf215546Sopenharmony_ci                   struct pipe_resource **outbuf);
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci#ifdef __cplusplus
128bf215546Sopenharmony_ci} // extern "C" {
129bf215546Sopenharmony_ci#endif
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci#endif
132