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 "core/intel_winsys.h"
32 #include "core/ilo_image.h"
33 #include "core/ilo_vma.h"
35 #include "ilo_common.h"
36 #include "ilo_screen.h"
38 enum ilo_texture_flags
{
40 * Possible writers of a texture. There can be at most one writer at any
43 * Wine set in resolve flags (in ilo_blit_resolve_slices()), they indicate
44 * the new writer. When set in slice flags (ilo_texture_slice::flags),
45 * they indicate the writer since last resolve.
47 ILO_TEXTURE_RENDER_WRITE
= 1 << 0,
48 ILO_TEXTURE_BLT_WRITE
= 1 << 1,
49 ILO_TEXTURE_CPU_WRITE
= 1 << 2,
52 * Possible readers of a texture. There may be multiple readers at any
55 * When set in resolve flags, they indicate the new readers. They are
56 * never set in slice flags.
58 ILO_TEXTURE_RENDER_READ
= 1 << 3,
59 ILO_TEXTURE_BLT_READ
= 1 << 4,
60 ILO_TEXTURE_CPU_READ
= 1 << 5,
63 * Set when the texture is cleared.
65 * When set in resolve flags, the new writer will clear. When set in slice
66 * flags, the slice has been cleared to ilo_texture_slice::clear_value.
68 ILO_TEXTURE_CLEAR
= 1 << 6,
72 * A 3D image slice, cube face, or array layer.
74 struct ilo_texture_slice
{
78 * Slice clear value. It is served for two purposes
80 * - the clear value used in commands such as 3DSTATE_CLEAR_PARAMS
81 * - the clear value when ILO_TEXTURE_CLEAR is set
83 * Since commands such as 3DSTATE_CLEAR_PARAMS expect a single clear value
84 * for all slices, ilo_blit_resolve_slices() will silently make all slices
85 * to have the same clear value.
91 struct pipe_resource base
;
95 enum pipe_format image_format
;
96 struct ilo_image image
;
98 struct ilo_vma aux_vma
;
100 /* XXX thread-safety */
101 struct ilo_texture_slice
*slices
[PIPE_MAX_TEXTURE_LEVELS
];
103 struct ilo_texture
*separate_s8
;
106 struct ilo_buffer_resource
{
107 struct pipe_resource base
;
113 static inline struct ilo_buffer_resource
*
114 ilo_buffer_resource(struct pipe_resource
*res
)
116 return (struct ilo_buffer_resource
*)
117 ((res
&& res
->target
== PIPE_BUFFER
) ? res
: NULL
);
120 static inline struct ilo_texture
*
121 ilo_texture(struct pipe_resource
*res
)
123 return (struct ilo_texture
*)
124 ((res
&& res
->target
!= PIPE_BUFFER
) ? res
: NULL
);
128 ilo_init_resource_functions(struct ilo_screen
*is
);
131 ilo_resource_rename_bo(struct pipe_resource
*res
);
134 * Return the VMA of the resource.
136 static inline const struct ilo_vma
*
137 ilo_resource_get_vma(struct pipe_resource
*res
)
139 return (res
->target
== PIPE_BUFFER
) ?
140 &((struct ilo_buffer_resource
*) res
)->vma
:
141 &((struct ilo_texture
*) res
)->vma
;
144 static inline struct ilo_texture_slice
*
145 ilo_texture_get_slice(const struct ilo_texture
*tex
,
146 unsigned level
, unsigned slice
)
148 assert(level
<= tex
->base
.last_level
);
149 assert(slice
< ((tex
->base
.target
== PIPE_TEXTURE_3D
) ?
150 u_minify(tex
->base
.depth0
, level
) : tex
->base
.array_size
));
152 return &tex
->slices
[level
][slice
];
156 ilo_texture_set_slice_flags(struct ilo_texture
*tex
, unsigned level
,
157 unsigned first_slice
, unsigned num_slices
,
158 unsigned mask
, unsigned value
)
160 const struct ilo_texture_slice
*last
=
161 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
162 struct ilo_texture_slice
*slice
=
163 ilo_texture_get_slice(tex
, level
, first_slice
);
165 while (slice
<= last
) {
166 slice
->flags
= (slice
->flags
& ~mask
) | (value
& mask
);
172 ilo_texture_set_slice_clear_value(struct ilo_texture
*tex
, unsigned level
,
173 unsigned first_slice
, unsigned num_slices
,
174 uint32_t clear_value
)
176 const struct ilo_texture_slice
*last
=
177 ilo_texture_get_slice(tex
, level
, first_slice
+ num_slices
- 1);
178 struct ilo_texture_slice
*slice
=
179 ilo_texture_get_slice(tex
, level
, first_slice
);
181 while (slice
<= last
) {
182 slice
->clear_value
= clear_value
;
187 #endif /* ILO_RESOURCE_H */