1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
5 #include "nv40_context.h"
8 nv40_miptree_layout(struct nv40_miptree
*mt
)
10 struct pipe_texture
*pt
= &mt
->base
;
11 uint width
= pt
->width
[0], height
= pt
->height
[0], depth
= pt
->depth
[0];
13 int nr_faces
, l
, f
, pitch
;
15 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
18 if (pt
->target
== PIPE_TEXTURE_3D
) {
19 nr_faces
= pt
->depth
[0];
25 for (l
= 0; l
<= pt
->last_level
; l
++) {
27 pt
->height
[l
] = height
;
29 pt
->nblocksx
[l
] = pf_get_nblocksx(&pt
->block
, width
);
30 pt
->nblocksy
[l
] = pf_get_nblocksy(&pt
->block
, height
);
32 if (!(pt
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
))
33 pitch
= pt
->nblocksx
[l
];
34 pitch
= align(pitch
, 64);
36 mt
->level
[l
].pitch
= pitch
* pt
->block
.size
;
37 mt
->level
[l
].image_offset
=
38 CALLOC(nr_faces
, sizeof(unsigned));
40 width
= MAX2(1, width
>> 1);
41 height
= MAX2(1, height
>> 1);
42 depth
= MAX2(1, depth
>> 1);
45 for (f
= 0; f
< nr_faces
; f
++) {
46 for (l
= 0; l
<= pt
->last_level
; l
++) {
47 mt
->level
[l
].image_offset
[f
] = offset
;
48 offset
+= mt
->level
[l
].pitch
* pt
->height
[l
];
52 mt
->total_size
= offset
;
55 static struct pipe_texture
*
56 nv40_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
58 struct pipe_winsys
*ws
= pscreen
->winsys
;
59 struct nv40_miptree
*mt
;
61 mt
= MALLOC(sizeof(struct nv40_miptree
));
65 mt
->base
.refcount
= 1;
66 mt
->base
.screen
= pscreen
;
67 mt
->shadow_tex
= NULL
;
68 mt
->shadow_surface
= NULL
;
70 /* Swizzled textures must be POT */
71 if (pt
->width
[0] & (pt
->width
[0] - 1) ||
72 pt
->height
[0] & (pt
->height
[0] - 1))
73 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
75 if (pt
->tex_usage
& (PIPE_TEXTURE_USAGE_PRIMARY
|
76 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
))
77 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
80 /* TODO: Figure out which formats can be swizzled */
81 case PIPE_FORMAT_A8R8G8B8_UNORM
:
82 case PIPE_FORMAT_X8R8G8B8_UNORM
:
83 /* XXX: Re-enable when SIFM size limits are fixed */
84 /*case PIPE_FORMAT_R16_SNORM:*/
87 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
91 nv40_miptree_layout(mt
);
93 mt
->buffer
= ws
->buffer_create(ws
, 256,
94 PIPE_BUFFER_USAGE_PIXEL
|
95 NOUVEAU_BUFFER_USAGE_TEXTURE
,
106 nv40_miptree_release(struct pipe_screen
*pscreen
, struct pipe_texture
**ppt
)
108 struct pipe_texture
*pt
= *ppt
;
109 struct nv40_miptree
*mt
= (struct nv40_miptree
*)pt
;
116 pipe_buffer_reference(pscreen
, &mt
->buffer
, NULL
);
117 for (l
= 0; l
<= pt
->last_level
; l
++) {
118 if (mt
->level
[l
].image_offset
)
119 FREE(mt
->level
[l
].image_offset
);
122 if (mt
->shadow_tex
) {
123 assert(mt
->shadow_surface
);
124 pscreen
->tex_surface_release(pscreen
, &mt
->shadow_surface
);
125 nv40_miptree_release(pscreen
, &mt
->shadow_tex
);
131 static struct pipe_surface
*
132 nv40_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
133 unsigned face
, unsigned level
, unsigned zslice
,
136 struct nv40_miptree
*mt
= (struct nv40_miptree
*)pt
;
137 struct pipe_surface
*ps
;
139 ps
= CALLOC_STRUCT(pipe_surface
);
142 pipe_texture_reference(&ps
->texture
, pt
);
143 pipe_buffer_reference(pscreen
, &ps
->buffer
, mt
->buffer
);
144 ps
->format
= pt
->format
;
145 ps
->width
= pt
->width
[level
];
146 ps
->height
= pt
->height
[level
];
147 ps
->block
= pt
->block
;
148 ps
->nblocksx
= pt
->nblocksx
[level
];
149 ps
->nblocksy
= pt
->nblocksy
[level
];
150 ps
->stride
= mt
->level
[level
].pitch
;
152 ps
->status
= PIPE_SURFACE_STATUS_DEFINED
;
154 ps
->winsys
= pscreen
->winsys
;
159 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
160 ps
->offset
= mt
->level
[level
].image_offset
[face
];
162 if (pt
->target
== PIPE_TEXTURE_3D
) {
163 ps
->offset
= mt
->level
[level
].image_offset
[zslice
];
165 ps
->offset
= mt
->level
[level
].image_offset
[0];
172 nv40_miptree_surface_del(struct pipe_screen
*pscreen
,
173 struct pipe_surface
**psurface
)
175 struct pipe_surface
*ps
= *psurface
;
178 if (--ps
->refcount
> 0)
181 pipe_texture_reference(&ps
->texture
, NULL
);
182 pipe_buffer_reference(pscreen
, &ps
->buffer
, NULL
);
187 nv40_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
189 pscreen
->texture_create
= nv40_miptree_create
;
190 pscreen
->texture_release
= nv40_miptree_release
;
191 pscreen
->get_tex_surface
= nv40_miptree_surface_new
;
192 pscreen
->tex_surface_release
= nv40_miptree_surface_del
;