faba6f2102540dd00566748311b6086fa0f718f2
[mesa.git] / src / gallium / drivers / llvmpipe / lp_texture.h
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
37 enum 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 struct pipe_context;
46 struct pipe_screen;
47 struct llvmpipe_context;
48
49 struct sw_displaytarget;
50
51
52 /** A 1D/2D/3D image, one mipmap level */
53 struct llvmpipe_texture_image
54 {
55 void *data;
56 };
57
58
59 /**
60 * llvmpipe subclass of pipe_resource. A texture, drawing surface,
61 * vertex buffer, const buffer, etc.
62 * Textures are stored differently than other types of objects such as
63 * vertex buffers and const buffers.
64 * The latter are simple malloc'd blocks of memory.
65 */
66 struct llvmpipe_resource
67 {
68 struct pipe_resource base;
69
70 /** Row stride in bytes */
71 unsigned row_stride[LP_MAX_TEXTURE_LEVELS];
72 /** Image stride (for cube maps, array or 3D textures) in bytes */
73 unsigned img_stride[LP_MAX_TEXTURE_LEVELS];
74 /** Number of 3D slices or cube faces per level */
75 unsigned num_slices_faces[LP_MAX_TEXTURE_LEVELS];
76 /** Offset to start of mipmap level, in bytes */
77 unsigned linear_mip_offsets[LP_MAX_TEXTURE_LEVELS];
78
79 /**
80 * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
81 * usage.
82 */
83 struct sw_displaytarget *dt;
84
85 /**
86 * Malloc'ed data for regular textures, or a mapping to dt above.
87 */
88 struct llvmpipe_texture_image linear_img;
89
90 /**
91 * Data for non-texture resources.
92 */
93 void *data;
94
95 boolean userBuffer; /** Is this a user-space buffer? */
96 unsigned timestamp;
97
98 unsigned id; /**< temporary, for debugging */
99
100 #ifdef DEBUG
101 /** for linked list */
102 struct llvmpipe_resource *prev, *next;
103 #endif
104 };
105
106
107 struct llvmpipe_transfer
108 {
109 struct pipe_transfer base;
110
111 unsigned long offset;
112 };
113
114
115 /** cast wrappers */
116 static INLINE struct llvmpipe_resource *
117 llvmpipe_resource(struct pipe_resource *pt)
118 {
119 return (struct llvmpipe_resource *) pt;
120 }
121
122
123 static INLINE const struct llvmpipe_resource *
124 llvmpipe_resource_const(const struct pipe_resource *pt)
125 {
126 return (const struct llvmpipe_resource *) pt;
127 }
128
129
130 static INLINE struct llvmpipe_transfer *
131 llvmpipe_transfer(struct pipe_transfer *pt)
132 {
133 return (struct llvmpipe_transfer *) pt;
134 }
135
136
137 void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
138 void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
139
140
141 static INLINE boolean
142 llvmpipe_resource_is_texture(const struct pipe_resource *resource)
143 {
144 switch (resource->target) {
145 case PIPE_BUFFER:
146 return FALSE;
147 case PIPE_TEXTURE_1D:
148 case PIPE_TEXTURE_1D_ARRAY:
149 case PIPE_TEXTURE_2D:
150 case PIPE_TEXTURE_2D_ARRAY:
151 case PIPE_TEXTURE_RECT:
152 case PIPE_TEXTURE_3D:
153 case PIPE_TEXTURE_CUBE:
154 return TRUE;
155 default:
156 assert(0);
157 return FALSE;
158 }
159 }
160
161
162 static INLINE unsigned
163 llvmpipe_resource_stride(struct pipe_resource *resource,
164 unsigned level)
165 {
166 struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
167 assert(level < LP_MAX_TEXTURE_2D_LEVELS);
168 return lpr->row_stride[level];
169 }
170
171
172 void *
173 llvmpipe_resource_map(struct pipe_resource *resource,
174 unsigned level,
175 unsigned layer,
176 enum lp_texture_usage tex_usage);
177
178 void
179 llvmpipe_resource_unmap(struct pipe_resource *resource,
180 unsigned level,
181 unsigned layer);
182
183
184 void *
185 llvmpipe_resource_data(struct pipe_resource *resource);
186
187
188 unsigned
189 llvmpipe_resource_size(const struct pipe_resource *resource);
190
191
192 ubyte *
193 llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
194 unsigned face_slice, unsigned level);
195
196 void *
197 llvmpipe_get_texture_image(struct llvmpipe_resource *resource,
198 unsigned face_slice, unsigned level,
199 enum lp_texture_usage usage);
200
201 void *
202 llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr,
203 unsigned level,
204 enum lp_texture_usage usage);
205
206 ubyte *
207 llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
208 unsigned face_slice, unsigned level,
209 enum lp_texture_usage usage,
210 unsigned x, unsigned y);
211
212
213 extern void
214 llvmpipe_print_resources(void);
215
216
217 #define LP_UNREFERENCED 0
218 #define LP_REFERENCED_FOR_READ (1 << 0)
219 #define LP_REFERENCED_FOR_WRITE (1 << 1)
220
221 unsigned int
222 llvmpipe_is_resource_referenced( struct pipe_context *pipe,
223 struct pipe_resource *presource,
224 unsigned level);
225
226 unsigned
227 llvmpipe_get_format_alignment(enum pipe_format format);
228
229 #endif /* LP_TEXTURE_H */