Path: blob/21.2-virgl/src/gallium/winsys/amdgpu/drm/amdgpu_surface.c
4561 views
/*1* Copyright © 2011 Red Hat All Rights Reserved.2* Copyright © 2014 Advanced Micro Devices, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,14* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES15* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND16* NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS17* AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,19* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*22* The above copyright notice and this permission notice (including the23* next paragraph) shall be included in all copies or substantial portions24* of the Software.25*/2627#include "amdgpu_winsys.h"28#include "util/format/u_format.h"2930static int amdgpu_surface_sanity(const struct pipe_resource *tex)31{32switch (tex->target) {33case PIPE_TEXTURE_1D:34if (tex->height0 > 1)35return -EINVAL;36FALLTHROUGH;37case PIPE_TEXTURE_2D:38case PIPE_TEXTURE_RECT:39if (tex->depth0 > 1 || tex->array_size > 1)40return -EINVAL;41break;42case PIPE_TEXTURE_3D:43if (tex->array_size > 1)44return -EINVAL;45break;46case PIPE_TEXTURE_1D_ARRAY:47if (tex->height0 > 1)48return -EINVAL;49FALLTHROUGH;50case PIPE_TEXTURE_CUBE:51case PIPE_TEXTURE_2D_ARRAY:52case PIPE_TEXTURE_CUBE_ARRAY:53if (tex->depth0 > 1)54return -EINVAL;55break;56default:57return -EINVAL;58}59return 0;60}6162static int amdgpu_surface_init(struct radeon_winsys *rws,63const struct pipe_resource *tex,64unsigned flags, unsigned bpe,65enum radeon_surf_mode mode,66struct radeon_surf *surf)67{68struct amdgpu_winsys *ws = amdgpu_winsys(rws);69int r;7071r = amdgpu_surface_sanity(tex);72if (r)73return r;7475surf->blk_w = util_format_get_blockwidth(tex->format);76surf->blk_h = util_format_get_blockheight(tex->format);77surf->bpe = bpe;78surf->flags = flags;7980struct ac_surf_config config;8182config.info.width = tex->width0;83config.info.height = tex->height0;84config.info.depth = tex->depth0;85config.info.array_size = tex->array_size;86config.info.samples = tex->nr_samples;87config.info.storage_samples = tex->nr_storage_samples;88config.info.levels = tex->last_level + 1;89config.info.num_channels = util_format_get_nr_components(tex->format);90config.is_1d = tex->target == PIPE_TEXTURE_1D ||91tex->target == PIPE_TEXTURE_1D_ARRAY;92config.is_3d = tex->target == PIPE_TEXTURE_3D;93config.is_cube = tex->target == PIPE_TEXTURE_CUBE;9495/* Use different surface counters for color and FMASK, so that MSAA MRTs96* always use consecutive surface indices when FMASK is allocated between97* them.98*/99config.info.surf_index = &ws->surf_index_color;100config.info.fmask_surf_index = &ws->surf_index_fmask;101102if (flags & RADEON_SURF_Z_OR_SBUFFER)103config.info.surf_index = NULL;104105return ac_compute_surface(ws->addrlib, &ws->info, &config, mode, surf);106}107108void amdgpu_surface_init_functions(struct amdgpu_screen_winsys *ws)109{110ws->base.surface_init = amdgpu_surface_init;111}112113114