gallium/ttn: add TXQ support (v2)
[mesa.git] / src / gallium / state_trackers / nine / basetexture9.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef _NINE_BASETEXTURE9_H_
24 #define _NINE_BASETEXTURE9_H_
25
26 #include "resource9.h"
27 #include "util/u_inlines.h"
28 #include "util/u_double_list.h"
29
30 struct NineBaseTexture9
31 {
32 struct NineResource9 base;
33 struct list_head list;
34
35 /* g3d */
36 struct pipe_context *pipe;
37 struct pipe_sampler_view *view[2]; /* linear and sRGB */
38
39 D3DFORMAT format;
40
41 D3DTEXTUREFILTERTYPE mipfilter;
42 DWORD lod;
43 DWORD lod_resident;
44
45 int16_t bind_count; /* to Device9->state.texture */
46
47 boolean shadow;
48 uint8_t pstype; /* 0: 2D, 1: 1D, 2: CUBE, 3: 3D */
49
50 boolean dirty;
51 boolean dirty_mip;
52 };
53 static INLINE struct NineBaseTexture9 *
54 NineBaseTexture9( void *data )
55 {
56 return (struct NineBaseTexture9 *)data;
57 }
58
59 HRESULT
60 NineBaseTexture9_ctor( struct NineBaseTexture9 *This,
61 struct NineUnknownParams *pParams,
62 struct pipe_resource *initResource,
63 D3DRESOURCETYPE Type,
64 D3DFORMAT format,
65 D3DPOOL Pool,
66 DWORD Usage);
67
68 void
69 NineBaseTexture9_dtor( struct NineBaseTexture9 *This );
70
71 DWORD WINAPI
72 NineBaseTexture9_SetLOD( struct NineBaseTexture9 *This,
73 DWORD LODNew );
74
75 DWORD WINAPI
76 NineBaseTexture9_GetLOD( struct NineBaseTexture9 *This );
77
78 DWORD WINAPI
79 NineBaseTexture9_GetLevelCount( struct NineBaseTexture9 *This );
80
81 HRESULT WINAPI
82 NineBaseTexture9_SetAutoGenFilterType( struct NineBaseTexture9 *This,
83 D3DTEXTUREFILTERTYPE FilterType );
84
85 D3DTEXTUREFILTERTYPE WINAPI
86 NineBaseTexture9_GetAutoGenFilterType( struct NineBaseTexture9 *This );
87
88 void WINAPI
89 NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This );
90
91 void WINAPI
92 NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This );
93
94 /* For D3DPOOL_MANAGED only (after SetLOD change): */
95 HRESULT
96 NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
97 BOOL CopyData );
98
99 /* For D3DPOOL_MANAGED only: */
100 HRESULT
101 NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This );
102
103 HRESULT
104 NineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This,
105 const int sRGB );
106
107 static INLINE void
108 NineBaseTexture9_Validate( struct NineBaseTexture9 *This )
109 {
110 DBG_FLAG(DBG_BASETEXTURE, "This=%p dirty=%i dirty_mip=%i lod=%u/%u\n",
111 This, This->dirty, This->dirty_mip, This->lod, This->lod_resident);
112 if ((This->base.pool == D3DPOOL_MANAGED) &&
113 (This->dirty || This->lod != This->lod_resident))
114 NineBaseTexture9_UploadSelf(This);
115 if (This->dirty_mip)
116 NineBaseTexture9_GenerateMipSubLevels(This);
117 }
118
119 static INLINE struct pipe_sampler_view *
120 NineBaseTexture9_GetSamplerView( struct NineBaseTexture9 *This, const int sRGB )
121 {
122 if (!This->view[sRGB])
123 NineBaseTexture9_UpdateSamplerView(This, sRGB);
124 return This->view[sRGB];
125 }
126
127 #ifdef DEBUG
128 void
129 NineBaseTexture9_Dump( struct NineBaseTexture9 *This );
130 #else
131 static INLINE void
132 NineBaseTexture9_Dump( struct NineBaseTexture9 *This ) { }
133 #endif
134
135 #define BASETEX_REGISTER_UPDATE(t) do { \
136 if (((t)->dirty | ((t)->dirty_mip)) && (t)->base.base.bind) \
137 if (LIST_IS_EMPTY(&(t)->list)) \
138 list_add(&(t)->list, &(t)->base.base.device->update_textures); \
139 } while(0)
140
141 #endif /* _NINE_BASETEXTURE9_H_ */