vc4: Enable PIPE_CAP_TGSI_TEXCOORD.
[mesa.git] / src / gallium / drivers / v3d / v3d_screen.c
1 /*
2 * Copyright © 2014-2017 Broadcom
3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #include <sys/sysinfo.h>
26
27 #include "common/v3d_device_info.h"
28 #include "util/os_misc.h"
29 #include "pipe/p_defines.h"
30 #include "pipe/p_screen.h"
31 #include "pipe/p_state.h"
32
33 #include "util/u_debug.h"
34 #include "util/u_memory.h"
35 #include "util/format/u_format.h"
36 #include "util/u_hash_table.h"
37 #include "util/u_screen.h"
38 #include "util/u_transfer_helper.h"
39 #include "util/ralloc.h"
40 #include "util/xmlconfig.h"
41
42 #include <xf86drm.h>
43 #include "v3d_screen.h"
44 #include "v3d_context.h"
45 #include "v3d_resource.h"
46 #include "compiler/v3d_compiler.h"
47 #include "drm-uapi/drm_fourcc.h"
48
49 static const char *
50 v3d_screen_get_name(struct pipe_screen *pscreen)
51 {
52 struct v3d_screen *screen = v3d_screen(pscreen);
53
54 if (!screen->name) {
55 screen->name = ralloc_asprintf(screen,
56 "V3D %d.%d",
57 screen->devinfo.ver / 10,
58 screen->devinfo.ver % 10);
59 }
60
61 return screen->name;
62 }
63
64 static const char *
65 v3d_screen_get_vendor(struct pipe_screen *pscreen)
66 {
67 return "Broadcom";
68 }
69
70 static void
71 v3d_screen_destroy(struct pipe_screen *pscreen)
72 {
73 struct v3d_screen *screen = v3d_screen(pscreen);
74
75 _mesa_hash_table_destroy(screen->bo_handles, NULL);
76 v3d_bufmgr_destroy(pscreen);
77 slab_destroy_parent(&screen->transfer_pool);
78 free(screen->ro);
79
80 if (using_v3d_simulator)
81 v3d_simulator_destroy(screen->sim_file);
82
83 v3d_compiler_free(screen->compiler);
84 u_transfer_helper_destroy(pscreen->transfer_helper);
85
86 close(screen->fd);
87 ralloc_free(pscreen);
88 }
89
90 static bool
91 v3d_has_feature(struct v3d_screen *screen, enum drm_v3d_param feature)
92 {
93 struct drm_v3d_get_param p = {
94 .param = feature,
95 };
96 int ret = v3d_ioctl(screen->fd, DRM_IOCTL_V3D_GET_PARAM, &p);
97
98 if (ret != 0)
99 return false;
100
101 return p.value;
102 }
103
104 static int
105 v3d_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
106 {
107 struct v3d_screen *screen = v3d_screen(pscreen);
108
109 switch (param) {
110 /* Supported features (boolean caps). */
111 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
112 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
113 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
114 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
115 case PIPE_CAP_NPOT_TEXTURES:
116 case PIPE_CAP_SHAREABLE_SHADERS:
117 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
118 case PIPE_CAP_TEXTURE_MULTISAMPLE:
119 case PIPE_CAP_TEXTURE_SWIZZLE:
120 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
121 case PIPE_CAP_START_INSTANCE:
122 case PIPE_CAP_TGSI_INSTANCEID:
123 case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
124 case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
125 case PIPE_CAP_VERTEX_SHADER_SATURATE:
126 case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
127 case PIPE_CAP_OCCLUSION_QUERY:
128 case PIPE_CAP_POINT_SPRITE:
129 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
130 case PIPE_CAP_DRAW_INDIRECT:
131 case PIPE_CAP_MULTI_DRAW_INDIRECT:
132 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
133 case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
134 case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
135 case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
136 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
137 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
138 case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
139 return 1;
140
141 case PIPE_CAP_TEXTURE_QUERY_LOD:
142 return screen->devinfo.ver >= 42;
143 break;
144
145 case PIPE_CAP_PACKED_UNIFORMS:
146 /* We can't enable this flag, because it results in load_ubo
147 * intrinsics across a 16b boundary, but v3d's TMU general
148 * memory accesses wrap on 16b boundaries.
149 */
150 return 0;
151
152 case PIPE_CAP_NIR_IMAGES_AS_DEREF:
153 return 0;
154
155 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
156 /* XXX perf: we don't want to emit these extra blits for
157 * glReadPixels(), since we still have to do an uncached read
158 * from the GPU of the result after waiting for the TFU blit
159 * to happen. However, disabling this introduces instability
160 * in
161 * dEQP-GLES31.functional.image_load_store.early_fragment_tests.*
162 * and corruption in chromium's rendering.
163 */
164 return 1;
165
166 case PIPE_CAP_COMPUTE:
167 return screen->has_csd && screen->devinfo.ver >= 41;
168
169 case PIPE_CAP_GENERATE_MIPMAP:
170 return v3d_has_feature(screen, DRM_V3D_PARAM_SUPPORTS_TFU);
171
172 case PIPE_CAP_INDEP_BLEND_ENABLE:
173 return screen->devinfo.ver >= 40;
174
175 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
176 return 256;
177
178 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
179 if (screen->devinfo.ver < 40)
180 return 0;
181 return 4;
182
183 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
184 if (screen->has_cache_flush)
185 return 4;
186 else
187 return 0; /* Disables shader storage */
188
189 case PIPE_CAP_GLSL_FEATURE_LEVEL:
190 return 330;
191
192 case PIPE_CAP_ESSL_FEATURE_LEVEL:
193 return 310;
194
195 case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
196 return 140;
197
198 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
199 return 1;
200 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
201 return 0;
202 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
203 if (screen->devinfo.ver >= 40)
204 return 0;
205 else
206 return 1;
207 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
208 if (screen->devinfo.ver >= 40)
209 return 1;
210 else
211 return 0;
212
213 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
214 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
215 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
216 return 1;
217
218 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
219 return 4;
220
221 case PIPE_CAP_MAX_VARYINGS:
222 return V3D_MAX_FS_INPUTS / 4;
223
224 /* Texturing. */
225 case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
226 if (screen->devinfo.ver < 40)
227 return 2048;
228 else if (screen->nonmsaa_texture_size_limit)
229 return 7680;
230 else
231 return 4096;
232 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
233 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
234 if (screen->devinfo.ver < 40)
235 return 12;
236 else
237 return V3D_MAX_MIP_LEVELS;
238 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
239 return 2048;
240
241 /* Render targets. */
242 case PIPE_CAP_MAX_RENDER_TARGETS:
243 return 4;
244
245 case PIPE_CAP_VENDOR_ID:
246 return 0x14E4;
247 case PIPE_CAP_ACCELERATED:
248 return 1;
249 case PIPE_CAP_VIDEO_MEMORY: {
250 uint64_t system_memory;
251
252 if (!os_get_total_physical_memory(&system_memory))
253 return 0;
254
255 return (int)(system_memory >> 20);
256 }
257 case PIPE_CAP_UMA:
258 return 1;
259
260 /* Geometry shaders */
261 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
262 /* Minimum required by GLES 3.2 */
263 return 1024;
264 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
265 /* MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS / 4 */
266 return 256;
267 case PIPE_CAP_MAX_GS_INVOCATIONS:
268 return 32;
269
270 default:
271 return u_pipe_screen_get_param_defaults(pscreen, param);
272 }
273 }
274
275 static float
276 v3d_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
277 {
278 switch (param) {
279 case PIPE_CAPF_MAX_LINE_WIDTH:
280 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
281 return 32;
282
283 case PIPE_CAPF_MAX_POINT_WIDTH:
284 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
285 return 512.0f;
286
287 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
288 return 0.0f;
289 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
290 return 16.0f;
291
292 case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
293 case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
294 case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
295 return 0.0f;
296 default:
297 fprintf(stderr, "unknown paramf %d\n", param);
298 return 0;
299 }
300 }
301
302 static int
303 v3d_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
304 enum pipe_shader_cap param)
305 {
306 struct v3d_screen *screen = v3d_screen(pscreen);
307
308 switch (shader) {
309 case PIPE_SHADER_VERTEX:
310 case PIPE_SHADER_FRAGMENT:
311 break;
312 case PIPE_SHADER_COMPUTE:
313 if (!screen->has_csd)
314 return 0;
315 break;
316 case PIPE_SHADER_GEOMETRY:
317 if (screen->devinfo.ver < 41)
318 return 0;
319 break;
320 default:
321 return 0;
322 }
323
324 /* this is probably not totally correct.. but it's a start: */
325 switch (param) {
326 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
327 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
328 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
329 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
330 return 16384;
331
332 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
333 return UINT_MAX;
334
335 case PIPE_SHADER_CAP_MAX_INPUTS:
336 switch (shader) {
337 case PIPE_SHADER_VERTEX:
338 return V3D_MAX_VS_INPUTS / 4;
339 case PIPE_SHADER_GEOMETRY:
340 return V3D_MAX_GS_INPUTS / 4;
341 case PIPE_SHADER_FRAGMENT:
342 return V3D_MAX_FS_INPUTS / 4;
343 default:
344 return 0;
345 };
346 case PIPE_SHADER_CAP_MAX_OUTPUTS:
347 if (shader == PIPE_SHADER_FRAGMENT)
348 return 4;
349 else
350 return V3D_MAX_FS_INPUTS / 4;
351 case PIPE_SHADER_CAP_MAX_TEMPS:
352 return 256; /* GL_MAX_PROGRAM_TEMPORARIES_ARB */
353 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
354 /* Note: Limited by the offset size in
355 * v3d_unit_data_create().
356 */
357 return 16 * 1024 * sizeof(float);
358 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
359 return 16;
360 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
361 return 0;
362 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
363 return 1;
364 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
365 return 0;
366 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
367 return 1;
368 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
369 return 1;
370 case PIPE_SHADER_CAP_SUBROUTINES:
371 return 0;
372 case PIPE_SHADER_CAP_INTEGERS:
373 return 1;
374 case PIPE_SHADER_CAP_FP16:
375 case PIPE_SHADER_CAP_FP16_DERIVATIVES:
376 case PIPE_SHADER_CAP_INT16:
377 case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
378 case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
379 case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
380 case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
381 case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
382 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
383 case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
384 case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
385 return 0;
386 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
387 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
388 return V3D_MAX_TEXTURE_SAMPLERS;
389
390 case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
391 if (screen->has_cache_flush) {
392 if (shader == PIPE_SHADER_VERTEX ||
393 shader == PIPE_SHADER_GEOMETRY) {
394 return 0;
395 }
396 return PIPE_MAX_SHADER_BUFFERS;
397 } else {
398 return 0;
399 }
400
401 case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
402 if (screen->has_cache_flush) {
403 if (screen->devinfo.ver < 41)
404 return 0;
405 else
406 return PIPE_MAX_SHADER_IMAGES;
407 } else {
408 return 0;
409 }
410
411 case PIPE_SHADER_CAP_PREFERRED_IR:
412 return PIPE_SHADER_IR_NIR;
413 case PIPE_SHADER_CAP_SUPPORTED_IRS:
414 return 1 << PIPE_SHADER_IR_NIR;
415 case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
416 return 32;
417 case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
418 case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
419 return 0;
420 default:
421 fprintf(stderr, "unknown shader param %d\n", param);
422 return 0;
423 }
424 return 0;
425 }
426
427 static int
428 v3d_get_compute_param(struct pipe_screen *pscreen, enum pipe_shader_ir ir_type,
429 enum pipe_compute_cap param, void *ret)
430 {
431 struct v3d_screen *screen = v3d_screen(pscreen);
432
433 if (!screen->has_csd)
434 return 0;
435
436 #define RET(x) do { \
437 if (ret) \
438 memcpy(ret, x, sizeof(x)); \
439 return sizeof(x); \
440 } while (0)
441
442 switch (param) {
443 case PIPE_COMPUTE_CAP_ADDRESS_BITS:
444 RET((uint32_t []) { 32 });
445 break;
446
447 case PIPE_COMPUTE_CAP_IR_TARGET:
448 sprintf(ret, "v3d");
449 return strlen(ret);
450
451 case PIPE_COMPUTE_CAP_GRID_DIMENSION:
452 RET((uint64_t []) { 3 });
453
454 case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
455 /* GL_MAX_COMPUTE_SHADER_WORK_GROUP_COUNT: The CSD has a
456 * 16-bit field for the number of workgroups in each
457 * dimension.
458 */
459 RET(((uint64_t []) { 65535, 65535, 65535 }));
460
461 case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
462 /* GL_MAX_COMPUTE_WORK_GROUP_SIZE */
463 RET(((uint64_t []) { 256, 256, 256 }));
464
465 case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
466 case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
467 /* GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS: This is
468 * limited by WG_SIZE in the CSD.
469 */
470 RET((uint64_t []) { 256 });
471
472 case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
473 RET((uint64_t []) { 1024 * 1024 * 1024 });
474
475 case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
476 /* GL_MAX_COMPUTE_SHARED_MEMORY_SIZE */
477 RET((uint64_t []) { 32768 });
478
479 case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
480 case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
481 RET((uint64_t []) { 4096 });
482
483 case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE: {
484 struct sysinfo si;
485 sysinfo(&si);
486 RET((uint64_t []) { si.totalram });
487 }
488
489 case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
490 /* OpenCL only */
491 RET((uint32_t []) { 0 });
492
493 case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
494 RET((uint32_t []) { 1 });
495
496 case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
497 RET((uint32_t []) { 1 });
498
499 case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
500 RET((uint32_t []) { 16 });
501
502 }
503
504 return 0;
505 }
506
507 static bool
508 v3d_screen_is_format_supported(struct pipe_screen *pscreen,
509 enum pipe_format format,
510 enum pipe_texture_target target,
511 unsigned sample_count,
512 unsigned storage_sample_count,
513 unsigned usage)
514 {
515 struct v3d_screen *screen = v3d_screen(pscreen);
516
517 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
518 return false;
519
520 if (sample_count > 1 && sample_count != V3D_MAX_SAMPLES)
521 return false;
522
523 if (target >= PIPE_MAX_TEXTURE_TYPES) {
524 return false;
525 }
526
527 if (usage & PIPE_BIND_VERTEX_BUFFER) {
528 switch (format) {
529 case PIPE_FORMAT_R32G32B32A32_FLOAT:
530 case PIPE_FORMAT_R32G32B32_FLOAT:
531 case PIPE_FORMAT_R32G32_FLOAT:
532 case PIPE_FORMAT_R32_FLOAT:
533 case PIPE_FORMAT_R32G32B32A32_SNORM:
534 case PIPE_FORMAT_R32G32B32_SNORM:
535 case PIPE_FORMAT_R32G32_SNORM:
536 case PIPE_FORMAT_R32_SNORM:
537 case PIPE_FORMAT_R32G32B32A32_SSCALED:
538 case PIPE_FORMAT_R32G32B32_SSCALED:
539 case PIPE_FORMAT_R32G32_SSCALED:
540 case PIPE_FORMAT_R32_SSCALED:
541 case PIPE_FORMAT_R16G16B16A16_UNORM:
542 case PIPE_FORMAT_R16G16B16_UNORM:
543 case PIPE_FORMAT_R16G16_UNORM:
544 case PIPE_FORMAT_R16_UNORM:
545 case PIPE_FORMAT_R16G16B16A16_SNORM:
546 case PIPE_FORMAT_R16G16B16_SNORM:
547 case PIPE_FORMAT_R16G16_SNORM:
548 case PIPE_FORMAT_R16_SNORM:
549 case PIPE_FORMAT_R16G16B16A16_USCALED:
550 case PIPE_FORMAT_R16G16B16_USCALED:
551 case PIPE_FORMAT_R16G16_USCALED:
552 case PIPE_FORMAT_R16_USCALED:
553 case PIPE_FORMAT_R16G16B16A16_SSCALED:
554 case PIPE_FORMAT_R16G16B16_SSCALED:
555 case PIPE_FORMAT_R16G16_SSCALED:
556 case PIPE_FORMAT_R16_SSCALED:
557 case PIPE_FORMAT_R8G8B8A8_UNORM:
558 case PIPE_FORMAT_R8G8B8_UNORM:
559 case PIPE_FORMAT_R8G8_UNORM:
560 case PIPE_FORMAT_R8_UNORM:
561 case PIPE_FORMAT_R8G8B8A8_SNORM:
562 case PIPE_FORMAT_R8G8B8_SNORM:
563 case PIPE_FORMAT_R8G8_SNORM:
564 case PIPE_FORMAT_R8_SNORM:
565 case PIPE_FORMAT_R8G8B8A8_USCALED:
566 case PIPE_FORMAT_R8G8B8_USCALED:
567 case PIPE_FORMAT_R8G8_USCALED:
568 case PIPE_FORMAT_R8_USCALED:
569 case PIPE_FORMAT_R8G8B8A8_SSCALED:
570 case PIPE_FORMAT_R8G8B8_SSCALED:
571 case PIPE_FORMAT_R8G8_SSCALED:
572 case PIPE_FORMAT_R8_SSCALED:
573 case PIPE_FORMAT_R10G10B10A2_UNORM:
574 case PIPE_FORMAT_B10G10R10A2_UNORM:
575 case PIPE_FORMAT_R10G10B10A2_SNORM:
576 case PIPE_FORMAT_B10G10R10A2_SNORM:
577 case PIPE_FORMAT_R10G10B10A2_USCALED:
578 case PIPE_FORMAT_B10G10R10A2_USCALED:
579 case PIPE_FORMAT_R10G10B10A2_SSCALED:
580 case PIPE_FORMAT_B10G10R10A2_SSCALED:
581 break;
582 default:
583 return false;
584 }
585 }
586
587 /* FORMAT_NONE gets allowed for ARB_framebuffer_no_attachments's probe
588 * of FRAMEBUFFER_MAX_SAMPLES
589 */
590 if ((usage & PIPE_BIND_RENDER_TARGET) &&
591 format != PIPE_FORMAT_NONE &&
592 !v3d_rt_format_supported(&screen->devinfo, format)) {
593 return false;
594 }
595
596 if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
597 !v3d_tex_format_supported(&screen->devinfo, format)) {
598 return false;
599 }
600
601 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
602 !(format == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
603 format == PIPE_FORMAT_X8Z24_UNORM ||
604 format == PIPE_FORMAT_Z16_UNORM ||
605 format == PIPE_FORMAT_Z32_FLOAT ||
606 format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)) {
607 return false;
608 }
609
610 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
611 !(format == PIPE_FORMAT_I8_UINT ||
612 format == PIPE_FORMAT_I16_UINT ||
613 format == PIPE_FORMAT_I32_UINT)) {
614 return false;
615 }
616
617 return true;
618 }
619
620 static const void *
621 v3d_screen_get_compiler_options(struct pipe_screen *pscreen,
622 enum pipe_shader_ir ir, unsigned shader)
623 {
624 return &v3d_nir_options;
625 }
626
627 static void
628 v3d_screen_query_dmabuf_modifiers(struct pipe_screen *pscreen,
629 enum pipe_format format, int max,
630 uint64_t *modifiers,
631 unsigned int *external_only,
632 int *count)
633 {
634 int i;
635 uint64_t available_modifiers[] = {
636 DRM_FORMAT_MOD_BROADCOM_UIF,
637 DRM_FORMAT_MOD_LINEAR,
638 };
639 int num_modifiers = ARRAY_SIZE(available_modifiers);
640
641 if (!modifiers) {
642 *count = num_modifiers;
643 return;
644 }
645
646 *count = MIN2(max, num_modifiers);
647 for (i = 0; i < *count; i++) {
648 modifiers[i] = available_modifiers[i];
649 if (external_only)
650 external_only[i] = false;
651 }
652 }
653
654 struct pipe_screen *
655 v3d_screen_create(int fd, const struct pipe_screen_config *config,
656 struct renderonly *ro)
657 {
658 struct v3d_screen *screen = rzalloc(NULL, struct v3d_screen);
659 struct pipe_screen *pscreen;
660
661 pscreen = &screen->base;
662
663 pscreen->destroy = v3d_screen_destroy;
664 pscreen->get_param = v3d_screen_get_param;
665 pscreen->get_paramf = v3d_screen_get_paramf;
666 pscreen->get_shader_param = v3d_screen_get_shader_param;
667 pscreen->get_compute_param = v3d_get_compute_param;
668 pscreen->context_create = v3d_context_create;
669 pscreen->is_format_supported = v3d_screen_is_format_supported;
670
671 screen->fd = fd;
672 if (ro) {
673 screen->ro = renderonly_dup(ro);
674 if (!screen->ro) {
675 fprintf(stderr, "Failed to dup renderonly object\n");
676 ralloc_free(screen);
677 return NULL;
678 }
679 }
680 list_inithead(&screen->bo_cache.time_list);
681 (void)mtx_init(&screen->bo_handles_mutex, mtx_plain);
682 screen->bo_handles = util_hash_table_create_ptr_keys();
683
684 #if defined(USE_V3D_SIMULATOR)
685 screen->sim_file = v3d_simulator_init(screen->fd);
686 #endif
687
688 if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl))
689 goto fail;
690
691 /* We have to driCheckOption for the simulator mode to not assertion
692 * fail on not having our XML config.
693 */
694 const char *nonmsaa_name = "v3d_nonmsaa_texture_size_limit";
695 screen->nonmsaa_texture_size_limit =
696 driCheckOption(config->options, nonmsaa_name, DRI_BOOL) &&
697 driQueryOptionb(config->options, nonmsaa_name);
698
699 slab_create_parent(&screen->transfer_pool, sizeof(struct v3d_transfer), 16);
700
701 screen->has_csd = v3d_has_feature(screen, DRM_V3D_PARAM_SUPPORTS_CSD);
702 screen->has_cache_flush =
703 v3d_has_feature(screen, DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH);
704
705 v3d_fence_init(screen);
706
707 v3d_process_debug_variable();
708
709 v3d_resource_screen_init(pscreen);
710
711 screen->compiler = v3d_compiler_init(&screen->devinfo);
712
713 pscreen->get_name = v3d_screen_get_name;
714 pscreen->get_vendor = v3d_screen_get_vendor;
715 pscreen->get_device_vendor = v3d_screen_get_vendor;
716 pscreen->get_compiler_options = v3d_screen_get_compiler_options;
717 pscreen->query_dmabuf_modifiers = v3d_screen_query_dmabuf_modifiers;
718
719 return pscreen;
720
721 fail:
722 close(fd);
723 ralloc_free(pscreen);
724 return NULL;
725 }