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
);
35 pitch
= pt
->nblocksx
[l
];
36 pitch
= align_int(pitch
, 64);
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);
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
*pscreen
, const struct pipe_texture
*pt
)
60 struct pipe_winsys
*ws
= pscreen
->winsys
;
61 struct nv30_miptree
*mt
;
63 mt
= MALLOC(sizeof(struct nv30_miptree
));
67 mt
->base
.refcount
= 1;
68 mt
->base
.screen
= pscreen
;
70 nv30_miptree_layout(mt
);
72 mt
->buffer
= ws
->buffer_create(ws
, 256,
73 PIPE_BUFFER_USAGE_PIXEL
|
74 NOUVEAU_BUFFER_USAGE_TEXTURE
,
85 nv30_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**pt
)
87 struct pipe_winsys
*ws
= pscreen
->winsys
;
88 struct pipe_texture
*mt
= *pt
;
91 if (--mt
->refcount
<= 0) {
92 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)mt
;
95 pipe_buffer_reference(ws
, &nv30mt
->buffer
, NULL
);
96 for (l
= 0; l
<= mt
->last_level
; l
++) {
97 if (nv30mt
->level
[l
].image_offset
)
98 FREE(nv30mt
->level
[l
].image_offset
);
104 static struct pipe_surface
*
105 nv30_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
106 unsigned face
, unsigned level
, unsigned zslice
,
109 struct pipe_winsys
*ws
= pscreen
->winsys
;
110 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)pt
;
111 struct pipe_surface
*ps
;
113 ps
= CALLOC_STRUCT(pipe_surface
);
116 pipe_texture_reference(&ps
->texture
, pt
);
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
->block
= pt
->block
;
122 ps
->nblocksx
= pt
->nblocksx
[level
];
123 ps
->nblocksy
= pt
->nblocksy
[level
];
124 ps
->stride
= nv30mt
->level
[level
].pitch
;
126 ps
->status
= PIPE_SURFACE_STATUS_DEFINED
;
128 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
129 ps
->offset
= nv30mt
->level
[level
].image_offset
[face
];
131 if (pt
->target
== PIPE_TEXTURE_3D
) {
132 ps
->offset
= nv30mt
->level
[level
].image_offset
[zslice
];
134 ps
->offset
= nv30mt
->level
[level
].image_offset
[0];
141 nv30_miptree_surface_del(struct pipe_screen
*pscreen
,
142 struct pipe_surface
**psurface
)
144 struct pipe_surface
*ps
= *psurface
;
147 if (--ps
->refcount
> 0)
150 pipe_texture_reference(&ps
->texture
, NULL
);
151 pipe_buffer_reference(pscreen
->winsys
, &ps
->buffer
, NULL
);
156 nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
158 pscreen
->texture_create
= nv30_miptree_create
;
159 pscreen
->texture_release
= nv30_miptree_release
;
160 pscreen
->get_tex_surface
= nv30_miptree_surface_new
;
161 pscreen
->tex_surface_release
= nv30_miptree_surface_del
;