radeonsi: don't call VBO prefetch with size=0
[mesa.git] / src / gallium / drivers / radeonsi / si_get.c
1 /*
2 * Copyright 2017 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "si_pipe.h"
26 #include "radeon/radeon_video.h"
27 #include "radeon/radeon_vce.h"
28 #include "radeon/radeon_uvd_enc.h"
29 #include "ac_llvm_util.h"
30 #include "vl/vl_decoder.h"
31 #include "vl/vl_video_buffer.h"
32 #include "util/u_screen.h"
33 #include "util/u_video.h"
34 #include "compiler/nir/nir.h"
35
36 #include <sys/utsname.h>
37
38 static const char *si_get_vendor(struct pipe_screen *pscreen)
39 {
40 /* Don't change this. Games such as Alien Isolation are broken if this
41 * returns "Advanced Micro Devices, Inc."
42 */
43 return "X.Org";
44 }
45
46 static const char *si_get_device_vendor(struct pipe_screen *pscreen)
47 {
48 return "AMD";
49 }
50
51 static const char *si_get_marketing_name(struct radeon_winsys *ws)
52 {
53 if (!ws->get_chip_name)
54 return NULL;
55 return ws->get_chip_name(ws);
56 }
57
58 static int si_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
59 {
60 struct si_screen *sscreen = (struct si_screen *)pscreen;
61
62 switch (param) {
63 /* Supported features (boolean caps). */
64 case PIPE_CAP_ACCELERATED:
65 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
66 case PIPE_CAP_ANISOTROPIC_FILTER:
67 case PIPE_CAP_POINT_SPRITE:
68 case PIPE_CAP_OCCLUSION_QUERY:
69 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
70 case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
71 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
72 case PIPE_CAP_TEXTURE_SWIZZLE:
73 case PIPE_CAP_DEPTH_CLIP_DISABLE:
74 case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
75 case PIPE_CAP_SHADER_STENCIL_EXPORT:
76 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
77 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
78 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
79 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
80 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
81 case PIPE_CAP_SM3:
82 case PIPE_CAP_SEAMLESS_CUBE_MAP:
83 case PIPE_CAP_PRIMITIVE_RESTART:
84 case PIPE_CAP_CONDITIONAL_RENDER:
85 case PIPE_CAP_TEXTURE_BARRIER:
86 case PIPE_CAP_INDEP_BLEND_ENABLE:
87 case PIPE_CAP_INDEP_BLEND_FUNC:
88 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
89 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
90 case PIPE_CAP_START_INSTANCE:
91 case PIPE_CAP_NPOT_TEXTURES:
92 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
93 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
94 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
95 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
96 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
97 case PIPE_CAP_TGSI_INSTANCEID:
98 case PIPE_CAP_COMPUTE:
99 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
100 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
101 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
102 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
103 case PIPE_CAP_CUBE_MAP_ARRAY:
104 case PIPE_CAP_SAMPLE_SHADING:
105 case PIPE_CAP_DRAW_INDIRECT:
106 case PIPE_CAP_CLIP_HALFZ:
107 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
108 case PIPE_CAP_POLYGON_OFFSET_CLAMP:
109 case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
110 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
111 case PIPE_CAP_TGSI_TEXCOORD:
112 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
113 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
114 case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
115 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
116 case PIPE_CAP_SHAREABLE_SHADERS:
117 case PIPE_CAP_DEPTH_BOUNDS_TEST:
118 case PIPE_CAP_SAMPLER_VIEW_TARGET:
119 case PIPE_CAP_TEXTURE_QUERY_LOD:
120 case PIPE_CAP_TEXTURE_GATHER_SM5:
121 case PIPE_CAP_TGSI_TXQS:
122 case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
123 case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
124 case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
125 case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
126 case PIPE_CAP_INVALIDATE_BUFFER:
127 case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
128 case PIPE_CAP_QUERY_BUFFER_OBJECT:
129 case PIPE_CAP_QUERY_MEMORY_INFO:
130 case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
131 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
132 case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
133 case PIPE_CAP_GENERATE_MIPMAP:
134 case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
135 case PIPE_CAP_STRING_MARKER:
136 case PIPE_CAP_CLEAR_TEXTURE:
137 case PIPE_CAP_CULL_DISTANCE:
138 case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
139 case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
140 case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
141 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
142 case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
143 case PIPE_CAP_DOUBLES:
144 case PIPE_CAP_TGSI_TEX_TXF_LZ:
145 case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
146 case PIPE_CAP_BINDLESS_TEXTURE:
147 case PIPE_CAP_QUERY_TIMESTAMP:
148 case PIPE_CAP_QUERY_TIME_ELAPSED:
149 case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
150 case PIPE_CAP_QUERY_SO_OVERFLOW:
151 case PIPE_CAP_MEMOBJ:
152 case PIPE_CAP_LOAD_CONSTBUF:
153 case PIPE_CAP_INT64:
154 case PIPE_CAP_INT64_DIVMOD:
155 case PIPE_CAP_TGSI_CLOCK:
156 case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
157 case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
158 case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
159 case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
160 case PIPE_CAP_TGSI_BALLOT:
161 case PIPE_CAP_TGSI_VOTE:
162 case PIPE_CAP_TGSI_FS_FBFETCH:
163 return 1;
164
165 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
166 return !SI_BIG_ENDIAN && sscreen->info.has_userptr;
167
168 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
169 return sscreen->info.has_gpu_reset_status_query ||
170 sscreen->info.has_gpu_reset_counter_query;
171
172 case PIPE_CAP_TEXTURE_MULTISAMPLE:
173 return sscreen->info.has_2d_tiling;
174
175 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
176 return SI_MAP_BUFFER_ALIGNMENT;
177
178 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
179 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
180 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
181 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
182 case PIPE_CAP_MAX_VERTEX_STREAMS:
183 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
184 case PIPE_CAP_MAX_WINDOW_RECTANGLES:
185 return 4;
186
187 case PIPE_CAP_GLSL_FEATURE_LEVEL:
188 case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
189 if (sscreen->info.has_indirect_compute_dispatch)
190 return 450;
191 return 420;
192
193 case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
194 /* Optimal number for good TexSubImage performance on Polaris10. */
195 return 64 * 1024 * 1024;
196
197 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
198 case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
199 return MIN2(sscreen->info.max_alloc_size, INT_MAX);
200
201 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
202 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
203 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
204 return !sscreen->info.has_unaligned_shader_loads;
205
206 case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
207 return sscreen->info.has_sparse_vm_mappings ?
208 RADEON_SPARSE_PAGE_SIZE : 0;
209
210 case PIPE_CAP_PACKED_UNIFORMS:
211 if (sscreen->debug_flags & DBG(NIR))
212 return 1;
213 return 0;
214
215 /* Unsupported features. */
216 case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
217 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
218 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
219 case PIPE_CAP_USER_VERTEX_BUFFERS:
220 case PIPE_CAP_FAKE_SW_MSAA:
221 case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
222 case PIPE_CAP_VERTEXID_NOBASE:
223 case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
224 case PIPE_CAP_TGSI_MUL_ZERO_WINS:
225 case PIPE_CAP_UMA:
226 case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
227 case PIPE_CAP_POST_DEPTH_COVERAGE:
228 case PIPE_CAP_TILE_RASTER_ORDER:
229 case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
230 case PIPE_CAP_CONTEXT_PRIORITY_MASK:
231 case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
232 case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
233 case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
234 case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
235 case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
236 case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
237 case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
238 return 0;
239
240 case PIPE_CAP_FENCE_SIGNAL:
241 return sscreen->info.has_syncobj;
242
243 case PIPE_CAP_CONSTBUF0_FLAGS:
244 return SI_RESOURCE_FLAG_32BIT;
245
246 case PIPE_CAP_NATIVE_FENCE_FD:
247 return sscreen->info.has_fence_to_handle;
248
249 case PIPE_CAP_DRAW_PARAMETERS:
250 case PIPE_CAP_MULTI_DRAW_INDIRECT:
251 case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
252 return sscreen->has_draw_indirect_multi;
253
254 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
255 return 30;
256
257 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
258 return sscreen->info.chip_class <= VI ?
259 PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600 : 0;
260
261 /* Stream output. */
262 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
263 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
264 return 32*4;
265
266 /* Geometry shader output. */
267 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
268 return 1024;
269 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
270 return 4095;
271 case PIPE_CAP_MAX_GS_INVOCATIONS:
272 /* The closed driver exposes 127, but 125 is the greatest
273 * number that works. */
274 return 125;
275
276 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
277 return 2048;
278
279 /* Texturing. */
280 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
281 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
282 return 15; /* 16384 */
283 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
284 /* textures support 8192, but layered rendering supports 2048 */
285 return 12;
286 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
287 /* textures support 8192, but layered rendering supports 2048 */
288 return 2048;
289
290 /* Viewports and render targets. */
291 case PIPE_CAP_MAX_VIEWPORTS:
292 return SI_MAX_VIEWPORTS;
293 case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
294 case PIPE_CAP_RASTERIZER_SUBPIXEL_BITS:
295 case PIPE_CAP_MAX_RENDER_TARGETS:
296 return 8;
297 case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
298 return sscreen->info.has_eqaa_surface_allocator ? 2 : 0;
299
300 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
301 case PIPE_CAP_MIN_TEXEL_OFFSET:
302 return -32;
303
304 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
305 case PIPE_CAP_MAX_TEXEL_OFFSET:
306 return 31;
307
308 case PIPE_CAP_ENDIANNESS:
309 return PIPE_ENDIAN_LITTLE;
310
311 case PIPE_CAP_VENDOR_ID:
312 return ATI_VENDOR_ID;
313 case PIPE_CAP_DEVICE_ID:
314 return sscreen->info.pci_id;
315 case PIPE_CAP_VIDEO_MEMORY:
316 return sscreen->info.vram_size >> 20;
317 case PIPE_CAP_PCI_GROUP:
318 return sscreen->info.pci_domain;
319 case PIPE_CAP_PCI_BUS:
320 return sscreen->info.pci_bus;
321 case PIPE_CAP_PCI_DEVICE:
322 return sscreen->info.pci_dev;
323 case PIPE_CAP_PCI_FUNCTION:
324 return sscreen->info.pci_func;
325
326 default:
327 return u_pipe_screen_get_param_defaults(pscreen, param);
328 }
329 }
330
331 static float si_get_paramf(struct pipe_screen* pscreen, enum pipe_capf param)
332 {
333 switch (param) {
334 case PIPE_CAPF_MAX_LINE_WIDTH:
335 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
336 case PIPE_CAPF_MAX_POINT_WIDTH:
337 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
338 return 8192.0f;
339 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
340 return 16.0f;
341 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
342 return 16.0f;
343 case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
344 case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
345 case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
346 return 0.0f;
347 }
348 return 0.0f;
349 }
350
351 static int si_get_shader_param(struct pipe_screen* pscreen,
352 enum pipe_shader_type shader,
353 enum pipe_shader_cap param)
354 {
355 struct si_screen *sscreen = (struct si_screen *)pscreen;
356
357 switch(shader)
358 {
359 case PIPE_SHADER_FRAGMENT:
360 case PIPE_SHADER_VERTEX:
361 case PIPE_SHADER_GEOMETRY:
362 case PIPE_SHADER_TESS_CTRL:
363 case PIPE_SHADER_TESS_EVAL:
364 break;
365 case PIPE_SHADER_COMPUTE:
366 switch (param) {
367 case PIPE_SHADER_CAP_SUPPORTED_IRS: {
368 int ir = 1 << PIPE_SHADER_IR_NATIVE;
369
370 if (sscreen->info.has_indirect_compute_dispatch)
371 ir |= 1 << PIPE_SHADER_IR_TGSI;
372
373 return ir;
374 }
375
376 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE: {
377 uint64_t max_const_buffer_size;
378 pscreen->get_compute_param(pscreen, PIPE_SHADER_IR_TGSI,
379 PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
380 &max_const_buffer_size);
381 return MIN2(max_const_buffer_size, INT_MAX);
382 }
383 default:
384 /* If compute shaders don't require a special value
385 * for this cap, we can return the same value we
386 * do for other shader types. */
387 break;
388 }
389 break;
390 default:
391 return 0;
392 }
393
394 switch (param) {
395 /* Shader limits. */
396 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
397 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
398 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
399 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
400 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
401 return 16384;
402 case PIPE_SHADER_CAP_MAX_INPUTS:
403 return shader == PIPE_SHADER_VERTEX ? SI_MAX_ATTRIBS : 32;
404 case PIPE_SHADER_CAP_MAX_OUTPUTS:
405 return shader == PIPE_SHADER_FRAGMENT ? 8 : 32;
406 case PIPE_SHADER_CAP_MAX_TEMPS:
407 return 256; /* Max native temporaries. */
408 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
409 return MIN2(sscreen->info.max_alloc_size, INT_MAX - 3); /* aligned to 4 */
410 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
411 return SI_NUM_CONST_BUFFERS;
412 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
413 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
414 return SI_NUM_SAMPLERS;
415 case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
416 return SI_NUM_SHADER_BUFFERS;
417 case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
418 return SI_NUM_IMAGES;
419 case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
420 if (sscreen->debug_flags & DBG(NIR))
421 return 0;
422 return 32;
423 case PIPE_SHADER_CAP_PREFERRED_IR:
424 if (sscreen->debug_flags & DBG(NIR))
425 return PIPE_SHADER_IR_NIR;
426 return PIPE_SHADER_IR_TGSI;
427 case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
428 return 4;
429
430 /* Supported boolean features. */
431 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
432 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
433 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
434 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
435 case PIPE_SHADER_CAP_INTEGERS:
436 case PIPE_SHADER_CAP_INT64_ATOMICS:
437 case PIPE_SHADER_CAP_FP16:
438 case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
439 case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
440 case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
441 case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
442 case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
443 case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
444 return 1;
445
446 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
447 /* TODO: Indirect indexing of GS inputs is unimplemented. */
448 if (shader == PIPE_SHADER_GEOMETRY)
449 return 0;
450
451 if (shader == PIPE_SHADER_VERTEX &&
452 !sscreen->llvm_has_working_vgpr_indexing)
453 return 0;
454
455 /* Doing indirect indexing on GFX9 with LLVM 6.0 hangs.
456 * This means we don't support INTERP instructions with
457 * indirect indexing on inputs.
458 */
459 if (shader == PIPE_SHADER_FRAGMENT &&
460 !sscreen->llvm_has_working_vgpr_indexing &&
461 HAVE_LLVM < 0x0700)
462 return 0;
463
464 /* TCS and TES load inputs directly from LDS or offchip
465 * memory, so indirect indexing is always supported.
466 * PS has to support indirect indexing, because we can't
467 * lower that to TEMPs for INTERP instructions.
468 */
469 return 1;
470
471 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
472 return sscreen->llvm_has_working_vgpr_indexing ||
473 /* TCS stores outputs directly to memory. */
474 shader == PIPE_SHADER_TESS_CTRL;
475
476 /* Unsupported boolean features. */
477 case PIPE_SHADER_CAP_SUBROUTINES:
478 case PIPE_SHADER_CAP_SUPPORTED_IRS:
479 case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
480 case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
481 return 0;
482 case PIPE_SHADER_CAP_SCALAR_ISA:
483 return 1;
484 }
485 return 0;
486 }
487
488 static const struct nir_shader_compiler_options nir_options = {
489 .lower_scmp = true,
490 .lower_flrp32 = true,
491 .lower_flrp64 = true,
492 .lower_fpow = true,
493 .lower_fsat = true,
494 .lower_fdiv = true,
495 .lower_sub = true,
496 .lower_ffma = true,
497 .lower_pack_snorm_2x16 = true,
498 .lower_pack_snorm_4x8 = true,
499 .lower_pack_unorm_2x16 = true,
500 .lower_pack_unorm_4x8 = true,
501 .lower_unpack_snorm_2x16 = true,
502 .lower_unpack_snorm_4x8 = true,
503 .lower_unpack_unorm_2x16 = true,
504 .lower_unpack_unorm_4x8 = true,
505 .lower_extract_byte = true,
506 .lower_extract_word = true,
507 .max_unroll_iterations = 32,
508 .native_integers = true,
509 };
510
511 static const void *
512 si_get_compiler_options(struct pipe_screen *screen,
513 enum pipe_shader_ir ir,
514 enum pipe_shader_type shader)
515 {
516 assert(ir == PIPE_SHADER_IR_NIR);
517 return &nir_options;
518 }
519
520 static void si_get_driver_uuid(struct pipe_screen *pscreen, char *uuid)
521 {
522 ac_compute_driver_uuid(uuid, PIPE_UUID_SIZE);
523 }
524
525 static void si_get_device_uuid(struct pipe_screen *pscreen, char *uuid)
526 {
527 struct si_screen *sscreen = (struct si_screen *)pscreen;
528
529 ac_compute_device_uuid(&sscreen->info, uuid, PIPE_UUID_SIZE);
530 }
531
532 static const char* si_get_name(struct pipe_screen *pscreen)
533 {
534 struct si_screen *sscreen = (struct si_screen*)pscreen;
535
536 return sscreen->renderer_string;
537 }
538
539 static int si_get_video_param_no_decode(struct pipe_screen *screen,
540 enum pipe_video_profile profile,
541 enum pipe_video_entrypoint entrypoint,
542 enum pipe_video_cap param)
543 {
544 switch (param) {
545 case PIPE_VIDEO_CAP_SUPPORTED:
546 return vl_profile_supported(screen, profile, entrypoint);
547 case PIPE_VIDEO_CAP_NPOT_TEXTURES:
548 return 1;
549 case PIPE_VIDEO_CAP_MAX_WIDTH:
550 case PIPE_VIDEO_CAP_MAX_HEIGHT:
551 return vl_video_buffer_max_size(screen);
552 case PIPE_VIDEO_CAP_PREFERED_FORMAT:
553 return PIPE_FORMAT_NV12;
554 case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
555 return false;
556 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:
557 return false;
558 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:
559 return true;
560 case PIPE_VIDEO_CAP_MAX_LEVEL:
561 return vl_level_supported(screen, profile);
562 default:
563 return 0;
564 }
565 }
566
567 static int si_get_video_param(struct pipe_screen *screen,
568 enum pipe_video_profile profile,
569 enum pipe_video_entrypoint entrypoint,
570 enum pipe_video_cap param)
571 {
572 struct si_screen *sscreen = (struct si_screen *)screen;
573 enum pipe_video_format codec = u_reduce_video_profile(profile);
574
575 if (entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) {
576 switch (param) {
577 case PIPE_VIDEO_CAP_SUPPORTED:
578 return (codec == PIPE_VIDEO_FORMAT_MPEG4_AVC &&
579 (si_vce_is_fw_version_supported(sscreen) ||
580 sscreen->info.family == CHIP_RAVEN)) ||
581 (profile == PIPE_VIDEO_PROFILE_HEVC_MAIN &&
582 (sscreen->info.family == CHIP_RAVEN ||
583 si_radeon_uvd_enc_supported(sscreen)));
584 case PIPE_VIDEO_CAP_NPOT_TEXTURES:
585 return 1;
586 case PIPE_VIDEO_CAP_MAX_WIDTH:
587 return (sscreen->info.family < CHIP_TONGA) ? 2048 : 4096;
588 case PIPE_VIDEO_CAP_MAX_HEIGHT:
589 return (sscreen->info.family < CHIP_TONGA) ? 1152 : 2304;
590 case PIPE_VIDEO_CAP_PREFERED_FORMAT:
591 return PIPE_FORMAT_NV12;
592 case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
593 return false;
594 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:
595 return false;
596 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:
597 return true;
598 case PIPE_VIDEO_CAP_STACKED_FRAMES:
599 return (sscreen->info.family < CHIP_TONGA) ? 1 : 2;
600 default:
601 return 0;
602 }
603 }
604
605 switch (param) {
606 case PIPE_VIDEO_CAP_SUPPORTED:
607 switch (codec) {
608 case PIPE_VIDEO_FORMAT_MPEG12:
609 return profile != PIPE_VIDEO_PROFILE_MPEG1;
610 case PIPE_VIDEO_FORMAT_MPEG4:
611 return 1;
612 case PIPE_VIDEO_FORMAT_MPEG4_AVC:
613 if ((sscreen->info.family == CHIP_POLARIS10 ||
614 sscreen->info.family == CHIP_POLARIS11) &&
615 sscreen->info.uvd_fw_version < UVD_FW_1_66_16 ) {
616 RVID_ERR("POLARIS10/11 firmware version need to be updated.\n");
617 return false;
618 }
619 return true;
620 case PIPE_VIDEO_FORMAT_VC1:
621 return true;
622 case PIPE_VIDEO_FORMAT_HEVC:
623 /* Carrizo only supports HEVC Main */
624 if (sscreen->info.family >= CHIP_STONEY)
625 return (profile == PIPE_VIDEO_PROFILE_HEVC_MAIN ||
626 profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10);
627 else if (sscreen->info.family >= CHIP_CARRIZO)
628 return profile == PIPE_VIDEO_PROFILE_HEVC_MAIN;
629 return false;
630 case PIPE_VIDEO_FORMAT_JPEG:
631 if (sscreen->info.family < CHIP_CARRIZO || sscreen->info.family >= CHIP_VEGA10)
632 return false;
633 if (!(sscreen->info.drm_major == 3 && sscreen->info.drm_minor >= 19)) {
634 RVID_ERR("No MJPEG support for the kernel version\n");
635 return false;
636 }
637 return true;
638 case PIPE_VIDEO_FORMAT_VP9:
639 if (sscreen->info.family < CHIP_RAVEN)
640 return false;
641 return true;
642 default:
643 return false;
644 }
645 case PIPE_VIDEO_CAP_NPOT_TEXTURES:
646 return 1;
647 case PIPE_VIDEO_CAP_MAX_WIDTH:
648 return (sscreen->info.family < CHIP_TONGA) ? 2048 : 4096;
649 case PIPE_VIDEO_CAP_MAX_HEIGHT:
650 return (sscreen->info.family < CHIP_TONGA) ? 1152 : 4096;
651 case PIPE_VIDEO_CAP_PREFERED_FORMAT:
652 if (profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10 ||
653 profile == PIPE_VIDEO_PROFILE_VP9_PROFILE2)
654 return PIPE_FORMAT_P016;
655 else
656 return PIPE_FORMAT_NV12;
657
658 case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
659 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED: {
660 enum pipe_video_format format = u_reduce_video_profile(profile);
661
662 if (format == PIPE_VIDEO_FORMAT_HEVC)
663 return false; //The firmware doesn't support interlaced HEVC.
664 else if (format == PIPE_VIDEO_FORMAT_JPEG)
665 return false;
666 else if (format == PIPE_VIDEO_FORMAT_VP9)
667 return false;
668 return true;
669 }
670 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:
671 return true;
672 case PIPE_VIDEO_CAP_MAX_LEVEL:
673 switch (profile) {
674 case PIPE_VIDEO_PROFILE_MPEG1:
675 return 0;
676 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
677 case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
678 return 3;
679 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
680 return 3;
681 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
682 return 5;
683 case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
684 return 1;
685 case PIPE_VIDEO_PROFILE_VC1_MAIN:
686 return 2;
687 case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
688 return 4;
689 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
690 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
691 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
692 return (sscreen->info.family < CHIP_TONGA) ? 41 : 52;
693 case PIPE_VIDEO_PROFILE_HEVC_MAIN:
694 case PIPE_VIDEO_PROFILE_HEVC_MAIN_10:
695 return 186;
696 default:
697 return 0;
698 }
699 default:
700 return 0;
701 }
702 }
703
704 static boolean si_vid_is_format_supported(struct pipe_screen *screen,
705 enum pipe_format format,
706 enum pipe_video_profile profile,
707 enum pipe_video_entrypoint entrypoint)
708 {
709 /* HEVC 10 bit decoding should use P016 instead of NV12 if possible */
710 if (profile == PIPE_VIDEO_PROFILE_HEVC_MAIN_10)
711 return (format == PIPE_FORMAT_NV12) ||
712 (format == PIPE_FORMAT_P016);
713
714 /* we can only handle this one with UVD */
715 if (profile != PIPE_VIDEO_PROFILE_UNKNOWN)
716 return format == PIPE_FORMAT_NV12;
717
718 return vl_video_buffer_is_format_supported(screen, format, profile, entrypoint);
719 }
720
721 static unsigned get_max_threads_per_block(struct si_screen *screen,
722 enum pipe_shader_ir ir_type)
723 {
724 if (ir_type == PIPE_SHADER_IR_NATIVE)
725 return 256;
726
727 /* Only 16 waves per thread-group on gfx9. */
728 if (screen->info.chip_class >= GFX9)
729 return 1024;
730
731 /* Up to 40 waves per thread-group on GCN < gfx9. Expose a nice
732 * round number.
733 */
734 return 2048;
735 }
736
737 static int si_get_compute_param(struct pipe_screen *screen,
738 enum pipe_shader_ir ir_type,
739 enum pipe_compute_cap param,
740 void *ret)
741 {
742 struct si_screen *sscreen = (struct si_screen *)screen;
743
744 //TODO: select these params by asic
745 switch (param) {
746 case PIPE_COMPUTE_CAP_IR_TARGET: {
747 const char *gpu, *triple;
748
749 triple = "amdgcn-mesa-mesa3d";
750 gpu = ac_get_llvm_processor_name(sscreen->info.family);
751 if (ret) {
752 sprintf(ret, "%s-%s", gpu, triple);
753 }
754 /* +2 for dash and terminating NIL byte */
755 return (strlen(triple) + strlen(gpu) + 2) * sizeof(char);
756 }
757 case PIPE_COMPUTE_CAP_GRID_DIMENSION:
758 if (ret) {
759 uint64_t *grid_dimension = ret;
760 grid_dimension[0] = 3;
761 }
762 return 1 * sizeof(uint64_t);
763
764 case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
765 if (ret) {
766 uint64_t *grid_size = ret;
767 grid_size[0] = 65535;
768 grid_size[1] = 65535;
769 grid_size[2] = 65535;
770 }
771 return 3 * sizeof(uint64_t) ;
772
773 case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
774 if (ret) {
775 uint64_t *block_size = ret;
776 unsigned threads_per_block = get_max_threads_per_block(sscreen, ir_type);
777 block_size[0] = threads_per_block;
778 block_size[1] = threads_per_block;
779 block_size[2] = threads_per_block;
780 }
781 return 3 * sizeof(uint64_t);
782
783 case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
784 if (ret) {
785 uint64_t *max_threads_per_block = ret;
786 *max_threads_per_block = get_max_threads_per_block(sscreen, ir_type);
787 }
788 return sizeof(uint64_t);
789 case PIPE_COMPUTE_CAP_ADDRESS_BITS:
790 if (ret) {
791 uint32_t *address_bits = ret;
792 address_bits[0] = 64;
793 }
794 return 1 * sizeof(uint32_t);
795
796 case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
797 if (ret) {
798 uint64_t *max_global_size = ret;
799 uint64_t max_mem_alloc_size;
800
801 si_get_compute_param(screen, ir_type,
802 PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
803 &max_mem_alloc_size);
804
805 /* In OpenCL, the MAX_MEM_ALLOC_SIZE must be at least
806 * 1/4 of the MAX_GLOBAL_SIZE. Since the
807 * MAX_MEM_ALLOC_SIZE is fixed for older kernels,
808 * make sure we never report more than
809 * 4 * MAX_MEM_ALLOC_SIZE.
810 */
811 *max_global_size = MIN2(4 * max_mem_alloc_size,
812 MAX2(sscreen->info.gart_size,
813 sscreen->info.vram_size));
814 }
815 return sizeof(uint64_t);
816
817 case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
818 if (ret) {
819 uint64_t *max_local_size = ret;
820 /* Value reported by the closed source driver. */
821 *max_local_size = 32768;
822 }
823 return sizeof(uint64_t);
824
825 case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
826 if (ret) {
827 uint64_t *max_input_size = ret;
828 /* Value reported by the closed source driver. */
829 *max_input_size = 1024;
830 }
831 return sizeof(uint64_t);
832
833 case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
834 if (ret) {
835 uint64_t *max_mem_alloc_size = ret;
836
837 *max_mem_alloc_size = sscreen->info.max_alloc_size;
838 }
839 return sizeof(uint64_t);
840
841 case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
842 if (ret) {
843 uint32_t *max_clock_frequency = ret;
844 *max_clock_frequency = sscreen->info.max_shader_clock;
845 }
846 return sizeof(uint32_t);
847
848 case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
849 if (ret) {
850 uint32_t *max_compute_units = ret;
851 *max_compute_units = sscreen->info.num_good_compute_units;
852 }
853 return sizeof(uint32_t);
854
855 case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
856 if (ret) {
857 uint32_t *images_supported = ret;
858 *images_supported = 0;
859 }
860 return sizeof(uint32_t);
861 case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
862 break; /* unused */
863 case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
864 if (ret) {
865 uint32_t *subgroup_size = ret;
866 *subgroup_size = 64;
867 }
868 return sizeof(uint32_t);
869 case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
870 if (ret) {
871 uint64_t *max_variable_threads_per_block = ret;
872 if (ir_type == PIPE_SHADER_IR_NATIVE)
873 *max_variable_threads_per_block = 0;
874 else
875 *max_variable_threads_per_block = SI_MAX_VARIABLE_THREADS_PER_BLOCK;
876 }
877 return sizeof(uint64_t);
878 }
879
880 fprintf(stderr, "unknown PIPE_COMPUTE_CAP %d\n", param);
881 return 0;
882 }
883
884 static uint64_t si_get_timestamp(struct pipe_screen *screen)
885 {
886 struct si_screen *sscreen = (struct si_screen*)screen;
887
888 return 1000000 * sscreen->ws->query_value(sscreen->ws, RADEON_TIMESTAMP) /
889 sscreen->info.clock_crystal_freq;
890 }
891
892 static void si_query_memory_info(struct pipe_screen *screen,
893 struct pipe_memory_info *info)
894 {
895 struct si_screen *sscreen = (struct si_screen*)screen;
896 struct radeon_winsys *ws = sscreen->ws;
897 unsigned vram_usage, gtt_usage;
898
899 info->total_device_memory = sscreen->info.vram_size / 1024;
900 info->total_staging_memory = sscreen->info.gart_size / 1024;
901
902 /* The real TTM memory usage is somewhat random, because:
903 *
904 * 1) TTM delays freeing memory, because it can only free it after
905 * fences expire.
906 *
907 * 2) The memory usage can be really low if big VRAM evictions are
908 * taking place, but the real usage is well above the size of VRAM.
909 *
910 * Instead, return statistics of this process.
911 */
912 vram_usage = ws->query_value(ws, RADEON_VRAM_USAGE) / 1024;
913 gtt_usage = ws->query_value(ws, RADEON_GTT_USAGE) / 1024;
914
915 info->avail_device_memory =
916 vram_usage <= info->total_device_memory ?
917 info->total_device_memory - vram_usage : 0;
918 info->avail_staging_memory =
919 gtt_usage <= info->total_staging_memory ?
920 info->total_staging_memory - gtt_usage : 0;
921
922 info->device_memory_evicted =
923 ws->query_value(ws, RADEON_NUM_BYTES_MOVED) / 1024;
924
925 if (sscreen->info.drm_major == 3 && sscreen->info.drm_minor >= 4)
926 info->nr_device_memory_evictions =
927 ws->query_value(ws, RADEON_NUM_EVICTIONS);
928 else
929 /* Just return the number of evicted 64KB pages. */
930 info->nr_device_memory_evictions = info->device_memory_evicted / 64;
931 }
932
933 static struct disk_cache *si_get_disk_shader_cache(struct pipe_screen *pscreen)
934 {
935 struct si_screen *sscreen = (struct si_screen*)pscreen;
936
937 return sscreen->disk_shader_cache;
938 }
939
940 static void si_init_renderer_string(struct si_screen *sscreen)
941 {
942 struct radeon_winsys *ws = sscreen->ws;
943 char first_name[256], second_name[32] = {}, kernel_version[128] = {};
944 struct utsname uname_data;
945
946 const char *marketing_name = si_get_marketing_name(ws);
947
948 if (marketing_name) {
949 snprintf(first_name, sizeof(first_name), "%s", marketing_name);
950 snprintf(second_name, sizeof(second_name), "%s, ",
951 sscreen->info.name);
952 } else {
953 snprintf(first_name, sizeof(first_name), "AMD %s",
954 sscreen->info.name);
955 }
956
957 if (uname(&uname_data) == 0)
958 snprintf(kernel_version, sizeof(kernel_version),
959 ", %s", uname_data.release);
960
961 snprintf(sscreen->renderer_string, sizeof(sscreen->renderer_string),
962 "%s (%sDRM %i.%i.%i%s, LLVM %i.%i.%i)",
963 first_name, second_name, sscreen->info.drm_major,
964 sscreen->info.drm_minor, sscreen->info.drm_patchlevel,
965 kernel_version,
966 (HAVE_LLVM >> 8) & 0xff,
967 HAVE_LLVM & 0xff,
968 MESA_LLVM_VERSION_PATCH);
969 }
970
971 void si_init_screen_get_functions(struct si_screen *sscreen)
972 {
973 sscreen->b.get_name = si_get_name;
974 sscreen->b.get_vendor = si_get_vendor;
975 sscreen->b.get_device_vendor = si_get_device_vendor;
976 sscreen->b.get_param = si_get_param;
977 sscreen->b.get_paramf = si_get_paramf;
978 sscreen->b.get_compute_param = si_get_compute_param;
979 sscreen->b.get_timestamp = si_get_timestamp;
980 sscreen->b.get_shader_param = si_get_shader_param;
981 sscreen->b.get_compiler_options = si_get_compiler_options;
982 sscreen->b.get_device_uuid = si_get_device_uuid;
983 sscreen->b.get_driver_uuid = si_get_driver_uuid;
984 sscreen->b.query_memory_info = si_query_memory_info;
985 sscreen->b.get_disk_shader_cache = si_get_disk_shader_cache;
986
987 if (sscreen->info.has_hw_decode) {
988 sscreen->b.get_video_param = si_get_video_param;
989 sscreen->b.is_video_format_supported = si_vid_is_format_supported;
990 } else {
991 sscreen->b.get_video_param = si_get_video_param_no_decode;
992 sscreen->b.is_video_format_supported = vl_video_buffer_is_format_supported;
993 }
994
995 si_init_renderer_string(sscreen);
996 }