radv: use ac_compute_surface
[mesa.git] / src / amd / vulkan / winsys / amdgpu / radv_amdgpu_surface.c
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * based on amdgpu winsys.
6 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
7 * Copyright © 2015 Advanced Micro Devices, Inc.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 * IN THE SOFTWARE.
27 */
28
29 #include <errno.h>
30
31 #include "radv_private.h"
32 #include "addrlib/addrinterface.h"
33 #include "util/bitset.h"
34 #include "radv_amdgpu_winsys.h"
35 #include "radv_amdgpu_surface.h"
36 #include "sid.h"
37
38 #include "ac_surface.h"
39
40 static int radv_amdgpu_surface_sanity(const struct ac_surf_info *surf_info,
41 const struct radeon_surf *surf)
42 {
43 unsigned type = RADEON_SURF_GET(surf->flags, TYPE);
44
45 if (!(surf->flags & RADEON_SURF_HAS_TILE_MODE_INDEX))
46 return -EINVAL;
47
48 if (!surf->blk_w || !surf->blk_h)
49 return -EINVAL;
50
51 switch (type) {
52 case RADEON_SURF_TYPE_1D:
53 if (surf_info->height > 1)
54 return -EINVAL;
55 /* fall through */
56 case RADEON_SURF_TYPE_2D:
57 case RADEON_SURF_TYPE_CUBEMAP:
58 if (surf_info->depth > 1 || surf_info->array_size > 1)
59 return -EINVAL;
60 break;
61 case RADEON_SURF_TYPE_3D:
62 if (surf_info->array_size > 1)
63 return -EINVAL;
64 break;
65 case RADEON_SURF_TYPE_1D_ARRAY:
66 if (surf_info->height > 1)
67 return -EINVAL;
68 /* fall through */
69 case RADEON_SURF_TYPE_2D_ARRAY:
70 if (surf_info->depth > 1)
71 return -EINVAL;
72 break;
73 default:
74 return -EINVAL;
75 }
76 return 0;
77 }
78
79 static int radv_amdgpu_winsys_surface_init(struct radeon_winsys *_ws,
80 const struct ac_surf_info *surf_info,
81 struct radeon_surf *surf)
82 {
83 struct radv_amdgpu_winsys *ws = radv_amdgpu_winsys(_ws);
84 unsigned mode, type;
85 int r;
86
87 r = radv_amdgpu_surface_sanity(surf_info, surf);
88 if (r)
89 return r;
90
91 type = RADEON_SURF_GET(surf->flags, TYPE);
92 mode = RADEON_SURF_GET(surf->flags, MODE);
93
94 struct ac_surf_config config;
95
96 memcpy(&config.info, surf_info, sizeof(config.info));
97 config.is_3d = !!(type == RADEON_SURF_TYPE_3D);
98 config.is_cube = !!(type == RADEON_SURF_TYPE_CUBEMAP);
99
100 return ac_compute_surface(ws->addrlib, &ws->info, &config, mode, surf);
101 }
102
103 static int radv_amdgpu_winsys_surface_best(struct radeon_winsys *rws,
104 struct radeon_surf *surf)
105 {
106 return 0;
107 }
108
109 void radv_amdgpu_surface_init_functions(struct radv_amdgpu_winsys *ws)
110 {
111 ws->base.surface_init = radv_amdgpu_winsys_surface_init;
112 ws->base.surface_best = radv_amdgpu_winsys_surface_best;
113 }