1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
5 #include "nv10_context.h"
6 #include "nv10_screen.h"
9 nv10_miptree_layout(struct nv10_miptree
*nv10mt
)
11 struct pipe_texture
*pt
= &nv10mt
->base
;
12 boolean swizzled
= FALSE
;
13 uint width
= pt
->width
[0], height
= pt
->height
[0];
17 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
23 for (l
= 0; l
<= pt
->last_level
; l
++) {
25 pt
->height
[l
] = height
;
26 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
27 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
30 nv10mt
->level
[l
].pitch
= pt
->nblocksx
[l
] * pt
->block
.size
;
32 nv10mt
->level
[l
].pitch
= pt
->nblocksx
[0] * pt
->block
.size
;
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);
43 for (f
= 0; f
< nr_faces
; f
++) {
44 for (l
= 0; l
<= pt
->last_level
; l
++) {
45 nv10mt
->level
[l
].image_offset
[f
] = offset
;
46 offset
+= nv10mt
->level
[l
].pitch
* pt
->height
[l
];
50 nv10mt
->total_size
= offset
;
53 static struct pipe_texture
*
54 nv10_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
56 struct pipe_winsys
*ws
= screen
->winsys
;
57 struct nv10_miptree
*mt
;
59 mt
= MALLOC(sizeof(struct nv10_miptree
));
63 mt
->base
.refcount
= 1;
64 mt
->base
.screen
= screen
;
66 nv10_miptree_layout(mt
);
68 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
79 nv10_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
81 struct pipe_texture
*mt
= *pt
;
84 if (--mt
->refcount
<= 0) {
85 struct nv10_miptree
*nv10mt
= (struct nv10_miptree
*)mt
;
88 pipe_buffer_reference(screen
, &nv10mt
->buffer
, NULL
);
89 for (l
= 0; l
<= mt
->last_level
; l
++) {
90 if (nv10mt
->level
[l
].image_offset
)
91 FREE(nv10mt
->level
[l
].image_offset
);
98 nv10_miptree_update(struct pipe_context
*pipe
, struct pipe_texture
*mt
,
99 uint face
, uint levels
)
104 static struct pipe_surface
*
105 nv10_miptree_surface_get(struct pipe_screen
*screen
, struct pipe_texture
*pt
,
106 unsigned face
, unsigned level
, unsigned zslice
,
109 struct pipe_winsys
*ws
= screen
->winsys
;
110 struct nv10_miptree
*nv10mt
= (struct nv10_miptree
*)pt
;
111 struct pipe_surface
*ps
;
113 ps
= ws
->surface_alloc(ws
);
116 pipe_buffer_reference(screen
, &ps
->buffer
, nv10mt
->buffer
);
117 ps
->format
= pt
->format
;
118 ps
->width
= pt
->width
[level
];
119 ps
->height
= pt
->height
[level
];
120 ps
->block
= pt
->block
;
121 ps
->nblocksx
= pt
->nblocksx
[level
];
122 ps
->nblocksy
= pt
->nblocksy
[level
];
123 ps
->stride
= nv10mt
->level
[level
].pitch
;
125 ps
->winsys
= screen
->winsys
;
127 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
128 ps
->offset
= nv10mt
->level
[level
].image_offset
[face
];
130 ps
->offset
= nv10mt
->level
[level
].image_offset
[0];
137 nv10_miptree_surface_release(struct pipe_screen
*screen
,
138 struct pipe_surface
**surface
)
142 void nv10_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
144 pscreen
->texture_create
= nv10_miptree_create
;
145 pscreen
->texture_release
= nv10_miptree_release
;
146 pscreen
->get_tex_surface
= nv10_miptree_surface_get
;
147 pscreen
->tex_surface_release
= nv10_miptree_surface_release
;