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
{
37 ILO_TEXTURE_RENDER_WRITE
= 1 << 0,
38 ILO_TEXTURE_BLT_WRITE
= 1 << 1,
39 ILO_TEXTURE_CPU_WRITE
= 1 << 2,
40 ILO_TEXTURE_RENDER_READ
= 1 << 3,
41 ILO_TEXTURE_BLT_READ
= 1 << 4,
42 ILO_TEXTURE_CPU_READ
= 1 << 5,
43 ILO_TEXTURE_CLEAR
= 1 << 6,
44 ILO_TEXTURE_HIZ
= 1 << 7,
48 struct pipe_resource base
;
56 * A 3D image slice, cube face, or array layer.
58 struct ilo_texture_slice
{
59 /* 2D offset to the slice */
65 struct pipe_resource base
;
70 enum pipe_format bo_format
;
74 * These are the values passed to or returned from winsys for bo
75 * allocation. As such,
77 * - width and height are in blocks,
78 * - cpp is the block size in bytes, and
79 * - stride is the distance in bytes between two block rows.
81 int bo_width
, bo_height
, bo_cpp
, bo_stride
;
82 enum intel_tiling_mode tiling
;
86 unsigned block_height
;
88 /* true if the mip level alignments are stricter */
89 bool halign_8
, valign_4
;
90 /* true if space is reserved between layers */
91 bool array_spacing_full
;
92 /* true if samples are interleaved */
95 struct ilo_texture_slice
*slices
[PIPE_MAX_TEXTURE_LEVELS
];
97 struct ilo_texture
*separate_s8
;
105 static inline struct ilo_buffer
*
106 ilo_buffer(struct pipe_resource
*res
)
108 return (struct ilo_buffer
*)
109 ((res
&& res
->target
== PIPE_BUFFER
) ? res
: NULL
);
112 static inline struct ilo_texture
*
113 ilo_texture(struct pipe_resource
*res
)
115 return (struct ilo_texture
*)
116 ((res
&& res
->target
!= PIPE_BUFFER
) ? res
: NULL
);
120 ilo_init_resource_functions(struct ilo_screen
*is
);
123 ilo_buffer_alloc_bo(struct ilo_buffer
*buf
);
126 ilo_texture_alloc_bo(struct ilo_texture
*tex
);
128 static inline struct ilo_texture_slice
*
129 ilo_texture_get_slice(const struct ilo_texture
*tex
,
130 unsigned level
, unsigned slice
)
132 assert(level
<= tex
->base
.last_level
);
133 assert(slice
< ((tex
->base
.target
== PIPE_TEXTURE_3D
) ?
134 u_minify(tex
->base
.depth0
, level
) : tex
->base
.array_size
));
136 return &tex
->slices
[level
][slice
];
140 ilo_texture_get_slice_offset(const struct ilo_texture
*tex
,
141 unsigned level
, unsigned slice
,
142 unsigned *x_offset
, unsigned *y_offset
);
145 ilo_texture_set_slice_flags(struct ilo_texture
*tex
, unsigned level
,
146 unsigned first_slice
, unsigned num_slices
,
147 unsigned mask
, unsigned value
)
149 const struct ilo_texture_slice
*last
=
150 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
151 struct ilo_texture_slice
*slice
=
152 ilo_texture_get_slice(tex
, level
, first_slice
);
154 while (slice
<= last
) {
155 slice
->flags
= (slice
->flags
& ~mask
) | (value
& mask
);
161 ilo_texture_can_enable_hiz(const struct ilo_texture
*tex
, unsigned level
,
162 unsigned first_slice
, unsigned num_slices
)
164 const struct ilo_screen
*is
= ilo_screen(tex
->base
.screen
);
165 const struct ilo_texture_slice
*slice
=
166 ilo_texture_get_slice(tex
, level
, first_slice
);
171 /* we can adjust 3DSTATE_DEPTH_BUFFER for the first slice */
172 if (level
== 0 && first_slice
== 0 && num_slices
== 1)
175 /* HiZ is non-mipmapped and non-array on GEN6 */
176 assert(is
->dev
.gen
> ILO_GEN(6));
179 * Either all or none of the slices in the same level have ILO_TEXTURE_HIZ
180 * set. It suffices to check only the first slice.
182 return (slice
->flags
& ILO_TEXTURE_HIZ
);
185 #endif /* ILO_RESOURCE_H */