xref: /third_party/mesa3d/src/mesa/vbo/vbo_save.h (revision bf215546)
1/**************************************************************************
2
3Copyright 2002 VMware, Inc.
4
5All Rights Reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a
8copy of this software and associated documentation files (the "Software"),
9to deal in the Software without restriction, including without limitation
10on the rights to use, copy, modify, merge, publish, distribute, sub
11license, and/or sell copies of the Software, and to permit persons to whom
12the Software is furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice (including the next
15paragraph) shall be included in all copies or substantial portions of the
16Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26**************************************************************************/
27
28/*
29 * Authors:
30 *   Keith Whitwell <keithw@vmware.com>
31 *
32 */
33
34#ifndef VBO_SAVE_H
35#define VBO_SAVE_H
36
37#include "dlist.h"
38#include "vbo.h"
39#include "vbo_attrib.h"
40
41/* For display lists, this structure holds a run of vertices of the
42 * same format, and a strictly well-formed set of begin/end pairs,
43 * starting on the first vertex and ending at the last.  Vertex
44 * copying on buffer breaks is precomputed according to these
45 * primitives, though there are situations where the copying will need
46 * correction at execute-time, perhaps by replaying the list as
47 * immediate mode commands.
48 *
49 * On executing this list, the 'current' values may be updated with
50 * the values of the final vertex, and often no fixup of the start of
51 * the vertex list is required.
52 *
53 * Eval and other commands that don't fit into these vertex lists are
54 * compiled using the fallback opcode mechanism provided by dlist.c.
55 */
56struct vbo_save_vertex_list {
57   union gl_dlist_node header;
58
59   /* Data used in vbo_save_playback_vertex_list */
60   unsigned num_draws;
61   uint8_t *modes;
62   union {
63      struct pipe_draw_start_count_bias *start_counts;
64      struct pipe_draw_start_count_bias start_count;
65   };
66   uint8_t mode;
67   bool draw_begins;
68
69   int16_t private_refcount[VP_MODE_MAX];
70   struct gl_context *ctx;
71   struct pipe_vertex_state *state[VP_MODE_MAX];
72   GLbitfield enabled_attribs[VP_MODE_MAX];
73
74   /* Cold: used during construction or to handle edge-cases.
75    * It's not part of the structure because we want display list nodes
76    * to be tightly packed to get cache hits. Without this, performance would
77    * decrease by an order of magnitude with 10k display lists.
78    */
79   struct {
80      struct gl_vertex_array_object *VAO[VP_MODE_MAX];
81      struct _mesa_index_buffer ib;
82
83      struct pipe_draw_info info;
84
85      /* Copy of the final vertex from node->vertex_store->bufferobj.
86       * Keep this in regular (non-VBO) memory to avoid repeated
87       * map/unmap of the VBO when updating GL current data.
88       */
89      fi_type *current_data;
90
91      GLuint vertex_count;         /**< number of vertices in this list */
92      GLuint wrap_count;		/* number of copied vertices at start */
93
94      struct _mesa_prim *prims;
95      GLuint prim_count;
96      GLuint min_index, max_index;
97   } *cold;
98};
99
100
101/**
102 * Return the stride in bytes of the display list node.
103 */
104static inline GLsizei
105_vbo_save_get_stride(const struct vbo_save_vertex_list *node)
106{
107   return node->cold->VAO[0]->BufferBinding[0].Stride;
108}
109
110/* Default size for the buffer holding the vertices and the indices.
111 * A bigger buffer helps reducing the number of draw calls but may
112 * waste memory.
113 */
114#define VBO_SAVE_BUFFER_SIZE (20*1024*1024)
115#define VBO_SAVE_PRIM_MODE_MASK 0x3f
116
117struct vbo_save_vertex_store {
118   fi_type *buffer_in_ram;
119   GLuint buffer_in_ram_size;
120   GLuint used;           /**< Number of 4-byte words used in buffer */
121};
122
123struct vbo_save_primitive_store {
124   struct _mesa_prim *prims;
125   GLuint used;
126   GLuint size;
127};
128
129
130void vbo_save_init(struct gl_context *ctx);
131void vbo_save_destroy(struct gl_context *ctx);
132
133/* save_loopback.c:
134 */
135void _vbo_loopback_vertex_list(struct gl_context *ctx,
136                               const struct vbo_save_vertex_list* node,
137                               fi_type *buffer);
138
139/* Callbacks:
140 */
141void
142vbo_save_playback_vertex_list(struct gl_context *ctx, void *data, bool copy_to_current);
143
144void
145vbo_save_playback_vertex_list_loopback(struct gl_context *ctx, void *data);
146
147void
148vbo_save_api_init(struct vbo_save_context *save);
149
150#endif /* VBO_SAVE_H */
151