1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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
47 struct llvmpipe_context
;
49 struct sw_displaytarget
;
53 * llvmpipe subclass of pipe_resource. A texture, drawing surface,
54 * vertex buffer, const buffer, etc.
55 * Textures are stored differently than other types of objects such as
56 * vertex buffers and const buffers.
57 * The latter are simple malloc'd blocks of memory.
59 struct llvmpipe_resource
61 struct pipe_resource base
;
63 /** Row stride in bytes */
64 unsigned row_stride
[LP_MAX_TEXTURE_LEVELS
];
65 /** Image stride (for cube maps, array or 3D textures) in bytes */
66 unsigned img_stride
[LP_MAX_TEXTURE_LEVELS
];
67 /** Offset to start of mipmap level, in bytes */
68 unsigned mip_offsets
[LP_MAX_TEXTURE_LEVELS
];
69 /** allocated total size (for non-display target texture resources only) */
70 unsigned total_alloc_size
;
73 * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
76 struct sw_displaytarget
*dt
;
79 * Malloc'ed data for regular textures, or a mapping to dt above.
84 * Data for non-texture resources.
88 boolean userBuffer
; /** Is this a user-space buffer? */
91 unsigned id
; /**< temporary, for debugging */
93 unsigned sample_stride
;
95 uint64_t size_required
;
96 uint64_t backing_offset
;
99 /** for linked list */
100 struct llvmpipe_resource
*prev
, *next
;
105 struct llvmpipe_transfer
107 struct pipe_transfer base
;
109 unsigned long offset
;
114 static inline struct llvmpipe_resource
*
115 llvmpipe_resource(struct pipe_resource
*pt
)
117 return (struct llvmpipe_resource
*) pt
;
121 static inline const struct llvmpipe_resource
*
122 llvmpipe_resource_const(const struct pipe_resource
*pt
)
124 return (const struct llvmpipe_resource
*) pt
;
128 static inline struct llvmpipe_transfer
*
129 llvmpipe_transfer(struct pipe_transfer
*pt
)
131 return (struct llvmpipe_transfer
*) pt
;
135 void llvmpipe_init_screen_resource_funcs(struct pipe_screen
*screen
);
136 void llvmpipe_init_context_resource_funcs(struct pipe_context
*pipe
);
139 static inline boolean
140 llvmpipe_resource_is_texture(const struct pipe_resource
*resource
)
142 switch (resource
->target
) {
145 case PIPE_TEXTURE_1D
:
146 case PIPE_TEXTURE_1D_ARRAY
:
147 case PIPE_TEXTURE_2D
:
148 case PIPE_TEXTURE_2D_ARRAY
:
149 case PIPE_TEXTURE_RECT
:
150 case PIPE_TEXTURE_3D
:
151 case PIPE_TEXTURE_CUBE
:
152 case PIPE_TEXTURE_CUBE_ARRAY
:
161 static inline boolean
162 llvmpipe_resource_is_1d(const struct pipe_resource
*resource
)
164 switch (resource
->target
) {
166 case PIPE_TEXTURE_1D
:
167 case PIPE_TEXTURE_1D_ARRAY
:
169 case PIPE_TEXTURE_2D
:
170 case PIPE_TEXTURE_2D_ARRAY
:
171 case PIPE_TEXTURE_RECT
:
172 case PIPE_TEXTURE_3D
:
173 case PIPE_TEXTURE_CUBE
:
174 case PIPE_TEXTURE_CUBE_ARRAY
:
183 static inline unsigned
184 llvmpipe_layer_stride(struct pipe_resource
*resource
,
187 struct llvmpipe_resource
*lpr
= llvmpipe_resource(resource
);
188 assert(level
< LP_MAX_TEXTURE_2D_LEVELS
);
189 return lpr
->img_stride
[level
];
193 static inline unsigned
194 llvmpipe_resource_stride(struct pipe_resource
*resource
,
197 struct llvmpipe_resource
*lpr
= llvmpipe_resource(resource
);
198 assert(level
< LP_MAX_TEXTURE_2D_LEVELS
);
199 return lpr
->row_stride
[level
];
202 static inline unsigned
203 llvmpipe_sample_stride(struct pipe_resource
*resource
)
205 struct llvmpipe_resource
*lpr
= llvmpipe_resource(resource
);
206 return lpr
->sample_stride
;
210 llvmpipe_resource_map(struct pipe_resource
*resource
,
213 enum lp_texture_usage tex_usage
);
216 llvmpipe_resource_unmap(struct pipe_resource
*resource
,
222 llvmpipe_resource_data(struct pipe_resource
*resource
);
226 llvmpipe_resource_size(const struct pipe_resource
*resource
);
230 llvmpipe_get_texture_image_address(struct llvmpipe_resource
*lpr
,
231 unsigned face_slice
, unsigned level
);
235 llvmpipe_print_resources(void);
238 #define LP_UNREFERENCED 0
239 #define LP_REFERENCED_FOR_READ (1 << 0)
240 #define LP_REFERENCED_FOR_WRITE (1 << 1)
243 llvmpipe_is_resource_referenced( struct pipe_context
*pipe
,
244 struct pipe_resource
*presource
,
248 llvmpipe_get_format_alignment(enum pipe_format format
);
251 llvmpipe_transfer_map_ms( struct pipe_context
*pipe
,
252 struct pipe_resource
*resource
,
256 const struct pipe_box
*box
,
257 struct pipe_transfer
**transfer
);
258 #endif /* LP_TEXTURE_H */