1 /**************************************************************************
3 * Copyright 2011 Marek Olšák <maraeo@gmail.com>
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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)
36 #include "pipe/p_context.h"
37 #include "pipe/p_state.h"
38 #include "util/u_transfer.h"
40 /* Hardware vertex fetcher limitations can be described by this structure. */
42 /* Vertex format CAPs. */
43 /* TRUE if hardware supports it. */
44 unsigned format_fixed32:1; /* PIPE_FORMAT_*32*_FIXED */
45 unsigned format_float16:1; /* PIPE_FORMAT_*16*_FLOAT */
46 unsigned format_float64:1; /* PIPE_FORMAT_*64*_FLOAT */
47 unsigned format_norm32:1; /* PIPE_FORMAT_*32*NORM */
48 unsigned format_scaled32:1; /* PIPE_FORMAT_*32*SCALED */
50 /* Whether vertex fetches don't have to be dword-aligned. */
51 /* TRUE if hardware supports it. */
52 unsigned fetch_dword_unaligned:1;
56 * This structure should also be used to access vertex buffers
59 /* This is what was set in set_vertex_buffers.
60 * May contain user buffers. */
61 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
62 unsigned nr_vertex_buffers;
64 /* This uploader can optionally be used by the driver.
71 struct u_upload_mgr *uploader;
73 struct u_vbuf_caps caps;
76 struct u_vbuf_resource {
81 /* Opaque type containing information about vertex elements for the manager. */
82 struct u_vbuf_elements;
84 enum u_fetch_alignment {
85 U_VERTEX_FETCH_BYTE_ALIGNED,
86 U_VERTEX_FETCH_DWORD_ALIGNED
91 u_vbuf_create(struct pipe_context *pipe,
92 unsigned upload_buffer_size,
93 unsigned upload_buffer_alignment,
94 unsigned upload_buffer_bind,
95 enum u_fetch_alignment fetch_alignment);
97 void u_vbuf_destroy(struct u_vbuf *mgr);
99 struct u_vbuf_elements *
100 u_vbuf_create_vertex_elements(struct u_vbuf *mgr,
102 const struct pipe_vertex_element *attrs,
103 struct pipe_vertex_element *native_attrs);
105 void u_vbuf_bind_vertex_elements(struct u_vbuf *mgr,
107 struct u_vbuf_elements *ve);
109 void u_vbuf_destroy_vertex_elements(struct u_vbuf *mgr,
110 struct u_vbuf_elements *ve);
112 void u_vbuf_draw_begin(struct u_vbuf *mgr,
113 struct pipe_draw_info *info);
115 unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf *mgr);
117 void u_vbuf_draw_end(struct u_vbuf *mgr);
120 static INLINE struct u_vbuf_resource *u_vbuf_resource(struct pipe_resource *r)
122 return (struct u_vbuf_resource*)r;