2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "common/gen_device_info.h"
27 #include "genxml/gen_macros.h"
29 #include "brw_context.h"
30 #include "brw_state.h"
32 #include "intel_batchbuffer.h"
35 emit_dwords(struct brw_context
*brw
, unsigned n
)
37 intel_batchbuffer_begin(brw
, n
, RENDER_RING
);
38 uint32_t *map
= brw
->batch
.map_next
;
39 brw
->batch
.map_next
+= n
;
40 intel_batchbuffer_advance(brw
);
46 uint32_t read_domains
;
47 uint32_t write_domain
;
52 emit_reloc(struct brw_context
*brw
,
53 void *location
, struct brw_address address
, uint32_t delta
)
55 uint32_t offset
= (char *) location
- (char *) brw
->batch
.map
;
57 return brw_emit_reloc(&brw
->batch
, offset
, address
.bo
,
58 address
.offset
+ delta
,
60 address
.write_domain
);
63 #define __gen_address_type struct brw_address
64 #define __gen_user_data struct brw_context
67 __gen_combine_address(struct brw_context
*brw
, void *location
,
68 struct brw_address address
, uint32_t delta
)
70 if (address
.bo
== NULL
) {
71 return address
.offset
+ delta
;
73 return emit_reloc(brw
, location
, address
, delta
);
77 #include "genxml/genX_pack.h"
79 #define _brw_cmd_length(cmd) cmd ## _length
80 #define _brw_cmd_length_bias(cmd) cmd ## _length_bias
81 #define _brw_cmd_header(cmd) cmd ## _header
82 #define _brw_cmd_pack(cmd) cmd ## _pack
84 #define brw_batch_emit(brw, cmd, name) \
85 for (struct cmd name = { _brw_cmd_header(cmd) }, \
86 *_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
87 __builtin_expect(_dst != NULL, 1); \
88 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
91 #define brw_batch_emitn(brw, cmd, n) ({ \
92 uint32_t *_dw = emit_dwords(brw, n); \
93 struct cmd template = { \
94 _brw_cmd_header(cmd), \
95 .DWordLength = n - _brw_cmd_length_bias(cmd), \
97 _brw_cmd_pack(cmd)(brw, _dw, &template); \
98 _dw + 1; /* Array starts at dw[1] */ \
101 #define brw_state_emit(brw, cmd, align, offset, name) \
102 for (struct cmd name = { 0, }, \
103 *_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4, \
105 __builtin_expect(_dst != NULL, 1); \
106 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
109 /* ---------------------------------------------------------------------- */
112 /* ---------------------------------------------------------------------- */
115 genX(init_atoms
)(struct brw_context
*brw
)
118 static const struct brw_tracked_state
*render_atoms
[] =
120 /* Once all the programs are done, we know how large urb entry
121 * sizes need to be and can decide if we need to change the urb
125 &brw_recalculate_urb_fence
,
130 /* Surface state setup. Must come before the VS/WM unit. The binding
131 * table upload must be last.
133 &brw_vs_pull_constants
,
134 &brw_wm_pull_constants
,
135 &brw_renderbuffer_surfaces
,
136 &brw_renderbuffer_read_surfaces
,
137 &brw_texture_surfaces
,
138 &brw_vs_binding_table
,
139 &brw_wm_binding_table
,
144 /* These set up state for brw_psp_urb_cbs */
148 &brw_vs_unit
, /* always required, enabled or not */
154 &brw_invariant_state
,
156 &brw_binding_table_pointers
,
157 &brw_blend_constant_color
,
161 &brw_polygon_stipple
,
162 &brw_polygon_stipple_offset
,
169 &brw_indices
, /* must come before brw_vertices */
176 static const struct brw_tracked_state
*render_atoms
[] =
178 &gen6_sf_and_clip_viewports
,
180 /* Command packets: */
183 &gen6_viewport_state
, /* must do after *_vp stages */
186 &gen6_blend_state
, /* must do before cc unit */
187 &gen6_color_calc_state
, /* must do before cc unit */
188 &gen6_depth_stencil_state
, /* must do before cc unit */
190 &gen6_vs_push_constants
, /* Before vs_state */
191 &gen6_gs_push_constants
, /* Before gs_state */
192 &gen6_wm_push_constants
, /* Before wm_state */
194 /* Surface state setup. Must come before the VS/WM unit. The binding
195 * table upload must be last.
197 &brw_vs_pull_constants
,
198 &brw_vs_ubo_surfaces
,
199 &brw_gs_pull_constants
,
200 &brw_gs_ubo_surfaces
,
201 &brw_wm_pull_constants
,
202 &brw_wm_ubo_surfaces
,
203 &gen6_renderbuffer_surfaces
,
204 &brw_renderbuffer_read_surfaces
,
205 &brw_texture_surfaces
,
207 &brw_vs_binding_table
,
208 &gen6_gs_binding_table
,
209 &brw_wm_binding_table
,
215 &gen6_multisample_state
,
225 &gen6_binding_table_pointers
,
229 &brw_polygon_stipple
,
230 &brw_polygon_stipple_offset
,
236 &brw_indices
, /* must come before brw_vertices */
241 static const struct brw_tracked_state
*render_atoms
[] =
243 /* Command packets: */
246 &gen7_sf_clip_viewport
,
249 &gen7_push_constant_space
,
251 &gen6_blend_state
, /* must do before cc unit */
252 &gen6_color_calc_state
, /* must do before cc unit */
253 &gen6_depth_stencil_state
, /* must do before cc unit */
255 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
256 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
257 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
258 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
259 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
261 &gen6_vs_push_constants
, /* Before vs_state */
262 &gen7_tcs_push_constants
,
263 &gen7_tes_push_constants
,
264 &gen6_gs_push_constants
, /* Before gs_state */
265 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
267 /* Surface state setup. Must come before the VS/WM unit. The binding
268 * table upload must be last.
270 &brw_vs_pull_constants
,
271 &brw_vs_ubo_surfaces
,
272 &brw_vs_abo_surfaces
,
273 &brw_tcs_pull_constants
,
274 &brw_tcs_ubo_surfaces
,
275 &brw_tcs_abo_surfaces
,
276 &brw_tes_pull_constants
,
277 &brw_tes_ubo_surfaces
,
278 &brw_tes_abo_surfaces
,
279 &brw_gs_pull_constants
,
280 &brw_gs_ubo_surfaces
,
281 &brw_gs_abo_surfaces
,
282 &brw_wm_pull_constants
,
283 &brw_wm_ubo_surfaces
,
284 &brw_wm_abo_surfaces
,
285 &gen6_renderbuffer_surfaces
,
286 &brw_renderbuffer_read_surfaces
,
287 &brw_texture_surfaces
,
288 &brw_vs_binding_table
,
289 &brw_tcs_binding_table
,
290 &brw_tes_binding_table
,
291 &brw_gs_binding_table
,
292 &brw_wm_binding_table
,
299 &gen6_multisample_state
,
317 &brw_polygon_stipple
,
318 &brw_polygon_stipple_offset
,
324 &brw_indices
, /* must come before brw_vertices */
331 static const struct brw_tracked_state
*render_atoms
[] =
334 &gen8_sf_clip_viewport
,
337 &gen7_push_constant_space
,
340 &gen6_color_calc_state
,
342 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
343 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
344 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
345 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
346 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
348 &gen6_vs_push_constants
, /* Before vs_state */
349 &gen7_tcs_push_constants
,
350 &gen7_tes_push_constants
,
351 &gen6_gs_push_constants
, /* Before gs_state */
352 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
354 /* Surface state setup. Must come before the VS/WM unit. The binding
355 * table upload must be last.
357 &brw_vs_pull_constants
,
358 &brw_vs_ubo_surfaces
,
359 &brw_vs_abo_surfaces
,
360 &brw_tcs_pull_constants
,
361 &brw_tcs_ubo_surfaces
,
362 &brw_tcs_abo_surfaces
,
363 &brw_tes_pull_constants
,
364 &brw_tes_ubo_surfaces
,
365 &brw_tes_abo_surfaces
,
366 &brw_gs_pull_constants
,
367 &brw_gs_ubo_surfaces
,
368 &brw_gs_abo_surfaces
,
369 &brw_wm_pull_constants
,
370 &brw_wm_ubo_surfaces
,
371 &brw_wm_abo_surfaces
,
372 &gen6_renderbuffer_surfaces
,
373 &brw_renderbuffer_read_surfaces
,
374 &brw_texture_surfaces
,
375 &brw_vs_binding_table
,
376 &brw_tcs_binding_table
,
377 &brw_tes_binding_table
,
378 &brw_gs_binding_table
,
379 &brw_wm_binding_table
,
386 &gen8_multisample_state
,
401 &gen8_wm_depth_stencil
,
408 &brw_polygon_stipple
,
409 &brw_polygon_stipple_offset
,
426 STATIC_ASSERT(ARRAY_SIZE(render_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
427 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
428 render_atoms
, ARRAY_SIZE(render_atoms
));
431 static const struct brw_tracked_state
*compute_atoms
[] =
434 &brw_cs_image_surfaces
,
435 &gen7_cs_push_constants
,
436 &brw_cs_pull_constants
,
437 &brw_cs_ubo_surfaces
,
438 &brw_cs_abo_surfaces
,
439 &brw_cs_texture_surfaces
,
440 &brw_cs_work_groups_surface
,
445 STATIC_ASSERT(ARRAY_SIZE(compute_atoms
) <= ARRAY_SIZE(brw
->compute_atoms
));
446 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
447 compute_atoms
, ARRAY_SIZE(compute_atoms
));