Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014, 2015 Red Hat. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 8 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 9 | * the Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 21 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include "util/u_memory.h" |
| 24 | #include "util/u_format.h" |
| 25 | #include "util/u_format_s3tc.h" |
| 26 | #include "util/u_video.h" |
| 27 | #include "os/os_time.h" |
| 28 | #include "pipe/p_defines.h" |
| 29 | #include "pipe/p_screen.h" |
| 30 | #include "draw/draw_context.h" |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 31 | |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 32 | #include "tgsi/tgsi_exec.h" |
| 33 | |
Emil Velikov | 0c82c2f | 2015-10-29 10:10:35 +0000 | [diff] [blame] | 34 | #include "virgl_screen.h" |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 35 | #include "virgl_resource.h" |
| 36 | #include "virgl_public.h" |
| 37 | #include "virgl_context.h" |
| 38 | |
| 39 | #define SP_MAX_TEXTURE_2D_LEVELS 15 /* 16K x 16K */ |
| 40 | #define SP_MAX_TEXTURE_3D_LEVELS 9 /* 512 x 512 x 512 */ |
| 41 | #define SP_MAX_TEXTURE_CUBE_LEVELS 13 /* 4K x 4K */ |
| 42 | |
| 43 | static const char * |
| 44 | virgl_get_vendor(struct pipe_screen *screen) |
| 45 | { |
| 46 | return "Red Hat"; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | static const char * |
| 51 | virgl_get_name(struct pipe_screen *screen) |
| 52 | { |
| 53 | return "virgl"; |
| 54 | } |
| 55 | |
| 56 | static int |
| 57 | virgl_get_param(struct pipe_screen *screen, enum pipe_cap param) |
| 58 | { |
| 59 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 60 | switch (param) { |
| 61 | case PIPE_CAP_NPOT_TEXTURES: |
| 62 | return 1; |
| 63 | case PIPE_CAP_TWO_SIDED_STENCIL: |
| 64 | return 1; |
| 65 | case PIPE_CAP_SM3: |
| 66 | return 1; |
| 67 | case PIPE_CAP_ANISOTROPIC_FILTER: |
| 68 | return 1; |
| 69 | case PIPE_CAP_POINT_SPRITE: |
| 70 | return 1; |
| 71 | case PIPE_CAP_MAX_RENDER_TARGETS: |
| 72 | return vscreen->caps.caps.v1.max_render_targets; |
| 73 | case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS: |
| 74 | return vscreen->caps.caps.v1.max_dual_source_render_targets; |
| 75 | case PIPE_CAP_OCCLUSION_QUERY: |
| 76 | return vscreen->caps.caps.v1.bset.occlusion_query; |
| 77 | case PIPE_CAP_TEXTURE_MIRROR_CLAMP: |
| 78 | return vscreen->caps.caps.v1.bset.mirror_clamp; |
| 79 | case PIPE_CAP_TEXTURE_SHADOW_MAP: |
| 80 | return 1; |
| 81 | case PIPE_CAP_TEXTURE_SWIZZLE: |
| 82 | return 1; |
| 83 | case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: |
| 84 | return SP_MAX_TEXTURE_2D_LEVELS; |
| 85 | case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: |
| 86 | return SP_MAX_TEXTURE_3D_LEVELS; |
| 87 | case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: |
| 88 | return SP_MAX_TEXTURE_CUBE_LEVELS; |
| 89 | case PIPE_CAP_BLEND_EQUATION_SEPARATE: |
| 90 | return 1; |
| 91 | case PIPE_CAP_INDEP_BLEND_ENABLE: |
| 92 | return vscreen->caps.caps.v1.bset.indep_blend_enable; |
| 93 | case PIPE_CAP_INDEP_BLEND_FUNC: |
| 94 | return vscreen->caps.caps.v1.bset.indep_blend_func; |
| 95 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: |
| 96 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: |
| 97 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: |
| 98 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: |
| 99 | return vscreen->caps.caps.v1.bset.fragment_coord_conventions; |
| 100 | case PIPE_CAP_DEPTH_CLIP_DISABLE: |
| 101 | return vscreen->caps.caps.v1.bset.depth_clip_disable; |
| 102 | case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: |
| 103 | return vscreen->caps.caps.v1.max_streamout_buffers; |
| 104 | case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS: |
| 105 | case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS: |
| 106 | return 16*4; |
| 107 | case PIPE_CAP_PRIMITIVE_RESTART: |
| 108 | return vscreen->caps.caps.v1.bset.primitive_restart; |
| 109 | case PIPE_CAP_SHADER_STENCIL_EXPORT: |
| 110 | return vscreen->caps.caps.v1.bset.shader_stencil_export; |
| 111 | case PIPE_CAP_TGSI_INSTANCEID: |
| 112 | case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: |
| 113 | return 1; |
| 114 | case PIPE_CAP_SEAMLESS_CUBE_MAP: |
| 115 | return vscreen->caps.caps.v1.bset.seamless_cube_map; |
| 116 | case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE: |
| 117 | return vscreen->caps.caps.v1.bset.seamless_cube_map_per_texture; |
| 118 | case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: |
| 119 | return vscreen->caps.caps.v1.max_texture_array_layers; |
| 120 | case PIPE_CAP_MIN_TEXEL_OFFSET: |
| 121 | case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET: |
| 122 | return -8; |
| 123 | case PIPE_CAP_MAX_TEXEL_OFFSET: |
| 124 | case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET: |
| 125 | return 7; |
| 126 | case PIPE_CAP_CONDITIONAL_RENDER: |
| 127 | return vscreen->caps.caps.v1.bset.conditional_render; |
| 128 | case PIPE_CAP_TEXTURE_BARRIER: |
| 129 | return 0; |
| 130 | case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: |
| 131 | return 1; |
| 132 | case PIPE_CAP_FRAGMENT_COLOR_CLAMPED: |
| 133 | case PIPE_CAP_VERTEX_COLOR_CLAMPED: |
| 134 | return vscreen->caps.caps.v1.bset.color_clamping; |
| 135 | case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: |
| 136 | return 1; |
| 137 | case PIPE_CAP_GLSL_FEATURE_LEVEL: |
| 138 | return vscreen->caps.caps.v1.glsl_level; |
| 139 | case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION: |
| 140 | return 0; |
| 141 | case PIPE_CAP_COMPUTE: |
| 142 | return 0; |
| 143 | case PIPE_CAP_USER_VERTEX_BUFFERS: |
| 144 | return 0; |
| 145 | case PIPE_CAP_USER_INDEX_BUFFERS: |
| 146 | case PIPE_CAP_USER_CONSTANT_BUFFERS: |
| 147 | return 1; |
| 148 | case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: |
| 149 | return 16; |
| 150 | case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME: |
Ilia Mirkin | 3fdeb7c | 2016-10-14 00:03:12 -0400 | [diff] [blame^] | 151 | case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS: |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 152 | return vscreen->caps.caps.v1.bset.streamout_pause_resume; |
| 153 | case PIPE_CAP_START_INSTANCE: |
| 154 | return vscreen->caps.caps.v1.bset.start_instance; |
| 155 | case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: |
| 156 | case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY: |
| 157 | case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: |
| 158 | case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY: |
| 159 | case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER: |
| 160 | return 0; |
| 161 | case PIPE_CAP_QUERY_TIMESTAMP: |
| 162 | return 1; |
| 163 | case PIPE_CAP_QUERY_TIME_ELAPSED: |
| 164 | return 0; |
| 165 | case PIPE_CAP_TGSI_TEXCOORD: |
| 166 | return 0; |
| 167 | case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT: |
| 168 | return VIRGL_MAP_BUFFER_ALIGNMENT; |
| 169 | case PIPE_CAP_TEXTURE_BUFFER_OBJECTS: |
| 170 | return vscreen->caps.caps.v1.max_tbo_size > 0; |
| 171 | case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT: |
| 172 | return 0; |
Nicolai Hähnle | 3abb548 | 2016-01-26 10:26:30 -0500 | [diff] [blame] | 173 | case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY: |
| 174 | return 0; |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 175 | case PIPE_CAP_CUBE_MAP_ARRAY: |
| 176 | return vscreen->caps.caps.v1.bset.cube_map_array; |
| 177 | case PIPE_CAP_TEXTURE_MULTISAMPLE: |
| 178 | return vscreen->caps.caps.v1.bset.texture_multisample; |
| 179 | case PIPE_CAP_MAX_VIEWPORTS: |
| 180 | return vscreen->caps.caps.v1.max_viewports; |
| 181 | case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE: |
| 182 | return vscreen->caps.caps.v1.max_tbo_size; |
| 183 | case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK: |
| 184 | case PIPE_CAP_QUERY_PIPELINE_STATISTICS: |
| 185 | case PIPE_CAP_ENDIANNESS: |
| 186 | return 0; |
| 187 | case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: |
Ilia Mirkin | 9515d65 | 2016-08-20 22:40:33 -0400 | [diff] [blame] | 188 | case PIPE_CAP_MIXED_COLOR_DEPTH_BITS: |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 189 | return 1; |
| 190 | case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT: |
| 191 | return 0; |
| 192 | case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES: |
Dave Airlie | c7cc264 | 2016-06-28 06:45:28 +1000 | [diff] [blame] | 193 | return 256; |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 194 | case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS: |
| 195 | return 16384; |
| 196 | case PIPE_CAP_TEXTURE_QUERY_LOD: |
| 197 | return vscreen->caps.caps.v1.bset.texture_query_lod; |
| 198 | case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS: |
| 199 | return vscreen->caps.caps.v1.max_texture_gather_components; |
| 200 | case PIPE_CAP_TEXTURE_GATHER_SM5: |
| 201 | case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT: |
| 202 | case PIPE_CAP_SAMPLE_SHADING: |
| 203 | case PIPE_CAP_FAKE_SW_MSAA: |
| 204 | case PIPE_CAP_TEXTURE_GATHER_OFFSETS: |
| 205 | case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION: |
| 206 | case PIPE_CAP_MAX_VERTEX_STREAMS: |
| 207 | case PIPE_CAP_DRAW_INDIRECT: |
Ilia Mirkin | d67b9ba | 2015-12-31 13:30:13 -0500 | [diff] [blame] | 208 | case PIPE_CAP_MULTI_DRAW_INDIRECT: |
| 209 | case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS: |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 210 | case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE: |
| 211 | case PIPE_CAP_CONDITIONAL_RENDER_INVERTED: |
| 212 | case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE: |
| 213 | case PIPE_CAP_SAMPLER_VIEW_TARGET: |
| 214 | case PIPE_CAP_CLIP_HALFZ: |
| 215 | case PIPE_CAP_VERTEXID_NOBASE: |
| 216 | case PIPE_CAP_POLYGON_OFFSET_CLAMP: |
| 217 | case PIPE_CAP_MULTISAMPLE_Z_RESOLVE: |
| 218 | case PIPE_CAP_RESOURCE_FROM_USER_MEMORY: |
| 219 | case PIPE_CAP_DEVICE_RESET_STATUS_QUERY: |
| 220 | case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS: |
| 221 | case PIPE_CAP_TEXTURE_FLOAT_LINEAR: |
| 222 | case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR: |
| 223 | case PIPE_CAP_DEPTH_BOUNDS_TEST: |
| 224 | case PIPE_CAP_TGSI_TXQS: |
| 225 | case PIPE_CAP_FORCE_PERSAMPLE_INTERP: |
| 226 | case PIPE_CAP_SHAREABLE_SHADERS: |
Ilia Mirkin | 3695b25 | 2015-11-09 13:27:07 -0500 | [diff] [blame] | 227 | case PIPE_CAP_CLEAR_TEXTURE: |
Ilia Mirkin | 87b4e4e | 2015-12-29 16:49:32 -0500 | [diff] [blame] | 228 | case PIPE_CAP_DRAW_PARAMETERS: |
Ilia Mirkin | e9f43d6 | 2016-01-02 18:55:48 -0500 | [diff] [blame] | 229 | case PIPE_CAP_TGSI_PACK_HALF_FLOAT: |
Marek Olšák | 34738a9 | 2016-01-02 20:45:00 +0100 | [diff] [blame] | 230 | case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL: |
| 231 | case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL: |
Ilia Mirkin | ebfb544 | 2016-01-02 21:56:45 -0500 | [diff] [blame] | 232 | case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT: |
Nicolai Hähnle | 654670b | 2016-01-11 17:38:08 -0500 | [diff] [blame] | 233 | case PIPE_CAP_INVALIDATE_BUFFER: |
Charmaine Lee | 3038e89 | 2016-01-14 10:22:17 -0700 | [diff] [blame] | 234 | case PIPE_CAP_GENERATE_MIPMAP: |
Nicolai Hähnle | 6af6d7b | 2016-01-26 10:27:58 -0500 | [diff] [blame] | 235 | case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS: |
Ilia Mirkin | f9e6f46 | 2016-01-09 23:30:16 -0500 | [diff] [blame] | 236 | case PIPE_CAP_QUERY_BUFFER_OBJECT: |
Dave Airlie | 840aa52 | 2016-02-26 04:02:56 +0000 | [diff] [blame] | 237 | case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS: |
| 238 | case PIPE_CAP_STRING_MARKER: |
| 239 | case PIPE_CAP_QUERY_MEMORY_INFO: |
Marek Olšák | dcb2b77 | 2016-02-29 20:22:37 +0100 | [diff] [blame] | 240 | case PIPE_CAP_PCI_GROUP: |
| 241 | case PIPE_CAP_PCI_BUS: |
| 242 | case PIPE_CAP_PCI_DEVICE: |
| 243 | case PIPE_CAP_PCI_FUNCTION: |
Edward O'Callaghan | 4bc9130 | 2016-02-17 20:59:52 +1100 | [diff] [blame] | 244 | case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT: |
Bas Nieuwenhuizen | 70dcd84 | 2016-04-12 15:00:31 +0200 | [diff] [blame] | 245 | case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR: |
Dave Airlie | b19a0d5 | 2016-05-21 06:19:29 +1000 | [diff] [blame] | 246 | case PIPE_CAP_CULL_DISTANCE: |
Kenneth Graunke | 70048eb | 2016-05-20 21:05:34 -0700 | [diff] [blame] | 247 | case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES: |
Ilia Mirkin | edfa7a4 | 2016-05-29 11:39:52 -0400 | [diff] [blame] | 248 | case PIPE_CAP_TGSI_VOTE: |
Ilia Mirkin | 07fcb06 | 2016-06-11 15:26:45 -0400 | [diff] [blame] | 249 | case PIPE_CAP_MAX_WINDOW_RECTANGLES: |
Axel Davy | 59a6929 | 2016-06-13 22:28:32 +0200 | [diff] [blame] | 250 | case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED: |
Józef Kucia | 3cd28fe | 2016-07-19 13:07:24 +0200 | [diff] [blame] | 251 | case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS: |
Nicolai Hähnle | 700a571 | 2016-10-07 09:42:55 +0200 | [diff] [blame] | 252 | case PIPE_CAP_TGSI_ARRAY_COMPONENTS: |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 253 | return 0; |
| 254 | case PIPE_CAP_VENDOR_ID: |
| 255 | return 0x1af4; |
| 256 | case PIPE_CAP_DEVICE_ID: |
| 257 | return 0x1010; |
| 258 | case PIPE_CAP_ACCELERATED: |
| 259 | return 1; |
| 260 | case PIPE_CAP_UMA: |
| 261 | case PIPE_CAP_VIDEO_MEMORY: |
| 262 | return 0; |
| 263 | } |
| 264 | /* should only get here on unhandled cases */ |
| 265 | debug_printf("Unexpected PIPE_CAP %d query\n", param); |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | static int |
| 270 | virgl_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param) |
| 271 | { |
| 272 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 273 | switch(shader) |
| 274 | { |
| 275 | case PIPE_SHADER_FRAGMENT: |
| 276 | case PIPE_SHADER_VERTEX: |
| 277 | case PIPE_SHADER_GEOMETRY: |
| 278 | switch (param) { |
| 279 | case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: |
| 280 | case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: |
| 281 | case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: |
| 282 | case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: |
| 283 | return INT_MAX; |
| 284 | case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: |
| 285 | case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: |
| 286 | case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: |
| 287 | return 1; |
| 288 | case PIPE_SHADER_CAP_MAX_INPUTS: |
| 289 | if (vscreen->caps.caps.v1.glsl_level < 150) |
| 290 | return 16; |
Dave Airlie | c7cc264 | 2016-06-28 06:45:28 +1000 | [diff] [blame] | 291 | return (shader == PIPE_SHADER_VERTEX || |
| 292 | shader == PIPE_SHADER_GEOMETRY) ? 16 : 32; |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 293 | case PIPE_SHADER_CAP_MAX_OUTPUTS: |
Dave Airlie | c7cc264 | 2016-06-28 06:45:28 +1000 | [diff] [blame] | 294 | return 32; |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 295 | // case PIPE_SHADER_CAP_MAX_CONSTS: |
| 296 | // return 4096; |
| 297 | case PIPE_SHADER_CAP_MAX_TEMPS: |
| 298 | return 256; |
| 299 | case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: |
| 300 | return vscreen->caps.caps.v1.max_uniform_blocks; |
| 301 | // case PIPE_SHADER_CAP_MAX_ADDRS: |
| 302 | // return 1; |
| 303 | case PIPE_SHADER_CAP_MAX_PREDS: |
| 304 | return 0; |
| 305 | case PIPE_SHADER_CAP_SUBROUTINES: |
| 306 | return 1; |
| 307 | case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: |
| 308 | return 16; |
| 309 | case PIPE_SHADER_CAP_INTEGERS: |
| 310 | return vscreen->caps.caps.v1.glsl_level >= 130; |
| 311 | case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: |
| 312 | return 32; |
| 313 | case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE: |
| 314 | return 4096 * sizeof(float[4]); |
| 315 | default: |
| 316 | return 0; |
| 317 | } |
| 318 | default: |
| 319 | return 0; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | static float |
| 324 | virgl_get_paramf(struct pipe_screen *screen, enum pipe_capf param) |
| 325 | { |
| 326 | switch (param) { |
| 327 | case PIPE_CAPF_MAX_LINE_WIDTH: |
| 328 | /* fall-through */ |
| 329 | case PIPE_CAPF_MAX_LINE_WIDTH_AA: |
| 330 | return 255.0; /* arbitrary */ |
| 331 | case PIPE_CAPF_MAX_POINT_WIDTH: |
| 332 | /* fall-through */ |
| 333 | case PIPE_CAPF_MAX_POINT_WIDTH_AA: |
| 334 | return 255.0; /* arbitrary */ |
| 335 | case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: |
| 336 | return 16.0; |
| 337 | case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: |
| 338 | return 16.0; /* arbitrary */ |
| 339 | case PIPE_CAPF_GUARD_BAND_LEFT: |
| 340 | case PIPE_CAPF_GUARD_BAND_TOP: |
| 341 | case PIPE_CAPF_GUARD_BAND_RIGHT: |
| 342 | case PIPE_CAPF_GUARD_BAND_BOTTOM: |
| 343 | return 0.0; |
| 344 | } |
| 345 | /* should only get here on unhandled cases */ |
| 346 | debug_printf("Unexpected PIPE_CAPF %d query\n", param); |
| 347 | return 0.0; |
| 348 | } |
| 349 | |
| 350 | static boolean |
| 351 | virgl_is_vertex_format_supported(struct pipe_screen *screen, |
| 352 | enum pipe_format format) |
| 353 | { |
| 354 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 355 | const struct util_format_description *format_desc; |
| 356 | int i; |
| 357 | |
| 358 | format_desc = util_format_description(format); |
| 359 | if (!format_desc) |
| 360 | return FALSE; |
| 361 | |
| 362 | if (format == PIPE_FORMAT_R11G11B10_FLOAT) { |
| 363 | int vformat = VIRGL_FORMAT_R11G11B10_FLOAT; |
| 364 | int big = vformat / 32; |
| 365 | int small = vformat % 32; |
| 366 | if (!(vscreen->caps.caps.v1.vertexbuffer.bitmask[big] & (1 << small))) |
| 367 | return FALSE; |
| 368 | return TRUE; |
| 369 | } |
| 370 | |
| 371 | /* Find the first non-VOID channel. */ |
| 372 | for (i = 0; i < 4; i++) { |
| 373 | if (format_desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (i == 4) |
| 379 | return FALSE; |
| 380 | |
| 381 | if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) |
| 382 | return FALSE; |
| 383 | |
| 384 | if (format_desc->channel[i].type == UTIL_FORMAT_TYPE_FIXED) |
| 385 | return FALSE; |
| 386 | return TRUE; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Query format support for creating a texture, drawing surface, etc. |
| 391 | * \param format the format to test |
| 392 | * \param type one of PIPE_TEXTURE, PIPE_SURFACE |
| 393 | */ |
| 394 | static boolean |
| 395 | virgl_is_format_supported( struct pipe_screen *screen, |
| 396 | enum pipe_format format, |
| 397 | enum pipe_texture_target target, |
| 398 | unsigned sample_count, |
| 399 | unsigned bind) |
| 400 | { |
| 401 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 402 | const struct util_format_description *format_desc; |
| 403 | int i; |
| 404 | |
| 405 | assert(target == PIPE_BUFFER || |
| 406 | target == PIPE_TEXTURE_1D || |
| 407 | target == PIPE_TEXTURE_1D_ARRAY || |
| 408 | target == PIPE_TEXTURE_2D || |
| 409 | target == PIPE_TEXTURE_2D_ARRAY || |
| 410 | target == PIPE_TEXTURE_RECT || |
| 411 | target == PIPE_TEXTURE_3D || |
| 412 | target == PIPE_TEXTURE_CUBE || |
| 413 | target == PIPE_TEXTURE_CUBE_ARRAY); |
| 414 | |
| 415 | format_desc = util_format_description(format); |
| 416 | if (!format_desc) |
| 417 | return FALSE; |
| 418 | |
| 419 | if (util_format_is_intensity(format)) |
| 420 | return FALSE; |
| 421 | |
| 422 | if (sample_count > 1) { |
| 423 | if (!vscreen->caps.caps.v1.bset.texture_multisample) |
| 424 | return FALSE; |
| 425 | if (sample_count > vscreen->caps.caps.v1.max_samples) |
| 426 | return FALSE; |
| 427 | } |
| 428 | |
| 429 | if (bind & PIPE_BIND_VERTEX_BUFFER) { |
| 430 | return virgl_is_vertex_format_supported(screen, format); |
| 431 | } |
| 432 | |
| 433 | if (bind & PIPE_BIND_RENDER_TARGET) { |
| 434 | if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) |
| 435 | return FALSE; |
| 436 | |
| 437 | /* |
| 438 | * Although possible, it is unnatural to render into compressed or YUV |
| 439 | * surfaces. So disable these here to avoid going into weird paths |
| 440 | * inside the state trackers. |
| 441 | */ |
| 442 | if (format_desc->block.width != 1 || |
| 443 | format_desc->block.height != 1) |
| 444 | return FALSE; |
| 445 | |
| 446 | { |
| 447 | int big = format / 32; |
| 448 | int small = format % 32; |
| 449 | if (!(vscreen->caps.caps.v1.render.bitmask[big] & (1 << small))) |
| 450 | return FALSE; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if (bind & PIPE_BIND_DEPTH_STENCIL) { |
| 455 | if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) |
| 456 | return FALSE; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * All other operations (sampling, transfer, etc). |
| 461 | */ |
| 462 | |
| 463 | if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { |
| 464 | if (util_format_s3tc_enabled) |
| 465 | goto out_lookup; |
| 466 | return FALSE; |
| 467 | } |
| 468 | if (format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC) { |
| 469 | goto out_lookup; |
| 470 | } |
| 471 | |
| 472 | if (format == PIPE_FORMAT_R11G11B10_FLOAT) { |
| 473 | goto out_lookup; |
| 474 | } else if (format == PIPE_FORMAT_R9G9B9E5_FLOAT) { |
| 475 | goto out_lookup; |
| 476 | } |
| 477 | |
| 478 | /* Find the first non-VOID channel. */ |
| 479 | for (i = 0; i < 4; i++) { |
| 480 | if (format_desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | if (i == 4) |
| 486 | return FALSE; |
| 487 | |
| 488 | /* no L4A4 */ |
| 489 | if (format_desc->nr_channels < 4 && format_desc->channel[i].size == 4) |
| 490 | return FALSE; |
| 491 | |
| 492 | out_lookup: |
| 493 | { |
| 494 | int big = format / 32; |
| 495 | int small = format % 32; |
| 496 | if (!(vscreen->caps.caps.v1.sampler.bitmask[big] & (1 << small))) |
| 497 | return FALSE; |
| 498 | } |
| 499 | /* |
| 500 | * Everything else should be supported by u_format. |
| 501 | */ |
| 502 | return TRUE; |
| 503 | } |
| 504 | |
| 505 | static void virgl_flush_frontbuffer(struct pipe_screen *screen, |
| 506 | struct pipe_resource *res, |
| 507 | unsigned level, unsigned layer, |
| 508 | void *winsys_drawable_handle, struct pipe_box *sub_box) |
| 509 | { |
| 510 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 511 | struct virgl_winsys *vws = vscreen->vws; |
Emil Velikov | 7af46b9 | 2015-10-28 11:14:02 +0000 | [diff] [blame] | 512 | struct virgl_resource *vres = virgl_resource(res); |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 513 | |
| 514 | if (vws->flush_frontbuffer) |
| 515 | vws->flush_frontbuffer(vws, vres->hw_res, level, layer, winsys_drawable_handle, |
| 516 | sub_box); |
| 517 | } |
| 518 | |
| 519 | static void virgl_fence_reference(struct pipe_screen *screen, |
| 520 | struct pipe_fence_handle **ptr, |
| 521 | struct pipe_fence_handle *fence) |
| 522 | { |
| 523 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 524 | struct virgl_winsys *vws = vscreen->vws; |
| 525 | |
| 526 | vws->fence_reference(vws, ptr, fence); |
| 527 | } |
| 528 | |
| 529 | static boolean virgl_fence_finish(struct pipe_screen *screen, |
Marek Olšák | 54272e1 | 2016-08-06 16:41:42 +0200 | [diff] [blame] | 530 | struct pipe_context *ctx, |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 531 | struct pipe_fence_handle *fence, |
| 532 | uint64_t timeout) |
| 533 | { |
| 534 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 535 | struct virgl_winsys *vws = vscreen->vws; |
| 536 | |
| 537 | return vws->fence_wait(vws, fence, timeout); |
| 538 | } |
| 539 | |
| 540 | static uint64_t |
| 541 | virgl_get_timestamp(struct pipe_screen *_screen) |
| 542 | { |
| 543 | return os_time_get_nano(); |
| 544 | } |
| 545 | |
| 546 | static void |
| 547 | virgl_destroy_screen(struct pipe_screen *screen) |
| 548 | { |
| 549 | struct virgl_screen *vscreen = virgl_screen(screen); |
| 550 | struct virgl_winsys *vws = vscreen->vws; |
| 551 | |
Nicolai Hähnle | 8a94356 | 2016-09-27 19:12:24 +0200 | [diff] [blame] | 552 | slab_destroy_parent(&vscreen->texture_transfer_pool); |
| 553 | |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 554 | if (vws) |
| 555 | vws->destroy(vws); |
| 556 | FREE(vscreen); |
| 557 | } |
| 558 | |
| 559 | struct pipe_screen * |
| 560 | virgl_create_screen(struct virgl_winsys *vws) |
| 561 | { |
| 562 | struct virgl_screen *screen = CALLOC_STRUCT(virgl_screen); |
| 563 | |
| 564 | if (!screen) |
| 565 | return NULL; |
| 566 | |
| 567 | screen->vws = vws; |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 568 | screen->base.get_name = virgl_get_name; |
| 569 | screen->base.get_vendor = virgl_get_vendor; |
| 570 | screen->base.get_param = virgl_get_param; |
| 571 | screen->base.get_shader_param = virgl_get_shader_param; |
| 572 | screen->base.get_paramf = virgl_get_paramf; |
| 573 | screen->base.is_format_supported = virgl_is_format_supported; |
| 574 | screen->base.destroy = virgl_destroy_screen; |
| 575 | screen->base.context_create = virgl_context_create; |
| 576 | screen->base.flush_frontbuffer = virgl_flush_frontbuffer; |
| 577 | screen->base.get_timestamp = virgl_get_timestamp; |
| 578 | screen->base.fence_reference = virgl_fence_reference; |
| 579 | //screen->base.fence_signalled = virgl_fence_signalled; |
| 580 | screen->base.fence_finish = virgl_fence_finish; |
| 581 | |
| 582 | virgl_init_screen_resource_functions(&screen->base); |
| 583 | |
| 584 | vws->get_caps(vws, &screen->caps); |
| 585 | |
Rob Herring | f87330d | 2016-01-29 16:36:28 -0600 | [diff] [blame] | 586 | screen->refcnt = 1; |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 587 | |
Nicolai Hähnle | 8a94356 | 2016-09-27 19:12:24 +0200 | [diff] [blame] | 588 | slab_create_parent(&screen->texture_transfer_pool, sizeof(struct virgl_transfer), 16); |
| 589 | |
Dave Airlie | a8987b8 | 2015-01-22 15:11:47 +1000 | [diff] [blame] | 590 | util_format_s3tc_init(); |
| 591 | return &screen->base; |
| 592 | } |