1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "compiler/nir/nir.h"
30bf215546Sopenharmony_ci#include "util/u_memory.h"
31bf215546Sopenharmony_ci#include "util/format/u_format.h"
32bf215546Sopenharmony_ci#include "util/format/u_format_s3tc.h"
33bf215546Sopenharmony_ci#include "util/u_screen.h"
34bf215546Sopenharmony_ci#include "util/u_video.h"
35bf215546Sopenharmony_ci#include "util/os_misc.h"
36bf215546Sopenharmony_ci#include "util/os_time.h"
37bf215546Sopenharmony_ci#include "pipe/p_defines.h"
38bf215546Sopenharmony_ci#include "pipe/p_screen.h"
39bf215546Sopenharmony_ci#include "draw/draw_context.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#include "frontend/sw_winsys.h"
42bf215546Sopenharmony_ci#include "tgsi/tgsi_exec.h"
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci#include "sp_texture.h"
45bf215546Sopenharmony_ci#include "sp_screen.h"
46bf215546Sopenharmony_ci#include "sp_context.h"
47bf215546Sopenharmony_ci#include "sp_fence.h"
48bf215546Sopenharmony_ci#include "sp_public.h"
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistatic const struct debug_named_value sp_debug_options[] = {
51bf215546Sopenharmony_ci   {"vs",        SP_DBG_VS,         "dump vertex shader assembly to stderr"},
52bf215546Sopenharmony_ci   {"gs",        SP_DBG_GS,         "dump geometry shader assembly to stderr"},
53bf215546Sopenharmony_ci   {"fs",        SP_DBG_FS,         "dump fragment shader assembly to stderr"},
54bf215546Sopenharmony_ci   {"cs",        SP_DBG_CS,         "dump compute shader assembly to stderr"},
55bf215546Sopenharmony_ci   {"no_rast",   SP_DBG_NO_RAST,    "no-ops rasterization, for profiling purposes"},
56bf215546Sopenharmony_ci   {"use_llvm",  SP_DBG_USE_LLVM,   "Use LLVM if available for shaders"},
57bf215546Sopenharmony_ci   {"use_tgsi",  SP_DBG_USE_TGSI,   "Request TGSI from the API instead of NIR"},
58bf215546Sopenharmony_ci   DEBUG_NAMED_VALUE_END
59bf215546Sopenharmony_ci};
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ciint sp_debug;
62bf215546Sopenharmony_ciDEBUG_GET_ONCE_FLAGS_OPTION(sp_debug, "SOFTPIPE_DEBUG", sp_debug_options, 0)
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_cistatic const char *
65bf215546Sopenharmony_cisoftpipe_get_vendor(struct pipe_screen *screen)
66bf215546Sopenharmony_ci{
67bf215546Sopenharmony_ci   return "Mesa/X.org";
68bf215546Sopenharmony_ci}
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_cistatic const char *
72bf215546Sopenharmony_cisoftpipe_get_name(struct pipe_screen *screen)
73bf215546Sopenharmony_ci{
74bf215546Sopenharmony_ci   return "softpipe";
75bf215546Sopenharmony_ci}
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_cistatic const nir_shader_compiler_options sp_compiler_options = {
78bf215546Sopenharmony_ci   .fdot_replicates = true,
79bf215546Sopenharmony_ci   .fuse_ffma32 = true,
80bf215546Sopenharmony_ci   .fuse_ffma64 = true,
81bf215546Sopenharmony_ci   .lower_extract_byte = true,
82bf215546Sopenharmony_ci   .lower_extract_word = true,
83bf215546Sopenharmony_ci   .lower_insert_byte = true,
84bf215546Sopenharmony_ci   .lower_insert_word = true,
85bf215546Sopenharmony_ci   .lower_fdph = true,
86bf215546Sopenharmony_ci   .lower_flrp64 = true,
87bf215546Sopenharmony_ci   .lower_fmod = true,
88bf215546Sopenharmony_ci   .lower_rotate = true,
89bf215546Sopenharmony_ci   .lower_uniforms_to_ubo = true,
90bf215546Sopenharmony_ci   .lower_vector_cmp = true,
91bf215546Sopenharmony_ci   .lower_int64_options = nir_lower_imul_2x32_64,
92bf215546Sopenharmony_ci   .max_unroll_iterations = 32,
93bf215546Sopenharmony_ci   .use_interpolated_input_intrinsics = true,
94bf215546Sopenharmony_ci};
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_cistatic const void *
97bf215546Sopenharmony_cisoftpipe_get_compiler_options(struct pipe_screen *pscreen,
98bf215546Sopenharmony_ci                              enum pipe_shader_ir ir,
99bf215546Sopenharmony_ci                              enum pipe_shader_type shader)
100bf215546Sopenharmony_ci{
101bf215546Sopenharmony_ci   assert(ir == PIPE_SHADER_IR_NIR);
102bf215546Sopenharmony_ci   return &sp_compiler_options;
103bf215546Sopenharmony_ci}
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_cistatic int
106bf215546Sopenharmony_cisoftpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
107bf215546Sopenharmony_ci{
108bf215546Sopenharmony_ci   struct softpipe_screen *sp_screen = softpipe_screen(screen);
109bf215546Sopenharmony_ci   switch (param) {
110bf215546Sopenharmony_ci   case PIPE_CAP_NPOT_TEXTURES:
111bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
112bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
113bf215546Sopenharmony_ci      return 1;
114bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
115bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
116bf215546Sopenharmony_ci      return 1;
117bf215546Sopenharmony_ci   case PIPE_CAP_ANISOTROPIC_FILTER:
118bf215546Sopenharmony_ci      return 1;
119bf215546Sopenharmony_ci   case PIPE_CAP_POINT_SPRITE:
120bf215546Sopenharmony_ci      return 1;
121bf215546Sopenharmony_ci   case PIPE_CAP_MAX_RENDER_TARGETS:
122bf215546Sopenharmony_ci      return PIPE_MAX_COLOR_BUFS;
123bf215546Sopenharmony_ci   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
124bf215546Sopenharmony_ci      return 1;
125bf215546Sopenharmony_ci   case PIPE_CAP_OCCLUSION_QUERY:
126bf215546Sopenharmony_ci      return 1;
127bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIME_ELAPSED:
128bf215546Sopenharmony_ci      return 1;
129bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
130bf215546Sopenharmony_ci      return 1;
131bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
132bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
133bf215546Sopenharmony_ci      return 1;
134bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SWIZZLE:
135bf215546Sopenharmony_ci      return 1;
136bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
137bf215546Sopenharmony_ci      return 1 << (SP_MAX_TEXTURE_2D_LEVELS - 1);
138bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
139bf215546Sopenharmony_ci      return SP_MAX_TEXTURE_3D_LEVELS;
140bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
141bf215546Sopenharmony_ci      return SP_MAX_TEXTURE_CUBE_LEVELS;
142bf215546Sopenharmony_ci   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
143bf215546Sopenharmony_ci   case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
144bf215546Sopenharmony_ci      return 1;
145bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_ENABLE:
146bf215546Sopenharmony_ci      return 1;
147bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_FUNC:
148bf215546Sopenharmony_ci      return 1;
149bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
150bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_LOWER_LEFT:
151bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
152bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_INTEGER:
153bf215546Sopenharmony_ci      return 1;
154bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE:
155bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_BOUNDS_TEST:
156bf215546Sopenharmony_ci      return 1;
157bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
158bf215546Sopenharmony_ci      return PIPE_MAX_SO_BUFFERS;
159bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
160bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
161bf215546Sopenharmony_ci      return 16*4;
162bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
163bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
164bf215546Sopenharmony_ci      return 1024;
165bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_STREAMS:
166bf215546Sopenharmony_ci      if (sp_screen->use_llvm)
167bf215546Sopenharmony_ci         return 1;
168bf215546Sopenharmony_ci      else
169bf215546Sopenharmony_ci         return PIPE_MAX_VERTEX_STREAMS;
170bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
171bf215546Sopenharmony_ci      return 2048;
172bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART:
173bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
174bf215546Sopenharmony_ci      return 1;
175bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_STENCIL_EXPORT:
176bf215546Sopenharmony_ci      return 1;
177bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_ATOMIC_FLOAT_ADD:
178bf215546Sopenharmony_ci   case PIPE_CAP_VS_INSTANCEID:
179bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
180bf215546Sopenharmony_ci   case PIPE_CAP_START_INSTANCE:
181bf215546Sopenharmony_ci      return 1;
182bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP:
183bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
184bf215546Sopenharmony_ci      return 1;
185bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
186bf215546Sopenharmony_ci      return 256; /* for GL3 */
187bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXEL_OFFSET:
188bf215546Sopenharmony_ci      return -8;
189bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_OFFSET:
190bf215546Sopenharmony_ci      return 7;
191bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER:
192bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
193bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: /* draw module */
194bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_CLAMPED: /* draw module */
195bf215546Sopenharmony_ci      return 1;
196bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
197bf215546Sopenharmony_ci      return 1;
198bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL:
199bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
200bf215546Sopenharmony_ci      return 400;
201bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE:
202bf215546Sopenharmony_ci      return 1;
203bf215546Sopenharmony_ci   case PIPE_CAP_USER_VERTEX_BUFFERS:
204bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
205bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
206bf215546Sopenharmony_ci   case PIPE_CAP_VS_LAYER_VIEWPORT:
207bf215546Sopenharmony_ci   case PIPE_CAP_DOUBLES:
208bf215546Sopenharmony_ci   case PIPE_CAP_INT64:
209bf215546Sopenharmony_ci   case PIPE_CAP_INT64_DIVMOD:
210bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_DIV:
211bf215546Sopenharmony_ci      return 1;
212bf215546Sopenharmony_ci   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
213bf215546Sopenharmony_ci      return 16;
214bf215546Sopenharmony_ci   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
215bf215546Sopenharmony_ci      return 64;
216bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIMESTAMP:
217bf215546Sopenharmony_ci   case PIPE_CAP_CUBE_MAP_ARRAY:
218bf215546Sopenharmony_ci      return 1;
219bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
220bf215546Sopenharmony_ci      return 1;
221bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
222bf215546Sopenharmony_ci      return 65536;
223bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
224bf215546Sopenharmony_ci      return 16;
225bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_TRANSFER_MODES:
226bf215546Sopenharmony_ci      return 0;
227bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VIEWPORTS:
228bf215546Sopenharmony_ci      return PIPE_MAX_VIEWPORTS;
229bf215546Sopenharmony_ci   case PIPE_CAP_ENDIANNESS:
230bf215546Sopenharmony_ci      return PIPE_ENDIAN_NATIVE;
231bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
232bf215546Sopenharmony_ci      return 4;
233bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_GATHER_SM5:
234bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_LOD:
235bf215546Sopenharmony_ci      return 1;
236bf215546Sopenharmony_ci   case PIPE_CAP_VS_WINDOW_SPACE_POSITION:
237bf215546Sopenharmony_ci      return 1;
238bf215546Sopenharmony_ci   case PIPE_CAP_FS_FINE_DERIVATIVE:
239bf215546Sopenharmony_ci      return 1;
240bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_VIEW_TARGET:
241bf215546Sopenharmony_ci      return 1;
242bf215546Sopenharmony_ci   case PIPE_CAP_FAKE_SW_MSAA:
243bf215546Sopenharmony_ci      return 1;
244bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
245bf215546Sopenharmony_ci      return -32;
246bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
247bf215546Sopenharmony_ci      return 31;
248bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_INDIRECT:
249bf215546Sopenharmony_ci      return 1;
250bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_SO_OVERFLOW:
251bf215546Sopenharmony_ci      return 1;
252bf215546Sopenharmony_ci   case PIPE_CAP_NIR_IMAGES_AS_DEREF:
253bf215546Sopenharmony_ci      return 0;
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_ci   case PIPE_CAP_SHAREABLE_SHADERS:
256bf215546Sopenharmony_ci      /* Can't expose shareable shaders because the draw shaders reference the
257bf215546Sopenharmony_ci       * draw module's state, which is per-context.
258bf215546Sopenharmony_ci       */
259bf215546Sopenharmony_ci      return 0;
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci   case PIPE_CAP_VENDOR_ID:
262bf215546Sopenharmony_ci      return 0xFFFFFFFF;
263bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_ID:
264bf215546Sopenharmony_ci      return 0xFFFFFFFF;
265bf215546Sopenharmony_ci   case PIPE_CAP_ACCELERATED:
266bf215546Sopenharmony_ci      return 0;
267bf215546Sopenharmony_ci   case PIPE_CAP_VIDEO_MEMORY: {
268bf215546Sopenharmony_ci      /* XXX: Do we want to return the full amount fo system memory ? */
269bf215546Sopenharmony_ci      uint64_t system_memory;
270bf215546Sopenharmony_ci
271bf215546Sopenharmony_ci      if (!os_get_total_physical_memory(&system_memory))
272bf215546Sopenharmony_ci         return 0;
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_ci      if (sizeof(void *) == 4)
275bf215546Sopenharmony_ci         /* Cap to 2 GB on 32 bits system. We do this because softpipe does
276bf215546Sopenharmony_ci          * eat application memory, which is quite limited on 32 bits. App
277bf215546Sopenharmony_ci          * shouldn't expect too much available memory. */
278bf215546Sopenharmony_ci         system_memory = MIN2(system_memory, 2048 << 20);
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci      return (int)(system_memory >> 20);
281bf215546Sopenharmony_ci   }
282bf215546Sopenharmony_ci   case PIPE_CAP_UMA:
283bf215546Sopenharmony_ci      return 0;
284bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
285bf215546Sopenharmony_ci      return 1;
286bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_HALFZ:
287bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
288bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
289bf215546Sopenharmony_ci      return 1;
290bf215546Sopenharmony_ci   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
291bf215546Sopenharmony_ci   case PIPE_CAP_CULL_DISTANCE:
292bf215546Sopenharmony_ci   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
293bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_ARRAY_COMPONENTS:
294bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEXCOORD:
295bf215546Sopenharmony_ci      return 1;
296bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_TEXTURE:
297bf215546Sopenharmony_ci      return 1;
298bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VARYINGS:
299bf215546Sopenharmony_ci      return TGSI_EXEC_MAX_INPUT_ATTRIBS;
300bf215546Sopenharmony_ci   case PIPE_CAP_PCI_GROUP:
301bf215546Sopenharmony_ci   case PIPE_CAP_PCI_BUS:
302bf215546Sopenharmony_ci   case PIPE_CAP_PCI_DEVICE:
303bf215546Sopenharmony_ci   case PIPE_CAP_PCI_FUNCTION:
304bf215546Sopenharmony_ci      return 0;
305bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GS_INVOCATIONS:
306bf215546Sopenharmony_ci      return 32;
307bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
308bf215546Sopenharmony_ci      return 1 << 27;
309bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
310bf215546Sopenharmony_ci      return 4;
311bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_STORE_FORMATTED:
312bf215546Sopenharmony_ci      return 1;
313bf215546Sopenharmony_ci   default:
314bf215546Sopenharmony_ci      return u_pipe_screen_get_param_defaults(screen, param);
315bf215546Sopenharmony_ci   }
316bf215546Sopenharmony_ci}
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_cistatic int
319bf215546Sopenharmony_cisoftpipe_get_shader_param(struct pipe_screen *screen,
320bf215546Sopenharmony_ci                          enum pipe_shader_type shader,
321bf215546Sopenharmony_ci                          enum pipe_shader_cap param)
322bf215546Sopenharmony_ci{
323bf215546Sopenharmony_ci   struct softpipe_screen *sp_screen = softpipe_screen(screen);
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci   switch (param) {
326bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_PREFERRED_IR:
327bf215546Sopenharmony_ci      return (sp_debug & SP_DBG_USE_TGSI) ? PIPE_SHADER_IR_TGSI : PIPE_SHADER_IR_NIR;
328bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUPPORTED_IRS:
329bf215546Sopenharmony_ci      return (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_TGSI);
330bf215546Sopenharmony_ci   default:
331bf215546Sopenharmony_ci      break;
332bf215546Sopenharmony_ci   }
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_ci   switch(shader)
335bf215546Sopenharmony_ci   {
336bf215546Sopenharmony_ci   case PIPE_SHADER_FRAGMENT:
337bf215546Sopenharmony_ci      return tgsi_exec_get_shader_param(param);
338bf215546Sopenharmony_ci   case PIPE_SHADER_COMPUTE:
339bf215546Sopenharmony_ci      return tgsi_exec_get_shader_param(param);
340bf215546Sopenharmony_ci   case PIPE_SHADER_VERTEX:
341bf215546Sopenharmony_ci   case PIPE_SHADER_GEOMETRY:
342bf215546Sopenharmony_ci      if (sp_screen->use_llvm)
343bf215546Sopenharmony_ci         return draw_get_shader_param(shader, param);
344bf215546Sopenharmony_ci      else
345bf215546Sopenharmony_ci         return draw_get_shader_param_no_llvm(shader, param);
346bf215546Sopenharmony_ci   default:
347bf215546Sopenharmony_ci      return 0;
348bf215546Sopenharmony_ci   }
349bf215546Sopenharmony_ci}
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_cistatic float
352bf215546Sopenharmony_cisoftpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
353bf215546Sopenharmony_ci{
354bf215546Sopenharmony_ci   switch (param) {
355bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH:
356bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH_AA:
357bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE:
358bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE_AA:
359bf215546Sopenharmony_ci      return 1;
360bf215546Sopenharmony_ci   case PIPE_CAPF_POINT_SIZE_GRANULARITY:
361bf215546Sopenharmony_ci   case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
362bf215546Sopenharmony_ci      return 0.1;
363bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH:
364bf215546Sopenharmony_ci      FALLTHROUGH;
365bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
366bf215546Sopenharmony_ci      return 255.0; /* arbitrary */
367bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE:
368bf215546Sopenharmony_ci      FALLTHROUGH;
369bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE_AA:
370bf215546Sopenharmony_ci      return 255.0; /* arbitrary */
371bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
372bf215546Sopenharmony_ci      return 16.0;
373bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
374bf215546Sopenharmony_ci      return 16.0; /* arbitrary */
375bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
376bf215546Sopenharmony_ci      return 0.0;
377bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
378bf215546Sopenharmony_ci      return 0.0;
379bf215546Sopenharmony_ci   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
380bf215546Sopenharmony_ci      return 0.0;
381bf215546Sopenharmony_ci   }
382bf215546Sopenharmony_ci   /* should only get here on unhandled cases */
383bf215546Sopenharmony_ci   debug_printf("Unexpected PIPE_CAPF %d query\n", param);
384bf215546Sopenharmony_ci   return 0.0;
385bf215546Sopenharmony_ci}
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci/**
388bf215546Sopenharmony_ci * Query format support for creating a texture, drawing surface, etc.
389bf215546Sopenharmony_ci * \param format  the format to test
390bf215546Sopenharmony_ci * \param type  one of PIPE_TEXTURE, PIPE_SURFACE
391bf215546Sopenharmony_ci */
392bf215546Sopenharmony_cistatic bool
393bf215546Sopenharmony_cisoftpipe_is_format_supported( struct pipe_screen *screen,
394bf215546Sopenharmony_ci                              enum pipe_format format,
395bf215546Sopenharmony_ci                              enum pipe_texture_target target,
396bf215546Sopenharmony_ci                              unsigned sample_count,
397bf215546Sopenharmony_ci                              unsigned storage_sample_count,
398bf215546Sopenharmony_ci                              unsigned bind)
399bf215546Sopenharmony_ci{
400bf215546Sopenharmony_ci   struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
401bf215546Sopenharmony_ci   const struct util_format_description *format_desc;
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci   assert(target == PIPE_BUFFER ||
404bf215546Sopenharmony_ci          target == PIPE_TEXTURE_1D ||
405bf215546Sopenharmony_ci          target == PIPE_TEXTURE_1D_ARRAY ||
406bf215546Sopenharmony_ci          target == PIPE_TEXTURE_2D ||
407bf215546Sopenharmony_ci          target == PIPE_TEXTURE_2D_ARRAY ||
408bf215546Sopenharmony_ci          target == PIPE_TEXTURE_RECT ||
409bf215546Sopenharmony_ci          target == PIPE_TEXTURE_3D ||
410bf215546Sopenharmony_ci          target == PIPE_TEXTURE_CUBE ||
411bf215546Sopenharmony_ci          target == PIPE_TEXTURE_CUBE_ARRAY);
412bf215546Sopenharmony_ci
413bf215546Sopenharmony_ci   if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
414bf215546Sopenharmony_ci      return false;
415bf215546Sopenharmony_ci
416bf215546Sopenharmony_ci   format_desc = util_format_description(format);
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci   if (sample_count > 1)
419bf215546Sopenharmony_ci      return false;
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_ci   if (bind & (PIPE_BIND_DISPLAY_TARGET |
422bf215546Sopenharmony_ci               PIPE_BIND_SCANOUT |
423bf215546Sopenharmony_ci               PIPE_BIND_SHARED)) {
424bf215546Sopenharmony_ci      if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
425bf215546Sopenharmony_ci         return false;
426bf215546Sopenharmony_ci   }
427bf215546Sopenharmony_ci
428bf215546Sopenharmony_ci   if (bind & PIPE_BIND_RENDER_TARGET) {
429bf215546Sopenharmony_ci      if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
430bf215546Sopenharmony_ci         return false;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci      /*
433bf215546Sopenharmony_ci       * Although possible, it is unnatural to render into compressed or YUV
434bf215546Sopenharmony_ci       * surfaces. So disable these here to avoid going into weird paths
435bf215546Sopenharmony_ci       * inside gallium frontends.
436bf215546Sopenharmony_ci       */
437bf215546Sopenharmony_ci      if (format_desc->block.width != 1 ||
438bf215546Sopenharmony_ci          format_desc->block.height != 1)
439bf215546Sopenharmony_ci         return false;
440bf215546Sopenharmony_ci   }
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_ci   if (bind & PIPE_BIND_DEPTH_STENCIL) {
443bf215546Sopenharmony_ci      if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
444bf215546Sopenharmony_ci         return false;
445bf215546Sopenharmony_ci   }
446bf215546Sopenharmony_ci
447bf215546Sopenharmony_ci   if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC ||
448bf215546Sopenharmony_ci       format_desc->layout == UTIL_FORMAT_LAYOUT_ATC) {
449bf215546Sopenharmony_ci      /* Software decoding is not hooked up. */
450bf215546Sopenharmony_ci      return false;
451bf215546Sopenharmony_ci   }
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) &&
454bf215546Sopenharmony_ci       ((bind & PIPE_BIND_DISPLAY_TARGET) == 0) &&
455bf215546Sopenharmony_ci       target != PIPE_BUFFER) {
456bf215546Sopenharmony_ci      const struct util_format_description *desc =
457bf215546Sopenharmony_ci         util_format_description(format);
458bf215546Sopenharmony_ci      if (desc->nr_channels == 3 && desc->is_array) {
459bf215546Sopenharmony_ci         /* Don't support any 3-component formats for rendering/texturing
460bf215546Sopenharmony_ci          * since we don't support the corresponding 8-bit 3 channel UNORM
461bf215546Sopenharmony_ci          * formats.  This allows us to support GL_ARB_copy_image between
462bf215546Sopenharmony_ci          * GL_RGB8 and GL_RGB8UI, for example.  Otherwise, we may be asked to
463bf215546Sopenharmony_ci          * do a resource copy between PIPE_FORMAT_R8G8B8_UINT and
464bf215546Sopenharmony_ci          * PIPE_FORMAT_R8G8B8X8_UNORM, for example, which will not work
465bf215546Sopenharmony_ci          * (different bpp).
466bf215546Sopenharmony_ci          */
467bf215546Sopenharmony_ci         return false;
468bf215546Sopenharmony_ci      }
469bf215546Sopenharmony_ci   }
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_ci   if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
472bf215546Sopenharmony_ci       format != PIPE_FORMAT_ETC1_RGB8)
473bf215546Sopenharmony_ci      return false;
474bf215546Sopenharmony_ci
475bf215546Sopenharmony_ci   /*
476bf215546Sopenharmony_ci    * All other operations (sampling, transfer, etc).
477bf215546Sopenharmony_ci    */
478bf215546Sopenharmony_ci
479bf215546Sopenharmony_ci   /*
480bf215546Sopenharmony_ci    * Everything else should be supported by u_format.
481bf215546Sopenharmony_ci    */
482bf215546Sopenharmony_ci   return true;
483bf215546Sopenharmony_ci}
484bf215546Sopenharmony_ci
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_cistatic void
487bf215546Sopenharmony_cisoftpipe_destroy_screen( struct pipe_screen *screen )
488bf215546Sopenharmony_ci{
489bf215546Sopenharmony_ci   struct softpipe_screen *sp_screen = softpipe_screen(screen);
490bf215546Sopenharmony_ci   struct sw_winsys *winsys = sp_screen->winsys;
491bf215546Sopenharmony_ci
492bf215546Sopenharmony_ci   if(winsys->destroy)
493bf215546Sopenharmony_ci      winsys->destroy(winsys);
494bf215546Sopenharmony_ci
495bf215546Sopenharmony_ci   FREE(screen);
496bf215546Sopenharmony_ci}
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ci
499bf215546Sopenharmony_ci/* This is often overriden by the co-state tracker.
500bf215546Sopenharmony_ci */
501bf215546Sopenharmony_cistatic void
502bf215546Sopenharmony_cisoftpipe_flush_frontbuffer(struct pipe_screen *_screen,
503bf215546Sopenharmony_ci                           struct pipe_context *pipe,
504bf215546Sopenharmony_ci                           struct pipe_resource *resource,
505bf215546Sopenharmony_ci                           unsigned level, unsigned layer,
506bf215546Sopenharmony_ci                           void *context_private,
507bf215546Sopenharmony_ci                           struct pipe_box *sub_box)
508bf215546Sopenharmony_ci{
509bf215546Sopenharmony_ci   struct softpipe_screen *screen = softpipe_screen(_screen);
510bf215546Sopenharmony_ci   struct sw_winsys *winsys = screen->winsys;
511bf215546Sopenharmony_ci   struct softpipe_resource *texture = softpipe_resource(resource);
512bf215546Sopenharmony_ci
513bf215546Sopenharmony_ci   assert(texture->dt);
514bf215546Sopenharmony_ci   if (texture->dt)
515bf215546Sopenharmony_ci      winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box);
516bf215546Sopenharmony_ci}
517bf215546Sopenharmony_ci
518bf215546Sopenharmony_cistatic uint64_t
519bf215546Sopenharmony_cisoftpipe_get_timestamp(struct pipe_screen *_screen)
520bf215546Sopenharmony_ci{
521bf215546Sopenharmony_ci   return os_time_get_nano();
522bf215546Sopenharmony_ci}
523bf215546Sopenharmony_ci
524bf215546Sopenharmony_cistatic int
525bf215546Sopenharmony_cisoftpipe_get_compute_param(struct pipe_screen *_screen,
526bf215546Sopenharmony_ci                           enum pipe_shader_ir ir_type,
527bf215546Sopenharmony_ci                           enum pipe_compute_cap param,
528bf215546Sopenharmony_ci                           void *ret)
529bf215546Sopenharmony_ci{
530bf215546Sopenharmony_ci   switch (param) {
531bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IR_TARGET:
532bf215546Sopenharmony_ci      return 0;
533bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
534bf215546Sopenharmony_ci      if (ret) {
535bf215546Sopenharmony_ci         uint64_t *grid_size = ret;
536bf215546Sopenharmony_ci         grid_size[0] = 65535;
537bf215546Sopenharmony_ci         grid_size[1] = 65535;
538bf215546Sopenharmony_ci         grid_size[2] = 65535;
539bf215546Sopenharmony_ci      }
540bf215546Sopenharmony_ci      return 3 * sizeof(uint64_t) ;
541bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
542bf215546Sopenharmony_ci      if (ret) {
543bf215546Sopenharmony_ci         uint64_t *block_size = ret;
544bf215546Sopenharmony_ci         block_size[0] = 1024;
545bf215546Sopenharmony_ci         block_size[1] = 1024;
546bf215546Sopenharmony_ci         block_size[2] = 1024;
547bf215546Sopenharmony_ci      }
548bf215546Sopenharmony_ci      return 3 * sizeof(uint64_t);
549bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
550bf215546Sopenharmony_ci      if (ret) {
551bf215546Sopenharmony_ci         uint64_t *max_threads_per_block = ret;
552bf215546Sopenharmony_ci         *max_threads_per_block = 1024;
553bf215546Sopenharmony_ci      }
554bf215546Sopenharmony_ci      return sizeof(uint64_t);
555bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
556bf215546Sopenharmony_ci      if (ret) {
557bf215546Sopenharmony_ci         uint64_t *max_local_size = ret;
558bf215546Sopenharmony_ci         *max_local_size = 32768;
559bf215546Sopenharmony_ci      }
560bf215546Sopenharmony_ci      return sizeof(uint64_t);
561bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_GRID_DIMENSION:
562bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
563bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
564bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
565bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
566bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
567bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
568bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
569bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
570bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_ADDRESS_BITS:
571bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
572bf215546Sopenharmony_ci      break;
573bf215546Sopenharmony_ci   }
574bf215546Sopenharmony_ci   return 0;
575bf215546Sopenharmony_ci}
576bf215546Sopenharmony_ci
577bf215546Sopenharmony_ci/**
578bf215546Sopenharmony_ci * Create a new pipe_screen object
579bf215546Sopenharmony_ci * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
580bf215546Sopenharmony_ci */
581bf215546Sopenharmony_cistruct pipe_screen *
582bf215546Sopenharmony_cisoftpipe_create_screen(struct sw_winsys *winsys)
583bf215546Sopenharmony_ci{
584bf215546Sopenharmony_ci   struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci   if (!screen)
587bf215546Sopenharmony_ci      return NULL;
588bf215546Sopenharmony_ci
589bf215546Sopenharmony_ci   sp_debug = debug_get_option_sp_debug();
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_ci   screen->winsys = winsys;
592bf215546Sopenharmony_ci
593bf215546Sopenharmony_ci   screen->base.destroy = softpipe_destroy_screen;
594bf215546Sopenharmony_ci
595bf215546Sopenharmony_ci   screen->base.get_name = softpipe_get_name;
596bf215546Sopenharmony_ci   screen->base.get_vendor = softpipe_get_vendor;
597bf215546Sopenharmony_ci   screen->base.get_device_vendor = softpipe_get_vendor; // TODO should be the CPU vendor
598bf215546Sopenharmony_ci   screen->base.get_param = softpipe_get_param;
599bf215546Sopenharmony_ci   screen->base.get_shader_param = softpipe_get_shader_param;
600bf215546Sopenharmony_ci   screen->base.get_paramf = softpipe_get_paramf;
601bf215546Sopenharmony_ci   screen->base.get_timestamp = softpipe_get_timestamp;
602bf215546Sopenharmony_ci   screen->base.is_format_supported = softpipe_is_format_supported;
603bf215546Sopenharmony_ci   screen->base.context_create = softpipe_create_context;
604bf215546Sopenharmony_ci   screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
605bf215546Sopenharmony_ci   screen->base.get_compute_param = softpipe_get_compute_param;
606bf215546Sopenharmony_ci   screen->base.get_compiler_options = softpipe_get_compiler_options;
607bf215546Sopenharmony_ci   screen->use_llvm = sp_debug & SP_DBG_USE_LLVM;
608bf215546Sopenharmony_ci
609bf215546Sopenharmony_ci   softpipe_init_screen_texture_funcs(&screen->base);
610bf215546Sopenharmony_ci   softpipe_init_screen_fence_funcs(&screen->base);
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_ci   return &screen->base;
613bf215546Sopenharmony_ci}
614