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
;
87 * A 3D image slice, cube face, or array layer.
89 struct ilo_texture_slice
{
90 /* 2D offset to the slice */
95 * Slice clear value. It is served for two purposes
97 * - the clear value used in commands such as 3DSTATE_CLEAR_PARAMS
98 * - the clear value when ILO_TEXTURE_CLEAR is set
100 * Since commands such as 3DSTATE_CLEAR_PARAMS expect a single clear value
101 * for all slices, ilo_blit_resolve_slices() will silently make all slices
102 * to have the same clear value.
104 uint32_t clear_value
;
108 struct pipe_resource base
;
112 enum pipe_format bo_format
;
115 enum intel_tiling_mode tiling
;
116 unsigned long bo_stride
; /* distance between two block rows in bytes */
117 unsigned long bo_height
;
119 unsigned block_width
;
120 unsigned block_height
;
123 /* true if the mip level alignments are stricter */
124 bool halign_8
, valign_4
;
125 /* true if space is reserved between layers */
126 bool array_spacing_full
;
127 /* true if samples are interleaved */
130 struct ilo_texture_slice
*slices
[PIPE_MAX_TEXTURE_LEVELS
];
132 struct ilo_texture
*separate_s8
;
136 unsigned long bo_stride
;
140 static inline struct ilo_buffer
*
141 ilo_buffer(struct pipe_resource
*res
)
143 return (struct ilo_buffer
*)
144 ((res
&& res
->target
== PIPE_BUFFER
) ? res
: NULL
);
147 static inline struct ilo_texture
*
148 ilo_texture(struct pipe_resource
*res
)
150 return (struct ilo_texture
*)
151 ((res
&& res
->target
!= PIPE_BUFFER
) ? res
: NULL
);
155 ilo_init_resource_functions(struct ilo_screen
*is
);
158 ilo_buffer_rename_bo(struct ilo_buffer
*buf
);
161 ilo_texture_rename_bo(struct ilo_texture
*tex
);
164 * Return the bo of the resource.
166 static inline struct intel_bo
*
167 ilo_resource_get_bo(struct pipe_resource
*res
)
169 return (res
->target
== PIPE_BUFFER
) ?
170 ilo_buffer(res
)->bo
: ilo_texture(res
)->bo
;
173 static inline struct ilo_texture_slice
*
174 ilo_texture_get_slice(const struct ilo_texture
*tex
,
175 unsigned level
, unsigned slice
)
177 assert(level
<= tex
->base
.last_level
);
178 assert(slice
< ((tex
->base
.target
== PIPE_TEXTURE_3D
) ?
179 u_minify(tex
->base
.depth0
, level
) : tex
->base
.array_size
));
181 return &tex
->slices
[level
][slice
];
185 ilo_texture_get_slice_offset(const struct ilo_texture
*tex
,
186 unsigned level
, unsigned slice
,
187 unsigned *x_offset
, unsigned *y_offset
);
190 ilo_texture_set_slice_flags(struct ilo_texture
*tex
, unsigned level
,
191 unsigned first_slice
, unsigned num_slices
,
192 unsigned mask
, unsigned value
)
194 const struct ilo_texture_slice
*last
=
195 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
196 struct ilo_texture_slice
*slice
=
197 ilo_texture_get_slice(tex
, level
, first_slice
);
199 while (slice
<= last
) {
200 slice
->flags
= (slice
->flags
& ~mask
) | (value
& mask
);
206 ilo_texture_set_slice_clear_value(struct ilo_texture
*tex
, unsigned level
,
207 unsigned first_slice
, unsigned num_slices
,
208 uint32_t clear_value
)
210 const struct ilo_texture_slice
*last
=
211 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
212 struct ilo_texture_slice
*slice
=
213 ilo_texture_get_slice(tex
, level
, first_slice
);
215 while (slice
<= last
) {
216 slice
->clear_value
= clear_value
;
222 ilo_texture_can_enable_hiz(const struct ilo_texture
*tex
, unsigned level
,
223 unsigned first_slice
, unsigned num_slices
)
225 const struct ilo_screen
*is
= ilo_screen(tex
->base
.screen
);
226 const struct ilo_texture_slice
*slice
=
227 ilo_texture_get_slice(tex
, level
, first_slice
);
232 /* we can adjust 3DSTATE_DEPTH_BUFFER for the first slice */
233 if (level
== 0 && first_slice
== 0 && num_slices
== 1)
236 /* HiZ is non-mipmapped and non-array on GEN6 */
237 assert(is
->dev
.gen
> ILO_GEN(6));
240 * Either all or none of the slices in the same level have ILO_TEXTURE_HIZ
241 * set. It suffices to check only the first slice.
243 return (slice
->flags
& ILO_TEXTURE_HIZ
);
246 #endif /* ILO_RESOURCE_H */