st/nine: Do not use NineBaseTexture9 in nine_context
[mesa.git] / src / gallium / state_trackers / nine / basetexture9.c
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 #include "basetexture9.h"
24 #include "device9.h"
25
26 /* For UploadSelf: */
27 #include "texture9.h"
28 #include "cubetexture9.h"
29 #include "volumetexture9.h"
30
31 #ifdef DEBUG
32 #include "nine_pipe.h"
33 #include "nine_dump.h"
34 #endif
35
36 #include "util/u_format.h"
37 #include "util/u_gen_mipmap.h"
38
39 #define DBG_CHANNEL DBG_BASETEXTURE
40
41 HRESULT
42 NineBaseTexture9_ctor( struct NineBaseTexture9 *This,
43 struct NineUnknownParams *pParams,
44 struct pipe_resource *initResource,
45 D3DRESOURCETYPE Type,
46 D3DFORMAT format,
47 D3DPOOL Pool,
48 DWORD Usage)
49 {
50 BOOL alloc = (Pool == D3DPOOL_DEFAULT) && !initResource &&
51 (format != D3DFMT_NULL);
52 HRESULT hr;
53
54 DBG("This=%p, pParams=%p initResource=%p Type=%d format=%d Pool=%d Usage=%d\n",
55 This, pParams, initResource, Type, format, Pool, Usage);
56
57 user_assert(!(Usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) ||
58 Pool == D3DPOOL_DEFAULT, D3DERR_INVALIDCALL);
59 user_assert(!(Usage & D3DUSAGE_DYNAMIC) ||
60 !(Pool == D3DPOOL_MANAGED ||
61 Pool == D3DPOOL_SCRATCH), D3DERR_INVALIDCALL);
62
63 hr = NineResource9_ctor(&This->base, pParams, initResource, alloc, Type, Pool, Usage);
64 if (FAILED(hr))
65 return hr;
66
67 This->format = format;
68 This->mipfilter = (Usage & D3DUSAGE_AUTOGENMIPMAP) ?
69 D3DTEXF_LINEAR : D3DTEXF_NONE;
70 This->managed.lod = 0;
71 This->managed.lod_resident = -1;
72 /* Mark the texture as dirty to trigger first upload when we need the texture,
73 * even if it wasn't set by the application */
74 if (Pool == D3DPOOL_MANAGED)
75 This->managed.dirty = TRUE;
76 /* When a depth buffer is sampled, it is for shadow mapping, except for
77 * D3DFMT_INTZ, D3DFMT_DF16 and D3DFMT_DF24.
78 * In addition D3DFMT_INTZ can be used for both texturing and depth buffering
79 * if z write is disabled. This particular feature may not work for us in
80 * practice because OGL doesn't have that. However apparently it is known
81 * some cards have performance issues with this feature, so real apps
82 * shouldn't use it. */
83 This->shadow = (This->format != D3DFMT_INTZ && This->format != D3DFMT_DF16 &&
84 This->format != D3DFMT_DF24) &&
85 util_format_has_depth(util_format_description(This->base.info.format));
86
87 list_inithead(&This->list);
88 list_inithead(&This->list2);
89 if (Pool == D3DPOOL_MANAGED)
90 list_add(&This->list2, &This->base.base.device->managed_textures);
91
92 return D3D_OK;
93 }
94
95 void
96 NineBaseTexture9_dtor( struct NineBaseTexture9 *This )
97 {
98 DBG("This=%p\n", This);
99
100 pipe_sampler_view_reference(&This->view[0], NULL);
101 pipe_sampler_view_reference(&This->view[1], NULL);
102
103 if (This->list.prev != NULL && This->list.next != NULL)
104 list_del(&This->list);
105 if (This->list2.prev != NULL && This->list2.next != NULL)
106 list_del(&This->list2);
107
108 NineResource9_dtor(&This->base);
109 }
110
111 DWORD NINE_WINAPI
112 NineBaseTexture9_SetLOD( struct NineBaseTexture9 *This,
113 DWORD LODNew )
114 {
115 DWORD old = This->managed.lod;
116 DWORD max_level;
117
118 DBG("This=%p LODNew=%d\n", This, LODNew);
119
120 user_assert(This->base.pool == D3DPOOL_MANAGED, 0);
121
122 max_level = (This->base.usage & D3DUSAGE_AUTOGENMIPMAP) ?
123 0 : This->base.info.last_level;
124 This->managed.lod = MIN2(LODNew, max_level);
125
126 if (This->managed.lod != old && This->bind_count && LIST_IS_EMPTY(&This->list))
127 list_add(&This->list, &This->base.base.device->update_textures);
128
129 return old;
130 }
131
132 DWORD NINE_WINAPI
133 NineBaseTexture9_GetLOD( struct NineBaseTexture9 *This )
134 {
135 DBG("This=%p\n", This);
136
137 return This->managed.lod;
138 }
139
140 DWORD NINE_WINAPI
141 NineBaseTexture9_GetLevelCount( struct NineBaseTexture9 *This )
142 {
143 DBG("This=%p\n", This);
144
145 if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
146 return 1;
147 return This->base.info.last_level + 1;
148 }
149
150 HRESULT NINE_WINAPI
151 NineBaseTexture9_SetAutoGenFilterType( struct NineBaseTexture9 *This,
152 D3DTEXTUREFILTERTYPE FilterType )
153 {
154 DBG("This=%p FilterType=%d\n", This, FilterType);
155
156 if (!(This->base.usage & D3DUSAGE_AUTOGENMIPMAP))
157 return D3D_OK;
158 user_assert(FilterType != D3DTEXF_NONE, D3DERR_INVALIDCALL);
159
160 This->mipfilter = FilterType;
161 This->dirty_mip = TRUE;
162 NineBaseTexture9_GenerateMipSubLevels(This);
163
164 return D3D_OK;
165 }
166
167 D3DTEXTUREFILTERTYPE NINE_WINAPI
168 NineBaseTexture9_GetAutoGenFilterType( struct NineBaseTexture9 *This )
169 {
170 DBG("This=%p\n", This);
171
172 return This->mipfilter;
173 }
174
175 HRESULT
176 NineBaseTexture9_UploadSelf( struct NineBaseTexture9 *This )
177 {
178 HRESULT hr;
179 unsigned last_level = This->base.info.last_level;
180 unsigned l, min_level_dirty = This->managed.lod;
181 BOOL update_lod;
182
183 DBG("This=%p dirty=%i type=%s\n", This, This->managed.dirty,
184 nine_D3DRTYPE_to_str(This->base.type));
185
186 assert(This->base.pool == D3DPOOL_MANAGED);
187
188 if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
189 last_level = 0;
190
191 update_lod = This->managed.lod_resident != This->managed.lod;
192 if (!update_lod && !This->managed.dirty)
193 return D3D_OK;
194
195 /* Allocate a new resource with the correct number of levels,
196 * Mark states for update, and tell the nine surfaces/volumes
197 * their new resource. */
198 if (update_lod) {
199 struct pipe_resource *res;
200
201 DBG("updating LOD from %u to %u ...\n", This->managed.lod_resident, This->managed.lod);
202
203 pipe_sampler_view_reference(&This->view[0], NULL);
204 pipe_sampler_view_reference(&This->view[1], NULL);
205
206 /* Allocate a new resource */
207 hr = NineBaseTexture9_CreatePipeResource(This, This->managed.lod_resident != -1);
208 if (FAILED(hr))
209 return hr;
210 res = This->base.resource;
211
212 if (This->managed.lod_resident == -1) {/* no levels were resident */
213 This->managed.dirty = FALSE; /* We are going to upload everything. */
214 This->managed.lod_resident = This->base.info.last_level + 1;
215 }
216
217 if (This->base.type == D3DRTYPE_TEXTURE) {
218 struct NineTexture9 *tex = NineTexture9(This);
219
220 /* last content (if apply) has been copied to the new resource.
221 * Note: We cannot render to surfaces of managed textures.
222 * Note2: the level argument passed is to get the level offset
223 * right when the texture is uploaded (the texture first level
224 * corresponds to This->managed.lod).
225 * Note3: We don't care about the value passed for the surfaces
226 * before This->managed.lod, negative with this implementation. */
227 for (l = 0; l <= This->base.info.last_level; ++l)
228 NineSurface9_SetResource(tex->surfaces[l], res, l - This->managed.lod);
229 } else
230 if (This->base.type == D3DRTYPE_CUBETEXTURE) {
231 struct NineCubeTexture9 *tex = NineCubeTexture9(This);
232 unsigned z;
233
234 for (l = 0; l <= This->base.info.last_level; ++l) {
235 for (z = 0; z < 6; ++z)
236 NineSurface9_SetResource(tex->surfaces[l * 6 + z],
237 res, l - This->managed.lod);
238 }
239 } else
240 if (This->base.type == D3DRTYPE_VOLUMETEXTURE) {
241 struct NineVolumeTexture9 *tex = NineVolumeTexture9(This);
242
243 for (l = 0; l <= This->base.info.last_level; ++l)
244 NineVolume9_SetResource(tex->volumes[l], res, l - This->managed.lod);
245 } else {
246 assert(!"invalid texture type");
247 }
248
249 /* We are going to fully upload the new levels,
250 * no need to update dirty parts of the texture for these */
251 min_level_dirty = MAX2(This->managed.lod, This->managed.lod_resident);
252 }
253
254 /* Update dirty parts of the texture */
255 if (This->managed.dirty) {
256 if (This->base.type == D3DRTYPE_TEXTURE) {
257 struct NineTexture9 *tex = NineTexture9(This);
258 struct pipe_box box;
259 box.z = 0;
260 box.depth = 1;
261
262 DBG("TEXTURE: dirty rect=(%u,%u) (%ux%u)\n",
263 tex->dirty_rect.x, tex->dirty_rect.y,
264 tex->dirty_rect.width, tex->dirty_rect.height);
265
266 /* Note: for l < min_level_dirty, the resource is
267 * either non-existing (and thus will be entirely re-uploaded
268 * if the lod changes) or going to have a full upload */
269 if (tex->dirty_rect.width) {
270 for (l = min_level_dirty; l <= last_level; ++l) {
271 u_box_minify_2d(&box, &tex->dirty_rect, l);
272 NineSurface9_UploadSelf(tex->surfaces[l], &box);
273 }
274 memset(&tex->dirty_rect, 0, sizeof(tex->dirty_rect));
275 tex->dirty_rect.depth = 1;
276 }
277 } else
278 if (This->base.type == D3DRTYPE_CUBETEXTURE) {
279 struct NineCubeTexture9 *tex = NineCubeTexture9(This);
280 unsigned z;
281 struct pipe_box box;
282 box.z = 0;
283 box.depth = 1;
284
285 for (z = 0; z < 6; ++z) {
286 DBG("FACE[%u]: dirty rect=(%u,%u) (%ux%u)\n", z,
287 tex->dirty_rect[z].x, tex->dirty_rect[z].y,
288 tex->dirty_rect[z].width, tex->dirty_rect[z].height);
289
290 if (tex->dirty_rect[z].width) {
291 for (l = min_level_dirty; l <= last_level; ++l) {
292 u_box_minify_2d(&box, &tex->dirty_rect[z], l);
293 NineSurface9_UploadSelf(tex->surfaces[l * 6 + z], &box);
294 }
295 memset(&tex->dirty_rect[z], 0, sizeof(tex->dirty_rect[z]));
296 tex->dirty_rect[z].depth = 1;
297 }
298 }
299 } else
300 if (This->base.type == D3DRTYPE_VOLUMETEXTURE) {
301 struct NineVolumeTexture9 *tex = NineVolumeTexture9(This);
302 struct pipe_box box;
303
304 DBG("VOLUME: dirty_box=(%u,%u,%u) (%ux%ux%u)\n",
305 tex->dirty_box.x, tex->dirty_box.y, tex->dirty_box.y,
306 tex->dirty_box.width, tex->dirty_box.height, tex->dirty_box.depth);
307
308 if (tex->dirty_box.width) {
309 for (l = min_level_dirty; l <= last_level; ++l) {
310 u_box_minify_3d(&box, &tex->dirty_box, l);
311 NineVolume9_UploadSelf(tex->volumes[l], &box);
312 }
313 memset(&tex->dirty_box, 0, sizeof(tex->dirty_box));
314 }
315 } else {
316 assert(!"invalid texture type");
317 }
318 This->managed.dirty = FALSE;
319 }
320
321 /* Upload the new levels */
322 if (update_lod) {
323 if (This->base.type == D3DRTYPE_TEXTURE) {
324 struct NineTexture9 *tex = NineTexture9(This);
325 struct pipe_box box;
326
327 box.x = box.y = box.z = 0;
328 box.depth = 1;
329 for (l = This->managed.lod; l < This->managed.lod_resident; ++l) {
330 box.width = u_minify(This->base.info.width0, l);
331 box.height = u_minify(This->base.info.height0, l);
332 NineSurface9_UploadSelf(tex->surfaces[l], &box);
333 }
334 } else
335 if (This->base.type == D3DRTYPE_CUBETEXTURE) {
336 struct NineCubeTexture9 *tex = NineCubeTexture9(This);
337 struct pipe_box box;
338 unsigned z;
339
340 box.x = box.y = box.z = 0;
341 box.depth = 1;
342 for (l = This->managed.lod; l < This->managed.lod_resident; ++l) {
343 box.width = u_minify(This->base.info.width0, l);
344 box.height = u_minify(This->base.info.height0, l);
345 for (z = 0; z < 6; ++z)
346 NineSurface9_UploadSelf(tex->surfaces[l * 6 + z], &box);
347 }
348 } else
349 if (This->base.type == D3DRTYPE_VOLUMETEXTURE) {
350 struct NineVolumeTexture9 *tex = NineVolumeTexture9(This);
351 struct pipe_box box;
352
353 box.x = box.y = box.z = 0;
354 for (l = This->managed.lod; l < This->managed.lod_resident; ++l) {
355 box.width = u_minify(This->base.info.width0, l);
356 box.height = u_minify(This->base.info.height0, l);
357 box.depth = u_minify(This->base.info.depth0, l);
358 NineVolume9_UploadSelf(tex->volumes[l], &box);
359 }
360 } else {
361 assert(!"invalid texture type");
362 }
363
364 This->managed.lod_resident = This->managed.lod;
365 }
366
367 if (This->base.usage & D3DUSAGE_AUTOGENMIPMAP)
368 This->dirty_mip = TRUE;
369
370 /* Set again the textures currently bound to update the texture data */
371 if (This->bind_count) {
372 struct nine_state *state = &This->base.base.device->state;
373 unsigned s;
374 for (s = 0; s < NINE_MAX_SAMPLERS; ++s)
375 /* Dirty tracking is done in device9 state, not nine_context. */
376 if (state->texture[s] == This)
377 nine_context_set_texture(This->base.base.device, s, This);
378 }
379
380 DBG("DONE, generate mip maps = %i\n", This->dirty_mip);
381 return D3D_OK;
382 }
383
384 void NINE_WINAPI
385 NineBaseTexture9_GenerateMipSubLevels( struct NineBaseTexture9 *This )
386 {
387 struct pipe_context *pipe;
388 struct pipe_resource *resource;
389 unsigned base_level = 0;
390 unsigned last_level = This->base.info.last_level - This->managed.lod;
391 unsigned first_layer = 0;
392 unsigned last_layer;
393 unsigned filter = This->mipfilter == D3DTEXF_POINT ? PIPE_TEX_FILTER_NEAREST
394 : PIPE_TEX_FILTER_LINEAR;
395 DBG("This=%p\n", This);
396
397 if (This->base.pool == D3DPOOL_MANAGED)
398 NineBaseTexture9_UploadSelf(This);
399 if (!This->dirty_mip)
400 return;
401 if (This->managed.lod) {
402 ERR("AUTOGENMIPMAP if level 0 is not resident not supported yet !\n");
403 return;
404 }
405
406 if (!This->view[0])
407 NineBaseTexture9_UpdateSamplerView(This, 0);
408
409 last_layer = util_max_layer(This->view[0]->texture, base_level);
410
411 resource = This->base.resource;
412
413 pipe = NineDevice9_GetPipe(This->base.base.device);
414 util_gen_mipmap(pipe, resource,
415 resource->format, base_level, last_level,
416 first_layer, last_layer, filter);
417
418 This->dirty_mip = FALSE;
419 }
420
421 HRESULT
422 NineBaseTexture9_CreatePipeResource( struct NineBaseTexture9 *This,
423 BOOL CopyData )
424 {
425 struct pipe_context *pipe;
426 struct pipe_screen *screen = This->base.info.screen;
427 struct pipe_resource templ;
428 unsigned l, m;
429 struct pipe_resource *res;
430 struct pipe_resource *old = This->base.resource;
431
432 DBG("This=%p lod=%u last_level=%u\n", This,
433 This->managed.lod, This->base.info.last_level);
434
435 assert(This->base.pool == D3DPOOL_MANAGED);
436
437 templ = This->base.info;
438
439 if (This->managed.lod) {
440 templ.width0 = u_minify(templ.width0, This->managed.lod);
441 templ.height0 = u_minify(templ.height0, This->managed.lod);
442 templ.depth0 = u_minify(templ.depth0, This->managed.lod);
443 }
444 templ.last_level = This->base.info.last_level - This->managed.lod;
445
446 if (old) {
447 /* LOD might have changed. */
448 if (old->width0 == templ.width0 &&
449 old->height0 == templ.height0 &&
450 old->depth0 == templ.depth0)
451 return D3D_OK;
452 }
453
454 res = screen->resource_create(screen, &templ);
455 if (!res)
456 return D3DERR_OUTOFVIDEOMEMORY;
457 This->base.resource = res;
458 pipe = NineDevice9_GetPipe(This->base.base.device);
459
460 if (old && CopyData) { /* Don't return without releasing old ! */
461 struct pipe_box box;
462 box.x = 0;
463 box.y = 0;
464 box.z = 0;
465
466 l = (This->managed.lod < This->managed.lod_resident) ? This->managed.lod_resident - This->managed.lod : 0;
467 m = (This->managed.lod < This->managed.lod_resident) ? 0 : This->managed.lod - This->managed.lod_resident;
468
469 box.width = u_minify(templ.width0, l);
470 box.height = u_minify(templ.height0, l);
471 box.depth = u_minify(templ.depth0, l);
472
473 for (; l <= templ.last_level; ++l, ++m) {
474 pipe->resource_copy_region(pipe,
475 res, l, 0, 0, 0,
476 old, m, &box);
477 box.width = u_minify(box.width, 1);
478 box.height = u_minify(box.height, 1);
479 box.depth = u_minify(box.depth, 1);
480 }
481 }
482 pipe_resource_reference(&old, NULL);
483
484 return D3D_OK;
485 }
486
487 #define SWIZZLE_TO_REPLACE(s) (s == PIPE_SWIZZLE_0 || \
488 s == PIPE_SWIZZLE_1 || \
489 s == PIPE_SWIZZLE_NONE)
490
491 HRESULT
492 NineBaseTexture9_UpdateSamplerView( struct NineBaseTexture9 *This,
493 const int sRGB )
494 {
495 const struct util_format_description *desc;
496 struct pipe_context *pipe;
497 struct pipe_screen *screen = NineDevice9_GetScreen(This->base.base.device);
498 struct pipe_resource *resource = This->base.resource;
499 struct pipe_sampler_view templ;
500 enum pipe_format srgb_format;
501 unsigned i;
502 uint8_t swizzle[4];
503
504 DBG("This=%p sRGB=%d\n", This, sRGB);
505
506 if (unlikely(!resource)) {
507 if (unlikely(This->format == D3DFMT_NULL))
508 return D3D_OK;
509 NineBaseTexture9_Dump(This);
510 }
511 assert(resource);
512
513 pipe_sampler_view_reference(&This->view[sRGB], NULL);
514
515 swizzle[0] = PIPE_SWIZZLE_X;
516 swizzle[1] = PIPE_SWIZZLE_Y;
517 swizzle[2] = PIPE_SWIZZLE_Z;
518 swizzle[3] = PIPE_SWIZZLE_W;
519 desc = util_format_description(resource->format);
520 if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
521 /* msdn doc is incomplete here and wrong.
522 * The only formats that can be read directly here
523 * are DF16, DF24 and INTZ.
524 * Tested on win the swizzle is
525 * R = depth, G = B = 0, A = 1 for DF16 and DF24
526 * R = G = B = A = depth for INTZ
527 * For the other ZS formats that can't be read directly
528 * but can be used as shadow map, the result is duplicated on
529 * all channel */
530 if (This->format == D3DFMT_DF16 ||
531 This->format == D3DFMT_DF24) {
532 swizzle[1] = PIPE_SWIZZLE_0;
533 swizzle[2] = PIPE_SWIZZLE_0;
534 swizzle[3] = PIPE_SWIZZLE_1;
535 } else {
536 swizzle[1] = PIPE_SWIZZLE_X;
537 swizzle[2] = PIPE_SWIZZLE_X;
538 swizzle[3] = PIPE_SWIZZLE_X;
539 }
540 } else if (resource->format == PIPE_FORMAT_RGTC2_UNORM) {
541 swizzle[0] = PIPE_SWIZZLE_Y;
542 swizzle[1] = PIPE_SWIZZLE_X;
543 swizzle[2] = PIPE_SWIZZLE_1;
544 swizzle[3] = PIPE_SWIZZLE_1;
545 } else if (resource->format != PIPE_FORMAT_A8_UNORM &&
546 resource->format != PIPE_FORMAT_RGTC1_UNORM) {
547 /* exceptions:
548 * A8 should have 0.0 as default values for RGB.
549 * ATI1/RGTC1 should be r 0 0 1 (tested on windows).
550 * It is already what gallium does. All the other ones
551 * should have 1.0 for non-defined values */
552 for (i = 0; i < 4; i++) {
553 if (SWIZZLE_TO_REPLACE(desc->swizzle[i]))
554 swizzle[i] = PIPE_SWIZZLE_1;
555 }
556 }
557
558 /* if requested and supported, convert to the sRGB format */
559 srgb_format = util_format_srgb(resource->format);
560 if (sRGB && srgb_format != PIPE_FORMAT_NONE &&
561 screen->is_format_supported(screen, srgb_format,
562 resource->target, 0, resource->bind))
563 templ.format = srgb_format;
564 else
565 templ.format = resource->format;
566 templ.u.tex.first_layer = 0;
567 templ.u.tex.last_layer = resource->target == PIPE_TEXTURE_3D ?
568 resource->depth0 - 1 : resource->array_size - 1;
569 templ.u.tex.first_level = 0;
570 templ.u.tex.last_level = resource->last_level;
571 templ.swizzle_r = swizzle[0];
572 templ.swizzle_g = swizzle[1];
573 templ.swizzle_b = swizzle[2];
574 templ.swizzle_a = swizzle[3];
575 templ.target = resource->target;
576
577 pipe = NineDevice9_GetPipe(This->base.base.device);
578 This->view[sRGB] = pipe->create_sampler_view(pipe, resource, &templ);
579
580 DBG("sampler view = %p(resource = %p)\n", This->view[sRGB], resource);
581
582 return This->view ? D3D_OK : D3DERR_DRIVERINTERNALERROR;
583 }
584
585 void NINE_WINAPI
586 NineBaseTexture9_PreLoad( struct NineBaseTexture9 *This )
587 {
588 DBG("This=%p\n", This);
589
590 if (This->base.pool == D3DPOOL_MANAGED)
591 NineBaseTexture9_UploadSelf(This);
592 }
593
594 void
595 NineBaseTexture9_UnLoad( struct NineBaseTexture9 *This )
596 {
597 if (This->base.pool != D3DPOOL_MANAGED ||
598 This->managed.lod_resident == -1)
599 return;
600
601 pipe_resource_reference(&This->base.resource, NULL);
602 This->managed.lod_resident = -1;
603 This->managed.dirty = TRUE;
604
605 /* If the texture is bound, we have to re-upload it */
606 BASETEX_REGISTER_UPDATE(This);
607 }
608
609 #ifdef DEBUG
610 void
611 NineBaseTexture9_Dump( struct NineBaseTexture9 *This )
612 {
613 DBG("\nNineBaseTexture9(%p->NULL/%p): Pool=%s Type=%s Usage=%s\n"
614 "Format=%s Dims=%ux%ux%u/%u LastLevel=%u Lod=%u(%u)\n", This,
615 This->base.resource,
616 nine_D3DPOOL_to_str(This->base.pool),
617 nine_D3DRTYPE_to_str(This->base.type),
618 nine_D3DUSAGE_to_str(This->base.usage),
619 d3dformat_to_string(This->format),
620 This->base.info.width0, This->base.info.height0, This->base.info.depth0,
621 This->base.info.array_size, This->base.info.last_level,
622 This->managed.lod, This->managed.lod_resident);
623 }
624 #endif /* DEBUG */