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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef IRIS_CONTEXT_H
24 #define IRIS_CONTEXT_H
26 #include "pipe/p_context.h"
27 #include "pipe/p_state.h"
28 #include "util/u_debug.h"
29 #include "intel/blorp/blorp.h"
30 #include "intel/common/gen_debug.h"
31 #include "intel/compiler/brw_compiler.h"
32 #include "iris_batch.h"
33 #include "iris_screen.h"
40 #define IRIS_RESOURCE_FLAG_SHADER_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
41 #define IRIS_RESOURCE_FLAG_SURFACE_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
42 #define IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
44 #define IRIS_MAX_TEXTURE_SAMPLERS 32
45 #define IRIS_MAX_VIEWPORTS 16
47 #define IRIS_DIRTY_COLOR_CALC_STATE (1ull << 0)
48 #define IRIS_DIRTY_POLYGON_STIPPLE (1ull << 1)
49 #define IRIS_DIRTY_SCISSOR_RECT (1ull << 2)
50 #define IRIS_DIRTY_WM_DEPTH_STENCIL (1ull << 3)
51 #define IRIS_DIRTY_CC_VIEWPORT (1ull << 4)
52 #define IRIS_DIRTY_SF_CL_VIEWPORT (1ull << 5)
53 #define IRIS_DIRTY_PS_BLEND (1ull << 6)
54 #define IRIS_DIRTY_BLEND_STATE (1ull << 7)
55 #define IRIS_DIRTY_RASTER (1ull << 8)
56 #define IRIS_DIRTY_CLIP (1ull << 9)
57 // XXX: define IRIS_DIRTY_ (1ull << 10)
58 #define IRIS_DIRTY_LINE_STIPPLE (1ull << 11)
59 #define IRIS_DIRTY_VERTEX_ELEMENTS (1ull << 12)
60 #define IRIS_DIRTY_MULTISAMPLE (1ull << 13)
61 #define IRIS_DIRTY_VERTEX_BUFFERS (1ull << 14)
62 #define IRIS_DIRTY_SAMPLE_MASK (1ull << 15)
63 #define IRIS_DIRTY_SAMPLER_STATES_VS (1ull << 16)
64 #define IRIS_DIRTY_SAMPLER_STATES_TCS (1ull << 17)
65 #define IRIS_DIRTY_SAMPLER_STATES_TES (1ull << 18)
66 #define IRIS_DIRTY_SAMPLER_STATES_GS (1ull << 19)
67 #define IRIS_DIRTY_SAMPLER_STATES_PS (1ull << 20)
68 #define IRIS_DIRTY_SAMPLER_STATES_CS (1ull << 21)
69 #define IRIS_DIRTY_UNCOMPILED_VS (1ull << 22)
70 #define IRIS_DIRTY_UNCOMPILED_TCS (1ull << 23)
71 #define IRIS_DIRTY_UNCOMPILED_TES (1ull << 24)
72 #define IRIS_DIRTY_UNCOMPILED_GS (1ull << 25)
73 #define IRIS_DIRTY_UNCOMPILED_FS (1ull << 26)
74 #define IRIS_DIRTY_UNCOMPILED_CS (1ull << 27)
75 #define IRIS_DIRTY_VS (1ull << 28)
76 #define IRIS_DIRTY_TCS (1ull << 29)
77 #define IRIS_DIRTY_TES (1ull << 30)
78 #define IRIS_DIRTY_GS (1ull << 31)
79 #define IRIS_DIRTY_FS (1ull << 32)
80 #define IRIS_DIRTY_CS (1ull << 33)
81 #define IRIS_DIRTY_URB (1ull << 34)
82 #define IRIS_DIRTY_CONSTANTS_VS (1ull << 35)
83 #define IRIS_DIRTY_CONSTANTS_TCS (1ull << 36)
84 #define IRIS_DIRTY_CONSTANTS_TES (1ull << 37)
85 #define IRIS_DIRTY_CONSTANTS_GS (1ull << 38)
86 #define IRIS_DIRTY_CONSTANTS_FS (1ull << 39)
87 #define IRIS_DIRTY_DEPTH_BUFFER (1ull << 40)
88 #define IRIS_DIRTY_WM (1ull << 41)
89 #define IRIS_DIRTY_BINDINGS_VS (1ull << 42)
90 #define IRIS_DIRTY_BINDINGS_TCS (1ull << 43)
91 #define IRIS_DIRTY_BINDINGS_TES (1ull << 44)
92 #define IRIS_DIRTY_BINDINGS_GS (1ull << 45)
93 #define IRIS_DIRTY_BINDINGS_FS (1ull << 46)
94 #define IRIS_DIRTY_BINDINGS_CS (1ull << 47)
96 struct iris_depth_stencil_alpha_state
;
98 enum iris_program_cache_id
{
99 IRIS_CACHE_VS
= MESA_SHADER_VERTEX
,
100 IRIS_CACHE_TCS
= MESA_SHADER_TESS_CTRL
,
101 IRIS_CACHE_TES
= MESA_SHADER_TESS_EVAL
,
102 IRIS_CACHE_GS
= MESA_SHADER_GEOMETRY
,
103 IRIS_CACHE_FS
= MESA_SHADER_FRAGMENT
,
104 IRIS_CACHE_CS
= MESA_SHADER_COMPUTE
,
110 * PIPE_CONTROL operation, a combination MI_FLUSH and register write with
111 * additional flushing control.
113 * The bits here are not the actual hardware values. The actual values
114 * shift around a bit per-generation, so we just have flags for each
115 * potential operation, and use genxml to encode the actual packet.
117 enum pipe_control_flags
119 PIPE_CONTROL_FLUSH_LLC
= (1 << 1),
120 PIPE_CONTROL_LRI_POST_SYNC_OP
= (1 << 2),
121 PIPE_CONTROL_STORE_DATA_INDEX
= (1 << 3),
122 PIPE_CONTROL_CS_STALL
= (1 << 4),
123 PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET
= (1 << 5),
124 PIPE_CONTROL_SYNC_GFDT
= (1 << 6),
125 PIPE_CONTROL_TLB_INVALIDATE
= (1 << 7),
126 PIPE_CONTROL_MEDIA_STATE_CLEAR
= (1 << 8),
127 PIPE_CONTROL_WRITE_IMMEDIATE
= (1 << 9),
128 PIPE_CONTROL_WRITE_DEPTH_COUNT
= (1 << 10),
129 PIPE_CONTROL_WRITE_TIMESTAMP
= (1 << 11),
130 PIPE_CONTROL_DEPTH_STALL
= (1 << 12),
131 PIPE_CONTROL_RENDER_TARGET_FLUSH
= (1 << 13),
132 PIPE_CONTROL_INSTRUCTION_INVALIDATE
= (1 << 14),
133 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
= (1 << 15),
134 PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE
= (1 << 16),
135 PIPE_CONTROL_NOTIFY_ENABLE
= (1 << 17),
136 PIPE_CONTROL_FLUSH_ENABLE
= (1 << 18),
137 PIPE_CONTROL_DATA_CACHE_FLUSH
= (1 << 19),
138 PIPE_CONTROL_VF_CACHE_INVALIDATE
= (1 << 20),
139 PIPE_CONTROL_CONST_CACHE_INVALIDATE
= (1 << 21),
140 PIPE_CONTROL_STATE_CACHE_INVALIDATE
= (1 << 22),
141 PIPE_CONTROL_STALL_AT_SCOREBOARD
= (1 << 23),
142 PIPE_CONTROL_DEPTH_CACHE_FLUSH
= (1 << 24),
145 #define PIPE_CONTROL_CACHE_FLUSH_BITS \
146 (PIPE_CONTROL_DEPTH_CACHE_FLUSH | \
147 PIPE_CONTROL_DATA_CACHE_FLUSH | \
148 PIPE_CONTROL_RENDER_TARGET_FLUSH)
150 #define PIPE_CONTROL_CACHE_INVALIDATE_BITS \
151 (PIPE_CONTROL_STATE_CACHE_INVALIDATE | \
152 PIPE_CONTROL_CONST_CACHE_INVALIDATE | \
153 PIPE_CONTROL_VF_CACHE_INVALIDATE | \
154 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | \
155 PIPE_CONTROL_INSTRUCTION_INVALIDATE)
159 struct iris_compiled_shader
{
160 /** Buffer containing the uploaded assembly. */
161 struct pipe_resource
*buffer
;
163 /** Pointer to the assembly in the BO's map. */
166 /** The program data (owned by the program cache hash table) */
167 struct brw_stage_prog_data
*prog_data
;
169 /** Offset where the assembly lives in the BO. */
173 * Shader packets and other data derived from prog_data. These must be
174 * completely determined from prog_data.
176 uint8_t derived_data
[0];
179 struct iris_const_buffer
{
180 /** The resource and offset for the actual constant data */
181 struct pipe_resource
*resource
;
184 /** The resource and offset for the SURFACE_STATE for pull access. */
185 struct pipe_resource
*surface_state_resource
;
186 unsigned surface_state_offset
;
189 struct iris_shader_state
{
190 struct iris_const_buffer constbuf
[PIPE_MAX_CONSTANT_BUFFERS
];
194 void (*destroy_state
)(struct iris_context
*ice
);
195 void (*init_render_context
)(struct iris_screen
*screen
,
196 struct iris_batch
*batch
,
197 struct iris_vtable
*vtbl
,
198 struct pipe_debug_callback
*dbg
);
199 void (*upload_render_state
)(struct iris_context
*ice
,
200 struct iris_batch
*batch
,
201 const struct pipe_draw_info
*draw
);
202 void (*emit_raw_pipe_control
)(struct iris_batch
*batch
, uint32_t flags
,
203 struct iris_bo
*bo
, uint32_t offset
,
206 unsigned (*derived_program_state_size
)(enum iris_program_cache_id id
);
207 void (*store_derived_program_state
)(const struct gen_device_info
*devinfo
,
208 enum iris_program_cache_id cache_id
,
209 struct iris_compiled_shader
*shader
);
210 void (*populate_vs_key
)(const struct iris_context
*ice
,
211 struct brw_vs_prog_key
*key
);
212 void (*populate_tcs_key
)(const struct iris_context
*ice
,
213 struct brw_tcs_prog_key
*key
);
214 void (*populate_tes_key
)(const struct iris_context
*ice
,
215 struct brw_tes_prog_key
*key
);
216 void (*populate_gs_key
)(const struct iris_context
*ice
,
217 struct brw_gs_prog_key
*key
);
218 void (*populate_fs_key
)(const struct iris_context
*ice
,
219 struct brw_wm_prog_key
*key
);
222 struct iris_context
{
223 struct pipe_context ctx
;
225 struct pipe_debug_callback dbg
;
227 struct iris_vtable vtbl
;
230 struct iris_uncompiled_shader
*uncompiled
[MESA_SHADER_STAGES
];
231 struct iris_compiled_shader
*prog
[MESA_SHADER_STAGES
];
232 struct brw_vue_map
*last_vue_map
;
234 struct iris_shader_state state
[MESA_SHADER_STAGES
];
236 struct u_upload_mgr
*uploader
;
237 struct hash_table
*cache
;
242 struct blorp_context blorp
;
244 /** The main batch for rendering */
245 struct iris_batch render_batch
;
249 unsigned num_viewports
;
250 unsigned sample_mask
;
251 struct iris_blend_state
*cso_blend
;
252 struct iris_rasterizer_state
*cso_rast
;
253 struct iris_depth_stencil_alpha_state
*cso_zsa
;
254 struct iris_vertex_element_state
*cso_vertex_elements
;
255 struct iris_vertex_buffer_state
*cso_vertex_buffers
;
256 struct iris_viewport_state
*cso_vp
;
257 struct iris_depth_state
*cso_depth
;
258 struct pipe_blend_color blend_color
;
259 struct pipe_poly_stipple poly_stipple
;
260 struct pipe_scissor_state scissors
[IRIS_MAX_VIEWPORTS
];
261 struct pipe_stencil_ref stencil_ref
;
262 struct pipe_framebuffer_state framebuffer
;
263 struct iris_depth_buffer_state
*cso_depthbuffer
;
265 struct pipe_resource
*sampler_table_resource
[MESA_SHADER_STAGES
];
266 uint32_t sampler_table_offset
[MESA_SHADER_STAGES
];
267 struct iris_sampler_state
*samplers
[MESA_SHADER_STAGES
][IRIS_MAX_TEXTURE_SAMPLERS
];
268 struct iris_sampler_view
*textures
[MESA_SHADER_STAGES
][IRIS_MAX_TEXTURE_SAMPLERS
];
269 unsigned num_samplers
[MESA_SHADER_STAGES
];
270 unsigned num_textures
[MESA_SHADER_STAGES
];
272 struct u_upload_mgr
*surface_uploader
;
273 // XXX: may want a separate uploader for "hey I made a CSO!" vs
274 // "I'm streaming this out at draw time and never want it again!"
275 struct u_upload_mgr
*dynamic_uploader
;
278 * Resources containing streamed state which our render context
279 * currently points to. Used to re-add these to the validation
280 * list when we start a new batch and haven't resubmitted commands.
283 struct pipe_resource
*cc_vp
;
284 struct pipe_resource
*sf_cl_vp
;
285 struct pipe_resource
*color_calc
;
286 struct pipe_resource
*scissor
;
287 struct pipe_resource
*blend
;
292 #define perf_debug(dbg, ...) do { \
293 if (INTEL_DEBUG & DEBUG_PERF) \
294 dbg_printf(__VA_ARGS__); \
296 pipe_debug_message(dbg, PERF_INFO, __VA_ARGS__); \
299 double get_time(void);
301 struct pipe_context
*
302 iris_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
);
304 void iris_init_blit_functions(struct pipe_context
*ctx
);
305 void iris_init_clear_functions(struct pipe_context
*ctx
);
306 void iris_init_program_functions(struct pipe_context
*ctx
);
307 void iris_init_resource_functions(struct pipe_context
*ctx
);
308 void iris_init_query_functions(struct pipe_context
*ctx
);
309 void iris_update_compiled_shaders(struct iris_context
*ice
);
312 void iris_blorp_surf_for_resource(struct blorp_surf
*surf
,
313 struct pipe_resource
*p_res
,
314 enum isl_aux_usage aux_usage
,
315 bool is_render_target
);
319 void iris_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
);
321 /* iris_pipe_control.c */
323 void iris_emit_pipe_control_flush(struct iris_batch
*batch
,
325 void iris_emit_pipe_control_write(struct iris_batch
*batch
, uint32_t flags
,
326 struct iris_bo
*bo
, uint32_t offset
,
328 void iris_emit_end_of_pipe_sync(struct iris_batch
*batch
,
331 void iris_cache_sets_clear(struct iris_batch
*batch
);
332 void iris_cache_flush_for_read(struct iris_batch
*batch
, struct iris_bo
*bo
);
333 void iris_cache_flush_for_render(struct iris_batch
*batch
,
335 enum isl_format format
,
336 enum isl_aux_usage aux_usage
);
337 void iris_render_cache_add_bo(struct iris_batch
*batch
,
339 enum isl_format format
,
340 enum isl_aux_usage aux_usage
);
341 void iris_cache_flush_for_depth(struct iris_batch
*batch
, struct iris_bo
*bo
);
342 void iris_depth_cache_add_bo(struct iris_batch
*batch
, struct iris_bo
*bo
);
346 void gen9_init_blorp(struct iris_context
*ice
);
347 void gen10_init_blorp(struct iris_context
*ice
);
351 void gen9_init_state(struct iris_context
*ice
);
352 void gen10_init_state(struct iris_context
*ice
);
354 /* iris_program_cache.c */
356 void iris_init_program_cache(struct iris_context
*ice
);
357 void iris_destroy_program_cache(struct iris_context
*ice
);
358 void iris_print_program_cache(struct iris_context
*ice
);
359 bool iris_bind_cached_shader(struct iris_context
*ice
,
360 enum iris_program_cache_id cache_id
,
362 void iris_upload_and_bind_shader(struct iris_context
*ice
,
363 enum iris_program_cache_id cache_id
,
365 const void *assembly
,
366 struct brw_stage_prog_data
*prog_data
);
367 const void *iris_find_previous_compile(const struct iris_context
*ice
,
368 enum iris_program_cache_id cache_id
,
369 unsigned program_string_id
);
370 bool iris_blorp_lookup_shader(struct blorp_batch
*blorp_batch
,
373 uint32_t *kernel_out
,
374 void *prog_data_out
);
375 bool iris_blorp_upload_shader(struct blorp_batch
*blorp_batch
,
376 const void *key
, uint32_t key_size
,
377 const void *kernel
, uint32_t kernel_size
,
378 const struct brw_stage_prog_data
*prog_data
,
379 uint32_t prog_data_size
,
380 uint32_t *kernel_out
,
381 void *prog_data_out
);