1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2010 Luca Barbieri 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 6bf215546Sopenharmony_ci * a copy of this software and associated documentation files (the 7bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 8bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 9bf215546Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 10bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 11bf215546Sopenharmony_ci * the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 14bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 15bf215546Sopenharmony_ci * portions of the Software. 16bf215546Sopenharmony_ci * 17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20bf215546Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 21bf215546Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22bf215546Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23bf215546Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24bf215546Sopenharmony_ci * 25bf215546Sopenharmony_ci **************************************************************************/ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#ifndef U_DIRTY_SURFACES_H_ 28bf215546Sopenharmony_ci#define U_DIRTY_SURFACES_H_ 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "pipe/p_state.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "util/list.h" 33bf215546Sopenharmony_ci#include "util/u_math.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_cistruct pipe_context; 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_citypedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *); 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistruct util_dirty_surfaces 40bf215546Sopenharmony_ci{ 41bf215546Sopenharmony_ci struct list_head dirty_list; 42bf215546Sopenharmony_ci}; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_cistruct util_dirty_surface 45bf215546Sopenharmony_ci{ 46bf215546Sopenharmony_ci struct pipe_surface base; 47bf215546Sopenharmony_ci struct list_head dirty_list; 48bf215546Sopenharmony_ci}; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cistatic inline void 51bf215546Sopenharmony_ciutil_dirty_surfaces_init(struct util_dirty_surfaces *ds) 52bf215546Sopenharmony_ci{ 53bf215546Sopenharmony_ci list_inithead(&ds->dirty_list); 54bf215546Sopenharmony_ci} 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_cistatic inline void 57bf215546Sopenharmony_ciutil_dirty_surfaces_use_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, util_dirty_surface_flush_t flush) 58bf215546Sopenharmony_ci{ 59bf215546Sopenharmony_ci struct list_head *p, *next; 60bf215546Sopenharmony_ci for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) 61bf215546Sopenharmony_ci { 62bf215546Sopenharmony_ci struct util_dirty_surface *ds = list_entry(p, struct util_dirty_surface, dirty_list); 63bf215546Sopenharmony_ci next = p->next; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci flush(pipe, &ds->base); 66bf215546Sopenharmony_ci } 67bf215546Sopenharmony_ci} 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_cistatic inline void 70bf215546Sopenharmony_ciutil_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) 71bf215546Sopenharmony_ci{ 72bf215546Sopenharmony_ci struct list_head *p, *next; 73bf215546Sopenharmony_ci if(first > last) 74bf215546Sopenharmony_ci return; 75bf215546Sopenharmony_ci for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next) 76bf215546Sopenharmony_ci { 77bf215546Sopenharmony_ci struct util_dirty_surface *ds = list_entry(p, struct util_dirty_surface, dirty_list); 78bf215546Sopenharmony_ci next = p->next; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last) 81bf215546Sopenharmony_ci flush(pipe, &ds->base); 82bf215546Sopenharmony_ci } 83bf215546Sopenharmony_ci} 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_cistatic inline void 86bf215546Sopenharmony_ciutil_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) 87bf215546Sopenharmony_ci{ 88bf215546Sopenharmony_ci if(!list_is_empty(&dss->dirty_list)) 89bf215546Sopenharmony_ci util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level, 90bf215546Sopenharmony_ci MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush); 91bf215546Sopenharmony_ci} 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_cistatic inline void 94bf215546Sopenharmony_ciutil_dirty_surface_init(struct util_dirty_surface *ds) 95bf215546Sopenharmony_ci{ 96bf215546Sopenharmony_ci list_inithead(&ds->dirty_list); 97bf215546Sopenharmony_ci} 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_cistatic inline boolean 100bf215546Sopenharmony_ciutil_dirty_surface_is_dirty(struct util_dirty_surface *ds) 101bf215546Sopenharmony_ci{ 102bf215546Sopenharmony_ci return !list_is_empty(&ds->dirty_list); 103bf215546Sopenharmony_ci} 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_cistatic inline void 106bf215546Sopenharmony_ciutil_dirty_surface_set_dirty(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) 107bf215546Sopenharmony_ci{ 108bf215546Sopenharmony_ci if(list_is_empty(&ds->dirty_list)) 109bf215546Sopenharmony_ci list_addtail(&ds->dirty_list, &dss->dirty_list); 110bf215546Sopenharmony_ci} 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_cistatic inline void 113bf215546Sopenharmony_ciutil_dirty_surface_set_clean(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds) 114bf215546Sopenharmony_ci{ 115bf215546Sopenharmony_ci if(!list_is_empty(&ds->dirty_list)) 116bf215546Sopenharmony_ci list_delinit(&ds->dirty_list); 117bf215546Sopenharmony_ci} 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci#endif 120