a84140b4876e88754fe7cc84075e9ad08f04c540
[mesa.git] / src / gallium / drivers / ilo / ilo_gpe.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_GPE_H
29 #define ILO_GPE_H
30
31 #include "ilo_common.h"
32
33 /**
34 * \see brw_context.h
35 */
36 #define ILO_MAX_DRAW_BUFFERS 8
37 #define ILO_MAX_CONST_BUFFERS (1 + 12)
38 #define ILO_MAX_SAMPLER_VIEWS 16
39 #define ILO_MAX_SAMPLERS 16
40 #define ILO_MAX_SO_BINDINGS 64
41 #define ILO_MAX_SO_BUFFERS 4
42 #define ILO_MAX_VIEWPORTS 1
43
44 #define ILO_MAX_VS_SURFACES (ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
45 #define ILO_VS_CONST_SURFACE(i) (i)
46 #define ILO_VS_TEXTURE_SURFACE(i) (ILO_MAX_CONST_BUFFERS + i)
47
48 #define ILO_MAX_GS_SURFACES (ILO_MAX_SO_BINDINGS)
49 #define ILO_GS_SO_SURFACE(i) (i)
50
51 #define ILO_MAX_WM_SURFACES (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
52 #define ILO_WM_DRAW_SURFACE(i) (i)
53 #define ILO_WM_CONST_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + i)
54 #define ILO_WM_TEXTURE_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + i)
55
56 struct ilo_vb_state {
57 struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS];
58 uint32_t enabled_mask;
59 };
60
61 struct ilo_ib_state {
62 struct pipe_index_buffer state;
63 };
64
65 struct ilo_ve_cso {
66 /* VERTEX_ELEMENT_STATE */
67 uint32_t payload[2];
68 };
69
70 struct ilo_ve_state {
71 struct ilo_ve_cso cso[PIPE_MAX_ATTRIBS];
72 unsigned count;
73
74 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
75 unsigned vb_mapping[PIPE_MAX_ATTRIBS];
76 unsigned vb_count;
77 };
78
79 struct ilo_so_state {
80 struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS];
81 unsigned count;
82 unsigned append_bitmask;
83
84 bool enabled;
85 };
86
87 struct ilo_viewport_cso {
88 /* matrix form */
89 float m00, m11, m22, m30, m31, m32;
90
91 /* guardband in NDC space */
92 float min_gbx, min_gby, max_gbx, max_gby;
93
94 /* viewport in screen space */
95 float min_x, min_y, min_z;
96 float max_x, max_y, max_z;
97 };
98
99 struct ilo_viewport_state {
100 struct ilo_viewport_cso cso[ILO_MAX_VIEWPORTS];
101 unsigned count;
102
103 struct pipe_viewport_state viewport0;
104 };
105
106 struct ilo_scissor_state {
107 /* SCISSOR_RECT */
108 uint32_t payload[ILO_MAX_VIEWPORTS * 2];
109 };
110
111 struct ilo_rasterizer_state {
112 struct pipe_rasterizer_state state;
113 };
114
115 struct ilo_dsa_state {
116 /* DEPTH_STENCIL_STATE */
117 uint32_t payload[3];
118
119 struct pipe_alpha_state alpha;
120 };
121
122 struct ilo_blend_cso {
123 /* BLEND_STATE */
124 uint32_t payload[2];
125
126 uint32_t dw_blend;
127 uint32_t dw_blend_dst_alpha_forced_one;
128
129 uint32_t dw_logicop;
130 uint32_t dw_alpha_mod;
131 };
132
133 struct ilo_blend_state {
134 struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
135
136 bool independent_blend_enable;
137 bool dual_blend;
138 bool alpha_to_coverage;
139 };
140
141 struct ilo_sampler_cso {
142 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
143 uint32_t payload[15];
144
145 uint32_t dw_filter;
146 uint32_t dw_filter_aniso;
147 uint32_t dw_wrap;
148 uint32_t dw_wrap_1d;
149 uint32_t dw_wrap_cube;
150
151 bool anisotropic;
152 bool saturate_r;
153 bool saturate_s;
154 bool saturate_t;
155 };
156
157 struct ilo_sampler_state {
158 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
159 unsigned count;
160 };
161
162 struct ilo_view_state {
163 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
164 unsigned count;
165 };
166
167 struct ilo_cbuf_state {
168 struct pipe_constant_buffer states[ILO_MAX_CONST_BUFFERS];
169 unsigned count;
170 };
171
172 struct ilo_resource_state {
173 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
174 unsigned count;
175 };
176
177 struct ilo_fb_state {
178 struct pipe_framebuffer_state state;
179
180 unsigned num_samples;
181 };
182
183 struct ilo_global_binding {
184 /*
185 * XXX These should not be treated as real resources (and there could be
186 * thousands of them). They should be treated as regions in GLOBAL
187 * resource, which is the only real resource.
188 *
189 * That is, a resource here should instead be
190 *
191 * struct ilo_global_region {
192 * struct pipe_resource base;
193 * int offset;
194 * int size;
195 * };
196 *
197 * and it describes the region [offset, offset + size) in GLOBAL
198 * resource.
199 */
200 struct pipe_resource *resources[PIPE_MAX_SHADER_RESOURCES];
201 uint32_t *handles[PIPE_MAX_SHADER_RESOURCES];
202 unsigned count;
203 };
204
205 void
206 ilo_gpe_init_ve(const struct ilo_dev_info *dev,
207 unsigned num_states,
208 const struct pipe_vertex_element *states,
209 struct ilo_ve_state *ve);
210
211 void
212 ilo_gpe_set_viewport_cso(const struct ilo_dev_info *dev,
213 const struct pipe_viewport_state *state,
214 struct ilo_viewport_cso *vp);
215
216 void
217 ilo_gpe_set_scissor(const struct ilo_dev_info *dev,
218 unsigned start_slot,
219 unsigned num_states,
220 const struct pipe_scissor_state *states,
221 struct ilo_scissor_state *scissor);
222
223 void
224 ilo_gpe_set_scissor_null(const struct ilo_dev_info *dev,
225 struct ilo_scissor_state *scissor);
226
227 void
228 ilo_gpe_init_dsa(const struct ilo_dev_info *dev,
229 const struct pipe_depth_stencil_alpha_state *state,
230 struct ilo_dsa_state *dsa);
231
232 void
233 ilo_gpe_init_blend(const struct ilo_dev_info *dev,
234 const struct pipe_blend_state *state,
235 struct ilo_blend_state *blend);
236
237 void
238 ilo_gpe_init_sampler_cso(const struct ilo_dev_info *dev,
239 const struct pipe_sampler_state *state,
240 struct ilo_sampler_cso *sampler);
241
242 #endif /* ILO_GPE_H */