2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #ifndef ILO_RESOURCE_H
29 #define ILO_RESOURCE_H
31 #include "intel_winsys.h"
33 #include "ilo_common.h"
34 #include "ilo_screen.h"
36 enum ilo_texture_flags
{
38 * Possible writers of a texture. There can be at most one writer at any
41 * Wine set in resolve flags (in ilo_blit_resolve_slices()), they indicate
42 * the new writer. When set in slice flags (ilo_texture_slice::flags),
43 * they indicate the writer since last resolve.
45 ILO_TEXTURE_RENDER_WRITE
= 1 << 0,
46 ILO_TEXTURE_BLT_WRITE
= 1 << 1,
47 ILO_TEXTURE_CPU_WRITE
= 1 << 2,
50 * Possible readers of a texture. There may be multiple readers at any
53 * When set in resolve flags, they indicate the new readers. They are
54 * never set in slice flags.
56 ILO_TEXTURE_RENDER_READ
= 1 << 3,
57 ILO_TEXTURE_BLT_READ
= 1 << 4,
58 ILO_TEXTURE_CPU_READ
= 1 << 5,
61 * Set when the texture is cleared.
63 * When set in resolve flags, the new writer will clear. When set in slice
64 * flags, the slice has been cleared to ilo_texture_slice::clear_value.
66 ILO_TEXTURE_CLEAR
= 1 << 6,
69 * Set when HiZ can be enabled.
71 * It is never set in resolve flags. When set in slice flags, the slice
72 * can have HiZ enabled. It is to be noted that this bit is always set for
73 * either all or none of the slices in a level, allowing quick check in
74 * case of layered rendering.
76 ILO_TEXTURE_HIZ
= 1 << 7,
80 struct pipe_resource base
;
88 * A 3D image slice, cube face, or array layer.
90 struct ilo_texture_slice
{
91 /* 2D offset to the slice */
96 * Slice clear value. It is served for two purposes
98 * - the clear value used in commands such as 3DSTATE_CLEAR_PARAMS
99 * - the clear value when ILO_TEXTURE_CLEAR is set
101 * Since commands such as 3DSTATE_CLEAR_PARAMS expect a single clear value
102 * for all slices, ilo_blit_resolve_slices() will silently make all slices
103 * to have the same clear value.
105 uint32_t clear_value
;
109 struct pipe_resource base
;
114 enum pipe_format bo_format
;
118 * These are the values passed to or returned from winsys for bo
119 * allocation. As such,
121 * - width and height are in blocks,
122 * - cpp is the block size in bytes, and
123 * - stride is the distance in bytes between two block rows.
125 int bo_width
, bo_height
, bo_cpp
, bo_stride
;
126 enum intel_tiling_mode tiling
;
129 unsigned block_width
;
130 unsigned block_height
;
132 /* true if the mip level alignments are stricter */
133 bool halign_8
, valign_4
;
134 /* true if space is reserved between layers */
135 bool array_spacing_full
;
136 /* true if samples are interleaved */
139 struct ilo_texture_slice
*slices
[PIPE_MAX_TEXTURE_LEVELS
];
141 struct ilo_texture
*separate_s8
;
149 static inline struct ilo_buffer
*
150 ilo_buffer(struct pipe_resource
*res
)
152 return (struct ilo_buffer
*)
153 ((res
&& res
->target
== PIPE_BUFFER
) ? res
: NULL
);
156 static inline struct ilo_texture
*
157 ilo_texture(struct pipe_resource
*res
)
159 return (struct ilo_texture
*)
160 ((res
&& res
->target
!= PIPE_BUFFER
) ? res
: NULL
);
164 ilo_init_resource_functions(struct ilo_screen
*is
);
167 ilo_buffer_alloc_bo(struct ilo_buffer
*buf
);
170 ilo_texture_alloc_bo(struct ilo_texture
*tex
);
172 static inline struct ilo_texture_slice
*
173 ilo_texture_get_slice(const struct ilo_texture
*tex
,
174 unsigned level
, unsigned slice
)
176 assert(level
<= tex
->base
.last_level
);
177 assert(slice
< ((tex
->base
.target
== PIPE_TEXTURE_3D
) ?
178 u_minify(tex
->base
.depth0
, level
) : tex
->base
.array_size
));
180 return &tex
->slices
[level
][slice
];
184 ilo_texture_get_slice_offset(const struct ilo_texture
*tex
,
185 unsigned level
, unsigned slice
,
186 unsigned *x_offset
, unsigned *y_offset
);
189 ilo_texture_set_slice_flags(struct ilo_texture
*tex
, unsigned level
,
190 unsigned first_slice
, unsigned num_slices
,
191 unsigned mask
, unsigned value
)
193 const struct ilo_texture_slice
*last
=
194 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
195 struct ilo_texture_slice
*slice
=
196 ilo_texture_get_slice(tex
, level
, first_slice
);
198 while (slice
<= last
) {
199 slice
->flags
= (slice
->flags
& ~mask
) | (value
& mask
);
205 ilo_texture_set_slice_clear_value(struct ilo_texture
*tex
, unsigned level
,
206 unsigned first_slice
, unsigned num_slices
,
207 uint32_t clear_value
)
209 const struct ilo_texture_slice
*last
=
210 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
211 struct ilo_texture_slice
*slice
=
212 ilo_texture_get_slice(tex
, level
, first_slice
);
214 while (slice
<= last
) {
215 slice
->clear_value
= clear_value
;
221 ilo_texture_can_enable_hiz(const struct ilo_texture
*tex
, unsigned level
,
222 unsigned first_slice
, unsigned num_slices
)
224 const struct ilo_screen
*is
= ilo_screen(tex
->base
.screen
);
225 const struct ilo_texture_slice
*slice
=
226 ilo_texture_get_slice(tex
, level
, first_slice
);
231 /* we can adjust 3DSTATE_DEPTH_BUFFER for the first slice */
232 if (level
== 0 && first_slice
== 0 && num_slices
== 1)
235 /* HiZ is non-mipmapped and non-array on GEN6 */
236 assert(is
->dev
.gen
> ILO_GEN(6));
239 * Either all or none of the slices in the same level have ILO_TEXTURE_HIZ
240 * set. It suffices to check only the first slice.
242 return (slice
->flags
& ILO_TEXTURE_HIZ
);
245 #endif /* ILO_RESOURCE_H */