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"
13 struct cso_hash
*hash
;
14 struct pipe_surface
**array
;
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
);
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
)
25 if(likely((pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
) && us
->u
.array
))
27 struct pipe_surface
*ps
= us
->u
.array
[level
];
30 p_atomic_inc(&ps
->reference
.count
);
35 return util_surfaces_do_get(us
, surface_struct_size
, pscreen
, pt
, face
, level
, zslice
, flags
);
38 static INLINE
struct pipe_surface
*
39 util_surfaces_peek(struct util_surfaces
*us
, struct pipe_resource
*pt
, unsigned face
, unsigned level
, unsigned zslice
)
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
));
47 return us
->u
.array
[level
];
50 void util_surfaces_do_detach(struct util_surfaces
*us
, struct pipe_surface
*ps
);
53 util_surfaces_detach(struct util_surfaces
*us
, struct pipe_surface
*ps
)
55 if(likely(ps
->texture
->target
== PIPE_TEXTURE_2D
|| ps
->texture
->target
== PIPE_TEXTURE_RECT
))
57 us
->u
.array
[ps
->level
] = 0;
61 util_surfaces_do_detach(us
, ps
);
64 void util_surfaces_destroy(struct util_surfaces
*us
, struct pipe_resource
*pt
, void (*destroy_surface
) (struct pipe_surface
*));