13464ebd5Sriastradh/*
23464ebd5Sriastradh * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
33464ebd5Sriastradh *
43464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
53464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
63464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
73464ebd5Sriastradh * on the rights to use, copy, modify, merge, publish, distribute, sub
83464ebd5Sriastradh * license, and/or sell copies of the Software, and to permit persons to whom
93464ebd5Sriastradh * the Software is furnished to do so, subject to the following conditions:
103464ebd5Sriastradh *
113464ebd5Sriastradh * The above copyright notice and this permission notice (including the next
123464ebd5Sriastradh * paragraph) shall be included in all copies or substantial portions of the
133464ebd5Sriastradh * Software.
143464ebd5Sriastradh *
153464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
173464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
183464ebd5Sriastradh * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
193464ebd5Sriastradh * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
203464ebd5Sriastradh * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
213464ebd5Sriastradh * USE OR OTHER DEALINGS IN THE SOFTWARE.
223464ebd5Sriastradh *
233464ebd5Sriastradh * Authors:
243464ebd5Sriastradh *      Jerome Glisse
253464ebd5Sriastradh */
263464ebd5Sriastradh#ifndef R600_PIPE_H
273464ebd5Sriastradh#define R600_PIPE_H
283464ebd5Sriastradh
2901e04c3fSmrg#include "r600_pipe_common.h"
3001e04c3fSmrg#include "r600_cs.h"
313464ebd5Sriastradh#include "r600_public.h"
3201e04c3fSmrg#include "pipe/p_defines.h"
333464ebd5Sriastradh
34af69d88dSmrg#include "util/u_suballoc.h"
3501e04c3fSmrg#include "util/list.h"
36af69d88dSmrg#include "util/u_transfer.h"
3701e04c3fSmrg#include "util/u_memory.h"
3801e04c3fSmrg
3901e04c3fSmrg#include "tgsi/tgsi_scan.h"
40af69d88dSmrg
4101e04c3fSmrg#define R600_NUM_ATOMS 56
4201e04c3fSmrg
4301e04c3fSmrg#define R600_MAX_IMAGES 8
4401e04c3fSmrg/*
4501e04c3fSmrg * ranges reserved for images on evergreen
4601e04c3fSmrg * first set for the immediate buffers,
4701e04c3fSmrg * second for the actual resources for RESQ.
4801e04c3fSmrg */
4901e04c3fSmrg#define R600_IMAGE_IMMED_RESOURCE_OFFSET 160
5001e04c3fSmrg#define R600_IMAGE_REAL_RESOURCE_OFFSET 168
5101e04c3fSmrg
5201e04c3fSmrg/* read caches */
5301e04c3fSmrg#define R600_CONTEXT_INV_VERTEX_CACHE		(R600_CONTEXT_PRIVATE_FLAG << 0)
5401e04c3fSmrg#define R600_CONTEXT_INV_TEX_CACHE		(R600_CONTEXT_PRIVATE_FLAG << 1)
5501e04c3fSmrg#define R600_CONTEXT_INV_CONST_CACHE		(R600_CONTEXT_PRIVATE_FLAG << 2)
5601e04c3fSmrg/* read-write caches */
5701e04c3fSmrg#define R600_CONTEXT_FLUSH_AND_INV		(R600_CONTEXT_PRIVATE_FLAG << 3)
5801e04c3fSmrg#define R600_CONTEXT_FLUSH_AND_INV_CB_META	(R600_CONTEXT_PRIVATE_FLAG << 4)
5901e04c3fSmrg#define R600_CONTEXT_FLUSH_AND_INV_DB_META	(R600_CONTEXT_PRIVATE_FLAG << 5)
6001e04c3fSmrg#define R600_CONTEXT_FLUSH_AND_INV_DB		(R600_CONTEXT_PRIVATE_FLAG << 6)
6101e04c3fSmrg#define R600_CONTEXT_FLUSH_AND_INV_CB		(R600_CONTEXT_PRIVATE_FLAG << 7)
6201e04c3fSmrg/* engine synchronization */
6301e04c3fSmrg#define R600_CONTEXT_PS_PARTIAL_FLUSH		(R600_CONTEXT_PRIVATE_FLAG << 8)
6401e04c3fSmrg#define R600_CONTEXT_WAIT_3D_IDLE		(R600_CONTEXT_PRIVATE_FLAG << 9)
6501e04c3fSmrg#define R600_CONTEXT_WAIT_CP_DMA_IDLE		(R600_CONTEXT_PRIVATE_FLAG << 10)
6601e04c3fSmrg#define R600_CONTEXT_CS_PARTIAL_FLUSH           (R600_CONTEXT_PRIVATE_FLAG << 11)
67af69d88dSmrg
68af69d88dSmrg/* the number of CS dwords for flushing and drawing */
6901e04c3fSmrg#define R600_MAX_FLUSH_CS_DWORDS	18
7001e04c3fSmrg#define R600_MAX_DRAW_CS_DWORDS		58
7101e04c3fSmrg#define R600_MAX_PFP_SYNC_ME_DWORDS	16
7201e04c3fSmrg
7301e04c3fSmrg#define EG_MAX_ATOMIC_BUFFERS 8
74af69d88dSmrg
7501e04c3fSmrg#define R600_MAX_USER_CONST_BUFFERS 15
7601e04c3fSmrg#define R600_MAX_DRIVER_CONST_BUFFERS 3
77af69d88dSmrg#define R600_MAX_CONST_BUFFERS (R600_MAX_USER_CONST_BUFFERS + R600_MAX_DRIVER_CONST_BUFFERS)
7801e04c3fSmrg#define R600_MAX_HW_CONST_BUFFERS 16
79af69d88dSmrg
80af69d88dSmrg/* start driver buffers after user buffers */
8101e04c3fSmrg#define R600_BUFFER_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS)
8201e04c3fSmrg#define R600_UCP_SIZE (4*4*8)
8301e04c3fSmrg#define R600_CS_BLOCK_GRID_SIZE (8 * 4)
8401e04c3fSmrg#define R600_TCS_DEFAULT_LEVELS_SIZE (6 * 4)
8501e04c3fSmrg#define R600_BUFFER_INFO_OFFSET (R600_UCP_SIZE)
86af69d88dSmrg
8701e04c3fSmrg/*
8801e04c3fSmrg * We only access this buffer through vtx clauses hence it's fine to exist
8901e04c3fSmrg * at index beyond 15.
9001e04c3fSmrg */
9101e04c3fSmrg#define R600_LDS_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 1)
9201e04c3fSmrg/*
9301e04c3fSmrg * Note GS doesn't use a constant buffer binding, just a resource index,
9401e04c3fSmrg * so it's fine to have it exist at index beyond 15. I.e. it's not actually
9501e04c3fSmrg * a const buffer, just a buffer resource.
9601e04c3fSmrg */
9701e04c3fSmrg#define R600_GS_RING_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 2)
9801e04c3fSmrg/* Currently R600_MAX_CONST_BUFFERS just fits on the hw, which has a limit
9901e04c3fSmrg * of 16 const buffers.
10001e04c3fSmrg * UCP/SAMPLE_POSITIONS are never accessed by same shader stage so they can use the same id.
10101e04c3fSmrg *
10201e04c3fSmrg * In order to support d3d 11 mandated minimum of 15 user const buffers
10301e04c3fSmrg * we'd have to squash all use cases into one driver buffer.
10401e04c3fSmrg */
105af69d88dSmrg#define R600_MAX_CONST_BUFFER_SIZE (4096 * sizeof(float[4]))
1063464ebd5Sriastradh
10701e04c3fSmrg/* HW stages */
10801e04c3fSmrg#define R600_HW_STAGE_PS 0
10901e04c3fSmrg#define R600_HW_STAGE_VS 1
11001e04c3fSmrg#define R600_HW_STAGE_GS 2
11101e04c3fSmrg#define R600_HW_STAGE_ES 3
11201e04c3fSmrg#define EG_HW_STAGE_LS 4
11301e04c3fSmrg#define EG_HW_STAGE_HS 5
11401e04c3fSmrg
11501e04c3fSmrg#define R600_NUM_HW_STAGES 4
11601e04c3fSmrg#define EG_NUM_HW_STAGES 6
1173464ebd5Sriastradh
118af69d88dSmrgstruct r600_context;
119af69d88dSmrgstruct r600_bytecode;
12001e04c3fSmrgunion  r600_shader_key;
121af69d88dSmrg
122af69d88dSmrg/* This is an atom containing GPU commands that never change.
123af69d88dSmrg * This is supposed to be copied directly into the CS. */
124af69d88dSmrgstruct r600_command_buffer {
125af69d88dSmrg	uint32_t *buf;
126af69d88dSmrg	unsigned num_dw;
127af69d88dSmrg	unsigned max_num_dw;
128af69d88dSmrg	unsigned pkt_flags;
1293464ebd5Sriastradh};
1303464ebd5Sriastradh
131af69d88dSmrgstruct r600_db_state {
132af69d88dSmrg	struct r600_atom		atom;
133af69d88dSmrg	struct r600_surface		*rsurf;
134af69d88dSmrg};
135af69d88dSmrg
136af69d88dSmrgstruct r600_db_misc_state {
137af69d88dSmrg	struct r600_atom		atom;
13801e04c3fSmrg	bool				occlusion_queries_disabled;
139af69d88dSmrg	bool				flush_depthstencil_through_cb;
14001e04c3fSmrg	bool				flush_depth_inplace;
14101e04c3fSmrg	bool				flush_stencil_inplace;
142af69d88dSmrg	bool				copy_depth, copy_stencil;
143af69d88dSmrg	unsigned			copy_sample;
144af69d88dSmrg	unsigned			log_samples;
145af69d88dSmrg	unsigned			db_shader_control;
146af69d88dSmrg	bool				htile_clear;
14701e04c3fSmrg	uint8_t				ps_conservative_z;
148af69d88dSmrg};
149af69d88dSmrg
150af69d88dSmrgstruct r600_cb_misc_state {
151af69d88dSmrg	struct r600_atom atom;
152af69d88dSmrg	unsigned cb_color_control; /* this comes from blend state */
153af69d88dSmrg	unsigned blend_colormask; /* 8*4 bits for 8 RGBA colorbuffers */
154af69d88dSmrg	unsigned nr_cbufs;
15501e04c3fSmrg	unsigned bound_cbufs_target_mask;
156af69d88dSmrg	unsigned nr_ps_color_outputs;
15701e04c3fSmrg	unsigned ps_color_export_mask;
15801e04c3fSmrg	unsigned image_rat_enabled_mask;
15901e04c3fSmrg	unsigned buffer_rat_enabled_mask;
160af69d88dSmrg	bool multiwrite;
161af69d88dSmrg	bool dual_src_blend;
162af69d88dSmrg};
163af69d88dSmrg
164af69d88dSmrgstruct r600_clip_misc_state {
165af69d88dSmrg	struct r600_atom atom;
166af69d88dSmrg	unsigned pa_cl_clip_cntl;   /* from rasterizer    */
167af69d88dSmrg	unsigned pa_cl_vs_out_cntl; /* from vertex shader */
168af69d88dSmrg	unsigned clip_plane_enable; /* from rasterizer    */
16901e04c3fSmrg	unsigned cc_dist_mask;      /* from vertex shader */
170af69d88dSmrg	unsigned clip_dist_write;   /* from vertex shader */
17101e04c3fSmrg	unsigned cull_dist_write;   /* from vertex shader */
172af69d88dSmrg	boolean clip_disable;       /* from vertex shader */
17301e04c3fSmrg	boolean vs_out_viewport;    /* from vertex shader */
174af69d88dSmrg};
175af69d88dSmrg
176af69d88dSmrgstruct r600_alphatest_state {
177af69d88dSmrg	struct r600_atom atom;
178af69d88dSmrg	unsigned sx_alpha_test_control; /* this comes from dsa state */
179af69d88dSmrg	unsigned sx_alpha_ref; /* this comes from dsa state */
180af69d88dSmrg	bool bypass;
181af69d88dSmrg	bool cb0_export_16bpc; /* from set_framebuffer_state */
182af69d88dSmrg};
183af69d88dSmrg
184af69d88dSmrgstruct r600_vgt_state {
185af69d88dSmrg	struct r600_atom atom;
186af69d88dSmrg	uint32_t vgt_multi_prim_ib_reset_en;
187af69d88dSmrg	uint32_t vgt_multi_prim_ib_reset_indx;
188af69d88dSmrg	uint32_t vgt_indx_offset;
18901e04c3fSmrg	bool last_draw_was_indirect;
190af69d88dSmrg};
191af69d88dSmrg
192af69d88dSmrgstruct r600_blend_color {
193af69d88dSmrg	struct r600_atom atom;
194af69d88dSmrg	struct pipe_blend_color state;
195af69d88dSmrg};
196af69d88dSmrg
197af69d88dSmrgstruct r600_clip_state {
198af69d88dSmrg	struct r600_atom atom;
199af69d88dSmrg	struct pipe_clip_state state;
200af69d88dSmrg};
2013464ebd5Sriastradh
202af69d88dSmrgstruct r600_cs_shader_state {
203af69d88dSmrg	struct r600_atom atom;
204af69d88dSmrg	unsigned kernel_index;
20501e04c3fSmrg	unsigned pc;
206af69d88dSmrg	struct r600_pipe_compute *shader;
207af69d88dSmrg};
208af69d88dSmrg
209af69d88dSmrgstruct r600_framebuffer {
210af69d88dSmrg	struct r600_atom atom;
211af69d88dSmrg	struct pipe_framebuffer_state state;
212af69d88dSmrg	unsigned compressed_cb_mask;
213af69d88dSmrg	unsigned nr_samples;
214af69d88dSmrg	bool export_16bpc;
215af69d88dSmrg	bool cb0_is_integer;
216af69d88dSmrg	bool is_msaa_resolve;
21701e04c3fSmrg	bool dual_src_blend;
21801e04c3fSmrg	bool do_update_surf_dirtiness;
219af69d88dSmrg};
220af69d88dSmrg
221af69d88dSmrgstruct r600_sample_mask {
222af69d88dSmrg	struct r600_atom atom;
223af69d88dSmrg	uint16_t sample_mask; /* there are only 8 bits on EG, 16 bits on Cayman */
224af69d88dSmrg};
225af69d88dSmrg
226af69d88dSmrgstruct r600_config_state {
227af69d88dSmrg	struct r600_atom atom;
228af69d88dSmrg	unsigned sq_gpr_resource_mgmt_1;
229af69d88dSmrg	unsigned sq_gpr_resource_mgmt_2;
23001e04c3fSmrg	unsigned sq_gpr_resource_mgmt_3;
23101e04c3fSmrg	bool dyn_gpr_enabled;
232af69d88dSmrg};
233af69d88dSmrg
234af69d88dSmrgstruct r600_stencil_ref
235af69d88dSmrg{
236af69d88dSmrg	ubyte ref_value[2];
237af69d88dSmrg	ubyte valuemask[2];
238af69d88dSmrg	ubyte writemask[2];
239af69d88dSmrg};
240af69d88dSmrg
241af69d88dSmrgstruct r600_stencil_ref_state {
242af69d88dSmrg	struct r600_atom atom;
243af69d88dSmrg	struct r600_stencil_ref state;
244af69d88dSmrg	struct pipe_stencil_ref pipe_state;
245af69d88dSmrg};
246af69d88dSmrg
247af69d88dSmrgstruct r600_shader_stages_state {
248af69d88dSmrg	struct r600_atom atom;
249af69d88dSmrg	unsigned geom_enable;
250af69d88dSmrg};
251af69d88dSmrg
252af69d88dSmrgstruct r600_gs_rings_state {
253af69d88dSmrg	struct r600_atom atom;
254af69d88dSmrg	unsigned enable;
255af69d88dSmrg	struct pipe_constant_buffer esgs_ring;
256af69d88dSmrg	struct pipe_constant_buffer gsvs_ring;
257af69d88dSmrg};
258af69d88dSmrg
259af69d88dSmrg/* This must start from 16. */
260af69d88dSmrg/* features */
26101e04c3fSmrg#define DBG_NO_CP_DMA		(1 << 30)
262af69d88dSmrg/* shader backend */
263af69d88dSmrg#define DBG_NO_SB		(1 << 21)
264af69d88dSmrg#define DBG_SB_CS		(1 << 22)
265af69d88dSmrg#define DBG_SB_DRY_RUN	(1 << 23)
266af69d88dSmrg#define DBG_SB_STAT		(1 << 24)
267af69d88dSmrg#define DBG_SB_DUMP		(1 << 25)
268af69d88dSmrg#define DBG_SB_NO_FALLBACK	(1 << 26)
269af69d88dSmrg#define DBG_SB_DISASM	(1 << 27)
270af69d88dSmrg#define DBG_SB_SAFEMATH	(1 << 28)
2717ec681f3Smrg#define DBG_NIR_SB	(1 << 28)
2727ec681f3Smrg
2737ec681f3Smrg#define DBG_NIR_PREFERRED (DBG_NIR_SB | DBG_NIR)
274af69d88dSmrg
275af69d88dSmrgstruct r600_screen {
276af69d88dSmrg	struct r600_common_screen	b;
277af69d88dSmrg	bool				has_msaa;
278af69d88dSmrg	bool				has_compressed_msaa_texturing;
27901e04c3fSmrg	bool				has_atomics;
280af69d88dSmrg
281af69d88dSmrg	/*for compute global memory binding, we allocate stuff here, instead of
282af69d88dSmrg	 * buffers.
283af69d88dSmrg	 * XXX: Not sure if this is the best place for global_pool.  Also,
284af69d88dSmrg	 * it's not thread safe, so it won't work with multiple contexts. */
285af69d88dSmrg	struct compute_memory_pool *global_pool;
2863464ebd5Sriastradh};
2873464ebd5Sriastradh
2883464ebd5Sriastradhstruct r600_pipe_sampler_view {
2893464ebd5Sriastradh	struct pipe_sampler_view	base;
290af69d88dSmrg	struct list_head		list;
291af69d88dSmrg	struct r600_resource		*tex_resource;
292af69d88dSmrg	uint32_t			tex_resource_words[8];
293af69d88dSmrg	bool				skip_mip_address_reloc;
29401e04c3fSmrg	bool				is_stencil_sampler;
2953464ebd5Sriastradh};
2963464ebd5Sriastradh
297af69d88dSmrgstruct r600_rasterizer_state {
298af69d88dSmrg	struct r600_command_buffer	buffer;
2993464ebd5Sriastradh	boolean				flatshade;
300af69d88dSmrg	boolean				two_side;
3013464ebd5Sriastradh	unsigned			sprite_coord_enable;
302af69d88dSmrg	unsigned                        clip_plane_enable;
303af69d88dSmrg	unsigned			pa_sc_line_stipple;
304af69d88dSmrg	unsigned			pa_cl_clip_cntl;
305af69d88dSmrg	unsigned			pa_su_sc_mode_cntl;
3063464ebd5Sriastradh	float				offset_units;
3073464ebd5Sriastradh	float				offset_scale;
308af69d88dSmrg	bool				offset_enable;
30901e04c3fSmrg	bool				offset_units_unscaled;
310af69d88dSmrg	bool				scissor_enable;
311af69d88dSmrg	bool				multisample_enable;
31201e04c3fSmrg	bool				clip_halfz;
31301e04c3fSmrg	bool				rasterizer_discard;
3143464ebd5Sriastradh};
3153464ebd5Sriastradh
316af69d88dSmrgstruct r600_poly_offset_state {
317af69d88dSmrg	struct r600_atom		atom;
318af69d88dSmrg	enum pipe_format		zs_format;
319af69d88dSmrg	float				offset_units;
320af69d88dSmrg	float				offset_scale;
32101e04c3fSmrg	bool				offset_units_unscaled;
322af69d88dSmrg};
323af69d88dSmrg
324af69d88dSmrgstruct r600_blend_state {
325af69d88dSmrg	struct r600_command_buffer	buffer;
326af69d88dSmrg	struct r600_command_buffer	buffer_no_blend;
3273464ebd5Sriastradh	unsigned			cb_target_mask;
328af69d88dSmrg	unsigned			cb_color_control;
329af69d88dSmrg	unsigned			cb_color_control_no_blend;
330af69d88dSmrg	bool				dual_src_blend;
331af69d88dSmrg	bool				alpha_to_one;
3323464ebd5Sriastradh};
3333464ebd5Sriastradh
334af69d88dSmrgstruct r600_dsa_state {
335af69d88dSmrg	struct r600_command_buffer	buffer;
3363464ebd5Sriastradh	unsigned			alpha_ref;
337af69d88dSmrg	ubyte				valuemask[2];
338af69d88dSmrg	ubyte				writemask[2];
339af69d88dSmrg	unsigned			zwritemask;
340af69d88dSmrg	unsigned			sx_alpha_test_control;
3413464ebd5Sriastradh};
3423464ebd5Sriastradh
343af69d88dSmrgstruct r600_pipe_shader;
344af69d88dSmrg
345af69d88dSmrgstruct r600_pipe_shader_selector {
346af69d88dSmrg	struct r600_pipe_shader *current;
347af69d88dSmrg
348af69d88dSmrg	struct tgsi_token       *tokens;
3497ec681f3Smrg        struct nir_shader       *nir;
350af69d88dSmrg	struct pipe_stream_output_info  so;
35101e04c3fSmrg	struct tgsi_shader_info		info;
352af69d88dSmrg
353af69d88dSmrg	unsigned	num_shaders;
354af69d88dSmrg
35501e04c3fSmrg	enum pipe_shader_type	type;
3567ec681f3Smrg        enum pipe_shader_ir ir_type;
35701e04c3fSmrg
35801e04c3fSmrg	/* geometry shader properties */
35901e04c3fSmrg	enum pipe_prim_type	gs_output_prim;
36001e04c3fSmrg	unsigned		gs_max_out_vertices;
36101e04c3fSmrg	unsigned		gs_num_invocations;
362af69d88dSmrg
36301e04c3fSmrg	/* TCS/VS */
36401e04c3fSmrg	uint64_t        lds_patch_outputs_written_mask;
36501e04c3fSmrg	uint64_t        lds_outputs_written_mask;
366af69d88dSmrg	unsigned	nr_ps_max_color_exports;
3673464ebd5Sriastradh};
3683464ebd5Sriastradh
3693464ebd5Sriastradhstruct r600_pipe_sampler_state {
370af69d88dSmrg	uint32_t			tex_sampler_words[3];
371af69d88dSmrg	union pipe_color_union		border_color;
372af69d88dSmrg	bool				border_color_use;
373af69d88dSmrg	bool				seamless_cube_map;
3743464ebd5Sriastradh};
3753464ebd5Sriastradh
3763464ebd5Sriastradh/* needed for blitter save */
3773464ebd5Sriastradh#define NUM_TEX_UNITS 16
3783464ebd5Sriastradh
379af69d88dSmrgstruct r600_seamless_cube_map {
380af69d88dSmrg	struct r600_atom		atom;
381af69d88dSmrg	bool				enabled;
382af69d88dSmrg};
383af69d88dSmrg
384af69d88dSmrgstruct r600_samplerview_state {
385af69d88dSmrg	struct r600_atom		atom;
3863464ebd5Sriastradh	struct r600_pipe_sampler_view	*views[NUM_TEX_UNITS];
387af69d88dSmrg	uint32_t			enabled_mask;
388af69d88dSmrg	uint32_t			dirty_mask;
389af69d88dSmrg	uint32_t			compressed_depthtex_mask; /* which textures are depth */
390af69d88dSmrg	uint32_t			compressed_colortex_mask;
391af69d88dSmrg	boolean				dirty_buffer_constants;
392af69d88dSmrg};
393af69d88dSmrg
394af69d88dSmrgstruct r600_sampler_states {
395af69d88dSmrg	struct r600_atom		atom;
396af69d88dSmrg	struct r600_pipe_sampler_state	*states[NUM_TEX_UNITS];
397af69d88dSmrg	uint32_t			enabled_mask;
398af69d88dSmrg	uint32_t			dirty_mask;
399af69d88dSmrg	uint32_t			has_bordercolor_mask; /* which states contain the border color */
400af69d88dSmrg};
401af69d88dSmrg
402af69d88dSmrgstruct r600_textures_info {
403af69d88dSmrg	struct r600_samplerview_state	views;
404af69d88dSmrg	struct r600_sampler_states	states;
405af69d88dSmrg	bool				is_array_sampler[NUM_TEX_UNITS];
40601e04c3fSmrg};
407af69d88dSmrg
40801e04c3fSmrgstruct r600_shader_driver_constants_info {
40901e04c3fSmrg	/* currently 128 bytes for UCP/samplepos + sampler buffer constants */
41001e04c3fSmrg	uint32_t			*constants;
41101e04c3fSmrg	uint32_t			alloc_size;
41201e04c3fSmrg	bool				texture_const_dirty;
41301e04c3fSmrg	bool				vs_ucp_dirty;
41401e04c3fSmrg	bool				ps_sample_pos_dirty;
41501e04c3fSmrg	bool                            cs_block_grid_size_dirty;
41601e04c3fSmrg	bool				tcs_default_levels_dirty;
417af69d88dSmrg};
418af69d88dSmrg
419af69d88dSmrgstruct r600_constbuf_state
420af69d88dSmrg{
421af69d88dSmrg	struct r600_atom		atom;
422af69d88dSmrg	struct pipe_constant_buffer	cb[PIPE_MAX_CONSTANT_BUFFERS];
423af69d88dSmrg	uint32_t			enabled_mask;
424af69d88dSmrg	uint32_t			dirty_mask;
4253464ebd5Sriastradh};
4263464ebd5Sriastradh
427af69d88dSmrgstruct r600_vertexbuf_state
428af69d88dSmrg{
429af69d88dSmrg	struct r600_atom		atom;
430af69d88dSmrg	struct pipe_vertex_buffer	vb[PIPE_MAX_ATTRIBS];
431af69d88dSmrg	uint32_t			enabled_mask; /* non-NULL buffers */
432af69d88dSmrg	uint32_t			dirty_mask;
4333464ebd5Sriastradh};
4343464ebd5Sriastradh
435af69d88dSmrg/* CSO (constant state object, in other words, immutable state). */
436af69d88dSmrgstruct r600_cso_state
437af69d88dSmrg{
438af69d88dSmrg	struct r600_atom atom;
439af69d88dSmrg	void *cso; /* e.g. r600_blend_state */
440af69d88dSmrg	struct r600_command_buffer *cb;
441af69d88dSmrg};
4423464ebd5Sriastradh
443af69d88dSmrgstruct r600_fetch_shader {
444af69d88dSmrg	struct r600_resource		*buffer;
445af69d88dSmrg	unsigned			offset;
4463464ebd5Sriastradh};
4473464ebd5Sriastradh
448af69d88dSmrgstruct r600_shader_state {
449af69d88dSmrg	struct r600_atom		atom;
450af69d88dSmrg	struct r600_pipe_shader *shader;
451af69d88dSmrg};
4523464ebd5Sriastradh
45301e04c3fSmrgstruct r600_atomic_buffer_state {
45401e04c3fSmrg	struct pipe_shader_buffer buffer[EG_MAX_ATOMIC_BUFFERS];
45501e04c3fSmrg};
45601e04c3fSmrg
45701e04c3fSmrgstruct r600_image_view {
45801e04c3fSmrg	struct pipe_image_view base;
45901e04c3fSmrg	uint32_t cb_color_base;
46001e04c3fSmrg	uint32_t cb_color_pitch;
46101e04c3fSmrg	uint32_t cb_color_slice;
46201e04c3fSmrg	uint32_t cb_color_view;
46301e04c3fSmrg	uint32_t cb_color_info;
46401e04c3fSmrg	uint32_t cb_color_attrib;
46501e04c3fSmrg	uint32_t cb_color_dim;
46601e04c3fSmrg	uint32_t cb_color_fmask;
46701e04c3fSmrg	uint32_t cb_color_fmask_slice;
46801e04c3fSmrg	uint32_t immed_resource_words[8];
46901e04c3fSmrg	uint32_t resource_words[8];
47001e04c3fSmrg	bool skip_mip_address_reloc;
47101e04c3fSmrg	uint32_t buf_size;
47201e04c3fSmrg};
47301e04c3fSmrg
47401e04c3fSmrgstruct r600_image_state {
47501e04c3fSmrg	struct r600_atom atom;
47601e04c3fSmrg	uint32_t                        enabled_mask;
47701e04c3fSmrg	uint32_t                        dirty_mask;
47801e04c3fSmrg	uint32_t			compressed_depthtex_mask;
47901e04c3fSmrg	uint32_t			compressed_colortex_mask;
48001e04c3fSmrg	boolean				dirty_buffer_constants;
48101e04c3fSmrg	struct r600_image_view views[R600_MAX_IMAGES];
48201e04c3fSmrg};
48301e04c3fSmrg
48401e04c3fSmrg/* Used to spill shader temps */
48501e04c3fSmrgstruct r600_scratch_buffer {
48601e04c3fSmrg	struct r600_resource		*buffer;
48701e04c3fSmrg	boolean					dirty;
48801e04c3fSmrg	unsigned				size;
48901e04c3fSmrg	unsigned				item_size;
49001e04c3fSmrg};
49101e04c3fSmrg
492af69d88dSmrgstruct r600_context {
493af69d88dSmrg	struct r600_common_context	b;
494af69d88dSmrg	struct r600_screen		*screen;
4953464ebd5Sriastradh	struct blitter_context		*blitter;
4967ec681f3Smrg	struct u_suballocator		allocator_fetch_shader;
497af69d88dSmrg
498af69d88dSmrg	/* Hardware info. */
499af69d88dSmrg	boolean				has_vertex_cache;
50001e04c3fSmrg	unsigned			default_gprs[EG_NUM_HW_STAGES];
50101e04c3fSmrg	unsigned                        current_gprs[EG_NUM_HW_STAGES];
502af69d88dSmrg	unsigned			r6xx_num_clause_temp_gprs;
503af69d88dSmrg
504af69d88dSmrg	/* Miscellaneous state objects. */
5053464ebd5Sriastradh	void				*custom_dsa_flush;
506af69d88dSmrg	void				*custom_blend_resolve;
507af69d88dSmrg	void				*custom_blend_decompress;
508af69d88dSmrg	void                            *custom_blend_fastclear;
509af69d88dSmrg	/* With rasterizer discard, there doesn't have to be a pixel shader.
510af69d88dSmrg	 * In that case, we bind this one: */
511af69d88dSmrg	void				*dummy_pixel_shader;
512af69d88dSmrg	/* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
513af69d88dSmrg	 * bug where valid CMASK and FMASK are required to be present to avoid
514af69d88dSmrg	 * a hardlock in certain operations but aren't actually used
515af69d88dSmrg	 * for anything useful. */
516af69d88dSmrg	struct r600_resource		*dummy_fmask;
517af69d88dSmrg	struct r600_resource		*dummy_cmask;
518af69d88dSmrg
519af69d88dSmrg	/* State binding slots are here. */
520af69d88dSmrg	struct r600_atom		*atoms[R600_NUM_ATOMS];
52101e04c3fSmrg	/* Dirty atom bitmask for fast tests */
52201e04c3fSmrg	uint64_t			dirty_atoms;
523af69d88dSmrg	/* States for CS initialization. */
524af69d88dSmrg	struct r600_command_buffer	start_cs_cmd; /* invariant state mostly */
525af69d88dSmrg	/** Compute specific registers initializations.  The start_cs_cmd atom
526af69d88dSmrg	 *  must be emitted before start_compute_cs_cmd. */
527af69d88dSmrg	struct r600_command_buffer      start_compute_cs_cmd;
528af69d88dSmrg	/* Register states. */
529af69d88dSmrg	struct r600_alphatest_state	alphatest_state;
530af69d88dSmrg	struct r600_cso_state		blend_state;
531af69d88dSmrg	struct r600_blend_color		blend_color;
532af69d88dSmrg	struct r600_cb_misc_state	cb_misc_state;
533af69d88dSmrg	struct r600_clip_misc_state	clip_misc_state;
534af69d88dSmrg	struct r600_clip_state		clip_state;
535af69d88dSmrg	struct r600_db_misc_state	db_misc_state;
536af69d88dSmrg	struct r600_db_state		db_state;
537af69d88dSmrg	struct r600_cso_state		dsa_state;
538af69d88dSmrg	struct r600_framebuffer		framebuffer;
539af69d88dSmrg	struct r600_poly_offset_state	poly_offset_state;
540af69d88dSmrg	struct r600_cso_state		rasterizer_state;
541af69d88dSmrg	struct r600_sample_mask		sample_mask;
542af69d88dSmrg	struct r600_seamless_cube_map	seamless_cube_map;
543af69d88dSmrg	struct r600_config_state	config_state;
544af69d88dSmrg	struct r600_stencil_ref_state	stencil_ref;
545af69d88dSmrg	struct r600_vgt_state		vgt_state;
54601e04c3fSmrg	struct r600_atomic_buffer_state atomic_buffer_state;
54701e04c3fSmrg	/* only have images on fragment shader */
54801e04c3fSmrg	struct r600_image_state         fragment_images;
54901e04c3fSmrg	struct r600_image_state         compute_images;
55001e04c3fSmrg	struct r600_image_state         fragment_buffers;
55101e04c3fSmrg	struct r600_image_state         compute_buffers;
552af69d88dSmrg	/* Shaders and shader resources. */
553af69d88dSmrg	struct r600_cso_state		vertex_fetch_shader;
55401e04c3fSmrg	struct r600_shader_state        hw_shader_stages[EG_NUM_HW_STAGES];
555af69d88dSmrg	struct r600_cs_shader_state	cs_shader_state;
556af69d88dSmrg	struct r600_shader_stages_state shader_stages;
557af69d88dSmrg	struct r600_gs_rings_state	gs_rings;
558af69d88dSmrg	struct r600_constbuf_state	constbuf_state[PIPE_SHADER_TYPES];
559af69d88dSmrg	struct r600_textures_info	samplers[PIPE_SHADER_TYPES];
56001e04c3fSmrg
56101e04c3fSmrg	struct r600_shader_driver_constants_info driver_consts[PIPE_SHADER_TYPES];
56201e04c3fSmrg
563af69d88dSmrg	/** Vertex buffers for fetch shaders */
564af69d88dSmrg	struct r600_vertexbuf_state	vertex_buffer_state;
565af69d88dSmrg	/** Vertex buffers for compute shaders */
566af69d88dSmrg	struct r600_vertexbuf_state	cs_vertex_buffer_state;
567af69d88dSmrg
568af69d88dSmrg	/* Additional context states. */
569af69d88dSmrg	unsigned			compute_cb_target_mask;
570af69d88dSmrg	struct r600_pipe_shader_selector *ps_shader;
571af69d88dSmrg	struct r600_pipe_shader_selector *vs_shader;
572af69d88dSmrg	struct r600_pipe_shader_selector *gs_shader;
57301e04c3fSmrg
57401e04c3fSmrg	struct r600_pipe_shader_selector *tcs_shader;
57501e04c3fSmrg	struct r600_pipe_shader_selector *tes_shader;
57601e04c3fSmrg
57701e04c3fSmrg	struct r600_pipe_shader_selector *fixed_func_tcs_shader;
57801e04c3fSmrg
579af69d88dSmrg	struct r600_rasterizer_state	*rasterizer;
580af69d88dSmrg	bool				alpha_to_one;
581af69d88dSmrg	bool				force_blend_disable;
58201e04c3fSmrg	bool                            gs_tri_strip_adj_fix;
583af69d88dSmrg	boolean				dual_src_blend;
584af69d88dSmrg	unsigned			zwritemask;
58501e04c3fSmrg	unsigned			ps_iter_samples;
586af69d88dSmrg
58701e04c3fSmrg	/* The list of all texture buffer objects in this context.
58801e04c3fSmrg	 * This list is walked when a buffer is invalidated/reallocated and
58901e04c3fSmrg	 * the GPU addresses are updated. */
59001e04c3fSmrg	struct list_head		texture_buffers;
5913464ebd5Sriastradh
592af69d88dSmrg	/* Last draw state (-1 = unset). */
59301e04c3fSmrg	enum pipe_prim_type		last_primitive_type; /* Last primitive type used in draw_vbo. */
59401e04c3fSmrg	enum pipe_prim_type		current_rast_prim; /* primitive type after TES, GS */
59501e04c3fSmrg	enum pipe_prim_type		last_rast_prim;
59601e04c3fSmrg	unsigned			last_start_instance;
5973464ebd5Sriastradh
598af69d88dSmrg	void				*sb_context;
599af69d88dSmrg	struct r600_isa		*isa;
60001e04c3fSmrg	float sample_positions[4 * 16];
60101e04c3fSmrg	float tess_state[8];
60201e04c3fSmrg	uint32_t cs_block_grid_sizes[8]; /* 3 for grid + 1 pad, 3 for block  + 1 pad*/
60301e04c3fSmrg	struct r600_pipe_shader_selector *last_ls;
60401e04c3fSmrg	struct r600_pipe_shader_selector *last_tcs;
60501e04c3fSmrg	unsigned last_num_tcs_input_cp;
60601e04c3fSmrg	unsigned lds_alloc;
60701e04c3fSmrg
60801e04c3fSmrg	struct r600_scratch_buffer scratch_buffers[MAX2(R600_NUM_HW_STAGES, EG_NUM_HW_STAGES)];
60901e04c3fSmrg
61001e04c3fSmrg	/* Debug state. */
61101e04c3fSmrg	bool			is_debug;
61201e04c3fSmrg	struct radeon_saved_cs	last_gfx;
61301e04c3fSmrg	struct r600_resource	*last_trace_buf;
61401e04c3fSmrg	struct r600_resource	*trace_buf;
61501e04c3fSmrg	unsigned		trace_id;
61601e04c3fSmrg
6177ec681f3Smrg	uint8_t patch_vertices;
61801e04c3fSmrg	bool cmd_buf_is_compute;
61901e04c3fSmrg	struct pipe_resource *append_fence;
62001e04c3fSmrg	uint32_t append_fence_id;
6213464ebd5Sriastradh};
6223464ebd5Sriastradh
62301e04c3fSmrgstatic inline void r600_emit_command_buffer(struct radeon_cmdbuf *cs,
624af69d88dSmrg					    struct r600_command_buffer *cb)
625af69d88dSmrg{
62601e04c3fSmrg	assert(cs->current.cdw + cb->num_dw <= cs->current.max_dw);
62701e04c3fSmrg	memcpy(cs->current.buf + cs->current.cdw, cb->buf, 4 * cb->num_dw);
62801e04c3fSmrg	cs->current.cdw += cb->num_dw;
62901e04c3fSmrg}
63001e04c3fSmrg
63101e04c3fSmrgstatic inline void r600_set_atom_dirty(struct r600_context *rctx,
63201e04c3fSmrg				       struct r600_atom *atom,
63301e04c3fSmrg				       bool dirty)
63401e04c3fSmrg{
63501e04c3fSmrg	uint64_t mask;
63601e04c3fSmrg
63701e04c3fSmrg	assert(atom->id != 0);
63801e04c3fSmrg	assert(atom->id < sizeof(mask) * 8);
63901e04c3fSmrg	mask = 1ull << atom->id;
64001e04c3fSmrg	if (dirty)
64101e04c3fSmrg		rctx->dirty_atoms |= mask;
64201e04c3fSmrg	else
64301e04c3fSmrg		rctx->dirty_atoms &= ~mask;
644af69d88dSmrg}
645af69d88dSmrg
64601e04c3fSmrgstatic inline void r600_mark_atom_dirty(struct r600_context *rctx,
64701e04c3fSmrg					struct r600_atom *atom)
64801e04c3fSmrg{
64901e04c3fSmrg	r600_set_atom_dirty(rctx, atom, true);
65001e04c3fSmrg}
651af69d88dSmrg
65201e04c3fSmrgstatic inline void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
653af69d88dSmrg{
654af69d88dSmrg	atom->emit(&rctx->b, atom);
65501e04c3fSmrg	r600_set_atom_dirty(rctx, atom, false);
656af69d88dSmrg}
657af69d88dSmrg
65801e04c3fSmrgstatic inline void r600_set_cso_state(struct r600_context *rctx,
65901e04c3fSmrg				      struct r600_cso_state *state, void *cso)
660af69d88dSmrg{
661af69d88dSmrg	state->cso = cso;
66201e04c3fSmrg	r600_set_atom_dirty(rctx, &state->atom, cso != NULL);
663af69d88dSmrg}
664af69d88dSmrg
66501e04c3fSmrgstatic inline void r600_set_cso_state_with_cb(struct r600_context *rctx,
66601e04c3fSmrg					      struct r600_cso_state *state, void *cso,
667af69d88dSmrg					      struct r600_command_buffer *cb)
668af69d88dSmrg{
669af69d88dSmrg	state->cb = cb;
670af69d88dSmrg	state->atom.num_dw = cb ? cb->num_dw : 0;
67101e04c3fSmrg	r600_set_cso_state(rctx, state, cso);
672af69d88dSmrg}
673af69d88dSmrg
674af69d88dSmrg/* compute_memory_pool.c */
675af69d88dSmrgstruct compute_memory_pool;
676af69d88dSmrgvoid compute_memory_pool_delete(struct compute_memory_pool* pool);
677af69d88dSmrgstruct compute_memory_pool* compute_memory_pool_new(
678af69d88dSmrg	struct r600_screen *rscreen);
679af69d88dSmrg
6803464ebd5Sriastradh/* evergreen_state.c */
681af69d88dSmrgstruct pipe_sampler_view *
682af69d88dSmrgevergreen_create_sampler_view_custom(struct pipe_context *ctx,
683af69d88dSmrg				     struct pipe_resource *texture,
684af69d88dSmrg				     const struct pipe_sampler_view *state,
685af69d88dSmrg				     unsigned width0, unsigned height0,
686af69d88dSmrg				     unsigned force_level);
68701e04c3fSmrgvoid evergreen_init_common_regs(struct r600_context *ctx,
68801e04c3fSmrg				struct r600_command_buffer *cb,
689af69d88dSmrg				enum chip_class ctx_chip_class,
690af69d88dSmrg				enum radeon_family ctx_family,
691af69d88dSmrg				int ctx_drm_minor);
692af69d88dSmrgvoid cayman_init_common_regs(struct r600_command_buffer *cb,
693af69d88dSmrg			     enum chip_class ctx_chip_class,
694af69d88dSmrg			     enum radeon_family ctx_family,
695af69d88dSmrg			     int ctx_drm_minor);
696af69d88dSmrg
697af69d88dSmrgvoid evergreen_init_state_functions(struct r600_context *rctx);
698af69d88dSmrgvoid evergreen_init_atom_start_cs(struct r600_context *rctx);
699af69d88dSmrgvoid evergreen_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
700af69d88dSmrgvoid evergreen_update_es_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
701af69d88dSmrgvoid evergreen_update_gs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
702af69d88dSmrgvoid evergreen_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
70301e04c3fSmrgvoid evergreen_update_ls_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
70401e04c3fSmrgvoid evergreen_update_hs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
705af69d88dSmrgvoid *evergreen_create_db_flush_dsa(struct r600_context *rctx);
706af69d88dSmrgvoid *evergreen_create_resolve_blend(struct r600_context *rctx);
707af69d88dSmrgvoid *evergreen_create_decompress_blend(struct r600_context *rctx);
708af69d88dSmrgvoid *evergreen_create_fastclear_blend(struct r600_context *rctx);
7097ec681f3Smrgbool evergreen_is_format_supported(struct pipe_screen *screen,
7107ec681f3Smrg				   enum pipe_format format,
7117ec681f3Smrg				   enum pipe_texture_target target,
7127ec681f3Smrg				   unsigned sample_count,
7137ec681f3Smrg				   unsigned storage_sample_count,
7147ec681f3Smrg				   unsigned usage);
715af69d88dSmrgvoid evergreen_init_color_surface(struct r600_context *rctx,
716af69d88dSmrg				  struct r600_surface *surf);
717af69d88dSmrgvoid evergreen_init_color_surface_rat(struct r600_context *rctx,
718af69d88dSmrg					struct r600_surface *surf);
719af69d88dSmrgvoid evergreen_update_db_shader_control(struct r600_context * rctx);
72001e04c3fSmrgbool evergreen_adjust_gprs(struct r600_context *rctx);
72101e04c3fSmrgvoid evergreen_setup_scratch_buffers(struct r600_context *rctx);
72201e04c3fSmrguint32_t evergreen_construct_rat_mask(struct r600_context *rctx, struct r600_cb_misc_state *a,
72301e04c3fSmrg				      unsigned nr_cbufs);
7243464ebd5Sriastradh/* r600_blit.c */
725af69d88dSmrgvoid r600_init_blit_functions(struct r600_context *rctx);
726af69d88dSmrgvoid r600_decompress_depth_textures(struct r600_context *rctx,
727af69d88dSmrg				    struct r600_samplerview_state *textures);
72801e04c3fSmrgvoid r600_decompress_depth_images(struct r600_context *rctx,
72901e04c3fSmrg				  struct r600_image_state *images);
730af69d88dSmrgvoid r600_decompress_color_textures(struct r600_context *rctx,
731af69d88dSmrg				    struct r600_samplerview_state *textures);
73201e04c3fSmrgvoid r600_decompress_color_images(struct r600_context *rctx,
73301e04c3fSmrg				  struct r600_image_state *images);
73401e04c3fSmrgvoid r600_resource_copy_region(struct pipe_context *ctx,
73501e04c3fSmrg			       struct pipe_resource *dst,
73601e04c3fSmrg			       unsigned dst_level,
73701e04c3fSmrg			       unsigned dstx, unsigned dsty, unsigned dstz,
73801e04c3fSmrg			       struct pipe_resource *src,
73901e04c3fSmrg			       unsigned src_level,
74001e04c3fSmrg			       const struct pipe_box *src_box);
7413464ebd5Sriastradh
7423464ebd5Sriastradh/* r600_shader.c */
743af69d88dSmrgint r600_pipe_shader_create(struct pipe_context *ctx,
744af69d88dSmrg			    struct r600_pipe_shader *shader,
74501e04c3fSmrg			    union r600_shader_key key);
746af69d88dSmrg
7473464ebd5Sriastradhvoid r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
7483464ebd5Sriastradh
7493464ebd5Sriastradh/* r600_state.c */
750af69d88dSmrgstruct pipe_sampler_view *
751af69d88dSmrgr600_create_sampler_view_custom(struct pipe_context *ctx,
752af69d88dSmrg				struct pipe_resource *texture,
753af69d88dSmrg				const struct pipe_sampler_view *state,
754af69d88dSmrg				unsigned width_first_level, unsigned height_first_level);
755af69d88dSmrgvoid r600_init_state_functions(struct r600_context *rctx);
756af69d88dSmrgvoid r600_init_atom_start_cs(struct r600_context *rctx);
757af69d88dSmrgvoid r600_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
758af69d88dSmrgvoid r600_update_es_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
759af69d88dSmrgvoid r600_update_gs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
760af69d88dSmrgvoid r600_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
761af69d88dSmrgvoid *r600_create_db_flush_dsa(struct r600_context *rctx);
762af69d88dSmrgvoid *r600_create_resolve_blend(struct r600_context *rctx);
763af69d88dSmrgvoid *r700_create_resolve_blend(struct r600_context *rctx);
764af69d88dSmrgvoid *r600_create_decompress_blend(struct r600_context *rctx);
765af69d88dSmrgbool r600_adjust_gprs(struct r600_context *rctx);
7667ec681f3Smrgbool r600_is_format_supported(struct pipe_screen *screen,
7677ec681f3Smrg			      enum pipe_format format,
7687ec681f3Smrg			      enum pipe_texture_target target,
7697ec681f3Smrg			      unsigned sample_count,
7707ec681f3Smrg			      unsigned storage_sample_count,
7717ec681f3Smrg			      unsigned usage);
772af69d88dSmrgvoid r600_update_db_shader_control(struct r600_context * rctx);
77301e04c3fSmrgvoid r600_setup_scratch_buffers(struct r600_context *rctx);
774af69d88dSmrg
775af69d88dSmrg/* r600_hw_context.c */
776af69d88dSmrgvoid r600_context_gfx_flush(void *context, unsigned flags,
777af69d88dSmrg			    struct pipe_fence_handle **fence);
778af69d88dSmrgvoid r600_begin_new_cs(struct r600_context *ctx);
779af69d88dSmrgvoid r600_flush_emit(struct r600_context *ctx);
78001e04c3fSmrgvoid r600_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in, unsigned num_atomics);
78101e04c3fSmrgvoid r600_emit_pfp_sync_me(struct r600_context *rctx);
782af69d88dSmrgvoid r600_cp_dma_copy_buffer(struct r600_context *rctx,
783af69d88dSmrg			     struct pipe_resource *dst, uint64_t dst_offset,
784af69d88dSmrg			     struct pipe_resource *src, uint64_t src_offset,
785af69d88dSmrg			     unsigned size);
786af69d88dSmrgvoid evergreen_cp_dma_clear_buffer(struct r600_context *rctx,
787af69d88dSmrg				   struct pipe_resource *dst, uint64_t offset,
78801e04c3fSmrg				   unsigned size, uint32_t clear_value,
78901e04c3fSmrg				   enum r600_coherency coher);
790af69d88dSmrgvoid r600_dma_copy_buffer(struct r600_context *rctx,
791af69d88dSmrg			  struct pipe_resource *dst,
792af69d88dSmrg			  struct pipe_resource *src,
793af69d88dSmrg			  uint64_t dst_offset,
794af69d88dSmrg			  uint64_t src_offset,
795af69d88dSmrg			  uint64_t size);
796af69d88dSmrg
797af69d88dSmrg/*
798af69d88dSmrg * evergreen_hw_context.c
799af69d88dSmrg */
800af69d88dSmrgvoid evergreen_dma_copy_buffer(struct r600_context *rctx,
801af69d88dSmrg			       struct pipe_resource *dst,
802af69d88dSmrg			       struct pipe_resource *src,
803af69d88dSmrg			       uint64_t dst_offset,
804af69d88dSmrg			       uint64_t src_offset,
805af69d88dSmrg			       uint64_t size);
80601e04c3fSmrgvoid evergreen_setup_tess_constants(struct r600_context *rctx,
80701e04c3fSmrg				    const struct pipe_draw_info *info,
80801e04c3fSmrg				    unsigned *num_patches);
80901e04c3fSmrguint32_t evergreen_get_ls_hs_config(struct r600_context *rctx,
81001e04c3fSmrg				    const struct pipe_draw_info *info,
81101e04c3fSmrg				    unsigned num_patches);
81201e04c3fSmrgvoid evergreen_set_ls_hs_config(struct r600_context *rctx,
81301e04c3fSmrg				struct radeon_cmdbuf *cs,
81401e04c3fSmrg				uint32_t ls_hs_config);
81501e04c3fSmrgvoid evergreen_set_lds_alloc(struct r600_context *rctx,
81601e04c3fSmrg			     struct radeon_cmdbuf *cs,
81701e04c3fSmrg			     uint32_t lds_alloc);
818af69d88dSmrg
819af69d88dSmrg/* r600_state_common.c */
820af69d88dSmrgvoid r600_init_common_state_functions(struct r600_context *rctx);
821af69d88dSmrgvoid r600_emit_cso_state(struct r600_context *rctx, struct r600_atom *atom);
822af69d88dSmrgvoid r600_emit_alphatest_state(struct r600_context *rctx, struct r600_atom *atom);
823af69d88dSmrgvoid r600_emit_blend_color(struct r600_context *rctx, struct r600_atom *atom);
824af69d88dSmrgvoid r600_emit_vgt_state(struct r600_context *rctx, struct r600_atom *atom);
825af69d88dSmrgvoid r600_emit_clip_misc_state(struct r600_context *rctx, struct r600_atom *atom);
826af69d88dSmrgvoid r600_emit_stencil_ref(struct r600_context *rctx, struct r600_atom *atom);
827af69d88dSmrgvoid r600_emit_shader(struct r600_context *rctx, struct r600_atom *a);
82801e04c3fSmrgvoid r600_add_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id);
829af69d88dSmrgvoid r600_init_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id,
830af69d88dSmrg		    void (*emit)(struct r600_context *ctx, struct r600_atom *state),
831af69d88dSmrg		    unsigned num_dw);
832af69d88dSmrgvoid r600_vertex_buffers_dirty(struct r600_context *rctx);
833af69d88dSmrgvoid r600_sampler_views_dirty(struct r600_context *rctx,
834af69d88dSmrg			      struct r600_samplerview_state *state);
835af69d88dSmrgvoid r600_sampler_states_dirty(struct r600_context *rctx,
836af69d88dSmrg			       struct r600_sampler_states *state);
837af69d88dSmrgvoid r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf_state *state);
83801e04c3fSmrgvoid r600_set_sample_locations_constant_buffer(struct r600_context *rctx);
83901e04c3fSmrgvoid r600_setup_scratch_area_for_shader(struct r600_context *rctx,
84001e04c3fSmrg	struct r600_pipe_shader *shader, struct r600_scratch_buffer *scratch,
84101e04c3fSmrg	unsigned ring_base_reg, unsigned item_size_reg, unsigned ring_size_reg);
842af69d88dSmrguint32_t r600_translate_stencil_op(int s_op);
843af69d88dSmrguint32_t r600_translate_fill(uint32_t func);
844af69d88dSmrgunsigned r600_tex_wrap(unsigned wrap);
845af69d88dSmrgunsigned r600_tex_mipfilter(unsigned filter);
846af69d88dSmrgunsigned r600_tex_compare(unsigned compare);
847af69d88dSmrgbool sampler_state_needs_border_color(const struct pipe_sampler_state *state);
848af69d88dSmrgunsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
849af69d88dSmrg				   const unsigned char *swizzle_view,
850af69d88dSmrg				   boolean vtx);
8513464ebd5Sriastradhuint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
8523464ebd5Sriastradh				  const unsigned char *swizzle_view,
85301e04c3fSmrg				  uint32_t *word4_p, uint32_t *yuv_format_p,
85401e04c3fSmrg				  bool do_endian_swap);
85501e04c3fSmrguint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format,
85601e04c3fSmrg				  bool do_endian_swap);
85701e04c3fSmrguint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap);
8583464ebd5Sriastradh
859af69d88dSmrg/* r600_uvd.c */
860af69d88dSmrgstruct pipe_video_codec *r600_uvd_create_decoder(struct pipe_context *context,
861af69d88dSmrg						   const struct pipe_video_codec *decoder);
8623464ebd5Sriastradh
863af69d88dSmrgstruct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
864af69d88dSmrg						   const struct pipe_video_buffer *tmpl);
865af69d88dSmrg
866af69d88dSmrg/*
867af69d88dSmrg * Helpers for building command buffers
868af69d88dSmrg */
869af69d88dSmrg
870af69d88dSmrg#define PKT3_SET_CONFIG_REG	0x68
871af69d88dSmrg#define PKT3_SET_CONTEXT_REG	0x69
872af69d88dSmrg#define PKT3_SET_CTL_CONST      0x6F
873af69d88dSmrg#define PKT3_SET_LOOP_CONST                    0x6C
874af69d88dSmrg
875af69d88dSmrg#define R600_CONFIG_REG_OFFSET	0x08000
876af69d88dSmrg#define R600_CONTEXT_REG_OFFSET 0x28000
877af69d88dSmrg#define R600_CTL_CONST_OFFSET   0x3CFF0
878af69d88dSmrg#define R600_LOOP_CONST_OFFSET                 0X0003E200
879af69d88dSmrg#define EG_LOOP_CONST_OFFSET               0x0003A200
880af69d88dSmrg
88101e04c3fSmrg#define PKT_TYPE_S(x)                   (((unsigned)(x) & 0x3) << 30)
88201e04c3fSmrg#define PKT_COUNT_S(x)                  (((unsigned)(x) & 0x3FFF) << 16)
88301e04c3fSmrg#define PKT3_IT_OPCODE_S(x)             (((unsigned)(x) & 0xFF) << 8)
884af69d88dSmrg#define PKT3_PREDICATE(x)               (((x) >> 0) & 0x1)
885af69d88dSmrg#define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
886af69d88dSmrg
887af69d88dSmrg#define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
888af69d88dSmrg
889af69d88dSmrg/*Evergreen Compute packet3*/
890af69d88dSmrg#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)
891af69d88dSmrg
89201e04c3fSmrgstatic inline void r600_store_value(struct r600_command_buffer *cb, unsigned value)
893af69d88dSmrg{
894af69d88dSmrg	cb->buf[cb->num_dw++] = value;
895af69d88dSmrg}
896af69d88dSmrg
89701e04c3fSmrgstatic inline void r600_store_array(struct r600_command_buffer *cb, unsigned num, unsigned *ptr)
898af69d88dSmrg{
899af69d88dSmrg	assert(cb->num_dw+num <= cb->max_num_dw);
900af69d88dSmrg	memcpy(&cb->buf[cb->num_dw], ptr, num * sizeof(ptr[0]));
901af69d88dSmrg	cb->num_dw += num;
902af69d88dSmrg}
903af69d88dSmrg
90401e04c3fSmrgstatic inline void r600_store_config_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
905af69d88dSmrg{
906af69d88dSmrg	assert(reg < R600_CONTEXT_REG_OFFSET);
907af69d88dSmrg	assert(cb->num_dw+2+num <= cb->max_num_dw);
908af69d88dSmrg	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
909af69d88dSmrg	cb->buf[cb->num_dw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
910af69d88dSmrg}
911af69d88dSmrg
912af69d88dSmrg/**
913af69d88dSmrg * Needs cb->pkt_flags set to  RADEON_CP_PACKET3_COMPUTE_MODE for compute
914af69d88dSmrg * shaders.
915af69d88dSmrg */
91601e04c3fSmrgstatic inline void r600_store_context_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
917af69d88dSmrg{
918af69d88dSmrg	assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
919af69d88dSmrg	assert(cb->num_dw+2+num <= cb->max_num_dw);
920af69d88dSmrg	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0) | cb->pkt_flags;
921af69d88dSmrg	cb->buf[cb->num_dw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
922af69d88dSmrg}
923af69d88dSmrg
924af69d88dSmrg/**
925af69d88dSmrg * Needs cb->pkt_flags set to  RADEON_CP_PACKET3_COMPUTE_MODE for compute
926af69d88dSmrg * shaders.
927af69d88dSmrg */
92801e04c3fSmrgstatic inline void r600_store_ctl_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
929af69d88dSmrg{
930af69d88dSmrg	assert(reg >= R600_CTL_CONST_OFFSET);
931af69d88dSmrg	assert(cb->num_dw+2+num <= cb->max_num_dw);
932af69d88dSmrg	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CTL_CONST, num, 0) | cb->pkt_flags;
933af69d88dSmrg	cb->buf[cb->num_dw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
934af69d88dSmrg}
935af69d88dSmrg
93601e04c3fSmrgstatic inline void r600_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
937af69d88dSmrg{
938af69d88dSmrg	assert(reg >= R600_LOOP_CONST_OFFSET);
939af69d88dSmrg	assert(cb->num_dw+2+num <= cb->max_num_dw);
940af69d88dSmrg	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0);
941af69d88dSmrg	cb->buf[cb->num_dw++] = (reg - R600_LOOP_CONST_OFFSET) >> 2;
942af69d88dSmrg}
943af69d88dSmrg
944af69d88dSmrg/**
945af69d88dSmrg * Needs cb->pkt_flags set to  RADEON_CP_PACKET3_COMPUTE_MODE for compute
946af69d88dSmrg * shaders.
947af69d88dSmrg */
94801e04c3fSmrgstatic inline void eg_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
949af69d88dSmrg{
950af69d88dSmrg	assert(reg >= EG_LOOP_CONST_OFFSET);
951af69d88dSmrg	assert(cb->num_dw+2+num <= cb->max_num_dw);
952af69d88dSmrg	cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0) | cb->pkt_flags;
953af69d88dSmrg	cb->buf[cb->num_dw++] = (reg - EG_LOOP_CONST_OFFSET) >> 2;
954af69d88dSmrg}
955af69d88dSmrg
95601e04c3fSmrgstatic inline void r600_store_config_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
957af69d88dSmrg{
958af69d88dSmrg	r600_store_config_reg_seq(cb, reg, 1);
959af69d88dSmrg	r600_store_value(cb, value);
960af69d88dSmrg}
961af69d88dSmrg
96201e04c3fSmrgstatic inline void r600_store_context_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
963af69d88dSmrg{
964af69d88dSmrg	r600_store_context_reg_seq(cb, reg, 1);
965af69d88dSmrg	r600_store_value(cb, value);
966af69d88dSmrg}
967af69d88dSmrg
96801e04c3fSmrgstatic inline void r600_store_ctl_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
969af69d88dSmrg{
970af69d88dSmrg	r600_store_ctl_const_seq(cb, reg, 1);
971af69d88dSmrg	r600_store_value(cb, value);
972af69d88dSmrg}
973af69d88dSmrg
97401e04c3fSmrgstatic inline void r600_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
975af69d88dSmrg{
976af69d88dSmrg	r600_store_loop_const_seq(cb, reg, 1);
977af69d88dSmrg	r600_store_value(cb, value);
978af69d88dSmrg}
979af69d88dSmrg
98001e04c3fSmrgstatic inline void eg_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
981af69d88dSmrg{
982af69d88dSmrg	eg_store_loop_const_seq(cb, reg, 1);
983af69d88dSmrg	r600_store_value(cb, value);
984af69d88dSmrg}
985af69d88dSmrg
986af69d88dSmrgvoid r600_init_command_buffer(struct r600_command_buffer *cb, unsigned num_dw);
987af69d88dSmrgvoid r600_release_command_buffer(struct r600_command_buffer *cb);
988af69d88dSmrg
98901e04c3fSmrgstatic inline void radeon_compute_set_context_reg_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num)
990af69d88dSmrg{
99101e04c3fSmrg	radeon_set_context_reg_seq(cs, reg, num);
992af69d88dSmrg	/* Set the compute bit on the packet header */
99301e04c3fSmrg	cs->current.buf[cs->current.cdw - 2] |= RADEON_CP_PACKET3_COMPUTE_MODE;
994af69d88dSmrg}
995af69d88dSmrg
99601e04c3fSmrgstatic inline void radeon_set_ctl_const_seq(struct radeon_cmdbuf *cs, unsigned reg, unsigned num)
997af69d88dSmrg{
998af69d88dSmrg	assert(reg >= R600_CTL_CONST_OFFSET);
99901e04c3fSmrg	assert(cs->current.cdw + 2 + num <= cs->current.max_dw);
100001e04c3fSmrg	radeon_emit(cs, PKT3(PKT3_SET_CTL_CONST, num, 0));
100101e04c3fSmrg	radeon_emit(cs, (reg - R600_CTL_CONST_OFFSET) >> 2);
1002af69d88dSmrg}
1003af69d88dSmrg
100401e04c3fSmrgstatic inline void radeon_compute_set_context_reg(struct radeon_cmdbuf *cs, unsigned reg, unsigned value)
1005af69d88dSmrg{
100601e04c3fSmrg	radeon_compute_set_context_reg_seq(cs, reg, 1);
1007af69d88dSmrg	radeon_emit(cs, value);
1008af69d88dSmrg}
1009af69d88dSmrg
101001e04c3fSmrgstatic inline void radeon_set_context_reg_flag(struct radeon_cmdbuf *cs, unsigned reg, unsigned value, unsigned flag)
1011af69d88dSmrg{
1012af69d88dSmrg	if (flag & RADEON_CP_PACKET3_COMPUTE_MODE) {
101301e04c3fSmrg		radeon_compute_set_context_reg(cs, reg, value);
1014af69d88dSmrg	} else {
101501e04c3fSmrg		radeon_set_context_reg(cs, reg, value);
1016af69d88dSmrg	}
1017af69d88dSmrg}
1018af69d88dSmrg
101901e04c3fSmrgstatic inline void radeon_set_ctl_const(struct radeon_cmdbuf *cs, unsigned reg, unsigned value)
1020af69d88dSmrg{
102101e04c3fSmrg	radeon_set_ctl_const_seq(cs, reg, 1);
1022af69d88dSmrg	radeon_emit(cs, value);
1023af69d88dSmrg}
10243464ebd5Sriastradh
10253464ebd5Sriastradh/*
10263464ebd5Sriastradh * common helpers
10273464ebd5Sriastradh */
10283464ebd5Sriastradh
1029af69d88dSmrg/* 12.4 fixed-point */
103001e04c3fSmrgstatic inline unsigned r600_pack_float_12p4(float x)
1031af69d88dSmrg{
1032af69d88dSmrg	return x <= 0    ? 0 :
1033af69d88dSmrg	       x >= 4096 ? 0xffff : x * 16;
1034af69d88dSmrg}
1035af69d88dSmrg
103601e04c3fSmrgstatic inline unsigned r600_get_flush_flags(enum r600_coherency coher)
1037af69d88dSmrg{
103801e04c3fSmrg	switch (coher) {
103901e04c3fSmrg	default:
104001e04c3fSmrg	case R600_COHERENCY_NONE:
104101e04c3fSmrg		return 0;
104201e04c3fSmrg	case R600_COHERENCY_SHADER:
104301e04c3fSmrg		return R600_CONTEXT_INV_CONST_CACHE |
104401e04c3fSmrg		       R600_CONTEXT_INV_VERTEX_CACHE |
104501e04c3fSmrg		       R600_CONTEXT_INV_TEX_CACHE |
104601e04c3fSmrg		       R600_CONTEXT_STREAMOUT_FLUSH;
104701e04c3fSmrg	case R600_COHERENCY_CB_META:
104801e04c3fSmrg		return R600_CONTEXT_FLUSH_AND_INV_CB |
104901e04c3fSmrg		       R600_CONTEXT_FLUSH_AND_INV_CB_META;
105001e04c3fSmrg	}
1051af69d88dSmrg}
1052af69d88dSmrg
1053af69d88dSmrg#define     V_028A6C_OUTPRIM_TYPE_POINTLIST            0
1054af69d88dSmrg#define     V_028A6C_OUTPRIM_TYPE_LINESTRIP            1
1055af69d88dSmrg#define     V_028A6C_OUTPRIM_TYPE_TRISTRIP             2
1056af69d88dSmrg
105701e04c3fSmrgunsigned r600_conv_prim_to_gs_out(unsigned mode);
105801e04c3fSmrg
105901e04c3fSmrgvoid eg_trace_emit(struct r600_context *rctx);
106001e04c3fSmrgvoid eg_dump_debug_state(struct pipe_context *ctx, FILE *f,
106101e04c3fSmrg			 unsigned flags);
106201e04c3fSmrg
106301e04c3fSmrgstruct r600_pipe_shader_selector *r600_create_shader_state_tokens(struct pipe_context *ctx,
10647ec681f3Smrg								  const void *tokens,
10657ec681f3Smrg								  enum pipe_shader_ir,
106601e04c3fSmrg								  unsigned pipe_shader_type);
106701e04c3fSmrgint r600_shader_select(struct pipe_context *ctx,
106801e04c3fSmrg		       struct r600_pipe_shader_selector* sel,
106901e04c3fSmrg		       bool *dirty);
107001e04c3fSmrg
107101e04c3fSmrgvoid r600_delete_shader_selector(struct pipe_context *ctx,
107201e04c3fSmrg				 struct r600_pipe_shader_selector *sel);
107301e04c3fSmrg
107401e04c3fSmrgstruct r600_shader_atomic;
107501e04c3fSmrgvoid evergreen_emit_atomic_buffer_setup_count(struct r600_context *rctx,
107601e04c3fSmrg					      struct r600_pipe_shader *cs_shader,
107701e04c3fSmrg					      struct r600_shader_atomic *combined_atomics,
107801e04c3fSmrg					      uint8_t *atomic_used_mask_p);
107901e04c3fSmrgvoid evergreen_emit_atomic_buffer_setup(struct r600_context *rctx,
108001e04c3fSmrg					bool is_compute,
108101e04c3fSmrg					struct r600_shader_atomic *combined_atomics,
108201e04c3fSmrg					uint8_t atomic_used_mask);
108301e04c3fSmrgvoid evergreen_emit_atomic_buffer_save(struct r600_context *rctx,
108401e04c3fSmrg				       bool is_compute,
108501e04c3fSmrg				       struct r600_shader_atomic *combined_atomics,
108601e04c3fSmrg				       uint8_t *atomic_used_mask_p);
108701e04c3fSmrgvoid r600_update_compressed_resource_state(struct r600_context *rctx, bool compute_only);
108801e04c3fSmrg
108901e04c3fSmrgvoid eg_setup_buffer_constants(struct r600_context *rctx, int shader_type);
109001e04c3fSmrgvoid r600_update_driver_const_buffers(struct r600_context *rctx, bool compute_only);
10913464ebd5Sriastradh#endif
1092