1 /*
2 * Copyright © 2018 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "pipe/p_screen.h"
25 #include "util/u_screen.h"
26
27 /**
28 * Helper to use from a pipe_screen->get_param() implementation to return
29 * default values for unsupported PIPE_CAPs.
30 *
31 * Call this function from your pipe_screen->get_param() implementation's
32 * default case, so that implementors of new pipe caps don't need to
33 */
34 int
u_pipe_screen_get_param_defaults(struct pipe_screen * pscreen,enum pipe_cap param)35 u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
36 enum pipe_cap param)
37 {
38 /* Let's keep these sorted by position in p_defines.h. */
39 switch (param) {
40 case PIPE_CAP_NPOT_TEXTURES:
41 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
42 case PIPE_CAP_ANISOTROPIC_FILTER:
43 case PIPE_CAP_POINT_SPRITE:
44 return 0;
45
46 case PIPE_CAP_GRAPHICS:
47 case PIPE_CAP_MAX_RENDER_TARGETS:
48 return 1;
49
50 case PIPE_CAP_OCCLUSION_QUERY:
51 case PIPE_CAP_QUERY_TIME_ELAPSED:
52 case PIPE_CAP_TEXTURE_SWIZZLE:
53 return 0;
54
55 case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
56 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
57 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
58 unreachable("driver must implement these.");
59
60 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
61 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
62 case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
63 case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
64 case PIPE_CAP_VERTEX_SHADER_SATURATE:
65 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: /* enables EXT_transform_feedback */
66 case PIPE_CAP_PRIMITIVE_RESTART:
67 case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
68 case PIPE_CAP_INDEP_BLEND_ENABLE:
69 case PIPE_CAP_INDEP_BLEND_FUNC:
70 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: /* Enables GL_EXT_texture_array */
71 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
72 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
73 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
74 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
75 case PIPE_CAP_DEPTH_CLIP_DISABLE:
76 case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
77 case PIPE_CAP_SHADER_STENCIL_EXPORT:
78 case PIPE_CAP_TGSI_INSTANCEID:
79 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
80 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
81 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
82 case PIPE_CAP_SEAMLESS_CUBE_MAP:
83 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
84 case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
85 return 0;
86
87 case PIPE_CAP_MIN_TEXEL_OFFSET:
88 /* GL 3.x minimum value. */
89 return -8;
90 case PIPE_CAP_MAX_TEXEL_OFFSET:
91 return 7;
92
93 case PIPE_CAP_CONDITIONAL_RENDER:
94 case PIPE_CAP_TEXTURE_BARRIER:
95 return 0;
96
97 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
98 /* GL_EXT_transform_feedback minimum value. */
99 return 4;
100 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
101 return 64;
102
103 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
104 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
105 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
106 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
107 return 0;
108
109 case PIPE_CAP_GLSL_FEATURE_LEVEL:
110 case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
111 /* Minimum GLSL level implemented by gallium drivers. */
112 return 120;
113
114 case PIPE_CAP_ESSL_FEATURE_LEVEL:
115 /* Tell gallium frontend to fallback to PIPE_CAP_GLSL_FEATURE_LEVEL */
116 return 0;
117
118 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
119 case PIPE_CAP_USER_VERTEX_BUFFERS:
120 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
121 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
122 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
123 case PIPE_CAP_COMPUTE:
124 return 0;
125
126 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
127 /* GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT default value. */
128 return 1;
129
130 case PIPE_CAP_START_INSTANCE:
131 case PIPE_CAP_QUERY_TIMESTAMP:
132 case PIPE_CAP_TEXTURE_MULTISAMPLE:
133 return 0;
134
135 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
136 /* GL_ARB_map_buffer_alignment minimum value. All drivers expose the
137 * extension.
138 */
139 return 64;
140
141 case PIPE_CAP_CUBE_MAP_ARRAY:
142 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
143 return 0;
144
145 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
146 /* GL_EXT_texture_buffer minimum value. */
147 return 256;
148
149 case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
150 case PIPE_CAP_TGSI_TEXCOORD:
151 return 0;
152
153 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
154 return 1;
155
156 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
157 case PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE:
158 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
159 return 0;
160
161 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
162 /* GL_EXT_texture_buffer minimum value. */
163 return 65536;
164
165 case PIPE_CAP_MAX_VIEWPORTS:
166 return 1;
167
168 case PIPE_CAP_ENDIANNESS:
169 return PIPE_ENDIAN_LITTLE;
170
171 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
172 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
173 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
174 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
175 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS: /* Enables ARB_texture_gather */
176 case PIPE_CAP_TEXTURE_GATHER_SM5:
177 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
178 case PIPE_CAP_FAKE_SW_MSAA:
179 case PIPE_CAP_TEXTURE_QUERY_LOD:
180 return 0;
181
182 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
183 return -8;
184 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
185 return 7;
186
187 case PIPE_CAP_SAMPLE_SHADING:
188 case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
189 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
190 case PIPE_CAP_MAX_VERTEX_STREAMS:
191 case PIPE_CAP_DRAW_INDIRECT:
192 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
193 return 0;
194
195 case PIPE_CAP_VENDOR_ID:
196 case PIPE_CAP_DEVICE_ID:
197 return 0xffffffff;
198
199 case PIPE_CAP_ACCELERATED:
200 case PIPE_CAP_VIDEO_MEMORY:
201 case PIPE_CAP_UMA:
202 unreachable("driver must implement these.");
203
204 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
205 return 0;
206
207 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
208 /* GL minimum value */
209 return 2048;
210
211 case PIPE_CAP_SAMPLER_VIEW_TARGET:
212 case PIPE_CAP_CLIP_HALFZ:
213 case PIPE_CAP_VERTEXID_NOBASE:
214 case PIPE_CAP_POLYGON_OFFSET_CLAMP:
215 case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
216 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
217 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY:
218 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
219 case PIPE_CAP_DEVICE_PROTECTED_CONTENT:
220 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
221 case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
222 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
223 case PIPE_CAP_DEPTH_BOUNDS_TEST:
224 case PIPE_CAP_TGSI_TXQS:
225 case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
226 case PIPE_CAP_SHAREABLE_SHADERS:
227 case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
228 case PIPE_CAP_CLEAR_TEXTURE:
229 case PIPE_CAP_CLEAR_SCISSORED:
230 case PIPE_CAP_DRAW_PARAMETERS:
231 case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
232 case PIPE_CAP_MULTI_DRAW_INDIRECT:
233 case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
234 case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
235 case PIPE_CAP_TGSI_FS_POINT_IS_SYSVAL:
236 case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
237 return 0;
238
239 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
240 /* Enables GL_ARB_shader_storage_buffer_object */
241 return 0;
242
243 case PIPE_CAP_INVALIDATE_BUFFER:
244 case PIPE_CAP_GENERATE_MIPMAP:
245 case PIPE_CAP_STRING_MARKER:
246 case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
247 case PIPE_CAP_QUERY_BUFFER_OBJECT:
248 case PIPE_CAP_QUERY_MEMORY_INFO: /* Enables GL_ATI_meminfo */
249 return 0;
250
251 case PIPE_CAP_PCI_GROUP:
252 case PIPE_CAP_PCI_BUS:
253 case PIPE_CAP_PCI_DEVICE:
254 case PIPE_CAP_PCI_FUNCTION:
255 unreachable("driver must implement these.");
256
257 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
258 case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
259 case PIPE_CAP_CULL_DISTANCE:
260 case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
261 case PIPE_CAP_TGSI_VOTE:
262 case PIPE_CAP_MAX_WINDOW_RECTANGLES: /* Enables EXT_window_rectangles */
263 case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
264 case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
265 case PIPE_CAP_VIEWPORT_SWIZZLE:
266 case PIPE_CAP_VIEWPORT_MASK:
267 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
268 case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
269 case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
270 case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
271 case PIPE_CAP_NATIVE_FENCE_FD:
272 return 0;
273
274 case PIPE_CAP_RASTERIZER_SUBPIXEL_BITS:
275 return 4; /* GLES 2.0 minimum value */
276
277 case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
278 return 1;
279
280 case PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS:
281 return 0;
282
283 case PIPE_CAP_FBFETCH:
284 case PIPE_CAP_FBFETCH_COHERENT:
285 case PIPE_CAP_BLEND_EQUATION_ADVANCED:
286 case PIPE_CAP_TGSI_MUL_ZERO_WINS:
287 case PIPE_CAP_DOUBLES:
288 case PIPE_CAP_INT64:
289 case PIPE_CAP_INT64_DIVMOD:
290 case PIPE_CAP_TGSI_TEX_TXF_LZ:
291 case PIPE_CAP_TGSI_CLOCK:
292 case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
293 case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
294 case PIPE_CAP_TGSI_BALLOT:
295 case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
296 case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
297 case PIPE_CAP_TGSI_DIV:
298 case PIPE_CAP_NIR_ATOMICS_AS_DEREF:
299 return 0;
300
301 case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
302 /* Drivers generally support this, and it reduces GL overhead just to
303 * throw an error when buffers are mapped.
304 */
305 return 1;
306
307 case PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF:
308 /* Don't unset this unless your driver can do better */
309 return 1;
310
311 case PIPE_CAP_POST_DEPTH_COVERAGE:
312 case PIPE_CAP_BINDLESS_TEXTURE:
313 case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
314 case PIPE_CAP_NIR_COMPACT_ARRAYS:
315 case PIPE_CAP_QUERY_SO_OVERFLOW:
316 case PIPE_CAP_MEMOBJ:
317 case PIPE_CAP_LOAD_CONSTBUF:
318 case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
319 case PIPE_CAP_TILE_RASTER_ORDER:
320 return 0;
321
322 case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
323 /* nonzero overrides defaults */
324 return 0;
325
326 case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
327 case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
328 case PIPE_CAP_CONTEXT_PRIORITY_MASK:
329 case PIPE_CAP_FENCE_SIGNAL:
330 case PIPE_CAP_CONSTBUF0_FLAGS:
331 case PIPE_CAP_PACKED_UNIFORMS:
332 case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
333 case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
334 case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
335 case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
336 case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
337 case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
338 case PIPE_CAP_CONSERVATIVE_RASTER_INNER_COVERAGE:
339 case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
340 case PIPE_CAP_MAX_COMBINED_SHADER_BUFFERS:
341 case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS:
342 case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS:
343 case PIPE_CAP_TGSI_ATOMFADD:
344 case PIPE_CAP_TGSI_SKIP_SHRINK_IO_ARRAYS:
345 case PIPE_CAP_IMAGE_LOAD_FORMATTED:
346 case PIPE_CAP_PREFER_COMPUTE_FOR_MULTIMEDIA:
347 case PIPE_CAP_FRAGMENT_SHADER_INTERLOCK:
348 case PIPE_CAP_CS_DERIVED_SYSTEM_VALUES_SUPPORTED:
349 case PIPE_CAP_ATOMIC_FLOAT_MINMAX:
350 case PIPE_CAP_SHADER_SAMPLES_IDENTICAL:
351 case PIPE_CAP_TGSI_ATOMINC_WRAP:
352 case PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE:
353 case PIPE_CAP_GLSL_ZERO_INIT:
354 return 0;
355
356 case PIPE_CAP_MAX_GS_INVOCATIONS:
357 return 32;
358
359 case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
360 return 1 << 27;
361
362 case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
363 case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
364 return 0;
365
366 case PIPE_CAP_MAX_VERTEX_ELEMENT_SRC_OFFSET:
367 return 2047;
368
369 case PIPE_CAP_SURFACE_SAMPLE_COUNT:
370 return 0;
371 case PIPE_CAP_DEST_SURFACE_SRGB_CONTROL:
372 return 1;
373
374 case PIPE_CAP_MAX_VARYINGS:
375 return 8;
376
377 case PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK:
378 return 0;
379
380 case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
381 return 0;
382
383 case PIPE_CAP_THROTTLE:
384 return 1;
385
386 case PIPE_CAP_TEXTURE_SHADOW_LOD:
387 return 0;
388
389 case PIPE_CAP_GL_SPIRV:
390 case PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS:
391 return 0;
392
393 case PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION:
394 return 0;
395
396 case PIPE_CAP_DMABUF:
397 #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD)
398 return 1;
399 #else
400 return 0;
401 #endif
402
403 case PIPE_CAP_TEXTURE_SHADOW_MAP: /* Enables ARB_shadow */
404 return 1;
405
406 case PIPE_CAP_FLATSHADE:
407 case PIPE_CAP_ALPHA_TEST:
408 case PIPE_CAP_POINT_SIZE_FIXED:
409 case PIPE_CAP_TWO_SIDED_COLOR:
410 case PIPE_CAP_CLIP_PLANES:
411 return 1;
412
413 case PIPE_CAP_MAX_VERTEX_BUFFERS:
414 return 16;
415
416 case PIPE_CAP_OPENCL_INTEGER_FUNCTIONS:
417 case PIPE_CAP_INTEGER_MULTIPLY_32X16:
418 case PIPE_CAP_DRAW_INFO_START_WITH_USER_INDICES:
419 return 0;
420 case PIPE_CAP_NIR_IMAGES_AS_DEREF:
421 return 1;
422
423 case PIPE_CAP_FRONTEND_NOOP:
424 /* Enables INTEL_blackhole_render */
425 return 0;
426
427 case PIPE_CAP_PACKED_STREAM_OUTPUT:
428 return 1;
429
430 case PIPE_CAP_VIEWPORT_TRANSFORM_LOWERED:
431 case PIPE_CAP_PSIZ_CLAMPED:
432 case PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE:
433 return 0;
434
435 case PIPE_CAP_GL_BEGIN_END_BUFFER_SIZE:
436 return 512 * 1024;
437
438 case PIPE_CAP_SYSTEM_SVM:
439 case PIPE_CAP_ALPHA_TO_COVERAGE_DITHER_CONTROL:
440 case PIPE_CAP_NO_CLIP_ON_COPY_TEX:
441 case PIPE_CAP_MAX_TEXTURE_MB:
442 return 0;
443
444 case PIPE_CAP_SHADER_ATOMIC_INT64:
445 return 0;
446
447 default:
448 unreachable("bad PIPE_CAP_*");
449 }
450 }
451