Merge branch 'xa_branch'
[mesa.git] / src / gallium / auxiliary / util / u_vbuf_mgr.h
1 /**************************************************************************
2 *
3 * Copyright 2011 Marek Olšák <maraeo@gmail.com>
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 AUTHORS 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 #ifndef U_VBUF_MGR_H
29 #define U_VBUF_MGR_H
30
31 /* This module builds upon u_upload_mgr and translate_cache and takes care of
32 * user buffer uploads and vertex format fallbacks. It's designed
33 * for the drivers which don't always use the Draw module. (e.g. for HWTCL)
34 */
35
36 #include "pipe/p_context.h"
37 #include "pipe/p_state.h"
38 #include "util/u_transfer.h"
39
40 /* The manager.
41 * This structure should also be used to access vertex buffers
42 * from a driver. */
43 struct u_vbuf_mgr {
44 /* This is what was set in set_vertex_buffers.
45 * May contain user buffers. */
46 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
47 unsigned nr_vertex_buffers;
48
49 /* Contains only real vertex buffers.
50 * Hardware drivers should use real_vertex_buffers[i]
51 * instead of vertex_buffers[i].buffer. */
52 struct pipe_resource *real_vertex_buffer[PIPE_MAX_ATTRIBS];
53 int nr_real_vertex_buffers;
54
55 /* Precomputed max_index for hardware vertex buffers. */
56 unsigned max_index;
57
58 /* This uploader can optionally be used by the driver.
59 *
60 * Allowed functions:
61 * - u_upload_alloc
62 * - u_upload_data
63 * - u_upload_buffer
64 * - u_upload_flush */
65 struct u_upload_mgr *uploader;
66 };
67
68 struct u_vbuf_resource {
69 struct u_resource b;
70 uint8_t *user_ptr;
71 };
72
73 /* Opaque type containing information about vertex elements for the manager. */
74 struct u_vbuf_mgr_elements;
75
76 enum u_fetch_alignment {
77 U_VERTEX_FETCH_BYTE_ALIGNED,
78 U_VERTEX_FETCH_DWORD_ALIGNED
79 };
80
81 enum u_vbuf_return_flags {
82 U_VBUF_BUFFERS_UPDATED = 1,
83 U_VBUF_UPLOAD_FLUSHED = 2
84 };
85
86
87 struct u_vbuf_mgr *
88 u_vbuf_mgr_create(struct pipe_context *pipe,
89 unsigned upload_buffer_size,
90 unsigned upload_buffer_alignment,
91 unsigned upload_buffer_bind,
92 enum u_fetch_alignment fetch_alignment);
93
94 void u_vbuf_mgr_destroy(struct u_vbuf_mgr *mgr);
95
96 struct u_vbuf_mgr_elements *
97 u_vbuf_mgr_create_vertex_elements(struct u_vbuf_mgr *mgr,
98 unsigned count,
99 const struct pipe_vertex_element *attrs,
100 struct pipe_vertex_element *native_attrs);
101
102 void u_vbuf_mgr_bind_vertex_elements(struct u_vbuf_mgr *mgr,
103 void *cso,
104 struct u_vbuf_mgr_elements *ve);
105
106 void u_vbuf_mgr_destroy_vertex_elements(struct u_vbuf_mgr *mgr,
107 struct u_vbuf_mgr_elements *ve);
108
109 void u_vbuf_mgr_set_vertex_buffers(struct u_vbuf_mgr *mgr,
110 unsigned count,
111 const struct pipe_vertex_buffer *bufs);
112
113 enum u_vbuf_return_flags
114 u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgr,
115 const struct pipe_draw_info *info);
116
117 void u_vbuf_mgr_draw_end(struct u_vbuf_mgr *mgr);
118
119
120 static INLINE struct u_vbuf_resource *u_vbuf_resource(struct pipe_resource *r)
121 {
122 return (struct u_vbuf_resource*)r;
123 }
124
125 #endif