mesa/st: Factor out array and buffer setup from st_atom_array.c.
[mesa.git] / src / mesa / state_tracker / st_atom.h
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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 /*
29 * Authors:
30 * Keith Whitwell <keithw@vmware.com>
31 */
32
33
34 #ifndef ST_ATOM_H
35 #define ST_ATOM_H
36
37 #include "main/glheader.h"
38
39 struct st_context;
40 struct st_vertex_program;
41 struct st_vp_variant;
42 struct pipe_vertex_buffer;
43 struct pipe_vertex_element;
44
45 /**
46 * Enumeration of state tracker pipelines.
47 */
48 enum st_pipeline {
49 ST_PIPELINE_RENDER,
50 ST_PIPELINE_CLEAR,
51 ST_PIPELINE_META,
52 ST_PIPELINE_UPDATE_FRAMEBUFFER,
53 ST_PIPELINE_COMPUTE,
54 };
55
56 void st_init_atoms( struct st_context *st );
57 void st_destroy_atoms( struct st_context *st );
58 void st_validate_state( struct st_context *st, enum st_pipeline pipeline );
59 GLuint st_compare_func_to_pipe(GLenum func);
60
61 enum pipe_format
62 st_pipe_vertex_format(const struct gl_vertex_format *glformat);
63
64 void
65 st_setup_arrays(struct st_context *st,
66 const struct st_vertex_program *vp,
67 const struct st_vp_variant *vp_variant,
68 struct pipe_vertex_element *velements,
69 struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers);
70
71 void
72 st_setup_current(struct st_context *st,
73 const struct st_vertex_program *vp,
74 const struct st_vp_variant *vp_variant,
75 struct pipe_vertex_element *velements,
76 struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers);
77
78 /* Define ST_NEW_xxx_INDEX */
79 enum {
80 #define ST_STATE(FLAG, st_update) FLAG##_INDEX,
81 #include "st_atom_list.h"
82 #undef ST_STATE
83 };
84
85 /* Define ST_NEW_xxx values as static const uint64_t values.
86 * We can't use an enum type because MSVC doesn't allow 64-bit enum values.
87 */
88 #define ST_STATE(FLAG, st_update) static const uint64_t FLAG = 1ull << FLAG##_INDEX;
89 #include "st_atom_list.h"
90 #undef ST_STATE
91
92 /* Declare function prototypes. */
93 #define ST_STATE(FLAG, st_update) void st_update(struct st_context *st);
94 #include "st_atom_list.h"
95 #undef ST_STATE
96
97 /* Combined state flags. */
98 #define ST_NEW_SAMPLERS (ST_NEW_VS_SAMPLERS | \
99 ST_NEW_TCS_SAMPLERS | \
100 ST_NEW_TES_SAMPLERS | \
101 ST_NEW_GS_SAMPLERS | \
102 ST_NEW_FS_SAMPLERS | \
103 ST_NEW_CS_SAMPLERS)
104
105 #define ST_NEW_FRAMEBUFFER (ST_NEW_FB_STATE | \
106 ST_NEW_SAMPLE_STATE | \
107 ST_NEW_SAMPLE_SHADING)
108
109 #define ST_NEW_VERTEX_PROGRAM(st, p) (p->affected_states | \
110 (st_user_clip_planes_enabled(st->ctx) ? \
111 ST_NEW_CLIP_STATE : 0))
112
113 #define ST_NEW_CONSTANTS (ST_NEW_VS_CONSTANTS | \
114 ST_NEW_TCS_CONSTANTS | \
115 ST_NEW_TES_CONSTANTS | \
116 ST_NEW_FS_CONSTANTS | \
117 ST_NEW_GS_CONSTANTS | \
118 ST_NEW_CS_CONSTANTS)
119
120 #define ST_NEW_UNIFORM_BUFFER (ST_NEW_VS_UBOS | \
121 ST_NEW_TCS_UBOS | \
122 ST_NEW_TES_UBOS | \
123 ST_NEW_FS_UBOS | \
124 ST_NEW_GS_UBOS | \
125 ST_NEW_CS_UBOS)
126
127 #define ST_NEW_SAMPLER_VIEWS (ST_NEW_VS_SAMPLER_VIEWS | \
128 ST_NEW_FS_SAMPLER_VIEWS | \
129 ST_NEW_GS_SAMPLER_VIEWS | \
130 ST_NEW_TCS_SAMPLER_VIEWS | \
131 ST_NEW_TES_SAMPLER_VIEWS | \
132 ST_NEW_CS_SAMPLER_VIEWS)
133
134 #define ST_NEW_ATOMIC_BUFFER (ST_NEW_VS_ATOMICS | \
135 ST_NEW_TCS_ATOMICS | \
136 ST_NEW_TES_ATOMICS | \
137 ST_NEW_FS_ATOMICS | \
138 ST_NEW_GS_ATOMICS | \
139 ST_NEW_CS_ATOMICS)
140
141 #define ST_NEW_STORAGE_BUFFER (ST_NEW_VS_SSBOS | \
142 ST_NEW_TCS_SSBOS | \
143 ST_NEW_TES_SSBOS | \
144 ST_NEW_FS_SSBOS | \
145 ST_NEW_GS_SSBOS | \
146 ST_NEW_CS_SSBOS)
147
148 #define ST_NEW_IMAGE_UNITS (ST_NEW_VS_IMAGES | \
149 ST_NEW_TCS_IMAGES | \
150 ST_NEW_TES_IMAGES | \
151 ST_NEW_GS_IMAGES | \
152 ST_NEW_FS_IMAGES | \
153 ST_NEW_CS_IMAGES)
154
155 #define ST_ALL_SHADER_RESOURCES (ST_NEW_SAMPLER_VIEWS | \
156 ST_NEW_SAMPLERS | \
157 ST_NEW_CONSTANTS | \
158 ST_NEW_UNIFORM_BUFFER | \
159 ST_NEW_ATOMIC_BUFFER | \
160 ST_NEW_STORAGE_BUFFER | \
161 ST_NEW_IMAGE_UNITS)
162
163 /* All state flags within each group: */
164 #define ST_PIPELINE_RENDER_STATE_MASK (ST_NEW_CS_STATE - 1)
165 #define ST_PIPELINE_COMPUTE_STATE_MASK (0xffull << ST_NEW_CS_STATE_INDEX)
166 #define ST_PIPELINE_CLEAR_STATE_MASK (ST_NEW_FB_STATE | \
167 ST_NEW_SCISSOR | \
168 ST_NEW_WINDOW_RECTANGLES)
169 #define ST_PIPELINE_META_STATE_MASK (ST_PIPELINE_RENDER_STATE_MASK & \
170 ~ST_NEW_VERTEX_ARRAYS)
171 /* For ReadPixels, ReadBuffer, GetSamplePosition: */
172 #define ST_PIPELINE_UPDATE_FB_STATE_MASK (ST_NEW_FB_STATE)
173
174 #define ST_ALL_STATES_MASK (ST_PIPELINE_RENDER_STATE_MASK | \
175 ST_PIPELINE_COMPUTE_STATE_MASK)
176
177 #endif