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 */
34int
35u_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_MAX_RENDER_TARGETS:
47      return 1;
48
49   case PIPE_CAP_OCCLUSION_QUERY:
50   case PIPE_CAP_QUERY_TIME_ELAPSED:
51   case PIPE_CAP_TEXTURE_SWIZZLE:
52      return 0;
53
54   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
55   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
56   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
57      unreachable("driver must implement these.");
58
59   case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
60   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
61   case PIPE_CAP_SM3:
62   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: /* enables EXT_transform_feedback */
63   case PIPE_CAP_PRIMITIVE_RESTART:
64   case PIPE_CAP_INDEP_BLEND_ENABLE:
65   case PIPE_CAP_INDEP_BLEND_FUNC:
66   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: /* Enables GL_EXT_texture_array */
67   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
68   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
69   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
70   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
71   case PIPE_CAP_DEPTH_CLIP_DISABLE:
72   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
73   case PIPE_CAP_SHADER_STENCIL_EXPORT:
74   case PIPE_CAP_TGSI_INSTANCEID:
75   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
76   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
77   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
78   case PIPE_CAP_SEAMLESS_CUBE_MAP:
79   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
80   case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
81      return 0;
82
83   case PIPE_CAP_MIN_TEXEL_OFFSET:
84      /* GL 3.x minimum value. */
85      return -8;
86   case PIPE_CAP_MAX_TEXEL_OFFSET:
87      return 7;
88
89   case PIPE_CAP_CONDITIONAL_RENDER:
90   case PIPE_CAP_TEXTURE_BARRIER:
91      return 0;
92
93   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
94      /* GL_EXT_transform_feedback minimum value. */
95      return 4;
96   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
97      return 64;
98
99   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
100   case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
101   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
102   case PIPE_CAP_VERTEX_COLOR_CLAMPED:
103      return 0;
104
105   case PIPE_CAP_GLSL_FEATURE_LEVEL:
106   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
107      /* Minimum GLSL level implemented by gallium drivers. */
108      return 120;
109
110   case PIPE_CAP_ESSL_FEATURE_LEVEL:
111      /* Tell state-tracker to fallback to PIPE_CAP_GLSL_FEATURE_LEVEL */
112      return 0;
113
114   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
115   case PIPE_CAP_USER_VERTEX_BUFFERS:
116   case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
117   case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
118   case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
119   case PIPE_CAP_COMPUTE:
120      return 0;
121
122   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
123      /* GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT default value. */
124      return 1;
125
126   case PIPE_CAP_START_INSTANCE:
127   case PIPE_CAP_QUERY_TIMESTAMP:
128   case PIPE_CAP_TEXTURE_MULTISAMPLE:
129      return 0;
130
131   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
132      /* GL_ARB_map_buffer_alignment minimum value. All drivers expose the
133       * extension.
134       */
135      return 64;
136
137   case PIPE_CAP_CUBE_MAP_ARRAY:
138   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
139      return 0;
140
141   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
142      /* GL_EXT_texture_buffer minimum value. */
143      return 256;
144
145   case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
146   case PIPE_CAP_TGSI_TEXCOORD:
147      return 0;
148
149   case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
150      return 1;
151
152   case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
153   case PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE:
154   case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
155      return 0;
156
157   case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
158      /* GL_EXT_texture_buffer minimum value. */
159      return 65536;
160
161   case PIPE_CAP_MAX_VIEWPORTS:
162      return 1;
163
164   case PIPE_CAP_ENDIANNESS:
165      return PIPE_ENDIAN_LITTLE;
166
167   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
168   case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
169   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
170   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
171   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS: /* Enables ARB_texture_gather */
172   case PIPE_CAP_TEXTURE_GATHER_SM5:
173   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
174   case PIPE_CAP_FAKE_SW_MSAA:
175   case PIPE_CAP_TEXTURE_QUERY_LOD:
176      return 0;
177
178   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
179      return -8;
180   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
181      return 7;
182
183   case PIPE_CAP_SAMPLE_SHADING:
184   case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
185   case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
186   case PIPE_CAP_MAX_VERTEX_STREAMS:
187   case PIPE_CAP_DRAW_INDIRECT:
188   case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
189      return 0;
190
191   case PIPE_CAP_VENDOR_ID:
192   case PIPE_CAP_DEVICE_ID:
193      return 0xffffffff;
194
195   case PIPE_CAP_ACCELERATED:
196   case PIPE_CAP_VIDEO_MEMORY:
197   case PIPE_CAP_UMA:
198      unreachable("driver must implement these.");
199
200   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
201      return 0;
202
203   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
204      /* GL minimum value */
205      return 2048;
206
207   case PIPE_CAP_SAMPLER_VIEW_TARGET:
208   case PIPE_CAP_CLIP_HALFZ:
209   case PIPE_CAP_VERTEXID_NOBASE:
210   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
211   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
212   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
213   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
214   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
215   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
216   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
217   case PIPE_CAP_DEPTH_BOUNDS_TEST:
218   case PIPE_CAP_TGSI_TXQS:
219   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
220   case PIPE_CAP_SHAREABLE_SHADERS:
221   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
222   case PIPE_CAP_CLEAR_TEXTURE:
223   case PIPE_CAP_DRAW_PARAMETERS:
224   case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
225   case PIPE_CAP_MULTI_DRAW_INDIRECT:
226   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
227   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
228   case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
229      return 0;
230
231   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
232      /* Enables GL_ARB_shader_storage_buffer_object */
233      return 0;
234
235   case PIPE_CAP_INVALIDATE_BUFFER:
236   case PIPE_CAP_GENERATE_MIPMAP:
237   case PIPE_CAP_STRING_MARKER:
238   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
239   case PIPE_CAP_QUERY_BUFFER_OBJECT:
240   case PIPE_CAP_QUERY_MEMORY_INFO: /* Enables GL_ATI_meminfo */
241      return 0;
242
243   case PIPE_CAP_PCI_GROUP:
244   case PIPE_CAP_PCI_BUS:
245   case PIPE_CAP_PCI_DEVICE:
246   case PIPE_CAP_PCI_FUNCTION:
247      unreachable("driver must implement these.");
248
249   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
250   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
251   case PIPE_CAP_CULL_DISTANCE:
252   case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
253   case PIPE_CAP_TGSI_VOTE:
254   case PIPE_CAP_MAX_WINDOW_RECTANGLES: /* Enables EXT_window_rectangles */
255   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
256   case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
257   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
258   case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
259   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
260   case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
261   case PIPE_CAP_NATIVE_FENCE_FD:
262      return 0;
263
264   case PIPE_CAP_RASTERIZER_SUBPIXEL_BITS:
265      return 4; /* GLES 2.0 minimum value */
266
267   case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
268      return 1;
269
270   case PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS:
271      return 0;
272
273   case PIPE_CAP_TGSI_FS_FBFETCH:
274   case PIPE_CAP_TGSI_MUL_ZERO_WINS:
275   case PIPE_CAP_DOUBLES:
276   case PIPE_CAP_INT64:
277   case PIPE_CAP_INT64_DIVMOD:
278   case PIPE_CAP_TGSI_TEX_TXF_LZ:
279   case PIPE_CAP_TGSI_CLOCK:
280   case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
281   case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
282   case PIPE_CAP_TGSI_BALLOT:
283   case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
284   case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
285   case PIPE_CAP_TGSI_DIV:
286      return 0;
287
288   case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
289      /* Drivers generally support this, and it reduces GL overhead just to
290       * throw an error when buffers are mapped.
291       */
292      return 1;
293
294   case PIPE_CAP_POST_DEPTH_COVERAGE:
295   case PIPE_CAP_BINDLESS_TEXTURE:
296   case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
297   case PIPE_CAP_NIR_COMPACT_ARRAYS:
298   case PIPE_CAP_QUERY_SO_OVERFLOW:
299   case PIPE_CAP_MEMOBJ:
300   case PIPE_CAP_LOAD_CONSTBUF:
301   case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
302   case PIPE_CAP_TILE_RASTER_ORDER:
303      return 0;
304
305   case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
306      /* nonzero overrides defaults */
307      return 0;
308
309   case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
310   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
311   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
312   case PIPE_CAP_FENCE_SIGNAL:
313   case PIPE_CAP_CONSTBUF0_FLAGS:
314   case PIPE_CAP_PACKED_UNIFORMS:
315   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
316   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
317   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
318   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
319   case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
320   case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
321   case PIPE_CAP_CONSERVATIVE_RASTER_INNER_COVERAGE:
322   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
323   case PIPE_CAP_MAX_COMBINED_SHADER_BUFFERS:
324   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS:
325   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS:
326   case PIPE_CAP_TGSI_ATOMFADD:
327   case PIPE_CAP_TGSI_SKIP_SHRINK_IO_ARRAYS:
328   case PIPE_CAP_IMAGE_LOAD_FORMATTED:
329   case PIPE_CAP_PREFER_COMPUTE_FOR_MULTIMEDIA:
330      return 0;
331
332   case PIPE_CAP_MAX_GS_INVOCATIONS:
333      return 32;
334
335   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
336      return 1 << 27;
337
338   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
339   case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
340      return 0;
341
342   case PIPE_CAP_MAX_VERTEX_ELEMENT_SRC_OFFSET:
343      return 2047;
344
345   case PIPE_CAP_SURFACE_SAMPLE_COUNT:
346      return 0;
347   case PIPE_CAP_DEST_SURFACE_SRGB_CONTROL:
348      return 1;
349
350   case PIPE_CAP_MAX_VARYINGS:
351      return 8;
352
353   case PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK:
354      return 0;
355
356   case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
357      return 0;
358
359   case PIPE_CAP_MAX_FRAMES_IN_FLIGHT:
360      return 1;
361
362   case PIPE_CAP_DMABUF:
363#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD)
364      return 1;
365#else
366      return 0;
367#endif
368
369   default:
370      unreachable("bad PIPE_CAP_*");
371   }
372}
373