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 "nv10_context.h"
7 #include "nv10_screen.h"
10 nv10_miptree_layout(struct nv10_miptree
*nv10mt
)
12 struct pipe_texture
*pt
= &nv10mt
->base
;
13 boolean swizzled
= FALSE
;
14 uint width
= pt
->width
[0], height
= pt
->height
[0], depth
= pt
->depth
[0];
18 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
24 for (l
= 0; l
<= pt
->last_level
; l
++) {
26 pt
->height
[l
] = height
;
30 nv10mt
->level
[l
].pitch
= pt
->width
[l
] * pt
->cpp
;
32 nv10mt
->level
[l
].pitch
= pt
->width
[0] * pt
->cpp
;
33 nv10mt
->level
[l
].pitch
= (nv10mt
->level
[l
].pitch
+ 63) & ~63;
35 nv10mt
->level
[l
].image_offset
=
36 CALLOC(nr_faces
, sizeof(unsigned));
38 width
= MAX2(1, width
>> 1);
39 height
= MAX2(1, height
>> 1);
40 depth
= MAX2(1, depth
>> 1);
44 for (f
= 0; f
< nr_faces
; f
++) {
45 for (l
= 0; l
<= pt
->last_level
; l
++) {
46 nv10mt
->level
[l
].image_offset
[f
] = offset
;
47 offset
+= nv10mt
->level
[l
].pitch
* pt
->height
[l
];
51 nv10mt
->total_size
= offset
;
54 static struct pipe_texture
*
55 nv10_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
57 struct pipe_winsys
*ws
= screen
->winsys
;
58 struct nv10_miptree
*mt
;
60 mt
= MALLOC(sizeof(struct nv10_miptree
));
64 mt
->base
.refcount
= 1;
65 mt
->base
.screen
= screen
;
67 nv10_miptree_layout(mt
);
69 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
80 nv10_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
82 struct pipe_winsys
*ws
= screen
->winsys
;
83 struct pipe_texture
*mt
= *pt
;
86 if (--mt
->refcount
<= 0) {
87 struct nv10_miptree
*nv10mt
= (struct nv10_miptree
*)mt
;
90 pipe_buffer_reference(ws
, &nv10mt
->buffer
, NULL
);
91 for (l
= 0; l
<= mt
->last_level
; l
++) {
92 if (nv10mt
->level
[l
].image_offset
)
93 FREE(nv10mt
->level
[l
].image_offset
);
100 nv10_miptree_update(struct pipe_context
*pipe
, struct pipe_texture
*mt
,
101 uint face
, uint levels
)
106 static struct pipe_surface
*
107 nv10_miptree_surface_get(struct pipe_screen
*screen
, struct pipe_texture
*pt
,
108 unsigned face
, unsigned level
, unsigned zslice
,
111 struct pipe_winsys
*ws
= screen
->winsys
;
112 struct nv10_miptree
*nv10mt
= (struct nv10_miptree
*)pt
;
113 struct pipe_surface
*ps
;
115 ps
= ws
->surface_alloc(ws
);
118 pipe_buffer_reference(ws
, &ps
->buffer
, nv10mt
->buffer
);
119 ps
->format
= pt
->format
;
121 ps
->width
= pt
->width
[level
];
122 ps
->height
= pt
->height
[level
];
123 ps
->pitch
= nv10mt
->level
[level
].pitch
/ ps
->cpp
;
125 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
126 ps
->offset
= nv10mt
->level
[level
].image_offset
[face
];
128 ps
->offset
= nv10mt
->level
[level
].image_offset
[0];
135 nv10_miptree_surface_release(struct pipe_screen
*screen
,
136 struct pipe_surface
**surface
)
140 void nv10_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
142 pscreen
->texture_create
= nv10_miptree_create
;
143 pscreen
->texture_release
= nv10_miptree_release
;
144 pscreen
->get_tex_surface
= nv10_miptree_surface_get
;
145 pscreen
->tex_surface_release
= nv10_miptree_surface_release
;