Home | History | Annotate | Download | only in amdgpu
      1 /*
      2  * Copyright  2016 Red Hat.
      3  * Copyright  2016 Bas Nieuwenhuizen
      4  *
      5  * based on amdgpu winsys.
      6  * Copyright  2011 Marek Olk <maraeo (at) 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->blk_w || !surf->blk_h)
     46 		return -EINVAL;
     47 
     48 	switch (type) {
     49 	case RADEON_SURF_TYPE_1D:
     50 		if (surf_info->height > 1)
     51 			return -EINVAL;
     52 		/* fall through */
     53 	case RADEON_SURF_TYPE_2D:
     54 	case RADEON_SURF_TYPE_CUBEMAP:
     55 		if (surf_info->depth > 1 || surf_info->array_size > 1)
     56 			return -EINVAL;
     57 		break;
     58 	case RADEON_SURF_TYPE_3D:
     59 		if (surf_info->array_size > 1)
     60 			return -EINVAL;
     61 		break;
     62 	case RADEON_SURF_TYPE_1D_ARRAY:
     63 		if (surf_info->height > 1)
     64 			return -EINVAL;
     65 		/* fall through */
     66 	case RADEON_SURF_TYPE_2D_ARRAY:
     67 		if (surf_info->depth > 1)
     68 			return -EINVAL;
     69 		break;
     70 	default:
     71 		return -EINVAL;
     72 	}
     73 	return 0;
     74 }
     75 
     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)
     79 {
     80 	struct radv_amdgpu_winsys *ws = radv_amdgpu_winsys(_ws);
     81 	unsigned mode, type;
     82 	int r;
     83 
     84 	r = radv_amdgpu_surface_sanity(surf_info, surf);
     85 	if (r)
     86 		return r;
     87 
     88 	type = RADEON_SURF_GET(surf->flags, TYPE);
     89 	mode = RADEON_SURF_GET(surf->flags, MODE);
     90 
     91 	struct ac_surf_config config;
     92 
     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);
     96 
     97 	return ac_compute_surface(ws->addrlib, &ws->info, &config, mode, surf);
     98 }
     99 
    100 static int radv_amdgpu_winsys_surface_best(struct radeon_winsys *rws,
    101 					   struct radeon_surf *surf)
    102 {
    103 	return 0;
    104 }
    105 
    106 void radv_amdgpu_surface_init_functions(struct radv_amdgpu_winsys *ws)
    107 {
    108 	ws->base.surface_init = radv_amdgpu_winsys_surface_init;
    109 	ws->base.surface_best = radv_amdgpu_winsys_surface_best;
    110 }
    111