1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef LP_TEXTURE_H 29bf215546Sopenharmony_ci#define LP_TEXTURE_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "pipe/p_state.h" 33bf215546Sopenharmony_ci#include "util/u_debug.h" 34bf215546Sopenharmony_ci#include "lp_limits.h" 35bf215546Sopenharmony_ci#ifdef DEBUG 36bf215546Sopenharmony_ci#include "util/list.h" 37bf215546Sopenharmony_ci#endif 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_cienum lp_texture_usage 41bf215546Sopenharmony_ci{ 42bf215546Sopenharmony_ci LP_TEX_USAGE_READ = 100, 43bf215546Sopenharmony_ci LP_TEX_USAGE_READ_WRITE, 44bf215546Sopenharmony_ci LP_TEX_USAGE_WRITE_ALL 45bf215546Sopenharmony_ci}; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistruct pipe_context; 49bf215546Sopenharmony_cistruct pipe_screen; 50bf215546Sopenharmony_cistruct llvmpipe_context; 51bf215546Sopenharmony_cistruct llvmpipe_screen; 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cistruct sw_displaytarget; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci/** 57bf215546Sopenharmony_ci * llvmpipe subclass of pipe_resource. A texture, drawing surface, 58bf215546Sopenharmony_ci * vertex buffer, const buffer, etc. 59bf215546Sopenharmony_ci * Textures are stored differently than other types of objects such as 60bf215546Sopenharmony_ci * vertex buffers and const buffers. 61bf215546Sopenharmony_ci * The latter are simple malloc'd blocks of memory. 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_cistruct llvmpipe_resource 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci struct pipe_resource base; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci /** an extra screen pointer to avoid crashing in driver trace */ 68bf215546Sopenharmony_ci struct llvmpipe_screen *screen; 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci /** Row stride in bytes */ 71bf215546Sopenharmony_ci unsigned row_stride[LP_MAX_TEXTURE_LEVELS]; 72bf215546Sopenharmony_ci /** Image stride (for cube maps, array or 3D textures) in bytes */ 73bf215546Sopenharmony_ci uint64_t img_stride[LP_MAX_TEXTURE_LEVELS]; 74bf215546Sopenharmony_ci /** Offset to start of mipmap level, in bytes */ 75bf215546Sopenharmony_ci uint64_t mip_offsets[LP_MAX_TEXTURE_LEVELS]; 76bf215546Sopenharmony_ci /** allocated total size (for non-display target texture resources only) */ 77bf215546Sopenharmony_ci uint64_t total_alloc_size; 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci /** 80bf215546Sopenharmony_ci * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET 81bf215546Sopenharmony_ci * usage. 82bf215546Sopenharmony_ci */ 83bf215546Sopenharmony_ci struct sw_displaytarget *dt; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci /** 86bf215546Sopenharmony_ci * Malloc'ed data for regular textures, or a mapping to dt above. 87bf215546Sopenharmony_ci */ 88bf215546Sopenharmony_ci void *tex_data; 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci /** 91bf215546Sopenharmony_ci * Data for non-texture resources. 92bf215546Sopenharmony_ci */ 93bf215546Sopenharmony_ci void *data; 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci bool user_ptr; /** Is this a user-space buffer? */ 96bf215546Sopenharmony_ci unsigned timestamp; 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci unsigned id; /**< temporary, for debugging */ 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci unsigned sample_stride; 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci uint64_t size_required; 103bf215546Sopenharmony_ci uint64_t backing_offset; 104bf215546Sopenharmony_ci bool backable; 105bf215546Sopenharmony_ci bool imported_memory; 106bf215546Sopenharmony_ci#ifdef DEBUG 107bf215546Sopenharmony_ci struct list_head list; 108bf215546Sopenharmony_ci#endif 109bf215546Sopenharmony_ci}; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_cistruct llvmpipe_transfer 113bf215546Sopenharmony_ci{ 114bf215546Sopenharmony_ci struct pipe_transfer base; 115bf215546Sopenharmony_ci}; 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_cistruct llvmpipe_memory_object 118bf215546Sopenharmony_ci{ 119bf215546Sopenharmony_ci struct pipe_memory_object b; 120bf215546Sopenharmony_ci struct pipe_memory_allocation *data; 121bf215546Sopenharmony_ci uint64_t size; 122bf215546Sopenharmony_ci}; 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci/** cast wrappers */ 126bf215546Sopenharmony_cistatic inline struct llvmpipe_resource * 127bf215546Sopenharmony_cillvmpipe_resource(struct pipe_resource *pt) 128bf215546Sopenharmony_ci{ 129bf215546Sopenharmony_ci return (struct llvmpipe_resource *) pt; 130bf215546Sopenharmony_ci} 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_cistatic inline const struct llvmpipe_resource * 134bf215546Sopenharmony_cillvmpipe_resource_const(const struct pipe_resource *pt) 135bf215546Sopenharmony_ci{ 136bf215546Sopenharmony_ci return (const struct llvmpipe_resource *) pt; 137bf215546Sopenharmony_ci} 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_cistatic inline struct llvmpipe_transfer * 141bf215546Sopenharmony_cillvmpipe_transfer(struct pipe_transfer *pt) 142bf215546Sopenharmony_ci{ 143bf215546Sopenharmony_ci return (struct llvmpipe_transfer *) pt; 144bf215546Sopenharmony_ci} 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_cistatic inline struct llvmpipe_memory_object * 147bf215546Sopenharmony_cillvmpipe_memory_object(struct pipe_memory_object *pt) 148bf215546Sopenharmony_ci{ 149bf215546Sopenharmony_ci return (struct llvmpipe_memory_object *) pt; 150bf215546Sopenharmony_ci} 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_civoid llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen); 154bf215546Sopenharmony_civoid llvmpipe_init_context_resource_funcs(struct pipe_context *pipe); 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_cistatic inline boolean 158bf215546Sopenharmony_cillvmpipe_resource_is_texture(const struct pipe_resource *resource) 159bf215546Sopenharmony_ci{ 160bf215546Sopenharmony_ci switch (resource->target) { 161bf215546Sopenharmony_ci case PIPE_BUFFER: 162bf215546Sopenharmony_ci return FALSE; 163bf215546Sopenharmony_ci case PIPE_TEXTURE_1D: 164bf215546Sopenharmony_ci case PIPE_TEXTURE_1D_ARRAY: 165bf215546Sopenharmony_ci case PIPE_TEXTURE_2D: 166bf215546Sopenharmony_ci case PIPE_TEXTURE_2D_ARRAY: 167bf215546Sopenharmony_ci case PIPE_TEXTURE_RECT: 168bf215546Sopenharmony_ci case PIPE_TEXTURE_3D: 169bf215546Sopenharmony_ci case PIPE_TEXTURE_CUBE: 170bf215546Sopenharmony_ci case PIPE_TEXTURE_CUBE_ARRAY: 171bf215546Sopenharmony_ci return TRUE; 172bf215546Sopenharmony_ci default: 173bf215546Sopenharmony_ci assert(0); 174bf215546Sopenharmony_ci return FALSE; 175bf215546Sopenharmony_ci } 176bf215546Sopenharmony_ci} 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_cistatic inline boolean 180bf215546Sopenharmony_cillvmpipe_resource_is_1d(const struct pipe_resource *resource) 181bf215546Sopenharmony_ci{ 182bf215546Sopenharmony_ci switch (resource->target) { 183bf215546Sopenharmony_ci case PIPE_BUFFER: 184bf215546Sopenharmony_ci case PIPE_TEXTURE_1D: 185bf215546Sopenharmony_ci case PIPE_TEXTURE_1D_ARRAY: 186bf215546Sopenharmony_ci return TRUE; 187bf215546Sopenharmony_ci case PIPE_TEXTURE_2D: 188bf215546Sopenharmony_ci case PIPE_TEXTURE_2D_ARRAY: 189bf215546Sopenharmony_ci case PIPE_TEXTURE_RECT: 190bf215546Sopenharmony_ci case PIPE_TEXTURE_3D: 191bf215546Sopenharmony_ci case PIPE_TEXTURE_CUBE: 192bf215546Sopenharmony_ci case PIPE_TEXTURE_CUBE_ARRAY: 193bf215546Sopenharmony_ci return FALSE; 194bf215546Sopenharmony_ci default: 195bf215546Sopenharmony_ci assert(0); 196bf215546Sopenharmony_ci return FALSE; 197bf215546Sopenharmony_ci } 198bf215546Sopenharmony_ci} 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci 201bf215546Sopenharmony_cistatic inline unsigned 202bf215546Sopenharmony_cillvmpipe_layer_stride(struct pipe_resource *resource, 203bf215546Sopenharmony_ci unsigned level) 204bf215546Sopenharmony_ci{ 205bf215546Sopenharmony_ci struct llvmpipe_resource *lpr = llvmpipe_resource(resource); 206bf215546Sopenharmony_ci assert(level < LP_MAX_TEXTURE_2D_LEVELS); 207bf215546Sopenharmony_ci return lpr->img_stride[level]; 208bf215546Sopenharmony_ci} 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_cistatic inline unsigned 212bf215546Sopenharmony_cillvmpipe_resource_stride(struct pipe_resource *resource, 213bf215546Sopenharmony_ci unsigned level) 214bf215546Sopenharmony_ci{ 215bf215546Sopenharmony_ci struct llvmpipe_resource *lpr = llvmpipe_resource(resource); 216bf215546Sopenharmony_ci assert(level < LP_MAX_TEXTURE_2D_LEVELS); 217bf215546Sopenharmony_ci return lpr->row_stride[level]; 218bf215546Sopenharmony_ci} 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_cistatic inline unsigned 221bf215546Sopenharmony_cillvmpipe_sample_stride(struct pipe_resource *resource) 222bf215546Sopenharmony_ci{ 223bf215546Sopenharmony_ci struct llvmpipe_resource *lpr = llvmpipe_resource(resource); 224bf215546Sopenharmony_ci return lpr->sample_stride; 225bf215546Sopenharmony_ci} 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_civoid * 228bf215546Sopenharmony_cillvmpipe_resource_map(struct pipe_resource *resource, 229bf215546Sopenharmony_ci unsigned level, 230bf215546Sopenharmony_ci unsigned layer, 231bf215546Sopenharmony_ci enum lp_texture_usage tex_usage); 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_civoid 234bf215546Sopenharmony_cillvmpipe_resource_unmap(struct pipe_resource *resource, 235bf215546Sopenharmony_ci unsigned level, 236bf215546Sopenharmony_ci unsigned layer); 237bf215546Sopenharmony_ci 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_civoid * 240bf215546Sopenharmony_cillvmpipe_resource_data(struct pipe_resource *resource); 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ciunsigned 244bf215546Sopenharmony_cillvmpipe_resource_size(const struct pipe_resource *resource); 245bf215546Sopenharmony_ci 246bf215546Sopenharmony_ci 247bf215546Sopenharmony_ciubyte * 248bf215546Sopenharmony_cillvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr, 249bf215546Sopenharmony_ci unsigned face_slice, unsigned level); 250bf215546Sopenharmony_ci 251bf215546Sopenharmony_ci 252bf215546Sopenharmony_ciextern void 253bf215546Sopenharmony_cillvmpipe_print_resources(void); 254bf215546Sopenharmony_ci 255bf215546Sopenharmony_ci 256bf215546Sopenharmony_ci#define LP_UNREFERENCED 0 257bf215546Sopenharmony_ci#define LP_REFERENCED_FOR_READ (1 << 0) 258bf215546Sopenharmony_ci#define LP_REFERENCED_FOR_WRITE (1 << 1) 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ciunsigned int 261bf215546Sopenharmony_cillvmpipe_is_resource_referenced( struct pipe_context *pipe, 262bf215546Sopenharmony_ci struct pipe_resource *presource, 263bf215546Sopenharmony_ci unsigned level); 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ciunsigned 266bf215546Sopenharmony_cillvmpipe_get_format_alignment(enum pipe_format format); 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_civoid * 269bf215546Sopenharmony_cillvmpipe_transfer_map_ms( struct pipe_context *pipe, 270bf215546Sopenharmony_ci struct pipe_resource *resource, 271bf215546Sopenharmony_ci unsigned level, 272bf215546Sopenharmony_ci unsigned usage, 273bf215546Sopenharmony_ci unsigned sample, 274bf215546Sopenharmony_ci const struct pipe_box *box, 275bf215546Sopenharmony_ci struct pipe_transfer **transfer ); 276bf215546Sopenharmony_ci#endif /* LP_TEXTURE_H */ 277