gallium: make all checks for PIPE_TEXTURE_2D check for PIPE_TEXTURE_RECT too
[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 #include "cso_cache/cso_hash.h"
8
9 struct util_surfaces
10 {
11 union
12 {
13 struct cso_hash *hash;
14 struct pipe_surface **array;
15 void* pv;
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 || pt->target == PIPE_TEXTURE_RECT) && 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 static INLINE struct pipe_surface *
39 util_surfaces_peek(struct util_surfaces *us, struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice)
40 {
41 if(!us->u.pv)
42 return 0;
43
44 if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE))
45 return cso_hash_iter_data(cso_hash_find(us->u.hash, ((zslice + face) << 8) | level));
46 else
47 return us->u.array[level];
48 }
49
50 void util_surfaces_do_detach(struct util_surfaces *us, struct pipe_surface *ps);
51
52 static INLINE void
53 util_surfaces_detach(struct util_surfaces *us, struct pipe_surface *ps)
54 {
55 if(likely(ps->texture->target == PIPE_TEXTURE_2D || ps->texture->target == PIPE_TEXTURE_RECT))
56 {
57 us->u.array[ps->level] = 0;
58 return;
59 }
60
61 util_surfaces_do_detach(us, ps);
62 }
63
64 void util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *));
65
66 #endif