• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2020 Valve Corporation
3  *
4  * based on amdgpu winsys.
5  * Copyright © 2016 Red Hat.
6  * Copyright © 2016 Bas Nieuwenhuizen
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the next
16  * paragraph) shall be included in all copies or substantial portions of the
17  * Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25  * IN THE SOFTWARE.
26  */
27 #include "radv_null_winsys_public.h"
28 
29 #include "util/u_string.h"
30 #include "radv_null_bo.h"
31 #include "radv_null_cs.h"
32 #include "vk_sync_dummy.h"
33 
34 /* Hardcode some GPU info that are needed for the driver or for some tools. */
35 static const struct {
36    uint32_t pci_id;
37    uint32_t num_render_backends;
38    bool has_dedicated_vram;
39 } gpu_info[] = {
40    /* clang-format off */
41    [CHIP_TAHITI] = {0x6780, 8, true},
42    [CHIP_PITCAIRN] = {0x6800, 8, true},
43    [CHIP_VERDE] = {0x6820, 4, true},
44    [CHIP_OLAND] = {0x6060, 2, true},
45    [CHIP_HAINAN] = {0x6660, 2, true},
46    [CHIP_BONAIRE] = {0x6640, 4, true},
47    [CHIP_KAVERI] = {0x1304, 2, false},
48    [CHIP_KABINI] = {0x9830, 2, false},
49    [CHIP_HAWAII] = {0x67A0, 16, true},
50    [CHIP_TONGA] = {0x6920, 8, true},
51    [CHIP_ICELAND] = {0x6900, 2, true},
52    [CHIP_CARRIZO] = {0x9870, 2, false},
53    [CHIP_FIJI] = {0x7300, 16, true},
54    [CHIP_STONEY] = {0x98E4, 2, false},
55    [CHIP_POLARIS10] = {0x67C0, 8, true},
56    [CHIP_POLARIS11] = {0x67E0, 4, true},
57    [CHIP_POLARIS12] = {0x6980, 4, true},
58    [CHIP_VEGAM] = {0x694C, 4, true},
59    [CHIP_VEGA10] = {0x6860, 16, true},
60    [CHIP_VEGA12] = {0x69A0, 8, true},
61    [CHIP_VEGA20] = {0x66A0, 16, true},
62    [CHIP_RAVEN] = {0x15DD, 2, false},
63    [CHIP_RENOIR] = {0x1636, 2, false},
64    [CHIP_MI100] = {0x738C, 2, true},
65    [CHIP_NAVI10] = {0x7310, 16, true},
66    [CHIP_NAVI12] = {0x7360, 8, true},
67    [CHIP_NAVI14] = {0x7340, 8, true},
68    [CHIP_NAVI21] = {0x73A0, 16, true},
69    [CHIP_VANGOGH] = {0x163F, 8, false},
70    [CHIP_NAVI22] = {0x73C0, 8, true},
71    [CHIP_NAVI23] = {0x73E0, 8, true},
72    [CHIP_NAVI31] = {0x744C, 24, true},
73    /* clang-format on */
74 };
75 
76 static void
radv_null_winsys_query_info(struct radeon_winsys * rws,struct radeon_info * info)77 radv_null_winsys_query_info(struct radeon_winsys *rws, struct radeon_info *info)
78 {
79    const char *family = getenv("RADV_FORCE_FAMILY");
80    unsigned i;
81 
82    info->gfx_level = CLASS_UNKNOWN;
83    info->family = CHIP_UNKNOWN;
84 
85    for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
86       if (!strcasecmp(family, ac_get_family_name(i))) {
87          /* Override family and gfx_level. */
88          info->family = i;
89          info->name = ac_get_family_name(i);
90 
91          if (info->family >= CHIP_NAVI31)
92             info->gfx_level = GFX11;
93          else if (i >= CHIP_NAVI21)
94             info->gfx_level = GFX10_3;
95          else if (i >= CHIP_NAVI10)
96             info->gfx_level = GFX10;
97          else if (i >= CHIP_VEGA10)
98             info->gfx_level = GFX9;
99          else if (i >= CHIP_TONGA)
100             info->gfx_level = GFX8;
101          else if (i >= CHIP_BONAIRE)
102             info->gfx_level = GFX7;
103          else
104             info->gfx_level = GFX6;
105       }
106    }
107 
108    if (info->family == CHIP_UNKNOWN) {
109       fprintf(stderr, "radv: Unknown family: %s\n", family);
110       abort();
111    }
112 
113    info->pci_id = gpu_info[info->family].pci_id;
114    info->max_se = 4;
115    info->num_se = 4;
116    if (info->gfx_level >= GFX10_3)
117       info->max_waves_per_simd = 16;
118    else if (info->gfx_level >= GFX10)
119       info->max_waves_per_simd = 20;
120    else if (info->family >= CHIP_POLARIS10 && info->family <= CHIP_VEGAM)
121       info->max_waves_per_simd = 8;
122    else
123       info->max_waves_per_simd = 10;
124 
125    if (info->gfx_level >= GFX10)
126       info->num_physical_sgprs_per_simd = 128 * info->max_waves_per_simd;
127    else if (info->gfx_level >= GFX8)
128       info->num_physical_sgprs_per_simd = 800;
129    else
130       info->num_physical_sgprs_per_simd = 512;
131 
132    info->has_3d_cube_border_color_mipmap = true;
133    info->has_image_opcodes = true;
134 
135    if (info->family == CHIP_NAVI31 || info->family == CHIP_NAVI32)
136       info->num_physical_wave64_vgprs_per_simd = 768;
137    else if (info->gfx_level >= GFX10)
138       info->num_physical_wave64_vgprs_per_simd = 512;
139    else
140       info->num_physical_wave64_vgprs_per_simd = 256;
141    info->num_simd_per_compute_unit = info->gfx_level >= GFX10 ? 2 : 4;
142    info->lds_size_per_workgroup = info->gfx_level >= GFX10  ? 128 * 1024
143                                   : info->gfx_level >= GFX7 ? 64 * 1024
144                                                             : 32 * 1024;
145    info->lds_encode_granularity = info->gfx_level >= GFX7 ? 128 * 4 : 64 * 4;
146    info->lds_alloc_granularity = info->gfx_level >= GFX10_3 ? 256 * 4 : info->lds_encode_granularity;
147    info->max_render_backends = gpu_info[info->family].num_render_backends;
148 
149    info->has_dedicated_vram = gpu_info[info->family].has_dedicated_vram;
150    info->has_packed_math_16bit = info->gfx_level >= GFX9;
151 
152    info->has_image_load_dcc_bug = info->family == CHIP_NAVI23 || info->family == CHIP_VANGOGH;
153 
154    info->has_accelerated_dot_product =
155       info->family == CHIP_VEGA20 || (info->family >= CHIP_MI100 && info->family != CHIP_NAVI10);
156 
157    info->address32_hi = info->gfx_level >= GFX9 ? 0xffff8000u : 0x0;
158 
159    info->has_rbplus = info->family == CHIP_STONEY || info->gfx_level >= GFX9;
160    info->rbplus_allowed =
161       info->has_rbplus && (info->family == CHIP_STONEY || info->family == CHIP_VEGA12 || info->family == CHIP_RAVEN ||
162                            info->family == CHIP_RAVEN2 || info->family == CHIP_RENOIR || info->gfx_level >= GFX10_3);
163 
164    info->has_scheduled_fence_dependency = true;
165    info->has_gang_submit = true;
166 }
167 
168 static const char *
radv_null_winsys_get_chip_name(struct radeon_winsys * rws)169 radv_null_winsys_get_chip_name(struct radeon_winsys *rws)
170 {
171    return "Null hardware";
172 }
173 
174 static void
radv_null_winsys_destroy(struct radeon_winsys * rws)175 radv_null_winsys_destroy(struct radeon_winsys *rws)
176 {
177    FREE(rws);
178 }
179 
180 static int
radv_null_winsys_get_fd(struct radeon_winsys * rws)181 radv_null_winsys_get_fd(struct radeon_winsys *rws)
182 {
183    return -1;
184 }
185 
186 static const struct vk_sync_type *const *
radv_null_winsys_get_sync_types(struct radeon_winsys * rws)187 radv_null_winsys_get_sync_types(struct radeon_winsys *rws)
188 {
189    return radv_null_winsys(rws)->sync_types;
190 }
191 
192 struct radeon_winsys *
radv_null_winsys_create()193 radv_null_winsys_create()
194 {
195    struct radv_null_winsys *ws;
196 
197    ws = calloc(1, sizeof(struct radv_null_winsys));
198    if (!ws)
199       return NULL;
200 
201    ws->base.destroy = radv_null_winsys_destroy;
202    ws->base.query_info = radv_null_winsys_query_info;
203    ws->base.get_fd = radv_null_winsys_get_fd;
204    ws->base.get_sync_types = radv_null_winsys_get_sync_types;
205    ws->base.get_chip_name = radv_null_winsys_get_chip_name;
206    radv_null_bo_init_functions(ws);
207    radv_null_cs_init_functions(ws);
208 
209    ws->sync_types[0] = &vk_sync_dummy_type;
210    ws->sync_types[1] = NULL;
211    return &ws->base;
212 }
213