svga_screen.c 38.3 KB
Newer Older
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/**********************************************************
 * Copyright 2008-2009 VMware, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **********************************************************/

26
#include "git_sha1.h" /* For MESA_GIT_SHA1 */
27
#include "util/u_format.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
28
#include "util/u_memory.h"
29
#include "util/u_inlines.h"
30
#include "util/u_screen.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
31 32 33
#include "util/u_string.h"
#include "util/u_math.h"

34 35
#include "os/os_process.h"

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
36
#include "svga_winsys.h"
37
#include "svga_public.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
38
#include "svga_context.h"
39
#include "svga_format.h"
40
#include "svga_msg.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
41
#include "svga_screen.h"
42
#include "svga_tgsi.h"
43 44
#include "svga_resource_texture.h"
#include "svga_resource.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
45 46 47
#include "svga_debug.h"

#include "svga3d_shaderdefs.h"
48
#include "VGPU10ShaderTokens.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
49

50 51
/* NOTE: this constant may get moved into a svga3d*.h header file */
#define SVGA3D_DX_MAX_RESOURCE_SIZE (128 * 1024 * 1024)
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
52 53 54 55 56

#ifdef DEBUG
int SVGA_DEBUG = 0;

static const struct debug_named_value svga_debug_flags[] = {
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
   { "dma",         DEBUG_DMA, NULL },
   { "tgsi",        DEBUG_TGSI, NULL },
   { "pipe",        DEBUG_PIPE, NULL },
   { "state",       DEBUG_STATE, NULL },
   { "screen",      DEBUG_SCREEN, NULL },
   { "tex",         DEBUG_TEX, NULL },
   { "swtnl",       DEBUG_SWTNL, NULL },
   { "const",       DEBUG_CONSTS, NULL },
   { "viewport",    DEBUG_VIEWPORT, NULL },
   { "views",       DEBUG_VIEWS, NULL },
   { "perf",        DEBUG_PERF, NULL },
   { "flush",       DEBUG_FLUSH, NULL },
   { "sync",        DEBUG_SYNC, NULL },
   { "cache",       DEBUG_CACHE, NULL },
   { "streamout",   DEBUG_STREAMOUT, NULL },
   { "query",       DEBUG_QUERY, NULL },
Brian Paul's avatar
Brian Paul committed
73
   { "samplers",    DEBUG_SAMPLERS, NULL },
74
   DEBUG_NAMED_VALUE_END
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
75 76 77 78 79 80 81 82 83 84 85 86 87
};
#endif

static const char *
svga_get_vendor( struct pipe_screen *pscreen )
{
   return "VMware, Inc.";
}


static const char *
svga_get_name( struct pipe_screen *pscreen )
{
88 89
   const char *build = "", *llvm = "", *mutex = "";
   static char name[100];
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
90 91 92
#ifdef DEBUG
   /* Only return internal details in the DEBUG version:
    */
93 94
   build = "build: DEBUG;";
   mutex = "mutex: " PIPE_ATOMIC ";";
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
95
#else
96
   build = "build: RELEASE;";
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
97
#endif
98 99 100
#ifdef HAVE_LLVM
   llvm = "LLVM;";
#endif
101 102 103

   util_snprintf(name, sizeof(name), "SVGA3D; %s %s %s", build, mutex, llvm);
   return name;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
104 105 106
}


107 108
/** Helper for querying float-valued device cap */
static float
109 110
get_float_cap(struct svga_winsys_screen *sws, SVGA3dDevCapIndex cap,
              float defaultVal)
111 112 113 114 115 116 117 118 119 120 121
{
   SVGA3dDevCapResult result;
   if (sws->get_cap(sws, cap, &result))
      return result.f;
   else
      return defaultVal;
}


/** Helper for querying uint-valued device cap */
static unsigned
122 123
get_uint_cap(struct svga_winsys_screen *sws, SVGA3dDevCapIndex cap,
             unsigned defaultVal)
124 125 126 127 128 129 130 131 132 133 134
{
   SVGA3dDevCapResult result;
   if (sws->get_cap(sws, cap, &result))
      return result.u;
   else
      return defaultVal;
}


/** Helper for querying boolean-valued device cap */
static boolean
135 136
get_bool_cap(struct svga_winsys_screen *sws, SVGA3dDevCapIndex cap,
             boolean defaultVal)
137 138 139 140 141 142 143
{
   SVGA3dDevCapResult result;
   if (sws->get_cap(sws, cap, &result))
      return result.b;
   else
      return defaultVal;
}
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
144 145 146


static float
147
svga_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
148 149 150 151 152
{
   struct svga_screen *svgascreen = svga_screen(screen);
   struct svga_winsys_screen *sws = svgascreen->sws;

   switch (param) {
153
   case PIPE_CAPF_MAX_LINE_WIDTH:
154
      return svgascreen->maxLineWidth;
155
   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
156
      return svgascreen->maxLineWidthAA;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
157

158
   case PIPE_CAPF_MAX_POINT_WIDTH:
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
159
      /* fall-through */
160
   case PIPE_CAPF_MAX_POINT_WIDTH_AA:
161
      return svgascreen->maxPointSize;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
162

163
   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
164
      return (float) get_uint_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY, 4);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
165

166
   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
167
      return 15.0;
168

169 170 171 172 173 174 175
   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
      /* fall-through */
   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
      /* fall-through */
   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
      return 0.0f;

176
   }
177 178 179

   debug_printf("Unexpected PIPE_CAPF_ query %u\n", param);
   return 0;
180 181 182 183 184 185 186 187 188 189 190
}


static int
svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
{
   struct svga_screen *svgascreen = svga_screen(screen);
   struct svga_winsys_screen *sws = svgascreen->sws;
   SVGA3dDevCapResult result;

   switch (param) {
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
191
   case PIPE_CAP_NPOT_TEXTURES:
192
   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
193
   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
194
      return 1;
195
   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
196 197 198 199 200 201
      /*
       * "In virtually every OpenGL implementation and hardware,
       * GL_MAX_DUAL_SOURCE_DRAW_BUFFERS is 1"
       * http://www.opengl.org/wiki/Blending
       */
      return sws->have_vgpu10 ? 1 : 0;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
202 203 204 205
   case PIPE_CAP_ANISOTROPIC_FILTER:
      return 1;
   case PIPE_CAP_POINT_SPRITE:
      return 1;
206 207
   case PIPE_CAP_TGSI_TEXCOORD:
      return 0;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
208
   case PIPE_CAP_MAX_RENDER_TARGETS:
209
      return svgascreen->max_color_buffers;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
210 211
   case PIPE_CAP_OCCLUSION_QUERY:
      return 1;
212
   case PIPE_CAP_QUERY_TIME_ELAPSED:
213
      return 0;
214 215
   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
      return sws->have_vgpu10;
Brian Paul's avatar
Brian Paul committed
216 217
   case PIPE_CAP_TEXTURE_SWIZZLE:
      return 1;
218 219
   case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
      return 0;
220
   case PIPE_CAP_USER_VERTEX_BUFFERS:
221
      return 0;
222
   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
223
      return 256;
224

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
225
   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
226 227 228 229 230 231 232 233 234 235 236 237 238
      {
         unsigned levels = SVGA_MAX_TEXTURE_LEVELS;
         if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH, &result))
            levels = MIN2(util_logbase2(result.u) + 1, levels);
         else
            levels = 12 /* 2048x2048 */;
         if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT, &result))
            levels = MIN2(util_logbase2(result.u) + 1, levels);
         else
            levels = 12 /* 2048x2048 */;
         return levels;
      }

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
239
   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
240 241 242 243
      if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VOLUME_EXTENT, &result))
         return 8;  /* max 128x128x128 */
      return MIN2(util_logbase2(result.u) + 1, SVGA_MAX_TEXTURE_LEVELS);

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
244
   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
245 246 247 248
      /*
       * No mechanism to query the host, and at least limited to 2048x2048 on
       * certain hardware.
       */
249 250
      return MIN2(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
                  12 /* 2048x2048 */);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
251

252 253 254
   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
      return sws->have_vgpu10 ? SVGA3D_MAX_SURFACE_ARRAYSIZE : 0;

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
255 256 257
   case PIPE_CAP_BLEND_EQUATION_SEPARATE: /* req. for GL 1.5 */
      return 1;

258 259
   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
      return 1;
Brian Paul's avatar
Brian Paul committed
260
   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
261
      return sws->have_vgpu10;
262 263
   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
      return 0;
Brian Paul's avatar
Brian Paul committed
264
   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
265
      return !sws->have_vgpu10;
266

267 268 269 270 271 272 273
   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
      return 1; /* The color outputs of vertex shaders are not clamped */
   case PIPE_CAP_VERTEX_COLOR_CLAMPED:
      return 0; /* The driver can't clamp vertex colors */
   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
      return 0; /* The driver can't clamp fragment colors */

274
   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
275 276
      return 1; /* expected for GL_ARB_framebuffer_object */

277
   case PIPE_CAP_GLSL_FEATURE_LEVEL:
278
      return sws->have_vgpu10 ? 330 : 120;
279

280
   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
281
      return sws->have_vgpu10 ? 330 : 120;
282

283
   case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
284
   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
285
      return 0;
286

287 288 289
   case PIPE_CAP_SM3:
      return 1;

290 291
   case PIPE_CAP_DEPTH_CLIP_DISABLE:
   case PIPE_CAP_INDEP_BLEND_ENABLE:
292 293
   case PIPE_CAP_CONDITIONAL_RENDER:
   case PIPE_CAP_QUERY_TIMESTAMP:
294 295
   case PIPE_CAP_TGSI_INSTANCEID:
   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
296 297 298 299 300 301 302 303 304 305 306
   case PIPE_CAP_SEAMLESS_CUBE_MAP:
   case PIPE_CAP_FAKE_SW_MSAA:
      return sws->have_vgpu10;

   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
      return sws->have_vgpu10 ? SVGA3D_DX_MAX_SOTARGETS : 0;
   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
      return sws->have_vgpu10 ? 4 : 0;
   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
      return sws->have_vgpu10 ? SVGA3D_MAX_STREAMOUT_DECLS : 0;
   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
307
   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
308 309 310 311 312
      return 0;
   case PIPE_CAP_TEXTURE_MULTISAMPLE:
      return svgascreen->ms_samples ? 1 : 0;

   case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
313 314 315 316
      /* convert bytes to texels for the case of the largest texel
       * size: float[4].
       */
      return SVGA3D_DX_MAX_RESOURCE_SIZE / (4 * sizeof(float));
317

318
   case PIPE_CAP_MIN_TEXEL_OFFSET:
319
      return sws->have_vgpu10 ? VGPU10_MIN_TEXEL_FETCH_OFFSET : 0;
320
   case PIPE_CAP_MAX_TEXEL_OFFSET:
321 322
      return sws->have_vgpu10 ? VGPU10_MAX_TEXEL_FETCH_OFFSET : 0;

323 324
   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
325 326
      return 0;

327
   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
328
      return sws->have_vgpu10 ? 256 : 0;
329
   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
330 331 332 333 334
      return sws->have_vgpu10 ? 1024 : 0;

   case PIPE_CAP_PRIMITIVE_RESTART:
      return 1; /* may be a sw fallback, depending on restart index */

335
   case PIPE_CAP_GENERATE_MIPMAP:
336
      return sws->have_generate_mipmap_cmd;
337

338 339 340
   case PIPE_CAP_NATIVE_FENCE_FD:
      return sws->have_fence_fd;

341
   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
342 343
      return 1;

344
   case PIPE_CAP_CUBE_MAP_ARRAY:
345
   case PIPE_CAP_INDEP_BLEND_FUNC:
346 347
   case PIPE_CAP_SAMPLE_SHADING:
   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
348
   case PIPE_CAP_TEXTURE_QUERY_LOD:
349 350
      return sws->have_sm4_1;

351 352 353
   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
      return sws->have_sm4_1 ? 1 : 0; /* only single-channel textures */

354
   /* Unsupported features */
355
   case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
356
   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
357 358 359
   case PIPE_CAP_SHADER_STENCIL_EXPORT:
   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
   case PIPE_CAP_TEXTURE_BARRIER:
360
   case PIPE_CAP_MAX_VERTEX_STREAMS:
361
   case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
362
   case PIPE_CAP_COMPUTE:
363
   case PIPE_CAP_START_INSTANCE:
364
   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
365
   case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
366
   case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
367
   case PIPE_CAP_TEXTURE_GATHER_SM5:
368
   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
369
   case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
370
   case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
371
   case PIPE_CAP_DRAW_INDIRECT:
372 373
   case PIPE_CAP_MULTI_DRAW_INDIRECT:
   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
374
   case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
375
   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
376
   case PIPE_CAP_SAMPLER_VIEW_TARGET:
377
   case PIPE_CAP_CLIP_HALFZ:
378
   case PIPE_CAP_VERTEXID_NOBASE:
379
   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
380
   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
381
   case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
382
   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
383
   case PIPE_CAP_INVALIDATE_BUFFER:
Rob Clark's avatar
Rob Clark committed
384
   case PIPE_CAP_STRING_MARKER:
385
   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
386
   case PIPE_CAP_QUERY_MEMORY_INFO:
387 388 389 390
   case PIPE_CAP_PCI_GROUP:
   case PIPE_CAP_PCI_BUS:
   case PIPE_CAP_PCI_DEVICE:
   case PIPE_CAP_PCI_FUNCTION:
391
   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
392 393 394 395 396 397
   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
   case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
   case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
398
   case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
399
      return 0;
400 401
   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
      return 64;
402 403
   case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
   case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
404
   case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
405
      return 1;  /* need 4-byte alignment for all offsets and strides */
406 407
   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
      return 2048;
408 409
   case PIPE_CAP_MAX_VIEWPORTS:
      return 1;
410 411
   case PIPE_CAP_ENDIANNESS:
      return PIPE_ENDIAN_LITTLE;
412 413 414 415 416 417 418 419 420 421

   case PIPE_CAP_VENDOR_ID:
      return 0x15ad; /* VMware Inc. */
   case PIPE_CAP_DEVICE_ID:
      return 0x0405; /* assume SVGA II */
   case PIPE_CAP_ACCELERATED:
      return 0; /* XXX: */
   case PIPE_CAP_VIDEO_MEMORY:
      /* XXX: Query the host ? */
      return 1;
422 423
   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
      return sws->have_vgpu10;
424 425
   case PIPE_CAP_CLEAR_TEXTURE:
      return sws->have_vgpu10;
426
   case PIPE_CAP_UMA:
427
   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
428
   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
429
   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
430 431
   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
432
   case PIPE_CAP_DEPTH_BOUNDS_TEST:
433
   case PIPE_CAP_TGSI_TXQS:
434
   case PIPE_CAP_SHAREABLE_SHADERS:
435
   case PIPE_CAP_DRAW_PARAMETERS:
436 437
   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
   case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
438
   case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
439
   case PIPE_CAP_QUERY_BUFFER_OBJECT:
440
   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
441
   case PIPE_CAP_CULL_DISTANCE:
442
   case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
443
   case PIPE_CAP_TGSI_VOTE:
444
   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
445
   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
446
   case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
447
   case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
448
   case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
449
   case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
450
   case PIPE_CAP_TGSI_FS_FBFETCH:
451
   case PIPE_CAP_TGSI_MUL_ZERO_WINS:
452
   case PIPE_CAP_DOUBLES:
453
   case PIPE_CAP_INT64:
454
   case PIPE_CAP_INT64_DIVMOD:
455
   case PIPE_CAP_TGSI_TEX_TXF_LZ:
456
   case PIPE_CAP_TGSI_CLOCK:
457
   case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
458
   case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
459
   case PIPE_CAP_TGSI_BALLOT:
460
   case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
461
   case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
462
   case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
463
   case PIPE_CAP_POST_DEPTH_COVERAGE:
464
   case PIPE_CAP_BINDLESS_TEXTURE:
465
   case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
466
   case PIPE_CAP_QUERY_SO_OVERFLOW:
467
   case PIPE_CAP_MEMOBJ:
468
   case PIPE_CAP_LOAD_CONSTBUF:
469
   case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
470
   case PIPE_CAP_TILE_RASTER_ORDER:
471
   case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
472
   case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
473
   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
474
   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
475
   case PIPE_CAP_FENCE_SIGNAL:
476
   case PIPE_CAP_CONSTBUF0_FLAGS:
477
   case PIPE_CAP_PACKED_UNIFORMS:
478
   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
479
      return 0;
480 481
   case PIPE_CAP_MAX_GS_INVOCATIONS:
      return 32;
482 483
   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
      return 1 << 27;
484 485
   default:
      return u_pipe_screen_get_param_defaults(screen, param);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
486 487 488
   }
}

489 490

static int
491 492
vgpu9_get_shader_param(struct pipe_screen *screen,
                       enum pipe_shader_type shader,
493
                       enum pipe_shader_cap param)
494 495 496
{
   struct svga_screen *svgascreen = svga_screen(screen);
   struct svga_winsys_screen *sws = svgascreen->sws;
497 498 499
   unsigned val;

   assert(!sws->have_vgpu10);
500 501 502 503 504 505 506 507

   switch (shader)
   {
   case PIPE_SHADER_FRAGMENT:
      switch (param)
      {
      case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
      case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
508 509 510
         return get_uint_cap(sws,
                             SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_INSTRUCTIONS,
                             512);
511 512
      case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
      case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
513
         return 512;
514 515 516 517
      case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
         return SVGA3D_MAX_NESTING_LEVEL;
      case PIPE_SHADER_CAP_MAX_INPUTS:
         return 10;
518 519
      case PIPE_SHADER_CAP_MAX_OUTPUTS:
         return svgascreen->max_color_buffers;
520 521
      case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
         return 224 * sizeof(float[4]);
522 523 524
      case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
         return 1;
      case PIPE_SHADER_CAP_MAX_TEMPS:
525 526
         val = get_uint_cap(sws, SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS, 32);
         return MIN2(val, SVGA3D_TEMPREG_MAX);
527
      case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
528 529 530 531 532 533
         /*
          * Although PS 3.0 has some addressing abilities it can only represent
          * loops that can be statically determined and unrolled. Given we can
          * only handle a subset of the cases that the state tracker already
          * does it is better to defer loop unrolling to the state tracker.
          */
534
         return 0;
535
      case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
536
         return 0;
537 538
      case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
         return 0;
539 540 541 542
      case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
      case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
      case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
         return 0;
543 544
      case PIPE_SHADER_CAP_SUBROUTINES:
         return 0;
545
      case PIPE_SHADER_CAP_INT64_ATOMICS:
546 547
      case PIPE_SHADER_CAP_INTEGERS:
         return 0;
Jan Vesely's avatar
Jan Vesely committed
548 549
      case PIPE_SHADER_CAP_FP16:
         return 0;
550
      case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
551
      case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
552
         return 16;
553 554
      case PIPE_SHADER_CAP_PREFERRED_IR:
         return PIPE_SHADER_IR_TGSI;
555 556
      case PIPE_SHADER_CAP_SUPPORTED_IRS:
         return 0;
557
      case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
Ilia Mirkin's avatar
Ilia Mirkin committed
558
      case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
559
      case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
560
      case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
561
      case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
562
      case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
563
      case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
564
      case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
565
      case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
566 567
      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
568
         return 0;
569 570
      case PIPE_SHADER_CAP_SCALAR_ISA:
         return 1;
571 572
      case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
         return 32;
573
      }
574 575 576
      /* If we get here, we failed to handle a cap above */
      debug_printf("Unexpected fragment shader query %u\n", param);
      return 0;
577 578 579 580 581
   case PIPE_SHADER_VERTEX:
      switch (param)
      {
      case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
      case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
582 583
         return get_uint_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS,
                             512);
584 585 586 587 588 589 590 591
      case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
      case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
         /* XXX: until we have vertex texture support */
         return 0;
      case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
         return SVGA3D_MAX_NESTING_LEVEL;
      case PIPE_SHADER_CAP_MAX_INPUTS:
         return 16;
592 593
      case PIPE_SHADER_CAP_MAX_OUTPUTS:
         return 10;
594 595
      case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
         return 256 * sizeof(float[4]);
596 597 598
      case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
         return 1;
      case PIPE_SHADER_CAP_MAX_TEMPS:
599 600
         val = get_uint_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS, 32);
         return MIN2(val, SVGA3D_TEMPREG_MAX);
601
      case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
602
         return 0;
603 604
      case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
         return 0;
605 606
      case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
      case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
607
         return 1;
608 609 610 611
      case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
         return 0;
      case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
         return 1;
612 613
      case PIPE_SHADER_CAP_SUBROUTINES:
         return 0;
614
      case PIPE_SHADER_CAP_INT64_ATOMICS:
615 616
      case PIPE_SHADER_CAP_INTEGERS:
         return 0;
Jan Vesely's avatar
Jan Vesely committed
617 618
      case PIPE_SHADER_CAP_FP16:
         return 0;
619
      case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
620
      case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
621
         return 0;
622 623
      case PIPE_SHADER_CAP_PREFERRED_IR:
         return PIPE_SHADER_IR_TGSI;
624 625
      case PIPE_SHADER_CAP_SUPPORTED_IRS:
         return 0;
626 627
      case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
      case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
628
      case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
629
      case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
630
      case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
631
      case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
632
      case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
633
      case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
634
      case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
635 636
      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
637
         return 0;
638 639
      case PIPE_SHADER_CAP_SCALAR_ISA:
         return 1;
640 641
      case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
         return 32;
642
      }
643 644 645
      /* If we get here, we failed to handle a cap above */
      debug_printf("Unexpected vertex shader query %u\n", param);
      return 0;
646
   case PIPE_SHADER_GEOMETRY:
647
   case PIPE_SHADER_COMPUTE:
648 649 650
   case PIPE_SHADER_TESS_CTRL:
   case PIPE_SHADER_TESS_EVAL:
      /* no support for geometry, tess or compute shaders at this time */
651
      return 0;
652
   default:
653
      debug_printf("Unexpected shader type (%u) query\n", shader);
654
      return 0;
655 656 657
   }
   return 0;
}
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
658 659


660
static int
661 662
vgpu10_get_shader_param(struct pipe_screen *screen,
                        enum pipe_shader_type shader,
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
                        enum pipe_shader_cap param)
{
   struct svga_screen *svgascreen = svga_screen(screen);
   struct svga_winsys_screen *sws = svgascreen->sws;

   assert(sws->have_vgpu10);
   (void) sws;  /* silence unused var warnings in non-debug builds */

   /* Only VS, GS, FS supported */
   if (shader != PIPE_SHADER_VERTEX &&
       shader != PIPE_SHADER_GEOMETRY &&
       shader != PIPE_SHADER_FRAGMENT) {
      return 0;
   }

   /* NOTE: we do not query the device for any caps/limits at this time */

   /* Generally the same limits for vertex, geometry and fragment shaders */
   switch (param) {
   case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
   case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
   case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
   case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
      return 64 * 1024;
   case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
      return 64;
   case PIPE_SHADER_CAP_MAX_INPUTS:
      if (shader == PIPE_SHADER_FRAGMENT)
         return VGPU10_MAX_FS_INPUTS;
      else if (shader == PIPE_SHADER_GEOMETRY)
         return VGPU10_MAX_GS_INPUTS;
      else
         return VGPU10_MAX_VS_INPUTS;
   case PIPE_SHADER_CAP_MAX_OUTPUTS:
      if (shader == PIPE_SHADER_FRAGMENT)
         return VGPU10_MAX_FS_OUTPUTS;
      else if (shader == PIPE_SHADER_GEOMETRY)
         return VGPU10_MAX_GS_OUTPUTS;
      else
         return VGPU10_MAX_VS_OUTPUTS;
   case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
      return VGPU10_MAX_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]);
   case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
      return svgascreen->max_const_buffers;
   case PIPE_SHADER_CAP_MAX_TEMPS:
      return VGPU10_MAX_TEMPS;
   case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
   case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
   case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
   case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
      return TRUE; /* XXX verify */
   case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
   case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
   case PIPE_SHADER_CAP_SUBROUTINES:
   case PIPE_SHADER_CAP_INTEGERS:
      return TRUE;
Jan Vesely's avatar
Jan Vesely committed
719 720
   case PIPE_SHADER_CAP_FP16:
      return FALSE;
721 722 723 724 725
   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
   case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
      return SVGA3D_DX_MAX_SAMPLERS;
   case PIPE_SHADER_CAP_PREFERRED_IR:
      return PIPE_SHADER_IR_TGSI;
726
   case PIPE_SHADER_CAP_SUPPORTED_IRS:
727
      return 0;
728 729
   case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
   case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
730
   case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED:
731 732
   case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
   case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
733
   case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
734
   case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
735
   case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
736
   case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
737
   case PIPE_SHADER_CAP_INT64_ATOMICS:
738 739
   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
740
      return 0;
741 742
   case PIPE_SHADER_CAP_SCALAR_ISA:
      return 1;
743 744
   case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
      return 32;
745 746 747 748 749 750 751 752 753
   default:
      debug_printf("Unexpected vgpu10 shader query %u\n", param);
      return 0;
   }
   return 0;
}


static int
754
svga_get_shader_param(struct pipe_screen *screen, enum pipe_shader_type shader,
755 756 757 758 759 760 761 762 763 764 765 766 767
                      enum pipe_shader_cap param)
{
   struct svga_screen *svgascreen = svga_screen(screen);
   struct svga_winsys_screen *sws = svgascreen->sws;
   if (sws->have_vgpu10) {
      return vgpu10_get_shader_param(screen, shader, param);
   }
   else {
      return vgpu9_get_shader_param(screen, shader, param);
   }
}


Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
768 769 770 771 772 773 774 775 776 777
static void
svga_fence_reference(struct pipe_screen *screen,
                     struct pipe_fence_handle **ptr,
                     struct pipe_fence_handle *fence)
{
   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
   sws->fence_reference(sws, ptr, fence);
}


778
static boolean
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
779
svga_fence_finish(struct pipe_screen *screen,
780
                  struct pipe_context *ctx,
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
781
                  struct pipe_fence_handle *fence,
782
                  uint64_t timeout)
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
783 784
{
   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
785
   boolean retVal;
Keith Whitwell's avatar
Keith Whitwell committed
786

787
   SVGA_STATS_TIME_PUSH(sws, SVGA_STATS_TIME_FENCEFINISH);
788

789 790 791 792 793 794 795
   if (!timeout) {
      retVal = sws->fence_signalled(sws, fence, 0) == 0;
   }
   else {
      SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",
               __FUNCTION__, fence);

796
      retVal = sws->fence_finish(sws, fence, timeout, 0) == 0;
797 798 799
   }

   SVGA_STATS_TIME_POP(sws);
Keith Whitwell's avatar
Keith Whitwell committed
800

801
   return retVal;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
802 803 804
}


805 806 807 808 809 810 811 812 813 814
static int
svga_fence_get_fd(struct pipe_screen *screen,
                  struct pipe_fence_handle *fence)
{
   struct svga_winsys_screen *sws = svga_screen(screen)->sws;

   return sws->fence_get_fd(sws, fence, TRUE);
}


815 816 817 818 819
static int
svga_get_driver_query_info(struct pipe_screen *screen,
                           unsigned index,
                           struct pipe_driver_query_info *info)
{
820 821 822
#define QUERY(NAME, ENUM, UNITS) \
   {NAME, ENUM, {0}, UNITS, PIPE_DRIVER_QUERY_RESULT_TYPE_AVERAGE, 0, 0x0}

823
   static const struct pipe_driver_query_info queries[] = {
824
      /* per-frame counters */
825 826 827 828 829 830 831 832 833 834
      QUERY("num-draw-calls", SVGA_QUERY_NUM_DRAW_CALLS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-fallbacks", SVGA_QUERY_NUM_FALLBACKS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-flushes", SVGA_QUERY_NUM_FLUSHES,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-validations", SVGA_QUERY_NUM_VALIDATIONS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("map-buffer-time", SVGA_QUERY_MAP_BUFFER_TIME,
            PIPE_DRIVER_QUERY_TYPE_MICROSECONDS),
835 836 837
      QUERY("num-buffers-mapped", SVGA_QUERY_NUM_BUFFERS_MAPPED,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-textures-mapped", SVGA_QUERY_NUM_TEXTURES_MAPPED,
838 839 840
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-bytes-uploaded", SVGA_QUERY_NUM_BYTES_UPLOADED,
            PIPE_DRIVER_QUERY_TYPE_BYTES),
841 842
      QUERY("command-buffer-size", SVGA_QUERY_COMMAND_BUFFER_SIZE,
            PIPE_DRIVER_QUERY_TYPE_BYTES),
843 844
      QUERY("flush-time", SVGA_QUERY_FLUSH_TIME,
            PIPE_DRIVER_QUERY_TYPE_MICROSECONDS),
845 846
      QUERY("surface-write-flushes", SVGA_QUERY_SURFACE_WRITE_FLUSHES,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
847 848
      QUERY("num-readbacks", SVGA_QUERY_NUM_READBACKS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
849 850 851 852 853 854 855 856
      QUERY("num-resource-updates", SVGA_QUERY_NUM_RESOURCE_UPDATES,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-buffer-uploads", SVGA_QUERY_NUM_BUFFER_UPLOADS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-const-buf-updates", SVGA_QUERY_NUM_CONST_BUF_UPDATES,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-const-updates", SVGA_QUERY_NUM_CONST_UPDATES,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
857 858

      /* running total counters */
859 860 861 862 863 864 865 866 867 868
      QUERY("memory-used", SVGA_QUERY_MEMORY_USED,
            PIPE_DRIVER_QUERY_TYPE_BYTES),
      QUERY("num-shaders", SVGA_QUERY_NUM_SHADERS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-resources", SVGA_QUERY_NUM_RESOURCES,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-state-objects", SVGA_QUERY_NUM_STATE_OBJECTS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
      QUERY("num-surface-views", SVGA_QUERY_NUM_SURFACE_VIEWS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
869 870
      QUERY("num-generate-mipmap", SVGA_QUERY_NUM_GENERATE_MIPMAP,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
871 872
      QUERY("num-failed-allocations", SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
            PIPE_DRIVER_QUERY_TYPE_UINT64),
873 874
      QUERY("num-commands-per-draw", SVGA_QUERY_NUM_COMMANDS_PER_DRAW,
            PIPE_DRIVER_QUERY_TYPE_FLOAT),
875
   };
876
#undef QUERY
877 878

   if (!info)
Brian Paul's avatar
Brian Paul committed
879
      return ARRAY_SIZE(queries);
880

Brian Paul's avatar
Brian Paul committed
881
   if (index >= ARRAY_SIZE(queries))
882 883 884 885 886 887 888
      return 0;

   *info = queries[index];
   return 1;
}


889 890 891 892 893 894 895 896 897 898 899 900
static void
init_logging(struct pipe_screen *screen)
{
   static const char *log_prefix = "Mesa: ";
   char host_log[1000];

   /* Log Version to Host */
   util_snprintf(host_log, sizeof(host_log) - strlen(log_prefix),
                 "%s%s", log_prefix, svga_get_name(screen));
   svga_host_log(host_log);

   util_snprintf(host_log, sizeof(host_log) - strlen(log_prefix),
901
                 "%s" PACKAGE_VERSION MESA_GIT_SHA1, log_prefix);
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
   svga_host_log(host_log);

   /* If the SVGA_EXTRA_LOGGING env var is set, log the process's command
    * line (program name and arguments).
    */
   if (debug_get_bool_option("SVGA_EXTRA_LOGGING", FALSE)) {
      char cmdline[1000];
      if (os_get_command_line(cmdline, sizeof(cmdline))) {
         util_snprintf(host_log, sizeof(host_log) - strlen(log_prefix),
                       "%s%s", log_prefix, cmdline);
         svga_host_log(host_log);
      }
   }
}


Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
918 919 920 921
static void
svga_destroy_screen( struct pipe_screen *screen )
{
   struct svga_screen *svgascreen = svga_screen(screen);
922

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
923 924
   svga_screen_cache_cleanup(svgascreen);

925 926
   mtx_destroy(&svgascreen->swc_mutex);
   mtx_destroy(&svgascreen->tex_mutex);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
927 928

   svgascreen->sws->destroy(svgascreen->sws);
929

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
   FREE(svgascreen);
}


/**
 * Create a new svga_screen object
 */
struct pipe_screen *
svga_screen_create(struct svga_winsys_screen *sws)
{
   struct svga_screen *svgascreen;
   struct pipe_screen *screen;

#ifdef DEBUG
   SVGA_DEBUG = debug_get_flags_option("SVGA_DEBUG", svga_debug_flags, 0 );
#endif

   svgascreen = CALLOC_STRUCT(svga_screen);
   if (!svgascreen)
      goto error1;

   svgascreen->debug.force_level_surface_view =
      debug_get_bool_option("SVGA_FORCE_LEVEL_SURFACE_VIEW", FALSE);
   svgascreen->debug.force_surface_view =
      debug_get_bool_option("SVGA_FORCE_SURFACE_VIEW", FALSE);
   svgascreen->debug.force_sampler_view =
      debug_get_bool_option("SVGA_FORCE_SAMPLER_VIEW", FALSE);
   svgascreen->debug.no_surface_view =
      debug_get_bool_option("SVGA_NO_SURFACE_VIEW", FALSE);
   svgascreen->debug.no_sampler_view =
      debug_get_bool_option("SVGA_NO_SAMPLER_VIEW", FALSE);
961 962
   svgascreen->debug.no_cache_index_buffers =
      debug_get_bool_option("SVGA_NO_CACHE_INDEX_BUFFERS", FALSE);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
963 964 965 966 967 968

   screen = &svgascreen->screen;

   screen->destroy = svga_destroy_screen;
   screen->get_name = svga_get_name;
   screen->get_vendor = svga_get_vendor;
969
   screen->get_device_vendor = svga_get_vendor; // TODO actual device vendor
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
970
   screen->get_param = svga_get_param;
971
   screen->get_shader_param = svga_get_shader_param;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
972
   screen->get_paramf = svga_get_paramf;
973
   screen->get_timestamp = NULL;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
974
   screen->is_format_supported = svga_is_format_supported;
975
   screen->context_create = svga_context_create;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
976 977
   screen->fence_reference = svga_fence_reference;
   screen->fence_finish = svga_fence_finish;
978 979
   screen->fence_get_fd = svga_fence_get_fd;

980
   screen->get_driver_query_info = svga_get_driver_query_info;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
981 982
   svgascreen->sws = sws;

983
   svga_init_screen_resource_functions(svgascreen);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
984

985 986 987 988 989 990
   if (sws->get_hw_version) {
      svgascreen->hw_version = sws->get_hw_version(sws);
   } else {
      svgascreen->hw_version = SVGA3D_HWVERSION_WS65_B1;
   }

991 992 993 994 995 996 997
   if (svgascreen->hw_version < SVGA3D_HWVERSION_WS8_B1) {
      /* too old for 3D acceleration */
      debug_printf("Hardware version 0x%x is too old for accerated 3D\n",
                   svgascreen->hw_version);
      goto error2;
   }

998 999 1000 1001
   debug_printf("%s enabled = %u\n",
                sws->have_sm4_1 ? "SM4_1" : "VGPU10",
                sws->have_sm4_1 ? 1 : sws->have_vgpu10);

1002 1003 1004
   debug_printf("Mesa: %s %s (%s)\n", svga_get_name(screen),
                PACKAGE_VERSION, MESA_GIT_SHA1);

1005 1006 1007 1008 1009 1010 1011 1012 1013
   /*
    * The D16, D24X8, and D24S8 formats always do an implicit shadow compare
    * when sampled from, where as the DF16, DF24, and D24S8_INT do not.  So
    * we prefer the later when available.
    *
    * This mimics hardware vendors extensions for D3D depth sampling. See also
    * http://aras-p.info/texts/D3D9GPUHacks.html
    */

1014
   {
1015 1016
      boolean has_df16, has_df24, has_d24s8_int;
      SVGA3dSurfaceFormatCaps caps;
1017 1018 1019 1020 1021
      SVGA3dSurfaceFormatCaps mask;
      mask.value = 0;
      mask.zStencil = 1;
      mask.texture = 1;

1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
      svgascreen->depth.z16 = SVGA3D_Z_D16;
      svgascreen->depth.x8z24 = SVGA3D_Z_D24X8;
      svgascreen->depth.s8z24 = SVGA3D_Z_D24S8;

      svga_get_format_cap(svgascreen, SVGA3D_Z_DF16, &caps);
      has_df16 = (caps.value & mask.value) == mask.value;

      svga_get_format_cap(svgascreen, SVGA3D_Z_DF24, &caps);
      has_df24 = (caps.value & mask.value) == mask.value;

      svga_get_format_cap(svgascreen, SVGA3D_Z_D24S8_INT, &caps);
      has_d24s8_int = (caps.value & mask.value) == mask.value;
1034

1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
      /* XXX: We might want some other logic here.
       * Like if we only have d24s8_int we should
       * emulate the other formats with that.
       */
      if (has_df16) {
         svgascreen->depth.z16 = SVGA3D_Z_DF16;
      }
      if (has_df24) {
         svgascreen->depth.x8z24 = SVGA3D_Z_DF24;
      }
      if (has_d24s8_int) {
         svgascreen->depth.s8z24 = SVGA3D_Z_D24S8_INT;
      }
   }
1049

1050 1051
   /* Query device caps
    */
1052 1053 1054 1055 1056 1057 1058
   if (sws->have_vgpu10) {
      svgascreen->haveProvokingVertex
         = get_bool_cap(sws, SVGA3D_DEVCAP_DX_PROVOKING_VERTEX, FALSE);
      svgascreen->haveLineSmooth = TRUE;
      svgascreen->maxPointSize = 80.0F;
      svgascreen->max_color_buffers = SVGA3D_DX_MAX_RENDER_TARGETS;

1059 1060 1061 1062 1063 1064 1065 1066
      /* Multisample samples per pixel */
      if (sws->have_sm4_1 && debug_get_bool_option("SVGA_MSAA", TRUE)) {
         if (get_bool_cap(sws, SVGA3D_DEVCAP_MULTISAMPLE_2X, FALSE))
            svgascreen->ms_samples |= 1 << 1;
         if (get_bool_cap(sws, SVGA3D_DEVCAP_MULTISAMPLE_4X, FALSE))
            svgascreen->ms_samples |= 1 << 3;
      }

1067 1068 1069 1070
      /* Maximum number of constant buffers */
      svgascreen->max_const_buffers =
         get_uint_cap(sws, SVGA3D_DEVCAP_DX_MAX_CONSTANT_BUFFERS, 1);
      assert(svgascreen->max_const_buffers <= SVGA_MAX_CONST_BUFS);
1071 1072

      screen->is_format_supported = svga_is_dx_format_supported;
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
   }
   else {
      /* VGPU9 */
      unsigned vs_ver = get_uint_cap(sws, SVGA3D_DEVCAP_VERTEX_SHADER_VERSION,
                                     SVGA3DVSVERSION_NONE);
      unsigned fs_ver = get_uint_cap(sws, SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION,
                                     SVGA3DPSVERSION_NONE);

      /* we require Shader model 3.0 or later */
      if (fs_ver < SVGA3DPSVERSION_30 || vs_ver < SVGA3DVSVERSION_30) {
         goto error2;
      }
1085

1086
      svgascreen->haveProvokingVertex = FALSE;
1087

1088 1089
      svgascreen->haveLineSmooth =
         get_bool_cap(sws, SVGA3D_DEVCAP_LINE_AA, FALSE);
1090

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
      svgascreen->maxPointSize =
         get_float_cap(sws, SVGA3D_DEVCAP_MAX_POINT_SIZE, 1.0f);
      /* Keep this to a reasonable size to avoid failures in conform/pntaa.c */
      svgascreen->maxPointSize = MIN2(svgascreen->maxPointSize, 80.0f);

      /* The SVGA3D device always supports 4 targets at this time, regardless
       * of what querying SVGA3D_DEVCAP_MAX_RENDER_TARGETS might return.
       */
      svgascreen->max_color_buffers = 4;

      /* Only support one constant buffer
       */
      svgascreen->max_const_buffers = 1;
1104

1105 1106 1107 1108 1109 1110 1111 1112 1113
      /* No multisampling */
      svgascreen->ms_samples = 0;
   }

   /* common VGPU9 / VGPU10 caps */
   svgascreen->haveLineStipple =
      get_bool_cap(sws, SVGA3D_DEVCAP_LINE_STIPPLE, FALSE);

   svgascreen->maxLineWidth =
1114
      MAX2(1.0, get_float_cap(sws, SVGA3D_DEVCAP_MAX_LINE_WIDTH, 1.0f));
1115 1116

   svgascreen->maxLineWidthAA =
1117
      MAX2(1.0, get_float_cap(sws, SVGA3D_DEVCAP_MAX_AA_LINE_WIDTH, 1.0f));
1118 1119 1120 1121

   if (0) {
      debug_printf("svga: haveProvokingVertex %u\n",
                   svgascreen->haveProvokingVertex);