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];
15 int nr_faces
, l
, f
, pitch
;
17 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
20 if (pt
->target
== PIPE_TEXTURE_3D
) {
21 nr_faces
= pt
->depth
[0];
27 for (l
= 0; l
<= pt
->last_level
; l
++) {
29 pt
->height
[l
] = height
;
34 pitch
= (pitch
+ 63) & ~63;
36 nv40mt
->level
[l
].pitch
= pitch
* pt
->cpp
;
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_screen
*pscreen
, const struct pipe_texture
*pt
)
59 struct pipe_winsys
*ws
= pscreen
->winsys
;
60 struct nv40_miptree
*mt
;
62 mt
= MALLOC(sizeof(struct nv40_miptree
));
66 mt
->base
.refcount
= 1;
67 mt
->base
.screen
= pscreen
;
69 nv40_miptree_layout(mt
);
71 mt
->buffer
= ws
->buffer_create(ws
, 256,
72 PIPE_BUFFER_USAGE_PIXEL
|
73 NOUVEAU_BUFFER_USAGE_TEXTURE
,
84 nv40_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**pt
)
86 struct pipe_winsys
*ws
= pscreen
->winsys
;
87 struct pipe_texture
*mt
= *pt
;
90 if (--mt
->refcount
<= 0) {
91 struct nv40_miptree
*nv40mt
= (struct nv40_miptree
*)mt
;
94 pipe_buffer_reference(ws
, &nv40mt
->buffer
, NULL
);
95 for (l
= 0; l
<= mt
->last_level
; l
++) {
96 if (nv40mt
->level
[l
].image_offset
)
97 FREE(nv40mt
->level
[l
].image_offset
);
104 nv40_miptree_update(struct pipe_context
*pipe
, struct pipe_texture
*mt
,
105 uint face
, uint levels
)
109 static struct pipe_surface
*
110 nv40_miptree_surface(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
111 unsigned face
, unsigned level
, unsigned zslice
)
113 struct pipe_winsys
*ws
= pscreen
->winsys
;
114 struct nv40_miptree
*nv40mt
= (struct nv40_miptree
*)pt
;
115 struct pipe_surface
*ps
;
117 ps
= ws
->surface_alloc(ws
);
120 pipe_buffer_reference(ws
, &ps
->buffer
, nv40mt
->buffer
);
121 ps
->format
= pt
->format
;
123 ps
->width
= pt
->width
[level
];
124 ps
->height
= pt
->height
[level
];
125 ps
->pitch
= nv40mt
->level
[level
].pitch
/ ps
->cpp
;
127 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
128 ps
->offset
= nv40mt
->level
[level
].image_offset
[face
];
130 if (pt
->target
== PIPE_TEXTURE_3D
) {
131 ps
->offset
= nv40mt
->level
[level
].image_offset
[zslice
];
133 ps
->offset
= nv40mt
->level
[level
].image_offset
[0];
140 nv40_init_miptree_functions(struct nv40_context
*nv40
)
142 nv40
->pipe
.texture_update
= nv40_miptree_update
;
146 nv40_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
148 pscreen
->texture_create
= nv40_miptree_create
;
149 pscreen
->texture_release
= nv40_miptree_release
;
150 pscreen
->get_tex_surface
= nv40_miptree_surface
;