1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_util.h"
4 #include "pipe/p_inlines.h"
6 #include "nv40_context.h"
9 nv40_miptree_layout(struct nv40_miptree
*nv40mt
)
11 struct pipe_texture
*pt
= &nv40mt
->base
;
12 boolean swizzled
= FALSE
;
13 uint width
= pt
->width
[0], height
= pt
->height
[0], depth
= pt
->depth
[0];
17 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
20 if (pt
->target
== PIPE_TEXTURE_3D
) {
21 nr_faces
= pt
->depth
[0];
26 for (l
= 0; l
<= pt
->last_level
; l
++) {
28 pt
->height
[l
] = height
;
32 nv40mt
->level
[l
].pitch
= pt
->width
[l
] * pt
->cpp
;
34 nv40mt
->level
[l
].pitch
= pt
->width
[0] * pt
->cpp
;
35 nv40mt
->level
[l
].pitch
= (nv40mt
->level
[l
].pitch
+ 63) & ~63;
37 nv40mt
->level
[l
].image_offset
=
38 CALLOC(nr_faces
, sizeof(unsigned));
40 width
= MAX2(1, width
>> 1);
41 height
= MAX2(1, height
>> 1);
42 depth
= MAX2(1, depth
>> 1);
46 for (f
= 0; f
< nr_faces
; f
++) {
47 for (l
= 0; l
<= pt
->last_level
; l
++) {
48 nv40mt
->level
[l
].image_offset
[f
] = offset
;
49 offset
+= nv40mt
->level
[l
].pitch
* pt
->height
[l
];
53 nv40mt
->total_size
= offset
;
56 static struct pipe_texture
*
57 nv40_miptree_create(struct pipe_context
*pipe
, const struct pipe_texture
*pt
)
59 struct pipe_winsys
*ws
= pipe
->winsys
;
60 struct nv40_miptree
*mt
;
62 mt
= MALLOC(sizeof(struct nv40_miptree
));
66 nv40_miptree_layout(mt
);
68 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
79 nv40_miptree_release(struct pipe_context
*pipe
, struct pipe_texture
**pt
)
81 struct pipe_winsys
*ws
= pipe
->winsys
;
82 struct pipe_texture
*mt
= *pt
;
85 if (--mt
->refcount
<= 0) {
86 struct nv40_miptree
*nv40mt
= (struct nv40_miptree
*)mt
;
89 pipe_buffer_reference(ws
, &nv40mt
->buffer
, NULL
);
90 for (l
= 0; l
<= mt
->last_level
; l
++) {
91 if (nv40mt
->level
[l
].image_offset
)
92 free(nv40mt
->level
[l
].image_offset
);
99 nv40_init_miptree_functions(struct nv40_context
*nv40
)
101 nv40
->pipe
.texture_create
= nv40_miptree_create
;
102 nv40
->pipe
.texture_release
= nv40_miptree_release
;