Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 25 | #include "genhw/genhw.h" |
| 26 | #include "kmd/winsys.h" |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 27 | #include "dev.h" |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 28 | #include "format.h" |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 29 | #include "gpu.h" |
| 30 | #include "img.h" |
| 31 | #include "mem.h" |
| 32 | #include "view.h" |
| 33 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 34 | static void emit_null_view_gen7(const struct intel_gpu *gpu, uint32_t dw[8]) |
| 35 | { |
| 36 | INTEL_GPU_ASSERT(gpu, 7, 7.5); |
| 37 | |
| 38 | /* |
| 39 | * From the Ivy Bridge PRM, volume 4 part 1, page 62: |
| 40 | * |
| 41 | * "A null surface is used in instances where an actual surface is not |
| 42 | * bound. When a write message is generated to a null surface, no |
| 43 | * actual surface is written to. When a read message (including any |
| 44 | * sampling engine message) is generated to a null surface, the result |
| 45 | * is all zeros. Note that a null surface type is allowed to be used |
| 46 | * with all messages, even if it is not specificially indicated as |
| 47 | * supported. All of the remaining fields in surface state are ignored |
| 48 | * for null surfaces, with the following exceptions: |
| 49 | * |
| 50 | * * Width, Height, Depth, LOD, and Render Target View Extent fields |
| 51 | * must match the depth buffer's corresponding state for all render |
| 52 | * target surfaces, including null. |
| 53 | * * All sampling engine and data port messages support null surfaces |
| 54 | * with the above behavior, even if not mentioned as specifically |
| 55 | * supported, except for the following: |
| 56 | * * Data Port Media Block Read/Write messages. |
| 57 | * * The Surface Type of a surface used as a render target (accessed |
| 58 | * via the Data Port's Render Target Write message) must be the same |
| 59 | * as the Surface Type of all other render targets and of the depth |
| 60 | * buffer (defined in 3DSTATE_DEPTH_BUFFER), unless either the depth |
| 61 | * buffer or render targets are SURFTYPE_NULL." |
| 62 | * |
| 63 | * From the Ivy Bridge PRM, volume 4 part 1, page 65: |
| 64 | * |
| 65 | * "If Surface Type is SURFTYPE_NULL, this field (Tiled Surface) must be |
| 66 | * true" |
| 67 | */ |
| 68 | |
| 69 | dw[0] = GEN6_SURFTYPE_NULL << GEN7_SURFACE_DW0_TYPE__SHIFT | |
| 70 | GEN6_FORMAT_B8G8R8A8_UNORM << GEN7_SURFACE_DW0_FORMAT__SHIFT | |
| 71 | GEN6_TILING_X << 13; |
| 72 | |
| 73 | dw[1] = 0; |
| 74 | dw[2] = 0; |
| 75 | dw[3] = 0; |
| 76 | dw[4] = 0; |
| 77 | dw[5] = 0; |
| 78 | dw[6] = 0; |
| 79 | dw[7] = 0; |
| 80 | } |
| 81 | |
| 82 | static void emit_mem_view_gen7(const struct intel_gpu *gpu, |
| 83 | unsigned offset, unsigned size, |
| 84 | unsigned struct_size, |
| 85 | XGL_FORMAT elem_format, |
| 86 | bool is_rt, bool render_cache_rw, |
| 87 | uint32_t dw[8]) |
| 88 | { |
| 89 | const bool typed = !icd_format_is_undef(elem_format); |
| 90 | const bool structured = (!typed && struct_size > 1); |
| 91 | const int elem_size = (typed) ? |
| 92 | icd_format_get_size(elem_format) : 1; |
| 93 | int width, height, depth, pitch; |
| 94 | int surface_type, surface_format, num_entries; |
| 95 | |
| 96 | INTEL_GPU_ASSERT(gpu, 7, 7.5); |
| 97 | |
| 98 | surface_type = (structured) ? GEN7_SURFTYPE_STRBUF : GEN6_SURFTYPE_BUFFER; |
| 99 | |
| 100 | surface_format = (typed) ? |
| 101 | intel_format_translate_color(gpu, elem_format) : GEN6_FORMAT_RAW; |
| 102 | |
| 103 | num_entries = size / struct_size; |
| 104 | /* see if there is enough space to fit another element */ |
| 105 | if (size % struct_size >= elem_size && !structured) |
| 106 | num_entries++; |
| 107 | |
| 108 | /* |
| 109 | * From the Ivy Bridge PRM, volume 4 part 1, page 67: |
| 110 | * |
| 111 | * "For SURFTYPE_BUFFER render targets, this field (Surface Base |
| 112 | * Address) specifies the base address of first element of the |
| 113 | * surface. The surface is interpreted as a simple array of that |
| 114 | * single element type. The address must be naturally-aligned to the |
| 115 | * element size (e.g., a buffer containing R32G32B32A32_FLOAT elements |
| 116 | * must be 16-byte aligned) |
| 117 | * |
| 118 | * For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies |
| 119 | * the base address of the first element of the surface, computed in |
| 120 | * software by adding the surface base address to the byte offset of |
| 121 | * the element in the buffer." |
| 122 | */ |
| 123 | if (is_rt) |
| 124 | assert(offset % elem_size == 0); |
| 125 | |
| 126 | /* |
| 127 | * From the Ivy Bridge PRM, volume 4 part 1, page 68: |
| 128 | * |
| 129 | * "For typed buffer and structured buffer surfaces, the number of |
| 130 | * entries in the buffer ranges from 1 to 2^27. For raw buffer |
| 131 | * surfaces, the number of entries in the buffer is the number of |
| 132 | * bytes which can range from 1 to 2^30." |
| 133 | */ |
| 134 | assert(num_entries >= 1 && |
| 135 | num_entries <= 1 << ((typed || structured) ? 27 : 30)); |
| 136 | |
| 137 | /* |
| 138 | * From the Ivy Bridge PRM, volume 4 part 1, page 69: |
| 139 | * |
| 140 | * "For SURFTYPE_BUFFER: The low two bits of this field (Width) must be |
| 141 | * 11 if the Surface Format is RAW (the size of the buffer must be a |
| 142 | * multiple of 4 bytes)." |
| 143 | * |
| 144 | * From the Ivy Bridge PRM, volume 4 part 1, page 70: |
| 145 | * |
| 146 | * "For surfaces of type SURFTYPE_BUFFER and SURFTYPE_STRBUF, this |
| 147 | * field (Surface Pitch) indicates the size of the structure." |
| 148 | * |
| 149 | * "For linear surfaces with Surface Type of SURFTYPE_STRBUF, the pitch |
| 150 | * must be a multiple of 4 bytes." |
| 151 | */ |
| 152 | if (structured) |
| 153 | assert(struct_size % 4 == 0); |
| 154 | else if (!typed) |
| 155 | assert(num_entries % 4 == 0); |
| 156 | |
| 157 | pitch = struct_size; |
| 158 | |
| 159 | pitch--; |
| 160 | num_entries--; |
| 161 | /* bits [6:0] */ |
| 162 | width = (num_entries & 0x0000007f); |
| 163 | /* bits [20:7] */ |
| 164 | height = (num_entries & 0x001fff80) >> 7; |
| 165 | /* bits [30:21] */ |
| 166 | depth = (num_entries & 0x7fe00000) >> 21; |
| 167 | /* limit to [26:21] */ |
| 168 | if (typed || structured) |
| 169 | depth &= 0x3f; |
| 170 | |
| 171 | dw[0] = surface_type << GEN7_SURFACE_DW0_TYPE__SHIFT | |
| 172 | surface_format << GEN7_SURFACE_DW0_FORMAT__SHIFT; |
| 173 | if (render_cache_rw) |
| 174 | dw[0] |= GEN7_SURFACE_DW0_RENDER_CACHE_RW; |
| 175 | |
| 176 | dw[1] = offset; |
| 177 | |
| 178 | dw[2] = height << GEN7_SURFACE_DW2_HEIGHT__SHIFT | |
| 179 | width << GEN7_SURFACE_DW2_WIDTH__SHIFT; |
| 180 | |
| 181 | dw[3] = depth << GEN7_SURFACE_DW3_DEPTH__SHIFT | |
| 182 | pitch; |
| 183 | |
| 184 | dw[4] = 0; |
| 185 | dw[5] = 0; |
| 186 | |
| 187 | dw[6] = 0; |
| 188 | dw[7] = 0; |
| 189 | |
| 190 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) { |
| 191 | dw[7] |= GEN75_SCS_RED << GEN75_SURFACE_DW7_SCS_R__SHIFT | |
| 192 | GEN75_SCS_GREEN << GEN75_SURFACE_DW7_SCS_G__SHIFT | |
| 193 | GEN75_SCS_BLUE << GEN75_SURFACE_DW7_SCS_B__SHIFT | |
| 194 | GEN75_SCS_ALPHA << GEN75_SURFACE_DW7_SCS_A__SHIFT; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | static int img_type_to_view_type(XGL_IMAGE_VIEW_TYPE type) |
| 199 | { |
| 200 | switch (type) { |
| 201 | case XGL_IMAGE_1D: return XGL_IMAGE_VIEW_1D; |
| 202 | case XGL_IMAGE_2D: return XGL_IMAGE_VIEW_2D; |
| 203 | case XGL_IMAGE_3D: return XGL_IMAGE_VIEW_3D; |
| 204 | default: assert(!"unknown img type"); return XGL_IMAGE_VIEW_1D; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | static int view_type_to_surface_type(XGL_IMAGE_VIEW_TYPE type) |
| 209 | { |
| 210 | switch (type) { |
| 211 | case XGL_IMAGE_VIEW_1D: return GEN6_SURFTYPE_1D; |
| 212 | case XGL_IMAGE_VIEW_2D: return GEN6_SURFTYPE_2D; |
| 213 | case XGL_IMAGE_VIEW_3D: return GEN6_SURFTYPE_3D; |
| 214 | case XGL_IMAGE_VIEW_CUBE: return GEN6_SURFTYPE_CUBE; |
| 215 | default: assert(!"unknown view type"); return GEN6_SURFTYPE_NULL; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | static int winsys_tiling_to_surface_tiling(enum intel_tiling_mode tiling) |
| 220 | { |
| 221 | switch (tiling) { |
| 222 | case INTEL_TILING_NONE: return GEN6_TILING_NONE; |
| 223 | case INTEL_TILING_X: return GEN6_TILING_X; |
| 224 | case INTEL_TILING_Y: return GEN6_TILING_Y; |
| 225 | default: assert(!"unknown tiling"); return GEN6_TILING_NONE; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | static void emit_img_view_gen7(const struct intel_gpu *gpu, |
| 230 | const struct intel_img *img, |
| 231 | XGL_IMAGE_VIEW_TYPE type, |
| 232 | XGL_FORMAT format, |
| 233 | unsigned first_level, |
| 234 | unsigned num_levels, |
| 235 | unsigned first_layer, |
| 236 | unsigned num_layers, |
| 237 | bool is_rt, |
| 238 | uint32_t dw[8]) |
| 239 | { |
| 240 | int surface_type, surface_format; |
| 241 | int width, height, depth, pitch, lod; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 242 | |
| 243 | INTEL_GPU_ASSERT(gpu, 7, 7.5); |
| 244 | |
| 245 | surface_type = view_type_to_surface_type(type); |
| 246 | assert(surface_type != GEN6_SURFTYPE_BUFFER); |
| 247 | |
| 248 | surface_format = intel_format_translate_color(gpu, format); |
| 249 | assert(surface_format >= 0); |
| 250 | |
| 251 | width = img->extent.width; |
| 252 | height = img->extent.height; |
| 253 | depth = (type == XGL_IMAGE_VIEW_3D) ? |
| 254 | img->extent.depth : num_layers; |
| 255 | pitch = img->layout.bo_stride; |
| 256 | |
| 257 | if (surface_type == GEN6_SURFTYPE_CUBE) { |
| 258 | /* |
| 259 | * From the Ivy Bridge PRM, volume 4 part 1, page 70: |
| 260 | * |
| 261 | * "For SURFTYPE_CUBE:For Sampling Engine Surfaces, the range of |
| 262 | * this field is [0,340], indicating the number of cube array |
| 263 | * elements (equal to the number of underlying 2D array elements |
| 264 | * divided by 6). For other surfaces, this field must be zero." |
| 265 | * |
| 266 | * When is_rt is true, we treat the texture as a 2D one to avoid the |
| 267 | * restriction. |
| 268 | */ |
| 269 | if (is_rt) { |
| 270 | surface_type = GEN6_SURFTYPE_2D; |
| 271 | } |
| 272 | else { |
| 273 | assert(num_layers % 6 == 0); |
| 274 | depth = num_layers / 6; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /* sanity check the size */ |
| 279 | assert(width >= 1 && height >= 1 && depth >= 1 && pitch >= 1); |
| 280 | assert(first_layer < 2048 && num_layers <= 2048); |
| 281 | switch (surface_type) { |
| 282 | case GEN6_SURFTYPE_1D: |
| 283 | assert(width <= 16384 && height == 1 && depth <= 2048); |
| 284 | break; |
| 285 | case GEN6_SURFTYPE_2D: |
| 286 | assert(width <= 16384 && height <= 16384 && depth <= 2048); |
| 287 | break; |
| 288 | case GEN6_SURFTYPE_3D: |
| 289 | assert(width <= 2048 && height <= 2048 && depth <= 2048); |
| 290 | if (!is_rt) |
| 291 | assert(first_layer == 0); |
| 292 | break; |
| 293 | case GEN6_SURFTYPE_CUBE: |
| 294 | assert(width <= 16384 && height <= 16384 && depth <= 86); |
| 295 | assert(width == height); |
| 296 | if (is_rt) |
| 297 | assert(first_layer == 0); |
| 298 | break; |
| 299 | default: |
| 300 | assert(!"unexpected surface type"); |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | if (is_rt) { |
| 305 | assert(num_levels == 1); |
| 306 | lod = first_level; |
| 307 | } |
| 308 | else { |
| 309 | lod = num_levels - 1; |
| 310 | } |
| 311 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 312 | /* |
| 313 | * From the Ivy Bridge PRM, volume 4 part 1, page 68: |
| 314 | * |
| 315 | * "The Base Address for linear render target surfaces and surfaces |
| 316 | * accessed with the typed surface read/write data port messages must |
| 317 | * be element-size aligned, for non-YUV surface formats, or a multiple |
| 318 | * of 2 element-sizes for YUV surface formats. Other linear surfaces |
| 319 | * have no alignment requirements (byte alignment is sufficient)." |
| 320 | * |
| 321 | * From the Ivy Bridge PRM, volume 4 part 1, page 70: |
| 322 | * |
| 323 | * "For linear render target surfaces and surfaces accessed with the |
| 324 | * typed data port messages, the pitch must be a multiple of the |
| 325 | * element size for non-YUV surface formats. Pitch must be a multiple |
| 326 | * of 2 * element size for YUV surface formats. For linear surfaces |
| 327 | * with Surface Type of SURFTYPE_STRBUF, the pitch must be a multiple |
| 328 | * of 4 bytes.For other linear surfaces, the pitch can be any multiple |
| 329 | * of bytes." |
| 330 | * |
| 331 | * From the Ivy Bridge PRM, volume 4 part 1, page 74: |
| 332 | * |
| 333 | * "For linear surfaces, this field (X Offset) must be zero." |
| 334 | */ |
| 335 | if (img->layout.tiling == INTEL_TILING_NONE) { |
| 336 | if (is_rt) { |
| 337 | const int elem_size = icd_format_get_size(format); |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 338 | assert(pitch % elem_size == 0); |
| 339 | } |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | dw[0] = surface_type << GEN7_SURFACE_DW0_TYPE__SHIFT | |
| 343 | surface_format << GEN7_SURFACE_DW0_FORMAT__SHIFT | |
| 344 | winsys_tiling_to_surface_tiling(img->layout.tiling) << 13; |
| 345 | |
| 346 | /* |
| 347 | * From the Ivy Bridge PRM, volume 4 part 1, page 63: |
| 348 | * |
| 349 | * "If this field (Surface Array) is enabled, the Surface Type must be |
| 350 | * SURFTYPE_1D, SURFTYPE_2D, or SURFTYPE_CUBE. If this field is |
| 351 | * disabled and Surface Type is SURFTYPE_1D, SURFTYPE_2D, or |
| 352 | * SURFTYPE_CUBE, the Depth field must be set to zero." |
| 353 | * |
| 354 | * For non-3D sampler surfaces, resinfo (the sampler message) always |
| 355 | * returns zero for the number of layers when this field is not set. |
| 356 | */ |
| 357 | if (surface_type != GEN6_SURFTYPE_3D) { |
| 358 | if (num_layers > 1) |
| 359 | dw[0] |= GEN7_SURFACE_DW0_IS_ARRAY; |
| 360 | else |
| 361 | assert(depth == 1); |
| 362 | } |
| 363 | |
| 364 | assert(img->layout.align_i == 4 || img->layout.align_i == 8); |
| 365 | assert(img->layout.align_j == 2 || img->layout.align_j == 4); |
| 366 | |
| 367 | if (img->layout.align_j == 4) |
| 368 | dw[0] |= GEN7_SURFACE_DW0_VALIGN_4; |
| 369 | |
| 370 | if (img->layout.align_i == 8) |
| 371 | dw[0] |= GEN7_SURFACE_DW0_HALIGN_8; |
| 372 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 373 | if (img->layout.walk == INTEL_LAYOUT_WALK_LOD) |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 374 | dw[0] |= GEN7_SURFACE_DW0_ARYSPC_LOD0; |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 375 | else |
| 376 | dw[0] |= GEN7_SURFACE_DW0_ARYSPC_FULL; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 377 | |
| 378 | if (is_rt) |
| 379 | dw[0] |= GEN7_SURFACE_DW0_RENDER_CACHE_RW; |
| 380 | |
| 381 | if (surface_type == GEN6_SURFTYPE_CUBE && !is_rt) |
| 382 | dw[0] |= GEN7_SURFACE_DW0_CUBE_FACE_ENABLES__MASK; |
| 383 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 384 | dw[1] = 0; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 385 | |
| 386 | dw[2] = (height - 1) << GEN7_SURFACE_DW2_HEIGHT__SHIFT | |
| 387 | (width - 1) << GEN7_SURFACE_DW2_WIDTH__SHIFT; |
| 388 | |
| 389 | dw[3] = (depth - 1) << GEN7_SURFACE_DW3_DEPTH__SHIFT | |
| 390 | (pitch - 1); |
| 391 | |
| 392 | dw[4] = first_layer << 18 | |
| 393 | (num_layers - 1) << 7; |
| 394 | |
| 395 | /* |
| 396 | * MSFMT_MSS means the samples are not interleaved and MSFMT_DEPTH_STENCIL |
| 397 | * means the samples are interleaved. The layouts are the same when the |
| 398 | * number of samples is 1. |
| 399 | */ |
| 400 | if (img->layout.interleaved_samples && img->samples > 1) { |
| 401 | assert(!is_rt); |
| 402 | dw[4] |= GEN7_SURFACE_DW4_MSFMT_DEPTH_STENCIL; |
| 403 | } |
| 404 | else { |
| 405 | dw[4] |= GEN7_SURFACE_DW4_MSFMT_MSS; |
| 406 | } |
| 407 | |
| 408 | if (img->samples > 4) |
| 409 | dw[4] |= GEN7_SURFACE_DW4_MULTISAMPLECOUNT_8; |
| 410 | else if (img->samples > 2) |
| 411 | dw[4] |= GEN7_SURFACE_DW4_MULTISAMPLECOUNT_4; |
| 412 | else |
| 413 | dw[4] |= GEN7_SURFACE_DW4_MULTISAMPLECOUNT_1; |
| 414 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 415 | dw[5] = (first_level) << GEN7_SURFACE_DW5_MIN_LOD__SHIFT | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 416 | lod; |
| 417 | |
| 418 | dw[6] = 0; |
| 419 | dw[7] = 0; |
| 420 | |
| 421 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) { |
| 422 | dw[7] |= GEN75_SCS_RED << GEN75_SURFACE_DW7_SCS_R__SHIFT | |
| 423 | GEN75_SCS_GREEN << GEN75_SURFACE_DW7_SCS_G__SHIFT | |
| 424 | GEN75_SCS_BLUE << GEN75_SURFACE_DW7_SCS_B__SHIFT | |
| 425 | GEN75_SCS_ALPHA << GEN75_SURFACE_DW7_SCS_A__SHIFT; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | static void emit_null_view_gen6(const struct intel_gpu *gpu, uint32_t dw[6]) |
| 430 | { |
| 431 | INTEL_GPU_ASSERT(gpu, 6, 6); |
| 432 | |
| 433 | /* |
| 434 | * From the Sandy Bridge PRM, volume 4 part 1, page 71: |
| 435 | * |
| 436 | * "A null surface will be used in instances where an actual surface is |
| 437 | * not bound. When a write message is generated to a null surface, no |
| 438 | * actual surface is written to. When a read message (including any |
| 439 | * sampling engine message) is generated to a null surface, the result |
| 440 | * is all zeros. Note that a null surface type is allowed to be used |
| 441 | * with all messages, even if it is not specificially indicated as |
| 442 | * supported. All of the remaining fields in surface state are ignored |
| 443 | * for null surfaces, with the following exceptions: |
| 444 | * |
| 445 | * * [DevSNB+]: Width, Height, Depth, and LOD fields must match the |
| 446 | * depth buffer's corresponding state for all render target |
| 447 | * surfaces, including null. |
| 448 | * * Surface Format must be R8G8B8A8_UNORM." |
| 449 | * |
| 450 | * From the Sandy Bridge PRM, volume 4 part 1, page 82: |
| 451 | * |
| 452 | * "If Surface Type is SURFTYPE_NULL, this field (Tiled Surface) must be |
| 453 | * true" |
| 454 | */ |
| 455 | |
| 456 | dw[0] = GEN6_SURFTYPE_NULL << GEN6_SURFACE_DW0_TYPE__SHIFT | |
| 457 | GEN6_FORMAT_B8G8R8A8_UNORM << GEN6_SURFACE_DW0_FORMAT__SHIFT; |
| 458 | |
| 459 | dw[1] = 0; |
| 460 | dw[2] = 0; |
| 461 | dw[3] = GEN6_TILING_X; |
| 462 | dw[4] = 0; |
| 463 | dw[5] = 0; |
| 464 | } |
| 465 | |
| 466 | static void emit_mem_view_gen6(const struct intel_gpu *gpu, |
| 467 | unsigned offset, unsigned size, |
| 468 | unsigned struct_size, |
| 469 | XGL_FORMAT elem_format, |
| 470 | bool is_rt, bool render_cache_rw, |
| 471 | uint32_t dw[6]) |
| 472 | { |
| 473 | const int elem_size = icd_format_get_size(elem_format); |
| 474 | int width, height, depth, pitch; |
| 475 | int surface_format, num_entries; |
| 476 | |
| 477 | INTEL_GPU_ASSERT(gpu, 6, 6); |
| 478 | |
| 479 | /* |
| 480 | * For SURFTYPE_BUFFER, a SURFACE_STATE specifies an element of a |
| 481 | * structure in a buffer. |
| 482 | */ |
| 483 | |
| 484 | surface_format = intel_format_translate_color(gpu, elem_format); |
| 485 | |
| 486 | num_entries = size / struct_size; |
| 487 | /* see if there is enough space to fit another element */ |
| 488 | if (size % struct_size >= elem_size) |
| 489 | num_entries++; |
| 490 | |
| 491 | /* |
| 492 | * From the Sandy Bridge PRM, volume 4 part 1, page 76: |
| 493 | * |
| 494 | * "For SURFTYPE_BUFFER render targets, this field (Surface Base |
| 495 | * Address) specifies the base address of first element of the |
| 496 | * surface. The surface is interpreted as a simple array of that |
| 497 | * single element type. The address must be naturally-aligned to the |
| 498 | * element size (e.g., a buffer containing R32G32B32A32_FLOAT elements |
| 499 | * must be 16-byte aligned). |
| 500 | * |
| 501 | * For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies |
| 502 | * the base address of the first element of the surface, computed in |
| 503 | * software by adding the surface base address to the byte offset of |
| 504 | * the element in the buffer." |
| 505 | */ |
| 506 | if (is_rt) |
| 507 | assert(offset % elem_size == 0); |
| 508 | |
| 509 | /* |
| 510 | * From the Sandy Bridge PRM, volume 4 part 1, page 77: |
| 511 | * |
| 512 | * "For buffer surfaces, the number of entries in the buffer ranges |
| 513 | * from 1 to 2^27." |
| 514 | */ |
| 515 | assert(num_entries >= 1 && num_entries <= 1 << 27); |
| 516 | |
| 517 | /* |
| 518 | * From the Sandy Bridge PRM, volume 4 part 1, page 81: |
| 519 | * |
| 520 | * "For surfaces of type SURFTYPE_BUFFER, this field (Surface Pitch) |
| 521 | * indicates the size of the structure." |
| 522 | */ |
| 523 | pitch = struct_size; |
| 524 | |
| 525 | pitch--; |
| 526 | num_entries--; |
| 527 | /* bits [6:0] */ |
| 528 | width = (num_entries & 0x0000007f); |
| 529 | /* bits [19:7] */ |
| 530 | height = (num_entries & 0x000fff80) >> 7; |
| 531 | /* bits [26:20] */ |
| 532 | depth = (num_entries & 0x07f00000) >> 20; |
| 533 | |
| 534 | dw[0] = GEN6_SURFTYPE_BUFFER << GEN6_SURFACE_DW0_TYPE__SHIFT | |
| 535 | surface_format << GEN6_SURFACE_DW0_FORMAT__SHIFT; |
| 536 | if (render_cache_rw) |
| 537 | dw[0] |= GEN6_SURFACE_DW0_RENDER_CACHE_RW; |
| 538 | |
| 539 | dw[1] = offset; |
| 540 | |
| 541 | dw[2] = height << GEN6_SURFACE_DW2_HEIGHT__SHIFT | |
| 542 | width << GEN6_SURFACE_DW2_WIDTH__SHIFT; |
| 543 | |
| 544 | dw[3] = depth << GEN6_SURFACE_DW3_DEPTH__SHIFT | |
| 545 | pitch << GEN6_SURFACE_DW3_PITCH__SHIFT; |
| 546 | |
| 547 | dw[4] = 0; |
| 548 | dw[5] = 0; |
| 549 | } |
| 550 | |
| 551 | static void emit_img_view_gen6(const struct intel_gpu *gpu, |
| 552 | const struct intel_img *img, |
| 553 | XGL_IMAGE_VIEW_TYPE type, |
| 554 | XGL_FORMAT format, |
| 555 | unsigned first_level, |
| 556 | unsigned num_levels, |
| 557 | unsigned first_layer, |
| 558 | unsigned num_layers, |
| 559 | bool is_rt, |
| 560 | uint32_t dw[6]) |
| 561 | { |
| 562 | int surface_type, surface_format; |
| 563 | int width, height, depth, pitch, lod; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 564 | |
| 565 | INTEL_GPU_ASSERT(gpu, 6, 6); |
| 566 | |
| 567 | surface_type = view_type_to_surface_type(type); |
| 568 | assert(surface_type != GEN6_SURFTYPE_BUFFER); |
| 569 | |
| 570 | surface_format = intel_format_translate_color(gpu, format); |
| 571 | assert(surface_format >= 0); |
| 572 | |
| 573 | width = img->extent.width; |
| 574 | height = img->extent.height; |
| 575 | depth = (type == XGL_IMAGE_VIEW_3D) ? |
| 576 | img->extent.depth : num_layers; |
| 577 | pitch = img->layout.bo_stride; |
| 578 | |
| 579 | if (surface_type == GEN6_SURFTYPE_CUBE) { |
| 580 | /* |
| 581 | * From the Sandy Bridge PRM, volume 4 part 1, page 81: |
| 582 | * |
| 583 | * "For SURFTYPE_CUBE: [DevSNB+]: for Sampling Engine Surfaces, the |
| 584 | * range of this field (Depth) is [0,84], indicating the number of |
| 585 | * cube array elements (equal to the number of underlying 2D array |
| 586 | * elements divided by 6). For other surfaces, this field must be |
| 587 | * zero." |
| 588 | * |
| 589 | * When is_rt is true, we treat the texture as a 2D one to avoid the |
| 590 | * restriction. |
| 591 | */ |
| 592 | if (is_rt) { |
| 593 | surface_type = GEN6_SURFTYPE_2D; |
| 594 | } |
| 595 | else { |
| 596 | assert(num_layers % 6 == 0); |
| 597 | depth = num_layers / 6; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /* sanity check the size */ |
| 602 | assert(width >= 1 && height >= 1 && depth >= 1 && pitch >= 1); |
| 603 | switch (surface_type) { |
| 604 | case GEN6_SURFTYPE_1D: |
| 605 | assert(width <= 8192 && height == 1 && depth <= 512); |
| 606 | assert(first_layer < 512 && num_layers <= 512); |
| 607 | break; |
| 608 | case GEN6_SURFTYPE_2D: |
| 609 | assert(width <= 8192 && height <= 8192 && depth <= 512); |
| 610 | assert(first_layer < 512 && num_layers <= 512); |
| 611 | break; |
| 612 | case GEN6_SURFTYPE_3D: |
| 613 | assert(width <= 2048 && height <= 2048 && depth <= 2048); |
| 614 | assert(first_layer < 2048 && num_layers <= 512); |
| 615 | if (!is_rt) |
| 616 | assert(first_layer == 0); |
| 617 | break; |
| 618 | case GEN6_SURFTYPE_CUBE: |
| 619 | assert(width <= 8192 && height <= 8192 && depth <= 85); |
| 620 | assert(width == height); |
| 621 | assert(first_layer < 512 && num_layers <= 512); |
| 622 | if (is_rt) |
| 623 | assert(first_layer == 0); |
| 624 | break; |
| 625 | default: |
| 626 | assert(!"unexpected surface type"); |
| 627 | break; |
| 628 | } |
| 629 | |
| 630 | /* non-full array spacing is supported only on GEN7+ */ |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 631 | assert(img->layout.walk != INTEL_LAYOUT_WALK_LOD); |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 632 | /* non-interleaved samples are supported only on GEN7+ */ |
| 633 | if (img->samples > 1) |
| 634 | assert(img->layout.interleaved_samples); |
| 635 | |
| 636 | if (is_rt) { |
| 637 | assert(num_levels == 1); |
| 638 | lod = first_level; |
| 639 | } |
| 640 | else { |
| 641 | lod = num_levels - 1; |
| 642 | } |
| 643 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 644 | /* |
| 645 | * From the Sandy Bridge PRM, volume 4 part 1, page 76: |
| 646 | * |
| 647 | * "Linear render target surface base addresses must be element-size |
| 648 | * aligned, for non-YUV surface formats, or a multiple of 2 |
| 649 | * element-sizes for YUV surface formats. Other linear surfaces have |
| 650 | * no alignment requirements (byte alignment is sufficient.)" |
| 651 | * |
| 652 | * From the Sandy Bridge PRM, volume 4 part 1, page 81: |
| 653 | * |
| 654 | * "For linear render target surfaces, the pitch must be a multiple |
| 655 | * of the element size for non-YUV surface formats. Pitch must be a |
| 656 | * multiple of 2 * element size for YUV surface formats." |
| 657 | * |
| 658 | * From the Sandy Bridge PRM, volume 4 part 1, page 86: |
| 659 | * |
| 660 | * "For linear surfaces, this field (X Offset) must be zero" |
| 661 | */ |
| 662 | if (img->layout.tiling == INTEL_TILING_NONE) { |
| 663 | if (is_rt) { |
| 664 | const int elem_size = icd_format_get_size(format); |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 665 | assert(pitch % elem_size == 0); |
| 666 | } |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | dw[0] = surface_type << GEN6_SURFACE_DW0_TYPE__SHIFT | |
| 670 | surface_format << GEN6_SURFACE_DW0_FORMAT__SHIFT | |
| 671 | GEN6_SURFACE_DW0_MIPLAYOUT_BELOW; |
| 672 | |
| 673 | if (surface_type == GEN6_SURFTYPE_CUBE && !is_rt) { |
| 674 | dw[0] |= 1 << 9 | |
| 675 | GEN6_SURFACE_DW0_CUBE_FACE_ENABLES__MASK; |
| 676 | } |
| 677 | |
| 678 | if (is_rt) |
| 679 | dw[0] |= GEN6_SURFACE_DW0_RENDER_CACHE_RW; |
| 680 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 681 | dw[1] = 0; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 682 | |
| 683 | dw[2] = (height - 1) << GEN6_SURFACE_DW2_HEIGHT__SHIFT | |
| 684 | (width - 1) << GEN6_SURFACE_DW2_WIDTH__SHIFT | |
| 685 | lod << GEN6_SURFACE_DW2_MIP_COUNT_LOD__SHIFT; |
| 686 | |
| 687 | dw[3] = (depth - 1) << GEN6_SURFACE_DW3_DEPTH__SHIFT | |
| 688 | (pitch - 1) << GEN6_SURFACE_DW3_PITCH__SHIFT | |
| 689 | winsys_tiling_to_surface_tiling(img->layout.tiling); |
| 690 | |
| 691 | dw[4] = first_level << GEN6_SURFACE_DW4_MIN_LOD__SHIFT | |
| 692 | first_layer << 17 | |
| 693 | (num_layers - 1) << 8 | |
| 694 | ((img->samples > 1) ? GEN6_SURFACE_DW4_MULTISAMPLECOUNT_4 : |
| 695 | GEN6_SURFACE_DW4_MULTISAMPLECOUNT_1); |
| 696 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 697 | dw[5] = 0; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 698 | |
| 699 | assert(img->layout.align_j == 2 || img->layout.align_j == 4); |
| 700 | if (img->layout.align_j == 4) |
| 701 | dw[5] |= GEN6_SURFACE_DW5_VALIGN_4; |
| 702 | } |
| 703 | |
| 704 | struct ds_surface_info { |
| 705 | int surface_type; |
| 706 | int format; |
| 707 | |
| 708 | struct { |
| 709 | unsigned stride; |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 710 | unsigned offset; |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 711 | } zs, stencil, hiz; |
| 712 | |
| 713 | unsigned width, height, depth; |
| 714 | unsigned lod, first_layer, num_layers; |
| 715 | }; |
| 716 | |
| 717 | static void |
| 718 | ds_init_info_null(const struct intel_gpu *gpu, |
| 719 | struct ds_surface_info *info) |
| 720 | { |
| 721 | INTEL_GPU_ASSERT(gpu, 6, 7.5); |
| 722 | |
| 723 | memset(info, 0, sizeof(*info)); |
| 724 | |
| 725 | info->surface_type = GEN6_SURFTYPE_NULL; |
| 726 | info->format = GEN6_ZFORMAT_D32_FLOAT; |
| 727 | info->width = 1; |
| 728 | info->height = 1; |
| 729 | info->depth = 1; |
| 730 | info->num_layers = 1; |
| 731 | } |
| 732 | |
| 733 | static void |
| 734 | ds_init_info(const struct intel_gpu *gpu, |
| 735 | const struct intel_img *img, |
| 736 | XGL_FORMAT format, unsigned level, |
| 737 | unsigned first_layer, unsigned num_layers, |
| 738 | struct ds_surface_info *info) |
| 739 | { |
| 740 | bool separate_stencil; |
| 741 | |
| 742 | INTEL_GPU_ASSERT(gpu, 6, 7.5); |
| 743 | |
| 744 | memset(info, 0, sizeof(*info)); |
| 745 | |
| 746 | info->surface_type = |
| 747 | view_type_to_surface_type(img_type_to_view_type(img->type)); |
| 748 | |
| 749 | if (info->surface_type == GEN6_SURFTYPE_CUBE) { |
| 750 | /* |
| 751 | * From the Sandy Bridge PRM, volume 2 part 1, page 325-326: |
| 752 | * |
| 753 | * "For Other Surfaces (Cube Surfaces): |
| 754 | * This field (Minimum Array Element) is ignored." |
| 755 | * |
| 756 | * "For Other Surfaces (Cube Surfaces): |
| 757 | * This field (Render Target View Extent) is ignored." |
| 758 | * |
| 759 | * As such, we cannot set first_layer and num_layers on cube surfaces. |
| 760 | * To work around that, treat it as a 2D surface. |
| 761 | */ |
| 762 | info->surface_type = GEN6_SURFTYPE_2D; |
| 763 | } |
| 764 | |
| 765 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7)) { |
| 766 | separate_stencil = true; |
| 767 | } |
| 768 | else { |
| 769 | /* |
| 770 | * From the Sandy Bridge PRM, volume 2 part 1, page 317: |
| 771 | * |
| 772 | * "This field (Separate Stencil Buffer Enable) must be set to the |
| 773 | * same value (enabled or disabled) as Hierarchical Depth Buffer |
| 774 | * Enable." |
| 775 | */ |
| 776 | separate_stencil = img->aux_offset; |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * From the Sandy Bridge PRM, volume 2 part 1, page 317: |
| 781 | * |
| 782 | * "If this field (Hierarchical Depth Buffer Enable) is enabled, the |
| 783 | * Surface Format of the depth buffer cannot be |
| 784 | * D32_FLOAT_S8X24_UINT or D24_UNORM_S8_UINT. Use of stencil |
| 785 | * requires the separate stencil buffer." |
| 786 | * |
| 787 | * From the Ironlake PRM, volume 2 part 1, page 330: |
| 788 | * |
| 789 | * "If this field (Separate Stencil Buffer Enable) is disabled, the |
| 790 | * Surface Format of the depth buffer cannot be D24_UNORM_X8_UINT." |
| 791 | * |
| 792 | * There is no similar restriction for GEN6. But when D24_UNORM_X8_UINT |
| 793 | * is indeed used, the depth values output by the fragment shaders will |
| 794 | * be different when read back. |
| 795 | * |
| 796 | * As for GEN7+, separate_stencil is always true. |
| 797 | */ |
| 798 | switch (format.channelFormat) { |
| 799 | case XGL_CH_FMT_R16: |
| 800 | info->format = GEN6_ZFORMAT_D16_UNORM; |
| 801 | break; |
| 802 | case XGL_CH_FMT_R32: |
| 803 | info->format = GEN6_ZFORMAT_D32_FLOAT; |
| 804 | break; |
| 805 | case XGL_CH_FMT_R32G8: |
| 806 | info->format = (separate_stencil) ? |
| 807 | GEN6_ZFORMAT_D32_FLOAT : |
| 808 | GEN6_ZFORMAT_D32_FLOAT_S8X24_UINT; |
| 809 | break; |
| 810 | case XGL_CH_FMT_R8: |
| 811 | if (separate_stencil) { |
| 812 | info->format = GEN6_ZFORMAT_D32_FLOAT; |
| 813 | break; |
| 814 | } |
| 815 | /* fall through */ |
| 816 | default: |
| 817 | assert(!"unsupported depth/stencil format"); |
| 818 | ds_init_info_null(gpu, info); |
| 819 | return; |
| 820 | break; |
| 821 | } |
| 822 | |
| 823 | if (format.channelFormat != XGL_CH_FMT_R8) |
| 824 | info->zs.stride = img->layout.bo_stride; |
| 825 | |
| 826 | if (img->s8_layout) { |
| 827 | /* |
| 828 | * From the Sandy Bridge PRM, volume 2 part 1, page 329: |
| 829 | * |
| 830 | * "The pitch must be set to 2x the value computed based on width, |
| 831 | * as the stencil buffer is stored with two rows interleaved." |
| 832 | * |
| 833 | * According to the classic driver, we need to do the same for GEN7+ |
| 834 | * even though the Ivy Bridge PRM does not say anything about it. |
| 835 | */ |
| 836 | info->stencil.stride = img->s8_layout->bo_stride * 2; |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 837 | |
| 838 | if (intel_gpu_gen(gpu) == INTEL_GEN(6)) { |
| 839 | unsigned x, y; |
| 840 | |
| 841 | assert(img->s8_layout->walk == INTEL_LAYOUT_WALK_LOD); |
| 842 | |
| 843 | /* offset to the level */ |
| 844 | intel_layout_get_slice_pos(img->s8_layout, level, 0, &x, &y); |
| 845 | intel_layout_pos_to_mem(img->s8_layout, x, y, &x, &y); |
| 846 | info->stencil.offset = intel_layout_mem_to_raw(img->s8_layout, x, y); |
| 847 | } |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 848 | } else if (format.channelFormat == XGL_CH_FMT_R8) { |
| 849 | info->stencil.stride = img->layout.bo_stride * 2; |
| 850 | } |
| 851 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 852 | if (img->aux_offset) { |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 853 | info->hiz.stride = img->layout.aux_stride; |
| 854 | |
Chia-I Wu | 457d0a6 | 2014-08-18 13:02:26 +0800 | [diff] [blame^] | 855 | /* offset to the level */ |
| 856 | if (intel_gpu_gen(gpu) == INTEL_GEN(6)) |
| 857 | info->hiz.offset = img->layout.aux_offsets[level]; |
| 858 | } |
| 859 | |
| 860 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 861 | info->width = img->extent.width; |
| 862 | info->height = img->extent.height; |
| 863 | info->depth = (img->type == XGL_IMAGE_3D) ? |
| 864 | img->extent.depth : num_layers; |
| 865 | |
| 866 | info->lod = level; |
| 867 | info->first_layer = first_layer; |
| 868 | info->num_layers = num_layers; |
| 869 | } |
| 870 | |
| 871 | static void emit_ds_view(const struct intel_gpu *gpu, |
| 872 | const struct intel_img *img, |
| 873 | XGL_FORMAT format, unsigned level, |
| 874 | unsigned first_layer, unsigned num_layers, |
| 875 | uint32_t dw[10]) |
| 876 | { |
| 877 | const int max_2d_size = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16384 : 8192; |
| 878 | const int max_array_size = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 2048 : 512; |
| 879 | struct ds_surface_info info; |
| 880 | uint32_t dw1, dw2, dw3, dw4, dw5, dw6; |
| 881 | |
| 882 | INTEL_GPU_ASSERT(gpu, 6, 7.5); |
| 883 | |
| 884 | if (img) { |
| 885 | ds_init_info(gpu, img, format, level, first_layer, num_layers, &info); |
| 886 | } |
| 887 | else { |
| 888 | ds_init_info_null(gpu, &info); |
| 889 | } |
| 890 | |
| 891 | switch (info.surface_type) { |
| 892 | case GEN6_SURFTYPE_NULL: |
| 893 | break; |
| 894 | case GEN6_SURFTYPE_1D: |
| 895 | assert(info.width <= max_2d_size && info.height == 1 && |
| 896 | info.depth <= max_array_size); |
| 897 | assert(info.first_layer < max_array_size - 1 && |
| 898 | info.num_layers <= max_array_size); |
| 899 | break; |
| 900 | case GEN6_SURFTYPE_2D: |
| 901 | assert(info.width <= max_2d_size && info.height <= max_2d_size && |
| 902 | info.depth <= max_array_size); |
| 903 | assert(info.first_layer < max_array_size - 1 && |
| 904 | info.num_layers <= max_array_size); |
| 905 | break; |
| 906 | case GEN6_SURFTYPE_3D: |
| 907 | assert(info.width <= 2048 && info.height <= 2048 && info.depth <= 2048); |
| 908 | assert(info.first_layer < 2048 && info.num_layers <= max_array_size); |
| 909 | break; |
| 910 | case GEN6_SURFTYPE_CUBE: |
| 911 | assert(info.width <= max_2d_size && info.height <= max_2d_size && |
| 912 | info.depth == 1); |
| 913 | assert(info.first_layer == 0 && info.num_layers == 1); |
| 914 | assert(info.width == info.height); |
| 915 | break; |
| 916 | default: |
| 917 | assert(!"unexpected depth surface type"); |
| 918 | break; |
| 919 | } |
| 920 | |
| 921 | dw1 = info.surface_type << 29 | |
| 922 | info.format << 18; |
| 923 | |
| 924 | if (info.zs.stride) { |
| 925 | /* required for GEN6+ */ |
| 926 | assert(info.zs.stride > 0 && info.zs.stride < 128 * 1024 && |
| 927 | info.zs.stride % 128 == 0); |
| 928 | assert(info.width <= info.zs.stride); |
| 929 | |
| 930 | dw1 |= (info.zs.stride - 1); |
| 931 | } |
| 932 | |
| 933 | dw2 = 0; |
| 934 | |
| 935 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7)) { |
| 936 | if (info.zs.stride) |
| 937 | dw1 |= 1 << 28; |
| 938 | |
| 939 | if (info.stencil.stride) |
| 940 | dw1 |= 1 << 27; |
| 941 | |
| 942 | if (info.hiz.stride) |
| 943 | dw1 |= 1 << 22; |
| 944 | |
| 945 | dw3 = (info.height - 1) << 18 | |
| 946 | (info.width - 1) << 4 | |
| 947 | info.lod; |
| 948 | |
| 949 | dw4 = (info.depth - 1) << 21 | |
| 950 | info.first_layer << 10; |
| 951 | |
| 952 | dw5 = 0; |
| 953 | |
| 954 | dw6 = (info.num_layers - 1) << 21; |
| 955 | } |
| 956 | else { |
| 957 | /* always Y-tiled */ |
| 958 | dw1 |= 1 << 27 | |
| 959 | 1 << 26; |
| 960 | |
| 961 | if (info.hiz.stride) { |
| 962 | dw1 |= 1 << 22 | |
| 963 | 1 << 21; |
| 964 | } |
| 965 | |
| 966 | dw3 = (info.height - 1) << 19 | |
| 967 | (info.width - 1) << 6 | |
| 968 | info.lod << 2 | |
| 969 | GEN6_DEPTH_DW3_MIPLAYOUT_BELOW; |
| 970 | |
| 971 | dw4 = (info.depth - 1) << 21 | |
| 972 | info.first_layer << 10 | |
| 973 | (info.num_layers - 1) << 1; |
| 974 | |
| 975 | dw5 = 0; |
| 976 | |
| 977 | dw6 = 0; |
| 978 | } |
| 979 | |
| 980 | dw[0] = dw1; |
| 981 | dw[1] = dw2; |
| 982 | dw[2] = dw3; |
| 983 | dw[3] = dw4; |
| 984 | dw[4] = dw5; |
| 985 | dw[5] = dw6; |
| 986 | |
| 987 | /* separate stencil */ |
| 988 | if (info.stencil.stride) { |
| 989 | assert(info.stencil.stride > 0 && info.stencil.stride < 128 * 1024 && |
| 990 | info.stencil.stride % 128 == 0); |
| 991 | |
| 992 | dw[6] = info.stencil.stride - 1; |
| 993 | dw[7] = img->s8_offset; |
| 994 | |
| 995 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7.5)) |
| 996 | dw[6] |= GEN75_STENCIL_DW1_STENCIL_BUFFER_ENABLE; |
| 997 | } |
| 998 | else { |
| 999 | dw[6] = 0; |
| 1000 | dw[7] = 0; |
| 1001 | } |
| 1002 | |
| 1003 | /* hiz */ |
| 1004 | if (info.hiz.stride) { |
| 1005 | dw[8] = info.hiz.stride - 1; |
| 1006 | dw[9] = img->aux_offset; |
| 1007 | } |
| 1008 | else { |
| 1009 | dw[8] = 0; |
| 1010 | dw[9] = 0; |
| 1011 | } |
| 1012 | } |
| 1013 | |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1014 | void intel_null_view_init(struct intel_null_view *view, |
| 1015 | struct intel_dev *dev) |
| 1016 | { |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 1017 | if (intel_gpu_gen(dev->gpu) >= INTEL_GEN(7)) |
| 1018 | emit_null_view_gen7(dev->gpu, view->cmd); |
| 1019 | else |
| 1020 | emit_null_view_gen6(dev->gpu, view->cmd); |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | void intel_mem_view_init(struct intel_mem_view *view, |
| 1024 | struct intel_dev *dev, |
| 1025 | const XGL_MEMORY_VIEW_ATTACH_INFO *info) |
| 1026 | { |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 1027 | bool will_write; |
| 1028 | |
| 1029 | switch (info->state) { |
| 1030 | case XGL_MEMORY_STATE_GRAPHICS_SHADER_WRITE_ONLY: |
| 1031 | case XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_WRITE: |
| 1032 | case XGL_MEMORY_STATE_COMPUTE_SHADER_WRITE_ONLY: |
| 1033 | case XGL_MEMORY_STATE_COMPUTE_SHADER_READ_WRITE: |
| 1034 | will_write = true; |
| 1035 | break; |
| 1036 | default: |
| 1037 | will_write = false; |
| 1038 | break; |
| 1039 | } |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1040 | |
| 1041 | view->mem = intel_mem(info->mem); |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 1042 | |
| 1043 | if (intel_gpu_gen(dev->gpu) >= INTEL_GEN(7)) { |
| 1044 | emit_mem_view_gen7(dev->gpu, info->offset, info->range, info->stride, |
| 1045 | info->format, will_write, will_write, view->cmd); |
| 1046 | } else { |
| 1047 | emit_mem_view_gen6(dev->gpu, info->offset, info->range, info->stride, |
| 1048 | info->format, will_write, will_write, view->cmd); |
| 1049 | } |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static void img_view_destroy(struct intel_obj *obj) |
| 1053 | { |
| 1054 | struct intel_img_view *view = intel_img_view_from_obj(obj); |
| 1055 | |
| 1056 | intel_img_view_destroy(view); |
| 1057 | } |
| 1058 | |
| 1059 | XGL_RESULT intel_img_view_create(struct intel_dev *dev, |
| 1060 | const XGL_IMAGE_VIEW_CREATE_INFO *info, |
| 1061 | struct intel_img_view **view_ret) |
| 1062 | { |
| 1063 | struct intel_img *img = intel_img(info->image); |
| 1064 | struct intel_img_view *view; |
| 1065 | |
| 1066 | view = (struct intel_img_view *) intel_base_create(dev, sizeof(*view), |
| 1067 | dev->base.dbg, XGL_DBG_OBJECT_IMAGE_VIEW, info, 0); |
| 1068 | if (!view) |
| 1069 | return XGL_ERROR_OUT_OF_MEMORY; |
| 1070 | |
| 1071 | view->obj.destroy = img_view_destroy; |
| 1072 | |
| 1073 | view->img = img; |
| 1074 | view->swizzles = info->channels; |
| 1075 | view->min_lod = info->minLod; |
| 1076 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 1077 | if (intel_gpu_gen(dev->gpu) >= INTEL_GEN(7)) { |
| 1078 | emit_img_view_gen7(dev->gpu, img, info->viewType, info->format, |
| 1079 | info->subresourceRange.baseMipLevel, |
| 1080 | info->subresourceRange.mipLevels, |
| 1081 | info->subresourceRange.baseArraySlice, |
| 1082 | info->subresourceRange.arraySize, false, view->cmd); |
| 1083 | } else { |
| 1084 | emit_img_view_gen6(dev->gpu, info->image, info->viewType, info->format, |
| 1085 | info->subresourceRange.baseMipLevel, |
| 1086 | info->subresourceRange.mipLevels, |
| 1087 | info->subresourceRange.baseArraySlice, |
| 1088 | info->subresourceRange.arraySize, false, view->cmd); |
| 1089 | } |
| 1090 | |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1091 | *view_ret = view; |
| 1092 | |
| 1093 | return XGL_SUCCESS; |
| 1094 | } |
| 1095 | |
| 1096 | void intel_img_view_destroy(struct intel_img_view *view) |
| 1097 | { |
| 1098 | intel_base_destroy(&view->obj.base); |
| 1099 | } |
| 1100 | |
| 1101 | static void rt_view_destroy(struct intel_obj *obj) |
| 1102 | { |
| 1103 | struct intel_rt_view *view = intel_rt_view_from_obj(obj); |
| 1104 | |
| 1105 | intel_rt_view_destroy(view); |
| 1106 | } |
| 1107 | |
| 1108 | XGL_RESULT intel_rt_view_create(struct intel_dev *dev, |
| 1109 | const XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO *info, |
| 1110 | struct intel_rt_view **view_ret) |
| 1111 | { |
| 1112 | struct intel_img *img = intel_img(info->image); |
| 1113 | struct intel_rt_view *view; |
| 1114 | |
| 1115 | view = (struct intel_rt_view *) intel_base_create(dev, sizeof(*view), |
| 1116 | dev->base.dbg, XGL_DBG_OBJECT_COLOR_TARGET_VIEW, info, 0); |
| 1117 | if (!view) |
| 1118 | return XGL_ERROR_OUT_OF_MEMORY; |
| 1119 | |
| 1120 | view->obj.destroy = rt_view_destroy; |
| 1121 | |
| 1122 | view->img = img; |
| 1123 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 1124 | if (intel_gpu_gen(dev->gpu) >= INTEL_GEN(7)) { |
| 1125 | emit_img_view_gen7(dev->gpu, img, img_type_to_view_type(img->type), |
| 1126 | info->format, info->mipLevel, 1, |
| 1127 | info->baseArraySlice, info->arraySize, |
| 1128 | true, view->cmd); |
| 1129 | } else { |
| 1130 | emit_img_view_gen6(dev->gpu, img, img_type_to_view_type(img->type), |
| 1131 | info->format, info->mipLevel, 1, |
| 1132 | info->baseArraySlice, info->arraySize, |
| 1133 | true, view->cmd); |
| 1134 | } |
| 1135 | |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1136 | *view_ret = view; |
| 1137 | |
| 1138 | return XGL_SUCCESS; |
| 1139 | } |
| 1140 | |
| 1141 | void intel_rt_view_destroy(struct intel_rt_view *view) |
| 1142 | { |
| 1143 | intel_base_destroy(&view->obj.base); |
| 1144 | } |
| 1145 | |
| 1146 | static void ds_view_destroy(struct intel_obj *obj) |
| 1147 | { |
| 1148 | struct intel_ds_view *view = intel_ds_view_from_obj(obj); |
| 1149 | |
| 1150 | intel_ds_view_destroy(view); |
| 1151 | } |
| 1152 | |
| 1153 | XGL_RESULT intel_ds_view_create(struct intel_dev *dev, |
| 1154 | const XGL_DEPTH_STENCIL_VIEW_CREATE_INFO *info, |
| 1155 | struct intel_ds_view **view_ret) |
| 1156 | { |
| 1157 | struct intel_img *img = intel_img(info->image); |
| 1158 | struct intel_ds_view *view; |
| 1159 | |
| 1160 | view = (struct intel_ds_view *) intel_base_create(dev, sizeof(*view), |
| 1161 | dev->base.dbg, XGL_DBG_OBJECT_DEPTH_STENCIL_VIEW, info, 0); |
| 1162 | if (!view) |
| 1163 | return XGL_ERROR_OUT_OF_MEMORY; |
| 1164 | |
| 1165 | view->obj.destroy = ds_view_destroy; |
| 1166 | |
| 1167 | view->img = img; |
| 1168 | |
Chia-I Wu | 9269d1c | 2014-08-16 12:47:47 +0800 | [diff] [blame] | 1169 | emit_ds_view(dev->gpu, img, img->layout.format, info->mipLevel, |
| 1170 | info->baseArraySlice, info->arraySize, view->cmd); |
| 1171 | |
Chia-I Wu | 5a32326 | 2014-08-11 10:31:53 +0800 | [diff] [blame] | 1172 | *view_ret = view; |
| 1173 | |
| 1174 | return XGL_SUCCESS; |
| 1175 | } |
| 1176 | |
| 1177 | void intel_ds_view_destroy(struct intel_ds_view *view) |
| 1178 | { |
| 1179 | intel_base_destroy(&view->obj.base); |
| 1180 | } |
| 1181 | |
| 1182 | XGL_RESULT XGLAPI intelCreateImageView( |
| 1183 | XGL_DEVICE device, |
| 1184 | const XGL_IMAGE_VIEW_CREATE_INFO* pCreateInfo, |
| 1185 | XGL_IMAGE_VIEW* pView) |
| 1186 | { |
| 1187 | struct intel_dev *dev = intel_dev(device); |
| 1188 | |
| 1189 | return intel_img_view_create(dev, pCreateInfo, |
| 1190 | (struct intel_img_view **) pView); |
| 1191 | } |
| 1192 | |
| 1193 | XGL_RESULT XGLAPI intelCreateColorAttachmentView( |
| 1194 | XGL_DEVICE device, |
| 1195 | const XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO* pCreateInfo, |
| 1196 | XGL_COLOR_ATTACHMENT_VIEW* pView) |
| 1197 | { |
| 1198 | struct intel_dev *dev = intel_dev(device); |
| 1199 | |
| 1200 | return intel_rt_view_create(dev, pCreateInfo, |
| 1201 | (struct intel_rt_view **) pView); |
| 1202 | } |
| 1203 | |
| 1204 | XGL_RESULT XGLAPI intelCreateDepthStencilView( |
| 1205 | XGL_DEVICE device, |
| 1206 | const XGL_DEPTH_STENCIL_VIEW_CREATE_INFO* pCreateInfo, |
| 1207 | XGL_DEPTH_STENCIL_VIEW* pView) |
| 1208 | { |
| 1209 | struct intel_dev *dev = intel_dev(device); |
| 1210 | |
| 1211 | return intel_ds_view_create(dev, pCreateInfo, |
| 1212 | (struct intel_ds_view **) pView); |
| 1213 | } |