Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_dirty_surfaces.h
4561 views
/**************************************************************************1*2* Copyright 2010 Luca Barbieri3*4* Permission is hereby granted, free of charge, to any person obtaining5* a copy of this software and associated documentation files (the6* "Software"), to deal in the Software without restriction, including7* without limitation the rights to use, copy, modify, merge, publish,8* distribute, sublicense, and/or sell copies of the Software, and to9* permit persons to whom the Software is furnished to do so, subject to10* the following conditions:11*12* The above copyright notice and this permission notice (including the13* next paragraph) shall be included in all copies or substantial14* portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.19* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*24**************************************************************************/2526#ifndef U_DIRTY_SURFACES_H_27#define U_DIRTY_SURFACES_H_2829#include "pipe/p_state.h"3031#include "util/list.h"32#include "util/u_math.h"3334struct pipe_context;3536typedef void (*util_dirty_surface_flush_t) (struct pipe_context *, struct pipe_surface *);3738struct util_dirty_surfaces39{40struct list_head dirty_list;41};4243struct util_dirty_surface44{45struct pipe_surface base;46struct list_head dirty_list;47};4849static inline void50util_dirty_surfaces_init(struct util_dirty_surfaces *ds)51{52list_inithead(&ds->dirty_list);53}5455static inline void56util_dirty_surfaces_use_for_sampling(struct pipe_context *pipe, struct util_dirty_surfaces *dss, util_dirty_surface_flush_t flush)57{58struct list_head *p, *next;59for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next)60{61struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list);62next = p->next;6364flush(pipe, &ds->base);65}66}6768static inline void69util_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)70{71struct list_head *p, *next;72if(first > last)73return;74for(p = dss->dirty_list.next; p != &dss->dirty_list; p = next)75{76struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list);77next = p->next;7879if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last)80flush(pipe, &ds->base);81}82}8384static inline void85util_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)86{87if(!list_is_empty(&dss->dirty_list))88util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level,89MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush);90}9192static inline void93util_dirty_surface_init(struct util_dirty_surface *ds)94{95list_inithead(&ds->dirty_list);96}9798static inline boolean99util_dirty_surface_is_dirty(struct util_dirty_surface *ds)100{101return !list_is_empty(&ds->dirty_list);102}103104static inline void105util_dirty_surface_set_dirty(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds)106{107if(list_is_empty(&ds->dirty_list))108list_addtail(&ds->dirty_list, &dss->dirty_list);109}110111static inline void112util_dirty_surface_set_clean(struct util_dirty_surfaces *dss, struct util_dirty_surface *ds)113{114if(!list_is_empty(&ds->dirty_list))115list_delinit(&ds->dirty_list);116}117118#endif119120121