1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include "pipe/p_state.h"
33 #include "util/u_debug.h"
34 #include "lp_limits.h"
39 LP_TEX_USAGE_READ
= 100,
40 LP_TEX_USAGE_READ_WRITE
,
41 LP_TEX_USAGE_WRITE_ALL
45 /** Per-tile layout mode */
46 enum lp_texture_layout
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 */
57 struct llvmpipe_context
;
59 struct sw_displaytarget
;
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.
70 /** A 1D/2D/3D image, one mipmap level */
71 struct llvmpipe_texture_image
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.
85 struct llvmpipe_resource
87 struct pipe_resource base
;
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
];
99 * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
102 struct sw_displaytarget
*dt
;
105 * Malloc'ed data for regular textures, or a mapping to dt above.
107 struct llvmpipe_texture_image tiled
[LP_MAX_TEXTURE_LEVELS
];
108 struct llvmpipe_texture_image linear
[LP_MAX_TEXTURE_LEVELS
];
111 * Data for non-texture resources.
115 /** array [level][face or slice][tile_y][tile_x] of layout values) */
116 enum lp_texture_layout
*layout
[LP_MAX_TEXTURE_LEVELS
];
118 boolean userBuffer
; /** Is this a user-space buffer? */
121 unsigned id
; /**< temporary, for debugging */
124 /** for linked list */
125 struct llvmpipe_resource
*prev
, *next
;
130 struct llvmpipe_transfer
132 struct pipe_transfer base
;
134 unsigned long offset
;
139 static INLINE
struct llvmpipe_resource
*
140 llvmpipe_resource(struct pipe_resource
*pt
)
142 return (struct llvmpipe_resource
*) pt
;
146 static INLINE
const struct llvmpipe_resource
*
147 llvmpipe_resource_const(const struct pipe_resource
*pt
)
149 return (const struct llvmpipe_resource
*) pt
;
153 static INLINE
struct llvmpipe_transfer
*
154 llvmpipe_transfer(struct pipe_transfer
*pt
)
156 return (struct llvmpipe_transfer
*) pt
;
160 void llvmpipe_init_screen_resource_funcs(struct pipe_screen
*screen
);
161 void llvmpipe_init_context_resource_funcs(struct pipe_context
*pipe
);
163 static INLINE
unsigned
164 llvmpipe_resource_stride(struct pipe_resource
*resource
,
167 struct llvmpipe_resource
*lpr
= llvmpipe_resource(resource
);
168 assert(level
< LP_MAX_TEXTURE_2D_LEVELS
);
169 return lpr
->row_stride
[level
];
174 llvmpipe_resource_map(struct pipe_resource
*resource
,
177 enum lp_texture_usage tex_usage
,
178 enum lp_texture_layout layout
);
181 llvmpipe_resource_unmap(struct pipe_resource
*resource
,
187 llvmpipe_resource_data(struct pipe_resource
*resource
);
191 llvmpipe_resource_size(const struct pipe_resource
*resource
);
195 llvmpipe_get_texture_image_address(struct llvmpipe_resource
*lpr
,
196 unsigned face_slice
, unsigned level
,
197 enum lp_texture_layout layout
);
200 llvmpipe_get_texture_image(struct llvmpipe_resource
*resource
,
201 unsigned face_slice
, unsigned level
,
202 enum lp_texture_usage usage
,
203 enum lp_texture_layout layout
);
206 llvmpipe_get_texture_image_all(struct llvmpipe_resource
*lpr
,
208 enum lp_texture_usage usage
,
209 enum lp_texture_layout layout
);
212 llvmpipe_get_texture_tile_linear(struct llvmpipe_resource
*lpr
,
213 unsigned face_slice
, unsigned level
,
214 enum lp_texture_usage usage
,
215 unsigned x
, unsigned y
);
218 llvmpipe_get_texture_tile(struct llvmpipe_resource
*lpr
,
219 unsigned face_slice
, unsigned level
,
220 enum lp_texture_usage usage
,
221 unsigned x
, unsigned y
);
225 llvmpipe_unswizzle_cbuf_tile(struct llvmpipe_resource
*lpr
,
226 unsigned face_slice
, unsigned level
,
227 unsigned x
, unsigned y
,
231 llvmpipe_swizzle_cbuf_tile(struct llvmpipe_resource
*lpr
,
232 unsigned face_slice
, unsigned level
,
233 unsigned x
, unsigned y
,
237 llvmpipe_print_resources(void);
241 llvmpipe_init_screen_texture_funcs(struct pipe_screen
*screen
);
244 llvmpipe_init_context_texture_funcs(struct pipe_context
*pipe
);
247 #define LP_UNREFERENCED 0
248 #define LP_REFERENCED_FOR_READ (1 << 0)
249 #define LP_REFERENCED_FOR_WRITE (1 << 1)
252 llvmpipe_is_resource_referenced( struct pipe_context
*pipe
,
253 struct pipe_resource
*presource
,
254 unsigned level
, int layer
);
256 #endif /* LP_TEXTURE_H */