2 * Copyright © 2014 Broadcom
3 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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:
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
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
27 #include "pipe/p_defines.h"
28 #include "pipe/p_screen.h"
29 #include "pipe/p_state.h"
31 #include "util/u_debug.h"
32 #include "util/u_memory.h"
33 #include "util/u_format.h"
35 #include "vc4_screen.h"
36 #include "vc4_context.h"
37 #include "vc4_resource.h"
39 static const struct debug_named_value debug_options[] = {
40 {"cl", VC4_DBG_CL, "Dump command list during creation"},
44 vc4_screen_get_name(struct pipe_screen *pscreen)
50 vc4_screen_get_vendor(struct pipe_screen *pscreen)
56 vc4_screen_destroy(struct pipe_screen *pscreen)
62 vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
65 /* Supported features (boolean caps). */
66 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
67 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
68 case PIPE_CAP_NPOT_TEXTURES:
69 case PIPE_CAP_USER_CONSTANT_BUFFERS:
70 case PIPE_CAP_TEXTURE_SHADOW_MAP:
71 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
72 case PIPE_CAP_TWO_SIDED_STENCIL:
75 /* lying for GL 2.0 */
76 case PIPE_CAP_OCCLUSION_QUERY:
77 case PIPE_CAP_POINT_SPRITE:
80 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
83 case PIPE_CAP_GLSL_FEATURE_LEVEL:
86 case PIPE_CAP_MAX_VIEWPORTS:
89 /* Unsupported features. */
90 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
91 case PIPE_CAP_ANISOTROPIC_FILTER:
92 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
93 case PIPE_CAP_CUBE_MAP_ARRAY:
94 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
95 case PIPE_CAP_TEXTURE_SWIZZLE:
96 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
97 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
98 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
99 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
100 case PIPE_CAP_SEAMLESS_CUBE_MAP:
101 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
102 case PIPE_CAP_TGSI_INSTANCEID:
103 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
104 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
105 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
106 case PIPE_CAP_COMPUTE:
107 case PIPE_CAP_START_INSTANCE:
108 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
109 case PIPE_CAP_SHADER_STENCIL_EXPORT:
110 case PIPE_CAP_TGSI_TEXCOORD:
111 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
112 case PIPE_CAP_CONDITIONAL_RENDER:
113 case PIPE_CAP_PRIMITIVE_RESTART:
114 case PIPE_CAP_TEXTURE_MULTISAMPLE:
115 case PIPE_CAP_TEXTURE_BARRIER:
117 case PIPE_CAP_INDEP_BLEND_ENABLE:
118 case PIPE_CAP_INDEP_BLEND_FUNC:
119 case PIPE_CAP_DEPTH_CLIP_DISABLE:
120 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
121 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
122 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
123 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
124 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
125 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
126 case PIPE_CAP_USER_VERTEX_BUFFERS:
127 case PIPE_CAP_USER_INDEX_BUFFERS:
128 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
129 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
130 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
131 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
132 case PIPE_CAP_TEXTURE_GATHER_SM5:
133 case PIPE_CAP_FAKE_SW_MSAA:
134 case PIPE_CAP_TEXTURE_QUERY_LOD:
135 case PIPE_CAP_SAMPLE_SHADING:
136 case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
137 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
138 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
139 case PIPE_CAP_MAX_TEXEL_OFFSET:
140 case PIPE_CAP_MAX_VERTEX_STREAMS:
141 case PIPE_CAP_DRAW_INDIRECT:
145 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
146 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
147 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
148 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
151 /* Geometry shader output, unsupported. */
152 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
153 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
157 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
158 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
159 return VC4_MAX_MIP_LEVELS;
160 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
162 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
165 /* Render targets. */
166 case PIPE_CAP_MAX_RENDER_TARGETS:
170 case PIPE_CAP_QUERY_TIME_ELAPSED:
171 case PIPE_CAP_QUERY_TIMESTAMP:
174 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
175 case PIPE_CAP_MIN_TEXEL_OFFSET:
178 case PIPE_CAP_ENDIANNESS:
179 return PIPE_ENDIAN_LITTLE;
181 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
185 fprintf(stderr, "unknown param %d\n", param);
191 vc4_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
194 case PIPE_CAPF_MAX_LINE_WIDTH:
195 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
196 case PIPE_CAPF_MAX_POINT_WIDTH:
197 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
199 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
201 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
203 case PIPE_CAPF_GUARD_BAND_LEFT:
204 case PIPE_CAPF_GUARD_BAND_TOP:
205 case PIPE_CAPF_GUARD_BAND_RIGHT:
206 case PIPE_CAPF_GUARD_BAND_BOTTOM:
209 fprintf(stderr, "unknown paramf %d\n", param);
215 vc4_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
216 enum pipe_shader_cap param)
218 if (shader != PIPE_SHADER_VERTEX &&
219 shader != PIPE_SHADER_FRAGMENT) {
223 /* this is probably not totally correct.. but it's a start: */
225 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
226 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
227 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
228 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
230 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
232 case PIPE_SHADER_CAP_MAX_INPUTS:
234 case PIPE_SHADER_CAP_MAX_TEMPS:
235 return 64; /* Max native temporaries. */
236 case PIPE_SHADER_CAP_MAX_ADDRS:
237 return 1; /* Max native address registers */
238 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
239 return 64 * sizeof(float[4]);
240 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
242 case PIPE_SHADER_CAP_MAX_PREDS:
243 return 0; /* nothing uses this */
244 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
246 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
247 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
248 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
249 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
251 case PIPE_SHADER_CAP_SUBROUTINES:
253 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
255 case PIPE_SHADER_CAP_INTEGERS:
256 case PIPE_SHADER_CAP_DOUBLES:
258 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
259 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
261 case PIPE_SHADER_CAP_PREFERRED_IR:
262 return PIPE_SHADER_IR_TGSI;
264 fprintf(stderr, "unknown shader param %d\n", param);
271 vc4_get_texture_format(enum pipe_format format)
274 case PIPE_FORMAT_B8G8R8A8_UNORM:
276 case PIPE_FORMAT_B8G8R8X8_UNORM:
278 case PIPE_FORMAT_R8G8B8A8_UNORM:
280 case PIPE_FORMAT_R8G8B8X8_UNORM:
282 case PIPE_FORMAT_A8R8G8B8_UNORM:
284 case PIPE_FORMAT_X8R8G8B8_UNORM:
286 case PIPE_FORMAT_A8B8G8R8_UNORM:
288 case PIPE_FORMAT_X8B8G8R8_UNORM:
291 case PIPE_FORMAT_R4G4B4A4_UNORM:
293 case PIPE_FORMAT_R5G5B5A1_UNORM:
295 case PIPE_FORMAT_R5G6B5_UNORM:
298 case PIPE_FORMAT_L8_UNORM:
300 case PIPE_FORMAT_A8_UNORM:
302 case PIPE_FORMAT_L8A8_UNORM:
304 /* XXX: ETC1 and more*/
311 vc4_screen_is_format_supported(struct pipe_screen *pscreen,
312 enum pipe_format format,
313 enum pipe_texture_target target,
314 unsigned sample_count,
319 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
320 (sample_count > 1) ||
321 !util_format_is_supported(format, usage)) {
325 if (usage & PIPE_BIND_VERTEX_BUFFER)
326 retval |= PIPE_BIND_VERTEX_BUFFER; /* XXX */
328 if ((usage & PIPE_BIND_RENDER_TARGET) &&
329 (format == PIPE_FORMAT_B8G8R8A8_UNORM ||
330 format == PIPE_FORMAT_B8G8R8X8_UNORM || /* XXX: really? */
331 format == PIPE_FORMAT_R8G8B8A8_UNORM ||
332 format == PIPE_FORMAT_R8G8B8X8_UNORM || /* XXX: really? */
333 format == PIPE_FORMAT_A8B8G8R8_UNORM ||
334 format == PIPE_FORMAT_X8B8G8R8_UNORM || /* XXX: really? */
335 format == PIPE_FORMAT_A8R8G8B8_UNORM ||
336 format == PIPE_FORMAT_X8R8G8B8_UNORM || /* XXX: really? */
337 format == PIPE_FORMAT_R16G16B16A16_FLOAT)) {
338 retval |= PIPE_BIND_RENDER_TARGET;
341 if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
342 (vc4_get_texture_format(format) != ~0)) {
343 retval |= usage & (PIPE_BIND_SAMPLER_VIEW |
344 PIPE_BIND_VERTEX_BUFFER);
347 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
348 (format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
349 format == PIPE_FORMAT_Z24X8_UNORM)) {
350 retval |= PIPE_BIND_DEPTH_STENCIL;
353 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
354 (format == PIPE_FORMAT_I8_UINT ||
355 format == PIPE_FORMAT_I16_UINT)) {
356 retval |= PIPE_BIND_INDEX_BUFFER;
359 if (usage & PIPE_BIND_TRANSFER_READ)
360 retval |= PIPE_BIND_TRANSFER_READ;
361 if (usage & PIPE_BIND_TRANSFER_WRITE)
362 retval |= PIPE_BIND_TRANSFER_WRITE;
364 return retval == usage;
368 vc4_screen_create(int fd)
370 struct vc4_screen *screen = CALLOC_STRUCT(vc4_screen);
371 struct pipe_screen *pscreen;
373 pscreen = &screen->base;
375 pscreen->destroy = vc4_screen_destroy;
376 pscreen->get_param = vc4_screen_get_param;
377 pscreen->get_paramf = vc4_screen_get_paramf;
378 pscreen->get_shader_param = vc4_screen_get_shader_param;
379 pscreen->context_create = vc4_context_create;
380 pscreen->is_format_supported = vc4_screen_is_format_supported;
384 #if USE_VC4_SIMULATOR
385 vc4_simulator_init(screen);
388 vc4_resource_screen_init(pscreen);
390 pscreen->get_name = vc4_screen_get_name;
391 pscreen->get_vendor = vc4_screen_get_vendor;
397 vc4_screen_bo_get_handle(struct pipe_screen *pscreen,
400 struct winsys_handle *whandle)
402 whandle->stride = stride;
404 switch (whandle->type) {
405 case DRM_API_HANDLE_TYPE_SHARED:
406 return vc4_bo_flink(bo, &whandle->handle);
407 case DRM_API_HANDLE_TYPE_KMS:
408 whandle->handle = bo->handle;
416 vc4_screen_bo_from_handle(struct pipe_screen *pscreen,
417 struct winsys_handle *whandle,
418 unsigned *out_stride)
420 struct vc4_screen *screen = vc4_screen(pscreen);
423 if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
425 "Attempt to import unsupported handle type %d\n",
430 bo = vc4_bo_open_name(screen, whandle->handle, whandle->stride);
432 fprintf(stderr, "Open name %d failed\n", whandle->handle);
436 *out_stride = whandle->stride;