1 /************************************************************************** 2 * 3 * Copyright 2010 Luca Barbieri 4 * 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: 12 * 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. 16 * 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. 24 * 25 **************************************************************************/ 26 27 #ifndef U_DIRTY_SURFACES_H_ 28 #define U_DIRTY_SURFACES_H_ 29 30 #include "pipe/p_state.h" 31 32 #include "util/u_double_list.h" 33 #include "util/u_math.h" 34 35 struct pipe_context; 36 37 typedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *); 38 39 struct util_dirty_surfaces 40 { 41 struct list_head dirty_list; 42 }; 43 44 struct util_dirty_surface 45 { 46 struct pipe_surface base; 47 struct list_head dirty_list; 48 }; 49 50 static INLINE void 51 util_dirty_surfaces_init(struct util_dirty_surfaces *ds) 52 { 53 LIST_INITHEAD(&ds->dirty_list); 54 } 55 56 static INLINE void 57 util_dirty_surfaces_use_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, util_dirty_surface_flush_t flush) 58 { 59 struct list_head *p, *next; 60 for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) 61 { 62 struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); 63 next = p->next; 64 65 flush(pipe, &ds->base); 66 } 67 } 68 69 static INLINE void 70 util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, unsigned first, unsigned last, util_dirty_surface_flush_t flush) 71 { 72 struct list_head *p, *next; 73 if(first > last) 74 return; 75 for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) 76 { 77 struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list); 78 next = p->next; 79 80 if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last) 81 flush(pipe, &ds->base); 82 } 83 } 84 85 static INLINE void 86 util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush) 87 { 88 if(!LIST_IS_EMPTY(&dss->dirty_list)) 89 util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level, 90 MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush); 91 } 92 93 static INLINE void 94 util_dirty_surface_init(struct util_dirty_surface *ds) 95 { 96 LIST_INITHEAD(&ds->dirty_list); 97 } 98 99 static INLINE boolean 100 util_dirty_surface_is_dirty(struct util_dirty_surface *ds) 101 { 102 return !LIST_IS_EMPTY(&ds->dirty_list); 103 } 104 105 static INLINE void 106 util_dirty_surface_set_dirty(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) 107 { 108 if(LIST_IS_EMPTY(&ds->dirty_list)) 109 LIST_ADDTAIL(&ds->dirty_list, &dss->dirty_list); 110 } 111 112 static INLINE void 113 util_dirty_surface_set_clean(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) 114 { 115 if(!LIST_IS_EMPTY(&ds->dirty_list)) 116 LIST_DELINIT(&ds->dirty_list); 117 } 118 119 #endif 120