1 /**************************************************************************
3 * Copyright 2010 Luca Barbieri
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_state.h"
32 #include "util/u_atomic.h"
33 #include "cso_cache/cso_hash.h"
39 struct cso_hash
*hash
;
40 struct pipe_surface
**array
;
45 /* Return value indicates if the pipe surface result is new */
47 util_surfaces_do_get(struct util_surfaces
*us
, unsigned surface_struct_size
,
48 struct pipe_context
*ctx
, struct pipe_resource
*pt
,
49 unsigned level
, unsigned layer
, unsigned flags
,
50 struct pipe_surface
**res
);
52 /* fast inline path for the very common case */
54 util_surfaces_get(struct util_surfaces
*us
, unsigned surface_struct_size
,
55 struct pipe_context
*ctx
, struct pipe_resource
*pt
,
56 unsigned level
, unsigned layer
, unsigned flags
,
57 struct pipe_surface
**res
)
59 if(likely((pt
->target
== PIPE_TEXTURE_2D
|| pt
->target
== PIPE_TEXTURE_RECT
) && us
->u
.array
))
61 struct pipe_surface
*ps
= us
->u
.array
[level
];
62 if(ps
&& ps
->context
== ctx
)
64 p_atomic_inc(&ps
->reference
.count
);
70 return util_surfaces_do_get(us
, surface_struct_size
, ctx
, pt
, level
, layer
, flags
, res
);
73 static INLINE
struct pipe_surface
*
74 util_surfaces_peek(struct util_surfaces
*us
, struct pipe_resource
*pt
, unsigned level
, unsigned layer
)
79 if(unlikely(pt
->target
== PIPE_TEXTURE_3D
|| pt
->target
== PIPE_TEXTURE_CUBE
))
80 return cso_hash_iter_data(cso_hash_find(us
->u
.hash
, (layer
<< 8) | level
));
82 return us
->u
.array
[level
];
85 void util_surfaces_do_detach(struct util_surfaces
*us
, struct pipe_surface
*ps
);
88 util_surfaces_detach(struct util_surfaces
*us
, struct pipe_surface
*ps
)
90 if(likely(ps
->texture
->target
== PIPE_TEXTURE_2D
|| ps
->texture
->target
== PIPE_TEXTURE_RECT
))
92 us
->u
.array
[ps
->u
.tex
.level
] = 0;
96 util_surfaces_do_detach(us
, ps
);
99 void util_surfaces_destroy(struct util_surfaces
*us
, struct pipe_resource
*pt
, void (*destroy_surface
) (struct pipe_surface
*));