1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
30 #include "pipe/p_defines.h"
31 #include "pipe/p_screen.h"
32 #include "pipe/p_state.h"
34 #include "util/u_memory.h"
35 #include "util/u_inlines.h"
36 #include "util/u_format.h"
37 #include "util/u_format_s3tc.h"
38 #include "util/u_string.h"
39 #include "util/u_debug.h"
41 #include "os/os_time.h"
47 #include "freedreno_screen.h"
48 #include "freedreno_resource.h"
49 #include "freedreno_fence.h"
50 #include "freedreno_query.h"
51 #include "freedreno_util.h"
53 #include "a2xx/fd2_screen.h"
54 #include "a3xx/fd3_screen.h"
55 #include "a4xx/fd4_screen.h"
57 /* XXX this should go away */
58 #include "state_tracker/drm_driver.h"
60 static const struct debug_named_value debug_options
[] = {
61 {"msgs", FD_DBG_MSGS
, "Print debug messages"},
62 {"disasm", FD_DBG_DISASM
, "Dump TGSI and adreno shader disassembly"},
63 {"dclear", FD_DBG_DCLEAR
, "Mark all state dirty after clear"},
64 {"ddraw", FD_DBG_DDRAW
, "Mark all state dirty after draw"},
65 {"noscis", FD_DBG_NOSCIS
, "Disable scissor optimization"},
66 {"direct", FD_DBG_DIRECT
, "Force inline (SS_DIRECT) state loads"},
67 {"nobypass", FD_DBG_NOBYPASS
, "Disable GMEM bypass"},
68 {"fraghalf", FD_DBG_FRAGHALF
, "Use half-precision in fragment shader"},
69 {"nobin", FD_DBG_NOBIN
, "Disable hw binning"},
70 {"optmsgs", FD_DBG_OPTMSGS
,"Enable optimizer debug messages"},
71 {"glsl120", FD_DBG_GLSL120
,"Temporary flag to force GLSL 1.20 (rather than 1.30) on a3xx+"},
72 {"shaderdb", FD_DBG_SHADERDB
, "Enable shaderdb output"},
73 {"flush", FD_DBG_FLUSH
, "Force flush after every draw"},
77 DEBUG_GET_ONCE_FLAGS_OPTION(fd_mesa_debug
, "FD_MESA_DEBUG", debug_options
, 0)
79 int fd_mesa_debug
= 0;
80 bool fd_binning_enabled
= true;
81 static bool glsl120
= false;
84 fd_screen_get_name(struct pipe_screen
*pscreen
)
86 static char buffer
[128];
87 util_snprintf(buffer
, sizeof(buffer
), "FD%03d",
88 fd_screen(pscreen
)->device_id
);
93 fd_screen_get_vendor(struct pipe_screen
*pscreen
)
99 fd_screen_get_device_vendor(struct pipe_screen
*pscreen
)
106 fd_screen_get_timestamp(struct pipe_screen
*pscreen
)
108 int64_t cpu_time
= os_time_get() * 1000;
109 return cpu_time
+ fd_screen(pscreen
)->cpu_gpu_time_delta
;
113 fd_screen_destroy(struct pipe_screen
*pscreen
)
115 struct fd_screen
*screen
= fd_screen(pscreen
);
118 fd_pipe_del(screen
->pipe
);
121 fd_device_del(screen
->dev
);
127 TODO either move caps to a2xx/a3xx specific code, or maybe have some
128 tables for things that differ if the delta is not too much..
131 fd_screen_get_param(struct pipe_screen
*pscreen
, enum pipe_cap param
)
133 struct fd_screen
*screen
= fd_screen(pscreen
);
135 /* this is probably not totally correct.. but it's a start: */
137 /* Supported features (boolean caps). */
138 case PIPE_CAP_NPOT_TEXTURES
:
139 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES
:
140 case PIPE_CAP_TWO_SIDED_STENCIL
:
141 case PIPE_CAP_ANISOTROPIC_FILTER
:
142 case PIPE_CAP_POINT_SPRITE
:
143 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
144 case PIPE_CAP_BLEND_EQUATION_SEPARATE
:
145 case PIPE_CAP_TEXTURE_SWIZZLE
:
146 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS
:
147 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT
:
148 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER
:
149 case PIPE_CAP_SEAMLESS_CUBE_MAP
:
150 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED
:
151 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
:
152 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY
:
153 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY
:
154 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY
:
155 case PIPE_CAP_USER_CONSTANT_BUFFERS
:
156 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT
:
157 case PIPE_CAP_VERTEXID_NOBASE
:
160 case PIPE_CAP_SHADER_STENCIL_EXPORT
:
161 case PIPE_CAP_TGSI_TEXCOORD
:
162 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER
:
163 case PIPE_CAP_TEXTURE_MULTISAMPLE
:
164 case PIPE_CAP_TEXTURE_BARRIER
:
165 case PIPE_CAP_TEXTURE_MIRROR_CLAMP
:
166 case PIPE_CAP_COMPUTE
:
170 case PIPE_CAP_PRIMITIVE_RESTART
:
171 case PIPE_CAP_TGSI_INSTANCEID
:
172 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR
:
173 case PIPE_CAP_INDEP_BLEND_ENABLE
:
174 case PIPE_CAP_INDEP_BLEND_FUNC
:
175 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS
:
176 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR
:
177 case PIPE_CAP_CONDITIONAL_RENDER
:
178 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED
:
179 case PIPE_CAP_FAKE_SW_MSAA
:
180 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE
:
181 case PIPE_CAP_DEPTH_CLIP_DISABLE
:
182 case PIPE_CAP_CLIP_HALFZ
:
183 return is_a3xx(screen
) || is_a4xx(screen
);
185 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT
:
186 if (is_a3xx(screen
)) return 16;
187 if (is_a4xx(screen
)) return 32;
189 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE
:
190 /* We could possibly emulate more by pretending 2d/rect textures and
191 * splitting high bits of index into 2nd dimension..
193 if (is_a3xx(screen
)) return 8192;
194 if (is_a4xx(screen
)) return 16384;
197 case PIPE_CAP_TEXTURE_FLOAT_LINEAR
:
198 case PIPE_CAP_CUBE_MAP_ARRAY
:
199 case PIPE_CAP_START_INSTANCE
:
200 case PIPE_CAP_SAMPLER_VIEW_TARGET
:
201 case PIPE_CAP_TEXTURE_QUERY_LOD
:
202 return is_a4xx(screen
);
204 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT
:
207 case PIPE_CAP_GLSL_FEATURE_LEVEL
:
210 return is_ir3(screen
) ? 140 : 120;
212 /* Unsupported features. */
213 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT
:
214 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER
:
215 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS
:
216 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED
:
217 case PIPE_CAP_VERTEX_COLOR_CLAMPED
:
218 case PIPE_CAP_USER_VERTEX_BUFFERS
:
219 case PIPE_CAP_USER_INDEX_BUFFERS
:
220 case PIPE_CAP_QUERY_PIPELINE_STATISTICS
:
221 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK
:
222 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT
:
223 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS
:
224 case PIPE_CAP_TEXTURE_GATHER_SM5
:
225 case PIPE_CAP_SAMPLE_SHADING
:
226 case PIPE_CAP_TEXTURE_GATHER_OFFSETS
:
227 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION
:
228 case PIPE_CAP_DRAW_INDIRECT
:
229 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE
:
230 case PIPE_CAP_POLYGON_OFFSET_CLAMP
:
231 case PIPE_CAP_MULTISAMPLE_Z_RESOLVE
:
232 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY
:
233 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY
:
234 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS
:
235 case PIPE_CAP_DEPTH_BOUNDS_TEST
:
236 case PIPE_CAP_TGSI_TXQS
:
237 case PIPE_CAP_FORCE_PERSAMPLE_INTERP
:
238 case PIPE_CAP_SHAREABLE_SHADERS
:
239 case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS
:
240 case PIPE_CAP_CLEAR_TEXTURE
:
241 case PIPE_CAP_DRAW_PARAMETERS
:
242 case PIPE_CAP_TGSI_PACK_HALF_FLOAT
:
245 case PIPE_CAP_MAX_VIEWPORTS
:
249 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
:
251 return PIPE_MAX_SO_BUFFERS
;
253 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME
:
257 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS
:
258 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS
:
260 return 16 * 4; /* should only be shader out limit? */
263 /* Geometry shader output, unsupported. */
264 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES
:
265 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS
:
266 case PIPE_CAP_MAX_VERTEX_STREAMS
:
269 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE
:
273 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
274 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
275 return MAX_MIP_LEVELS
;
276 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
279 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
:
280 return (is_a3xx(screen
) || is_a4xx(screen
)) ? 256 : 0;
282 /* Render targets. */
283 case PIPE_CAP_MAX_RENDER_TARGETS
:
284 return screen
->max_rts
;
285 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS
:
286 return is_a3xx(screen
) ? 1 : 0;
289 case PIPE_CAP_QUERY_TIME_ELAPSED
:
290 case PIPE_CAP_QUERY_TIMESTAMP
:
292 case PIPE_CAP_OCCLUSION_QUERY
:
293 return is_a3xx(screen
) || is_a4xx(screen
);
295 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET
:
296 case PIPE_CAP_MIN_TEXEL_OFFSET
:
299 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET
:
300 case PIPE_CAP_MAX_TEXEL_OFFSET
:
303 case PIPE_CAP_ENDIANNESS
:
304 return PIPE_ENDIAN_LITTLE
;
306 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT
:
309 case PIPE_CAP_VENDOR_ID
:
311 case PIPE_CAP_DEVICE_ID
:
313 case PIPE_CAP_ACCELERATED
:
315 case PIPE_CAP_VIDEO_MEMORY
:
316 DBG("FINISHME: The value returned is incorrect\n");
321 debug_printf("unknown param %d\n", param
);
326 fd_screen_get_paramf(struct pipe_screen
*pscreen
, enum pipe_capf param
)
329 case PIPE_CAPF_MAX_LINE_WIDTH
:
330 case PIPE_CAPF_MAX_LINE_WIDTH_AA
:
331 case PIPE_CAPF_MAX_POINT_WIDTH
:
332 case PIPE_CAPF_MAX_POINT_WIDTH_AA
:
334 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY
:
336 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS
:
338 case PIPE_CAPF_GUARD_BAND_LEFT
:
339 case PIPE_CAPF_GUARD_BAND_TOP
:
340 case PIPE_CAPF_GUARD_BAND_RIGHT
:
341 case PIPE_CAPF_GUARD_BAND_BOTTOM
:
344 debug_printf("unknown paramf %d\n", param
);
349 fd_screen_get_shader_param(struct pipe_screen
*pscreen
, unsigned shader
,
350 enum pipe_shader_cap param
)
352 struct fd_screen
*screen
= fd_screen(pscreen
);
356 case PIPE_SHADER_FRAGMENT
:
357 case PIPE_SHADER_VERTEX
:
359 case PIPE_SHADER_COMPUTE
:
360 case PIPE_SHADER_GEOMETRY
:
361 /* maye we could emulate.. */
364 DBG("unknown shader type %d", shader
);
368 /* this is probably not totally correct.. but it's a start: */
370 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS
:
371 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS
:
372 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS
:
373 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS
:
375 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH
:
377 case PIPE_SHADER_CAP_MAX_INPUTS
:
378 case PIPE_SHADER_CAP_MAX_OUTPUTS
:
380 case PIPE_SHADER_CAP_MAX_TEMPS
:
381 return 64; /* Max native temporaries. */
382 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE
:
383 /* NOTE: seems to be limit for a3xx is actually 512 but
384 * split between VS and FS. Use lower limit of 256 to
385 * avoid getting into impossible situations:
387 return ((is_a3xx(screen
) || is_a4xx(screen
)) ? 4096 : 64) * sizeof(float[4]);
388 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS
:
389 return is_ir3(screen
) ? 16 : 1;
390 case PIPE_SHADER_CAP_MAX_PREDS
:
391 return 0; /* nothing uses this */
392 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED
:
394 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR
:
395 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR
:
396 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR
:
397 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR
:
399 case PIPE_SHADER_CAP_SUBROUTINES
:
400 case PIPE_SHADER_CAP_DOUBLES
:
401 case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED
:
402 case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED
:
403 case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED
:
404 case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE
:
406 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED
:
408 case PIPE_SHADER_CAP_INTEGERS
:
411 return is_ir3(screen
) ? 1 : 0;
412 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
:
413 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS
:
415 case PIPE_SHADER_CAP_PREFERRED_IR
:
416 return PIPE_SHADER_IR_TGSI
;
417 case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT
:
420 debug_printf("unknown shader param %d\n", param
);
425 fd_screen_bo_get_handle(struct pipe_screen
*pscreen
,
428 struct winsys_handle
*whandle
)
430 whandle
->stride
= stride
;
432 if (whandle
->type
== DRM_API_HANDLE_TYPE_SHARED
) {
433 return fd_bo_get_name(bo
, &whandle
->handle
) == 0;
434 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_KMS
) {
435 whandle
->handle
= fd_bo_handle(bo
);
437 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_FD
) {
438 whandle
->handle
= fd_bo_dmabuf(bo
);
446 fd_screen_bo_from_handle(struct pipe_screen
*pscreen
,
447 struct winsys_handle
*whandle
,
448 unsigned *out_stride
)
450 struct fd_screen
*screen
= fd_screen(pscreen
);
453 if (whandle
->type
== DRM_API_HANDLE_TYPE_SHARED
) {
454 bo
= fd_bo_from_name(screen
->dev
, whandle
->handle
);
455 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_KMS
) {
456 bo
= fd_bo_from_handle(screen
->dev
, whandle
->handle
, 0);
457 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_FD
) {
458 bo
= fd_bo_from_dmabuf(screen
->dev
, whandle
->handle
);
460 DBG("Attempt to import unsupported handle type %d", whandle
->type
);
465 DBG("ref name 0x%08x failed", whandle
->handle
);
469 *out_stride
= whandle
->stride
;
475 fd_screen_create(struct fd_device
*dev
)
477 struct fd_screen
*screen
= CALLOC_STRUCT(fd_screen
);
478 struct pipe_screen
*pscreen
;
481 fd_mesa_debug
= debug_get_option_fd_mesa_debug();
483 if (fd_mesa_debug
& FD_DBG_NOBIN
)
484 fd_binning_enabled
= false;
486 glsl120
= !!(fd_mesa_debug
& FD_DBG_GLSL120
);
491 pscreen
= &screen
->base
;
496 // maybe this should be in context?
497 screen
->pipe
= fd_pipe_new(screen
->dev
, FD_PIPE_3D
);
499 DBG("could not create 3d pipe");
503 if (fd_pipe_get_param(screen
->pipe
, FD_GMEM_SIZE
, &val
)) {
504 DBG("could not get GMEM size");
507 screen
->gmemsize_bytes
= val
;
509 if (fd_pipe_get_param(screen
->pipe
, FD_DEVICE_ID
, &val
)) {
510 DBG("could not get device-id");
513 screen
->device_id
= val
;
515 if (fd_pipe_get_param(screen
->pipe
, FD_GPU_ID
, &val
)) {
516 DBG("could not get gpu-id");
519 screen
->gpu_id
= val
;
521 if (fd_pipe_get_param(screen
->pipe
, FD_CHIP_ID
, &val
)) {
522 DBG("could not get chip-id");
523 /* older kernels may not have this property: */
524 unsigned core
= screen
->gpu_id
/ 100;
525 unsigned major
= (screen
->gpu_id
% 100) / 10;
526 unsigned minor
= screen
->gpu_id
% 10;
527 unsigned patch
= 0; /* assume the worst */
528 val
= (patch
& 0xff) | ((minor
& 0xff) << 8) |
529 ((major
& 0xff) << 16) | ((core
& 0xff) << 24);
531 screen
->chip_id
= val
;
534 DBG(" GPU-id: %d", screen
->gpu_id
);
535 DBG(" Chip-id: 0x%08x", screen
->chip_id
);
536 DBG(" GMEM size: 0x%08x", screen
->gmemsize_bytes
);
538 /* explicitly checking for GPU revisions that are known to work. This
539 * may be overly conservative for a3xx, where spoofing the gpu_id with
540 * the blob driver seems to generate identical cmdstream dumps. But
541 * on a2xx, there seem to be small differences between the GPU revs
542 * so it is probably better to actually test first on real hardware
545 * If you have a different adreno version, feel free to add it to one
546 * of the cases below and see what happens. And if it works, please
549 switch (screen
->gpu_id
) {
551 fd2_screen_init(pscreen
);
557 fd3_screen_init(pscreen
);
560 fd4_screen_init(pscreen
);
563 debug_printf("unsupported GPU: a%03d\n", screen
->gpu_id
);
567 pscreen
->destroy
= fd_screen_destroy
;
568 pscreen
->get_param
= fd_screen_get_param
;
569 pscreen
->get_paramf
= fd_screen_get_paramf
;
570 pscreen
->get_shader_param
= fd_screen_get_shader_param
;
572 fd_resource_screen_init(pscreen
);
573 fd_query_screen_init(pscreen
);
575 pscreen
->get_name
= fd_screen_get_name
;
576 pscreen
->get_vendor
= fd_screen_get_vendor
;
577 pscreen
->get_device_vendor
= fd_screen_get_device_vendor
;
579 pscreen
->get_timestamp
= fd_screen_get_timestamp
;
581 pscreen
->fence_reference
= fd_screen_fence_ref
;
582 pscreen
->fence_finish
= fd_screen_fence_finish
;
584 util_format_s3tc_init();
589 fd_screen_destroy(pscreen
);