1 /************************************************************************** 2 * 3 * Copyright (C) 2015 Red Hat Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included 13 * in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 **************************************************************************/ 24 #ifndef VIRGL_HW_H 25 #define VIRGL_HW_H 26 27 #include <stdint.h> 28 29 struct virgl_box { 30 uint32_t x, y, z; 31 uint32_t w, h, d; 32 }; 33 34 /* formats known by the HW device - based on gallium subset */ 35 enum virgl_formats { 36 VIRGL_FORMAT_B8G8R8A8_UNORM = 1, 37 VIRGL_FORMAT_B8G8R8X8_UNORM = 2, 38 VIRGL_FORMAT_A8R8G8B8_UNORM = 3, 39 VIRGL_FORMAT_X8R8G8B8_UNORM = 4, 40 VIRGL_FORMAT_B5G5R5A1_UNORM = 5, 41 VIRGL_FORMAT_B4G4R4A4_UNORM = 6, 42 VIRGL_FORMAT_B5G6R5_UNORM = 7, 43 VIRGL_FORMAT_R10G10B10A2_UNORM = 8, 44 VIRGL_FORMAT_L8_UNORM = 9, /**< ubyte luminance */ 45 VIRGL_FORMAT_A8_UNORM = 10, /**< ubyte alpha */ 46 VIRGL_FORMAT_L8A8_UNORM = 12, /**< ubyte alpha, luminance */ 47 VIRGL_FORMAT_L16_UNORM = 13, /**< ushort luminance */ 48 49 VIRGL_FORMAT_Z16_UNORM = 16, 50 VIRGL_FORMAT_Z32_UNORM = 17, 51 VIRGL_FORMAT_Z32_FLOAT = 18, 52 VIRGL_FORMAT_Z24_UNORM_S8_UINT = 19, 53 VIRGL_FORMAT_S8_UINT_Z24_UNORM = 20, 54 VIRGL_FORMAT_Z24X8_UNORM = 21, 55 VIRGL_FORMAT_S8_UINT = 23, /**< ubyte stencil */ 56 57 VIRGL_FORMAT_R32_FLOAT = 28, 58 VIRGL_FORMAT_R32G32_FLOAT = 29, 59 VIRGL_FORMAT_R32G32B32_FLOAT = 30, 60 VIRGL_FORMAT_R32G32B32A32_FLOAT = 31, 61 62 VIRGL_FORMAT_R16_UNORM = 48, 63 VIRGL_FORMAT_R16G16_UNORM = 49, 64 65 VIRGL_FORMAT_R16G16B16A16_UNORM = 51, 66 67 VIRGL_FORMAT_R16_SNORM = 56, 68 VIRGL_FORMAT_R16G16_SNORM = 57, 69 VIRGL_FORMAT_R16G16B16A16_SNORM = 59, 70 71 VIRGL_FORMAT_R8_UNORM = 64, 72 VIRGL_FORMAT_R8G8_UNORM = 65, 73 VIRGL_FORMAT_R8G8B8_UNORM = 66, 74 VIRGL_FORMAT_R8G8B8A8_UNORM = 67, 75 76 VIRGL_FORMAT_R8_SNORM = 74, 77 VIRGL_FORMAT_R8G8_SNORM = 75, 78 VIRGL_FORMAT_R8G8B8_SNORM = 76, 79 VIRGL_FORMAT_R8G8B8A8_SNORM = 77, 80 81 VIRGL_FORMAT_R16_FLOAT = 91, 82 VIRGL_FORMAT_R16G16_FLOAT = 92, 83 VIRGL_FORMAT_R16G16B16_FLOAT = 93, 84 VIRGL_FORMAT_R16G16B16A16_FLOAT = 94, 85 86 VIRGL_FORMAT_L8_SRGB = 95, 87 VIRGL_FORMAT_L8A8_SRGB = 96, 88 VIRGL_FORMAT_B8G8R8A8_SRGB = 100, 89 VIRGL_FORMAT_B8G8R8X8_SRGB = 101, 90 VIRGL_FORMAT_R8G8B8A8_SRGB = 104, 91 92 /* compressed formats */ 93 VIRGL_FORMAT_DXT1_RGB = 105, 94 VIRGL_FORMAT_DXT1_RGBA = 106, 95 VIRGL_FORMAT_DXT3_RGBA = 107, 96 VIRGL_FORMAT_DXT5_RGBA = 108, 97 98 /* sRGB, compressed */ 99 VIRGL_FORMAT_DXT1_SRGB = 109, 100 VIRGL_FORMAT_DXT1_SRGBA = 110, 101 VIRGL_FORMAT_DXT3_SRGBA = 111, 102 VIRGL_FORMAT_DXT5_SRGBA = 112, 103 104 /* rgtc compressed */ 105 VIRGL_FORMAT_RGTC1_UNORM = 113, 106 VIRGL_FORMAT_RGTC1_SNORM = 114, 107 VIRGL_FORMAT_RGTC2_UNORM = 115, 108 VIRGL_FORMAT_RGTC2_SNORM = 116, 109 110 VIRGL_FORMAT_A8B8G8R8_UNORM = 121, 111 VIRGL_FORMAT_B5G5R5X1_UNORM = 122, 112 VIRGL_FORMAT_R11G11B10_FLOAT = 124, 113 VIRGL_FORMAT_R9G9B9E5_FLOAT = 125, 114 VIRGL_FORMAT_Z32_FLOAT_S8X24_UINT = 126, 115 116 VIRGL_FORMAT_B10G10R10A2_UNORM = 131, 117 VIRGL_FORMAT_R8G8B8X8_UNORM = 134, 118 VIRGL_FORMAT_B4G4R4X4_UNORM = 135, 119 VIRGL_FORMAT_X24S8_UINT = 136, 120 VIRGL_FORMAT_S8X24_UINT = 137, 121 VIRGL_FORMAT_B2G3R3_UNORM = 139, 122 123 VIRGL_FORMAT_L16A16_UNORM = 140, 124 VIRGL_FORMAT_A16_UNORM = 141, 125 126 VIRGL_FORMAT_A8_SNORM = 147, 127 VIRGL_FORMAT_L8_SNORM = 148, 128 VIRGL_FORMAT_L8A8_SNORM = 149, 129 130 VIRGL_FORMAT_A16_SNORM = 151, 131 VIRGL_FORMAT_L16_SNORM = 152, 132 VIRGL_FORMAT_L16A16_SNORM = 153, 133 134 VIRGL_FORMAT_A16_FLOAT = 155, 135 VIRGL_FORMAT_L16_FLOAT = 156, 136 VIRGL_FORMAT_L16A16_FLOAT = 157, 137 138 VIRGL_FORMAT_A32_FLOAT = 159, 139 VIRGL_FORMAT_L32_FLOAT = 160, 140 VIRGL_FORMAT_L32A32_FLOAT = 161, 141 142 VIRGL_FORMAT_YV12 = 163, 143 VIRGL_FORMAT_YV16 = 164, 144 VIRGL_FORMAT_IYUV = 165, /**< aka I420 */ 145 VIRGL_FORMAT_NV12 = 166, 146 VIRGL_FORMAT_NV21 = 167, 147 148 VIRGL_FORMAT_R8_UINT = 177, 149 VIRGL_FORMAT_R8G8_UINT = 178, 150 VIRGL_FORMAT_R8G8B8_UINT = 179, 151 VIRGL_FORMAT_R8G8B8A8_UINT = 180, 152 153 VIRGL_FORMAT_R8_SINT = 181, 154 VIRGL_FORMAT_R8G8_SINT = 182, 155 VIRGL_FORMAT_R8G8B8_SINT = 183, 156 VIRGL_FORMAT_R8G8B8A8_SINT = 184, 157 158 VIRGL_FORMAT_R16_UINT = 185, 159 VIRGL_FORMAT_R16G16_UINT = 186, 160 VIRGL_FORMAT_R16G16B16_UINT = 187, 161 VIRGL_FORMAT_R16G16B16A16_UINT = 188, 162 163 VIRGL_FORMAT_R16_SINT = 189, 164 VIRGL_FORMAT_R16G16_SINT = 190, 165 VIRGL_FORMAT_R16G16B16_SINT = 191, 166 VIRGL_FORMAT_R16G16B16A16_SINT = 192, 167 VIRGL_FORMAT_R32_UINT = 193, 168 VIRGL_FORMAT_R32G32_UINT = 194, 169 VIRGL_FORMAT_R32G32B32_UINT = 195, 170 VIRGL_FORMAT_R32G32B32A32_UINT = 196, 171 172 VIRGL_FORMAT_R32_SINT = 197, 173 VIRGL_FORMAT_R32G32_SINT = 198, 174 VIRGL_FORMAT_R32G32B32_SINT = 199, 175 VIRGL_FORMAT_R32G32B32A32_SINT = 200, 176 177 VIRGL_FORMAT_A8_UINT = 201, 178 VIRGL_FORMAT_L8_UINT = 203, 179 VIRGL_FORMAT_L8A8_UINT = 204, 180 181 VIRGL_FORMAT_A8_SINT = 205, 182 VIRGL_FORMAT_L8_SINT = 207, 183 VIRGL_FORMAT_L8A8_SINT = 208, 184 185 VIRGL_FORMAT_A16_UINT = 209, 186 VIRGL_FORMAT_L16_UINT = 211, 187 VIRGL_FORMAT_L16A16_UINT = 212, 188 189 VIRGL_FORMAT_A16_SINT = 213, 190 VIRGL_FORMAT_L16_SINT = 215, 191 VIRGL_FORMAT_L16A16_SINT = 216, 192 193 VIRGL_FORMAT_A32_UINT = 217, 194 VIRGL_FORMAT_L32_UINT = 219, 195 VIRGL_FORMAT_L32A32_UINT = 220, 196 197 VIRGL_FORMAT_A32_SINT = 221, 198 VIRGL_FORMAT_L32_SINT = 223, 199 VIRGL_FORMAT_L32A32_SINT = 224, 200 201 VIRGL_FORMAT_B10G10R10A2_UINT = 225, 202 VIRGL_FORMAT_R8G8B8X8_SNORM = 229, 203 204 VIRGL_FORMAT_R8G8B8X8_SRGB = 230, 205 206 VIRGL_FORMAT_R8G8B8X8_UINT = 231, 207 VIRGL_FORMAT_R8G8B8X8_SINT = 232, 208 VIRGL_FORMAT_B10G10R10X2_UNORM = 233, 209 VIRGL_FORMAT_R16G16B16X16_UNORM = 234, 210 VIRGL_FORMAT_R16G16B16X16_SNORM = 235, 211 VIRGL_FORMAT_R16G16B16X16_FLOAT = 236, 212 VIRGL_FORMAT_R16G16B16X16_UINT = 237, 213 VIRGL_FORMAT_R16G16B16X16_SINT = 238, 214 215 VIRGL_FORMAT_R10G10B10A2_UINT = 253, 216 217 VIRGL_FORMAT_BPTC_RGBA_UNORM = 255, 218 VIRGL_FORMAT_BPTC_SRGBA = 256, 219 VIRGL_FORMAT_BPTC_RGB_FLOAT = 257, 220 VIRGL_FORMAT_BPTC_RGB_UFLOAT = 258, 221 222 VIRGL_FORMAT_R10G10B10X2_UNORM = 308, 223 VIRGL_FORMAT_A4B4G4R4_UNORM = 311, 224 225 VIRGL_FORMAT_R8_SRGB = 312, 226 VIRGL_FORMAT_R8G8_SRGB = 313, 227 228 VIRGL_FORMAT_P010 = 314, 229 VIRGL_FORMAT_P012 = 315, 230 VIRGL_FORMAT_P016 = 316, 231 232 VIRGL_FORMAT_MAX /* = PIPE_FORMAT_COUNT */, 233 }; 234 235 struct virgl_caps_bool_set1 { 236 unsigned indep_blend_enable:1; 237 unsigned indep_blend_func:1; 238 unsigned cube_map_array:1; 239 unsigned shader_stencil_export:1; 240 unsigned conditional_render:1; 241 unsigned start_instance:1; 242 unsigned primitive_restart:1; 243 unsigned blend_eq_sep:1; 244 unsigned instanceid:1; 245 unsigned vertex_element_instance_divisor:1; 246 unsigned seamless_cube_map:1; 247 unsigned occlusion_query:1; 248 unsigned timer_query:1; 249 unsigned streamout_pause_resume:1; 250 unsigned texture_multisample:1; 251 unsigned fragment_coord_conventions:1; 252 unsigned depth_clip_disable:1; 253 unsigned seamless_cube_map_per_texture:1; 254 unsigned ubo:1; 255 unsigned color_clamping:1; /* not in GL 3.1 core profile */ 256 unsigned poly_stipple:1; /* not in GL 3.1 core profile */ 257 unsigned mirror_clamp:1; 258 unsigned texture_query_lod:1; 259 unsigned has_fp64:1; 260 unsigned has_tessellation_shaders:1; 261 unsigned has_indirect_draw:1; 262 unsigned has_sample_shading:1; 263 unsigned has_cull:1; 264 }; 265 266 /* endless expansion capabilites - current gallium has 252 formats */ 267 struct virgl_supported_format_mask { 268 uint32_t bitmask[16]; 269 }; 270 /* capabilities set 2 - version 1 - 32-bit and float values */ 271 struct virgl_caps_v1 { 272 uint32_t max_version; 273 struct virgl_supported_format_mask sampler; 274 struct virgl_supported_format_mask render; 275 struct virgl_supported_format_mask depthstencil; 276 struct virgl_supported_format_mask vertexbuffer; 277 struct virgl_caps_bool_set1 bset; 278 uint32_t glsl_level; 279 uint32_t max_texture_array_layers; 280 uint32_t max_streamout_buffers; 281 uint32_t max_dual_source_render_targets; 282 uint32_t max_render_targets; 283 uint32_t max_samples; 284 uint32_t prim_mask; 285 uint32_t max_tbo_size; 286 uint32_t max_uniform_blocks; 287 uint32_t max_viewports; 288 uint32_t max_texture_gather_components; 289 }; 290 291 /* 292 * This struct should be growable when used in capset 2, 293 * so we shouldn't have to add a v3 ever. 294 */ 295 struct virgl_caps_v2 { 296 struct virgl_caps_v1 v1; 297 float min_aliased_point_size; 298 float max_aliased_point_size; 299 float min_smooth_point_size; 300 float max_smooth_point_size; 301 float min_aliased_line_width; 302 float max_aliased_line_width; 303 float min_smooth_line_width; 304 float max_smooth_line_width; 305 float max_texture_lod_bias; 306 uint32_t max_geom_output_vertices; 307 uint32_t max_geom_total_output_components; 308 uint32_t max_vertex_outputs; 309 uint32_t max_vertex_attribs; 310 uint32_t max_shader_patch_varyings; 311 int32_t min_texel_offset; 312 int32_t max_texel_offset; 313 int32_t min_texture_gather_offset; 314 int32_t max_texture_gather_offset; 315 uint32_t texture_buffer_offset_alignment; 316 uint32_t uniform_buffer_offset_alignment; 317 uint32_t tgsi_invariant; 318 uint32_t shader_buffer_offset_alignment; 319 }; 320 321 union virgl_caps { 322 uint32_t max_version; 323 struct virgl_caps_v1 v1; 324 struct virgl_caps_v2 v2; 325 }; 326 327 enum virgl_errors { 328 VIRGL_ERROR_NONE, 329 VIRGL_ERROR_UNKNOWN, 330 VIRGL_ERROR_UNKNOWN_RESOURCE_FORMAT, 331 }; 332 333 enum virgl_ctx_errors { 334 VIRGL_ERROR_CTX_NONE, 335 VIRGL_ERROR_CTX_UNKNOWN, 336 VIRGL_ERROR_CTX_ILLEGAL_SHADER, 337 VIRGL_ERROR_CTX_ILLEGAL_HANDLE, 338 VIRGL_ERROR_CTX_ILLEGAL_RESOURCE, 339 VIRGL_ERROR_CTX_ILLEGAL_SURFACE, 340 VIRGL_ERROR_CTX_ILLEGAL_VERTEX_FORMAT, 341 VIRGL_ERROR_CTX_ILLEGAL_CMD_BUFFER, 342 }; 343 344 /* virgl bind flags - these are compatible with mesa 10.5 gallium. 345 * but are fixed, no other should be passed to virgl either. 346 */ 347 #define VIRGL_BIND_DEPTH_STENCIL (1 << 0) 348 #define VIRGL_BIND_RENDER_TARGET (1 << 1) 349 #define VIRGL_BIND_SAMPLER_VIEW (1 << 3) 350 #define VIRGL_BIND_VERTEX_BUFFER (1 << 4) 351 #define VIRGL_BIND_INDEX_BUFFER (1 << 5) 352 #define VIRGL_BIND_CONSTANT_BUFFER (1 << 6) 353 #define VIRGL_BIND_DISPLAY_TARGET (1 << 7) 354 #define VIRGL_BIND_COMMAND_ARGS (1 << 8) 355 #define VIRGL_BIND_STREAM_OUTPUT (1 << 11) 356 #define VIRGL_BIND_SHADER_BUFFER (1 << 14) 357 #define VIRGL_BIND_QUERY_BUFFER (1 << 15) 358 #define VIRGL_BIND_CURSOR (1 << 16) 359 #define VIRGL_BIND_CUSTOM (1 << 17) 360 #define VIRGL_BIND_SCANOUT (1 << 18) 361 /* Used for buffers that are backed by guest storage and 362 * are only read by the host. 363 */ 364 #define VIRGL_BIND_STAGING (1 << 19) 365 #define VIRGL_BIND_SHARED (1 << 20) 366 #define VIRGL_BIND_PREFER_EMULATED_BGRA (1 << 21) 367 #define VIRGL_BIND_LINEAR (1 << 22) 368 369 #define VIRGL_RESOURCE_Y_0_TOP (1 << 0) 370 #endif 371