17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom
97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */
227ec681f3Smrg
237ec681f3Smrg#ifndef _NINE_BASETEXTURE9_H_
247ec681f3Smrg#define _NINE_BASETEXTURE9_H_
257ec681f3Smrg
267ec681f3Smrg#include "device9.h"
277ec681f3Smrg#include "resource9.h"
287ec681f3Smrg#include "util/u_inlines.h"
297ec681f3Smrg#include "util/list.h"
307ec681f3Smrg
317ec681f3Smrgstruct NineBaseTexture9
327ec681f3Smrg{
337ec681f3Smrg    struct NineResource9 base;
347ec681f3Smrg    struct list_head list; /* for update_textures */
357ec681f3Smrg    struct list_head list2; /* for managed_textures */
367ec681f3Smrg
377ec681f3Smrg    /* g3d */
387ec681f3Smrg    struct pipe_sampler_view *view[2]; /* linear and sRGB */
397ec681f3Smrg
407ec681f3Smrg    D3DFORMAT format;
417ec681f3Smrg
427ec681f3Smrg    int16_t bind_count; /* to Device9->state.texture */
437ec681f3Smrg
447ec681f3Smrg    boolean shadow;
457ec681f3Smrg    boolean fetch4_compatible;
467ec681f3Smrg    uint8_t pstype; /* 0: 2D, 1: 1D, 2: CUBE, 3: 3D */
477ec681f3Smrg
487ec681f3Smrg    boolean dirty_mip;
497ec681f3Smrg    D3DTEXTUREFILTERTYPE mipfilter;
507ec681f3Smrg
517ec681f3Smrg    unsigned level_count;
527ec681f3Smrg
537ec681f3Smrg    /* Specific to managed textures */
547ec681f3Smrg    struct {
557ec681f3Smrg        boolean dirty;
567ec681f3Smrg        DWORD lod;
577ec681f3Smrg        DWORD lod_resident;
587ec681f3Smrg    } managed;
597ec681f3Smrg};
607ec681f3Smrgstatic inline struct NineBaseTexture9 *
617ec681f3SmrgNineBaseTexture9( void *data )
627ec681f3Smrg{
637ec681f3Smrg    return (struct NineBaseTexture9 *)data;
647ec681f3Smrg}
657ec681f3Smrg
667ec681f3SmrgHRESULT
677ec681f3SmrgNineBaseTexture9_ctor( struct NineBaseTexture9 *This,
687ec681f3Smrg                       struct NineUnknownParams *pParams,
697ec681f3Smrg                       struct pipe_resource *initResource,
707ec681f3Smrg                       D3DRESOURCETYPE Type,
717ec681f3Smrg                       D3DFORMAT format,
727ec681f3Smrg                       D3DPOOL Pool,
737ec681f3Smrg                       DWORD Usage);
747ec681f3Smrg
757ec681f3Smrgvoid
767ec681f3SmrgNineBaseTexture9_dtor( struct NineBaseTexture9 *This );
777ec681f3Smrg
787ec681f3SmrgDWORD NINE_WINAPI
797ec681f3SmrgNineBaseTexture9_SetLOD( struct NineBaseTexture9 *This,
807ec681f3Smrg                         DWORD LODNew );
817ec681f3Smrg
827ec681f3SmrgDWORD NINE_WINAPI
837ec681f3SmrgNineBaseTexture9_GetLOD( struct NineBaseTexture9 *This );
847ec681f3Smrg
857ec681f3SmrgDWORD NINE_WINAPI
867ec681f3SmrgNineBaseTexture9_GetLevelCount( struct NineBaseTexture9 *This );
877ec681f3Smrg
887ec681f3SmrgHRESULT NINE_WINAPI
897ec681f3SmrgNineBaseTexture9_SetAutoGenFilterType( struct NineBaseTexture9 *This,
907ec681f3Smrg                                       D3DTEXTUREFILTERTYPE FilterType );
917ec681f3Smrg
927ec681f3SmrgD3DTEXTUREFILTERTYPE NINE_WINAPI
937ec681f3SmrgNineBaseTexture9_GetAutoGenFilterType( struct NineBaseTexture9 *This );
947ec681f3Smrg
957ec681f3Smrgvoid NINE_WINAPI
967ec681f3SmrgNineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This );
977ec681f3Smrg
987ec681f3Smrgvoid NINE_WINAPI
997ec681f3SmrgNineBaseTexture9_PreLoad( struct NineBaseTexture9 *This );
1007ec681f3Smrg
1017ec681f3Smrgvoid
1027ec681f3SmrgNineBaseTexture9_UnLoad( struct NineBaseTexture9 *This );
1037ec681f3Smrg
1047ec681f3Smrg/* For D3DPOOL_MANAGED only (after SetLOD change): */
1057ec681f3SmrgHRESULT
1067ec681f3SmrgNineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
1077ec681f3Smrg                                     BOOL CopyData );
1087ec681f3Smrg
1097ec681f3Smrg/* For D3DPOOL_MANAGED only: */
1107ec681f3SmrgHRESULT
1117ec681f3SmrgNineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This );
1127ec681f3Smrg
1137ec681f3SmrgHRESULT
1147ec681f3SmrgNineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This,
1157ec681f3Smrg                                    const int sRGB );
1167ec681f3Smrg
1177ec681f3Smrgstatic inline void
1187ec681f3SmrgNineBaseTexture9_Validate( struct NineBaseTexture9 *This )
1197ec681f3Smrg{
1207ec681f3Smrg    DBG_FLAG(DBG_BASETEXTURE, "This=%p dirty=%i dirty_mip=%i lod=%u/%u\n",
1217ec681f3Smrg             This, This->managed.dirty, This->dirty_mip, This->managed.lod, This->managed.lod_resident);
1227ec681f3Smrg    if ((This->base.pool == D3DPOOL_MANAGED) &&
1237ec681f3Smrg        (This->managed.dirty || This->managed.lod != This->managed.lod_resident))
1247ec681f3Smrg        NineBaseTexture9_UploadSelf(This);
1257ec681f3Smrg    if (This->dirty_mip)
1267ec681f3Smrg        NineBaseTexture9_GenerateMipSubLevels(This);
1277ec681f3Smrg}
1287ec681f3Smrg
1297ec681f3Smrgstatic inline struct pipe_sampler_view *
1307ec681f3SmrgNineBaseTexture9_GetSamplerView( struct NineBaseTexture9 *This, const int sRGB )
1317ec681f3Smrg{
1327ec681f3Smrg    if (!This->view[sRGB])
1337ec681f3Smrg        NineBaseTexture9_UpdateSamplerView(This, sRGB);
1347ec681f3Smrg    return This->view[sRGB];
1357ec681f3Smrg}
1367ec681f3Smrg
1377ec681f3Smrgstatic void inline
1387ec681f3SmrgNineBindTextureToDevice( struct NineDevice9 *device,
1397ec681f3Smrg                         struct NineBaseTexture9 **slot,
1407ec681f3Smrg                         struct NineBaseTexture9 *tex )
1417ec681f3Smrg{
1427ec681f3Smrg    struct NineBaseTexture9 *old = *slot;
1437ec681f3Smrg
1447ec681f3Smrg    if (tex) {
1457ec681f3Smrg        if ((tex->managed.dirty | tex->dirty_mip) && list_is_empty(&tex->list))
1467ec681f3Smrg            list_add(&tex->list, &device->update_textures);
1477ec681f3Smrg
1487ec681f3Smrg        tex->bind_count++;
1497ec681f3Smrg    }
1507ec681f3Smrg    if (old) {
1517ec681f3Smrg        old->bind_count--;
1527ec681f3Smrg        if (!old->bind_count)
1537ec681f3Smrg            list_delinit(&old->list);
1547ec681f3Smrg    }
1557ec681f3Smrg
1567ec681f3Smrg    nine_bind(slot, tex);
1577ec681f3Smrg}
1587ec681f3Smrg
1597ec681f3Smrg#if defined(DEBUG) || !defined(NDEBUG)
1607ec681f3Smrgvoid
1617ec681f3SmrgNineBaseTexture9_Dump( struct NineBaseTexture9 *This );
1627ec681f3Smrg#else
1637ec681f3Smrgstatic inline void
1647ec681f3SmrgNineBaseTexture9_Dump( struct NineBaseTexture9 *This ) { }
1657ec681f3Smrg#endif
1667ec681f3Smrg
1677ec681f3Smrg#define BASETEX_REGISTER_UPDATE(t) do { \
1687ec681f3Smrg    if (((t)->managed.dirty | ((t)->dirty_mip)) && (t)->bind_count) \
1697ec681f3Smrg        if (list_is_empty(&(t)->list)) \
1707ec681f3Smrg            list_add(&(t)->list, &(t)->base.base.device->update_textures); \
1717ec681f3Smrg    } while(0)
1727ec681f3Smrg
1737ec681f3Smrg#endif /* _NINE_BASETEXTURE9_H_ */
174