0cbb91e187bfb3b505314a82b807153b072ce91f
1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
5 #include "nv04_context.h"
6 #include "nv04_screen.h"
9 nv04_miptree_layout(struct nv04_miptree
*nv04mt
)
11 struct pipe_texture
*pt
= &nv04mt
->base
;
12 uint width
= pt
->width
[0], height
= pt
->height
[0];
18 for (l
= 0; l
<= pt
->last_level
; l
++) {
20 pt
->height
[l
] = height
;
22 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
23 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
25 nv04mt
->level
[l
].pitch
= pt
->width
[0] * pt
->block
.size
;
26 nv04mt
->level
[l
].pitch
= (nv04mt
->level
[l
].pitch
+ 63) & ~63;
28 nv04mt
->level
[l
].image_offset
=
29 CALLOC(nr_faces
, sizeof(unsigned));
31 width
= MAX2(1, width
>> 1);
32 height
= MAX2(1, height
>> 1);
36 for (f
= 0; f
< nr_faces
; f
++) {
37 for (l
= 0; l
<= pt
->last_level
; l
++) {
38 nv04mt
->level
[l
].image_offset
[f
] = offset
;
39 offset
+= nv04mt
->level
[l
].pitch
* pt
->height
[l
];
43 nv04mt
->total_size
= offset
;
46 static struct pipe_texture
*
47 nv04_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
49 struct pipe_winsys
*ws
= screen
->winsys
;
50 struct nv04_miptree
*mt
;
52 mt
= MALLOC(sizeof(struct nv04_miptree
));
56 mt
->base
.refcount
= 1;
57 mt
->base
.screen
= screen
;
59 nv04_miptree_layout(mt
);
61 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
72 nv04_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
74 struct pipe_texture
*mt
= *pt
;
77 if (--mt
->refcount
<= 0) {
78 struct nv04_miptree
*nv04mt
= (struct nv04_miptree
*)mt
;
81 pipe_buffer_reference(screen
, &nv04mt
->buffer
, NULL
);
82 for (l
= 0; l
<= mt
->last_level
; l
++) {
83 if (nv04mt
->level
[l
].image_offset
)
84 FREE(nv04mt
->level
[l
].image_offset
);
90 static struct pipe_surface
*
91 nv04_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
92 unsigned face
, unsigned level
, unsigned zslice
,
95 struct pipe_winsys
*ws
= pscreen
->winsys
;
96 struct nv04_miptree
*nv04mt
= (struct nv04_miptree
*)pt
;
97 struct pipe_surface
*ps
;
99 ps
= ws
->surface_alloc(ws
);
102 pipe_buffer_reference(pscreen
, &ps
->buffer
, nv04mt
->buffer
);
103 ps
->format
= pt
->format
;
104 ps
->width
= pt
->width
[level
];
105 ps
->height
= pt
->height
[level
];
106 ps
->block
= pt
->block
;
107 ps
->width
= pt
->width
[level
];
108 ps
->height
= pt
->height
[level
];
109 ps
->nblocksx
= pt
->nblocksx
[level
];
110 ps
->nblocksy
= pt
->nblocksy
[level
];
111 ps
->stride
= nv04mt
->level
[level
].pitch
;
113 ps
->winsys
= pscreen
->winsys
;
115 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
116 ps
->offset
= nv04mt
->level
[level
].image_offset
[face
];
118 ps
->offset
= nv04mt
->level
[level
].image_offset
[0];
125 nv04_miptree_surface_del(struct pipe_screen
*pscreen
,
126 struct pipe_surface
**psurface
)
131 nv04_init_miptree_functions(struct pipe_screen
*pscreen
)
133 pscreen
->texture_create
= nv04_miptree_create
;
134 pscreen
->texture_release
= nv04_miptree_release
;
135 pscreen
->get_tex_surface
= nv04_miptree_surface_new
;
136 pscreen
->tex_surface_release
= nv04_miptree_surface_del
;