1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2008 VMware, Inc.
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg
29848b8605Smrg#include "util/u_memory.h"
30848b8605Smrg#include "util/u_format.h"
31848b8605Smrg#include "util/u_format_s3tc.h"
32b8e80941Smrg#include "util/u_screen.h"
33848b8605Smrg#include "util/u_video.h"
34b8e80941Smrg#include "util/os_misc.h"
35b8e80941Smrg#include "util/os_time.h"
36848b8605Smrg#include "pipe/p_defines.h"
37848b8605Smrg#include "pipe/p_screen.h"
38848b8605Smrg#include "draw/draw_context.h"
39848b8605Smrg
40848b8605Smrg#include "state_tracker/sw_winsys.h"
41848b8605Smrg#include "tgsi/tgsi_exec.h"
42848b8605Smrg
43848b8605Smrg#include "sp_texture.h"
44848b8605Smrg#include "sp_screen.h"
45848b8605Smrg#include "sp_context.h"
46848b8605Smrg#include "sp_fence.h"
47848b8605Smrg#include "sp_public.h"
48848b8605Smrg
49848b8605SmrgDEBUG_GET_ONCE_BOOL_OPTION(use_llvm, "SOFTPIPE_USE_LLVM", FALSE)
50848b8605Smrg
51848b8605Smrgstatic const char *
52848b8605Smrgsoftpipe_get_vendor(struct pipe_screen *screen)
53848b8605Smrg{
54848b8605Smrg   return "VMware, Inc.";
55848b8605Smrg}
56848b8605Smrg
57848b8605Smrg
58848b8605Smrgstatic const char *
59848b8605Smrgsoftpipe_get_name(struct pipe_screen *screen)
60848b8605Smrg{
61848b8605Smrg   return "softpipe";
62848b8605Smrg}
63848b8605Smrg
64848b8605Smrg
65848b8605Smrgstatic int
66848b8605Smrgsoftpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
67848b8605Smrg{
68b8e80941Smrg   struct softpipe_screen *sp_screen = softpipe_screen(screen);
69848b8605Smrg   switch (param) {
70848b8605Smrg   case PIPE_CAP_NPOT_TEXTURES:
71848b8605Smrg   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
72b8e80941Smrg   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
73848b8605Smrg      return 1;
74848b8605Smrg   case PIPE_CAP_SM3:
75848b8605Smrg      return 1;
76848b8605Smrg   case PIPE_CAP_ANISOTROPIC_FILTER:
77848b8605Smrg      return 1;
78848b8605Smrg   case PIPE_CAP_POINT_SPRITE:
79848b8605Smrg      return 1;
80848b8605Smrg   case PIPE_CAP_MAX_RENDER_TARGETS:
81848b8605Smrg      return PIPE_MAX_COLOR_BUFS;
82848b8605Smrg   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
83848b8605Smrg      return 1;
84848b8605Smrg   case PIPE_CAP_OCCLUSION_QUERY:
85848b8605Smrg      return 1;
86848b8605Smrg   case PIPE_CAP_QUERY_TIME_ELAPSED:
87848b8605Smrg      return 1;
88848b8605Smrg   case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
89848b8605Smrg      return 1;
90848b8605Smrg   case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
91b8e80941Smrg   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
92848b8605Smrg      return 1;
93848b8605Smrg   case PIPE_CAP_TEXTURE_SWIZZLE:
94848b8605Smrg      return 1;
95848b8605Smrg   case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
96b8e80941Smrg   case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
97848b8605Smrg      return 0;
98848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
99848b8605Smrg      return SP_MAX_TEXTURE_2D_LEVELS;
100848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
101848b8605Smrg      return SP_MAX_TEXTURE_3D_LEVELS;
102848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
103848b8605Smrg      return SP_MAX_TEXTURE_CUBE_LEVELS;
104848b8605Smrg   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
105848b8605Smrg      return 1;
106848b8605Smrg   case PIPE_CAP_INDEP_BLEND_ENABLE:
107848b8605Smrg      return 1;
108848b8605Smrg   case PIPE_CAP_INDEP_BLEND_FUNC:
109848b8605Smrg      return 1;
110848b8605Smrg   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
111848b8605Smrg   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
112848b8605Smrg   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
113848b8605Smrg   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
114848b8605Smrg      return 1;
115848b8605Smrg   case PIPE_CAP_DEPTH_CLIP_DISABLE:
116848b8605Smrg      return 1;
117848b8605Smrg   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
118848b8605Smrg      return PIPE_MAX_SO_BUFFERS;
119848b8605Smrg   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
120848b8605Smrg   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
121848b8605Smrg      return 16*4;
122848b8605Smrg   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
123848b8605Smrg   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
124848b8605Smrg      return 1024;
125848b8605Smrg   case PIPE_CAP_MAX_VERTEX_STREAMS:
126b8e80941Smrg      if (sp_screen->use_llvm)
127b8e80941Smrg         return 1;
128b8e80941Smrg      else
129b8e80941Smrg         return PIPE_MAX_VERTEX_STREAMS;
130b8e80941Smrg   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
131b8e80941Smrg      return 2048;
132848b8605Smrg   case PIPE_CAP_PRIMITIVE_RESTART:
133848b8605Smrg      return 1;
134848b8605Smrg   case PIPE_CAP_SHADER_STENCIL_EXPORT:
135848b8605Smrg      return 1;
136b8e80941Smrg   case PIPE_CAP_TGSI_ATOMFADD:
137848b8605Smrg   case PIPE_CAP_TGSI_INSTANCEID:
138848b8605Smrg   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
139b8e80941Smrg   case PIPE_CAP_START_INSTANCE:
140848b8605Smrg      return 1;
141848b8605Smrg   case PIPE_CAP_SEAMLESS_CUBE_MAP:
142848b8605Smrg   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
143848b8605Smrg      return 1;
144848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
145848b8605Smrg      return 256; /* for GL3 */
146848b8605Smrg   case PIPE_CAP_MIN_TEXEL_OFFSET:
147848b8605Smrg      return -8;
148848b8605Smrg   case PIPE_CAP_MAX_TEXEL_OFFSET:
149848b8605Smrg      return 7;
150848b8605Smrg   case PIPE_CAP_CONDITIONAL_RENDER:
151848b8605Smrg      return 1;
152848b8605Smrg   case PIPE_CAP_TEXTURE_BARRIER:
153b8e80941Smrg   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
154848b8605Smrg      return 0;
155848b8605Smrg   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
156848b8605Smrg   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: /* draw module */
157848b8605Smrg   case PIPE_CAP_VERTEX_COLOR_CLAMPED: /* draw module */
158848b8605Smrg      return 1;
159848b8605Smrg   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
160b8e80941Smrg      return 1;
161848b8605Smrg   case PIPE_CAP_GLSL_FEATURE_LEVEL:
162b8e80941Smrg      return 400;
163b8e80941Smrg   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
164b8e80941Smrg      return 140;
165848b8605Smrg   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
166b8e80941Smrg   case PIPE_CAP_TGSI_TEX_TXF_LZ:
167848b8605Smrg      return 0;
168848b8605Smrg   case PIPE_CAP_COMPUTE:
169b8e80941Smrg      return 1;
170848b8605Smrg   case PIPE_CAP_USER_VERTEX_BUFFERS:
171848b8605Smrg   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
172b8e80941Smrg   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
173848b8605Smrg   case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
174b8e80941Smrg   case PIPE_CAP_DOUBLES:
175b8e80941Smrg   case PIPE_CAP_INT64:
176b8e80941Smrg   case PIPE_CAP_INT64_DIVMOD:
177b8e80941Smrg   case PIPE_CAP_TGSI_DIV:
178848b8605Smrg      return 1;
179848b8605Smrg   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
180848b8605Smrg      return 16;
181848b8605Smrg   case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
182848b8605Smrg   case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
183848b8605Smrg   case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
184848b8605Smrg   case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
185848b8605Smrg   case PIPE_CAP_TEXTURE_MULTISAMPLE:
186848b8605Smrg      return 0;
187848b8605Smrg   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
188848b8605Smrg      return 64;
189848b8605Smrg   case PIPE_CAP_QUERY_TIMESTAMP:
190848b8605Smrg   case PIPE_CAP_CUBE_MAP_ARRAY:
191848b8605Smrg      return 1;
192848b8605Smrg   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
193848b8605Smrg      return 1;
194b8e80941Smrg   case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
195b8e80941Smrg      return 0;
196848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
197848b8605Smrg      return 65536;
198848b8605Smrg   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
199b8e80941Smrg      return 16;
200848b8605Smrg   case PIPE_CAP_TGSI_TEXCOORD:
201848b8605Smrg   case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
202848b8605Smrg      return 0;
203848b8605Smrg   case PIPE_CAP_MAX_VIEWPORTS:
204b8e80941Smrg      return PIPE_MAX_VIEWPORTS;
205848b8605Smrg   case PIPE_CAP_ENDIANNESS:
206848b8605Smrg      return PIPE_ENDIAN_NATIVE;
207848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
208b8e80941Smrg      return 4;
209848b8605Smrg   case PIPE_CAP_TEXTURE_GATHER_SM5:
210848b8605Smrg   case PIPE_CAP_TEXTURE_QUERY_LOD:
211b8e80941Smrg      return 1;
212b8e80941Smrg   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
213848b8605Smrg   case PIPE_CAP_SAMPLE_SHADING:
214848b8605Smrg   case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
215b8e80941Smrg      return 0;
216848b8605Smrg   case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
217b8e80941Smrg      return 1;
218848b8605Smrg   case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
219848b8605Smrg      return 0;
220b8e80941Smrg   case PIPE_CAP_SAMPLER_VIEW_TARGET:
221b8e80941Smrg      return 1;
222848b8605Smrg   case PIPE_CAP_FAKE_SW_MSAA:
223848b8605Smrg      return 1;
224848b8605Smrg   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
225b8e80941Smrg      return -32;
226848b8605Smrg   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
227b8e80941Smrg      return 31;
228848b8605Smrg   case PIPE_CAP_DRAW_INDIRECT:
229848b8605Smrg      return 1;
230b8e80941Smrg   case PIPE_CAP_QUERY_SO_OVERFLOW:
231b8e80941Smrg      return 1;
232848b8605Smrg
233848b8605Smrg   case PIPE_CAP_VENDOR_ID:
234848b8605Smrg      return 0xFFFFFFFF;
235848b8605Smrg   case PIPE_CAP_DEVICE_ID:
236848b8605Smrg      return 0xFFFFFFFF;
237848b8605Smrg   case PIPE_CAP_ACCELERATED:
238848b8605Smrg      return 0;
239848b8605Smrg   case PIPE_CAP_VIDEO_MEMORY: {
240848b8605Smrg      /* XXX: Do we want to return the full amount fo system memory ? */
241848b8605Smrg      uint64_t system_memory;
242848b8605Smrg
243848b8605Smrg      if (!os_get_total_physical_memory(&system_memory))
244848b8605Smrg         return 0;
245848b8605Smrg
246b8e80941Smrg      if (sizeof(void *) == 4)
247b8e80941Smrg         /* Cap to 2 GB on 32 bits system. We do this because softpipe does
248b8e80941Smrg          * eat application memory, which is quite limited on 32 bits. App
249b8e80941Smrg          * shouldn't expect too much available memory. */
250b8e80941Smrg         system_memory = MIN2(system_memory, 2048 << 20);
251b8e80941Smrg
252848b8605Smrg      return (int)(system_memory >> 20);
253848b8605Smrg   }
254848b8605Smrg   case PIPE_CAP_UMA:
255848b8605Smrg      return 0;
256848b8605Smrg   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
257848b8605Smrg      return 1;
258b8e80941Smrg   case PIPE_CAP_CLIP_HALFZ:
259b8e80941Smrg   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
260b8e80941Smrg   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
261b8e80941Smrg      return 1;
262b8e80941Smrg   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
263b8e80941Smrg   case PIPE_CAP_CULL_DISTANCE:
264b8e80941Smrg      return 1;
265b8e80941Smrg   case PIPE_CAP_VERTEXID_NOBASE:
266b8e80941Smrg      return 0;
267b8e80941Smrg   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
268b8e80941Smrg      return 0;
269b8e80941Smrg   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
270b8e80941Smrg   case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
271b8e80941Smrg      return 1;
272b8e80941Smrg   case PIPE_CAP_CLEAR_TEXTURE:
273b8e80941Smrg      return 1;
274b8e80941Smrg   case PIPE_CAP_MAX_VARYINGS:
275b8e80941Smrg      return TGSI_EXEC_MAX_INPUT_ATTRIBS;
276b8e80941Smrg   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
277b8e80941Smrg   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
278b8e80941Smrg   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
279b8e80941Smrg   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
280b8e80941Smrg   case PIPE_CAP_DEPTH_BOUNDS_TEST:
281b8e80941Smrg   case PIPE_CAP_TGSI_TXQS:
282b8e80941Smrg   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
283b8e80941Smrg   case PIPE_CAP_SHAREABLE_SHADERS:
284b8e80941Smrg   case PIPE_CAP_DRAW_PARAMETERS:
285b8e80941Smrg   case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
286b8e80941Smrg   case PIPE_CAP_MULTI_DRAW_INDIRECT:
287b8e80941Smrg   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
288b8e80941Smrg   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
289b8e80941Smrg   case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
290b8e80941Smrg   case PIPE_CAP_INVALIDATE_BUFFER:
291b8e80941Smrg   case PIPE_CAP_GENERATE_MIPMAP:
292b8e80941Smrg   case PIPE_CAP_STRING_MARKER:
293b8e80941Smrg   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
294b8e80941Smrg   case PIPE_CAP_QUERY_BUFFER_OBJECT:
295b8e80941Smrg   case PIPE_CAP_QUERY_MEMORY_INFO:
296b8e80941Smrg   case PIPE_CAP_PCI_GROUP:
297b8e80941Smrg   case PIPE_CAP_PCI_BUS:
298b8e80941Smrg   case PIPE_CAP_PCI_DEVICE:
299b8e80941Smrg   case PIPE_CAP_PCI_FUNCTION:
300b8e80941Smrg   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
301b8e80941Smrg   case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
302b8e80941Smrg   case PIPE_CAP_TGSI_VOTE:
303b8e80941Smrg   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
304b8e80941Smrg   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
305b8e80941Smrg   case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
306b8e80941Smrg   case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
307b8e80941Smrg   case PIPE_CAP_NATIVE_FENCE_FD:
308b8e80941Smrg   case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
309b8e80941Smrg   case PIPE_CAP_TGSI_FS_FBFETCH:
310b8e80941Smrg   case PIPE_CAP_TGSI_MUL_ZERO_WINS:
311b8e80941Smrg   case PIPE_CAP_TGSI_CLOCK:
312b8e80941Smrg   case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
313b8e80941Smrg   case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
314b8e80941Smrg   case PIPE_CAP_TGSI_BALLOT:
315b8e80941Smrg   case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
316b8e80941Smrg   case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
317b8e80941Smrg   case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
318b8e80941Smrg   case PIPE_CAP_POST_DEPTH_COVERAGE:
319b8e80941Smrg   case PIPE_CAP_BINDLESS_TEXTURE:
320b8e80941Smrg   case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
321b8e80941Smrg   case PIPE_CAP_MEMOBJ:
322b8e80941Smrg   case PIPE_CAP_LOAD_CONSTBUF:
323b8e80941Smrg   case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
324b8e80941Smrg   case PIPE_CAP_TILE_RASTER_ORDER:
325b8e80941Smrg   case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
326b8e80941Smrg   case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
327b8e80941Smrg   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
328b8e80941Smrg   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
329b8e80941Smrg   case PIPE_CAP_FENCE_SIGNAL:
330b8e80941Smrg   case PIPE_CAP_CONSTBUF0_FLAGS:
331b8e80941Smrg   case PIPE_CAP_PACKED_UNIFORMS:
332b8e80941Smrg   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
333b8e80941Smrg   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
334b8e80941Smrg   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
335b8e80941Smrg   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
336b8e80941Smrg   case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
337b8e80941Smrg   case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
338b8e80941Smrg   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
339b8e80941Smrg      return 0;
340b8e80941Smrg   case PIPE_CAP_MAX_GS_INVOCATIONS:
341b8e80941Smrg      return 32;
342b8e80941Smrg   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
343b8e80941Smrg      return 1 << 27;
344b8e80941Smrg   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
345b8e80941Smrg      return 4;
346b8e80941Smrg   default:
347b8e80941Smrg      return u_pipe_screen_get_param_defaults(screen, param);
348848b8605Smrg   }
349848b8605Smrg}
350848b8605Smrg
351848b8605Smrgstatic int
352b8e80941Smrgsoftpipe_get_shader_param(struct pipe_screen *screen,
353b8e80941Smrg                          enum pipe_shader_type shader,
354b8e80941Smrg                          enum pipe_shader_cap param)
355848b8605Smrg{
356848b8605Smrg   struct softpipe_screen *sp_screen = softpipe_screen(screen);
357848b8605Smrg   switch(shader)
358848b8605Smrg   {
359848b8605Smrg   case PIPE_SHADER_FRAGMENT:
360848b8605Smrg      return tgsi_exec_get_shader_param(param);
361b8e80941Smrg   case PIPE_SHADER_COMPUTE:
362b8e80941Smrg      return tgsi_exec_get_shader_param(param);
363848b8605Smrg   case PIPE_SHADER_VERTEX:
364848b8605Smrg   case PIPE_SHADER_GEOMETRY:
365b8e80941Smrg      if (sp_screen->use_llvm)
366b8e80941Smrg         return draw_get_shader_param(shader, param);
367b8e80941Smrg      else
368b8e80941Smrg         return draw_get_shader_param_no_llvm(shader, param);
369848b8605Smrg   default:
370848b8605Smrg      return 0;
371848b8605Smrg   }
372848b8605Smrg}
373848b8605Smrg
374848b8605Smrgstatic float
375848b8605Smrgsoftpipe_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
376848b8605Smrg{
377848b8605Smrg   switch (param) {
378848b8605Smrg   case PIPE_CAPF_MAX_LINE_WIDTH:
379848b8605Smrg      /* fall-through */
380848b8605Smrg   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
381848b8605Smrg      return 255.0; /* arbitrary */
382848b8605Smrg   case PIPE_CAPF_MAX_POINT_WIDTH:
383848b8605Smrg      /* fall-through */
384848b8605Smrg   case PIPE_CAPF_MAX_POINT_WIDTH_AA:
385848b8605Smrg      return 255.0; /* arbitrary */
386848b8605Smrg   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
387848b8605Smrg      return 16.0;
388848b8605Smrg   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
389848b8605Smrg      return 16.0; /* arbitrary */
390b8e80941Smrg   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
391b8e80941Smrg      return 0.0;
392b8e80941Smrg   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
393b8e80941Smrg      return 0.0;
394b8e80941Smrg   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
395848b8605Smrg      return 0.0;
396848b8605Smrg   }
397848b8605Smrg   /* should only get here on unhandled cases */
398848b8605Smrg   debug_printf("Unexpected PIPE_CAPF %d query\n", param);
399848b8605Smrg   return 0.0;
400848b8605Smrg}
401848b8605Smrg
402848b8605Smrg/**
403848b8605Smrg * Query format support for creating a texture, drawing surface, etc.
404848b8605Smrg * \param format  the format to test
405848b8605Smrg * \param type  one of PIPE_TEXTURE, PIPE_SURFACE
406848b8605Smrg */
407848b8605Smrgstatic boolean
408848b8605Smrgsoftpipe_is_format_supported( struct pipe_screen *screen,
409848b8605Smrg                              enum pipe_format format,
410848b8605Smrg                              enum pipe_texture_target target,
411848b8605Smrg                              unsigned sample_count,
412b8e80941Smrg                              unsigned storage_sample_count,
413848b8605Smrg                              unsigned bind)
414848b8605Smrg{
415848b8605Smrg   struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
416848b8605Smrg   const struct util_format_description *format_desc;
417848b8605Smrg
418848b8605Smrg   assert(target == PIPE_BUFFER ||
419848b8605Smrg          target == PIPE_TEXTURE_1D ||
420848b8605Smrg          target == PIPE_TEXTURE_1D_ARRAY ||
421848b8605Smrg          target == PIPE_TEXTURE_2D ||
422848b8605Smrg          target == PIPE_TEXTURE_2D_ARRAY ||
423848b8605Smrg          target == PIPE_TEXTURE_RECT ||
424848b8605Smrg          target == PIPE_TEXTURE_3D ||
425848b8605Smrg          target == PIPE_TEXTURE_CUBE ||
426848b8605Smrg          target == PIPE_TEXTURE_CUBE_ARRAY);
427848b8605Smrg
428b8e80941Smrg   if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
429b8e80941Smrg      return false;
430b8e80941Smrg
431848b8605Smrg   format_desc = util_format_description(format);
432848b8605Smrg   if (!format_desc)
433848b8605Smrg      return FALSE;
434848b8605Smrg
435848b8605Smrg   if (sample_count > 1)
436848b8605Smrg      return FALSE;
437848b8605Smrg
438848b8605Smrg   if (bind & (PIPE_BIND_DISPLAY_TARGET |
439848b8605Smrg               PIPE_BIND_SCANOUT |
440848b8605Smrg               PIPE_BIND_SHARED)) {
441848b8605Smrg      if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
442848b8605Smrg         return FALSE;
443848b8605Smrg   }
444848b8605Smrg
445848b8605Smrg   if (bind & PIPE_BIND_RENDER_TARGET) {
446848b8605Smrg      if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
447848b8605Smrg         return FALSE;
448848b8605Smrg
449848b8605Smrg      /*
450848b8605Smrg       * Although possible, it is unnatural to render into compressed or YUV
451848b8605Smrg       * surfaces. So disable these here to avoid going into weird paths
452848b8605Smrg       * inside the state trackers.
453848b8605Smrg       */
454848b8605Smrg      if (format_desc->block.width != 1 ||
455848b8605Smrg          format_desc->block.height != 1)
456848b8605Smrg         return FALSE;
457848b8605Smrg   }
458848b8605Smrg
459848b8605Smrg   if (bind & PIPE_BIND_DEPTH_STENCIL) {
460848b8605Smrg      if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
461848b8605Smrg         return FALSE;
462848b8605Smrg   }
463848b8605Smrg
464b8e80941Smrg   if (format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC ||
465b8e80941Smrg       format_desc->layout == UTIL_FORMAT_LAYOUT_ATC) {
466848b8605Smrg      /* Software decoding is not hooked up. */
467848b8605Smrg      return FALSE;
468848b8605Smrg   }
469848b8605Smrg
470b8e80941Smrg   if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) &&
471b8e80941Smrg       ((bind & PIPE_BIND_DISPLAY_TARGET) == 0) &&
472b8e80941Smrg       target != PIPE_BUFFER) {
473b8e80941Smrg      const struct util_format_description *desc =
474b8e80941Smrg         util_format_description(format);
475b8e80941Smrg      if (desc->nr_channels == 3 && desc->is_array) {
476b8e80941Smrg         /* Don't support any 3-component formats for rendering/texturing
477b8e80941Smrg          * since we don't support the corresponding 8-bit 3 channel UNORM
478b8e80941Smrg          * formats.  This allows us to support GL_ARB_copy_image between
479b8e80941Smrg          * GL_RGB8 and GL_RGB8UI, for example.  Otherwise, we may be asked to
480b8e80941Smrg          * do a resource copy between PIPE_FORMAT_R8G8B8_UINT and
481b8e80941Smrg          * PIPE_FORMAT_R8G8B8X8_UNORM, for example, which will not work
482b8e80941Smrg          * (different bpp).
483b8e80941Smrg          */
484b8e80941Smrg         return FALSE;
485b8e80941Smrg      }
486b8e80941Smrg   }
487b8e80941Smrg
488b8e80941Smrg   if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
489b8e80941Smrg       format != PIPE_FORMAT_ETC1_RGB8)
490b8e80941Smrg      return FALSE;
491b8e80941Smrg
492848b8605Smrg   /*
493848b8605Smrg    * All other operations (sampling, transfer, etc).
494848b8605Smrg    */
495848b8605Smrg
496848b8605Smrg   /*
497848b8605Smrg    * Everything else should be supported by u_format.
498848b8605Smrg    */
499848b8605Smrg   return TRUE;
500848b8605Smrg}
501848b8605Smrg
502848b8605Smrg
503848b8605Smrgstatic void
504848b8605Smrgsoftpipe_destroy_screen( struct pipe_screen *screen )
505848b8605Smrg{
506848b8605Smrg   struct softpipe_screen *sp_screen = softpipe_screen(screen);
507848b8605Smrg   struct sw_winsys *winsys = sp_screen->winsys;
508848b8605Smrg
509848b8605Smrg   if(winsys->destroy)
510848b8605Smrg      winsys->destroy(winsys);
511848b8605Smrg
512848b8605Smrg   FREE(screen);
513848b8605Smrg}
514848b8605Smrg
515848b8605Smrg
516848b8605Smrg/* This is often overriden by the co-state tracker.
517848b8605Smrg */
518848b8605Smrgstatic void
519848b8605Smrgsoftpipe_flush_frontbuffer(struct pipe_screen *_screen,
520848b8605Smrg                           struct pipe_resource *resource,
521848b8605Smrg                           unsigned level, unsigned layer,
522848b8605Smrg                           void *context_private,
523848b8605Smrg                           struct pipe_box *sub_box)
524848b8605Smrg{
525848b8605Smrg   struct softpipe_screen *screen = softpipe_screen(_screen);
526848b8605Smrg   struct sw_winsys *winsys = screen->winsys;
527848b8605Smrg   struct softpipe_resource *texture = softpipe_resource(resource);
528848b8605Smrg
529848b8605Smrg   assert(texture->dt);
530848b8605Smrg   if (texture->dt)
531848b8605Smrg      winsys->displaytarget_display(winsys, texture->dt, context_private, sub_box);
532848b8605Smrg}
533848b8605Smrg
534848b8605Smrgstatic uint64_t
535848b8605Smrgsoftpipe_get_timestamp(struct pipe_screen *_screen)
536848b8605Smrg{
537848b8605Smrg   return os_time_get_nano();
538848b8605Smrg}
539848b8605Smrg
540b8e80941Smrgstatic int
541b8e80941Smrgsoftpipe_get_compute_param(struct pipe_screen *_screen,
542b8e80941Smrg                           enum pipe_shader_ir ir_type,
543b8e80941Smrg                           enum pipe_compute_cap param,
544b8e80941Smrg                           void *ret)
545b8e80941Smrg{
546b8e80941Smrg   switch (param) {
547b8e80941Smrg   case PIPE_COMPUTE_CAP_IR_TARGET:
548b8e80941Smrg      return 0;
549b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
550b8e80941Smrg      if (ret) {
551b8e80941Smrg         uint64_t *grid_size = ret;
552b8e80941Smrg         grid_size[0] = 65535;
553b8e80941Smrg         grid_size[1] = 65535;
554b8e80941Smrg         grid_size[2] = 65535;
555b8e80941Smrg      }
556b8e80941Smrg      return 3 * sizeof(uint64_t) ;
557b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
558b8e80941Smrg      if (ret) {
559b8e80941Smrg         uint64_t *block_size = ret;
560b8e80941Smrg         block_size[0] = 1024;
561b8e80941Smrg         block_size[1] = 1024;
562b8e80941Smrg         block_size[2] = 1024;
563b8e80941Smrg      }
564b8e80941Smrg      return 3 * sizeof(uint64_t);
565b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
566b8e80941Smrg      if (ret) {
567b8e80941Smrg         uint64_t *max_threads_per_block = ret;
568b8e80941Smrg         *max_threads_per_block = 1024;
569b8e80941Smrg      }
570b8e80941Smrg      return sizeof(uint64_t);
571b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
572b8e80941Smrg      if (ret) {
573b8e80941Smrg         uint64_t *max_local_size = ret;
574b8e80941Smrg         *max_local_size = 32768;
575b8e80941Smrg      }
576b8e80941Smrg      return sizeof(uint64_t);
577b8e80941Smrg   case PIPE_COMPUTE_CAP_GRID_DIMENSION:
578b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:
579b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:
580b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:
581b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
582b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
583b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
584b8e80941Smrg   case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
585b8e80941Smrg   case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
586b8e80941Smrg   case PIPE_COMPUTE_CAP_ADDRESS_BITS:
587b8e80941Smrg   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
588b8e80941Smrg      break;
589b8e80941Smrg   }
590b8e80941Smrg   return 0;
591b8e80941Smrg}
592b8e80941Smrg
593848b8605Smrg/**
594848b8605Smrg * Create a new pipe_screen object
595848b8605Smrg * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
596848b8605Smrg */
597848b8605Smrgstruct pipe_screen *
598848b8605Smrgsoftpipe_create_screen(struct sw_winsys *winsys)
599848b8605Smrg{
600848b8605Smrg   struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
601848b8605Smrg
602848b8605Smrg   if (!screen)
603848b8605Smrg      return NULL;
604848b8605Smrg
605848b8605Smrg   screen->winsys = winsys;
606848b8605Smrg
607848b8605Smrg   screen->base.destroy = softpipe_destroy_screen;
608848b8605Smrg
609848b8605Smrg   screen->base.get_name = softpipe_get_name;
610848b8605Smrg   screen->base.get_vendor = softpipe_get_vendor;
611b8e80941Smrg   screen->base.get_device_vendor = softpipe_get_vendor; // TODO should be the CPU vendor
612848b8605Smrg   screen->base.get_param = softpipe_get_param;
613848b8605Smrg   screen->base.get_shader_param = softpipe_get_shader_param;
614848b8605Smrg   screen->base.get_paramf = softpipe_get_paramf;
615848b8605Smrg   screen->base.get_timestamp = softpipe_get_timestamp;
616848b8605Smrg   screen->base.is_format_supported = softpipe_is_format_supported;
617848b8605Smrg   screen->base.context_create = softpipe_create_context;
618848b8605Smrg   screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
619b8e80941Smrg   screen->base.get_compute_param = softpipe_get_compute_param;
620848b8605Smrg   screen->use_llvm = debug_get_option_use_llvm();
621848b8605Smrg
622848b8605Smrg   softpipe_init_screen_texture_funcs(&screen->base);
623848b8605Smrg   softpipe_init_screen_fence_funcs(&screen->base);
624848b8605Smrg
625848b8605Smrg   return &screen->base;
626848b8605Smrg}
627