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