1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_inlines.h"
4 #include "util/u_math.h"
6 #include "nv30_context.h"
9 nv30_miptree_layout(struct nv30_miptree
*nv30mt
)
11 struct pipe_texture
*pt
= &nv30mt
->base
;
12 uint width
= pt
->width0
;
15 uint wide_pitch
= pt
->tex_usage
& (PIPE_TEXTURE_USAGE_SAMPLER
|
16 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
|
17 PIPE_TEXTURE_USAGE_RENDER_TARGET
|
18 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
19 PIPE_TEXTURE_USAGE_PRIMARY
);
21 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
24 if (pt
->target
== PIPE_TEXTURE_3D
) {
25 nr_faces
= pt
->depth0
;
30 for (l
= 0; l
<= pt
->last_level
; l
++) {
31 if (wide_pitch
&& (pt
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
))
32 nv30mt
->level
[l
].pitch
= align(pf_get_stride(pt
->format
, pt
->width0
), 64);
34 nv30mt
->level
[l
].pitch
= pf_get_stride(pt
->format
, width
);
36 nv30mt
->level
[l
].image_offset
=
37 CALLOC(nr_faces
, sizeof(unsigned));
39 width
= u_minify(width
, 1);
42 for (f
= 0; f
< nr_faces
; f
++) {
43 for (l
= 0; l
< pt
->last_level
; l
++) {
44 nv30mt
->level
[l
].image_offset
[f
] = offset
;
46 if (!(pt
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
) &&
47 u_minify(pt
->width0
, l
+ 1) > 1 && u_minify(pt
->height0
, l
+ 1) > 1)
48 offset
+= align(nv30mt
->level
[l
].pitch
* u_minify(pt
->height0
, l
), 64);
50 offset
+= nv30mt
->level
[l
].pitch
* u_minify(pt
->height0
, l
);
53 nv30mt
->level
[l
].image_offset
[f
] = offset
;
54 offset
+= nv30mt
->level
[l
].pitch
* u_minify(pt
->height0
, l
);
57 nv30mt
->total_size
= offset
;
60 static struct pipe_texture
*
61 nv30_miptree_create(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
)
63 struct nv30_miptree
*mt
;
64 unsigned buf_usage
= PIPE_BUFFER_USAGE_PIXEL
|
65 NOUVEAU_BUFFER_USAGE_TEXTURE
;
67 mt
= MALLOC(sizeof(struct nv30_miptree
));
71 pipe_reference_init(&mt
->base
.reference
, 1);
72 mt
->base
.screen
= pscreen
;
74 /* Swizzled textures must be POT */
75 if (pt
->width0
& (pt
->width0
- 1) ||
76 pt
->height0
& (pt
->height0
- 1))
77 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
79 if (pt
->tex_usage
& (PIPE_TEXTURE_USAGE_PRIMARY
|
80 PIPE_TEXTURE_USAGE_DISPLAY_TARGET
|
81 PIPE_TEXTURE_USAGE_DEPTH_STENCIL
))
82 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
84 if (pt
->tex_usage
& PIPE_TEXTURE_USAGE_DYNAMIC
)
85 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
88 /* TODO: Figure out which formats can be swizzled */
89 case PIPE_FORMAT_A8R8G8B8_UNORM
:
90 case PIPE_FORMAT_X8R8G8B8_UNORM
:
91 case PIPE_FORMAT_R16_SNORM
:
92 case PIPE_FORMAT_R5G6B5_UNORM
:
93 case PIPE_FORMAT_A8L8_UNORM
:
94 case PIPE_FORMAT_A8_UNORM
:
95 case PIPE_FORMAT_L8_UNORM
:
96 case PIPE_FORMAT_I8_UNORM
:
98 if (debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE
))
99 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
103 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
107 if (pt
->tex_usage
& PIPE_TEXTURE_USAGE_DYNAMIC
)
108 buf_usage
|= PIPE_BUFFER_USAGE_CPU_READ_WRITE
;
110 nv30_miptree_layout(mt
);
112 mt
->buffer
= pscreen
->buffer_create(pscreen
, 256, buf_usage
,
122 static struct pipe_texture
*
123 nv30_miptree_blanket(struct pipe_screen
*pscreen
, const struct pipe_texture
*pt
,
124 const unsigned *stride
, struct pipe_buffer
*pb
)
126 struct nv30_miptree
*mt
;
128 /* Only supports 2D, non-mipmapped textures for the moment */
129 if (pt
->target
!= PIPE_TEXTURE_2D
|| pt
->last_level
!= 0 ||
133 mt
= CALLOC_STRUCT(nv30_miptree
);
138 pipe_reference_init(&mt
->base
.reference
, 1);
139 mt
->base
.screen
= pscreen
;
140 mt
->level
[0].pitch
= stride
[0];
141 mt
->level
[0].image_offset
= CALLOC(1, sizeof(unsigned));
143 /* Assume whoever created this buffer expects it to be linear for now */
144 mt
->base
.tex_usage
|= NOUVEAU_TEXTURE_USAGE_LINEAR
;
146 pipe_buffer_reference(&mt
->buffer
, pb
);
151 nv30_miptree_destroy(struct pipe_texture
*pt
)
153 struct nv30_miptree
*mt
= (struct nv30_miptree
*)pt
;
156 pipe_buffer_reference(&mt
->buffer
, NULL
);
157 for (l
= 0; l
<= pt
->last_level
; l
++) {
158 if (mt
->level
[l
].image_offset
)
159 FREE(mt
->level
[l
].image_offset
);
165 static struct pipe_surface
*
166 nv30_miptree_surface_new(struct pipe_screen
*pscreen
, struct pipe_texture
*pt
,
167 unsigned face
, unsigned level
, unsigned zslice
,
170 struct nv30_miptree
*nv30mt
= (struct nv30_miptree
*)pt
;
171 struct nv04_surface
*ns
;
173 ns
= CALLOC_STRUCT(nv04_surface
);
176 pipe_texture_reference(&ns
->base
.texture
, pt
);
177 ns
->base
.format
= pt
->format
;
178 ns
->base
.width
= u_minify(pt
->width0
, level
);
179 ns
->base
.height
= u_minify(pt
->height0
, level
);
180 ns
->base
.usage
= flags
;
181 pipe_reference_init(&ns
->base
.reference
, 1);
182 ns
->base
.face
= face
;
183 ns
->base
.level
= level
;
184 ns
->base
.zslice
= zslice
;
185 ns
->pitch
= nv30mt
->level
[level
].pitch
;
187 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
188 ns
->base
.offset
= nv30mt
->level
[level
].image_offset
[face
];
190 if (pt
->target
== PIPE_TEXTURE_3D
) {
191 ns
->base
.offset
= nv30mt
->level
[level
].image_offset
[zslice
];
193 ns
->base
.offset
= nv30mt
->level
[level
].image_offset
[0];
200 nv30_miptree_surface_del(struct pipe_surface
*ps
)
202 pipe_texture_reference(&ps
->texture
, NULL
);
207 nv30_screen_init_miptree_functions(struct pipe_screen
*pscreen
)
209 pscreen
->texture_create
= nv30_miptree_create
;
210 pscreen
->texture_blanket
= nv30_miptree_blanket
;
211 pscreen
->texture_destroy
= nv30_miptree_destroy
;
212 pscreen
->get_tex_surface
= nv30_miptree_surface_new
;
213 pscreen
->tex_surface_destroy
= nv30_miptree_surface_del
;