virgl_screen.c 34.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2014, 2015 Red Hat.
 *
 * 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
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, 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 (including the next
 * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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.
 */
#include "util/u_memory.h"
24 25
#include "util/format/u_format.h"
#include "util/format/u_format_s3tc.h"
26
#include "util/u_screen.h"
27
#include "util/u_video.h"
28
#include "util/u_math.h"
29
#include "util/os_time.h"
30
#include "util/xmlconfig.h"
31 32 33 34 35
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"

#include "tgsi/tgsi_exec.h"

36
#include "virgl_screen.h"
37 38 39
#include "virgl_resource.h"
#include "virgl_public.h"
#include "virgl_context.h"
40
#include "virgl_protocol.h"
41

42 43
int virgl_debug = 0;
static const struct debug_named_value debug_options[] = {
44 45 46 47
   { "verbose",   VIRGL_DEBUG_VERBOSE,             NULL },
   { "tgsi",      VIRGL_DEBUG_TGSI,                NULL },
   { "emubgra",   VIRGL_DEBUG_EMULATE_BGRA,        "Enable tweak to emulate BGRA as RGBA on GLES hosts"},
   { "bgraswz",   VIRGL_DEBUG_BGRA_DEST_SWIZZLE,   "Enable tweak to swizzle emulated BGRA on GLES hosts" },
Chia-I Wu's avatar
Chia-I Wu committed
48
   { "sync",      VIRGL_DEBUG_SYNC,                "Sync after every flush" },
Chia-I Wu's avatar
Chia-I Wu committed
49
   { "xfer",      VIRGL_DEBUG_XFER,                "Do not optimize for transfers" },
50 51 52 53
   DEBUG_NAMED_VALUE_END
};
DEBUG_GET_ONCE_FLAGS_OPTION(virgl_debug, "VIRGL_DEBUG", debug_options, 0)

54 55 56
static const char *
virgl_get_vendor(struct pipe_screen *screen)
{
57
   return "Mesa/X.org";
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
}


static const char *
virgl_get_name(struct pipe_screen *screen)
{
   return "virgl";
}

static int
virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   switch (param) {
   case PIPE_CAP_NPOT_TEXTURES:
      return 1;
74 75 76
   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
   case PIPE_CAP_VERTEX_SHADER_SATURATE:
77 78 79 80 81 82 83 84 85 86 87 88
      return 1;
   case PIPE_CAP_ANISOTROPIC_FILTER:
      return 1;
   case PIPE_CAP_POINT_SPRITE:
      return 1;
   case PIPE_CAP_MAX_RENDER_TARGETS:
      return vscreen->caps.caps.v1.max_render_targets;
   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
      return vscreen->caps.caps.v1.max_dual_source_render_targets;
   case PIPE_CAP_OCCLUSION_QUERY:
      return vscreen->caps.caps.v1.bset.occlusion_query;
   case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
89
   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
90 91 92
      return vscreen->caps.caps.v1.bset.mirror_clamp;
   case PIPE_CAP_TEXTURE_SWIZZLE:
      return 1;
93
   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
94
      if (vscreen->caps.caps.v2.max_texture_2d_size)
95 96
         return vscreen->caps.caps.v2.max_texture_2d_size;
      return 16384;
97
   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
98 99
      if (vscreen->caps.caps.v2.max_texture_3d_size)
         return 1 + util_logbase2(vscreen->caps.caps.v2.max_texture_3d_size);
100
      return 9; /* 256 x 256 x 256 */
101
   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
102 103
      if (vscreen->caps.caps.v2.max_texture_cube_size)
         return 1 + util_logbase2(vscreen->caps.caps.v2.max_texture_cube_size);
104
      return 13; /* 4K x 4K */
105 106 107 108 109 110 111 112 113
   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
      return 1;
   case PIPE_CAP_INDEP_BLEND_ENABLE:
      return vscreen->caps.caps.v1.bset.indep_blend_enable;
   case PIPE_CAP_INDEP_BLEND_FUNC:
      return vscreen->caps.caps.v1.bset.indep_blend_func;
   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
114 115
      return 1;
   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
116 117
      return vscreen->caps.caps.v1.bset.fragment_coord_conventions;
   case PIPE_CAP_DEPTH_CLIP_DISABLE:
118 119 120 121 122
      if (vscreen->caps.caps.v1.bset.depth_clip_disable)
         return 1;
      if (vscreen->caps.caps.v2.host_feature_check_version >= 3)
         return 2;
      return 0;
123 124 125 126 127 128
   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
      return vscreen->caps.caps.v1.max_streamout_buffers;
   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
      return 16*4;
   case PIPE_CAP_PRIMITIVE_RESTART:
129
   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
130 131 132 133 134 135 136 137 138 139 140 141 142
      return vscreen->caps.caps.v1.bset.primitive_restart;
   case PIPE_CAP_SHADER_STENCIL_EXPORT:
      return vscreen->caps.caps.v1.bset.shader_stencil_export;
   case PIPE_CAP_TGSI_INSTANCEID:
   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
      return 1;
   case PIPE_CAP_SEAMLESS_CUBE_MAP:
      return vscreen->caps.caps.v1.bset.seamless_cube_map;
   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
      return vscreen->caps.caps.v1.bset.seamless_cube_map_per_texture;
   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
      return vscreen->caps.caps.v1.max_texture_array_layers;
   case PIPE_CAP_MIN_TEXEL_OFFSET:
143
      return vscreen->caps.caps.v2.min_texel_offset;
144
   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
145
      return vscreen->caps.caps.v2.min_texture_gather_offset;
146
   case PIPE_CAP_MAX_TEXEL_OFFSET:
147
      return vscreen->caps.caps.v2.max_texel_offset;
148
   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
149
      return vscreen->caps.caps.v2.max_texture_gather_offset;
150 151 152
   case PIPE_CAP_CONDITIONAL_RENDER:
      return vscreen->caps.caps.v1.bset.conditional_render;
   case PIPE_CAP_TEXTURE_BARRIER:
153
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_TEXTURE_BARRIER;
154 155 156 157 158 159
   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
      return 1;
   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
   case PIPE_CAP_VERTEX_COLOR_CLAMPED:
      return vscreen->caps.caps.v1.bset.color_clamping;
   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
160 161
      return (vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_FBO_MIXED_COLOR_FORMATS) ||
            (vscreen->caps.caps.v2.host_feature_check_version < 1);
162 163
   case PIPE_CAP_GLSL_FEATURE_LEVEL:
      return vscreen->caps.caps.v1.glsl_level;
164 165
   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
      return MIN2(vscreen->caps.caps.v1.glsl_level, 140);
166
   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
167
   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
168 169
      return 0;
   case PIPE_CAP_COMPUTE:
170
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_COMPUTE_SHADER;
171 172 173
   case PIPE_CAP_USER_VERTEX_BUFFERS:
      return 0;
   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
174
      return vscreen->caps.caps.v2.uniform_buffer_offset_alignment;
175
   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
176
   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
177 178 179 180 181 182 183 184 185 186 187 188
      return vscreen->caps.caps.v1.bset.streamout_pause_resume;
   case PIPE_CAP_START_INSTANCE:
      return vscreen->caps.caps.v1.bset.start_instance;
   case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
   case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
   case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
   case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
   case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
      return 0;
   case PIPE_CAP_QUERY_TIMESTAMP:
      return 1;
   case PIPE_CAP_QUERY_TIME_ELAPSED:
189
      return 1;
190 191 192 193 194 195 196
   case PIPE_CAP_TGSI_TEXCOORD:
      return 0;
   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
      return VIRGL_MAP_BUFFER_ALIGNMENT;
   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
      return vscreen->caps.caps.v1.max_tbo_size > 0;
   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
197
      return vscreen->caps.caps.v2.texture_buffer_offset_alignment;
198 199
   case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
      return 0;
200 201 202 203 204 205 206 207 208 209 210 211 212
   case PIPE_CAP_CUBE_MAP_ARRAY:
      return vscreen->caps.caps.v1.bset.cube_map_array;
   case PIPE_CAP_TEXTURE_MULTISAMPLE:
      return vscreen->caps.caps.v1.bset.texture_multisample;
   case PIPE_CAP_MAX_VIEWPORTS:
      return vscreen->caps.caps.v1.max_viewports;
   case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
      return vscreen->caps.caps.v1.max_tbo_size;
   case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
   case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
   case PIPE_CAP_ENDIANNESS:
      return 0;
   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
213
   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
214 215 216 217
      return 1;
   case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
      return 0;
   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
218
      return vscreen->caps.caps.v2.max_geom_output_vertices;
219
   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
220
      return vscreen->caps.caps.v2.max_geom_total_output_components;
221 222 223 224
   case PIPE_CAP_TEXTURE_QUERY_LOD:
      return vscreen->caps.caps.v1.bset.texture_query_lod;
   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
      return vscreen->caps.caps.v1.max_texture_gather_components;
225 226
   case PIPE_CAP_DRAW_INDIRECT:
      return vscreen->caps.caps.v1.bset.has_indirect_draw;
227 228 229
   case PIPE_CAP_SAMPLE_SHADING:
   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
      return vscreen->caps.caps.v1.bset.has_sample_shading;
230 231
   case PIPE_CAP_CULL_DISTANCE:
      return vscreen->caps.caps.v1.bset.has_cull;
232
   case PIPE_CAP_MAX_VERTEX_STREAMS:
233 234
      return ((vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_TRANSFORM_FEEDBACK3) ||
              (vscreen->caps.caps.v2.host_feature_check_version < 2)) ? 4 : 1;
235 236
   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
      return vscreen->caps.caps.v1.bset.conditional_render_inverted;
237 238
   case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
      return vscreen->caps.caps.v1.bset.derivative_control;
Dave Airlie's avatar
Dave Airlie committed
239 240
   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
      return vscreen->caps.caps.v1.bset.polygon_offset_clamp;
241 242
   case PIPE_CAP_QUERY_SO_OVERFLOW:
      return vscreen->caps.caps.v1.bset.transform_feedback_overflow_query;
243 244
   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
      return vscreen->caps.caps.v2.shader_buffer_offset_alignment;
245
   case PIPE_CAP_DOUBLES:
246 247
      return vscreen->caps.caps.v1.bset.has_fp64 ||
            (vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_FAKE_FP64);
248 249
   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
      return vscreen->caps.caps.v2.max_shader_patch_varyings;
250 251
   case PIPE_CAP_SAMPLER_VIEW_TARGET:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_TEXTURE_VIEW;
252 253
   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
      return vscreen->caps.caps.v2.max_vertex_attrib_stride;
254 255
   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_COPY_IMAGE;
Dave Airlie's avatar
Dave Airlie committed
256 257
   case PIPE_CAP_TGSI_TXQS:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_TXQS;
258 259
   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_FB_NO_ATTACH;
260 261
   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_ROBUST_BUFFER_ACCESS;
262 263 264
   case PIPE_CAP_FBFETCH:
      return (vscreen->caps.caps.v2.capability_bits &
              VIRGL_CAP_TGSI_FBFETCH) ? 1 : 0;
265 266
   case PIPE_CAP_TGSI_CLOCK:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_SHADER_CLOCK;
267 268
   case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_TGSI_COMPONENTS;
269 270 271 272 273 274
   case PIPE_CAP_MAX_COMBINED_SHADER_BUFFERS:
      return vscreen->caps.caps.v2.max_combined_shader_buffers;
   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS:
      return vscreen->caps.caps.v2.max_combined_atomic_counters;
   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS:
      return vscreen->caps.caps.v2.max_combined_atomic_counter_buffers;
275 276 277
   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
      return 1; /* TODO: need to introduce a hw-cap for this */
278 279
   case PIPE_CAP_QUERY_BUFFER_OBJECT:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_QBO;
280 281 282 283
   case PIPE_CAP_MAX_VARYINGS:
      if (vscreen->caps.caps.v1.glsl_level < 150)
         return vscreen->caps.caps.v2.max_vertex_attribs;
      return 32;
284 285 286 287
   case PIPE_CAP_FAKE_SW_MSAA:
      /* If the host supports only one sample (e.g., if it is using softpipe),
       * fake multisampling to able to advertise higher GL versions. */
      return (vscreen->caps.caps.v1.max_samples == 1) ? 1 : 0;
288 289
   case PIPE_CAP_MULTI_DRAW_INDIRECT:
      return !!(vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_MULTI_DRAW_INDIRECT);
290 291
   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
      return !!(vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_INDIRECT_PARAMS);
292 293 294 295 296 297 298 299 300 301
   case PIPE_CAP_TEXTURE_GATHER_SM5:
   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
   case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
   case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
   case PIPE_CAP_VERTEXID_NOBASE:
   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
   case PIPE_CAP_DEPTH_BOUNDS_TEST:
   case PIPE_CAP_SHAREABLE_SHADERS:
302
   case PIPE_CAP_DRAW_PARAMETERS:
303
   case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
304 305
   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
   case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
306
   case PIPE_CAP_INVALIDATE_BUFFER:
307
   case PIPE_CAP_GENERATE_MIPMAP:
308
   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
309 310
   case PIPE_CAP_STRING_MARKER:
   case PIPE_CAP_QUERY_MEMORY_INFO:
311 312 313 314
   case PIPE_CAP_PCI_GROUP:
   case PIPE_CAP_PCI_BUS:
   case PIPE_CAP_PCI_DEVICE:
   case PIPE_CAP_PCI_FUNCTION:
315
   case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
316
   case PIPE_CAP_TGSI_VOTE:
317
   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
318
   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
319
   case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
320
   case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
321
   case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
322
   case PIPE_CAP_TGSI_MUL_ZERO_WINS:
323
   case PIPE_CAP_INT64:
324
   case PIPE_CAP_INT64_DIVMOD:
325
   case PIPE_CAP_TGSI_TEX_TXF_LZ:
326
   case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
327
   case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
328
   case PIPE_CAP_TGSI_BALLOT:
329
   case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
330
   case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
331
   case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
332
   case PIPE_CAP_POST_DEPTH_COVERAGE:
333
   case PIPE_CAP_BINDLESS_TEXTURE:
334
   case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
335
   case PIPE_CAP_MEMOBJ:
336
   case PIPE_CAP_LOAD_CONSTBUF:
337
   case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
338
   case PIPE_CAP_TILE_RASTER_ORDER:
339
   case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
340
   case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
341
   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
342
   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
343
   case PIPE_CAP_FENCE_SIGNAL:
344
   case PIPE_CAP_CONSTBUF0_FLAGS:
345
   case PIPE_CAP_PACKED_UNIFORMS:
346 347 348 349 350 351
   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:
352
   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
353
   case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
354
      return 0;
355 356
   case PIPE_CAP_CLEAR_TEXTURE:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_CLEAR_TEXTURE;
357 358
   case PIPE_CAP_CLIP_HALFZ:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_CLIP_HALFZ;
359 360
   case PIPE_CAP_MAX_GS_INVOCATIONS:
      return 32;
361 362
   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
      return 1 << 27;
363 364 365 366 367 368 369 370 371
   case PIPE_CAP_VENDOR_ID:
      return 0x1af4;
   case PIPE_CAP_DEVICE_ID:
      return 0x1010;
   case PIPE_CAP_ACCELERATED:
      return 1;
   case PIPE_CAP_UMA:
   case PIPE_CAP_VIDEO_MEMORY:
      return 0;
372
   case PIPE_CAP_NATIVE_FENCE_FD:
Robert Foss's avatar
Robert Foss committed
373
      return vscreen->vws->supports_fences;
374
   case PIPE_CAP_DEST_SURFACE_SRGB_CONTROL:
375 376
      return (vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_SRGB_WRITE_CONTROL) ||
            (vscreen->caps.caps.v2.host_feature_check_version < 1);
377 378
   case PIPE_CAP_TGSI_SKIP_SHRINK_IO_ARRAYS:
      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_INDIRECT_INPUT_ADDR;
379 380
   default:
      return u_pipe_screen_get_param_defaults(screen, param);
381 382 383 384
   }
}

static int
385 386 387
virgl_get_shader_param(struct pipe_screen *screen,
                       enum pipe_shader_type shader,
                       enum pipe_shader_cap param)
388 389
{
   struct virgl_screen *vscreen = virgl_screen(screen);
390 391 392 393 394

   if ((shader == PIPE_SHADER_TESS_CTRL || shader == PIPE_SHADER_TESS_EVAL) &&
       !vscreen->caps.caps.v1.bset.has_tessellation_shaders)
      return 0;

395 396 397 398
   if (shader == PIPE_SHADER_COMPUTE &&
       !(vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_COMPUTE_SHADER))
     return 0;

399 400 401 402 403
   switch(shader)
   {
   case PIPE_SHADER_FRAGMENT:
   case PIPE_SHADER_VERTEX:
   case PIPE_SHADER_GEOMETRY:
404 405
   case PIPE_SHADER_TESS_CTRL:
   case PIPE_SHADER_TESS_EVAL:
406
   case PIPE_SHADER_COMPUTE:
407 408 409 410 411 412 413 414 415 416
      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 INT_MAX;
      case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
      case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
      case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
         return 1;
417 418 419
      case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
      case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
         return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_INDIRECT_INPUT_ADDR;
420 421
      case PIPE_SHADER_CAP_MAX_INPUTS:
         if (vscreen->caps.caps.v1.glsl_level < 150)
422
            return vscreen->caps.caps.v2.max_vertex_attribs;
423
         return (shader == PIPE_SHADER_VERTEX ||
424
                 shader == PIPE_SHADER_GEOMETRY) ? vscreen->caps.caps.v2.max_vertex_attribs : 32;
425
      case PIPE_SHADER_CAP_MAX_OUTPUTS:
426 427 428
         if (shader == PIPE_SHADER_FRAGMENT)
            return vscreen->caps.caps.v1.max_render_targets;
         return vscreen->caps.caps.v2.max_vertex_outputs;
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
     // case PIPE_SHADER_CAP_MAX_CONSTS:
     //    return 4096;
      case PIPE_SHADER_CAP_MAX_TEMPS:
         return 256;
      case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
         return vscreen->caps.caps.v1.max_uniform_blocks;
    //  case PIPE_SHADER_CAP_MAX_ADDRS:
     //    return 1;
      case PIPE_SHADER_CAP_SUBROUTINES:
         return 1;
      case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
            return 16;
      case PIPE_SHADER_CAP_INTEGERS:
         return vscreen->caps.caps.v1.glsl_level >= 130;
      case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
         return 32;
      case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
         return 4096 * sizeof(float[4]);
447
      case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
448
         if (shader == PIPE_SHADER_FRAGMENT || shader == PIPE_SHADER_COMPUTE)
449 450 451
            return vscreen->caps.caps.v2.max_shader_buffer_frag_compute;
         else
            return vscreen->caps.caps.v2.max_shader_buffer_other_stages;
452
      case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
453
         if (shader == PIPE_SHADER_FRAGMENT || shader == PIPE_SHADER_COMPUTE)
454 455 456
            return vscreen->caps.caps.v2.max_shader_image_frag_compute;
         else
            return vscreen->caps.caps.v2.max_shader_image_other_stages;
457 458
      case PIPE_SHADER_CAP_SUPPORTED_IRS:
         return (1 << PIPE_SHADER_IR_TGSI);
459 460 461 462
      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
         return vscreen->caps.caps.v2.max_atomic_counters[shader];
      case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
         return vscreen->caps.caps.v2.max_atomic_counter_buffers[shader];
463
      case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
464
      case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
465
      case PIPE_SHADER_CAP_INT64_ATOMICS:
Jan Vesely's avatar
Jan Vesely committed
466
      case PIPE_SHADER_CAP_FP16:
467 468
      case PIPE_SHADER_CAP_FP16_DERIVATIVES:
      case PIPE_SHADER_CAP_INT16:
469
         return 0;
470 471 472 473 474 475 476 477 478 479 480
      default:
         return 0;
      }
   default:
      return 0;
   }
}

static float
virgl_get_paramf(struct pipe_screen *screen, enum pipe_capf param)
{
481
   struct virgl_screen *vscreen = virgl_screen(screen);
482 483
   switch (param) {
   case PIPE_CAPF_MAX_LINE_WIDTH:
484
      return vscreen->caps.caps.v2.max_aliased_line_width;
485
   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
486
      return vscreen->caps.caps.v2.max_smooth_line_width;
487
   case PIPE_CAPF_MAX_POINT_WIDTH:
488
      return vscreen->caps.caps.v2.max_aliased_point_size;
489
   case PIPE_CAPF_MAX_POINT_WIDTH_AA:
490
      return vscreen->caps.caps.v2.max_smooth_point_size;
491 492 493
   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
      return 16.0;
   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
494
      return vscreen->caps.caps.v2.max_texture_lod_bias;
495 496 497 498
   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
      return 0.0f;
499 500 501 502 503 504
   }
   /* should only get here on unhandled cases */
   debug_printf("Unexpected PIPE_CAPF %d query\n", param);
   return 0.0;
}

505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
static int
virgl_get_compute_param(struct pipe_screen *screen,
                        enum pipe_shader_ir ir_type,
                        enum pipe_compute_cap param,
                        void *ret)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   if (!(vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_COMPUTE_SHADER))
      return 0;
   switch (param) {
   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
      if (ret) {
         uint64_t *grid_size = ret;
         grid_size[0] = vscreen->caps.caps.v2.max_compute_grid_size[0];
         grid_size[1] = vscreen->caps.caps.v2.max_compute_grid_size[1];
         grid_size[2] = vscreen->caps.caps.v2.max_compute_grid_size[2];
      }
      return 3 * sizeof(uint64_t) ;
   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
      if (ret) {
         uint64_t *block_size = ret;
         block_size[0] = vscreen->caps.caps.v2.max_compute_block_size[0];
         block_size[1] = vscreen->caps.caps.v2.max_compute_block_size[1];
         block_size[2] = vscreen->caps.caps.v2.max_compute_block_size[2];
      }
      return 3 * sizeof(uint64_t);
   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
      if (ret) {
         uint64_t *max_threads_per_block = ret;
         *max_threads_per_block = vscreen->caps.caps.v2.max_compute_work_group_invocations;
      }
      return sizeof(uint64_t);
   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:
      if (ret) {
         uint64_t *max_local_size = ret;
         /* Value reported by the closed source driver. */
         *max_local_size = vscreen->caps.caps.v2.max_compute_shared_memory_size;
      }
      return sizeof(uint64_t);
   default:
      break;
   }
   return 0;
}

550
static bool
551 552 553 554 555 556 557 558
has_format_bit(struct virgl_supported_format_mask *mask,
               enum virgl_formats fmt)
{
   assert(fmt < VIRGL_FORMAT_MAX);
   unsigned val = (unsigned)fmt;
   unsigned idx = val / 32;
   unsigned bit = val % 32;
   assert(idx < ARRAY_SIZE(mask->bitmask));
559
   return (mask->bitmask[idx] & (1u << bit)) != 0;
560 561
}

562
bool
563 564 565 566 567 568 569 570
virgl_has_readback_format(struct pipe_screen *screen,
                          enum virgl_formats fmt)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   return has_format_bit(&vscreen->caps.caps.v2.supported_readback_formats,
                         fmt);
}

571
static bool
572 573 574 575 576 577 578 579 580
virgl_is_vertex_format_supported(struct pipe_screen *screen,
                                 enum pipe_format format)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   const struct util_format_description *format_desc;
   int i;

   format_desc = util_format_description(format);
   if (!format_desc)
581
      return false;
582 583 584 585 586 587

   if (format == PIPE_FORMAT_R11G11B10_FLOAT) {
      int vformat = VIRGL_FORMAT_R11G11B10_FLOAT;
      int big = vformat / 32;
      int small = vformat % 32;
      if (!(vscreen->caps.caps.v1.vertexbuffer.bitmask[big] & (1 << small)))
588 589
         return false;
      return true;
590 591 592 593 594 595 596 597 598 599
   }

   /* Find the first non-VOID channel. */
   for (i = 0; i < 4; i++) {
      if (format_desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
         break;
      }
   }

   if (i == 4)
600
      return false;
601 602

   if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
603
      return false;
604 605

   if (format_desc->channel[i].type == UTIL_FORMAT_TYPE_FIXED)
606 607
      return false;
   return true;
608 609
}

610
static bool
611
virgl_format_check_bitmask(enum pipe_format format,
612
                           uint32_t bitmask[16],
613
                           bool may_emulate_bgra)
614
{
615 616 617
   enum virgl_formats vformat = pipe_to_virgl_format(format);
   int big = vformat / 32;
   int small = vformat % 32;
618
   if ((bitmask[big] & (1 << small)))
619
      return true;
620

621 622 623 624 625 626 627 628
   /* On GLES hosts we don't advertise BGRx_SRGB, but we may be able
    * emulate it by using a swizzled RGBx */
   if (may_emulate_bgra) {
      if (format == PIPE_FORMAT_B8G8R8A8_SRGB)
         format = PIPE_FORMAT_R8G8B8A8_SRGB;
      else if (format == PIPE_FORMAT_B8G8R8X8_SRGB)
         format = PIPE_FORMAT_R8G8B8X8_SRGB;
      else {
629
         return false;
630 631
      }

632 633 634
      vformat = pipe_to_virgl_format(format);
      big = vformat / 32;
      small = vformat % 32;
635
      if (bitmask[big] & (1 << small))
636
         return true;
637
   }
638
   return false;
639 640
}

641 642 643 644 645
/**
 * Query format support for creating a texture, drawing surface, etc.
 * \param format  the format to test
 * \param type  one of PIPE_TEXTURE, PIPE_SURFACE
 */
646
static bool
647 648 649 650
virgl_is_format_supported( struct pipe_screen *screen,
                                 enum pipe_format format,
                                 enum pipe_texture_target target,
                                 unsigned sample_count,
651
                                 unsigned storage_sample_count,
652 653 654 655 656 657
                                 unsigned bind)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   const struct util_format_description *format_desc;
   int i;

658 659 660 661
   union virgl_caps *caps = &vscreen->caps.caps; 
   boolean may_emulate_bgra = (caps->v2.capability_bits &
                               VIRGL_CAP_APP_TWEAK_SUPPORT) &&
                               vscreen->tweak_gles_emulate_bgra;
662

663 664 665
   if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
      return false;

666 667 668
   if (!util_is_power_of_two_or_zero(sample_count))
      return false;

669 670 671 672 673 674 675 676 677 678 679 680
   assert(target == PIPE_BUFFER ||
          target == PIPE_TEXTURE_1D ||
          target == PIPE_TEXTURE_1D_ARRAY ||
          target == PIPE_TEXTURE_2D ||
          target == PIPE_TEXTURE_2D_ARRAY ||
          target == PIPE_TEXTURE_RECT ||
          target == PIPE_TEXTURE_3D ||
          target == PIPE_TEXTURE_CUBE ||
          target == PIPE_TEXTURE_CUBE_ARRAY);

   format_desc = util_format_description(format);
   if (!format_desc)
681
      return false;
682 683

   if (util_format_is_intensity(format))
684
      return false;
685 686

   if (sample_count > 1) {
687
      if (!caps->v1.bset.texture_multisample)
688
         return false;
689 690

      if (bind & PIPE_BIND_SHADER_IMAGE) {
691
         if (sample_count > caps->v2.max_image_samples)
692
            return false;
693 694
      }

695
      if (sample_count > caps->v1.max_samples)
696
         return false;
697 698 699 700 701 702
   }

   if (bind & PIPE_BIND_VERTEX_BUFFER) {
      return virgl_is_vertex_format_supported(screen, format);
   }

703
   if (util_format_is_compressed(format) && target == PIPE_BUFFER)
704
      return false;
705

706 707 708 709 710
   /* Allow 3-comp 32 bit textures only for TBOs (needed for ARB_tbo_rgb32) */
   if ((format == PIPE_FORMAT_R32G32B32_FLOAT ||
       format == PIPE_FORMAT_R32G32B32_SINT ||
       format == PIPE_FORMAT_R32G32B32_UINT) &&
       target != PIPE_BUFFER)
711
      return false;
712

713 714 715 716
   if ((format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC ||
        format_desc->layout == UTIL_FORMAT_LAYOUT_ETC ||
        format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) &&
       target == PIPE_TEXTURE_3D)
717
      return false;
718

719

720
   if (bind & PIPE_BIND_RENDER_TARGET) {
721 722 723 724
      /* For ARB_framebuffer_no_attachments. */
      if (format == PIPE_FORMAT_NONE)
         return TRUE;

725
      if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
726
         return false;
727 728 729 730

      /*
       * Although possible, it is unnatural to render into compressed or YUV
       * surfaces. So disable these here to avoid going into weird paths
731
       * inside gallium frontends.
732 733 734
       */
      if (format_desc->block.width != 1 ||
          format_desc->block.height != 1)
735
         return false;
736

737
      if (!virgl_format_check_bitmask(format,
738
                                      caps->v1.render.bitmask,
739
                                      may_emulate_bgra))
740
         return false;
741 742 743 744
   }

   if (bind & PIPE_BIND_DEPTH_STENCIL) {
      if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
745
         return false;
746 747
   }

Gurchetan Singh's avatar
Gurchetan Singh committed
748 749 750 751 752
   if (bind & PIPE_BIND_SCANOUT) {
      if (!virgl_format_check_bitmask(format, caps->v2.scanout.bitmask, false))
         return false;
   }

753 754 755 756 757
   /*
    * All other operations (sampling, transfer, etc).
    */

   if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
758
      goto out_lookup;
759 760 761 762
   }
   if (format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC) {
      goto out_lookup;
   }
Dave Airlie's avatar
Dave Airlie committed
763 764 765
   if (format_desc->layout == UTIL_FORMAT_LAYOUT_BPTC) {
      goto out_lookup;
   }
766 767 768
   if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC) {
      goto out_lookup;
   }
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783

   if (format == PIPE_FORMAT_R11G11B10_FLOAT) {
      goto out_lookup;
   } else if (format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
      goto out_lookup;
   }

   /* Find the first non-VOID channel. */
   for (i = 0; i < 4; i++) {
      if (format_desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
         break;
      }
   }

   if (i == 4)
784
      return false;
785 786 787

   /* no L4A4 */
   if (format_desc->nr_channels < 4 && format_desc->channel[i].size == 4)
788
      return false;
789 790

 out_lookup:
791
   return virgl_format_check_bitmask(format,
792
                                     caps->v1.sampler.bitmask,
793
                                     may_emulate_bgra);
794 795 796 797 798 799 800 801 802
}

static void virgl_flush_frontbuffer(struct pipe_screen *screen,
                                      struct pipe_resource *res,
                                      unsigned level, unsigned layer,
                                    void *winsys_drawable_handle, struct pipe_box *sub_box)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   struct virgl_winsys *vws = vscreen->vws;
803
   struct virgl_resource *vres = virgl_resource(res);
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819

   if (vws->flush_frontbuffer)
      vws->flush_frontbuffer(vws, vres->hw_res, level, layer, winsys_drawable_handle,
                             sub_box);
}

static void virgl_fence_reference(struct pipe_screen *screen,
                                  struct pipe_fence_handle **ptr,
                                  struct pipe_fence_handle *fence)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   struct virgl_winsys *vws = vscreen->vws;

   vws->fence_reference(vws, ptr, fence);
}

820 821 822 823
static bool virgl_fence_finish(struct pipe_screen *screen,
                               struct pipe_context *ctx,
                               struct pipe_fence_handle *fence,
                               uint64_t timeout)
824 825 826 827 828 829 830
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   struct virgl_winsys *vws = vscreen->vws;

   return vws->fence_wait(vws, fence, timeout);
}

Robert Foss's avatar
Robert Foss committed
831 832 833 834 835 836 837 838 839
static int virgl_fence_get_fd(struct pipe_screen *screen,
            struct pipe_fence_handle *fence)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   struct virgl_winsys *vws = vscreen->vws;

   return vws->fence_get_fd(vws, fence);
}

840 841 842 843 844 845 846 847 848 849 850 851
static uint64_t
virgl_get_timestamp(struct pipe_screen *_screen)
{
   return os_time_get_nano();
}

static void
virgl_destroy_screen(struct pipe_screen *screen)
{
   struct virgl_screen *vscreen = virgl_screen(screen);
   struct virgl_winsys *vws = vscreen->vws;

852
   slab_destroy_parent(&vscreen->transfer_pool);
853

854 855 856 857 858
   if (vws)
      vws->destroy(vws);
   FREE(vscreen);
}

859
static void
860
fixup_formats(union virgl_caps *caps, struct virgl_supported_format_mask *mask)
861
{
862
   const size_t size = ARRAY_SIZE(mask->bitmask);
863
   for (int i = 0; i < size; ++i) {
864
      if (mask->bitmask[i] != 0)
865 866 867 868 869 870
         return; /* we got some formats, we definately have a new protocol */
   }

   /* old protocol used; fall back to considering all sampleable formats valid
    * readback-formats
    */
871 872
   for (int i = 0; i < size; ++i)
      mask->bitmask[i] = caps->v1.sampler.bitmask[i];
873 874
}

875
struct pipe_screen *
876
virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *config)
877 878 879
{
   struct virgl_screen *screen = CALLOC_STRUCT(virgl_screen);

880
   const char *VIRGL_GLES_EMULATE_BGRA = "gles_emulate_bgra";
881
   const char *VIRGL_GLES_APPLY_BGRA_DEST_SWIZZLE = "gles_apply_bgra_dest_swizzle";
882 883
   const char *VIRGL_GLES_SAMPLES_PASSED_VALUE = "gles_samples_passed_value";

884 885 886
   if (!screen)
      return NULL;

887 888
   virgl_debug = debug_get_option_virgl_debug();

889 890 891
   if (config && config->options) {
      screen->tweak_gles_emulate_bgra =
            driQueryOptionb(config->options, VIRGL_GLES_EMULATE_BGRA);
892 893
      screen->tweak_gles_apply_bgra_dest_swizzle =
            driQueryOptionb(config->options, VIRGL_GLES_APPLY_BGRA_DEST_SWIZZLE);
894 895
      screen->tweak_gles_tf3_value =
            driQueryOptioni(config->options, VIRGL_GLES_SAMPLES_PASSED_VALUE);
896
   }
897

898 899 900
   screen->tweak_gles_emulate_bgra |= !!(virgl_debug & VIRGL_DEBUG_EMULATE_BGRA);
   screen->tweak_gles_apply_bgra_dest_swizzle |= !!(virgl_debug & VIRGL_DEBUG_BGRA_DEST_SWIZZLE);

901 902 903 904 905
   screen->vws = vws;
   screen->base.get_name = virgl_get_name;
   screen->base.get_vendor = virgl_get_vendor;
   screen->base.get_param = virgl_get_param;
   screen->base.get_shader_param = virgl_get_shader_param;
906
   screen->base.get_compute_param = virgl_get_compute_param;
907 908 909 910 911 912 913 914 915
   screen->base.get_paramf = virgl_get_paramf;
   screen->base.is_format_supported = virgl_is_format_supported;
   screen->base.destroy = virgl_destroy_screen;
   screen->base.context_create = virgl_context_create;
   screen->base.flush_frontbuffer = virgl_flush_frontbuffer;
   screen->base.get_timestamp = virgl_get_timestamp;
   screen->base.fence_reference = virgl_fence_reference;
   //screen->base.fence_signalled = virgl_fence_signalled;
   screen->base.fence_finish = virgl_fence_finish;
Robert Foss's avatar
Robert Foss committed
916
   screen->base.fence_get_fd = virgl_fence_get_fd;
917 918 919 920

   virgl_init_screen_resource_functions(&screen->base);

   vws->get_caps(vws, &screen->caps);
921 922
   fixup_formats(&screen->caps.caps,
                 &screen->caps.caps.v2.supported_readback_formats);
Gurchetan Singh's avatar
Gurchetan Singh committed
923
   fixup_formats(&screen->caps.caps, &screen->caps.caps.v2.scanout);
924

925
   screen->refcnt = 1;
926

927
   slab_create_parent(&screen->transfer_pool, sizeof(struct virgl_transfer), 16);
928

929 930
   return &screen->base;
}