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 35struct pipe_context; 36 37typedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *); 38 39struct util_dirty_surfaces 40{ 41 struct list_head dirty_list; 42}; 43 44struct util_dirty_surface 45{ 46 struct pipe_surface base; 47 struct list_head dirty_list; 48}; 49 50static INLINE void 51util_dirty_surfaces_init(struct util_dirty_surfaces *ds) 52{ 53 LIST_INITHEAD(&ds->dirty_list); 54} 55 56static INLINE void 57util_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 69static INLINE void 70util_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 85static INLINE void 86util_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 93static INLINE void 94util_dirty_surface_init(struct util_dirty_surface *ds) 95{ 96 LIST_INITHEAD(&ds->dirty_list); 97} 98 99static INLINE boolean 100util_dirty_surface_is_dirty(struct util_dirty_surface *ds) 101{ 102 return !LIST_IS_EMPTY(&ds->dirty_list); 103} 104 105static INLINE void 106util_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 112static INLINE void 113util_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