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 "nv30_context.h"
9 nv30_miptree_layout(struct nv30_miptree
*nv30mt
)
11 struct pipe_texture
*pt
= &nv30mt
->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
;
31 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
32 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
36 pitch
= (pitch
+ 63) & ~63;
38 nv30mt
->level
[l
].pitch
= pitch
* pt
->block
.size
;
39 nv30mt
->level
[l
].image_offset
=
40 CALLOC(nr_faces
, sizeof(unsigned));
42 width
= MAX2(1, width
>> 1);
43 height
= MAX2(1, height
>> 1);
44 depth
= MAX2(1, depth
>> 1);
48 for (f
= 0; f
< nr_faces
; f
++) {
49 for (l
= 0; l
<= pt
->last_level
; l
++) {
50 nv30mt
->level
[l
].image_offset
[f
] = offset
;
51 offset
+= nv30mt
->level
[l
].pitch
* pt
->height
[l
];
55 nv30mt
->total_size
= offset
;
58 static struct pipe_texture
*
59 nv30_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
61 struct pipe_winsys
*ws
= pscreen
->winsys
;
62 struct nv30_miptree
*mt
;
64 mt
= MALLOC(sizeof(struct nv30_miptree
));
68 mt
->base
.refcount
= 1;
69 mt
->base
.screen
= pscreen
;
71 nv30_miptree_layout(mt
);
73 mt
->buffer
= ws
->buffer_create(ws
, 256,
74 PIPE_BUFFER_USAGE_PIXEL
|
75 NOUVEAU_BUFFER_USAGE_TEXTURE
,
86 nv30_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**pt
)
88 struct pipe_winsys
*ws
= pscreen
->winsys
;
89 struct pipe_texture
*mt
= *pt
;
92 if (--mt
->refcount
<= 0) {
93 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)mt
;
96 pipe_buffer_reference(ws
, &nv30mt
->buffer
, NULL
);
97 for (l
= 0; l
<= mt
->last_level
; l
++) {
98 if (nv30mt
->level
[l
].image_offset
)
99 FREE(nv30mt
->level
[l
].image_offset
);
105 static struct pipe_surface
*
106 nv30_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
107 unsigned face
, unsigned level
, unsigned zslice
,
110 struct pipe_winsys
*ws
= pscreen
->winsys
;
111 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)pt
;
112 struct pipe_surface
*ps
;
114 ps
= ws
->surface_alloc(ws
);
117 pipe_buffer_reference(ws
, &ps
->buffer
, nv30mt
->buffer
);
118 ps
->format
= pt
->format
;
119 ps
->width
= pt
->width
[level
];
120 ps
->height
= pt
->height
[level
];
121 ps
->nblocksx
= pt
->nblocksx
[level
];
122 ps
->nblocksy
= pt
->nblocksy
[level
];
123 ps
->block
= pt
->block
;
124 ps
->stride
= nv30mt
->level
[level
].pitch
;
126 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
127 ps
->offset
= nv30mt
->level
[level
].image_offset
[face
];
129 if (pt
->target
== PIPE_TEXTURE_3D
) {
130 ps
->offset
= nv30mt
->level
[level
].image_offset
[zslice
];
132 ps
->offset
= nv30mt
->level
[level
].image_offset
[0];
139 nv30_miptree_surface_del(struct pipe_screen
*pscreen
,
140 struct pipe_surface
**psurface
)
145 nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
147 pscreen
->texture_create
= nv30_miptree_create
;
148 pscreen
->texture_release
= nv30_miptree_release
;
149 pscreen
->get_tex_surface
= nv30_miptree_surface_new
;
150 pscreen
->tex_surface_release
= nv30_miptree_surface_del
;