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