1 #include "u_surfaces.h"
2 #include "util/u_hash_table.h"
3 #include "util/u_inlines.h"
4 #include "util/u_memory.h"
7 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
)
9 struct pipe_surface
*ps
;
11 if(pt
->target
== PIPE_TEXTURE_3D
|| pt
->target
== PIPE_TEXTURE_CUBE
)
14 us
->u
.hash
= cso_hash_create();
16 ps
= cso_hash_iter_data(cso_hash_find(us
->u
.hash
, ((zslice
+ face
) << 8) | level
));
21 us
->u
.array
= CALLOC(pt
->last_level
+ 1, sizeof(struct pipe_surface
*));
22 ps
= us
->u
.array
[level
];
27 p_atomic_inc(&ps
->reference
.count
);
31 ps
= (struct pipe_surface
*)CALLOC(1, surface_struct_size
);
35 pipe_surface_init(ps
, pt
, face
, level
, zslice
, flags
);
38 if(pt
->target
== PIPE_TEXTURE_3D
|| pt
->target
== PIPE_TEXTURE_CUBE
)
39 cso_hash_insert(us
->u
.hash
, ((zslice
+ face
) << 8) | level
, ps
);
41 us
->u
.array
[level
] = ps
;
47 util_surfaces_do_detach(struct util_surfaces
*us
, struct pipe_surface
*ps
)
49 struct pipe_resource
*pt
= ps
->texture
;
50 if(pt
->target
== PIPE_TEXTURE_3D
|| pt
->target
== PIPE_TEXTURE_CUBE
)
52 cso_hash_erase(us
->u
.hash
, cso_hash_find(us
->u
.hash
, ((ps
->zslice
+ ps
->face
) << 8) | ps
->level
));
55 us
->u
.array
[ps
->level
] = 0;
59 util_surfaces_destroy(struct util_surfaces
*us
, struct pipe_resource
*pt
, void (*destroy_surface
) (struct pipe_surface
*))
61 if(pt
->target
== PIPE_TEXTURE_3D
|| pt
->target
== PIPE_TEXTURE_CUBE
)
65 struct cso_hash_iter iter
;
66 iter
= cso_hash_first_node(us
->u
.hash
);
67 while (!cso_hash_iter_is_null(iter
)) {
68 destroy_surface(cso_hash_iter_data(iter
));
69 iter
= cso_hash_iter_next(iter
);
72 cso_hash_delete(us
->u
.hash
);
81 for(i
= 0; i
<= pt
->last_level
; ++i
)
83 struct pipe_surface
*ps
= us
->u
.array
[i
];