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#include "r600_pipe.h"
24bf215546Sopenharmony_ci#include "r600_public.h"
25bf215546Sopenharmony_ci#include "r600_isa.h"
26bf215546Sopenharmony_ci#include "evergreen_compute.h"
27bf215546Sopenharmony_ci#include "r600d.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "sb/sb_public.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include <errno.h>
32bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h"
33bf215546Sopenharmony_ci#include "util/u_debug.h"
34bf215546Sopenharmony_ci#include "util/u_memory.h"
35bf215546Sopenharmony_ci#include "util/u_screen.h"
36bf215546Sopenharmony_ci#include "util/u_simple_shaders.h"
37bf215546Sopenharmony_ci#include "util/u_upload_mgr.h"
38bf215546Sopenharmony_ci#include "util/u_math.h"
39bf215546Sopenharmony_ci#include "vl/vl_decoder.h"
40bf215546Sopenharmony_ci#include "vl/vl_video_buffer.h"
41bf215546Sopenharmony_ci#include "radeon_video.h"
42bf215546Sopenharmony_ci#include "radeon_uvd.h"
43bf215546Sopenharmony_ci#include "util/os_time.h"
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistatic const struct debug_named_value r600_debug_options[] = {
46bf215546Sopenharmony_ci	/* features */
47bf215546Sopenharmony_ci	{ "nocpdma", DBG_NO_CP_DMA, "Disable CP DMA" },
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci	/* shader backend */
50bf215546Sopenharmony_ci	{ "nosb", DBG_NO_SB, "Disable sb backend for graphics shaders" },
51bf215546Sopenharmony_ci	{ "sbdry", DBG_SB_DRY_RUN, "Don't use optimized bytecode (just print the dumps)" },
52bf215546Sopenharmony_ci	{ "sbstat", DBG_SB_STAT, "Print optimization statistics for shaders" },
53bf215546Sopenharmony_ci	{ "sbdump", DBG_SB_DUMP, "Print IR dumps after some optimization passes" },
54bf215546Sopenharmony_ci	{ "sbnofallback", DBG_SB_NO_FALLBACK, "Abort on errors instead of fallback" },
55bf215546Sopenharmony_ci	{ "sbdisasm", DBG_SB_DISASM, "Use sb disassembler for shader dumps" },
56bf215546Sopenharmony_ci	{ "sbsafemath", DBG_SB_SAFEMATH, "Disable unsafe math optimizations" },
57bf215546Sopenharmony_ci        { "nirsb", DBG_NIR_SB, "Enable NIR with SB optimizer"},
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci	DEBUG_NAMED_VALUE_END /* must be last */
60bf215546Sopenharmony_ci};
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci/*
63bf215546Sopenharmony_ci * pipe_context
64bf215546Sopenharmony_ci */
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_cistatic void r600_destroy_context(struct pipe_context *context)
67bf215546Sopenharmony_ci{
68bf215546Sopenharmony_ci	struct r600_context *rctx = (struct r600_context *)context;
69bf215546Sopenharmony_ci	unsigned sh, i;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci	r600_isa_destroy(rctx->isa);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci	r600_sb_context_destroy(rctx->sb_context);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci	for (sh = 0; sh < (rctx->b.gfx_level < EVERGREEN ? R600_NUM_HW_STAGES : EG_NUM_HW_STAGES); sh++) {
76bf215546Sopenharmony_ci		r600_resource_reference(&rctx->scratch_buffers[sh].buffer, NULL);
77bf215546Sopenharmony_ci	}
78bf215546Sopenharmony_ci	r600_resource_reference(&rctx->dummy_cmask, NULL);
79bf215546Sopenharmony_ci	r600_resource_reference(&rctx->dummy_fmask, NULL);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci	if (rctx->append_fence)
82bf215546Sopenharmony_ci		pipe_resource_reference((struct pipe_resource**)&rctx->append_fence, NULL);
83bf215546Sopenharmony_ci	for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
84bf215546Sopenharmony_ci		rctx->b.b.set_constant_buffer(&rctx->b.b, sh, R600_BUFFER_INFO_CONST_BUFFER, false, NULL);
85bf215546Sopenharmony_ci		free(rctx->driver_consts[sh].constants);
86bf215546Sopenharmony_ci	}
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci	if (rctx->fixed_func_tcs_shader)
89bf215546Sopenharmony_ci		rctx->b.b.delete_tcs_state(&rctx->b.b, rctx->fixed_func_tcs_shader);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci	if (rctx->dummy_pixel_shader) {
92bf215546Sopenharmony_ci		rctx->b.b.delete_fs_state(&rctx->b.b, rctx->dummy_pixel_shader);
93bf215546Sopenharmony_ci	}
94bf215546Sopenharmony_ci	if (rctx->custom_dsa_flush) {
95bf215546Sopenharmony_ci		rctx->b.b.delete_depth_stencil_alpha_state(&rctx->b.b, rctx->custom_dsa_flush);
96bf215546Sopenharmony_ci	}
97bf215546Sopenharmony_ci	if (rctx->custom_blend_resolve) {
98bf215546Sopenharmony_ci		rctx->b.b.delete_blend_state(&rctx->b.b, rctx->custom_blend_resolve);
99bf215546Sopenharmony_ci	}
100bf215546Sopenharmony_ci	if (rctx->custom_blend_decompress) {
101bf215546Sopenharmony_ci		rctx->b.b.delete_blend_state(&rctx->b.b, rctx->custom_blend_decompress);
102bf215546Sopenharmony_ci	}
103bf215546Sopenharmony_ci	if (rctx->custom_blend_fastclear) {
104bf215546Sopenharmony_ci		rctx->b.b.delete_blend_state(&rctx->b.b, rctx->custom_blend_fastclear);
105bf215546Sopenharmony_ci	}
106bf215546Sopenharmony_ci	util_unreference_framebuffer_state(&rctx->framebuffer.state);
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci	if (rctx->gs_rings.gsvs_ring.buffer)
109bf215546Sopenharmony_ci		pipe_resource_reference(&rctx->gs_rings.gsvs_ring.buffer, NULL);
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci	if (rctx->gs_rings.esgs_ring.buffer)
112bf215546Sopenharmony_ci		pipe_resource_reference(&rctx->gs_rings.esgs_ring.buffer, NULL);
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci	for (sh = 0; sh < PIPE_SHADER_TYPES; ++sh)
115bf215546Sopenharmony_ci		for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; ++i)
116bf215546Sopenharmony_ci			rctx->b.b.set_constant_buffer(context, sh, i, false, NULL);
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci	if (rctx->blitter) {
119bf215546Sopenharmony_ci		util_blitter_destroy(rctx->blitter);
120bf215546Sopenharmony_ci	}
121bf215546Sopenharmony_ci	u_suballocator_destroy(&rctx->allocator_fetch_shader);
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci	r600_release_command_buffer(&rctx->start_cs_cmd);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci	FREE(rctx->start_compute_cs_cmd.buf);
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci	r600_common_context_cleanup(&rctx->b);
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci	r600_resource_reference(&rctx->trace_buf, NULL);
130bf215546Sopenharmony_ci	r600_resource_reference(&rctx->last_trace_buf, NULL);
131bf215546Sopenharmony_ci	radeon_clear_saved_cs(&rctx->last_gfx);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci	FREE(rctx);
134bf215546Sopenharmony_ci}
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_cistatic struct pipe_context *r600_create_context(struct pipe_screen *screen,
137bf215546Sopenharmony_ci                                                void *priv, unsigned flags)
138bf215546Sopenharmony_ci{
139bf215546Sopenharmony_ci	struct r600_context *rctx = CALLOC_STRUCT(r600_context);
140bf215546Sopenharmony_ci	struct r600_screen* rscreen = (struct r600_screen *)screen;
141bf215546Sopenharmony_ci	struct radeon_winsys *ws = rscreen->b.ws;
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci	if (!rctx)
144bf215546Sopenharmony_ci		return NULL;
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci	rctx->b.b.screen = screen;
147bf215546Sopenharmony_ci	assert(!priv);
148bf215546Sopenharmony_ci	rctx->b.b.priv = NULL; /* for threaded_context_unwrap_sync */
149bf215546Sopenharmony_ci	rctx->b.b.destroy = r600_destroy_context;
150bf215546Sopenharmony_ci	rctx->b.set_atom_dirty = (void *)r600_set_atom_dirty;
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_ci	if (!r600_common_context_init(&rctx->b, &rscreen->b, flags))
153bf215546Sopenharmony_ci		goto fail;
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci	rctx->screen = rscreen;
156bf215546Sopenharmony_ci	list_inithead(&rctx->texture_buffers);
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci	r600_init_blit_functions(rctx);
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci	if (rscreen->b.info.ip[AMD_IP_UVD].num_queues) {
161bf215546Sopenharmony_ci		rctx->b.b.create_video_codec = r600_uvd_create_decoder;
162bf215546Sopenharmony_ci		rctx->b.b.create_video_buffer = r600_video_buffer_create;
163bf215546Sopenharmony_ci	} else {
164bf215546Sopenharmony_ci		rctx->b.b.create_video_codec = vl_create_decoder;
165bf215546Sopenharmony_ci		rctx->b.b.create_video_buffer = vl_video_buffer_create;
166bf215546Sopenharmony_ci	}
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci	if (getenv("R600_TRACE"))
169bf215546Sopenharmony_ci		rctx->is_debug = true;
170bf215546Sopenharmony_ci	r600_init_common_state_functions(rctx);
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci	switch (rctx->b.gfx_level) {
173bf215546Sopenharmony_ci	case R600:
174bf215546Sopenharmony_ci	case R700:
175bf215546Sopenharmony_ci		r600_init_state_functions(rctx);
176bf215546Sopenharmony_ci		r600_init_atom_start_cs(rctx);
177bf215546Sopenharmony_ci		rctx->custom_dsa_flush = r600_create_db_flush_dsa(rctx);
178bf215546Sopenharmony_ci		rctx->custom_blend_resolve = rctx->b.gfx_level == R700 ? r700_create_resolve_blend(rctx)
179bf215546Sopenharmony_ci								      : r600_create_resolve_blend(rctx);
180bf215546Sopenharmony_ci		rctx->custom_blend_decompress = r600_create_decompress_blend(rctx);
181bf215546Sopenharmony_ci		rctx->has_vertex_cache = !(rctx->b.family == CHIP_RV610 ||
182bf215546Sopenharmony_ci					   rctx->b.family == CHIP_RV620 ||
183bf215546Sopenharmony_ci					   rctx->b.family == CHIP_RS780 ||
184bf215546Sopenharmony_ci					   rctx->b.family == CHIP_RS880 ||
185bf215546Sopenharmony_ci					   rctx->b.family == CHIP_RV710);
186bf215546Sopenharmony_ci		break;
187bf215546Sopenharmony_ci	case EVERGREEN:
188bf215546Sopenharmony_ci	case CAYMAN:
189bf215546Sopenharmony_ci		evergreen_init_state_functions(rctx);
190bf215546Sopenharmony_ci		evergreen_init_atom_start_cs(rctx);
191bf215546Sopenharmony_ci		evergreen_init_atom_start_compute_cs(rctx);
192bf215546Sopenharmony_ci		rctx->custom_dsa_flush = evergreen_create_db_flush_dsa(rctx);
193bf215546Sopenharmony_ci		rctx->custom_blend_resolve = evergreen_create_resolve_blend(rctx);
194bf215546Sopenharmony_ci		rctx->custom_blend_decompress = evergreen_create_decompress_blend(rctx);
195bf215546Sopenharmony_ci		rctx->custom_blend_fastclear = evergreen_create_fastclear_blend(rctx);
196bf215546Sopenharmony_ci		rctx->has_vertex_cache = !(rctx->b.family == CHIP_CEDAR ||
197bf215546Sopenharmony_ci					   rctx->b.family == CHIP_PALM ||
198bf215546Sopenharmony_ci					   rctx->b.family == CHIP_SUMO ||
199bf215546Sopenharmony_ci					   rctx->b.family == CHIP_SUMO2 ||
200bf215546Sopenharmony_ci					   rctx->b.family == CHIP_CAICOS ||
201bf215546Sopenharmony_ci					   rctx->b.family == CHIP_CAYMAN ||
202bf215546Sopenharmony_ci					   rctx->b.family == CHIP_ARUBA);
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci		rctx->append_fence = pipe_buffer_create(rctx->b.b.screen, PIPE_BIND_CUSTOM,
205bf215546Sopenharmony_ci							 PIPE_USAGE_DEFAULT, 32);
206bf215546Sopenharmony_ci		break;
207bf215546Sopenharmony_ci	default:
208bf215546Sopenharmony_ci		R600_ERR("Unsupported gfx level %d.\n", rctx->b.gfx_level);
209bf215546Sopenharmony_ci		goto fail;
210bf215546Sopenharmony_ci	}
211bf215546Sopenharmony_ci
212bf215546Sopenharmony_ci	ws->cs_create(&rctx->b.gfx.cs, rctx->b.ctx, AMD_IP_GFX,
213bf215546Sopenharmony_ci                      r600_context_gfx_flush, rctx, false);
214bf215546Sopenharmony_ci	rctx->b.gfx.flush = r600_context_gfx_flush;
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ci	u_suballocator_init(&rctx->allocator_fetch_shader, &rctx->b.b, 64 * 1024,
217bf215546Sopenharmony_ci                            0, PIPE_USAGE_DEFAULT, 0, FALSE);
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci	rctx->isa = calloc(1, sizeof(struct r600_isa));
220bf215546Sopenharmony_ci	if (!rctx->isa || r600_isa_init(rctx, rctx->isa))
221bf215546Sopenharmony_ci		goto fail;
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci	if (rscreen->b.debug_flags & DBG_FORCE_DMA)
224bf215546Sopenharmony_ci		rctx->b.b.resource_copy_region = rctx->b.dma_copy;
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci	rctx->blitter = util_blitter_create(&rctx->b.b);
227bf215546Sopenharmony_ci	if (rctx->blitter == NULL)
228bf215546Sopenharmony_ci		goto fail;
229bf215546Sopenharmony_ci	util_blitter_set_texture_multisample(rctx->blitter, rscreen->has_msaa);
230bf215546Sopenharmony_ci	rctx->blitter->draw_rectangle = r600_draw_rectangle;
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci	r600_begin_new_cs(rctx);
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci	rctx->dummy_pixel_shader =
235bf215546Sopenharmony_ci		util_make_fragment_cloneinput_shader(&rctx->b.b, 0,
236bf215546Sopenharmony_ci						     TGSI_SEMANTIC_GENERIC,
237bf215546Sopenharmony_ci						     TGSI_INTERPOLATE_CONSTANT);
238bf215546Sopenharmony_ci	rctx->b.b.bind_fs_state(&rctx->b.b, rctx->dummy_pixel_shader);
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci	return &rctx->b.b;
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_cifail:
243bf215546Sopenharmony_ci	r600_destroy_context(&rctx->b.b);
244bf215546Sopenharmony_ci	return NULL;
245bf215546Sopenharmony_ci}
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_cistatic bool is_nir_enabled(struct r600_common_screen *screen) {
248bf215546Sopenharmony_ci   return (screen->debug_flags & DBG_NIR_PREFERRED); /* &&
249bf215546Sopenharmony_ci       screen->family >= CHIP_CEDAR);*/
250bf215546Sopenharmony_ci}
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci/*
253bf215546Sopenharmony_ci * pipe_screen
254bf215546Sopenharmony_ci */
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_cistatic int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
257bf215546Sopenharmony_ci{
258bf215546Sopenharmony_ci	struct r600_screen *rscreen = (struct r600_screen *)pscreen;
259bf215546Sopenharmony_ci	enum radeon_family family = rscreen->b.family;
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci	switch (param) {
262bf215546Sopenharmony_ci	/* Supported features (boolean caps). */
263bf215546Sopenharmony_ci	case PIPE_CAP_NPOT_TEXTURES:
264bf215546Sopenharmony_ci	case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
265bf215546Sopenharmony_ci	case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
266bf215546Sopenharmony_ci	case PIPE_CAP_ANISOTROPIC_FILTER:
267bf215546Sopenharmony_ci	case PIPE_CAP_POINT_SPRITE:
268bf215546Sopenharmony_ci	case PIPE_CAP_OCCLUSION_QUERY:
269bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
270bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
271bf215546Sopenharmony_ci	case PIPE_CAP_BLEND_EQUATION_SEPARATE:
272bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_SWIZZLE:
273bf215546Sopenharmony_ci	case PIPE_CAP_DEPTH_CLIP_DISABLE:
274bf215546Sopenharmony_ci	case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
275bf215546Sopenharmony_ci	case PIPE_CAP_SHADER_STENCIL_EXPORT:
276bf215546Sopenharmony_ci	case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
277bf215546Sopenharmony_ci	case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
278bf215546Sopenharmony_ci	case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
279bf215546Sopenharmony_ci	case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
280bf215546Sopenharmony_ci	case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
281bf215546Sopenharmony_ci	case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
282bf215546Sopenharmony_ci	case PIPE_CAP_SEAMLESS_CUBE_MAP:
283bf215546Sopenharmony_ci	case PIPE_CAP_PRIMITIVE_RESTART:
284bf215546Sopenharmony_ci	case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
285bf215546Sopenharmony_ci	case PIPE_CAP_CONDITIONAL_RENDER:
286bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_BARRIER:
287bf215546Sopenharmony_ci	case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
288bf215546Sopenharmony_ci	case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
289bf215546Sopenharmony_ci	case PIPE_CAP_VS_INSTANCEID:
290bf215546Sopenharmony_ci	case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
291bf215546Sopenharmony_ci	case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
292bf215546Sopenharmony_ci	case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
293bf215546Sopenharmony_ci	case PIPE_CAP_START_INSTANCE:
294bf215546Sopenharmony_ci	case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
295bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
296bf215546Sopenharmony_ci	case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
297bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_MULTISAMPLE:
298bf215546Sopenharmony_ci	case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
299bf215546Sopenharmony_ci	case PIPE_CAP_VS_WINDOW_SPACE_POSITION:
300bf215546Sopenharmony_ci	case PIPE_CAP_VS_LAYER_VIEWPORT:
301bf215546Sopenharmony_ci	case PIPE_CAP_SAMPLE_SHADING:
302bf215546Sopenharmony_ci	case PIPE_CAP_CLIP_HALFZ:
303bf215546Sopenharmony_ci	case PIPE_CAP_POLYGON_OFFSET_CLAMP:
304bf215546Sopenharmony_ci	case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
305bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
306bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
307bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_QUERY_SAMPLES:
308bf215546Sopenharmony_ci	case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
309bf215546Sopenharmony_ci	case PIPE_CAP_INVALIDATE_BUFFER:
310bf215546Sopenharmony_ci	case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
311bf215546Sopenharmony_ci	case PIPE_CAP_QUERY_MEMORY_INFO:
312bf215546Sopenharmony_ci	case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
313bf215546Sopenharmony_ci	case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
314bf215546Sopenharmony_ci	case PIPE_CAP_CLEAR_TEXTURE:
315bf215546Sopenharmony_ci	case PIPE_CAP_LEGACY_MATH_RULES:
316bf215546Sopenharmony_ci	case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
317bf215546Sopenharmony_ci	case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
318bf215546Sopenharmony_ci	case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
319bf215546Sopenharmony_ci		return 1;
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci        case PIPE_CAP_NIR_ATOMICS_AS_DEREF:
322bf215546Sopenharmony_ci		return rscreen->b.debug_flags & DBG_NIR_PREFERRED;
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_TRANSFER_MODES:
325bf215546Sopenharmony_ci		return PIPE_TEXTURE_TRANSFER_BLIT;
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci	case PIPE_CAP_SHAREABLE_SHADERS:
328bf215546Sopenharmony_ci		return 0;
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
331bf215546Sopenharmony_ci		/* Optimal number for good TexSubImage performance on Polaris10. */
332bf215546Sopenharmony_ci		return 64 * 1024 * 1024;
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_ci	case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
335bf215546Sopenharmony_ci		return 1;
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci	case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
338bf215546Sopenharmony_ci		return !R600_BIG_ENDIAN && rscreen->b.info.has_userptr;
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_ci	case PIPE_CAP_COMPUTE:
341bf215546Sopenharmony_ci		return rscreen->b.gfx_level > R700;
342bf215546Sopenharmony_ci
343bf215546Sopenharmony_ci	case PIPE_CAP_TGSI_TEXCOORD:
344bf215546Sopenharmony_ci		return 1;
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci	case PIPE_CAP_NIR_IMAGES_AS_DEREF:
347bf215546Sopenharmony_ci	case PIPE_CAP_FAKE_SW_MSAA:
348bf215546Sopenharmony_ci		return 0;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
351bf215546Sopenharmony_ci		return MIN2(rscreen->b.info.max_heap_size_kb * 1024ull / 4, INT_MAX);
352bf215546Sopenharmony_ci
353bf215546Sopenharmony_ci        case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
354bf215546Sopenharmony_ci                return R600_MAP_BUFFER_ALIGNMENT;
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci	case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
357bf215546Sopenharmony_ci		return 256;
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
360bf215546Sopenharmony_ci		return 4;
361bf215546Sopenharmony_ci	case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
362bf215546Sopenharmony_ci		if (!is_nir_enabled(&rscreen->b))
363bf215546Sopenharmony_ci			return 140;
364bf215546Sopenharmony_ci		FALLTHROUGH;
365bf215546Sopenharmony_ci	case PIPE_CAP_GLSL_FEATURE_LEVEL:
366bf215546Sopenharmony_ci		if (family >= CHIP_CEDAR)
367bf215546Sopenharmony_ci		   return is_nir_enabled(&rscreen->b) ? 450 : 430;
368bf215546Sopenharmony_ci		return 330;
369bf215546Sopenharmony_ci
370bf215546Sopenharmony_ci	/* Supported except the original R600. */
371bf215546Sopenharmony_ci	case PIPE_CAP_INDEP_BLEND_ENABLE:
372bf215546Sopenharmony_ci	case PIPE_CAP_INDEP_BLEND_FUNC:
373bf215546Sopenharmony_ci		/* R600 doesn't support per-MRT blends */
374bf215546Sopenharmony_ci		return family == CHIP_R600 ? 0 : 1;
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ci	/* Supported on Evergreen. */
377bf215546Sopenharmony_ci	case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
378bf215546Sopenharmony_ci	case PIPE_CAP_CUBE_MAP_ARRAY:
379bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_GATHER_SM5:
380bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_QUERY_LOD:
381bf215546Sopenharmony_ci	case PIPE_CAP_FS_FINE_DERIVATIVE:
382bf215546Sopenharmony_ci	case PIPE_CAP_SAMPLER_VIEW_TARGET:
383bf215546Sopenharmony_ci	case PIPE_CAP_SHADER_PACK_HALF_FLOAT:
384bf215546Sopenharmony_ci	case PIPE_CAP_SHADER_CLOCK:
385bf215546Sopenharmony_ci	case PIPE_CAP_SHADER_ARRAY_COMPONENTS:
386bf215546Sopenharmony_ci	case PIPE_CAP_QUERY_BUFFER_OBJECT:
387bf215546Sopenharmony_ci	case PIPE_CAP_IMAGE_STORE_FORMATTED:
388bf215546Sopenharmony_ci		return family >= CHIP_CEDAR ? 1 : 0;
389bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
390bf215546Sopenharmony_ci		return family >= CHIP_CEDAR ? 4 : 0;
391bf215546Sopenharmony_ci	case PIPE_CAP_DRAW_INDIRECT:
392bf215546Sopenharmony_ci		/* kernel command checker support is also required */
393bf215546Sopenharmony_ci		return family >= CHIP_CEDAR;
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci	case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
396bf215546Sopenharmony_ci		return family >= CHIP_CEDAR ? 0 : 1;
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ci	case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
399bf215546Sopenharmony_ci		return 8;
400bf215546Sopenharmony_ci
401bf215546Sopenharmony_ci	case PIPE_CAP_MAX_GS_INVOCATIONS:
402bf215546Sopenharmony_ci		return 32;
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_ci	/* shader buffer objects */
405bf215546Sopenharmony_ci	case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
406bf215546Sopenharmony_ci		return 1 << 27;
407bf215546Sopenharmony_ci	case PIPE_CAP_MAX_COMBINED_SHADER_BUFFERS:
408bf215546Sopenharmony_ci		return 8;
409bf215546Sopenharmony_ci
410bf215546Sopenharmony_ci        case PIPE_CAP_INT64:
411bf215546Sopenharmony_ci	case PIPE_CAP_DOUBLES:
412bf215546Sopenharmony_ci		if (rscreen->b.family == CHIP_ARUBA ||
413bf215546Sopenharmony_ci		    rscreen->b.family == CHIP_CAYMAN ||
414bf215546Sopenharmony_ci		    rscreen->b.family == CHIP_CYPRESS ||
415bf215546Sopenharmony_ci		    rscreen->b.family == CHIP_HEMLOCK)
416bf215546Sopenharmony_ci			return 1;
417bf215546Sopenharmony_ci		if (is_nir_enabled(&rscreen->b) &&
418bf215546Sopenharmony_ci			rscreen->b.family >= CHIP_CEDAR)
419bf215546Sopenharmony_ci			return 1;
420bf215546Sopenharmony_ci		return 0;
421bf215546Sopenharmony_ci
422bf215546Sopenharmony_ci	case PIPE_CAP_TWO_SIDED_COLOR:
423bf215546Sopenharmony_ci		return !is_nir_enabled(&rscreen->b);
424bf215546Sopenharmony_ci	case PIPE_CAP_INT64_DIVMOD:
425bf215546Sopenharmony_ci		/* it is actually not supported, but the nir lowering handles this corectly wheras
426bf215546Sopenharmony_ci		 * the glsl lowering path seems to not initialize the buildins correctly.
427bf215546Sopenharmony_ci		 */
428bf215546Sopenharmony_ci		return is_nir_enabled(&rscreen->b);
429bf215546Sopenharmony_ci	case PIPE_CAP_CULL_DISTANCE:
430bf215546Sopenharmony_ci		return 1;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci	case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
433bf215546Sopenharmony_ci		if (family >= CHIP_CEDAR)
434bf215546Sopenharmony_ci			return 256;
435bf215546Sopenharmony_ci		return 0;
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_ci	case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
438bf215546Sopenharmony_ci		if (family >= CHIP_CEDAR)
439bf215546Sopenharmony_ci			return 30;
440bf215546Sopenharmony_ci		else
441bf215546Sopenharmony_ci			return 0;
442bf215546Sopenharmony_ci	/* Stream output. */
443bf215546Sopenharmony_ci	case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
444bf215546Sopenharmony_ci		return rscreen->b.has_streamout ? 4 : 0;
445bf215546Sopenharmony_ci	case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
446bf215546Sopenharmony_ci	case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
447bf215546Sopenharmony_ci		return rscreen->b.has_streamout ? 1 : 0;
448bf215546Sopenharmony_ci	case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
449bf215546Sopenharmony_ci	case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
450bf215546Sopenharmony_ci		return 32*4;
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_ci	/* Geometry shader output. */
453bf215546Sopenharmony_ci	case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
454bf215546Sopenharmony_ci		return 1024;
455bf215546Sopenharmony_ci	case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
456bf215546Sopenharmony_ci		return 16384;
457bf215546Sopenharmony_ci	case PIPE_CAP_MAX_VERTEX_STREAMS:
458bf215546Sopenharmony_ci		return family >= CHIP_CEDAR ? 4 : 1;
459bf215546Sopenharmony_ci
460bf215546Sopenharmony_ci	case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
461bf215546Sopenharmony_ci		/* Should be 2047, but 2048 is a requirement for GL 4.4 */
462bf215546Sopenharmony_ci		return 2048;
463bf215546Sopenharmony_ci
464bf215546Sopenharmony_ci	/* Texturing. */
465bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
466bf215546Sopenharmony_ci		if (family >= CHIP_CEDAR)
467bf215546Sopenharmony_ci			return 16384;
468bf215546Sopenharmony_ci		else
469bf215546Sopenharmony_ci			return 8192;
470bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
471bf215546Sopenharmony_ci		if (family >= CHIP_CEDAR)
472bf215546Sopenharmony_ci			return 15;
473bf215546Sopenharmony_ci		else
474bf215546Sopenharmony_ci			return 14;
475bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
476bf215546Sopenharmony_ci		/* textures support 8192, but layered rendering supports 2048 */
477bf215546Sopenharmony_ci		return 12;
478bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
479bf215546Sopenharmony_ci		/* textures support 8192, but layered rendering supports 2048 */
480bf215546Sopenharmony_ci		return 2048;
481bf215546Sopenharmony_ci
482bf215546Sopenharmony_ci	/* Render targets. */
483bf215546Sopenharmony_ci	case PIPE_CAP_MAX_RENDER_TARGETS:
484bf215546Sopenharmony_ci		/* XXX some r6xx are buggy and can only do 4 */
485bf215546Sopenharmony_ci		return 8;
486bf215546Sopenharmony_ci
487bf215546Sopenharmony_ci	case PIPE_CAP_MAX_VIEWPORTS:
488bf215546Sopenharmony_ci		return R600_MAX_VIEWPORTS;
489bf215546Sopenharmony_ci	case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
490bf215546Sopenharmony_ci	case PIPE_CAP_RASTERIZER_SUBPIXEL_BITS:
491bf215546Sopenharmony_ci		return 8;
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci	/* Timer queries, present when the clock frequency is non zero. */
494bf215546Sopenharmony_ci	case PIPE_CAP_QUERY_TIME_ELAPSED:
495bf215546Sopenharmony_ci	case PIPE_CAP_QUERY_TIMESTAMP:
496bf215546Sopenharmony_ci		return rscreen->b.info.clock_crystal_freq != 0;
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ci	case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
499bf215546Sopenharmony_ci	case PIPE_CAP_MIN_TEXEL_OFFSET:
500bf215546Sopenharmony_ci		return -8;
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
503bf215546Sopenharmony_ci	case PIPE_CAP_MAX_TEXEL_OFFSET:
504bf215546Sopenharmony_ci		return 7;
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_ci	case PIPE_CAP_MAX_VARYINGS:
507bf215546Sopenharmony_ci		return 32;
508bf215546Sopenharmony_ci
509bf215546Sopenharmony_ci	case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
510bf215546Sopenharmony_ci		return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600;
511bf215546Sopenharmony_ci	case PIPE_CAP_ENDIANNESS:
512bf215546Sopenharmony_ci		return PIPE_ENDIAN_LITTLE;
513bf215546Sopenharmony_ci
514bf215546Sopenharmony_ci	case PIPE_CAP_VENDOR_ID:
515bf215546Sopenharmony_ci		return ATI_VENDOR_ID;
516bf215546Sopenharmony_ci	case PIPE_CAP_DEVICE_ID:
517bf215546Sopenharmony_ci		return rscreen->b.info.pci_id;
518bf215546Sopenharmony_ci	case PIPE_CAP_ACCELERATED:
519bf215546Sopenharmony_ci		return 1;
520bf215546Sopenharmony_ci	case PIPE_CAP_VIDEO_MEMORY:
521bf215546Sopenharmony_ci		return rscreen->b.info.vram_size_kb >> 10;
522bf215546Sopenharmony_ci	case PIPE_CAP_UMA:
523bf215546Sopenharmony_ci		return 0;
524bf215546Sopenharmony_ci	case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
525bf215546Sopenharmony_ci		return rscreen->b.gfx_level >= R700;
526bf215546Sopenharmony_ci	case PIPE_CAP_PCI_GROUP:
527bf215546Sopenharmony_ci		return rscreen->b.info.pci_domain;
528bf215546Sopenharmony_ci	case PIPE_CAP_PCI_BUS:
529bf215546Sopenharmony_ci		return rscreen->b.info.pci_bus;
530bf215546Sopenharmony_ci	case PIPE_CAP_PCI_DEVICE:
531bf215546Sopenharmony_ci		return rscreen->b.info.pci_dev;
532bf215546Sopenharmony_ci	case PIPE_CAP_PCI_FUNCTION:
533bf215546Sopenharmony_ci		return rscreen->b.info.pci_func;
534bf215546Sopenharmony_ci
535bf215546Sopenharmony_ci	case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS:
536bf215546Sopenharmony_ci		if (rscreen->b.family >= CHIP_CEDAR && rscreen->has_atomics)
537bf215546Sopenharmony_ci			return 8;
538bf215546Sopenharmony_ci		return 0;
539bf215546Sopenharmony_ci	case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS:
540bf215546Sopenharmony_ci		if (rscreen->b.family >= CHIP_CEDAR && rscreen->has_atomics)
541bf215546Sopenharmony_ci			return EG_MAX_ATOMIC_BUFFERS;
542bf215546Sopenharmony_ci		return 0;
543bf215546Sopenharmony_ci
544bf215546Sopenharmony_ci	default:
545bf215546Sopenharmony_ci		return u_pipe_screen_get_param_defaults(pscreen, param);
546bf215546Sopenharmony_ci	}
547bf215546Sopenharmony_ci}
548bf215546Sopenharmony_ci
549bf215546Sopenharmony_cistatic int r600_get_shader_param(struct pipe_screen* pscreen,
550bf215546Sopenharmony_ci				 enum pipe_shader_type shader,
551bf215546Sopenharmony_ci				 enum pipe_shader_cap param)
552bf215546Sopenharmony_ci{
553bf215546Sopenharmony_ci	struct r600_screen *rscreen = (struct r600_screen *)pscreen;
554bf215546Sopenharmony_ci
555bf215546Sopenharmony_ci	switch(shader)
556bf215546Sopenharmony_ci	{
557bf215546Sopenharmony_ci	case PIPE_SHADER_FRAGMENT:
558bf215546Sopenharmony_ci	case PIPE_SHADER_VERTEX:
559bf215546Sopenharmony_ci		break;
560bf215546Sopenharmony_ci	case PIPE_SHADER_GEOMETRY:
561bf215546Sopenharmony_ci		break;
562bf215546Sopenharmony_ci	case PIPE_SHADER_TESS_CTRL:
563bf215546Sopenharmony_ci	case PIPE_SHADER_TESS_EVAL:
564bf215546Sopenharmony_ci	case PIPE_SHADER_COMPUTE:
565bf215546Sopenharmony_ci		if (rscreen->b.family >= CHIP_CEDAR)
566bf215546Sopenharmony_ci			break;
567bf215546Sopenharmony_ci		FALLTHROUGH;
568bf215546Sopenharmony_ci	default:
569bf215546Sopenharmony_ci		return 0;
570bf215546Sopenharmony_ci	}
571bf215546Sopenharmony_ci
572bf215546Sopenharmony_ci	switch (param) {
573bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
574bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
575bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
576bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
577bf215546Sopenharmony_ci		return 16384;
578bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
579bf215546Sopenharmony_ci		return 32;
580bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_INPUTS:
581bf215546Sopenharmony_ci		return shader == PIPE_SHADER_VERTEX ? 16 : 32;
582bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_OUTPUTS:
583bf215546Sopenharmony_ci		return shader == PIPE_SHADER_FRAGMENT ? 8 : 32;
584bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_TEMPS:
585bf215546Sopenharmony_ci		return 256; /* Max native temporaries. */
586bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
587bf215546Sopenharmony_ci		if (shader == PIPE_SHADER_COMPUTE) {
588bf215546Sopenharmony_ci			uint64_t max_const_buffer_size;
589bf215546Sopenharmony_ci			enum pipe_shader_ir ir_type = is_nir_enabled(&rscreen->b) ?
590bf215546Sopenharmony_ci				PIPE_SHADER_IR_NIR: PIPE_SHADER_IR_TGSI;
591bf215546Sopenharmony_ci			pscreen->get_compute_param(pscreen, ir_type,
592bf215546Sopenharmony_ci						   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
593bf215546Sopenharmony_ci						   &max_const_buffer_size);
594bf215546Sopenharmony_ci			return MIN2(max_const_buffer_size, INT_MAX);
595bf215546Sopenharmony_ci
596bf215546Sopenharmony_ci		} else {
597bf215546Sopenharmony_ci			return R600_MAX_CONST_BUFFER_SIZE;
598bf215546Sopenharmony_ci		}
599bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
600bf215546Sopenharmony_ci		return R600_MAX_USER_CONST_BUFFERS;
601bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_CONT_SUPPORTED:
602bf215546Sopenharmony_ci		return 1;
603bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
604bf215546Sopenharmony_ci		return 1;
605bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
606bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
607bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
608bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
609bf215546Sopenharmony_ci		return 1;
610bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_SUBROUTINES:
611bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_INT64_ATOMICS:
612bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_FP16:
613bf215546Sopenharmony_ci        case PIPE_SHADER_CAP_FP16_DERIVATIVES:
614bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
615bf215546Sopenharmony_ci        case PIPE_SHADER_CAP_INT16:
616bf215546Sopenharmony_ci        case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
617bf215546Sopenharmony_ci		return 0;
618bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_INTEGERS:
619bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
620bf215546Sopenharmony_ci		return 1;
621bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
622bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
623bf215546Sopenharmony_ci		return 16;
624bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_PREFERRED_IR:
625bf215546Sopenharmony_ci		if (rscreen->b.debug_flags & DBG_USE_TGSI)
626bf215546Sopenharmony_ci			return PIPE_SHADER_IR_TGSI;
627bf215546Sopenharmony_ci		return PIPE_SHADER_IR_NIR;
628bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_SUPPORTED_IRS: {
629bf215546Sopenharmony_ci		int ir = 0;
630bf215546Sopenharmony_ci		if (shader == PIPE_SHADER_COMPUTE)
631bf215546Sopenharmony_ci			ir = 1 << PIPE_SHADER_IR_NATIVE;
632bf215546Sopenharmony_ci		ir |= 1 << PIPE_SHADER_IR_TGSI;
633bf215546Sopenharmony_ci		if (is_nir_enabled(&rscreen->b)) {
634bf215546Sopenharmony_ci			ir |= 1 << PIPE_SHADER_IR_NIR;
635bf215546Sopenharmony_ci		}
636bf215546Sopenharmony_ci		return ir;
637bf215546Sopenharmony_ci	}
638bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_DROUND_SUPPORTED:
639bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
640bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
641bf215546Sopenharmony_ci		return 0;
642bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
643bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
644bf215546Sopenharmony_ci		if (rscreen->b.family >= CHIP_CEDAR &&
645bf215546Sopenharmony_ci		    (shader == PIPE_SHADER_FRAGMENT || shader == PIPE_SHADER_COMPUTE))
646bf215546Sopenharmony_ci		    return 8;
647bf215546Sopenharmony_ci		return 0;
648bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
649bf215546Sopenharmony_ci		if (rscreen->b.family >= CHIP_CEDAR && rscreen->has_atomics)
650bf215546Sopenharmony_ci			return 8;
651bf215546Sopenharmony_ci		return 0;
652bf215546Sopenharmony_ci	case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
653bf215546Sopenharmony_ci		/* having to allocate the atomics out amongst shaders stages is messy,
654bf215546Sopenharmony_ci		   so give compute 8 buffers and all the others one */
655bf215546Sopenharmony_ci		if (rscreen->b.family >= CHIP_CEDAR && rscreen->has_atomics) {
656bf215546Sopenharmony_ci			return EG_MAX_ATOMIC_BUFFERS;
657bf215546Sopenharmony_ci		}
658bf215546Sopenharmony_ci		return 0;
659bf215546Sopenharmony_ci	}
660bf215546Sopenharmony_ci	return 0;
661bf215546Sopenharmony_ci}
662bf215546Sopenharmony_ci
663bf215546Sopenharmony_cistatic void r600_destroy_screen(struct pipe_screen* pscreen)
664bf215546Sopenharmony_ci{
665bf215546Sopenharmony_ci	struct r600_screen *rscreen = (struct r600_screen *)pscreen;
666bf215546Sopenharmony_ci
667bf215546Sopenharmony_ci	if (!rscreen)
668bf215546Sopenharmony_ci		return;
669bf215546Sopenharmony_ci
670bf215546Sopenharmony_ci	if (!rscreen->b.ws->unref(rscreen->b.ws))
671bf215546Sopenharmony_ci		return;
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_ci	if (rscreen->global_pool) {
674bf215546Sopenharmony_ci		compute_memory_pool_delete(rscreen->global_pool);
675bf215546Sopenharmony_ci	}
676bf215546Sopenharmony_ci
677bf215546Sopenharmony_ci	r600_destroy_common_screen(&rscreen->b);
678bf215546Sopenharmony_ci}
679bf215546Sopenharmony_ci
680bf215546Sopenharmony_cistatic struct pipe_resource *r600_resource_create(struct pipe_screen *screen,
681bf215546Sopenharmony_ci						  const struct pipe_resource *templ)
682bf215546Sopenharmony_ci{
683bf215546Sopenharmony_ci	if (templ->target == PIPE_BUFFER &&
684bf215546Sopenharmony_ci	    (templ->bind & PIPE_BIND_GLOBAL))
685bf215546Sopenharmony_ci		return r600_compute_global_buffer_create(screen, templ);
686bf215546Sopenharmony_ci
687bf215546Sopenharmony_ci	return r600_resource_create_common(screen, templ);
688bf215546Sopenharmony_ci}
689bf215546Sopenharmony_ci
690bf215546Sopenharmony_cistruct pipe_screen *r600_screen_create(struct radeon_winsys *ws,
691bf215546Sopenharmony_ci				       const struct pipe_screen_config *config)
692bf215546Sopenharmony_ci{
693bf215546Sopenharmony_ci	struct r600_screen *rscreen = CALLOC_STRUCT(r600_screen);
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci	if (!rscreen) {
696bf215546Sopenharmony_ci		return NULL;
697bf215546Sopenharmony_ci	}
698bf215546Sopenharmony_ci
699bf215546Sopenharmony_ci	/* Set functions first. */
700bf215546Sopenharmony_ci	rscreen->b.b.context_create = r600_create_context;
701bf215546Sopenharmony_ci	rscreen->b.b.destroy = r600_destroy_screen;
702bf215546Sopenharmony_ci	rscreen->b.b.get_param = r600_get_param;
703bf215546Sopenharmony_ci	rscreen->b.b.get_shader_param = r600_get_shader_param;
704bf215546Sopenharmony_ci	rscreen->b.b.resource_create = r600_resource_create;
705bf215546Sopenharmony_ci
706bf215546Sopenharmony_ci	if (!r600_common_screen_init(&rscreen->b, ws)) {
707bf215546Sopenharmony_ci		FREE(rscreen);
708bf215546Sopenharmony_ci		return NULL;
709bf215546Sopenharmony_ci	}
710bf215546Sopenharmony_ci
711bf215546Sopenharmony_ci	if (rscreen->b.info.gfx_level >= EVERGREEN) {
712bf215546Sopenharmony_ci		rscreen->b.b.is_format_supported = evergreen_is_format_supported;
713bf215546Sopenharmony_ci	} else {
714bf215546Sopenharmony_ci		rscreen->b.b.is_format_supported = r600_is_format_supported;
715bf215546Sopenharmony_ci	}
716bf215546Sopenharmony_ci
717bf215546Sopenharmony_ci	rscreen->b.debug_flags |= debug_get_flags_option("R600_DEBUG", r600_debug_options, 0);
718bf215546Sopenharmony_ci	if (debug_get_bool_option("R600_DEBUG_COMPUTE", FALSE))
719bf215546Sopenharmony_ci		rscreen->b.debug_flags |= DBG_COMPUTE;
720bf215546Sopenharmony_ci	if (debug_get_bool_option("R600_DUMP_SHADERS", FALSE))
721bf215546Sopenharmony_ci		rscreen->b.debug_flags |= DBG_ALL_SHADERS | DBG_FS;
722bf215546Sopenharmony_ci	if (!debug_get_bool_option("R600_HYPERZ", TRUE))
723bf215546Sopenharmony_ci		rscreen->b.debug_flags |= DBG_NO_HYPERZ;
724bf215546Sopenharmony_ci
725bf215546Sopenharmony_ci	if (rscreen->b.family == CHIP_UNKNOWN) {
726bf215546Sopenharmony_ci		fprintf(stderr, "r600: Unknown chipset 0x%04X\n", rscreen->b.info.pci_id);
727bf215546Sopenharmony_ci		FREE(rscreen);
728bf215546Sopenharmony_ci		return NULL;
729bf215546Sopenharmony_ci	}
730bf215546Sopenharmony_ci
731bf215546Sopenharmony_ci	rscreen->b.has_streamout = true;
732bf215546Sopenharmony_ci
733bf215546Sopenharmony_ci	rscreen->has_msaa = true;
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_ci	/* MSAA support. */
736bf215546Sopenharmony_ci	switch (rscreen->b.gfx_level) {
737bf215546Sopenharmony_ci	case R600:
738bf215546Sopenharmony_ci	case R700:
739bf215546Sopenharmony_ci		rscreen->has_compressed_msaa_texturing = false;
740bf215546Sopenharmony_ci		break;
741bf215546Sopenharmony_ci	case EVERGREEN:
742bf215546Sopenharmony_ci		rscreen->has_compressed_msaa_texturing = true;
743bf215546Sopenharmony_ci		break;
744bf215546Sopenharmony_ci	case CAYMAN:
745bf215546Sopenharmony_ci		rscreen->has_compressed_msaa_texturing = true;
746bf215546Sopenharmony_ci		break;
747bf215546Sopenharmony_ci	default:
748bf215546Sopenharmony_ci		rscreen->has_compressed_msaa_texturing = false;
749bf215546Sopenharmony_ci	}
750bf215546Sopenharmony_ci
751bf215546Sopenharmony_ci	rscreen->b.has_cp_dma = !(rscreen->b.debug_flags & DBG_NO_CP_DMA);
752bf215546Sopenharmony_ci
753bf215546Sopenharmony_ci	rscreen->b.barrier_flags.cp_to_L2 =
754bf215546Sopenharmony_ci		R600_CONTEXT_INV_VERTEX_CACHE |
755bf215546Sopenharmony_ci		R600_CONTEXT_INV_TEX_CACHE |
756bf215546Sopenharmony_ci		R600_CONTEXT_INV_CONST_CACHE;
757bf215546Sopenharmony_ci	rscreen->b.barrier_flags.compute_to_L2 = R600_CONTEXT_CS_PARTIAL_FLUSH | R600_CONTEXT_FLUSH_AND_INV;
758bf215546Sopenharmony_ci
759bf215546Sopenharmony_ci	rscreen->global_pool = compute_memory_pool_new(rscreen);
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_ci	/* Create the auxiliary context. This must be done last. */
762bf215546Sopenharmony_ci	rscreen->b.aux_context = rscreen->b.b.context_create(&rscreen->b.b, NULL, 0);
763bf215546Sopenharmony_ci
764bf215546Sopenharmony_ci	rscreen->has_atomics = true;
765bf215546Sopenharmony_ci#if 0 /* This is for testing whether aux_context and buffer clearing work correctly. */
766bf215546Sopenharmony_ci	struct pipe_resource templ = {};
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci	templ.width0 = 4;
769bf215546Sopenharmony_ci	templ.height0 = 2048;
770bf215546Sopenharmony_ci	templ.depth0 = 1;
771bf215546Sopenharmony_ci	templ.array_size = 1;
772bf215546Sopenharmony_ci	templ.target = PIPE_TEXTURE_2D;
773bf215546Sopenharmony_ci	templ.format = PIPE_FORMAT_R8G8B8A8_UNORM;
774bf215546Sopenharmony_ci	templ.usage = PIPE_USAGE_DEFAULT;
775bf215546Sopenharmony_ci
776bf215546Sopenharmony_ci	struct r600_resource *res = r600_resource(rscreen->screen.resource_create(&rscreen->screen, &templ));
777bf215546Sopenharmony_ci	unsigned char *map = ws->buffer_map(res->buf, NULL, PIPE_MAP_WRITE);
778bf215546Sopenharmony_ci
779bf215546Sopenharmony_ci	memset(map, 0, 256);
780bf215546Sopenharmony_ci
781bf215546Sopenharmony_ci	r600_screen_clear_buffer(rscreen, &res->b.b, 4, 4, 0xCC);
782bf215546Sopenharmony_ci	r600_screen_clear_buffer(rscreen, &res->b.b, 8, 4, 0xDD);
783bf215546Sopenharmony_ci	r600_screen_clear_buffer(rscreen, &res->b.b, 12, 4, 0xEE);
784bf215546Sopenharmony_ci	r600_screen_clear_buffer(rscreen, &res->b.b, 20, 4, 0xFF);
785bf215546Sopenharmony_ci	r600_screen_clear_buffer(rscreen, &res->b.b, 32, 20, 0x87);
786bf215546Sopenharmony_ci
787bf215546Sopenharmony_ci	ws->buffer_wait(res->buf, RADEON_USAGE_WRITE);
788bf215546Sopenharmony_ci
789bf215546Sopenharmony_ci	int i;
790bf215546Sopenharmony_ci	for (i = 0; i < 256; i++) {
791bf215546Sopenharmony_ci		printf("%02X", map[i]);
792bf215546Sopenharmony_ci		if (i % 16 == 15)
793bf215546Sopenharmony_ci			printf("\n");
794bf215546Sopenharmony_ci	}
795bf215546Sopenharmony_ci#endif
796bf215546Sopenharmony_ci
797bf215546Sopenharmony_ci	if (rscreen->b.debug_flags & DBG_TEST_DMA)
798bf215546Sopenharmony_ci		r600_test_dma(&rscreen->b);
799bf215546Sopenharmony_ci
800bf215546Sopenharmony_ci	r600_query_fix_enabled_rb_mask(&rscreen->b);
801bf215546Sopenharmony_ci	return &rscreen->b.b;
802bf215546Sopenharmony_ci}
803