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_blanket(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
,
55 const unsigned *stride
, struct pipe_buffer
*pb
)
57 struct nv10_miptree
*mt
;
59 /* Only supports 2D, non-mipmapped textures for the moment */
60 if (pt
->target
!= PIPE_TEXTURE_2D
|| pt
->last_level
!= 0 ||
64 mt
= CALLOC_STRUCT(nv10_miptree
);
69 mt
->base
.refcount
= 1;
70 mt
->base
.screen
= pscreen
;
71 mt
->level
[0].pitch
= stride
[0];
72 mt
->level
[0].image_offset
= CALLOC(1, sizeof(unsigned));
74 pipe_buffer_reference(pscreen
, &mt
->buffer
, pb
);
78 static struct pipe_texture
*
79 nv10_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
81 struct pipe_winsys
*ws
= screen
->winsys
;
82 struct nv10_miptree
*mt
;
84 mt
= MALLOC(sizeof(struct nv10_miptree
));
88 mt
->base
.refcount
= 1;
89 mt
->base
.screen
= screen
;
91 nv10_miptree_layout(mt
);
93 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
104 nv10_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
106 struct pipe_texture
*mt
= *pt
;
109 if (--mt
->refcount
<= 0) {
110 struct nv10_miptree
*nv10mt
= (struct nv10_miptree
*)mt
;
113 pipe_buffer_reference(screen
, &nv10mt
->buffer
, NULL
);
114 for (l
= 0; l
<= mt
->last_level
; l
++) {
115 if (nv10mt
->level
[l
].image_offset
)
116 FREE(nv10mt
->level
[l
].image_offset
);
123 nv10_miptree_update(struct pipe_context
*pipe
, struct pipe_texture
*mt
,
124 uint face
, uint levels
)
129 static struct pipe_surface
*
130 nv10_miptree_surface_get(struct pipe_screen
*screen
, struct pipe_texture
*pt
,
131 unsigned face
, unsigned level
, unsigned zslice
,
134 struct pipe_winsys
*ws
= screen
->winsys
;
135 struct nv10_miptree
*nv10mt
= (struct nv10_miptree
*)pt
;
136 struct pipe_surface
*ps
;
138 ps
= CALLOC_STRUCT(pipe_surface
);
141 pipe_texture_reference(&ps
->texture
, pt
);
142 ps
->format
= pt
->format
;
143 ps
->width
= pt
->width
[level
];
144 ps
->height
= pt
->height
[level
];
145 ps
->block
= pt
->block
;
146 ps
->nblocksx
= pt
->nblocksx
[level
];
147 ps
->nblocksy
= pt
->nblocksy
[level
];
148 ps
->stride
= nv10mt
->level
[level
].pitch
;
151 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
152 ps
->offset
= nv10mt
->level
[level
].image_offset
[face
];
154 ps
->offset
= nv10mt
->level
[level
].image_offset
[0];
161 nv10_miptree_surface_release(struct pipe_screen
*screen
,
162 struct pipe_surface
**surface
)
166 void nv10_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
168 pscreen
->texture_create
= nv10_miptree_create
;
169 pscreen
->texture_blanket
= nv10_miptree_blanket
;
170 pscreen
->texture_release
= nv10_miptree_release
;
171 pscreen
->get_tex_surface
= nv10_miptree_surface_get
;
172 pscreen
->tex_surface_release
= nv10_miptree_surface_release
;