97f679731ea49955767fa014601c4c754fd30329
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 "nv04_context.h"
7 #include "nv04_screen.h"
10 nv04_miptree_layout(struct nv04_miptree
*nv04mt
)
12 struct pipe_texture
*pt
= &nv04mt
->base
;
13 uint width
= pt
->width
[0], height
= pt
->height
[0];
19 for (l
= 0; l
<= pt
->last_level
; l
++) {
21 pt
->height
[l
] = height
;
23 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
24 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
26 nv04mt
->level
[l
].pitch
= pt
->width
[0] * pt
->block
.size
;
27 nv04mt
->level
[l
].pitch
= (nv04mt
->level
[l
].pitch
+ 63) & ~63;
29 nv04mt
->level
[l
].image_offset
=
30 CALLOC(nr_faces
, sizeof(unsigned));
32 width
= MAX2(1, width
>> 1);
33 height
= MAX2(1, height
>> 1);
37 for (f
= 0; f
< nr_faces
; f
++) {
38 for (l
= 0; l
<= pt
->last_level
; l
++) {
39 nv04mt
->level
[l
].image_offset
[f
] = offset
;
40 offset
+= nv04mt
->level
[l
].pitch
* pt
->height
[l
];
44 nv04mt
->total_size
= offset
;
47 static struct pipe_texture
*
48 nv04_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
50 struct pipe_winsys
*ws
= screen
->winsys
;
51 struct nv04_miptree
*mt
;
53 mt
= MALLOC(sizeof(struct nv04_miptree
));
57 mt
->base
.refcount
= 1;
58 mt
->base
.screen
= screen
;
60 nv04_miptree_layout(mt
);
62 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
73 nv04_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
75 struct pipe_winsys
*ws
= screen
->winsys
;
76 struct pipe_texture
*mt
= *pt
;
79 if (--mt
->refcount
<= 0) {
80 struct nv04_miptree
*nv04mt
= (struct nv04_miptree
*)mt
;
83 pipe_buffer_reference(ws
, &nv04mt
->buffer
, NULL
);
84 for (l
= 0; l
<= mt
->last_level
; l
++) {
85 if (nv04mt
->level
[l
].image_offset
)
86 FREE(nv04mt
->level
[l
].image_offset
);
92 static struct pipe_surface
*
93 nv04_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
94 unsigned face
, unsigned level
, unsigned zslice
,
97 struct pipe_winsys
*ws
= pscreen
->winsys
;
98 struct nv04_miptree
*nv04mt
= (struct nv04_miptree
*)pt
;
99 struct pipe_surface
*ps
;
101 ps
= ws
->surface_alloc(ws
);
104 pipe_buffer_reference(ws
, &ps
->buffer
, nv04mt
->buffer
);
105 ps
->format
= pt
->format
;
106 ps
->width
= pt
->width
[level
];
107 ps
->height
= pt
->height
[level
];
108 ps
->block
= pt
->block
;
109 ps
->width
= pt
->width
[level
];
110 ps
->height
= pt
->height
[level
];
111 ps
->nblocksx
= pt
->nblocksx
[level
];
112 ps
->nblocksy
= pt
->nblocksy
[level
];
113 ps
->stride
= nv04mt
->level
[level
].pitch
;
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
;