u_upload_mgr.h revision cf4cd8592ab54b9c959ea3b5f21437e8dca6bbcf
15267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/**************************************************************************
25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
35267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright 2009 VMware, Inc.
45267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * All Rights Reserved.
55267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
65267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Permission is hereby granted, free of charge, to any person obtaining a
75267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * copy of this software and associated documentation files (the
85267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * "Software"), to deal in the Software without restriction, including
95267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * without limitation the rights to use, copy, modify, merge, publish,
105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * distribute, sub license, and/or sell copies of the Software, and to
115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * permit persons to whom the Software is furnished to do so, subject to
125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * the following conditions:
135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * The above copyright notice and this permission notice (including the
155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * next paragraph) shall be included in all copies or substantial portions
165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * of the Software.
175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) **************************************************************************/
275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/* Helper utility for uploading user buffers & other data, and
295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * coalescing small buffers into larger ones.
305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#ifndef U_UPLOAD_MGR_H
33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define U_UPLOAD_MGR_H
345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "pipe/p_compiler.h"
365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)struct pipe_context;
385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)struct pipe_resource;
395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/**
425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Create the upload manager.
435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * \param pipe          Pipe driver.
4551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * \param default_size  Minimum size of the upload buffer, in bytes.
465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * \param alignment     Alignment of each suballocation in the upload buffer.
4751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * \param bind          Bitmask of PIPE_BIND_* flags.
4851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) */
4951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
50a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)                                      unsigned default_size,
51a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)                                      unsigned alignment,
52a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)                                      unsigned bind );
535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/**
555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Destroy the upload manager.
565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void u_upload_destroy( struct u_upload_mgr *upload );
585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/* Unmap and release old upload buffer.
605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * This is like u_upload_unmap() except the upload buffer is released for
625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * recycling. This should be called on real hardware flushes on systems
635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * that don't support the PIPE_TRANSFER_UNSYNCHRONIZED flag, as otherwise
645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * the next u_upload_buffer will cause a sync on the buffer.
655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void u_upload_flush( struct u_upload_mgr *upload );
685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
695267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/**
705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Unmap upload buffer
715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * \param upload           Upload manager
735267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * This must usually be called prior to firing the command stream
755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * which references the upload buffer, as many memory managers either
765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * don't like firing a mapped buffer or cause subsequent maps of a
775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * fired buffer to wait.
785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void u_upload_unmap( struct u_upload_mgr *upload );
805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)/**
825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Sub-allocate new memory from the upload buffer.
835267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
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 flushed          Whether the upload buffer was flushed.
90 * \param ptr              Pointer to the allocated memory that is returned.
91 */
92enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
93                                unsigned min_out_offset,
94                                unsigned size,
95                                unsigned *out_offset,
96                                struct pipe_resource **outbuf,
97                                boolean *flushed,
98                                void **ptr );
99
100
101/**
102 * Allocate and write data to the upload buffer.
103 *
104 * Same as u_upload_alloc, but in addition to that, it copies "data"
105 * to the pointer returned from u_upload_alloc.
106 */
107enum pipe_error u_upload_data( struct u_upload_mgr *upload,
108                               unsigned min_out_offset,
109                               unsigned size,
110                               const void *data,
111                               unsigned *out_offset,
112                               struct pipe_resource **outbuf,
113                               boolean *flushed );
114
115
116/**
117 * Allocate and copy an input buffer to the upload buffer.
118 *
119 * Same as u_upload_data, except that the input data comes from a buffer
120 * instead of a user pointer.
121 */
122enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
123                                 unsigned min_out_offset,
124                                 unsigned offset,
125                                 unsigned size,
126                                 struct pipe_resource *inbuf,
127                                 unsigned *out_offset,
128                                 struct pipe_resource **outbuf,
129                                 boolean *flushed );
130
131
132
133#endif
134
135