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 uint width
= pt
->width
[0], height
= pt
->height
[0], depth
= pt
->depth
[0];
14 uint wide_pitch
= pt
->tex_usage
& (PIPE_TEXTURE_USAGE_SAMPLER
|
15 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
|
16 PIPE_TEXTURE_USAGE_RENDER_TARGET
|
17 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
18 PIPE_TEXTURE_USAGE_PRIMARY
);
20 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
23 if (pt
->target
== PIPE_TEXTURE_3D
) {
24 nr_faces
= pt
->depth
[0];
29 for (l
= 0; l
<= pt
->last_level
; l
++) {
31 pt
->height
[l
] = height
;
33 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
34 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
36 if (wide_pitch
&& (pt
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
))
37 nv30mt
->level
[l
].pitch
= align(pt
->width
[0] * pt
->block
.size
, 64);
39 nv30mt
->level
[l
].pitch
= pt
->width
[l
] * pt
->block
.size
;
41 nv30mt
->level
[l
].image_offset
=
42 CALLOC(nr_faces
, sizeof(unsigned));
44 width
= MAX2(1, width
>> 1);
45 height
= MAX2(1, height
>> 1);
46 depth
= MAX2(1, depth
>> 1);
49 for (f
= 0; f
< nr_faces
; f
++) {
50 for (l
= 0; l
< pt
->last_level
; l
++) {
51 nv30mt
->level
[l
].image_offset
[f
] = offset
;
53 if (!(pt
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
))
54 offset
+= align(nv30mt
->level
[l
].pitch
* pt
->height
[l
], 64);
56 offset
+= nv30mt
->level
[l
].pitch
* pt
->height
[l
];
59 nv30mt
->level
[l
].image_offset
[f
] = offset
;
60 offset
+= nv30mt
->level
[l
].pitch
* pt
->height
[l
];
63 nv30mt
->total_size
= offset
;
66 static struct pipe_texture
*
67 nv30_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
69 struct pipe_winsys
*ws
= pscreen
->winsys
;
70 struct nv30_miptree
*mt
;
72 mt
= MALLOC(sizeof(struct nv30_miptree
));
76 mt
->base
.refcount
= 1;
77 mt
->base
.screen
= pscreen
;
78 mt
->shadow_tex
= NULL
;
79 mt
->shadow_surface
= NULL
;
81 /* Swizzled textures must be POT */
82 if (pt
->width
[0] & (pt
->width
[0] - 1) ||
83 pt
->height
[0] & (pt
->height
[0] - 1))
84 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
86 if (pt
->tex_usage
& (PIPE_TEXTURE_USAGE_PRIMARY
|
87 + PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
88 + PIPE_TEXTURE_USAGE_DEPTH_STENCIL
))
89 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
91 if (pt
->tex_usage
& PIPE_TEXTURE_USAGE_DYNAMIC
)
92 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
95 /* TODO: Figure out which formats can be swizzled */
96 case PIPE_FORMAT_A8R8G8B8_UNORM
:
97 case PIPE_FORMAT_X8R8G8B8_UNORM
:
98 case PIPE_FORMAT_R16_SNORM
:
100 if (debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE
))
101 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
105 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
109 nv30_miptree_layout(mt
);
111 mt
->buffer
= ws
->buffer_create(ws
, 256,
112 PIPE_BUFFER_USAGE_PIXEL
|
113 NOUVEAU_BUFFER_USAGE_TEXTURE
,
123 static struct pipe_texture
*
124 nv30_miptree_blanket(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
,
125 const unsigned *stride
, struct pipe_buffer
*pb
)
127 struct nv30_miptree
*mt
;
129 /* Only supports 2D, non-mipmapped textures for the moment */
130 if (pt
->target
!= PIPE_TEXTURE_2D
|| pt
->last_level
!= 0 ||
134 mt
= CALLOC_STRUCT(nv30_miptree
);
139 mt
->base
.refcount
= 1;
140 mt
->base
.screen
= pscreen
;
141 mt
->level
[0].pitch
= stride
[0];
142 mt
->level
[0].image_offset
= CALLOC(1, sizeof(unsigned));
144 pipe_buffer_reference(pscreen
, &mt
->buffer
, pb
);
149 nv30_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**ppt
)
151 struct pipe_texture
*pt
= *ppt
;
152 struct nv30_miptree
*mt
= (struct nv30_miptree
*)pt
;
159 pipe_buffer_reference(pscreen
, &mt
->buffer
, NULL
);
160 for (l
= 0; l
<= pt
->last_level
; l
++) {
161 if (mt
->level
[l
].image_offset
)
162 FREE(mt
->level
[l
].image_offset
);
165 if (mt
->shadow_tex
) {
166 if (mt
->shadow_surface
)
167 pscreen
->tex_surface_release(pscreen
, &mt
->shadow_surface
);
168 nv30_miptree_release(pscreen
, &mt
->shadow_tex
);
174 static struct pipe_surface
*
175 nv30_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
176 unsigned face
, unsigned level
, unsigned zslice
,
179 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)pt
;
180 struct pipe_surface
*ps
;
182 ps
= CALLOC_STRUCT(pipe_surface
);
185 pipe_texture_reference(&ps
->texture
, pt
);
186 ps
->format
= pt
->format
;
187 ps
->width
= pt
->width
[level
];
188 ps
->height
= pt
->height
[level
];
189 ps
->block
= pt
->block
;
190 ps
->nblocksx
= pt
->nblocksx
[level
];
191 ps
->nblocksy
= pt
->nblocksy
[level
];
192 ps
->stride
= nv30mt
->level
[level
].pitch
;
194 ps
->status
= PIPE_SURFACE_STATUS_DEFINED
;
200 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
201 ps
->offset
= nv30mt
->level
[level
].image_offset
[face
];
203 if (pt
->target
== PIPE_TEXTURE_3D
) {
204 ps
->offset
= nv30mt
->level
[level
].image_offset
[zslice
];
206 ps
->offset
= nv30mt
->level
[level
].image_offset
[0];
213 nv30_miptree_surface_del(struct pipe_screen
*pscreen
,
214 struct pipe_surface
**psurface
)
216 struct pipe_surface
*ps
= *psurface
;
219 if (--ps
->refcount
> 0)
222 pipe_texture_reference(&ps
->texture
, NULL
);
227 nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
229 pscreen
->texture_create
= nv30_miptree_create
;
230 pscreen
->texture_blanket
= nv30_miptree_blanket
;
231 pscreen
->texture_release
= nv30_miptree_release
;
232 pscreen
->get_tex_surface
= nv30_miptree_surface_new
;
233 pscreen
->tex_surface_release
= nv30_miptree_surface_del
;