lp_texture.h revision 8257bb963f0b21c0c35da479707b5cacbc1c2824
1/************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#ifndef LP_TEXTURE_H 29#define LP_TEXTURE_H 30 31 32#include "pipe/p_state.h" 33#include "util/u_debug.h" 34#include "lp_limits.h" 35 36 37enum lp_texture_usage 38{ 39 LP_TEX_USAGE_READ = 100, 40 LP_TEX_USAGE_READ_WRITE, 41 LP_TEX_USAGE_WRITE_ALL 42}; 43 44 45/** Per-tile layout mode */ 46enum lp_texture_layout 47{ 48 LP_TEX_LAYOUT_NONE = 0, /**< no layout for the tile data yet */ 49 LP_TEX_LAYOUT_TILED, /**< the tile data is in tiled layout */ 50 LP_TEX_LAYOUT_LINEAR, /**< the tile data is in linear layout */ 51 LP_TEX_LAYOUT_BOTH /**< the tile data is in both modes */ 52}; 53 54 55struct pipe_context; 56struct pipe_screen; 57struct llvmpipe_context; 58 59struct sw_displaytarget; 60 61 62/** 63 * We keep one or two copies of the texture image data: one in a simple 64 * linear layout (for texture sampling) and another in a tiled layout (for 65 * render targets). We keep track of whether each image tile is linear 66 * or tiled on a per-tile basis. 67 */ 68 69 70/** A 1D/2D/3D image, one mipmap level */ 71struct llvmpipe_texture_image 72{ 73 void *data; 74}; 75 76 77/** 78 * llvmpipe subclass of pipe_resource. A texture, drawing surface, 79 * vertex buffer, const buffer, etc. 80 * Textures are stored differently than othere types of objects such as 81 * vertex buffers and const buffers. 82 * The former are tiled and have per-tile layout flags. 83 * The later are simple malloc'd blocks of memory. 84 */ 85struct llvmpipe_resource 86{ 87 struct pipe_resource base; 88 89 /** Row stride in bytes */ 90 unsigned row_stride[LP_MAX_TEXTURE_LEVELS]; 91 /** Image stride (for cube maps or 3D textures) in bytes */ 92 unsigned img_stride[LP_MAX_TEXTURE_LEVELS]; 93 unsigned tiles_per_row[LP_MAX_TEXTURE_LEVELS]; 94 unsigned tiles_per_image[LP_MAX_TEXTURE_LEVELS]; 95 /** Number of 3D slices or cube faces per level */ 96 unsigned num_slices_faces[LP_MAX_TEXTURE_LEVELS]; 97 /** Offset to start of mipmap level, in bytes */ 98 unsigned tiled_mip_offsets[LP_MAX_TEXTURE_LEVELS]; 99 unsigned linear_mip_offsets[LP_MAX_TEXTURE_LEVELS]; 100 101 /** 102 * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET 103 * usage. 104 */ 105 struct sw_displaytarget *dt; 106 107 /** 108 * Malloc'ed data for regular textures, or a mapping to dt above. 109 */ 110 struct llvmpipe_texture_image tiled_img; 111 struct llvmpipe_texture_image linear_img; 112 113 /** 114 * Data for non-texture resources. 115 */ 116 void *data; 117 118 /** array [level][face or slice][tile_y][tile_x] of layout values) */ 119 enum lp_texture_layout *layout[LP_MAX_TEXTURE_LEVELS]; 120 121 boolean userBuffer; /** Is this a user-space buffer? */ 122 unsigned timestamp; 123 124 unsigned id; /**< temporary, for debugging */ 125 126#ifdef DEBUG 127 /** for linked list */ 128 struct llvmpipe_resource *prev, *next; 129#endif 130}; 131 132 133struct llvmpipe_transfer 134{ 135 struct pipe_transfer base; 136 137 unsigned long offset; 138}; 139 140 141/** cast wrappers */ 142static INLINE struct llvmpipe_resource * 143llvmpipe_resource(struct pipe_resource *pt) 144{ 145 return (struct llvmpipe_resource *) pt; 146} 147 148 149static INLINE const struct llvmpipe_resource * 150llvmpipe_resource_const(const struct pipe_resource *pt) 151{ 152 return (const struct llvmpipe_resource *) pt; 153} 154 155 156static INLINE struct llvmpipe_transfer * 157llvmpipe_transfer(struct pipe_transfer *pt) 158{ 159 return (struct llvmpipe_transfer *) pt; 160} 161 162 163void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen); 164void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe); 165 166static INLINE unsigned 167llvmpipe_resource_stride(struct pipe_resource *resource, 168 unsigned level) 169{ 170 struct llvmpipe_resource *lpr = llvmpipe_resource(resource); 171 assert(level < LP_MAX_TEXTURE_2D_LEVELS); 172 return lpr->row_stride[level]; 173} 174 175 176void * 177llvmpipe_resource_map(struct pipe_resource *resource, 178 unsigned level, 179 unsigned layer, 180 enum lp_texture_usage tex_usage, 181 enum lp_texture_layout layout); 182 183void 184llvmpipe_resource_unmap(struct pipe_resource *resource, 185 unsigned level, 186 unsigned layer); 187 188 189void * 190llvmpipe_resource_data(struct pipe_resource *resource); 191 192 193unsigned 194llvmpipe_resource_size(const struct pipe_resource *resource); 195 196 197ubyte * 198llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr, 199 unsigned face_slice, unsigned level, 200 enum lp_texture_layout layout); 201 202void * 203llvmpipe_get_texture_image(struct llvmpipe_resource *resource, 204 unsigned face_slice, unsigned level, 205 enum lp_texture_usage usage, 206 enum lp_texture_layout layout); 207 208void * 209llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr, 210 unsigned level, 211 enum lp_texture_usage usage, 212 enum lp_texture_layout layout); 213 214ubyte * 215llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr, 216 unsigned face_slice, unsigned level, 217 enum lp_texture_usage usage, 218 unsigned x, unsigned y); 219 220ubyte * 221llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr, 222 unsigned face_slice, unsigned level, 223 enum lp_texture_usage usage, 224 unsigned x, unsigned y); 225 226 227void 228llvmpipe_unswizzle_cbuf_tile(struct llvmpipe_resource *lpr, 229 unsigned face_slice, unsigned level, 230 unsigned x, unsigned y, 231 uint8_t *tile); 232 233void 234llvmpipe_swizzle_cbuf_tile(struct llvmpipe_resource *lpr, 235 unsigned face_slice, unsigned level, 236 unsigned x, unsigned y, 237 uint8_t *tile); 238 239extern void 240llvmpipe_print_resources(void); 241 242 243extern void 244llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen); 245 246extern void 247llvmpipe_init_context_texture_funcs(struct pipe_context *pipe); 248 249 250#define LP_UNREFERENCED 0 251#define LP_REFERENCED_FOR_READ (1 << 0) 252#define LP_REFERENCED_FOR_WRITE (1 << 1) 253 254unsigned int 255llvmpipe_is_resource_referenced( struct pipe_context *pipe, 256 struct pipe_resource *presource, 257 unsigned level, int layer); 258 259#endif /* LP_TEXTURE_H */ 260