isl: Embed brw_device_info in isl_device
[mesa.git] / src / vulkan / isl.c
1 /*
2 * Copyright 2015 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25
26 #include "mesa/main/imports.h"
27
28 #include "isl.h"
29
30 /**
31 * Log base 2, rounding towards zero.
32 */
33 static inline uint32_t
34 isl_log2u(uint32_t n)
35 {
36 assert(n != 0);
37 return 31 - __builtin_clz(n);
38 }
39
40 void
41 isl_device_init(struct isl_device *dev,
42 const struct brw_device_info *info)
43 {
44 dev->info = info;
45 }
46
47 /**
48 * The returned extent's units are (width=bytes, height=rows).
49 */
50 void
51 isl_tiling_get_extent(const struct isl_device *dev,
52 enum isl_tiling tiling,
53 uint32_t cpp,
54 struct isl_extent2d *e)
55 {
56 static const struct isl_extent2d legacy_extents[] = {
57 [ISL_TILING_LINEAR] = { 1, 1 },
58 [ISL_TILING_X] = { 512, 8 },
59 [ISL_TILING_Y] = { 128, 32 },
60 [ISL_TILING_W] = { 128, 32 },
61 };
62
63 static const struct isl_extent2d yf_extents[] = {
64 /*cpp*/
65 /* 1*/ [0] = { 64, 64 },
66 /* 2*/ [1] = { 128, 32 },
67 /* 4*/ [2] = { 128, 32 },
68 /* 8*/ [3] = { 256, 16 },
69 /*16*/ [4] = { 256, 16 },
70 };
71
72 assert(cpp > 0);
73
74 switch (tiling) {
75 case ISL_TILING_LINEAR:
76 case ISL_TILING_X:
77 case ISL_TILING_Y:
78 case ISL_TILING_W:
79 *e = legacy_extents[tiling];
80 return;
81 case ISL_TILING_Yf:
82 case ISL_TILING_Ys:
83 assert(_mesa_is_pow_two(cpp));
84 *e = yf_extents[isl_log2u(cpp)];
85 if (tiling == ISL_TILING_Ys) {
86 e->width *= 4;
87 e->height *= 4;
88 }
89 return;
90 }
91 }