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 "util/u_memory.h"
30 #include "util/u_format.h"
31 #include "util/u_format_s3tc.h"
32 #include "util/u_video.h"
33 #include "os/os_misc.h"
34 #include "util/os_time.h"
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
37 #include "draw/draw_context.h"
38 
39 #include "state_tracker/sw_winsys.h"
40 #include "tgsi/tgsi_exec.h"
41 
42 #include "sp_texture.h"
43 #include "sp_screen.h"
44 #include "sp_context.h"
45 #include "sp_fence.h"
46 #include "sp_public.h"
47 
48 DEBUG_GET_ONCE_BOOL_OPTION(use_llvm, "SOFTPIPE_USE_LLVM", FALSE)
49 
50 static const char *
softpipe_get_vendor(struct pipe_screen * screen)51 softpipe_get_vendor(struct pipe_screen *screen)
52 {
53    return "VMware, Inc.";
54 }
55 
56 
57 static const char *
softpipe_get_name(struct pipe_screen * screen)58 softpipe_get_name(struct pipe_screen *screen)
59 {
60    return "softpipe";
61 }
62 
63 
64 static int
softpipe_get_param(struct pipe_screen * screen,enum pipe_cap param)65 softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
66 {
67    switch (param) {
68    case PIPE_CAP_NPOT_TEXTURES:
69    case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
70    case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
71       return 1;
72    case PIPE_CAP_SM3:
73       return 1;
74    case PIPE_CAP_ANISOTROPIC_FILTER:
75       return 1;
76    case PIPE_CAP_POINT_SPRITE:
77       return 1;
78    case PIPE_CAP_MAX_RENDER_TARGETS:
79       return PIPE_MAX_COLOR_BUFS;
80    case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
81       return 1;
82    case PIPE_CAP_OCCLUSION_QUERY:
83       return 1;
84    case PIPE_CAP_QUERY_TIME_ELAPSED:
85       return 1;
86    case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
87       return 1;
88    case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
89       return 1;
90    case PIPE_CAP_TEXTURE_SWIZZLE:
91       return 1;
92    case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
93       return 0;
94    case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
95       return SP_MAX_TEXTURE_2D_LEVELS;
96    case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
97       return SP_MAX_TEXTURE_3D_LEVELS;
98    case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
99       return SP_MAX_TEXTURE_CUBE_LEVELS;
100    case PIPE_CAP_BLEND_EQUATION_SEPARATE:
101       return 1;
102    case PIPE_CAP_INDEP_BLEND_ENABLE:
103       return 1;
104    case PIPE_CAP_INDEP_BLEND_FUNC:
105       return 1;
106    case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
107    case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
108    case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
109    case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
110       return 1;
111    case PIPE_CAP_DEPTH_CLIP_DISABLE:
112       return 1;
113    case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
114       return PIPE_MAX_SO_BUFFERS;
115    case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
116    case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
117       return 16*4;
118    case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
119    case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
120       return 1024;
121    case PIPE_CAP_MAX_VERTEX_STREAMS:
122       return 1;
123    case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
124       return 2048;
125    case PIPE_CAP_PRIMITIVE_RESTART:
126       return 1;
127    case PIPE_CAP_SHADER_STENCIL_EXPORT:
128       return 1;
129    case PIPE_CAP_TGSI_INSTANCEID:
130    case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
131    case PIPE_CAP_START_INSTANCE:
132       return 1;
133    case PIPE_CAP_SEAMLESS_CUBE_MAP:
134    case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
135       return 1;
136    case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
137       return 256; /* for GL3 */
138    case PIPE_CAP_MIN_TEXEL_OFFSET:
139       return -8;
140    case PIPE_CAP_MAX_TEXEL_OFFSET:
141       return 7;
142    case PIPE_CAP_CONDITIONAL_RENDER:
143       return 1;
144    case PIPE_CAP_TEXTURE_BARRIER:
145       return 0;
146    case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
147    case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: /* draw module */
148    case PIPE_CAP_VERTEX_COLOR_CLAMPED: /* draw module */
149       return 1;
150    case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
151       return 0;
152    case PIPE_CAP_GLSL_FEATURE_LEVEL:
153       return 330;
154    case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
155    case PIPE_CAP_TGSI_TEX_TXF_LZ:
156       return 0;
157    case PIPE_CAP_COMPUTE:
158       return 1;
159    case PIPE_CAP_USER_VERTEX_BUFFERS:
160    case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
161    case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
162    case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
163    case PIPE_CAP_DOUBLES:
164    case PIPE_CAP_INT64:
165    case PIPE_CAP_INT64_DIVMOD:
166       return 1;
167    case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
168       return 16;
169    case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
170    case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
171    case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
172    case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
173    case PIPE_CAP_TEXTURE_MULTISAMPLE:
174       return 0;
175    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
176       return 64;
177    case PIPE_CAP_QUERY_TIMESTAMP:
178    case PIPE_CAP_CUBE_MAP_ARRAY:
179       return 1;
180    case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
181       return 1;
182    case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
183       return 0;
184    case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
185       return 65536;
186    case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
187       return 0;
188    case PIPE_CAP_TGSI_TEXCOORD:
189    case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
190       return 0;
191    case PIPE_CAP_MAX_VIEWPORTS:
192       return PIPE_MAX_VIEWPORTS;
193    case PIPE_CAP_ENDIANNESS:
194       return PIPE_ENDIAN_NATIVE;
195    case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
196       return 4;
197    case PIPE_CAP_TEXTURE_GATHER_SM5:
198    case PIPE_CAP_TEXTURE_QUERY_LOD:
199       return 1;
200    case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
201    case PIPE_CAP_SAMPLE_SHADING:
202    case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
203       return 0;
204    case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
205       return 1;
206    case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
207       return 0;
208    case PIPE_CAP_SAMPLER_VIEW_TARGET:
209       return 1;
210    case PIPE_CAP_FAKE_SW_MSAA:
211       return 1;
212    case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
213       return -32;
214    case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
215       return 31;
216    case PIPE_CAP_DRAW_INDIRECT:
217       return 1;
218    case PIPE_CAP_QUERY_SO_OVERFLOW:
219       return 1;
220 
221    case PIPE_CAP_VENDOR_ID:
222       return 0xFFFFFFFF;
223    case PIPE_CAP_DEVICE_ID:
224       return 0xFFFFFFFF;
225    case PIPE_CAP_ACCELERATED:
226       return 0;
227    case PIPE_CAP_VIDEO_MEMORY: {
228       /* XXX: Do we want to return the full amount fo system memory ? */
229       uint64_t system_memory;
230 
231       if (!os_get_total_physical_memory(&system_memory))
232          return 0;
233 
234       if (sizeof(void *) == 4)
235          /* Cap to 2 GB on 32 bits system. We do this because softpipe does
236           * eat application memory, which is quite limited on 32 bits. App
237           * shouldn't expect too much available memory. */
238          system_memory = MIN2(system_memory, 2048 << 20);
239 
240       return (int)(system_memory >> 20);
241    }
242    case PIPE_CAP_UMA:
243       return 0;
244    case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
245       return 1;
246    case PIPE_CAP_CLIP_HALFZ:
247    case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
248    case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
249       return 1;
250    case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
251    case PIPE_CAP_CULL_DISTANCE:
252       return 1;
253    case PIPE_CAP_VERTEXID_NOBASE:
254       return 0;
255    case PIPE_CAP_POLYGON_OFFSET_CLAMP:
256       return 0;
257    case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
258    case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
259       return 1;
260    case PIPE_CAP_CLEAR_TEXTURE:
261       return 1;
262    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
263    case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
264    case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
265    case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
266    case PIPE_CAP_DEPTH_BOUNDS_TEST:
267    case PIPE_CAP_TGSI_TXQS:
268    case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
269    case PIPE_CAP_SHAREABLE_SHADERS:
270    case PIPE_CAP_DRAW_PARAMETERS:
271    case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
272    case PIPE_CAP_MULTI_DRAW_INDIRECT:
273    case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
274    case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
275    case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
276    case PIPE_CAP_INVALIDATE_BUFFER:
277    case PIPE_CAP_GENERATE_MIPMAP:
278    case PIPE_CAP_STRING_MARKER:
279    case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
280    case PIPE_CAP_QUERY_BUFFER_OBJECT:
281    case PIPE_CAP_QUERY_MEMORY_INFO:
282    case PIPE_CAP_PCI_GROUP:
283    case PIPE_CAP_PCI_BUS:
284    case PIPE_CAP_PCI_DEVICE:
285    case PIPE_CAP_PCI_FUNCTION:
286    case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
287    case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
288    case PIPE_CAP_TGSI_VOTE:
289    case PIPE_CAP_MAX_WINDOW_RECTANGLES:
290    case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
291    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
292    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
293    case PIPE_CAP_NATIVE_FENCE_FD:
294    case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
295    case PIPE_CAP_TGSI_FS_FBFETCH:
296    case PIPE_CAP_TGSI_MUL_ZERO_WINS:
297    case PIPE_CAP_TGSI_CLOCK:
298    case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
299    case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
300    case PIPE_CAP_TGSI_BALLOT:
301    case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
302    case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
303    case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
304    case PIPE_CAP_POST_DEPTH_COVERAGE:
305    case PIPE_CAP_BINDLESS_TEXTURE:
306    case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
307    case PIPE_CAP_MEMOBJ:
308    case PIPE_CAP_LOAD_CONSTBUF:
309    case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
310    case PIPE_CAP_TILE_RASTER_ORDER:
311    case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
312    case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
313    case PIPE_CAP_CONTEXT_PRIORITY_MASK:
314       return 0;
315    case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
316       return 4;
317    }
318    /* should only get here on unhandled cases */
319    debug_printf("Unexpected PIPE_CAP %d query\n", param);
320    return 0;
321 }
322 
323 static int
softpipe_get_shader_param(struct pipe_screen * screen,enum pipe_shader_type shader,enum pipe_shader_cap param)324 softpipe_get_shader_param(struct pipe_screen *screen,
325                           enum pipe_shader_type shader,
326                           enum pipe_shader_cap param)
327 {
328    struct softpipe_screen *sp_screen = softpipe_screen(screen);
329    switch(shader)
330    {
331    case PIPE_SHADER_FRAGMENT:
332       return tgsi_exec_get_shader_param(param);
333    case PIPE_SHADER_COMPUTE:
334       return tgsi_exec_get_shader_param(param);
335    case PIPE_SHADER_VERTEX:
336    case PIPE_SHADER_GEOMETRY:
337       if (sp_screen->use_llvm)
338          return draw_get_shader_param(shader, param);
339       else
340          return draw_get_shader_param_no_llvm(shader, param);
341    default:
342       return 0;
343    }
344 }
345 
346 static float
softpipe_get_paramf(struct pipe_screen * screen,enum pipe_capf param)347 softpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
348 {
349    switch (param) {
350    case PIPE_CAPF_MAX_LINE_WIDTH:
351       /* fall-through */
352    case PIPE_CAPF_MAX_LINE_WIDTH_AA:
353       return 255.0; /* arbitrary */
354    case PIPE_CAPF_MAX_POINT_WIDTH:
355       /* fall-through */
356    case PIPE_CAPF_MAX_POINT_WIDTH_AA:
357       return 255.0; /* arbitrary */
358    case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
359       return 16.0;
360    case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
361       return 16.0; /* arbitrary */
362    case PIPE_CAPF_GUARD_BAND_LEFT:
363    case PIPE_CAPF_GUARD_BAND_TOP:
364    case PIPE_CAPF_GUARD_BAND_RIGHT:
365    case PIPE_CAPF_GUARD_BAND_BOTTOM:
366       return 0.0;
367    }
368    /* should only get here on unhandled cases */
369    debug_printf("Unexpected PIPE_CAPF %d query\n", param);
370    return 0.0;
371 }
372 
373 /**
374  * Query format support for creating a texture, drawing surface, etc.
375  * \param format  the format to test
376  * \param type  one of PIPE_TEXTURE, PIPE_SURFACE
377  */
378 static boolean
softpipe_is_format_supported(struct pipe_screen * screen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned bind)379 softpipe_is_format_supported( struct pipe_screen *screen,
380                               enum pipe_format format,
381                               enum pipe_texture_target target,
382                               unsigned sample_count,
383                               unsigned bind)
384 {
385    struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
386    const struct util_format_description *format_desc;
387 
388    assert(target == PIPE_BUFFER ||
389           target == PIPE_TEXTURE_1D ||
390           target == PIPE_TEXTURE_1D_ARRAY ||
391           target == PIPE_TEXTURE_2D ||
392           target == PIPE_TEXTURE_2D_ARRAY ||
393           target == PIPE_TEXTURE_RECT ||
394           target == PIPE_TEXTURE_3D ||
395           target == PIPE_TEXTURE_CUBE ||
396           target == PIPE_TEXTURE_CUBE_ARRAY);
397 
398    format_desc = util_format_description(format);
399    if (!format_desc)
400       return FALSE;
401 
402    if (sample_count > 1)
403       return FALSE;
404 
405    if (bind & (PIPE_BIND_DISPLAY_TARGET |
406                PIPE_BIND_SCANOUT |
407                PIPE_BIND_SHARED)) {
408       if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
409          return FALSE;
410    }
411 
412    if (bind & PIPE_BIND_RENDER_TARGET) {
413       if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
414          return FALSE;
415 
416       /*
417        * Although possible, it is unnatural to render into compressed or YUV
418        * surfaces. So disable these here to avoid going into weird paths
419        * inside the state trackers.
420        */
421       if (format_desc->block.width != 1 ||
422           format_desc->block.height != 1)
423          return FALSE;
424    }
425 
426    if (bind & PIPE_BIND_DEPTH_STENCIL) {
427       if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
428          return FALSE;
429    }
430 
431    if (format_desc->layout == UTIL_FORMAT_LAYOUT_BPTC ||
432        format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC) {
433       /* Software decoding is not hooked up. */
434       return FALSE;
435    }
436 
437    if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) &&
438        ((bind & PIPE_BIND_DISPLAY_TARGET) == 0) &&
439        target != PIPE_BUFFER) {
440       const struct util_format_description *desc =
441          util_format_description(format);
442       if (desc->nr_channels == 3 && desc->is_array) {
443          /* Don't support any 3-component formats for rendering/texturing
444           * since we don't support the corresponding 8-bit 3 channel UNORM
445           * formats.  This allows us to support GL_ARB_copy_image between
446           * GL_RGB8 and GL_RGB8UI, for example.  Otherwise, we may be asked to
447           * do a resource copy between PIPE_FORMAT_R8G8B8_UINT and
448           * PIPE_FORMAT_R8G8B8X8_UNORM, for example, which will not work
449           * (different bpp).
450           */
451          return FALSE;
452       }
453    }
454 
455    if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
456        format != PIPE_FORMAT_ETC1_RGB8)
457       return FALSE;
458 
459    /*
460     * All other operations (sampling, transfer, etc).
461     */
462 
463    /*
464     * Everything else should be supported by u_format.
465     */
466    return TRUE;
467 }
468 
469 
470 static void
softpipe_destroy_screen(struct pipe_screen * screen)471 softpipe_destroy_screen( struct pipe_screen *screen )
472 {
473    struct softpipe_screen *sp_screen = softpipe_screen(screen);
474    struct sw_winsys *winsys = sp_screen->winsys;
475 
476    if(winsys->destroy)
477       winsys->destroy(winsys);
478 
479    FREE(screen);
480 }
481 
482 
483 /* This is often overriden by the co-state tracker.
484  */
485 static void
softpipe_flush_frontbuffer(struct pipe_screen * _screen,struct pipe_resource * resource,unsigned level,unsigned layer,void * context_private,struct pipe_box * sub_box)486 softpipe_flush_frontbuffer(struct pipe_screen *_screen,
487                            struct pipe_resource *resource,
488                            unsigned level, unsigned layer,
489                            void *context_private,
490                            struct pipe_box *sub_box)
491 {
492    struct softpipe_screen *screen = softpipe_screen(_screen);
493    struct sw_winsys *winsys = screen->winsys;
494    struct softpipe_resource *texture = softpipe_resource(resource);
495 
496    assert(texture->dt);
497    if (texture->dt)
498       winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box);
499 }
500 
501 static uint64_t
softpipe_get_timestamp(struct pipe_screen * _screen)502 softpipe_get_timestamp(struct pipe_screen *_screen)
503 {
504    return os_time_get_nano();
505 }
506 
507 static int
softpipe_get_compute_param(struct pipe_screen * _screen,enum pipe_shader_ir ir_type,enum pipe_compute_cap param,void * ret)508 softpipe_get_compute_param(struct pipe_screen *_screen,
509                            enum pipe_shader_ir ir_type,
510                            enum pipe_compute_cap param,
511                            void *ret)
512 {
513    switch (param) {
514    case PIPE_COMPUTE_CAP_IR_TARGET:
515       return 0;
516    case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
517       if (ret) {
518          uint64_t *grid_size = ret;
519          grid_size[0] = 65535;
520          grid_size[1] = 65535;
521          grid_size[2] = 65535;
522       }
523       return 3 * sizeof(uint64_t) ;
524    case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
525       if (ret) {
526          uint64_t *block_size = ret;
527          block_size[0] = 1024;
528          block_size[1] = 1024;
529          block_size[2] = 1024;
530       }
531       return 3 * sizeof(uint64_t);
532    case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
533       if (ret) {
534          uint64_t *max_threads_per_block = ret;
535          *max_threads_per_block = 1024;
536       }
537       return sizeof(uint64_t);
538    case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
539       if (ret) {
540          uint64_t *max_local_size = ret;
541          *max_local_size = 32768;
542       }
543       return sizeof(uint64_t);
544    case PIPE_COMPUTE_CAP_GRID_DIMENSION:
545    case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
546    case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
547    case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
548    case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
549    case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
550    case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
551    case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
552    case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
553    case PIPE_COMPUTE_CAP_ADDRESS_BITS:
554    case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
555       break;
556    }
557    return 0;
558 }
559 
560 /**
561  * Create a new pipe_screen object
562  * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
563  */
564 struct pipe_screen *
softpipe_create_screen(struct sw_winsys * winsys)565 softpipe_create_screen(struct sw_winsys *winsys)
566 {
567    struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
568 
569    if (!screen)
570       return NULL;
571 
572    screen->winsys = winsys;
573 
574    screen->base.destroy = softpipe_destroy_screen;
575 
576    screen->base.get_name = softpipe_get_name;
577    screen->base.get_vendor = softpipe_get_vendor;
578    screen->base.get_device_vendor = softpipe_get_vendor; // TODO should be the CPU vendor
579    screen->base.get_param = softpipe_get_param;
580    screen->base.get_shader_param = softpipe_get_shader_param;
581    screen->base.get_paramf = softpipe_get_paramf;
582    screen->base.get_timestamp = softpipe_get_timestamp;
583    screen->base.is_format_supported = softpipe_is_format_supported;
584    screen->base.context_create = softpipe_create_context;
585    screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
586    screen->base.get_compute_param = softpipe_get_compute_param;
587    screen->use_llvm = debug_get_option_use_llvm();
588 
589    softpipe_init_screen_texture_funcs(&screen->base);
590    softpipe_init_screen_fence_funcs(&screen->base);
591 
592    return &screen->base;
593 }
594