f5659353ea555a64735db73d4ce6297d5a4c02d9
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"
7 #include "nv30_screen.h"
10 nv30_miptree_layout(struct nv30_miptree
*nv30mt
)
12 struct pipe_texture
*pt
= &nv30mt
->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
) {
21 if (pt
->target
== PIPE_TEXTURE_3D
) {
22 nr_faces
= pt
->depth
[0];
27 for (l
= 0; l
<= pt
->last_level
; l
++) {
29 pt
->height
[l
] = height
;
33 nv30mt
->level
[l
].pitch
= pt
->width
[l
] * pt
->cpp
;
35 nv30mt
->level
[l
].pitch
= pt
->width
[0] * pt
->cpp
;
36 nv30mt
->level
[l
].pitch
= (nv30mt
->level
[l
].pitch
+ 63) & ~63;
38 nv30mt
->level
[l
].image_offset
=
39 CALLOC(nr_faces
, sizeof(unsigned));
41 width
= MAX2(1, width
>> 1);
42 height
= MAX2(1, height
>> 1);
43 depth
= MAX2(1, depth
>> 1);
47 for (f
= 0; f
< nr_faces
; f
++) {
48 for (l
= 0; l
<= pt
->last_level
; l
++) {
49 nv30mt
->level
[l
].image_offset
[f
] = offset
;
50 offset
+= nv30mt
->level
[l
].pitch
* pt
->height
[l
];
54 nv30mt
->total_size
= offset
;
57 static struct pipe_texture
*
58 nv30_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
60 struct pipe_winsys
*ws
= screen
->winsys
;
61 struct nv30_miptree
*mt
;
63 mt
= MALLOC(sizeof(struct nv30_miptree
));
67 mt
->base
.refcount
= 1;
68 mt
->base
.screen
= screen
;
70 nv30_miptree_layout(mt
);
72 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
83 nv30_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
85 struct pipe_winsys
*ws
= screen
->winsys
;
86 struct pipe_texture
*mt
= *pt
;
89 if (--mt
->refcount
<= 0) {
90 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)mt
;
93 pipe_buffer_reference(ws
, &nv30mt
->buffer
, NULL
);
94 for (l
= 0; l
<= mt
->last_level
; l
++) {
95 if (nv30mt
->level
[l
].image_offset
)
96 free(nv30mt
->level
[l
].image_offset
);
103 nv30_miptree_update(struct pipe_context
*pipe
, struct pipe_texture
*mt
)
107 static struct pipe_surface
*
108 nv30_miptree_surface_get(struct pipe_screen
*screen
, struct pipe_texture
*pt
,
109 unsigned face
, unsigned level
, unsigned zslice
)
111 struct pipe_winsys
*ws
= screen
->winsys
;
112 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)pt
;
113 struct pipe_surface
*ps
;
115 ps
= ws
->surface_alloc(ws
);
118 pipe_buffer_reference(ws
, &ps
->buffer
, nv30mt
->buffer
);
119 ps
->format
= pt
->format
;
121 ps
->width
= pt
->width
[level
];
122 ps
->height
= pt
->height
[level
];
123 ps
->pitch
= nv30mt
->level
[level
].pitch
/ ps
->cpp
;
125 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
126 ps
->offset
= nv30mt
->level
[level
].image_offset
[face
];
128 if (pt
->target
== PIPE_TEXTURE_3D
) {
129 ps
->offset
= nv30mt
->level
[level
].image_offset
[zslice
];
131 ps
->offset
= nv30mt
->level
[level
].image_offset
[0];
138 nv30_init_miptree_functions(struct nv30_context
*nv30
)
140 nv30
->pipe
.texture_update
= nv30_miptree_update
;
144 nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
146 pscreen
->texture_create
= nv30_miptree_create
;
147 pscreen
->texture_release
= nv30_miptree_release
;
148 pscreen
->get_tex_surface
= nv30_miptree_surface_get
;