1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
5 #include "nv20_context.h"
6 #include "nv20_screen.h"
9 nv20_miptree_layout(struct nv20_miptree
*nv20mt
)
11 struct pipe_texture
*pt
= &nv20mt
->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 nv20mt
->level
[l
].pitch
= pt
->nblocksx
[l
] * pt
->block
.size
;
32 nv20mt
->level
[l
].pitch
= pt
->nblocksx
[0] * pt
->block
.size
;
33 nv20mt
->level
[l
].pitch
= (nv20mt
->level
[l
].pitch
+ 63) & ~63;
35 nv20mt
->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 nv20mt
->level
[l
].image_offset
[f
] = offset
;
46 offset
+= nv20mt
->level
[l
].pitch
* pt
->height
[l
];
50 nv20mt
->total_size
= offset
;
53 static struct pipe_texture
*
54 nv20_miptree_create(struct pipe_screen
*screen
, const struct pipe_texture
*pt
)
56 struct pipe_winsys
*ws
= screen
->winsys
;
57 struct nv20_miptree
*mt
;
59 mt
= MALLOC(sizeof(struct nv20_miptree
));
63 mt
->base
.refcount
= 1;
64 mt
->base
.screen
= screen
;
66 nv20_miptree_layout(mt
);
68 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
79 nv20_miptree_release(struct pipe_screen
*screen
, struct pipe_texture
**pt
)
81 struct pipe_texture
*mt
= *pt
;
84 if (--mt
->refcount
<= 0) {
85 struct nv20_miptree
*nv20mt
= (struct nv20_miptree
*)mt
;
88 pipe_buffer_reference(screen
, &nv20mt
->buffer
, NULL
);
89 for (l
= 0; l
<= mt
->last_level
; l
++) {
90 if (nv20mt
->level
[l
].image_offset
)
91 FREE(nv20mt
->level
[l
].image_offset
);
97 static struct pipe_surface
*
98 nv20_miptree_surface_get(struct pipe_screen
*screen
, struct pipe_texture
*pt
,
99 unsigned face
, unsigned level
, unsigned zslice
,
102 struct nv20_miptree
*nv20mt
= (struct nv20_miptree
*)pt
;
103 struct pipe_surface
*ps
;
105 ps
= CALLOC_STRUCT(pipe_surface
);
108 pipe_texture_reference(&ps
->texture
, pt
);
109 pipe_buffer_reference(screen
, &ps
->buffer
, nv20mt
->buffer
);
110 ps
->format
= pt
->format
;
111 ps
->width
= pt
->width
[level
];
112 ps
->height
= pt
->height
[level
];
113 ps
->block
= pt
->block
;
114 ps
->nblocksx
= pt
->nblocksx
[level
];
115 ps
->nblocksy
= pt
->nblocksy
[level
];
116 ps
->stride
= nv20mt
->level
[level
].pitch
;
118 ps
->status
= PIPE_SURFACE_STATUS_DEFINED
;
120 ps
->winsys
= screen
->winsys
;
122 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
123 ps
->offset
= nv20mt
->level
[level
].image_offset
[face
];
125 if (pt
->target
== PIPE_TEXTURE_3D
) {
126 ps
->offset
= nv20mt
->level
[level
].image_offset
[zslice
];
128 ps
->offset
= nv20mt
->level
[level
].image_offset
[0];
135 nv20_miptree_surface_release(struct pipe_screen
*pscreen
,
136 struct pipe_surface
**psurface
)
138 struct pipe_surface
*ps
= *psurface
;
141 if (--ps
->refcount
> 0)
144 pipe_texture_reference(&ps
->texture
, NULL
);
145 pipe_buffer_reference(pscreen
, &ps
->buffer
, NULL
);
149 void nv20_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
151 pscreen
->texture_create
= nv20_miptree_create
;
152 pscreen
->texture_release
= nv20_miptree_release
;
153 pscreen
->get_tex_surface
= nv20_miptree_surface_get
;
154 pscreen
->tex_surface_release
= nv20_miptree_surface_release
;