1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *      Jerome Glisse
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci#ifndef R600_PIPE_H
27bf215546Sopenharmony_ci#define R600_PIPE_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "r600_pipe_common.h"
30bf215546Sopenharmony_ci#include "r600_cs.h"
31bf215546Sopenharmony_ci#include "r600_public.h"
32bf215546Sopenharmony_ci#include "pipe/p_defines.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "util/u_suballoc.h"
35bf215546Sopenharmony_ci#include "util/list.h"
36bf215546Sopenharmony_ci#include "util/u_transfer.h"
37bf215546Sopenharmony_ci#include "util/u_memory.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "tgsi/tgsi_scan.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#define R600_NUM_ATOMS 56
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci#define R600_MAX_IMAGES 8
44bf215546Sopenharmony_ci/*
45bf215546Sopenharmony_ci * ranges reserved for images on evergreen
46bf215546Sopenharmony_ci * first set for the immediate buffers,
47bf215546Sopenharmony_ci * second for the actual resources for RESQ.
48bf215546Sopenharmony_ci */
49bf215546Sopenharmony_ci#define R600_IMAGE_IMMED_RESOURCE_OFFSET 160
50bf215546Sopenharmony_ci#define R600_IMAGE_REAL_RESOURCE_OFFSET 168
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci/* read caches */
53bf215546Sopenharmony_ci#define R600_CONTEXT_INV_VERTEX_CACHE		(R600_CONTEXT_PRIVATE_FLAG << 0)
54bf215546Sopenharmony_ci#define R600_CONTEXT_INV_TEX_CACHE		(R600_CONTEXT_PRIVATE_FLAG << 1)
55bf215546Sopenharmony_ci#define R600_CONTEXT_INV_CONST_CACHE		(R600_CONTEXT_PRIVATE_FLAG << 2)
56bf215546Sopenharmony_ci/* read-write caches */
57bf215546Sopenharmony_ci#define R600_CONTEXT_FLUSH_AND_INV		(R600_CONTEXT_PRIVATE_FLAG << 3)
58bf215546Sopenharmony_ci#define R600_CONTEXT_FLUSH_AND_INV_CB_META	(R600_CONTEXT_PRIVATE_FLAG << 4)
59bf215546Sopenharmony_ci#define R600_CONTEXT_FLUSH_AND_INV_DB_META	(R600_CONTEXT_PRIVATE_FLAG << 5)
60bf215546Sopenharmony_ci#define R600_CONTEXT_FLUSH_AND_INV_DB		(R600_CONTEXT_PRIVATE_FLAG << 6)
61bf215546Sopenharmony_ci#define R600_CONTEXT_FLUSH_AND_INV_CB		(R600_CONTEXT_PRIVATE_FLAG << 7)
62bf215546Sopenharmony_ci/* engine synchronization */
63bf215546Sopenharmony_ci#define R600_CONTEXT_PS_PARTIAL_FLUSH		(R600_CONTEXT_PRIVATE_FLAG << 8)
64bf215546Sopenharmony_ci#define R600_CONTEXT_WAIT_3D_IDLE		(R600_CONTEXT_PRIVATE_FLAG << 9)
65bf215546Sopenharmony_ci#define R600_CONTEXT_WAIT_CP_DMA_IDLE		(R600_CONTEXT_PRIVATE_FLAG << 10)
66bf215546Sopenharmony_ci#define R600_CONTEXT_CS_PARTIAL_FLUSH           (R600_CONTEXT_PRIVATE_FLAG << 11)
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci/* the number of CS dwords for flushing and drawing */
69bf215546Sopenharmony_ci#define R600_MAX_FLUSH_CS_DWORDS	18
70bf215546Sopenharmony_ci#define R600_MAX_DRAW_CS_DWORDS		58
71bf215546Sopenharmony_ci#define R600_MAX_PFP_SYNC_ME_DWORDS	16
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci#define EG_MAX_ATOMIC_BUFFERS 8
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci#define R600_MAX_USER_CONST_BUFFERS 15
76bf215546Sopenharmony_ci#define R600_MAX_DRIVER_CONST_BUFFERS 3
77bf215546Sopenharmony_ci#define R600_MAX_CONST_BUFFERS (R600_MAX_USER_CONST_BUFFERS + R600_MAX_DRIVER_CONST_BUFFERS)
78bf215546Sopenharmony_ci#define R600_MAX_HW_CONST_BUFFERS 16
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci/* start driver buffers after user buffers */
81bf215546Sopenharmony_ci#define R600_BUFFER_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS)
82bf215546Sopenharmony_ci#define R600_UCP_SIZE (4*4*8)
83bf215546Sopenharmony_ci#define R600_CS_BLOCK_GRID_SIZE (8 * 4)
84bf215546Sopenharmony_ci#define R600_TCS_DEFAULT_LEVELS_SIZE (6 * 4)
85bf215546Sopenharmony_ci#define R600_BUFFER_INFO_OFFSET (R600_UCP_SIZE)
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci/*
88bf215546Sopenharmony_ci * We only access this buffer through vtx clauses hence it's fine to exist
89bf215546Sopenharmony_ci * at index beyond 15.
90bf215546Sopenharmony_ci */
91bf215546Sopenharmony_ci#define R600_LDS_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 1)
92bf215546Sopenharmony_ci/*
93bf215546Sopenharmony_ci * Note GS doesn't use a constant buffer binding, just a resource index,
94bf215546Sopenharmony_ci * so it's fine to have it exist at index beyond 15. I.e. it's not actually
95bf215546Sopenharmony_ci * a const buffer, just a buffer resource.
96bf215546Sopenharmony_ci */
97bf215546Sopenharmony_ci#define R600_GS_RING_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 2)
98bf215546Sopenharmony_ci/* Currently R600_MAX_CONST_BUFFERS just fits on the hw, which has a limit
99bf215546Sopenharmony_ci * of 16 const buffers.
100bf215546Sopenharmony_ci * UCP/SAMPLE_POSITIONS are never accessed by same shader stage so they can use the same id.
101bf215546Sopenharmony_ci *
102bf215546Sopenharmony_ci * In order to support d3d 11 mandated minimum of 15 user const buffers
103bf215546Sopenharmony_ci * we'd have to squash all use cases into one driver buffer.
104bf215546Sopenharmony_ci */
105bf215546Sopenharmony_ci#define R600_MAX_CONST_BUFFER_SIZE (4096 * sizeof(float[4]))
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci/* HW stages */
108bf215546Sopenharmony_ci#define R600_HW_STAGE_PS 0
109bf215546Sopenharmony_ci#define R600_HW_STAGE_VS 1
110bf215546Sopenharmony_ci#define R600_HW_STAGE_GS 2
111bf215546Sopenharmony_ci#define R600_HW_STAGE_ES 3
112bf215546Sopenharmony_ci#define EG_HW_STAGE_LS 4
113bf215546Sopenharmony_ci#define EG_HW_STAGE_HS 5
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci#define R600_NUM_HW_STAGES 4
116bf215546Sopenharmony_ci#define EG_NUM_HW_STAGES 6
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_cistruct r600_context;
119bf215546Sopenharmony_cistruct r600_bytecode;
120bf215546Sopenharmony_ciunion  r600_shader_key;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci/* This is an atom containing GPU commands that never change.
123bf215546Sopenharmony_ci * This is supposed to be copied directly into the CS. */
124bf215546Sopenharmony_cistruct r600_command_buffer {
125bf215546Sopenharmony_ci	uint32_t *buf;
126bf215546Sopenharmony_ci	unsigned num_dw;
127bf215546Sopenharmony_ci	unsigned max_num_dw;
128bf215546Sopenharmony_ci	unsigned pkt_flags;
129bf215546Sopenharmony_ci};
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_cistruct r600_db_state {
132bf215546Sopenharmony_ci	struct r600_atom		atom;
133bf215546Sopenharmony_ci	struct r600_surface		*rsurf;
134bf215546Sopenharmony_ci};
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_cistruct r600_db_misc_state {
137bf215546Sopenharmony_ci	struct r600_atom		atom;
138bf215546Sopenharmony_ci	bool				occlusion_queries_disabled;
139bf215546Sopenharmony_ci	bool				flush_depthstencil_through_cb;
140bf215546Sopenharmony_ci	bool				flush_depth_inplace;
141bf215546Sopenharmony_ci	bool				flush_stencil_inplace;
142bf215546Sopenharmony_ci	bool				copy_depth, copy_stencil;
143bf215546Sopenharmony_ci	unsigned			copy_sample;
144bf215546Sopenharmony_ci	unsigned			log_samples;
145bf215546Sopenharmony_ci	unsigned			db_shader_control;
146bf215546Sopenharmony_ci	bool				htile_clear;
147bf215546Sopenharmony_ci	uint8_t				ps_conservative_z;
148bf215546Sopenharmony_ci};
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_cistruct r600_cb_misc_state {
151bf215546Sopenharmony_ci	struct r600_atom atom;
152bf215546Sopenharmony_ci	unsigned cb_color_control; /* this comes from blend state */
153bf215546Sopenharmony_ci	unsigned blend_colormask; /* 8*4 bits for 8 RGBA colorbuffers */
154bf215546Sopenharmony_ci	unsigned nr_cbufs;
155bf215546Sopenharmony_ci	unsigned bound_cbufs_target_mask;
156bf215546Sopenharmony_ci	unsigned nr_ps_color_outputs;
157bf215546Sopenharmony_ci	unsigned ps_color_export_mask;
158bf215546Sopenharmony_ci	unsigned image_rat_enabled_mask;
159bf215546Sopenharmony_ci	unsigned buffer_rat_enabled_mask;
160bf215546Sopenharmony_ci	bool multiwrite;
161bf215546Sopenharmony_ci	bool dual_src_blend;
162bf215546Sopenharmony_ci};
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_cistruct r600_clip_misc_state {
165bf215546Sopenharmony_ci	struct r600_atom atom;
166bf215546Sopenharmony_ci	unsigned pa_cl_clip_cntl;   /* from rasterizer    */
167bf215546Sopenharmony_ci	unsigned pa_cl_vs_out_cntl; /* from vertex shader */
168bf215546Sopenharmony_ci	unsigned clip_plane_enable; /* from rasterizer    */
169bf215546Sopenharmony_ci	unsigned cc_dist_mask;      /* from vertex shader */
170bf215546Sopenharmony_ci	unsigned clip_dist_write;   /* from vertex shader */
171bf215546Sopenharmony_ci	unsigned cull_dist_write;   /* from vertex shader */
172bf215546Sopenharmony_ci	boolean clip_disable;       /* from vertex shader */
173bf215546Sopenharmony_ci	boolean vs_out_viewport;    /* from vertex shader */
174bf215546Sopenharmony_ci};
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_cistruct r600_alphatest_state {
177bf215546Sopenharmony_ci	struct r600_atom atom;
178bf215546Sopenharmony_ci	unsigned sx_alpha_test_control; /* this comes from dsa state */
179bf215546Sopenharmony_ci	unsigned sx_alpha_ref; /* this comes from dsa state */
180bf215546Sopenharmony_ci	bool bypass;
181bf215546Sopenharmony_ci	bool cb0_export_16bpc; /* from set_framebuffer_state */
182bf215546Sopenharmony_ci};
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_cistruct r600_vgt_state {
185bf215546Sopenharmony_ci	struct r600_atom atom;
186bf215546Sopenharmony_ci	uint32_t vgt_multi_prim_ib_reset_en;
187bf215546Sopenharmony_ci	uint32_t vgt_multi_prim_ib_reset_indx;
188bf215546Sopenharmony_ci	uint32_t vgt_indx_offset;
189bf215546Sopenharmony_ci	bool last_draw_was_indirect;
190bf215546Sopenharmony_ci};
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_cistruct r600_blend_color {
193bf215546Sopenharmony_ci	struct r600_atom atom;
194bf215546Sopenharmony_ci	struct pipe_blend_color state;
195bf215546Sopenharmony_ci};
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_cistruct r600_clip_state {
198bf215546Sopenharmony_ci	struct r600_atom atom;
199bf215546Sopenharmony_ci	struct pipe_clip_state state;
200bf215546Sopenharmony_ci};
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_cistruct r600_cs_shader_state {
203bf215546Sopenharmony_ci	struct r600_atom atom;
204bf215546Sopenharmony_ci	unsigned kernel_index;
205bf215546Sopenharmony_ci	unsigned pc;
206bf215546Sopenharmony_ci	struct r600_pipe_compute *shader;
207bf215546Sopenharmony_ci};
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_cistruct r600_framebuffer {
210bf215546Sopenharmony_ci	struct r600_atom atom;
211bf215546Sopenharmony_ci	struct pipe_framebuffer_state state;
212bf215546Sopenharmony_ci	unsigned compressed_cb_mask;
213bf215546Sopenharmony_ci	unsigned nr_samples;
214bf215546Sopenharmony_ci	bool export_16bpc;
215bf215546Sopenharmony_ci	bool cb0_is_integer;
216bf215546Sopenharmony_ci	bool is_msaa_resolve;
217bf215546Sopenharmony_ci	bool dual_src_blend;
218bf215546Sopenharmony_ci	bool do_update_surf_dirtiness;
219bf215546Sopenharmony_ci};
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_cistruct r600_sample_mask {
222bf215546Sopenharmony_ci	struct r600_atom atom;
223bf215546Sopenharmony_ci	uint16_t sample_mask; /* there are only 8 bits on EG, 16 bits on Cayman */
224bf215546Sopenharmony_ci};
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_cistruct r600_config_state {
227bf215546Sopenharmony_ci	struct r600_atom atom;
228bf215546Sopenharmony_ci	unsigned sq_gpr_resource_mgmt_1;
229bf215546Sopenharmony_ci	unsigned sq_gpr_resource_mgmt_2;
230bf215546Sopenharmony_ci	unsigned sq_gpr_resource_mgmt_3;
231bf215546Sopenharmony_ci	bool dyn_gpr_enabled;
232bf215546Sopenharmony_ci};
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_cistruct r600_stencil_ref
235bf215546Sopenharmony_ci{
236bf215546Sopenharmony_ci	ubyte ref_value[2];
237bf215546Sopenharmony_ci	ubyte valuemask[2];
238bf215546Sopenharmony_ci	ubyte writemask[2];
239bf215546Sopenharmony_ci};
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_cistruct r600_stencil_ref_state {
242bf215546Sopenharmony_ci	struct r600_atom atom;
243bf215546Sopenharmony_ci	struct r600_stencil_ref state;
244bf215546Sopenharmony_ci	struct pipe_stencil_ref pipe_state;
245bf215546Sopenharmony_ci};
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_cistruct r600_shader_stages_state {
248bf215546Sopenharmony_ci	struct r600_atom atom;
249bf215546Sopenharmony_ci	unsigned geom_enable;
250bf215546Sopenharmony_ci};
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_cistruct r600_gs_rings_state {
253bf215546Sopenharmony_ci	struct r600_atom atom;
254bf215546Sopenharmony_ci	unsigned enable;
255bf215546Sopenharmony_ci	struct pipe_constant_buffer esgs_ring;
256bf215546Sopenharmony_ci	struct pipe_constant_buffer gsvs_ring;
257bf215546Sopenharmony_ci};
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci/* This must start from 16. */
260bf215546Sopenharmony_ci/* features */
261bf215546Sopenharmony_ci#define DBG_NO_CP_DMA		(1 << 30)
262bf215546Sopenharmony_ci/* shader backend */
263bf215546Sopenharmony_ci#define DBG_NO_SB		(1 << 21)
264bf215546Sopenharmony_ci#define DBG_SB_DRY_RUN	(1 << 23)
265bf215546Sopenharmony_ci#define DBG_SB_STAT		(1 << 24)
266bf215546Sopenharmony_ci#define DBG_SB_DUMP		(1 << 25)
267bf215546Sopenharmony_ci#define DBG_SB_NO_FALLBACK	(1 << 26)
268bf215546Sopenharmony_ci#define DBG_SB_DISASM	(1 << 27)
269bf215546Sopenharmony_ci#define DBG_SB_SAFEMATH	(1 << 28)
270bf215546Sopenharmony_ci#define DBG_NIR_SB	(1 << 28)
271bf215546Sopenharmony_ci#define DBG_USE_TGSI	(1 << 29)
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ci#define DBG_NIR_PREFERRED (DBG_NIR_SB | DBG_NIR)
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_cistruct r600_screen {
276bf215546Sopenharmony_ci	struct r600_common_screen	b;
277bf215546Sopenharmony_ci	bool				has_msaa;
278bf215546Sopenharmony_ci	bool				has_compressed_msaa_texturing;
279bf215546Sopenharmony_ci	bool				has_atomics;
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci	/*for compute global memory binding, we allocate stuff here, instead of
282bf215546Sopenharmony_ci	 * buffers.
283bf215546Sopenharmony_ci	 * XXX: Not sure if this is the best place for global_pool.  Also,
284bf215546Sopenharmony_ci	 * it's not thread safe, so it won't work with multiple contexts. */
285bf215546Sopenharmony_ci	struct compute_memory_pool *global_pool;
286bf215546Sopenharmony_ci};
287bf215546Sopenharmony_ci
288bf215546Sopenharmony_cistruct r600_pipe_sampler_view {
289bf215546Sopenharmony_ci	struct pipe_sampler_view	base;
290bf215546Sopenharmony_ci	struct list_head		list;
291bf215546Sopenharmony_ci	struct r600_resource		*tex_resource;
292bf215546Sopenharmony_ci	uint32_t			tex_resource_words[8];
293bf215546Sopenharmony_ci	bool				skip_mip_address_reloc;
294bf215546Sopenharmony_ci	bool				is_stencil_sampler;
295bf215546Sopenharmony_ci};
296bf215546Sopenharmony_ci
297bf215546Sopenharmony_cistruct r600_rasterizer_state {
298bf215546Sopenharmony_ci	struct r600_command_buffer	buffer;
299bf215546Sopenharmony_ci	boolean				flatshade;
300bf215546Sopenharmony_ci	boolean				two_side;
301bf215546Sopenharmony_ci	unsigned			sprite_coord_enable;
302bf215546Sopenharmony_ci	unsigned                        clip_plane_enable;
303bf215546Sopenharmony_ci	unsigned			pa_sc_line_stipple;
304bf215546Sopenharmony_ci	unsigned			pa_cl_clip_cntl;
305bf215546Sopenharmony_ci	unsigned			pa_su_sc_mode_cntl;
306bf215546Sopenharmony_ci	float				offset_units;
307bf215546Sopenharmony_ci	float				offset_scale;
308bf215546Sopenharmony_ci	bool				offset_enable;
309bf215546Sopenharmony_ci	bool				offset_units_unscaled;
310bf215546Sopenharmony_ci	bool				scissor_enable;
311bf215546Sopenharmony_ci	bool				multisample_enable;
312bf215546Sopenharmony_ci	bool				clip_halfz;
313bf215546Sopenharmony_ci	bool				rasterizer_discard;
314bf215546Sopenharmony_ci};
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_cistruct r600_poly_offset_state {
317bf215546Sopenharmony_ci	struct r600_atom		atom;
318bf215546Sopenharmony_ci	enum pipe_format		zs_format;
319bf215546Sopenharmony_ci	float				offset_units;
320bf215546Sopenharmony_ci	float				offset_scale;
321bf215546Sopenharmony_ci	bool				offset_units_unscaled;
322bf215546Sopenharmony_ci};
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_cistruct r600_blend_state {
325bf215546Sopenharmony_ci	struct r600_command_buffer	buffer;
326bf215546Sopenharmony_ci	struct r600_command_buffer	buffer_no_blend;
327bf215546Sopenharmony_ci	unsigned			cb_target_mask;
328bf215546Sopenharmony_ci	unsigned			cb_color_control;
329bf215546Sopenharmony_ci	unsigned			cb_color_control_no_blend;
330bf215546Sopenharmony_ci	bool				dual_src_blend;
331bf215546Sopenharmony_ci	bool				alpha_to_one;
332bf215546Sopenharmony_ci};
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_cistruct r600_dsa_state {
335bf215546Sopenharmony_ci	struct r600_command_buffer	buffer;
336bf215546Sopenharmony_ci	unsigned			alpha_ref;
337bf215546Sopenharmony_ci	ubyte				valuemask[2];
338bf215546Sopenharmony_ci	ubyte				writemask[2];
339bf215546Sopenharmony_ci	unsigned			zwritemask;
340bf215546Sopenharmony_ci	unsigned			sx_alpha_test_control;
341bf215546Sopenharmony_ci};
342bf215546Sopenharmony_ci
343bf215546Sopenharmony_cistruct r600_pipe_shader;
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_cistruct r600_pipe_shader_selector {
346bf215546Sopenharmony_ci	struct r600_pipe_shader *current;
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci	struct tgsi_token       *tokens;
349bf215546Sopenharmony_ci        struct nir_shader       *nir;
350bf215546Sopenharmony_ci	struct pipe_stream_output_info  so;
351bf215546Sopenharmony_ci	struct tgsi_shader_info		info;
352bf215546Sopenharmony_ci
353bf215546Sopenharmony_ci	unsigned	num_shaders;
354bf215546Sopenharmony_ci
355bf215546Sopenharmony_ci	enum pipe_shader_type	type;
356bf215546Sopenharmony_ci        enum pipe_shader_ir ir_type;
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci	/* geometry shader properties */
359bf215546Sopenharmony_ci	enum pipe_prim_type	gs_output_prim;
360bf215546Sopenharmony_ci	unsigned		gs_max_out_vertices;
361bf215546Sopenharmony_ci	unsigned		gs_num_invocations;
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci	/* TCS/VS */
364bf215546Sopenharmony_ci	uint64_t        lds_patch_outputs_written_mask;
365bf215546Sopenharmony_ci	uint64_t        lds_outputs_written_mask;
366bf215546Sopenharmony_ci};
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_cistruct r600_pipe_sampler_state {
369bf215546Sopenharmony_ci	uint32_t			tex_sampler_words[3];
370bf215546Sopenharmony_ci	union pipe_color_union		border_color;
371bf215546Sopenharmony_ci	bool				border_color_use;
372bf215546Sopenharmony_ci	bool				seamless_cube_map;
373bf215546Sopenharmony_ci};
374bf215546Sopenharmony_ci
375bf215546Sopenharmony_ci/* needed for blitter save */
376bf215546Sopenharmony_ci#define NUM_TEX_UNITS 16
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_cistruct r600_seamless_cube_map {
379bf215546Sopenharmony_ci	struct r600_atom		atom;
380bf215546Sopenharmony_ci	bool				enabled;
381bf215546Sopenharmony_ci};
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_cistruct r600_samplerview_state {
384bf215546Sopenharmony_ci	struct r600_atom		atom;
385bf215546Sopenharmony_ci	struct r600_pipe_sampler_view	*views[NUM_TEX_UNITS];
386bf215546Sopenharmony_ci	uint32_t			enabled_mask;
387bf215546Sopenharmony_ci	uint32_t			dirty_mask;
388bf215546Sopenharmony_ci	uint32_t			compressed_depthtex_mask; /* which textures are depth */
389bf215546Sopenharmony_ci	uint32_t			compressed_colortex_mask;
390bf215546Sopenharmony_ci	boolean				dirty_buffer_constants;
391bf215546Sopenharmony_ci};
392bf215546Sopenharmony_ci
393bf215546Sopenharmony_cistruct r600_sampler_states {
394bf215546Sopenharmony_ci	struct r600_atom		atom;
395bf215546Sopenharmony_ci	struct r600_pipe_sampler_state	*states[NUM_TEX_UNITS];
396bf215546Sopenharmony_ci	uint32_t			enabled_mask;
397bf215546Sopenharmony_ci	uint32_t			dirty_mask;
398bf215546Sopenharmony_ci	uint32_t			has_bordercolor_mask; /* which states contain the border color */
399bf215546Sopenharmony_ci};
400bf215546Sopenharmony_ci
401bf215546Sopenharmony_cistruct r600_textures_info {
402bf215546Sopenharmony_ci	struct r600_samplerview_state	views;
403bf215546Sopenharmony_ci	struct r600_sampler_states	states;
404bf215546Sopenharmony_ci	bool				is_array_sampler[NUM_TEX_UNITS];
405bf215546Sopenharmony_ci};
406bf215546Sopenharmony_ci
407bf215546Sopenharmony_cistruct r600_shader_driver_constants_info {
408bf215546Sopenharmony_ci	/* currently 128 bytes for UCP/samplepos + sampler buffer constants */
409bf215546Sopenharmony_ci	uint32_t			*constants;
410bf215546Sopenharmony_ci	uint32_t			alloc_size;
411bf215546Sopenharmony_ci	bool				texture_const_dirty;
412bf215546Sopenharmony_ci	bool				vs_ucp_dirty;
413bf215546Sopenharmony_ci	bool				ps_sample_pos_dirty;
414bf215546Sopenharmony_ci	bool                            cs_block_grid_size_dirty;
415bf215546Sopenharmony_ci	bool				tcs_default_levels_dirty;
416bf215546Sopenharmony_ci};
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_cistruct r600_constbuf_state
419bf215546Sopenharmony_ci{
420bf215546Sopenharmony_ci	struct r600_atom		atom;
421bf215546Sopenharmony_ci	struct pipe_constant_buffer	cb[PIPE_MAX_CONSTANT_BUFFERS];
422bf215546Sopenharmony_ci	uint32_t			enabled_mask;
423bf215546Sopenharmony_ci	uint32_t			dirty_mask;
424bf215546Sopenharmony_ci};
425bf215546Sopenharmony_ci
426bf215546Sopenharmony_cistruct r600_vertexbuf_state
427bf215546Sopenharmony_ci{
428bf215546Sopenharmony_ci	struct r600_atom		atom;
429bf215546Sopenharmony_ci	struct pipe_vertex_buffer	vb[PIPE_MAX_ATTRIBS];
430bf215546Sopenharmony_ci	uint32_t			enabled_mask; /* non-NULL buffers */
431bf215546Sopenharmony_ci	uint32_t			dirty_mask;
432bf215546Sopenharmony_ci};
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci/* CSO (constant state object, in other words, immutable state). */
435bf215546Sopenharmony_cistruct r600_cso_state
436bf215546Sopenharmony_ci{
437bf215546Sopenharmony_ci	struct r600_atom atom;
438bf215546Sopenharmony_ci	void *cso; /* e.g. r600_blend_state */
439bf215546Sopenharmony_ci	struct r600_command_buffer *cb;
440bf215546Sopenharmony_ci};
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_cistruct r600_fetch_shader {
443bf215546Sopenharmony_ci	struct r600_resource		*buffer;
444bf215546Sopenharmony_ci	unsigned			offset;
445bf215546Sopenharmony_ci};
446bf215546Sopenharmony_ci
447bf215546Sopenharmony_cistruct r600_shader_state {
448bf215546Sopenharmony_ci	struct r600_atom		atom;
449bf215546Sopenharmony_ci	struct r600_pipe_shader *shader;
450bf215546Sopenharmony_ci};
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_cistruct r600_atomic_buffer_state {
453bf215546Sopenharmony_ci	struct pipe_shader_buffer buffer[EG_MAX_ATOMIC_BUFFERS];
454bf215546Sopenharmony_ci};
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_cistruct r600_image_view {
457bf215546Sopenharmony_ci	struct pipe_image_view base;
458bf215546Sopenharmony_ci	uint32_t cb_color_base;
459bf215546Sopenharmony_ci	uint32_t cb_color_pitch;
460bf215546Sopenharmony_ci	uint32_t cb_color_slice;
461bf215546Sopenharmony_ci	uint32_t cb_color_view;
462bf215546Sopenharmony_ci	uint32_t cb_color_info;
463bf215546Sopenharmony_ci	uint32_t cb_color_attrib;
464bf215546Sopenharmony_ci	uint32_t cb_color_dim;
465bf215546Sopenharmony_ci	uint32_t cb_color_fmask;
466bf215546Sopenharmony_ci	uint32_t cb_color_fmask_slice;
467bf215546Sopenharmony_ci	uint32_t immed_resource_words[8];
468bf215546Sopenharmony_ci	uint32_t resource_words[8];
469bf215546Sopenharmony_ci	bool skip_mip_address_reloc;
470bf215546Sopenharmony_ci	uint32_t buf_size;
471bf215546Sopenharmony_ci};
472bf215546Sopenharmony_ci
473bf215546Sopenharmony_cistruct r600_image_state {
474bf215546Sopenharmony_ci	struct r600_atom atom;
475bf215546Sopenharmony_ci	uint32_t                        enabled_mask;
476bf215546Sopenharmony_ci	uint32_t                        dirty_mask;
477bf215546Sopenharmony_ci	uint32_t			compressed_depthtex_mask;
478bf215546Sopenharmony_ci	uint32_t			compressed_colortex_mask;
479bf215546Sopenharmony_ci	boolean				dirty_buffer_constants;
480bf215546Sopenharmony_ci	struct r600_image_view views[R600_MAX_IMAGES];
481bf215546Sopenharmony_ci};
482bf215546Sopenharmony_ci
483bf215546Sopenharmony_ci/* Used to spill shader temps */
484bf215546Sopenharmony_cistruct r600_scratch_buffer {
485bf215546Sopenharmony_ci	struct r600_resource		*buffer;
486bf215546Sopenharmony_ci	boolean					dirty;
487bf215546Sopenharmony_ci	unsigned				size;
488bf215546Sopenharmony_ci	unsigned				item_size;
489bf215546Sopenharmony_ci};
490bf215546Sopenharmony_ci
491bf215546Sopenharmony_cistruct r600_context {
492bf215546Sopenharmony_ci	struct r600_common_context	b;
493bf215546Sopenharmony_ci	struct r600_screen		*screen;
494bf215546Sopenharmony_ci	struct blitter_context		*blitter;
495bf215546Sopenharmony_ci	struct u_suballocator		allocator_fetch_shader;
496bf215546Sopenharmony_ci
497bf215546Sopenharmony_ci	/* Hardware info. */
498bf215546Sopenharmony_ci	boolean				has_vertex_cache;
499bf215546Sopenharmony_ci	unsigned			default_gprs[EG_NUM_HW_STAGES];
500bf215546Sopenharmony_ci	unsigned                        current_gprs[EG_NUM_HW_STAGES];
501bf215546Sopenharmony_ci	unsigned			r6xx_num_clause_temp_gprs;
502bf215546Sopenharmony_ci
503bf215546Sopenharmony_ci	/* Miscellaneous state objects. */
504bf215546Sopenharmony_ci	void				*custom_dsa_flush;
505bf215546Sopenharmony_ci	void				*custom_blend_resolve;
506bf215546Sopenharmony_ci	void				*custom_blend_decompress;
507bf215546Sopenharmony_ci	void                            *custom_blend_fastclear;
508bf215546Sopenharmony_ci	/* With rasterizer discard, there doesn't have to be a pixel shader.
509bf215546Sopenharmony_ci	 * In that case, we bind this one: */
510bf215546Sopenharmony_ci	void				*dummy_pixel_shader;
511bf215546Sopenharmony_ci	/* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
512bf215546Sopenharmony_ci	 * bug where valid CMASK and FMASK are required to be present to avoid
513bf215546Sopenharmony_ci	 * a hardlock in certain operations but aren't actually used
514bf215546Sopenharmony_ci	 * for anything useful. */
515bf215546Sopenharmony_ci	struct r600_resource		*dummy_fmask;
516bf215546Sopenharmony_ci	struct r600_resource		*dummy_cmask;
517bf215546Sopenharmony_ci
518bf215546Sopenharmony_ci	/* State binding slots are here. */
519bf215546Sopenharmony_ci	struct r600_atom		*atoms[R600_NUM_ATOMS];
520bf215546Sopenharmony_ci	/* Dirty atom bitmask for fast tests */
521bf215546Sopenharmony_ci	uint64_t			dirty_atoms;
522bf215546Sopenharmony_ci	/* States for CS initialization. */
523bf215546Sopenharmony_ci	struct r600_command_buffer	start_cs_cmd; /* invariant state mostly */
524bf215546Sopenharmony_ci	/** Compute specific registers initializations.  The start_cs_cmd atom
525bf215546Sopenharmony_ci	 *  must be emitted before start_compute_cs_cmd. */
526bf215546Sopenharmony_ci	struct r600_command_buffer      start_compute_cs_cmd;
527bf215546Sopenharmony_ci	/* Register states. */
528bf215546Sopenharmony_ci	struct r600_alphatest_state	alphatest_state;
529bf215546Sopenharmony_ci	struct r600_cso_state		blend_state;
530bf215546Sopenharmony_ci	struct r600_blend_color		blend_color;
531bf215546Sopenharmony_ci	struct r600_cb_misc_state	cb_misc_state;
532bf215546Sopenharmony_ci	struct r600_clip_misc_state	clip_misc_state;
533bf215546Sopenharmony_ci	struct r600_clip_state		clip_state;
534bf215546Sopenharmony_ci	struct r600_db_misc_state	db_misc_state;
535bf215546Sopenharmony_ci	struct r600_db_state		db_state;
536bf215546Sopenharmony_ci	struct r600_cso_state		dsa_state;
537bf215546Sopenharmony_ci	struct r600_framebuffer		framebuffer;
538bf215546Sopenharmony_ci	struct r600_poly_offset_state	poly_offset_state;
539bf215546Sopenharmony_ci	struct r600_cso_state		rasterizer_state;
540bf215546Sopenharmony_ci	struct r600_sample_mask		sample_mask;
541bf215546Sopenharmony_ci	struct r600_seamless_cube_map	seamless_cube_map;
542bf215546Sopenharmony_ci	struct r600_config_state	config_state;
543bf215546Sopenharmony_ci	struct r600_stencil_ref_state	stencil_ref;
544bf215546Sopenharmony_ci	struct r600_vgt_state		vgt_state;
545bf215546Sopenharmony_ci	struct r600_atomic_buffer_state atomic_buffer_state;
546bf215546Sopenharmony_ci	/* only have images on fragment shader */
547bf215546Sopenharmony_ci	struct r600_image_state         fragment_images;
548bf215546Sopenharmony_ci	struct r600_image_state         compute_images;
549bf215546Sopenharmony_ci	struct r600_image_state         fragment_buffers;
550bf215546Sopenharmony_ci	struct r600_image_state         compute_buffers;
551bf215546Sopenharmony_ci	/* Shaders and shader resources. */
552bf215546Sopenharmony_ci	struct r600_cso_state		vertex_fetch_shader;
553bf215546Sopenharmony_ci	struct r600_shader_state        hw_shader_stages[EG_NUM_HW_STAGES];
554bf215546Sopenharmony_ci	struct r600_cs_shader_state	cs_shader_state;
555bf215546Sopenharmony_ci	struct r600_shader_stages_state shader_stages;
556bf215546Sopenharmony_ci	struct r600_gs_rings_state	gs_rings;
557bf215546Sopenharmony_ci	struct r600_constbuf_state	constbuf_state[PIPE_SHADER_TYPES];
558bf215546Sopenharmony_ci	struct r600_textures_info	samplers[PIPE_SHADER_TYPES];
559bf215546Sopenharmony_ci
560bf215546Sopenharmony_ci	struct r600_shader_driver_constants_info driver_consts[PIPE_SHADER_TYPES];
561bf215546Sopenharmony_ci
562bf215546Sopenharmony_ci	/** Vertex buffers for fetch shaders */
563bf215546Sopenharmony_ci	struct r600_vertexbuf_state	vertex_buffer_state;
564bf215546Sopenharmony_ci	/** Vertex buffers for compute shaders */
565bf215546Sopenharmony_ci	struct r600_vertexbuf_state	cs_vertex_buffer_state;
566bf215546Sopenharmony_ci
567bf215546Sopenharmony_ci	/* Additional context states. */
568bf215546Sopenharmony_ci	unsigned			compute_cb_target_mask;
569bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *ps_shader;
570bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *vs_shader;
571bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *gs_shader;
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *tcs_shader;
574bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *tes_shader;
575bf215546Sopenharmony_ci
576bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *fixed_func_tcs_shader;
577bf215546Sopenharmony_ci
578bf215546Sopenharmony_ci	struct r600_rasterizer_state	*rasterizer;
579bf215546Sopenharmony_ci	bool				alpha_to_one;
580bf215546Sopenharmony_ci	bool				force_blend_disable;
581bf215546Sopenharmony_ci	bool                            gs_tri_strip_adj_fix;
582bf215546Sopenharmony_ci	boolean				dual_src_blend;
583bf215546Sopenharmony_ci	unsigned			zwritemask;
584bf215546Sopenharmony_ci	unsigned			ps_iter_samples;
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci	/* The list of all texture buffer objects in this context.
587bf215546Sopenharmony_ci	 * This list is walked when a buffer is invalidated/reallocated and
588bf215546Sopenharmony_ci	 * the GPU addresses are updated. */
589bf215546Sopenharmony_ci	struct list_head		texture_buffers;
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_ci	/* Last draw state (-1 = unset). */
592bf215546Sopenharmony_ci	enum pipe_prim_type		last_primitive_type; /* Last primitive type used in draw_vbo. */
593bf215546Sopenharmony_ci	enum pipe_prim_type		current_rast_prim; /* primitive type after TES, GS */
594bf215546Sopenharmony_ci	enum pipe_prim_type		last_rast_prim;
595bf215546Sopenharmony_ci	unsigned			last_start_instance;
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci	void				*sb_context;
598bf215546Sopenharmony_ci	struct r600_isa		*isa;
599bf215546Sopenharmony_ci	float sample_positions[4 * 16];
600bf215546Sopenharmony_ci	float tess_state[8];
601bf215546Sopenharmony_ci	uint32_t cs_block_grid_sizes[8]; /* 3 for grid + 1 pad, 3 for block  + 1 pad*/
602bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *last_ls;
603bf215546Sopenharmony_ci	struct r600_pipe_shader_selector *last_tcs;
604bf215546Sopenharmony_ci	unsigned last_num_tcs_input_cp;
605bf215546Sopenharmony_ci	unsigned lds_alloc;
606bf215546Sopenharmony_ci
607bf215546Sopenharmony_ci	struct r600_scratch_buffer scratch_buffers[MAX2(R600_NUM_HW_STAGES, EG_NUM_HW_STAGES)];
608bf215546Sopenharmony_ci
609bf215546Sopenharmony_ci	/* Debug state. */
610bf215546Sopenharmony_ci	bool			is_debug;
611bf215546Sopenharmony_ci	struct radeon_saved_cs	last_gfx;
612bf215546Sopenharmony_ci	struct r600_resource	*last_trace_buf;
613bf215546Sopenharmony_ci	struct r600_resource	*trace_buf;
614bf215546Sopenharmony_ci	unsigned		trace_id;
615bf215546Sopenharmony_ci
616bf215546Sopenharmony_ci	uint8_t patch_vertices;
617bf215546Sopenharmony_ci	bool cmd_buf_is_compute;
618bf215546Sopenharmony_ci	struct pipe_resource *append_fence;
619bf215546Sopenharmony_ci	uint32_t append_fence_id;
620bf215546Sopenharmony_ci};
621bf215546Sopenharmony_ci
622bf215546Sopenharmony_cistatic inline void r600_emit_command_buffer(struct radeon_cmdbuf *cs,
623bf215546Sopenharmony_ci					    struct r600_command_buffer *cb)
624bf215546Sopenharmony_ci{
625bf215546Sopenharmony_ci	assert(cs->current.cdw + cb->num_dw <= cs->current.max_dw);
626bf215546Sopenharmony_ci	memcpy(cs->current.buf + cs->current.cdw, cb->buf, 4 * cb->num_dw);
627bf215546Sopenharmony_ci	cs->current.cdw += cb->num_dw;
628bf215546Sopenharmony_ci}
629bf215546Sopenharmony_ci
630bf215546Sopenharmony_cistatic inline void r600_set_atom_dirty(struct r600_context *rctx,
631bf215546Sopenharmony_ci				       struct r600_atom *atom,
632bf215546Sopenharmony_ci				       bool dirty)
633bf215546Sopenharmony_ci{
634bf215546Sopenharmony_ci	uint64_t mask;
635bf215546Sopenharmony_ci
636bf215546Sopenharmony_ci	assert(atom->id != 0);
637bf215546Sopenharmony_ci	assert(atom->id < sizeof(mask) * 8);
638bf215546Sopenharmony_ci	mask = 1ull << atom->id;
639bf215546Sopenharmony_ci	if (dirty)
640bf215546Sopenharmony_ci		rctx->dirty_atoms |= mask;
641bf215546Sopenharmony_ci	else
642bf215546Sopenharmony_ci		rctx->dirty_atoms &= ~mask;
643bf215546Sopenharmony_ci}
644bf215546Sopenharmony_ci
645bf215546Sopenharmony_cistatic inline void r600_mark_atom_dirty(struct r600_context *rctx,
646bf215546Sopenharmony_ci					struct r600_atom *atom)
647bf215546Sopenharmony_ci{
648bf215546Sopenharmony_ci	r600_set_atom_dirty(rctx, atom, true);
649bf215546Sopenharmony_ci}
650bf215546Sopenharmony_ci
651bf215546Sopenharmony_cistatic inline void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
652bf215546Sopenharmony_ci{
653bf215546Sopenharmony_ci	atom->emit(&rctx->b, atom);
654bf215546Sopenharmony_ci	r600_set_atom_dirty(rctx, atom, false);
655bf215546Sopenharmony_ci}
656bf215546Sopenharmony_ci
657bf215546Sopenharmony_cistatic inline void r600_set_cso_state(struct r600_context *rctx,
658bf215546Sopenharmony_ci				      struct r600_cso_state *state, void *cso)
659bf215546Sopenharmony_ci{
660bf215546Sopenharmony_ci	state->cso = cso;
661bf215546Sopenharmony_ci	r600_set_atom_dirty(rctx, &state->atom, cso != NULL);
662bf215546Sopenharmony_ci}
663bf215546Sopenharmony_ci
664bf215546Sopenharmony_cistatic inline void r600_set_cso_state_with_cb(struct r600_context *rctx,
665bf215546Sopenharmony_ci					      struct r600_cso_state *state, void *cso,
666bf215546Sopenharmony_ci					      struct r600_command_buffer *cb)
667bf215546Sopenharmony_ci{
668bf215546Sopenharmony_ci	state->cb = cb;
669bf215546Sopenharmony_ci	state->atom.num_dw = cb ? cb->num_dw : 0;
670bf215546Sopenharmony_ci	r600_set_cso_state(rctx, state, cso);
671bf215546Sopenharmony_ci}
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_ci/* compute_memory_pool.c */
674bf215546Sopenharmony_cistruct compute_memory_pool;
675bf215546Sopenharmony_civoid compute_memory_pool_delete(struct compute_memory_pool* pool);
676bf215546Sopenharmony_cistruct compute_memory_pool* compute_memory_pool_new(
677bf215546Sopenharmony_ci	struct r600_screen *rscreen);
678bf215546Sopenharmony_ci
679bf215546Sopenharmony_ci/* evergreen_state.c */
680bf215546Sopenharmony_cistruct pipe_sampler_view *
681bf215546Sopenharmony_cievergreen_create_sampler_view_custom(struct pipe_context *ctx,
682bf215546Sopenharmony_ci				     struct pipe_resource *texture,
683bf215546Sopenharmony_ci				     const struct pipe_sampler_view *state,
684bf215546Sopenharmony_ci				     unsigned width0, unsigned height0,
685bf215546Sopenharmony_ci				     unsigned force_level);
686bf215546Sopenharmony_civoid evergreen_init_common_regs(struct r600_context *ctx,
687bf215546Sopenharmony_ci				struct r600_command_buffer *cb,
688bf215546Sopenharmony_ci				enum amd_gfx_level ctx_chip_class,
689bf215546Sopenharmony_ci				enum radeon_family ctx_family,
690bf215546Sopenharmony_ci				int ctx_drm_minor);
691bf215546Sopenharmony_civoid cayman_init_common_regs(struct r600_command_buffer *cb,
692bf215546Sopenharmony_ci			     enum amd_gfx_level ctx_chip_class,
693bf215546Sopenharmony_ci			     enum radeon_family ctx_family,
694bf215546Sopenharmony_ci			     int ctx_drm_minor);
695bf215546Sopenharmony_ci
696bf215546Sopenharmony_civoid evergreen_init_state_functions(struct r600_context *rctx);
697bf215546Sopenharmony_civoid evergreen_init_atom_start_cs(struct r600_context *rctx);
698bf215546Sopenharmony_civoid evergreen_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
699bf215546Sopenharmony_civoid evergreen_update_es_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
700bf215546Sopenharmony_civoid evergreen_update_gs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
701bf215546Sopenharmony_civoid evergreen_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
702bf215546Sopenharmony_civoid evergreen_update_ls_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
703bf215546Sopenharmony_civoid evergreen_update_hs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
704bf215546Sopenharmony_civoid *evergreen_create_db_flush_dsa(struct r600_context *rctx);
705bf215546Sopenharmony_civoid *evergreen_create_resolve_blend(struct r600_context *rctx);
706bf215546Sopenharmony_civoid *evergreen_create_decompress_blend(struct r600_context *rctx);
707bf215546Sopenharmony_civoid *evergreen_create_fastclear_blend(struct r600_context *rctx);
708bf215546Sopenharmony_cibool evergreen_is_format_supported(struct pipe_screen *screen,
709bf215546Sopenharmony_ci				   enum pipe_format format,
710bf215546Sopenharmony_ci				   enum pipe_texture_target target,
711bf215546Sopenharmony_ci				   unsigned sample_count,
712bf215546Sopenharmony_ci				   unsigned storage_sample_count,
713bf215546Sopenharmony_ci				   unsigned usage);
714bf215546Sopenharmony_civoid evergreen_init_color_surface(struct r600_context *rctx,
715bf215546Sopenharmony_ci				  struct r600_surface *surf);
716bf215546Sopenharmony_civoid evergreen_init_color_surface_rat(struct r600_context *rctx,
717bf215546Sopenharmony_ci					struct r600_surface *surf);
718bf215546Sopenharmony_civoid evergreen_update_db_shader_control(struct r600_context * rctx);
719bf215546Sopenharmony_cibool evergreen_adjust_gprs(struct r600_context *rctx);
720bf215546Sopenharmony_civoid evergreen_setup_scratch_buffers(struct r600_context *rctx);
721bf215546Sopenharmony_ciuint32_t evergreen_construct_rat_mask(struct r600_context *rctx, struct r600_cb_misc_state *a,
722bf215546Sopenharmony_ci				      unsigned nr_cbufs);
723bf215546Sopenharmony_ci/* r600_blit.c */
724bf215546Sopenharmony_civoid r600_init_blit_functions(struct r600_context *rctx);
725bf215546Sopenharmony_civoid r600_decompress_depth_textures(struct r600_context *rctx,
726bf215546Sopenharmony_ci				    struct r600_samplerview_state *textures);
727bf215546Sopenharmony_civoid r600_decompress_depth_images(struct r600_context *rctx,
728bf215546Sopenharmony_ci				  struct r600_image_state *images);
729bf215546Sopenharmony_civoid r600_decompress_color_textures(struct r600_context *rctx,
730bf215546Sopenharmony_ci				    struct r600_samplerview_state *textures);
731bf215546Sopenharmony_civoid r600_decompress_color_images(struct r600_context *rctx,
732bf215546Sopenharmony_ci				  struct r600_image_state *images);
733bf215546Sopenharmony_civoid r600_resource_copy_region(struct pipe_context *ctx,
734bf215546Sopenharmony_ci			       struct pipe_resource *dst,
735bf215546Sopenharmony_ci			       unsigned dst_level,
736bf215546Sopenharmony_ci			       unsigned dstx, unsigned dsty, unsigned dstz,
737bf215546Sopenharmony_ci			       struct pipe_resource *src,
738bf215546Sopenharmony_ci			       unsigned src_level,
739bf215546Sopenharmony_ci			       const struct pipe_box *src_box);
740bf215546Sopenharmony_ci
741bf215546Sopenharmony_ci/* r600_shader.c */
742bf215546Sopenharmony_ciint r600_pipe_shader_create(struct pipe_context *ctx,
743bf215546Sopenharmony_ci			    struct r600_pipe_shader *shader,
744bf215546Sopenharmony_ci			    union r600_shader_key key);
745bf215546Sopenharmony_ci
746bf215546Sopenharmony_civoid r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
747bf215546Sopenharmony_ci
748bf215546Sopenharmony_ci/* r600_state.c */
749bf215546Sopenharmony_cistruct pipe_sampler_view *
750bf215546Sopenharmony_cir600_create_sampler_view_custom(struct pipe_context *ctx,
751bf215546Sopenharmony_ci				struct pipe_resource *texture,
752bf215546Sopenharmony_ci				const struct pipe_sampler_view *state,
753bf215546Sopenharmony_ci				unsigned width_first_level, unsigned height_first_level);
754bf215546Sopenharmony_civoid r600_init_state_functions(struct r600_context *rctx);
755bf215546Sopenharmony_civoid r600_init_atom_start_cs(struct r600_context *rctx);
756bf215546Sopenharmony_civoid r600_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
757bf215546Sopenharmony_civoid r600_update_es_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
758bf215546Sopenharmony_civoid r600_update_gs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
759bf215546Sopenharmony_civoid r600_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
760bf215546Sopenharmony_civoid *r600_create_db_flush_dsa(struct r600_context *rctx);
761bf215546Sopenharmony_civoid *r600_create_resolve_blend(struct r600_context *rctx);
762bf215546Sopenharmony_civoid *r700_create_resolve_blend(struct r600_context *rctx);
763bf215546Sopenharmony_civoid *r600_create_decompress_blend(struct r600_context *rctx);
764bf215546Sopenharmony_cibool r600_adjust_gprs(struct r600_context *rctx);
765bf215546Sopenharmony_cibool r600_is_format_supported(struct pipe_screen *screen,
766bf215546Sopenharmony_ci			      enum pipe_format format,
767bf215546Sopenharmony_ci			      enum pipe_texture_target target,
768bf215546Sopenharmony_ci			      unsigned sample_count,
769bf215546Sopenharmony_ci			      unsigned storage_sample_count,
770bf215546Sopenharmony_ci			      unsigned usage);
771bf215546Sopenharmony_civoid r600_update_db_shader_control(struct r600_context * rctx);
772bf215546Sopenharmony_civoid r600_setup_scratch_buffers(struct r600_context *rctx);
773bf215546Sopenharmony_ci
774bf215546Sopenharmony_ci/* r600_hw_context.c */
775bf215546Sopenharmony_civoid r600_context_gfx_flush(void *context, unsigned flags,
776bf215546Sopenharmony_ci			    struct pipe_fence_handle **fence);
777bf215546Sopenharmony_civoid r600_begin_new_cs(struct r600_context *ctx);
778bf215546Sopenharmony_civoid r600_flush_emit(struct r600_context *ctx);
779bf215546Sopenharmony_civoid r600_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in, unsigned num_atomics);
780bf215546Sopenharmony_civoid r600_emit_pfp_sync_me(struct r600_context *rctx);
781bf215546Sopenharmony_civoid r600_cp_dma_copy_buffer(struct r600_context *rctx,
782bf215546Sopenharmony_ci			     struct pipe_resource *dst, uint64_t dst_offset,
783bf215546Sopenharmony_ci			     struct pipe_resource *src, uint64_t src_offset,
784bf215546Sopenharmony_ci			     unsigned size);
785bf215546Sopenharmony_civoid evergreen_cp_dma_clear_buffer(struct r600_context *rctx,
786bf215546Sopenharmony_ci				   struct pipe_resource *dst, uint64_t offset,
787bf215546Sopenharmony_ci				   unsigned size, uint32_t clear_value,
788bf215546Sopenharmony_ci				   enum r600_coherency coher);
789bf215546Sopenharmony_civoid r600_dma_copy_buffer(struct r600_context *rctx,
790bf215546Sopenharmony_ci			  struct pipe_resource *dst,
791bf215546Sopenharmony_ci			  struct pipe_resource *src,
792bf215546Sopenharmony_ci			  uint64_t dst_offset,
793bf215546Sopenharmony_ci			  uint64_t src_offset,
794bf215546Sopenharmony_ci			  uint64_t size);
795bf215546Sopenharmony_ci
796bf215546Sopenharmony_ci/*
797bf215546Sopenharmony_ci * evergreen_hw_context.c
798bf215546Sopenharmony_ci */
799bf215546Sopenharmony_civoid evergreen_dma_copy_buffer(struct r600_context *rctx,
800bf215546Sopenharmony_ci			       struct pipe_resource *dst,
801bf215546Sopenharmony_ci			       struct pipe_resource *src,
802bf215546Sopenharmony_ci			       uint64_t dst_offset,
803bf215546Sopenharmony_ci			       uint64_t src_offset,
804bf215546Sopenharmony_ci			       uint64_t size);
805bf215546Sopenharmony_civoid evergreen_setup_tess_constants(struct r600_context *rctx,
806bf215546Sopenharmony_ci				    const struct pipe_draw_info *info,
807bf215546Sopenharmony_ci				    unsigned *num_patches);
808bf215546Sopenharmony_ciuint32_t evergreen_get_ls_hs_config(struct r600_context *rctx,
809bf215546Sopenharmony_ci				    const struct pipe_draw_info *info,
810bf215546Sopenharmony_ci				    unsigned num_patches);
811bf215546Sopenharmony_civoid evergreen_set_ls_hs_config(struct r600_context *rctx,
812bf215546Sopenharmony_ci				struct radeon_cmdbuf *cs,
813bf215546Sopenharmony_ci				uint32_t ls_hs_config);
814bf215546Sopenharmony_civoid evergreen_set_lds_alloc(struct r600_context *rctx,
815bf215546Sopenharmony_ci			     struct radeon_cmdbuf *cs,
816bf215546Sopenharmony_ci			     uint32_t lds_alloc);
817bf215546Sopenharmony_ci
818bf215546Sopenharmony_ci/* r600_state_common.c */
819bf215546Sopenharmony_civoid r600_init_common_state_functions(struct r600_context *rctx);
820bf215546Sopenharmony_civoid r600_emit_cso_state(struct r600_context *rctx, struct r600_atom *atom);
821bf215546Sopenharmony_civoid r600_emit_alphatest_state(struct r600_context *rctx, struct r600_atom *atom);
822bf215546Sopenharmony_civoid r600_emit_blend_color(struct r600_context *rctx, struct r600_atom *atom);
823bf215546Sopenharmony_civoid r600_emit_vgt_state(struct r600_context *rctx, struct r600_atom *atom);
824bf215546Sopenharmony_civoid r600_emit_clip_misc_state(struct r600_context *rctx, struct r600_atom *atom);
825bf215546Sopenharmony_civoid r600_emit_stencil_ref(struct r600_context *rctx, struct r600_atom *atom);
826bf215546Sopenharmony_civoid r600_emit_shader(struct r600_context *rctx, struct r600_atom *a);
827bf215546Sopenharmony_civoid r600_add_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id);
828bf215546Sopenharmony_civoid r600_init_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id,
829bf215546Sopenharmony_ci		    void (*emit)(struct r600_context *ctx, struct r600_atom *state),
830bf215546Sopenharmony_ci		    unsigned num_dw);
831bf215546Sopenharmony_civoid r600_vertex_buffers_dirty(struct r600_context *rctx);
832bf215546Sopenharmony_civoid r600_sampler_views_dirty(struct r600_context *rctx,
833bf215546Sopenharmony_ci			      struct r600_samplerview_state *state);
834bf215546Sopenharmony_civoid r600_sampler_states_dirty(struct r600_context *rctx,
835bf215546Sopenharmony_ci			       struct r600_sampler_states *state);
836bf215546Sopenharmony_civoid r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf_state *state);
837bf215546Sopenharmony_civoid r600_set_sample_locations_constant_buffer(struct r600_context *rctx);
838bf215546Sopenharmony_civoid r600_setup_scratch_area_for_shader(struct r600_context *rctx,
839bf215546Sopenharmony_ci	struct r600_pipe_shader *shader, struct r600_scratch_buffer *scratch,
840bf215546Sopenharmony_ci	unsigned ring_base_reg, unsigned item_size_reg, unsigned ring_size_reg);
841bf215546Sopenharmony_ciuint32_t r600_translate_stencil_op(int s_op);
842bf215546Sopenharmony_ciuint32_t r600_translate_fill(uint32_t func);
843bf215546Sopenharmony_ciunsigned r600_tex_wrap(unsigned wrap);
844bf215546Sopenharmony_ciunsigned r600_tex_mipfilter(unsigned filter);
845bf215546Sopenharmony_ciunsigned r600_tex_compare(unsigned compare);
846bf215546Sopenharmony_cibool sampler_state_needs_border_color(const struct pipe_sampler_state *state);
847bf215546Sopenharmony_ciunsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
848bf215546Sopenharmony_ci				   const unsigned char *swizzle_view,
849bf215546Sopenharmony_ci				   boolean vtx);
850bf215546Sopenharmony_ciuint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
851bf215546Sopenharmony_ci				  const unsigned char *swizzle_view,
852bf215546Sopenharmony_ci				  uint32_t *word4_p, uint32_t *yuv_format_p,
853bf215546Sopenharmony_ci				  bool do_endian_swap);
854bf215546Sopenharmony_ciuint32_t r600_translate_colorformat(enum amd_gfx_level chip, enum pipe_format format,
855bf215546Sopenharmony_ci				  bool do_endian_swap);
856bf215546Sopenharmony_ciuint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap);
857bf215546Sopenharmony_ci
858bf215546Sopenharmony_ci/* r600_uvd.c */
859bf215546Sopenharmony_cistruct pipe_video_codec *r600_uvd_create_decoder(struct pipe_context *context,
860bf215546Sopenharmony_ci						   const struct pipe_video_codec *decoder);
861bf215546Sopenharmony_ci
862bf215546Sopenharmony_cistruct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
863bf215546Sopenharmony_ci						   const struct pipe_video_buffer *tmpl);
864bf215546Sopenharmony_ci
865bf215546Sopenharmony_ci/*
866bf215546Sopenharmony_ci * Helpers for building command buffers
867bf215546Sopenharmony_ci */
868bf215546Sopenharmony_ci
869bf215546Sopenharmony_ci#define PKT3_SET_CONFIG_REG	0x68
870bf215546Sopenharmony_ci#define PKT3_SET_CONTEXT_REG	0x69
871bf215546Sopenharmony_ci#define PKT3_SET_CTL_CONST      0x6F
872bf215546Sopenharmony_ci#define PKT3_SET_LOOP_CONST                    0x6C
873bf215546Sopenharmony_ci
874bf215546Sopenharmony_ci#define R600_CONFIG_REG_OFFSET	0x08000
875bf215546Sopenharmony_ci#define R600_CONTEXT_REG_OFFSET 0x28000
876bf215546Sopenharmony_ci#define R600_CTL_CONST_OFFSET   0x3CFF0
877bf215546Sopenharmony_ci#define R600_LOOP_CONST_OFFSET                 0X0003E200
878bf215546Sopenharmony_ci#define EG_LOOP_CONST_OFFSET               0x0003A200
879bf215546Sopenharmony_ci
880bf215546Sopenharmony_ci#define PKT_TYPE_S(x)                   (((unsigned)(x) & 0x3) << 30)
881bf215546Sopenharmony_ci#define PKT_COUNT_S(x)                  (((unsigned)(x) & 0x3FFF) << 16)
882bf215546Sopenharmony_ci#define PKT3_IT_OPCODE_S(x)             (((unsigned)(x) & 0xFF) << 8)
883bf215546Sopenharmony_ci#define PKT3_PREDICATE(x)               (((x) >> 0) & 0x1)
884bf215546Sopenharmony_ci#define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
885bf215546Sopenharmony_ci
886bf215546Sopenharmony_ci#define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
887bf215546Sopenharmony_ci
888bf215546Sopenharmony_ci/*Evergreen Compute packet3*/
889bf215546Sopenharmony_ci#define PKT3C(op, count, predicate) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count) | PKT3_PREDICATE(predicate) | RADEON_CP_PACKET3_COMPUTE_MODE)
890bf215546Sopenharmony_ci
891bf215546Sopenharmony_cistatic inline void r600_store_value(struct r600_command_buffer *cb, unsigned value)
892bf215546Sopenharmony_ci{
893bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = value;
894bf215546Sopenharmony_ci}
895bf215546Sopenharmony_ci
896bf215546Sopenharmony_cistatic inline void r600_store_array(struct r600_command_buffer *cb, unsigned num, unsigned *ptr)
897bf215546Sopenharmony_ci{
898bf215546Sopenharmony_ci	assert(cb->num_dw+num <= cb->max_num_dw);
899bf215546Sopenharmony_ci	memcpy(&cb->buf[cb->num_dw], ptr, num * sizeof(ptr[0]));
900bf215546Sopenharmony_ci	cb->num_dw += num;
901bf215546Sopenharmony_ci}
902bf215546Sopenharmony_ci
903bf215546Sopenharmony_cistatic inline void r600_store_config_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
904bf215546Sopenharmony_ci{
905bf215546Sopenharmony_ci	assert(reg < R600_CONTEXT_REG_OFFSET);
906bf215546Sopenharmony_ci	assert(cb->num_dw+2+num <= cb->max_num_dw);
907bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
908bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
909bf215546Sopenharmony_ci}
910bf215546Sopenharmony_ci
911bf215546Sopenharmony_ci/**
912bf215546Sopenharmony_ci * Needs cb->pkt_flags set to  RADEON_CP_PACKET3_COMPUTE_MODE for compute
913bf215546Sopenharmony_ci * shaders.
914bf215546Sopenharmony_ci */
915bf215546Sopenharmony_cistatic inline void r600_store_context_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
916bf215546Sopenharmony_ci{
917bf215546Sopenharmony_ci	assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
918bf215546Sopenharmony_ci	assert(cb->num_dw+2+num <= cb->max_num_dw);
919bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0) | cb->pkt_flags;
920bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
921bf215546Sopenharmony_ci}
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci/**
924bf215546Sopenharmony_ci * Needs cb->pkt_flags set to  RADEON_CP_PACKET3_COMPUTE_MODE for compute
925bf215546Sopenharmony_ci * shaders.
926bf215546Sopenharmony_ci */
927bf215546Sopenharmony_cistatic inline void r600_store_ctl_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
928bf215546Sopenharmony_ci{
929bf215546Sopenharmony_ci	assert(reg >= R600_CTL_CONST_OFFSET);
930bf215546Sopenharmony_ci	assert(cb->num_dw+2+num <= cb->max_num_dw);
931bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CTL_CONST, num, 0) | cb->pkt_flags;
932bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
933bf215546Sopenharmony_ci}
934bf215546Sopenharmony_ci
935bf215546Sopenharmony_cistatic inline void r600_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
936bf215546Sopenharmony_ci{
937bf215546Sopenharmony_ci	assert(reg >= R600_LOOP_CONST_OFFSET);
938bf215546Sopenharmony_ci	assert(cb->num_dw+2+num <= cb->max_num_dw);
939bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0);
940bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = (reg - R600_LOOP_CONST_OFFSET) >> 2;
941bf215546Sopenharmony_ci}
942bf215546Sopenharmony_ci
943bf215546Sopenharmony_ci/**
944bf215546Sopenharmony_ci * Needs cb->pkt_flags set to  RADEON_CP_PACKET3_COMPUTE_MODE for compute
945bf215546Sopenharmony_ci * shaders.
946bf215546Sopenharmony_ci */
947bf215546Sopenharmony_cistatic inline void eg_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
948bf215546Sopenharmony_ci{
949bf215546Sopenharmony_ci	assert(reg >= EG_LOOP_CONST_OFFSET);
950bf215546Sopenharmony_ci	assert(cb->num_dw+2+num <= cb->max_num_dw);
951bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0) | cb->pkt_flags;
952bf215546Sopenharmony_ci	cb->buf[cb->num_dw++] = (reg - EG_LOOP_CONST_OFFSET) >> 2;
953bf215546Sopenharmony_ci}
954bf215546Sopenharmony_ci
955bf215546Sopenharmony_cistatic inline void r600_store_config_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
956bf215546Sopenharmony_ci{
957bf215546Sopenharmony_ci	r600_store_config_reg_seq(cb, reg, 1);
958bf215546Sopenharmony_ci	r600_store_value(cb, value);
959bf215546Sopenharmony_ci}
960bf215546Sopenharmony_ci
961bf215546Sopenharmony_cistatic inline void r600_store_context_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
962bf215546Sopenharmony_ci{
963bf215546Sopenharmony_ci	r600_store_context_reg_seq(cb, reg, 1);
964bf215546Sopenharmony_ci	r600_store_value(cb, value);
965bf215546Sopenharmony_ci}
966bf215546Sopenharmony_ci
967bf215546Sopenharmony_cistatic inline void r600_store_ctl_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
968bf215546Sopenharmony_ci{
969bf215546Sopenharmony_ci	r600_store_ctl_const_seq(cb, reg, 1);
970bf215546Sopenharmony_ci	r600_store_value(cb, value);
971bf215546Sopenharmony_ci}
972bf215546Sopenharmony_ci
973bf215546Sopenharmony_cistatic inline void r600_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
974bf215546Sopenharmony_ci{
975bf215546Sopenharmony_ci	r600_store_loop_const_seq(cb, reg, 1);
976bf215546Sopenharmony_ci	r600_store_value(cb, value);
977bf215546Sopenharmony_ci}
978bf215546Sopenharmony_ci
979bf215546Sopenharmony_cistatic inline void eg_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
980bf215546Sopenharmony_ci{
981bf215546Sopenharmony_ci	eg_store_loop_const_seq(cb, reg, 1);
982bf215546Sopenharmony_ci	r600_store_value(cb, value);
983bf215546Sopenharmony_ci}
984bf215546Sopenharmony_ci
985bf215546Sopenharmony_civoid r600_init_command_buffer(struct r600_command_buffer *cb, unsigned num_dw);
986bf215546Sopenharmony_civoid r600_release_command_buffer(struct r600_command_buffer *cb);
987bf215546Sopenharmony_ci
988bf215546Sopenharmony_cistatic inline void radeon_compute_set_context_reg_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num)
989bf215546Sopenharmony_ci{
990bf215546Sopenharmony_ci	radeon_set_context_reg_seq(cs, reg, num);
991bf215546Sopenharmony_ci	/* Set the compute bit on the packet header */
992bf215546Sopenharmony_ci	cs->current.buf[cs->current.cdw - 2] |= RADEON_CP_PACKET3_COMPUTE_MODE;
993bf215546Sopenharmony_ci}
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_cistatic inline void radeon_set_ctl_const_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num)
996bf215546Sopenharmony_ci{
997bf215546Sopenharmony_ci	assert(reg >= R600_CTL_CONST_OFFSET);
998bf215546Sopenharmony_ci	assert(cs->current.cdw + 2 + num <= cs->current.max_dw);
999bf215546Sopenharmony_ci	radeon_emit(cs, PKT3(PKT3_SET_CTL_CONST, num, 0));
1000bf215546Sopenharmony_ci	radeon_emit(cs, (reg - R600_CTL_CONST_OFFSET) >> 2);
1001bf215546Sopenharmony_ci}
1002bf215546Sopenharmony_ci
1003bf215546Sopenharmony_cistatic inline void radeon_compute_set_context_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value)
1004bf215546Sopenharmony_ci{
1005bf215546Sopenharmony_ci	radeon_compute_set_context_reg_seq(cs, reg, 1);
1006bf215546Sopenharmony_ci	radeon_emit(cs, value);
1007bf215546Sopenharmony_ci}
1008bf215546Sopenharmony_ci
1009bf215546Sopenharmony_cistatic inline void radeon_set_context_reg_flag(struct radeon_cmdbuf *cs, unsigned reg, unsigned value, unsigned flag)
1010bf215546Sopenharmony_ci{
1011bf215546Sopenharmony_ci	if (flag & RADEON_CP_PACKET3_COMPUTE_MODE) {
1012bf215546Sopenharmony_ci		radeon_compute_set_context_reg(cs, reg, value);
1013bf215546Sopenharmony_ci	} else {
1014bf215546Sopenharmony_ci		radeon_set_context_reg(cs, reg, value);
1015bf215546Sopenharmony_ci	}
1016bf215546Sopenharmony_ci}
1017bf215546Sopenharmony_ci
1018bf215546Sopenharmony_cistatic inline void radeon_set_ctl_const(struct radeon_cmdbuf *cs, unsigned reg, unsigned value)
1019bf215546Sopenharmony_ci{
1020bf215546Sopenharmony_ci	radeon_set_ctl_const_seq(cs, reg, 1);
1021bf215546Sopenharmony_ci	radeon_emit(cs, value);
1022bf215546Sopenharmony_ci}
1023bf215546Sopenharmony_ci
1024bf215546Sopenharmony_ci/*
1025bf215546Sopenharmony_ci * common helpers
1026bf215546Sopenharmony_ci */
1027bf215546Sopenharmony_ci
1028bf215546Sopenharmony_ci/* 12.4 fixed-point */
1029bf215546Sopenharmony_cistatic inline unsigned r600_pack_float_12p4(float x)
1030bf215546Sopenharmony_ci{
1031bf215546Sopenharmony_ci	return x <= 0    ? 0 :
1032bf215546Sopenharmony_ci	       x >= 4096 ? 0xffff : x * 16;
1033bf215546Sopenharmony_ci}
1034bf215546Sopenharmony_ci
1035bf215546Sopenharmony_cistatic inline unsigned r600_get_flush_flags(enum r600_coherency coher)
1036bf215546Sopenharmony_ci{
1037bf215546Sopenharmony_ci	switch (coher) {
1038bf215546Sopenharmony_ci	default:
1039bf215546Sopenharmony_ci	case R600_COHERENCY_NONE:
1040bf215546Sopenharmony_ci		return 0;
1041bf215546Sopenharmony_ci	case R600_COHERENCY_SHADER:
1042bf215546Sopenharmony_ci		return R600_CONTEXT_INV_CONST_CACHE |
1043bf215546Sopenharmony_ci		       R600_CONTEXT_INV_VERTEX_CACHE |
1044bf215546Sopenharmony_ci		       R600_CONTEXT_INV_TEX_CACHE |
1045bf215546Sopenharmony_ci		       R600_CONTEXT_STREAMOUT_FLUSH;
1046bf215546Sopenharmony_ci	case R600_COHERENCY_CB_META:
1047bf215546Sopenharmony_ci		return R600_CONTEXT_FLUSH_AND_INV_CB |
1048bf215546Sopenharmony_ci		       R600_CONTEXT_FLUSH_AND_INV_CB_META;
1049bf215546Sopenharmony_ci	}
1050bf215546Sopenharmony_ci}
1051bf215546Sopenharmony_ci
1052bf215546Sopenharmony_ci#define     V_028A6C_OUTPRIM_TYPE_POINTLIST            0
1053bf215546Sopenharmony_ci#define     V_028A6C_OUTPRIM_TYPE_LINESTRIP            1
1054bf215546Sopenharmony_ci#define     V_028A6C_OUTPRIM_TYPE_TRISTRIP             2
1055bf215546Sopenharmony_ci
1056bf215546Sopenharmony_ciunsigned r600_conv_prim_to_gs_out(unsigned mode);
1057bf215546Sopenharmony_ci
1058bf215546Sopenharmony_civoid eg_trace_emit(struct r600_context *rctx);
1059bf215546Sopenharmony_civoid eg_dump_debug_state(struct pipe_context *ctx, FILE *f,
1060bf215546Sopenharmony_ci			 unsigned flags);
1061bf215546Sopenharmony_ci
1062bf215546Sopenharmony_cistruct r600_pipe_shader_selector *r600_create_shader_state_tokens(struct pipe_context *ctx,
1063bf215546Sopenharmony_ci								  const void *tokens,
1064bf215546Sopenharmony_ci								  enum pipe_shader_ir,
1065bf215546Sopenharmony_ci								  unsigned pipe_shader_type);
1066bf215546Sopenharmony_ciint r600_shader_select(struct pipe_context *ctx,
1067bf215546Sopenharmony_ci		       struct r600_pipe_shader_selector* sel,
1068bf215546Sopenharmony_ci		       bool *dirty, bool precompile);
1069bf215546Sopenharmony_ci
1070bf215546Sopenharmony_civoid r600_delete_shader_selector(struct pipe_context *ctx,
1071bf215546Sopenharmony_ci				 struct r600_pipe_shader_selector *sel);
1072bf215546Sopenharmony_ci
1073bf215546Sopenharmony_cistruct r600_shader_atomic;
1074bf215546Sopenharmony_civoid evergreen_emit_atomic_buffer_setup_count(struct r600_context *rctx,
1075bf215546Sopenharmony_ci					      struct r600_pipe_shader *cs_shader,
1076bf215546Sopenharmony_ci					      struct r600_shader_atomic *combined_atomics,
1077bf215546Sopenharmony_ci					      uint8_t *atomic_used_mask_p);
1078bf215546Sopenharmony_civoid evergreen_emit_atomic_buffer_setup(struct r600_context *rctx,
1079bf215546Sopenharmony_ci					bool is_compute,
1080bf215546Sopenharmony_ci					struct r600_shader_atomic *combined_atomics,
1081bf215546Sopenharmony_ci					uint8_t atomic_used_mask);
1082bf215546Sopenharmony_civoid evergreen_emit_atomic_buffer_save(struct r600_context *rctx,
1083bf215546Sopenharmony_ci				       bool is_compute,
1084bf215546Sopenharmony_ci				       struct r600_shader_atomic *combined_atomics,
1085bf215546Sopenharmony_ci				       uint8_t *atomic_used_mask_p);
1086bf215546Sopenharmony_civoid r600_update_compressed_resource_state(struct r600_context *rctx, bool compute_only);
1087bf215546Sopenharmony_ci
1088bf215546Sopenharmony_civoid eg_setup_buffer_constants(struct r600_context *rctx, int shader_type);
1089bf215546Sopenharmony_civoid r600_update_driver_const_buffers(struct r600_context *rctx, bool compute_only);
1090bf215546Sopenharmony_ci#endif
1091