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"
36 #define LP_MAX_TEXTURE_2D_LEVELS 12 /* 2K x 2K for now */
37 #define LP_MAX_TEXTURE_3D_LEVELS 10 /* 512 x 512 x 512 for now */
39 #define LP_MAX_TEXTURE_LEVELS LP_MAX_TEXTURE_2D_LEVELS
44 LP_TEX_USAGE_READ
= 100,
45 LP_TEX_USAGE_READ_WRITE
,
46 LP_TEX_USAGE_WRITE_ALL
50 /** Per-tile layout mode */
51 enum lp_texture_layout
53 LP_TEX_LAYOUT_NONE
= 0, /**< no layout for the tile data yet */
54 LP_TEX_LAYOUT_TILED
, /**< the tile data is in tiled layout */
55 LP_TEX_LAYOUT_LINEAR
, /**< the tile data is in linear layout */
56 LP_TEX_LAYOUT_BOTH
/**< the tile data is in both modes */
62 struct llvmpipe_context
;
64 struct sw_displaytarget
;
68 * We keep one or two copies of the texture image data: one in a simple
69 * linear layout (for texture sampling) and another in a tiled layout (for
70 * render targets). We keep track of whether each image tile is linear
71 * or tiled on a per-tile basis.
75 /** A 1D/2D/3D image, one mipmap level */
76 struct llvmpipe_texture_image
83 * llvmpipe subclass of pipe_resource. A texture, drawing surface,
84 * vertex buffer, const buffer, etc.
85 * Textures are stored differently than othere types of objects such as
86 * vertex buffers and const buffers.
87 * The former are tiled and have per-tile layout flags.
88 * The later are simple malloc'd blocks of memory.
90 struct llvmpipe_resource
92 struct pipe_resource base
;
94 /** Row stride in bytes */
95 unsigned stride
[LP_MAX_TEXTURE_LEVELS
];
96 unsigned tiles_per_row
[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 /** per-tile layout info */
116 enum lp_texture_layout
*layout
[PIPE_TEX_FACE_MAX
][LP_MAX_TEXTURE_LEVELS
];
118 boolean userBuffer
; /** Is this a user-space buffer? */
121 unsigned id
; /**< temporary, for debugging */
125 struct llvmpipe_transfer
127 struct pipe_transfer base
;
129 unsigned long offset
;
134 static INLINE
struct llvmpipe_resource
*
135 llvmpipe_resource(struct pipe_resource
*pt
)
137 return (struct llvmpipe_resource
*) pt
;
141 static INLINE
const struct llvmpipe_resource
*
142 llvmpipe_resource_const(const struct pipe_resource
*pt
)
144 return (const struct llvmpipe_resource
*) pt
;
148 static INLINE
struct llvmpipe_transfer
*
149 llvmpipe_transfer(struct pipe_transfer
*pt
)
151 return (struct llvmpipe_transfer
*) pt
;
155 void llvmpipe_init_screen_resource_funcs(struct pipe_screen
*screen
);
156 void llvmpipe_init_context_resource_funcs(struct pipe_context
*pipe
);
158 static INLINE
unsigned
159 llvmpipe_resource_stride(struct pipe_resource
*resource
,
162 struct llvmpipe_resource
*lpr
= llvmpipe_resource(resource
);
163 assert(level
< LP_MAX_TEXTURE_2D_LEVELS
);
164 return lpr
->stride
[level
];
169 llvmpipe_resource_map(struct pipe_resource
*resource
,
173 enum lp_texture_usage tex_usage
,
174 enum lp_texture_layout layout
);
177 llvmpipe_resource_unmap(struct pipe_resource
*resource
,
184 llvmpipe_resource_data(struct pipe_resource
*resource
);
188 llvmpipe_get_texture_image_address(struct llvmpipe_resource
*lpr
,
189 unsigned face
, unsigned level
,
190 enum lp_texture_layout layout
);
193 llvmpipe_get_texture_image(struct llvmpipe_resource
*resource
,
194 unsigned face
, unsigned level
,
195 enum lp_texture_usage usage
,
196 enum lp_texture_layout layout
);
200 llvmpipe_get_texture_tile_linear(struct llvmpipe_resource
*lpr
,
201 unsigned face
, unsigned level
,
202 enum lp_texture_usage usage
,
203 unsigned x
, unsigned y
);
206 llvmpipe_get_texture_tile(struct llvmpipe_resource
*lpr
,
207 unsigned face
, unsigned level
,
208 enum lp_texture_usage usage
,
209 unsigned x
, unsigned y
);
214 llvmpipe_init_screen_texture_funcs(struct pipe_screen
*screen
);
217 llvmpipe_init_context_texture_funcs(struct pipe_context
*pipe
);
219 #endif /* LP_TEXTURE_H */