1 /* 2 * Copyright (c) 2012-2015 Etnaviv Project 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sub license, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the 12 * next paragraph) shall be included in all copies or substantial portions 13 * of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Wladimir J. van der Laan <laanwj (at) gmail.com> 25 */ 26 27 #ifndef H_ETNAVIV_RESOURCE 28 #define H_ETNAVIV_RESOURCE 29 30 #include "etnaviv_internal.h" 31 #include "etnaviv_tiling.h" 32 #include "pipe/p_state.h" 33 #include "util/list.h" 34 35 struct pipe_screen; 36 37 struct etna_resource_level { 38 unsigned width, padded_width; /* in pixels */ 39 unsigned height, padded_height; /* in samples */ 40 unsigned offset; /* offset into memory area */ 41 uint32_t stride; /* row stride */ 42 uint32_t layer_stride; /* layer stride */ 43 unsigned size; /* total size of memory area */ 44 45 uint32_t ts_offset; 46 uint32_t ts_layer_stride; 47 uint32_t ts_size; 48 uint32_t clear_value; /* clear value of resource level (mainly for TS) */ 49 }; 50 51 /* status of queued up but not flushed reads and write operations. 52 * In _transfer_map() we need to know if queued up rendering needs 53 * to be flushed to preserve the order of cpu and gpu access. */ 54 enum etna_resource_status { 55 ETNA_PENDING_WRITE = 0x01, 56 ETNA_PENDING_READ = 0x02, 57 }; 58 59 struct etna_resource { 60 struct pipe_resource base; 61 struct renderonly_scanout *scanout; 62 uint32_t seqno; 63 64 /* only lod 0 used for non-texture buffers */ 65 /* Layout for surface (tiled, multitiled, split tiled, ...) */ 66 enum etna_surface_layout layout; 67 /* Horizontal alignment for texture unit (TEXTURE_HALIGN_*) */ 68 unsigned halign; 69 struct etna_bo *bo; /* Surface video memory */ 70 struct etna_bo *ts_bo; /* Tile status video memory */ 71 72 struct etna_resource_level levels[ETNA_NUM_LOD]; 73 74 /* When we are rendering to a texture, we need a differently tiled resource */ 75 struct pipe_resource *texture; 76 77 enum etna_resource_status status; 78 79 /* resources accessed by queued but not flushed draws are tracked 80 * in the used_resources list. */ 81 struct list_head list; 82 struct etna_context *pending_ctx; 83 }; 84 85 /* returns TRUE if a is newer than b */ 86 static inline bool 87 etna_resource_newer(struct etna_resource *a, struct etna_resource *b) 88 { 89 return (int)(a->seqno - b->seqno) > 0; 90 } 91 92 /* returns TRUE if a is older than b */ 93 static inline bool 94 etna_resource_older(struct etna_resource *a, struct etna_resource *b) 95 { 96 return (int)(a->seqno - b->seqno) < 0; 97 } 98 99 /* is the resource only used on the sampler? */ 100 static inline bool 101 etna_resource_sampler_only(const struct pipe_resource *pres) 102 { 103 return (pres->bind & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET | 104 PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_BLENDABLE)) == 105 PIPE_BIND_SAMPLER_VIEW; 106 } 107 108 static inline struct etna_resource * 109 etna_resource(struct pipe_resource *p) 110 { 111 return (struct etna_resource *)p; 112 } 113 114 void 115 etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, 116 enum etna_resource_status status); 117 118 void 119 etna_resource_wait(struct pipe_context *ctx, struct etna_resource *rsc); 120 121 static inline void 122 resource_read(struct etna_context *ctx, struct pipe_resource *prsc) 123 { 124 etna_resource_used(ctx, prsc, ETNA_PENDING_READ); 125 } 126 127 static inline void 128 resource_written(struct etna_context *ctx, struct pipe_resource *prsc) 129 { 130 etna_resource_used(ctx, prsc, ETNA_PENDING_WRITE); 131 } 132 133 /* Allocate Tile Status for an etna resource. 134 * Tile status is a cache of the clear status per tile. This means a smaller 135 * surface has to be cleared which is faster. 136 * This is also called "fast clear". */ 137 bool 138 etna_screen_resource_alloc_ts(struct pipe_screen *pscreen, 139 struct etna_resource *prsc); 140 141 struct pipe_resource * 142 etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, 143 const struct pipe_resource *templat); 144 145 void 146 etna_resource_screen_init(struct pipe_screen *pscreen); 147 148 #endif 149