19f464c52Smaya/* 29f464c52Smaya * © Copyright2018-2019 Alyssa Rosenzweig 39f464c52Smaya * 49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a 59f464c52Smaya * copy of this software and associated documentation files (the "Software"), 69f464c52Smaya * to deal in the Software without restriction, including without limitation 79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sublicense, 89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the 99f464c52Smaya * Software is furnished to do so, subject to the following conditions: 109f464c52Smaya * 119f464c52Smaya * The above copyright notice and this permission notice (including the next 129f464c52Smaya * paragraph) shall be included in all copies or substantial portions of the 139f464c52Smaya * Software. 149f464c52Smaya * 159f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 169f464c52Smaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 179f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 189f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 199f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 209f464c52Smaya * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 219f464c52Smaya * SOFTWARE. 229f464c52Smaya * 239f464c52Smaya */ 249f464c52Smaya 259f464c52Smaya 269f464c52Smaya#ifndef PAN_RESOURCE_H 279f464c52Smaya#define PAN_RESOURCE_H 289f464c52Smaya 299f464c52Smaya#include "pan_screen.h" 307ec681f3Smrg#include "pan_minmax_cache.h" 317ec681f3Smrg#include "pan_texture.h" 329f464c52Smaya#include "drm-uapi/drm.h" 339f464c52Smaya#include "util/u_range.h" 349f464c52Smaya 357ec681f3Smrg#define LAYOUT_CONVERT_THRESHOLD 8 367ec681f3Smrg#define PAN_MAX_BATCHES 32 379f464c52Smaya 387ec681f3Smrgstruct panfrost_resource { 397ec681f3Smrg struct pipe_resource base; 407ec681f3Smrg struct { 417ec681f3Smrg struct pipe_scissor_state extent; 427ec681f3Smrg struct { 437ec681f3Smrg bool enable; 447ec681f3Smrg unsigned stride; 457ec681f3Smrg unsigned size; 467ec681f3Smrg BITSET_WORD *data; 477ec681f3Smrg } tile_map; 487ec681f3Smrg } damage; 497ec681f3Smrg 507ec681f3Smrg struct { 517ec681f3Smrg /** Number of batches accessing this resource. Used to check if 527ec681f3Smrg * a resource is in use. */ 537ec681f3Smrg _Atomic unsigned nr_users; 547ec681f3Smrg 557ec681f3Smrg /** Number of batches writing this resource. Note that only one 567ec681f3Smrg * batch per context may write a resource, so this is the 577ec681f3Smrg * number of contexts that have an active writer. */ 587ec681f3Smrg _Atomic unsigned nr_writers; 597ec681f3Smrg } track; 609f464c52Smaya 617ec681f3Smrg struct renderonly_scanout *scanout; 629f464c52Smaya 637ec681f3Smrg struct panfrost_resource *separate_stencil; 649f464c52Smaya 657ec681f3Smrg struct util_range valid_buffer_range; 669f464c52Smaya 677ec681f3Smrg /* Description of the resource layout */ 687ec681f3Smrg struct pan_image image; 699f464c52Smaya 707ec681f3Smrg struct { 717ec681f3Smrg /* Is the checksum for this image valid? Implicitly refers to 727ec681f3Smrg * the first slice; we only checksum non-mipmapped 2D images */ 737ec681f3Smrg bool crc; 749f464c52Smaya 757ec681f3Smrg /* Has anything been written to this slice? */ 767ec681f3Smrg BITSET_DECLARE(data, MAX_MIP_LEVELS); 777ec681f3Smrg } valid; 789f464c52Smaya 797ec681f3Smrg /* Whether the modifier can be changed */ 807ec681f3Smrg bool modifier_constant; 819f464c52Smaya 827ec681f3Smrg /* Used to decide when to convert to another modifier */ 837ec681f3Smrg uint16_t modifier_updates; 849f464c52Smaya 857ec681f3Smrg /* Cached min/max values for index buffers */ 867ec681f3Smrg struct panfrost_minmax_cache *index_cache; 879f464c52Smaya}; 889f464c52Smaya 899f464c52Smayastatic inline struct panfrost_resource * 909f464c52Smayapan_resource(struct pipe_resource *p) 919f464c52Smaya{ 927ec681f3Smrg return (struct panfrost_resource *)p; 939f464c52Smaya} 949f464c52Smaya 957ec681f3Smrgstruct panfrost_transfer { 969f464c52Smaya struct pipe_transfer base; 979f464c52Smaya void *map; 987ec681f3Smrg struct { 997ec681f3Smrg struct pipe_resource *rsrc; 1007ec681f3Smrg struct pipe_box box; 1017ec681f3Smrg } staging; 1029f464c52Smaya}; 1039f464c52Smaya 1047ec681f3Smrgstatic inline struct panfrost_transfer * 1059f464c52Smayapan_transfer(struct pipe_transfer *p) 1069f464c52Smaya{ 1077ec681f3Smrg return (struct panfrost_transfer *)p; 1089f464c52Smaya} 1099f464c52Smaya 1107ec681f3Smrgvoid panfrost_resource_screen_init(struct pipe_screen *screen); 1117ec681f3Smrg 1127ec681f3Smrgvoid panfrost_resource_screen_destroy(struct pipe_screen *screen); 1139f464c52Smaya 1149f464c52Smayavoid panfrost_resource_context_init(struct pipe_context *pctx); 1159f464c52Smaya 1167ec681f3Smrg/* Blitting */ 1177ec681f3Smrg 1187ec681f3Smrgvoid 1197ec681f3Smrgpanfrost_blit(struct pipe_context *pipe, 1207ec681f3Smrg const struct pipe_blit_info *info); 1217ec681f3Smrg 1227ec681f3Smrgvoid 1237ec681f3Smrgpanfrost_resource_set_damage_region(struct pipe_screen *screen, 1247ec681f3Smrg struct pipe_resource *res, 1257ec681f3Smrg unsigned int nrects, 1267ec681f3Smrg const struct pipe_box *rects); 1277ec681f3Smrg 1287ec681f3Smrgstatic inline enum mali_texture_dimension 1297ec681f3Smrgpanfrost_translate_texture_dimension(enum pipe_texture_target t) { 1307ec681f3Smrg switch (t) 1317ec681f3Smrg { 1327ec681f3Smrg case PIPE_BUFFER: 1337ec681f3Smrg case PIPE_TEXTURE_1D: 1347ec681f3Smrg case PIPE_TEXTURE_1D_ARRAY: 1357ec681f3Smrg return MALI_TEXTURE_DIMENSION_1D; 1367ec681f3Smrg 1377ec681f3Smrg case PIPE_TEXTURE_2D: 1387ec681f3Smrg case PIPE_TEXTURE_2D_ARRAY: 1397ec681f3Smrg case PIPE_TEXTURE_RECT: 1407ec681f3Smrg return MALI_TEXTURE_DIMENSION_2D; 1417ec681f3Smrg 1427ec681f3Smrg case PIPE_TEXTURE_3D: 1437ec681f3Smrg return MALI_TEXTURE_DIMENSION_3D; 1447ec681f3Smrg 1457ec681f3Smrg case PIPE_TEXTURE_CUBE: 1467ec681f3Smrg case PIPE_TEXTURE_CUBE_ARRAY: 1477ec681f3Smrg return MALI_TEXTURE_DIMENSION_CUBE; 1487ec681f3Smrg 1497ec681f3Smrg default: 1507ec681f3Smrg unreachable("Unknown target"); 1517ec681f3Smrg } 1527ec681f3Smrg} 1537ec681f3Smrg 1547ec681f3Smrgvoid 1557ec681f3Smrgpan_resource_modifier_convert(struct panfrost_context *ctx, 1567ec681f3Smrg struct panfrost_resource *rsrc, 1577ec681f3Smrg uint64_t modifier, const char *reason); 1587ec681f3Smrg 1597ec681f3Smrgvoid 1607ec681f3Smrgpan_legalize_afbc_format(struct panfrost_context *ctx, 1617ec681f3Smrg struct panfrost_resource *rsrc, 1627ec681f3Smrg enum pipe_format format); 1637ec681f3Smrg 1649f464c52Smaya#endif /* PAN_RESOURCE_H */ 165