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
= offset
;
35 offset
+= nv04mt
->level
[l
].pitch
* pt
->height
[l
];
38 nv04mt
->total_size
= offset
;
41 static struct pipe_texture
*
42 nv04_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
44 struct pipe_winsys
*ws
= pscreen
->winsys
;
45 struct nv04_miptree
*mt
;
47 mt
= MALLOC(sizeof(struct nv04_miptree
));
51 mt
->base
.refcount
= 1;
52 mt
->base
.screen
= pscreen
;
53 mt
->shadow_tex
= NULL
;
54 mt
->shadow_surface
= NULL
;
56 //mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
58 nv04_miptree_layout(mt
);
60 mt
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
|
61 NOUVEAU_BUFFER_USAGE_TEXTURE
,
64 printf("failed %d byte alloc\n",mt
->total_size
);
73 nv04_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**ppt
)
75 struct pipe_texture
*pt
= *ppt
;
76 struct nv04_miptree
*mt
= (struct nv04_miptree
*)pt
;
83 pipe_buffer_reference(pscreen
, &mt
->buffer
, NULL
);
84 for (l
= 0; l
<= pt
->last_level
; l
++) {
85 if (mt
->level
[l
].image_offset
)
86 FREE(mt
->level
[l
].image_offset
);
90 assert(mt
->shadow_surface
);
91 pscreen
->tex_surface_release(pscreen
, &mt
->shadow_surface
);
92 nv04_miptree_release(pscreen
, &mt
->shadow_tex
);
98 static struct pipe_surface
*
99 nv04_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
100 unsigned face
, unsigned level
, unsigned zslice
,
103 struct nv04_miptree
*nv04mt
= (struct nv04_miptree
*)pt
;
104 struct pipe_surface
*ps
;
106 ps
= CALLOC_STRUCT(pipe_surface
);
109 pipe_texture_reference(&ps
->texture
, pt
);
110 pipe_buffer_reference(pscreen
, &ps
->buffer
, nv04mt
->buffer
);
111 ps
->format
= pt
->format
;
112 ps
->width
= pt
->width
[level
];
113 ps
->height
= pt
->height
[level
];
114 ps
->block
= pt
->block
;
115 ps
->nblocksx
= pt
->nblocksx
[level
];
116 ps
->nblocksy
= pt
->nblocksy
[level
];
117 ps
->stride
= nv04mt
->level
[level
].pitch
;
119 ps
->status
= PIPE_SURFACE_STATUS_DEFINED
;
125 ps
->offset
= nv04mt
->level
[level
].image_offset
;
131 nv04_miptree_surface_del(struct pipe_screen
*pscreen
,
132 struct pipe_surface
**psurface
)
134 struct pipe_surface
*ps
= *psurface
;
137 if (--ps
->refcount
> 0)
140 pipe_texture_reference(&ps
->texture
, NULL
);
141 pipe_buffer_reference(pscreen
->winsys
, &ps
->buffer
, NULL
);
146 nv04_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
148 pscreen
->texture_create
= nv04_miptree_create
;
149 pscreen
->texture_release
= nv04_miptree_release
;
150 pscreen
->get_tex_surface
= nv04_miptree_surface_new
;
151 pscreen
->tex_surface_release
= nv04_miptree_surface_del
;