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