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