Path: blob/21.2-virgl/src/gallium/frontends/nine/basetexture9.h
4561 views
/*1* Copyright 2011 Joakim Sindholt <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#ifndef _NINE_BASETEXTURE9_H_23#define _NINE_BASETEXTURE9_H_2425#include "device9.h"26#include "resource9.h"27#include "util/u_inlines.h"28#include "util/list.h"2930struct NineBaseTexture931{32struct NineResource9 base;33struct list_head list; /* for update_textures */34struct list_head list2; /* for managed_textures */3536/* g3d */37struct pipe_sampler_view *view[2]; /* linear and sRGB */3839D3DFORMAT format;4041int16_t bind_count; /* to Device9->state.texture */4243boolean shadow;44boolean fetch4_compatible;45uint8_t pstype; /* 0: 2D, 1: 1D, 2: CUBE, 3: 3D */4647boolean dirty_mip;48D3DTEXTUREFILTERTYPE mipfilter;4950unsigned level_count;5152/* Specific to managed textures */53struct {54boolean dirty;55DWORD lod;56DWORD lod_resident;57} managed;58};59static inline struct NineBaseTexture9 *60NineBaseTexture9( void *data )61{62return (struct NineBaseTexture9 *)data;63}6465HRESULT66NineBaseTexture9_ctor( struct NineBaseTexture9 *This,67struct NineUnknownParams *pParams,68struct pipe_resource *initResource,69D3DRESOURCETYPE Type,70D3DFORMAT format,71D3DPOOL Pool,72DWORD Usage);7374void75NineBaseTexture9_dtor( struct NineBaseTexture9 *This );7677DWORD NINE_WINAPI78NineBaseTexture9_SetLOD( struct NineBaseTexture9 *This,79DWORD LODNew );8081DWORD NINE_WINAPI82NineBaseTexture9_GetLOD( struct NineBaseTexture9 *This );8384DWORD NINE_WINAPI85NineBaseTexture9_GetLevelCount( struct NineBaseTexture9 *This );8687HRESULT NINE_WINAPI88NineBaseTexture9_SetAutoGenFilterType( struct NineBaseTexture9 *This,89D3DTEXTUREFILTERTYPE FilterType );9091D3DTEXTUREFILTERTYPE NINE_WINAPI92NineBaseTexture9_GetAutoGenFilterType( struct NineBaseTexture9 *This );9394void NINE_WINAPI95NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This );9697void NINE_WINAPI98NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This );99100void101NineBaseTexture9_UnLoad( struct NineBaseTexture9 *This );102103/* For D3DPOOL_MANAGED only (after SetLOD change): */104HRESULT105NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,106BOOL CopyData );107108/* For D3DPOOL_MANAGED only: */109HRESULT110NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This );111112HRESULT113NineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This,114const int sRGB );115116static inline void117NineBaseTexture9_Validate( struct NineBaseTexture9 *This )118{119DBG_FLAG(DBG_BASETEXTURE, "This=%p dirty=%i dirty_mip=%i lod=%u/%u\n",120This, This->managed.dirty, This->dirty_mip, This->managed.lod, This->managed.lod_resident);121if ((This->base.pool == D3DPOOL_MANAGED) &&122(This->managed.dirty || This->managed.lod != This->managed.lod_resident))123NineBaseTexture9_UploadSelf(This);124if (This->dirty_mip)125NineBaseTexture9_GenerateMipSubLevels(This);126}127128static inline struct pipe_sampler_view *129NineBaseTexture9_GetSamplerView( struct NineBaseTexture9 *This, const int sRGB )130{131if (!This->view[sRGB])132NineBaseTexture9_UpdateSamplerView(This, sRGB);133return This->view[sRGB];134}135136static void inline137NineBindTextureToDevice( struct NineDevice9 *device,138struct NineBaseTexture9 **slot,139struct NineBaseTexture9 *tex )140{141struct NineBaseTexture9 *old = *slot;142143if (tex) {144if ((tex->managed.dirty | tex->dirty_mip) && list_is_empty(&tex->list))145list_add(&tex->list, &device->update_textures);146147tex->bind_count++;148}149if (old) {150old->bind_count--;151if (!old->bind_count)152list_delinit(&old->list);153}154155nine_bind(slot, tex);156}157158#if defined(DEBUG) || !defined(NDEBUG)159void160NineBaseTexture9_Dump( struct NineBaseTexture9 *This );161#else162static inline void163NineBaseTexture9_Dump( struct NineBaseTexture9 *This ) { }164#endif165166#define BASETEX_REGISTER_UPDATE(t) do { \167if (((t)->managed.dirty | ((t)->dirty_mip)) && (t)->bind_count) \168if (list_is_empty(&(t)->list)) \169list_add(&(t)->list, &(t)->base.base.device->update_textures); \170} while(0)171172#endif /* _NINE_BASETEXTURE9_H_ */173174175