Merge branch '7.8'
[mesa.git] / src / gallium / auxiliary / util / u_surfaces.h
1 #ifndef U_SURFACES_H_
2 #define U_SURFACES_H_
3
4 #include "pipe/p_compiler.h"
5 #include "pipe/p_state.h"
6 #include "util/u_atomic.h"
7
8 struct util_hash_table;
9
10 struct util_surfaces
11 {
12 union
13 {
14 struct util_hash_table *table;
15 struct pipe_surface **array;
16 } u;
17 };
18
19 struct pipe_surface *util_surfaces_do_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags);
20
21 /* fast inline path for the very common case */
22 static INLINE struct pipe_surface *
23 util_surfaces_get(struct util_surfaces *us, unsigned surface_struct_size, struct pipe_screen *pscreen, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned flags)
24 {
25 if(likely(pt->target == PIPE_TEXTURE_2D && us->u.array))
26 {
27 struct pipe_surface *ps = us->u.array[level];
28 if(ps)
29 {
30 p_atomic_inc(&ps->reference.count);
31 return ps;
32 }
33 }
34
35 return util_surfaces_do_get(us, surface_struct_size, pscreen, pt, face, level, zslice, flags);
36 }
37
38 void util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps);
39
40 static INLINE void
41 util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps)
42 {
43 if(likely(ps->texture->target == PIPE_TEXTURE_2D))
44 {
45 us->u.array[ps->level] = 0;
46 return;
47 }
48
49 return util_surfaces_do_detach(us, ps);
50 }
51
52 void util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *));
53
54 #endif