1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
5 #include "nv30_context.h"
8 nv30_miptree_layout(struct nv30_miptree
*nv30mt
)
10 struct pipe_texture
*pt
= &nv30mt
->base
;
11 boolean swizzled
= FALSE
;
12 uint width
= pt
->width
[0], height
= pt
->height
[0], depth
= pt
->depth
[0];
14 int nr_faces
, l
, f
, pitch
;
16 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
19 if (pt
->target
== PIPE_TEXTURE_3D
) {
20 nr_faces
= pt
->depth
[0];
26 for (l
= 0; l
<= pt
->last_level
; l
++) {
28 pt
->height
[l
] = height
;
30 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
31 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
34 pitch
= pt
->nblocksx
[l
];
35 pitch
= align(pitch
, 64);
37 nv30mt
->level
[l
].pitch
= pitch
* pt
->block
.size
;
38 nv30mt
->level
[l
].image_offset
=
39 CALLOC(nr_faces
, sizeof(unsigned));
41 width
= MAX2(1, width
>> 1);
42 height
= MAX2(1, height
>> 1);
43 depth
= MAX2(1, depth
>> 1);
46 for (f
= 0; f
< nr_faces
; f
++) {
47 for (l
= 0; l
<= pt
->last_level
; l
++) {
48 nv30mt
->level
[l
].image_offset
[f
] = offset
;
49 offset
+= nv30mt
->level
[l
].pitch
* pt
->height
[l
];
53 nv30mt
->total_size
= offset
;
56 static struct pipe_texture
*
57 nv30_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
59 struct pipe_winsys
*ws
= pscreen
->winsys
;
60 struct nv30_miptree
*mt
;
62 mt
= MALLOC(sizeof(struct nv30_miptree
));
66 mt
->base
.refcount
= 1;
67 mt
->base
.screen
= pscreen
;
68 mt
->shadow_tex
= NULL
;
69 mt
->shadow_surface
= NULL
;
71 /* Swizzled textures must be POT */
72 if (pt
->width
[0] & (pt
->width
[0] - 1) ||
73 pt
->height
[0] & (pt
->height
[0] - 1))
74 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
76 if (pt
->tex_usage
& (PIPE_TEXTURE_USAGE_PRIMARY
|
77 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
))
78 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
80 if (pt
->tex_usage
& PIPE_TEXTURE_USAGE_DYNAMIC
)
81 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
84 /* TODO: Figure out which formats can be swizzled */
85 case PIPE_FORMAT_A8R8G8B8_UNORM
:
86 case PIPE_FORMAT_X8R8G8B8_UNORM
:
87 case PIPE_FORMAT_R16_SNORM
:
90 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
94 nv30_miptree_layout(mt
);
96 mt
->buffer
= ws
->buffer_create(ws
, 256,
97 PIPE_BUFFER_USAGE_PIXEL
|
98 NOUVEAU_BUFFER_USAGE_TEXTURE
,
109 nv30_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**ppt
)
111 struct pipe_texture
*pt
= *ppt
;
112 struct nv30_miptree
*mt
= (struct nv30_miptree
*)pt
;
119 pipe_buffer_reference(pscreen
, &mt
->buffer
, NULL
);
120 for (l
= 0; l
<= pt
->last_level
; l
++) {
121 if (mt
->level
[l
].image_offset
)
122 FREE(mt
->level
[l
].image_offset
);
125 if (mt
->shadow_tex
) {
126 assert(mt
->shadow_surface
);
127 pscreen
->tex_surface_release(pscreen
, &mt
->shadow_surface
);
128 nv30_miptree_release(pscreen
, &mt
->shadow_tex
);
134 static struct pipe_surface
*
135 nv30_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
136 unsigned face
, unsigned level
, unsigned zslice
,
139 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)pt
;
140 struct pipe_surface
*ps
;
142 ps
= CALLOC_STRUCT(pipe_surface
);
145 pipe_texture_reference(&ps
->texture
, pt
);
146 pipe_buffer_reference(pscreen
, &ps
->buffer
, nv30mt
->buffer
);
147 ps
->format
= pt
->format
;
148 ps
->width
= pt
->width
[level
];
149 ps
->height
= pt
->height
[level
];
150 ps
->block
= pt
->block
;
151 ps
->nblocksx
= pt
->nblocksx
[level
];
152 ps
->nblocksy
= pt
->nblocksy
[level
];
153 ps
->stride
= nv30mt
->level
[level
].pitch
;
155 ps
->status
= PIPE_SURFACE_STATUS_DEFINED
;
161 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
162 ps
->offset
= nv30mt
->level
[level
].image_offset
[face
];
164 if (pt
->target
== PIPE_TEXTURE_3D
) {
165 ps
->offset
= nv30mt
->level
[level
].image_offset
[zslice
];
167 ps
->offset
= nv30mt
->level
[level
].image_offset
[0];
174 nv30_miptree_surface_del(struct pipe_screen
*pscreen
,
175 struct pipe_surface
**psurface
)
177 struct pipe_surface
*ps
= *psurface
;
180 if (--ps
->refcount
> 0)
183 pipe_texture_reference(&ps
->texture
, NULL
);
184 pipe_buffer_reference(pscreen
->winsys
, &ps
->buffer
, NULL
);
189 nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
191 pscreen
->texture_create
= nv30_miptree_create
;
192 pscreen
->texture_release
= nv30_miptree_release
;
193 pscreen
->get_tex_surface
= nv30_miptree_surface_new
;
194 pscreen
->tex_surface_release
= nv30_miptree_surface_del
;