• 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 
37 struct pipe_context;
38 struct pipe_resource;
39 
40 
41 /**
42  * Create the upload manager.
43  *
44  * \param pipe          Pipe driver.
45  * \param default_size  Minimum size of the upload buffer, in bytes.
46  * \param alignment     Alignment of each suballocation in the upload buffer.
47  * \param bind          Bitmask of PIPE_BIND_* flags.
48  */
49 struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
50                                       unsigned default_size,
51                                       unsigned alignment,
52                                       unsigned bind );
53 
54 /**
55  * Destroy the upload manager.
56  */
57 void u_upload_destroy( struct u_upload_mgr *upload );
58 
59 /**
60  * Unmap and release old upload buffer.
61  *
62  * This is like u_upload_unmap() except the upload buffer is released for
63  * recycling. This should be called on real hardware flushes on systems
64  * that don't support the PIPE_TRANSFER_UNSYNCHRONIZED flag, as otherwise
65  * the next u_upload_buffer will cause a sync on the buffer.
66  */
67 void u_upload_flush( struct u_upload_mgr *upload );
68 
69 /**
70  * Unmap upload buffer
71  *
72  * \param upload           Upload manager
73  *
74  * This must usually be called prior to firing the command stream
75  * which references the upload buffer, as many memory managers either
76  * don't like firing a mapped buffer or cause subsequent maps of a
77  * fired buffer to wait.
78  */
79 void u_upload_unmap( struct u_upload_mgr *upload );
80 
81 /**
82  * Sub-allocate new memory from the upload buffer.
83  *
84  * \param upload           Upload manager
85  * \param min_out_offset   Minimum offset that should be returned in out_offset.
86  * \param size             Size of the allocation.
87  * \param out_offset       Pointer to where the new buffer offset will be returned.
88  * \param outbuf           Pointer to where the upload buffer will be returned.
89  * \param ptr              Pointer to the allocated memory that is returned.
90  */
91 enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
92                                 unsigned min_out_offset,
93                                 unsigned size,
94                                 unsigned *out_offset,
95                                 struct pipe_resource **outbuf,
96                                 void **ptr );
97 
98 
99 /**
100  * Allocate and write data to the upload buffer.
101  *
102  * Same as u_upload_alloc, but in addition to that, it copies "data"
103  * to the pointer returned from u_upload_alloc.
104  */
105 enum pipe_error u_upload_data( struct u_upload_mgr *upload,
106                                unsigned min_out_offset,
107                                unsigned size,
108                                const void *data,
109                                unsigned *out_offset,
110                                struct pipe_resource **outbuf);
111 
112 
113 /**
114  * Allocate space in an upload buffer and copy an input buffer to it.
115  *
116  * Same as u_upload_data, except that the input data comes from a buffer
117  * instead of a user pointer.
118  */
119 enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
120                                  unsigned min_out_offset,
121                                  unsigned offset,
122                                  unsigned size,
123                                  struct pipe_resource *inbuf,
124                                  unsigned *out_offset,
125                                  struct pipe_resource **outbuf);
126 
127 
128 
129 #endif
130 
131