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];
26 nv04mt
->level
[l
].pitch
= (nv04mt
->level
[l
].pitch
+ 63) & ~63;
28 width
= MAX2(1, width
>> 1);
29 height
= MAX2(1, height
>> 1);
32 for (l
= 0; l
<= pt
->last_level
; l
++) {
34 nv04mt
->level
[l
].image_offset
=
35 CALLOC(nr_faces
, sizeof(unsigned));
36 offset
+= nv04mt
->level
[l
].pitch
* pt
->height
[l
];
39 nv04mt
->total_size
= offset
;
42 static struct pipe_texture
*
43 nv04_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
45 struct nv04_miptree
*mt
;
47 mt
= MALLOC(sizeof(struct nv04_miptree
));
51 pipe_reference_init(&mt
->base
.reference
, 1);
52 mt
->base
.screen
= pscreen
;
54 //mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
56 nv04_miptree_layout(mt
);
58 mt
->buffer
= pscreen
->buffer_create(pscreen
, 256, PIPE_BUFFER_USAGE_PIXEL
|
59 NOUVEAU_BUFFER_USAGE_TEXTURE
,
62 printf("failed %d byte alloc\n",mt
->total_size
);
70 static struct pipe_texture
*
71 nv04_miptree_blanket(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
,
72 const unsigned *stride
, struct pipe_buffer
*pb
)
74 struct nv04_miptree
*mt
;
76 /* Only supports 2D, non-mipmapped textures for the moment */
77 if (pt
->target
!= PIPE_TEXTURE_2D
|| pt
->last_level
!= 0 ||
81 mt
= CALLOC_STRUCT(nv04_miptree
);
86 pipe_reference_init(&mt
->base
.reference
, 1);
87 mt
->base
.screen
= pscreen
;
88 mt
->level
[0].pitch
= stride
[0];
89 mt
->level
[0].image_offset
= CALLOC(1, sizeof(unsigned));
91 pipe_buffer_reference(&mt
->buffer
, pb
);
96 nv04_miptree_destroy(struct pipe_texture
*pt
)
98 struct nv04_miptree
*mt
= (struct nv04_miptree
*)pt
;
101 pipe_buffer_reference(&mt
->buffer
, NULL
);
102 for (l
= 0; l
<= pt
->last_level
; l
++) {
103 if (mt
->level
[l
].image_offset
)
104 FREE(mt
->level
[l
].image_offset
);
110 static struct pipe_surface
*
111 nv04_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
112 unsigned face
, unsigned level
, unsigned zslice
,
115 struct nv04_miptree
*nv04mt
= (struct nv04_miptree
*)pt
;
116 struct nv04_surface
*ns
;
118 ns
= CALLOC_STRUCT(nv04_surface
);
121 pipe_texture_reference(&ns
->base
.texture
, pt
);
122 ns
->base
.format
= pt
->format
;
123 ns
->base
.width
= pt
->width
[level
];
124 ns
->base
.height
= pt
->height
[level
];
125 ns
->base
.usage
= flags
;
126 pipe_reference_init(&ns
->base
.reference
, 1);
127 ns
->base
.face
= face
;
128 ns
->base
.level
= level
;
129 ns
->base
.zslice
= zslice
;
130 ns
->pitch
= nv04mt
->level
[level
].pitch
;
132 ns
->base
.offset
= nv04mt
->level
[level
].image_offset
;
138 nv04_miptree_surface_del(struct pipe_surface
*ps
)
140 pipe_texture_reference(&ps
->texture
, NULL
);
145 nv04_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
147 pscreen
->texture_create
= nv04_miptree_create
;
148 pscreen
->texture_blanket
= nv04_miptree_blanket
;
149 pscreen
->texture_destroy
= nv04_miptree_destroy
;
150 pscreen
->get_tex_surface
= nv04_miptree_surface_new
;
151 pscreen
->tex_surface_destroy
= nv04_miptree_surface_del
;