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 "device9.h"
27 #include "resource9.h"
28 #include "util/u_inlines.h"
29 #include "util/list.h"
30
31 struct NineBaseTexture9
32 {
33 struct NineResource9 base;
34 struct list_head list; /* for update_textures */
35 struct list_head list2; /* for managed_textures */
36
37 /* g3d */
38 struct pipe_sampler_view *view[2]; /* linear and sRGB */
39
40 D3DFORMAT format;
41
42 int16_t bind_count; /* to Device9->state.texture */
43
44 boolean shadow;
45 boolean fetch4_compatible;
46 uint8_t pstype; /* 0: 2D, 1: 1D, 2: CUBE, 3: 3D */
47
48 boolean dirty_mip;
49 D3DTEXTUREFILTERTYPE mipfilter;
50
51 unsigned level_count;
52
53 /* Specific to managed textures */
54 struct {
55 boolean dirty;
56 DWORD lod;
57 DWORD lod_resident;
58 } managed;
59 };
60 static inline struct NineBaseTexture9 *
NineBaseTexture9(void * data)61 NineBaseTexture9( void *data )
62 {
63 return (struct NineBaseTexture9 *)data;
64 }
65
66 HRESULT
67 NineBaseTexture9_ctor( struct NineBaseTexture9 *This,
68 struct NineUnknownParams *pParams,
69 struct pipe_resource *initResource,
70 D3DRESOURCETYPE Type,
71 D3DFORMAT format,
72 D3DPOOL Pool,
73 DWORD Usage);
74
75 void
76 NineBaseTexture9_dtor( struct NineBaseTexture9 *This );
77
78 DWORD NINE_WINAPI
79 NineBaseTexture9_SetLOD( struct NineBaseTexture9 *This,
80 DWORD LODNew );
81
82 DWORD NINE_WINAPI
83 NineBaseTexture9_GetLOD( struct NineBaseTexture9 *This );
84
85 DWORD NINE_WINAPI
86 NineBaseTexture9_GetLevelCount( struct NineBaseTexture9 *This );
87
88 HRESULT NINE_WINAPI
89 NineBaseTexture9_SetAutoGenFilterType( struct NineBaseTexture9 *This,
90 D3DTEXTUREFILTERTYPE FilterType );
91
92 D3DTEXTUREFILTERTYPE NINE_WINAPI
93 NineBaseTexture9_GetAutoGenFilterType( struct NineBaseTexture9 *This );
94
95 void NINE_WINAPI
96 NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This );
97
98 void NINE_WINAPI
99 NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This );
100
101 void
102 NineBaseTexture9_UnLoad( struct NineBaseTexture9 *This );
103
104 /* For D3DPOOL_MANAGED only (after SetLOD change): */
105 HRESULT
106 NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
107 BOOL CopyData );
108
109 /* For D3DPOOL_MANAGED only: */
110 HRESULT
111 NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This );
112
113 HRESULT
114 NineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This,
115 const int sRGB );
116
117 static inline void
NineBaseTexture9_Validate(struct NineBaseTexture9 * This)118 NineBaseTexture9_Validate( struct NineBaseTexture9 *This )
119 {
120 DBG_FLAG(DBG_BASETEXTURE, "This=%p dirty=%i dirty_mip=%i lod=%u/%u\n",
121 This, This->managed.dirty, This->dirty_mip, This->managed.lod, This->managed.lod_resident);
122 if ((This->base.pool == D3DPOOL_MANAGED) &&
123 (This->managed.dirty || This->managed.lod != This->managed.lod_resident))
124 NineBaseTexture9_UploadSelf(This);
125 if (This->dirty_mip)
126 NineBaseTexture9_GenerateMipSubLevels(This);
127 }
128
129 static inline struct pipe_sampler_view *
NineBaseTexture9_GetSamplerView(struct NineBaseTexture9 * This,const int sRGB)130 NineBaseTexture9_GetSamplerView( struct NineBaseTexture9 *This, const int sRGB )
131 {
132 if (!This->view[sRGB])
133 NineBaseTexture9_UpdateSamplerView(This, sRGB);
134 return This->view[sRGB];
135 }
136
137 static void inline
NineBindTextureToDevice(struct NineDevice9 * device,struct NineBaseTexture9 ** slot,struct NineBaseTexture9 * tex)138 NineBindTextureToDevice( struct NineDevice9 *device,
139 struct NineBaseTexture9 **slot,
140 struct NineBaseTexture9 *tex )
141 {
142 struct NineBaseTexture9 *old = *slot;
143
144 if (tex) {
145 if ((tex->managed.dirty | tex->dirty_mip) && list_is_empty(&tex->list))
146 list_add(&tex->list, &device->update_textures);
147
148 tex->bind_count++;
149 }
150 if (old) {
151 old->bind_count--;
152 if (!old->bind_count)
153 list_delinit(&old->list);
154 }
155
156 nine_bind(slot, tex);
157 }
158
159 #if defined(DEBUG) || !defined(NDEBUG)
160 void
161 NineBaseTexture9_Dump( struct NineBaseTexture9 *This );
162 #else
163 static inline void
NineBaseTexture9_Dump(struct NineBaseTexture9 * This)164 NineBaseTexture9_Dump( struct NineBaseTexture9 *This ) { }
165 #endif
166
167 #define BASETEX_REGISTER_UPDATE(t) do { \
168 if (((t)->managed.dirty | ((t)->dirty_mip)) && (t)->bind_count) \
169 if (list_is_empty(&(t)->list)) \
170 list_add(&(t)->list, &(t)->base.base.device->update_textures); \
171 } while(0)
172
173 #endif /* _NINE_BASETEXTURE9_H_ */
174