2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based on amdgpu winsys.
6 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
7 * Copyright © 2015 Advanced Micro Devices, Inc.
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:
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
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
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"
38 #include "ac_surface.h"
40 static int radv_amdgpu_surface_sanity(const struct ac_surf_info
*surf_info
,
41 const struct radeon_surf
*surf
)
43 unsigned type
= RADEON_SURF_GET(surf
->flags
, TYPE
);
45 if (!surf
->blk_w
|| !surf
->blk_h
)
49 case RADEON_SURF_TYPE_1D
:
50 if (surf_info
->height
> 1)
53 case RADEON_SURF_TYPE_2D
:
54 case RADEON_SURF_TYPE_CUBEMAP
:
55 if (surf_info
->depth
> 1 || surf_info
->array_size
> 1)
58 case RADEON_SURF_TYPE_3D
:
59 if (surf_info
->array_size
> 1)
62 case RADEON_SURF_TYPE_1D_ARRAY
:
63 if (surf_info
->height
> 1)
66 case RADEON_SURF_TYPE_2D_ARRAY
:
67 if (surf_info
->depth
> 1)
76 static int radv_amdgpu_winsys_surface_init(struct radeon_winsys
*_ws
,
77 const struct ac_surf_info
*surf_info
,
78 struct radeon_surf
*surf
)
80 struct radv_amdgpu_winsys
*ws
= radv_amdgpu_winsys(_ws
);
84 r
= radv_amdgpu_surface_sanity(surf_info
, surf
);
88 type
= RADEON_SURF_GET(surf
->flags
, TYPE
);
89 mode
= RADEON_SURF_GET(surf
->flags
, MODE
);
91 struct ac_surf_config config
;
93 memcpy(&config
.info
, surf_info
, sizeof(config
.info
));
94 config
.is_3d
= !!(type
== RADEON_SURF_TYPE_3D
);
95 config
.is_cube
= !!(type
== RADEON_SURF_TYPE_CUBEMAP
);
97 return ac_compute_surface(ws
->addrlib
, &ws
->info
, &config
, mode
, surf
);
100 void radv_amdgpu_surface_init_functions(struct radv_amdgpu_winsys
*ws
)
102 ws
->base
.surface_init
= radv_amdgpu_winsys_surface_init
;