2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2010 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 /* Always include headers in the reverse order!! ~ M. */
25 #include "r300_texture.h"
27 #include "r300_context.h"
29 #include "r300_texture_desc.h"
30 #include "r300_transfer.h"
31 #include "r300_screen.h"
33 #include "util/u_format.h"
34 #include "util/u_format_s3tc.h"
35 #include "util/u_math.h"
36 #include "util/u_memory.h"
37 #include "util/u_mm.h"
39 #include "pipe/p_screen.h"
41 /* These formats are supported by swapping their bytes.
42 * The swizzles must be set exactly like their non-swapped counterparts,
43 * because byte-swapping is what reverses the component order, not swizzling.
45 * This function returns the format that must be used to program CB and TX
48 static enum pipe_format
r300_unbyteswap_array_format(enum pipe_format format
)
50 /* FIXME: Disabled on little endian because of a reported regression:
51 * https://bugs.freedesktop.org/show_bug.cgi?id=98869 */
52 if (PIPE_ENDIAN_NATIVE
!= PIPE_ENDIAN_BIG
)
55 /* Only BGRA 8888 array formats are supported for simplicity of
56 * the implementation. */
58 case PIPE_FORMAT_A8R8G8B8_UNORM
:
59 return PIPE_FORMAT_B8G8R8A8_UNORM
;
60 case PIPE_FORMAT_A8R8G8B8_SRGB
:
61 return PIPE_FORMAT_B8G8R8A8_SRGB
;
62 case PIPE_FORMAT_X8R8G8B8_UNORM
:
63 return PIPE_FORMAT_B8G8R8X8_UNORM
;
64 case PIPE_FORMAT_X8R8G8B8_SRGB
:
65 return PIPE_FORMAT_B8G8R8X8_SRGB
;
71 static unsigned r300_get_endian_swap(enum pipe_format format
)
73 const struct util_format_description
*desc
;
76 if (r300_unbyteswap_array_format(format
) != format
)
77 return R300_SURF_DWORD_SWAP
;
79 if (PIPE_ENDIAN_NATIVE
!= PIPE_ENDIAN_BIG
)
80 return R300_SURF_NO_SWAP
;
82 desc
= util_format_description(format
);
84 return R300_SURF_NO_SWAP
;
86 /* Compressed formats should be in the little endian format. */
87 if (desc
->block
.width
!= 1 || desc
->block
.height
!= 1)
88 return R300_SURF_NO_SWAP
;
90 swap_size
= desc
->is_array
? desc
->channel
[0].size
: desc
->block
.bits
;
93 default: /* shouldn't happen? */
95 return R300_SURF_NO_SWAP
;
97 return R300_SURF_WORD_SWAP
;
99 return R300_SURF_DWORD_SWAP
;
103 unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format
,
104 const unsigned char *swizzle_view
,
105 boolean dxtc_swizzle
)
108 unsigned char swizzle
[4];
110 const uint32_t swizzle_shift
[4] = {
111 R300_TX_FORMAT_R_SHIFT
,
112 R300_TX_FORMAT_G_SHIFT
,
113 R300_TX_FORMAT_B_SHIFT
,
114 R300_TX_FORMAT_A_SHIFT
116 uint32_t swizzle_bit
[4] = {
117 dxtc_swizzle
? R300_TX_FORMAT_Z
: R300_TX_FORMAT_X
,
119 dxtc_swizzle
? R300_TX_FORMAT_X
: R300_TX_FORMAT_Z
,
124 /* Combine two sets of swizzles. */
125 util_format_compose_swizzles(swizzle_format
, swizzle_view
, swizzle
);
127 memcpy(swizzle
, swizzle_format
, 4);
131 for (i
= 0; i
< 4; i
++) {
132 switch (swizzle
[i
]) {
134 result
|= swizzle_bit
[1] << swizzle_shift
[i
];
137 result
|= swizzle_bit
[2] << swizzle_shift
[i
];
140 result
|= swizzle_bit
[3] << swizzle_shift
[i
];
143 result
|= R300_TX_FORMAT_ZERO
<< swizzle_shift
[i
];
146 result
|= R300_TX_FORMAT_ONE
<< swizzle_shift
[i
];
148 default: /* PIPE_SWIZZLE_X */
149 result
|= swizzle_bit
[0] << swizzle_shift
[i
];
155 /* Translate a pipe_format into a useful texture format for sampling.
157 * Some special formats are translated directly using R300_EASY_TX_FORMAT,
158 * but the majority of them is translated in a generic way, automatically
159 * supporting all the formats hw can support.
161 * R300_EASY_TX_FORMAT swizzles the texture.
162 * Note the signature of R300_EASY_TX_FORMAT:
163 * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT);
165 * The FORMAT specifies how the texture sampler will treat the texture, and
166 * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */
167 uint32_t r300_translate_texformat(enum pipe_format format
,
168 const unsigned char *swizzle_view
,
170 boolean dxtc_swizzle
)
173 const struct util_format_description
*desc
;
175 boolean uniform
= TRUE
;
176 const uint32_t sign_bit
[4] = {
177 R300_TX_FORMAT_SIGNED_W
,
178 R300_TX_FORMAT_SIGNED_Z
,
179 R300_TX_FORMAT_SIGNED_Y
,
180 R300_TX_FORMAT_SIGNED_X
,
183 format
= r300_unbyteswap_array_format(format
);
184 desc
= util_format_description(format
);
186 /* Colorspace (return non-RGB formats directly). */
187 switch (desc
->colorspace
) {
188 /* Depth stencil formats.
189 * Swizzles are added in r300_merge_textures_and_samplers. */
190 case UTIL_FORMAT_COLORSPACE_ZS
:
192 case PIPE_FORMAT_Z16_UNORM
:
193 return R300_TX_FORMAT_X16
;
194 case PIPE_FORMAT_X8Z24_UNORM
:
195 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
197 return R500_TX_FORMAT_Y8X24
;
199 return R300_TX_FORMAT_Y16X16
;
201 return ~0; /* Unsupported. */
205 case UTIL_FORMAT_COLORSPACE_YUV
:
206 result
|= R300_TX_FORMAT_YUV_TO_RGB
;
209 case PIPE_FORMAT_UYVY
:
210 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, YVYU422
) | result
;
211 case PIPE_FORMAT_YUYV
:
212 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, VYUY422
) | result
;
214 return ~0; /* Unsupported/unknown. */
217 /* Add gamma correction. */
218 case UTIL_FORMAT_COLORSPACE_SRGB
:
219 result
|= R300_TX_FORMAT_GAMMA
;
224 /* Same as YUV but without the YUR->RGB conversion. */
225 case PIPE_FORMAT_R8G8_B8G8_UNORM
:
226 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, YVYU422
) | result
;
227 case PIPE_FORMAT_G8R8_G8B8_UNORM
:
228 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, VYUY422
) | result
;
234 /* The RGTC1_SNORM and LATC1_SNORM swizzle is done in the shader. */
235 if (util_format_is_compressed(format
) &&
237 format
!= PIPE_FORMAT_RGTC2_UNORM
&&
238 format
!= PIPE_FORMAT_RGTC2_SNORM
&&
239 format
!= PIPE_FORMAT_LATC2_UNORM
&&
240 format
!= PIPE_FORMAT_LATC2_SNORM
&&
241 format
!= PIPE_FORMAT_RGTC1_UNORM
&&
242 format
!= PIPE_FORMAT_RGTC1_SNORM
&&
243 format
!= PIPE_FORMAT_LATC1_UNORM
&&
244 format
!= PIPE_FORMAT_LATC1_SNORM
) {
245 result
|= r300_get_swizzle_combined(desc
->swizzle
, swizzle_view
,
248 result
|= r300_get_swizzle_combined(desc
->swizzle
, swizzle_view
,
253 if (desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
254 if (!util_format_s3tc_enabled
) {
255 return ~0; /* Unsupported. */
259 case PIPE_FORMAT_DXT1_RGB
:
260 case PIPE_FORMAT_DXT1_RGBA
:
261 case PIPE_FORMAT_DXT1_SRGB
:
262 case PIPE_FORMAT_DXT1_SRGBA
:
263 return R300_TX_FORMAT_DXT1
| result
;
264 case PIPE_FORMAT_DXT3_RGBA
:
265 case PIPE_FORMAT_DXT3_SRGBA
:
266 return R300_TX_FORMAT_DXT3
| result
;
267 case PIPE_FORMAT_DXT5_RGBA
:
268 case PIPE_FORMAT_DXT5_SRGBA
:
269 return R300_TX_FORMAT_DXT5
| result
;
271 return ~0; /* Unsupported/unknown. */
276 if (desc
->layout
== UTIL_FORMAT_LAYOUT_RGTC
) {
278 case PIPE_FORMAT_RGTC1_SNORM
:
279 case PIPE_FORMAT_LATC1_SNORM
:
280 result
|= sign_bit
[0];
281 case PIPE_FORMAT_LATC1_UNORM
:
282 case PIPE_FORMAT_RGTC1_UNORM
:
283 return R500_TX_FORMAT_ATI1N
| result
;
285 case PIPE_FORMAT_RGTC2_SNORM
:
286 case PIPE_FORMAT_LATC2_SNORM
:
287 result
|= sign_bit
[1] | sign_bit
[0];
288 case PIPE_FORMAT_RGTC2_UNORM
:
289 case PIPE_FORMAT_LATC2_UNORM
:
290 return R400_TX_FORMAT_ATI2N
| result
;
293 return ~0; /* Unsupported/unknown. */
297 /* This is truly a special format.
298 * It stores R8G8 and B is computed using sqrt(1 - R^2 - G^2)
299 * in the sampler unit. Also known as D3DFMT_CxV8U8. */
300 if (format
== PIPE_FORMAT_R8G8Bx_SNORM
) {
301 return R300_TX_FORMAT_CxV8U8
| result
;
304 /* Integer and fixed-point 16.16 textures are not supported. */
305 for (i
= 0; i
< 4; i
++) {
306 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FIXED
||
307 ((desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
||
308 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
) &&
309 (!desc
->channel
[i
].normalized
||
310 desc
->channel
[i
].pure_integer
))) {
311 return ~0; /* Unsupported/unknown. */
316 for (i
= 0; i
< desc
->nr_channels
; i
++) {
317 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
318 result
|= sign_bit
[i
];
322 /* See whether the components are of the same size. */
323 for (i
= 1; i
< desc
->nr_channels
; i
++) {
324 uniform
= uniform
&& desc
->channel
[0].size
== desc
->channel
[i
].size
;
327 /* Non-uniform formats. */
329 switch (desc
->nr_channels
) {
331 if (desc
->channel
[0].size
== 5 &&
332 desc
->channel
[1].size
== 6 &&
333 desc
->channel
[2].size
== 5) {
334 return R300_TX_FORMAT_Z5Y6X5
| result
;
336 if (desc
->channel
[0].size
== 5 &&
337 desc
->channel
[1].size
== 5 &&
338 desc
->channel
[2].size
== 6) {
339 return R300_TX_FORMAT_Z6Y5X5
| result
;
341 if (desc
->channel
[0].size
== 2 &&
342 desc
->channel
[1].size
== 3 &&
343 desc
->channel
[2].size
== 3) {
344 return R300_TX_FORMAT_Z3Y3X2
| result
;
346 return ~0; /* Unsupported/unknown. */
349 if (desc
->channel
[0].size
== 5 &&
350 desc
->channel
[1].size
== 5 &&
351 desc
->channel
[2].size
== 5 &&
352 desc
->channel
[3].size
== 1) {
353 return R300_TX_FORMAT_W1Z5Y5X5
| result
;
355 if (desc
->channel
[0].size
== 10 &&
356 desc
->channel
[1].size
== 10 &&
357 desc
->channel
[2].size
== 10 &&
358 desc
->channel
[3].size
== 2) {
359 return R300_TX_FORMAT_W2Z10Y10X10
| result
;
362 return ~0; /* Unsupported/unknown. */
365 /* Find the first non-VOID channel. */
366 for (i
= 0; i
< 4; i
++) {
367 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
373 return ~0; /* Unsupported/unknown. */
375 /* And finally, uniform formats. */
376 switch (desc
->channel
[i
].type
) {
377 case UTIL_FORMAT_TYPE_UNSIGNED
:
378 case UTIL_FORMAT_TYPE_SIGNED
:
379 if (!desc
->channel
[i
].normalized
&&
380 desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_SRGB
) {
384 switch (desc
->channel
[i
].size
) {
386 switch (desc
->nr_channels
) {
388 return R300_TX_FORMAT_Y4X4
| result
;
390 return R300_TX_FORMAT_W4Z4Y4X4
| result
;
395 switch (desc
->nr_channels
) {
397 return R300_TX_FORMAT_X8
| result
;
399 return R300_TX_FORMAT_Y8X8
| result
;
401 return R300_TX_FORMAT_W8Z8Y8X8
| result
;
406 switch (desc
->nr_channels
) {
408 return R300_TX_FORMAT_X16
| result
;
410 return R300_TX_FORMAT_Y16X16
| result
;
412 return R300_TX_FORMAT_W16Z16Y16X16
| result
;
417 case UTIL_FORMAT_TYPE_FLOAT
:
418 switch (desc
->channel
[i
].size
) {
420 switch (desc
->nr_channels
) {
422 return R300_TX_FORMAT_16F
| result
;
424 return R300_TX_FORMAT_16F_16F
| result
;
426 return R300_TX_FORMAT_16F_16F_16F_16F
| result
;
431 switch (desc
->nr_channels
) {
433 return R300_TX_FORMAT_32F
| result
;
435 return R300_TX_FORMAT_32F_32F
| result
;
437 return R300_TX_FORMAT_32F_32F_32F_32F
| result
;
442 return ~0; /* Unsupported/unknown. */
445 uint32_t r500_tx_format_msb_bit(enum pipe_format format
)
448 case PIPE_FORMAT_RGTC1_UNORM
:
449 case PIPE_FORMAT_RGTC1_SNORM
:
450 case PIPE_FORMAT_LATC1_UNORM
:
451 case PIPE_FORMAT_LATC1_SNORM
:
452 case PIPE_FORMAT_X8Z24_UNORM
:
453 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
454 return R500_TXFORMAT_MSB
;
460 /* Buffer formats. */
462 /* Colorbuffer formats. This is the unswizzled format of the RB3D block's
463 * output. For the swizzling of the targets, check the shader's format. */
464 static uint32_t r300_translate_colorformat(enum pipe_format format
)
466 format
= r300_unbyteswap_array_format(format
);
470 case PIPE_FORMAT_A8_UNORM
:
471 case PIPE_FORMAT_A8_SNORM
:
472 case PIPE_FORMAT_I8_UNORM
:
473 case PIPE_FORMAT_I8_SNORM
:
474 case PIPE_FORMAT_L8_UNORM
:
475 case PIPE_FORMAT_L8_SNORM
:
476 case PIPE_FORMAT_R8_UNORM
:
477 case PIPE_FORMAT_R8_SNORM
:
478 return R300_COLOR_FORMAT_I8
;
480 /* 16-bit buffers. */
481 case PIPE_FORMAT_L8A8_UNORM
:
482 case PIPE_FORMAT_L8A8_SNORM
:
483 case PIPE_FORMAT_R8G8_UNORM
:
484 case PIPE_FORMAT_R8G8_SNORM
:
485 case PIPE_FORMAT_R8A8_UNORM
:
486 case PIPE_FORMAT_R8A8_SNORM
:
487 /* These formats work fine with UV88 if US_OUT_FMT is set correctly. */
488 case PIPE_FORMAT_A16_UNORM
:
489 case PIPE_FORMAT_A16_SNORM
:
490 case PIPE_FORMAT_A16_FLOAT
:
491 case PIPE_FORMAT_L16_UNORM
:
492 case PIPE_FORMAT_L16_SNORM
:
493 case PIPE_FORMAT_L16_FLOAT
:
494 case PIPE_FORMAT_I16_UNORM
:
495 case PIPE_FORMAT_I16_SNORM
:
496 case PIPE_FORMAT_I16_FLOAT
:
497 case PIPE_FORMAT_R16_UNORM
:
498 case PIPE_FORMAT_R16_SNORM
:
499 case PIPE_FORMAT_R16_FLOAT
:
500 return R300_COLOR_FORMAT_UV88
;
502 case PIPE_FORMAT_B5G6R5_UNORM
:
503 return R300_COLOR_FORMAT_RGB565
;
505 case PIPE_FORMAT_B5G5R5A1_UNORM
:
506 case PIPE_FORMAT_B5G5R5X1_UNORM
:
507 return R300_COLOR_FORMAT_ARGB1555
;
509 case PIPE_FORMAT_B4G4R4A4_UNORM
:
510 case PIPE_FORMAT_B4G4R4X4_UNORM
:
511 return R300_COLOR_FORMAT_ARGB4444
;
513 /* 32-bit buffers. */
514 case PIPE_FORMAT_B8G8R8A8_UNORM
:
515 /*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
516 case PIPE_FORMAT_B8G8R8X8_UNORM
:
517 /*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
518 case PIPE_FORMAT_R8G8B8A8_UNORM
:
519 case PIPE_FORMAT_R8G8B8A8_SNORM
:
520 case PIPE_FORMAT_R8G8B8X8_UNORM
:
521 case PIPE_FORMAT_R8G8B8X8_SNORM
:
522 /* These formats work fine with ARGB8888 if US_OUT_FMT is set
524 case PIPE_FORMAT_R16G16_UNORM
:
525 case PIPE_FORMAT_R16G16_SNORM
:
526 case PIPE_FORMAT_R16G16_FLOAT
:
527 case PIPE_FORMAT_L16A16_UNORM
:
528 case PIPE_FORMAT_L16A16_SNORM
:
529 case PIPE_FORMAT_L16A16_FLOAT
:
530 case PIPE_FORMAT_R16A16_UNORM
:
531 case PIPE_FORMAT_R16A16_SNORM
:
532 case PIPE_FORMAT_R16A16_FLOAT
:
533 case PIPE_FORMAT_A32_FLOAT
:
534 case PIPE_FORMAT_L32_FLOAT
:
535 case PIPE_FORMAT_I32_FLOAT
:
536 case PIPE_FORMAT_R32_FLOAT
:
537 return R300_COLOR_FORMAT_ARGB8888
;
539 case PIPE_FORMAT_R10G10B10A2_UNORM
:
540 case PIPE_FORMAT_R10G10B10X2_SNORM
:
541 case PIPE_FORMAT_B10G10R10A2_UNORM
:
542 case PIPE_FORMAT_B10G10R10X2_UNORM
:
543 return R500_COLOR_FORMAT_ARGB2101010
; /* R5xx-only? */
545 /* 64-bit buffers. */
546 case PIPE_FORMAT_R16G16B16A16_UNORM
:
547 case PIPE_FORMAT_R16G16B16A16_SNORM
:
548 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
549 case PIPE_FORMAT_R16G16B16X16_UNORM
:
550 case PIPE_FORMAT_R16G16B16X16_SNORM
:
551 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
552 /* These formats work fine with ARGB16161616 if US_OUT_FMT is set
554 case PIPE_FORMAT_R32G32_FLOAT
:
555 case PIPE_FORMAT_L32A32_FLOAT
:
556 case PIPE_FORMAT_R32A32_FLOAT
:
557 return R300_COLOR_FORMAT_ARGB16161616
;
559 /* 128-bit buffers. */
560 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
561 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
562 return R300_COLOR_FORMAT_ARGB32323232
;
565 case PIPE_FORMAT_UYVY
:
566 return R300_COLOR_FORMAT_YVYU
;
567 case PIPE_FORMAT_YUYV
:
568 return R300_COLOR_FORMAT_VYUY
;
570 return ~0; /* Unsupported. */
574 /* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */
575 static uint32_t r300_translate_zsformat(enum pipe_format format
)
578 /* 16-bit depth, no stencil */
579 case PIPE_FORMAT_Z16_UNORM
:
580 return R300_DEPTHFORMAT_16BIT_INT_Z
;
581 /* 24-bit depth, ignored stencil */
582 case PIPE_FORMAT_X8Z24_UNORM
:
583 /* 24-bit depth, 8-bit stencil */
584 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
585 return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL
;
587 return ~0; /* Unsupported. */
591 /* Shader output formats. This is essentially the swizzle from the shader
594 * Note that formats are stored from C3 to C0. */
595 static uint32_t r300_translate_out_fmt(enum pipe_format format
)
597 uint32_t modifier
= 0;
599 const struct util_format_description
*desc
;
600 boolean uniform_sign
;
602 format
= r300_unbyteswap_array_format(format
);
603 desc
= util_format_description(format
);
605 /* Find the first non-VOID channel. */
606 for (i
= 0; i
< 4; i
++) {
607 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
613 return ~0; /* Unsupported/unknown. */
615 /* Specifies how the shader output is written to the fog unit. */
616 switch (desc
->channel
[i
].type
) {
617 case UTIL_FORMAT_TYPE_FLOAT
:
618 switch (desc
->channel
[i
].size
) {
620 switch (desc
->nr_channels
) {
622 modifier
|= R300_US_OUT_FMT_C_32_FP
;
625 modifier
|= R300_US_OUT_FMT_C2_32_FP
;
628 modifier
|= R300_US_OUT_FMT_C4_32_FP
;
634 switch (desc
->nr_channels
) {
636 modifier
|= R300_US_OUT_FMT_C_16_FP
;
639 modifier
|= R300_US_OUT_FMT_C2_16_FP
;
642 modifier
|= R300_US_OUT_FMT_C4_16_FP
;
650 switch (desc
->channel
[i
].size
) {
652 switch (desc
->nr_channels
) {
654 modifier
|= R300_US_OUT_FMT_C_16
;
657 modifier
|= R300_US_OUT_FMT_C2_16
;
660 modifier
|= R300_US_OUT_FMT_C4_16
;
666 modifier
|= R300_US_OUT_FMT_C4_10
;
670 /* C4_8 seems to be used for the formats whose pixel size
672 modifier
|= R300_US_OUT_FMT_C4_8
;
679 for (i
= 0; i
< desc
->nr_channels
; i
++)
680 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_SIGNED
)
681 uniform_sign
= FALSE
;
684 modifier
|= R300_OUT_SIGN(0xf);
686 /* Add swizzles and return. */
688 /*** Special cases (non-standard channel mapping) ***/
691 * COLORFORMAT_I8 stores the Z component (C2). */
692 case PIPE_FORMAT_A8_UNORM
:
693 case PIPE_FORMAT_A8_SNORM
:
694 return modifier
| R300_C2_SEL_A
;
695 case PIPE_FORMAT_I8_UNORM
:
696 case PIPE_FORMAT_I8_SNORM
:
697 case PIPE_FORMAT_L8_UNORM
:
698 case PIPE_FORMAT_L8_SNORM
:
699 case PIPE_FORMAT_R8_UNORM
:
700 case PIPE_FORMAT_R8_SNORM
:
701 return modifier
| R300_C2_SEL_R
;
704 * COLORFORMAT_UV88 stores ZX (C2 and C0). */
705 case PIPE_FORMAT_L8A8_SNORM
:
706 case PIPE_FORMAT_L8A8_UNORM
:
707 case PIPE_FORMAT_R8A8_SNORM
:
708 case PIPE_FORMAT_R8A8_UNORM
:
709 return modifier
| R300_C0_SEL_A
| R300_C2_SEL_R
;
710 case PIPE_FORMAT_R8G8_SNORM
:
711 case PIPE_FORMAT_R8G8_UNORM
:
712 return modifier
| R300_C0_SEL_G
| R300_C2_SEL_R
;
715 * ARGB16161616 stores XZ for RG32F */
716 case PIPE_FORMAT_R32G32_FLOAT
:
717 return modifier
| R300_C0_SEL_R
| R300_C2_SEL_G
;
719 /*** Generic cases (standard channel mapping) ***/
722 case PIPE_FORMAT_B5G6R5_UNORM
:
723 case PIPE_FORMAT_B5G5R5A1_UNORM
:
724 case PIPE_FORMAT_B5G5R5X1_UNORM
:
725 case PIPE_FORMAT_B4G4R4A4_UNORM
:
726 case PIPE_FORMAT_B4G4R4X4_UNORM
:
727 case PIPE_FORMAT_B8G8R8A8_UNORM
:
728 /*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
729 case PIPE_FORMAT_B8G8R8X8_UNORM
:
730 /*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
731 case PIPE_FORMAT_B10G10R10A2_UNORM
:
732 case PIPE_FORMAT_B10G10R10X2_UNORM
:
734 R300_C0_SEL_B
| R300_C1_SEL_G
|
735 R300_C2_SEL_R
| R300_C3_SEL_A
;
738 case PIPE_FORMAT_A16_UNORM
:
739 case PIPE_FORMAT_A16_SNORM
:
740 case PIPE_FORMAT_A16_FLOAT
:
741 case PIPE_FORMAT_A32_FLOAT
:
743 R300_C0_SEL_A
| R300_C1_SEL_R
|
744 R300_C2_SEL_G
| R300_C3_SEL_B
;
747 case PIPE_FORMAT_R8G8B8X8_UNORM
:
748 case PIPE_FORMAT_R8G8B8X8_SNORM
:
749 case PIPE_FORMAT_R8G8B8A8_UNORM
:
750 case PIPE_FORMAT_R8G8B8A8_SNORM
:
751 case PIPE_FORMAT_R10G10B10A2_UNORM
:
752 case PIPE_FORMAT_R10G10B10X2_SNORM
:
753 case PIPE_FORMAT_R16_UNORM
:
754 case PIPE_FORMAT_R16G16_UNORM
:
755 case PIPE_FORMAT_R16G16B16A16_UNORM
:
756 case PIPE_FORMAT_R16_SNORM
:
757 case PIPE_FORMAT_R16G16_SNORM
:
758 case PIPE_FORMAT_R16G16B16A16_SNORM
:
759 case PIPE_FORMAT_R16_FLOAT
:
760 case PIPE_FORMAT_R16G16_FLOAT
:
761 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
762 case PIPE_FORMAT_R32_FLOAT
:
763 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
764 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
765 case PIPE_FORMAT_L16_UNORM
:
766 case PIPE_FORMAT_L16_SNORM
:
767 case PIPE_FORMAT_L16_FLOAT
:
768 case PIPE_FORMAT_L32_FLOAT
:
769 case PIPE_FORMAT_I16_UNORM
:
770 case PIPE_FORMAT_I16_SNORM
:
771 case PIPE_FORMAT_I16_FLOAT
:
772 case PIPE_FORMAT_I32_FLOAT
:
773 case PIPE_FORMAT_R16G16B16X16_UNORM
:
774 case PIPE_FORMAT_R16G16B16X16_SNORM
:
775 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
777 R300_C0_SEL_R
| R300_C1_SEL_G
|
778 R300_C2_SEL_B
| R300_C3_SEL_A
;
781 case PIPE_FORMAT_L16A16_UNORM
:
782 case PIPE_FORMAT_L16A16_SNORM
:
783 case PIPE_FORMAT_L16A16_FLOAT
:
784 case PIPE_FORMAT_R16A16_UNORM
:
785 case PIPE_FORMAT_R16A16_SNORM
:
786 case PIPE_FORMAT_R16A16_FLOAT
:
787 case PIPE_FORMAT_L32A32_FLOAT
:
788 case PIPE_FORMAT_R32A32_FLOAT
:
790 R300_C0_SEL_R
| R300_C1_SEL_A
;
793 return ~0; /* Unsupported. */
797 static uint32_t r300_translate_colormask_swizzle(enum pipe_format format
)
799 format
= r300_unbyteswap_array_format(format
);
802 case PIPE_FORMAT_A8_UNORM
:
803 case PIPE_FORMAT_A8_SNORM
:
804 case PIPE_FORMAT_A16_UNORM
:
805 case PIPE_FORMAT_A16_SNORM
:
806 case PIPE_FORMAT_A16_FLOAT
:
807 case PIPE_FORMAT_A32_FLOAT
:
808 return COLORMASK_AAAA
;
810 case PIPE_FORMAT_I8_UNORM
:
811 case PIPE_FORMAT_I8_SNORM
:
812 case PIPE_FORMAT_L8_UNORM
:
813 case PIPE_FORMAT_L8_SNORM
:
814 case PIPE_FORMAT_R8_UNORM
:
815 case PIPE_FORMAT_R8_SNORM
:
816 case PIPE_FORMAT_R32_FLOAT
:
817 case PIPE_FORMAT_L32_FLOAT
:
818 case PIPE_FORMAT_I32_FLOAT
:
819 return COLORMASK_RRRR
;
821 case PIPE_FORMAT_L8A8_SNORM
:
822 case PIPE_FORMAT_L8A8_UNORM
:
823 case PIPE_FORMAT_R8A8_UNORM
:
824 case PIPE_FORMAT_R8A8_SNORM
:
825 case PIPE_FORMAT_L16A16_UNORM
:
826 case PIPE_FORMAT_L16A16_SNORM
:
827 case PIPE_FORMAT_L16A16_FLOAT
:
828 case PIPE_FORMAT_R16A16_UNORM
:
829 case PIPE_FORMAT_R16A16_SNORM
:
830 case PIPE_FORMAT_R16A16_FLOAT
:
831 case PIPE_FORMAT_L32A32_FLOAT
:
832 case PIPE_FORMAT_R32A32_FLOAT
:
833 return COLORMASK_ARRA
;
835 case PIPE_FORMAT_R8G8_SNORM
:
836 case PIPE_FORMAT_R8G8_UNORM
:
837 case PIPE_FORMAT_R16G16_UNORM
:
838 case PIPE_FORMAT_R16G16_SNORM
:
839 case PIPE_FORMAT_R16G16_FLOAT
:
840 case PIPE_FORMAT_R32G32_FLOAT
:
841 return COLORMASK_GRRG
;
843 case PIPE_FORMAT_B5G5R5X1_UNORM
:
844 case PIPE_FORMAT_B4G4R4X4_UNORM
:
845 case PIPE_FORMAT_B8G8R8X8_UNORM
:
846 /*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
847 case PIPE_FORMAT_B10G10R10X2_UNORM
:
848 return COLORMASK_BGRX
;
850 case PIPE_FORMAT_B5G6R5_UNORM
:
851 case PIPE_FORMAT_B5G5R5A1_UNORM
:
852 case PIPE_FORMAT_B4G4R4A4_UNORM
:
853 case PIPE_FORMAT_B8G8R8A8_UNORM
:
854 /*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
855 case PIPE_FORMAT_B10G10R10A2_UNORM
:
856 return COLORMASK_BGRA
;
858 case PIPE_FORMAT_R8G8B8X8_UNORM
:
859 /* RGBX_SNORM formats are broken for an unknown reason */
860 /*case PIPE_FORMAT_R8G8B8X8_SNORM:*/
861 /*case PIPE_FORMAT_R10G10B10X2_SNORM:*/
862 case PIPE_FORMAT_R16G16B16X16_UNORM
:
863 /*case PIPE_FORMAT_R16G16B16X16_SNORM:*/
864 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
865 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
866 return COLORMASK_RGBX
;
868 case PIPE_FORMAT_R8G8B8A8_UNORM
:
869 case PIPE_FORMAT_R8G8B8A8_SNORM
:
870 case PIPE_FORMAT_R10G10B10A2_UNORM
:
871 case PIPE_FORMAT_R16_UNORM
:
872 case PIPE_FORMAT_R16G16B16A16_UNORM
:
873 case PIPE_FORMAT_R16_SNORM
:
874 case PIPE_FORMAT_R16G16B16A16_SNORM
:
875 case PIPE_FORMAT_R16_FLOAT
:
876 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
877 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
878 case PIPE_FORMAT_L16_UNORM
:
879 case PIPE_FORMAT_L16_SNORM
:
880 case PIPE_FORMAT_L16_FLOAT
:
881 case PIPE_FORMAT_I16_UNORM
:
882 case PIPE_FORMAT_I16_SNORM
:
883 case PIPE_FORMAT_I16_FLOAT
:
884 return COLORMASK_RGBA
;
887 return ~0; /* Unsupported. */
891 boolean
r300_is_colorbuffer_format_supported(enum pipe_format format
)
893 return r300_translate_colorformat(format
) != ~0 &&
894 r300_translate_out_fmt(format
) != ~0 &&
895 r300_translate_colormask_swizzle(format
) != ~0;
898 boolean
r300_is_zs_format_supported(enum pipe_format format
)
900 return r300_translate_zsformat(format
) != ~0;
903 boolean
r300_is_sampler_format_supported(enum pipe_format format
)
905 return r300_translate_texformat(format
, 0, TRUE
, FALSE
) != ~0;
908 void r300_texture_setup_format_state(struct r300_screen
*screen
,
909 struct r300_resource
*tex
,
910 enum pipe_format format
,
912 unsigned width0_override
,
913 unsigned height0_override
,
914 struct r300_texture_format_state
*out
)
916 struct pipe_resource
*pt
= &tex
->b
.b
;
917 struct r300_texture_desc
*desc
= &tex
->tex
;
918 boolean is_r500
= screen
->caps
.is_r500
;
919 unsigned width
, height
, depth
;
920 unsigned txwidth
, txheight
, txdepth
;
922 width
= u_minify(width0_override
, level
);
923 height
= u_minify(height0_override
, level
);
924 depth
= u_minify(desc
->depth0
, level
);
926 txwidth
= (width
- 1) & 0x7ff;
927 txheight
= (height
- 1) & 0x7ff;
928 txdepth
= util_logbase2(depth
) & 0xf;
930 /* Mask out all the fields we change. */
932 out
->format1
&= ~R300_TX_FORMAT_TEX_COORD_TYPE_MASK
;
933 out
->format2
&= R500_TXFORMAT_MSB
;
934 out
->tile_config
= 0;
936 /* Set sampler state. */
938 R300_TX_WIDTH(txwidth
) |
939 R300_TX_HEIGHT(txheight
) |
940 R300_TX_DEPTH(txdepth
);
942 if (desc
->uses_stride_addressing
) {
944 r300_stride_to_width(format
, desc
->stride_in_bytes
[level
]);
945 /* rectangles love this */
946 out
->format0
|= R300_TX_PITCH_EN
;
947 out
->format2
= (stride
- 1) & 0x1fff;
950 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
951 out
->format1
|= R300_TX_FORMAT_CUBIC_MAP
;
953 if (pt
->target
== PIPE_TEXTURE_3D
) {
954 out
->format1
|= R300_TX_FORMAT_3D
;
957 /* large textures on r500 */
960 unsigned us_width
= txwidth
;
961 unsigned us_height
= txheight
;
962 unsigned us_depth
= txdepth
;
965 out
->format2
|= R500_TXWIDTH_BIT11
;
968 out
->format2
|= R500_TXHEIGHT_BIT11
;
971 /* The US_FORMAT register fixes an R500 TX addressing bug.
972 * Don't ask why it must be set like this. I don't know it either. */
974 us_width
= (0x000007FF + us_width
) >> 1;
975 us_depth
|= 0x0000000D;
978 us_height
= (0x000007FF + us_height
) >> 1;
979 us_depth
|= 0x0000000E;
983 R300_TX_WIDTH(us_width
) |
984 R300_TX_HEIGHT(us_height
) |
985 R300_TX_DEPTH(us_depth
);
988 out
->tile_config
= R300_TXO_MACRO_TILE(desc
->macrotile
[level
]) |
989 R300_TXO_MICRO_TILE(desc
->microtile
) |
990 R300_TXO_ENDIAN(r300_get_endian_swap(format
));
993 static void r300_texture_setup_fb_state(struct r300_surface
*surf
)
995 struct r300_resource
*tex
= r300_resource(surf
->base
.texture
);
996 unsigned level
= surf
->base
.u
.tex
.level
;
998 r300_stride_to_width(surf
->base
.format
, tex
->tex
.stride_in_bytes
[level
]);
1000 /* Set framebuffer state. */
1001 if (util_format_is_depth_or_stencil(surf
->base
.format
)) {
1004 R300_DEPTHMACROTILE(tex
->tex
.macrotile
[level
]) |
1005 R300_DEPTHMICROTILE(tex
->tex
.microtile
) |
1006 R300_DEPTHENDIAN(r300_get_endian_swap(surf
->base
.format
));
1007 surf
->format
= r300_translate_zsformat(surf
->base
.format
);
1008 surf
->pitch_zmask
= tex
->tex
.zmask_stride_in_pixels
[level
];
1009 surf
->pitch_hiz
= tex
->tex
.hiz_stride_in_pixels
[level
];
1011 enum pipe_format format
= util_format_linear(surf
->base
.format
);
1015 r300_translate_colorformat(format
) |
1016 R300_COLOR_TILE(tex
->tex
.macrotile
[level
]) |
1017 R300_COLOR_MICROTILE(tex
->tex
.microtile
) |
1018 R300_COLOR_ENDIAN(r300_get_endian_swap(format
));
1019 surf
->format
= r300_translate_out_fmt(format
);
1020 surf
->colormask_swizzle
=
1021 r300_translate_colormask_swizzle(format
);
1022 surf
->pitch_cmask
= tex
->tex
.cmask_stride_in_pixels
;
1026 static void r300_texture_destroy(struct pipe_screen
*screen
,
1027 struct pipe_resource
* texture
)
1029 struct r300_screen
*rscreen
= r300_screen(screen
);
1030 struct r300_resource
* tex
= (struct r300_resource
*)texture
;
1032 if (tex
->tex
.cmask_dwords
) {
1033 pipe_mutex_lock(rscreen
->cmask_mutex
);
1034 if (texture
== rscreen
->cmask_resource
) {
1035 rscreen
->cmask_resource
= NULL
;
1037 pipe_mutex_unlock(rscreen
->cmask_mutex
);
1039 pb_reference(&tex
->buf
, NULL
);
1043 boolean
r300_resource_get_handle(struct pipe_screen
* screen
,
1044 struct pipe_context
*ctx
,
1045 struct pipe_resource
*texture
,
1046 struct winsys_handle
*whandle
,
1049 struct radeon_winsys
*rws
= r300_screen(screen
)->rws
;
1050 struct r300_resource
* tex
= (struct r300_resource
*)texture
;
1056 return rws
->buffer_get_handle(tex
->buf
, tex
->tex
.stride_in_bytes
[0],
1060 static const struct u_resource_vtbl r300_texture_vtbl
=
1062 NULL
, /* get_handle */
1063 r300_texture_destroy
, /* resource_destroy */
1064 r300_texture_transfer_map
, /* transfer_map */
1065 NULL
, /* transfer_flush_region */
1066 r300_texture_transfer_unmap
, /* transfer_unmap */
1069 /* The common texture constructor. */
1070 static struct r300_resource
*
1071 r300_texture_create_object(struct r300_screen
*rscreen
,
1072 const struct pipe_resource
*base
,
1073 enum radeon_bo_layout microtile
,
1074 enum radeon_bo_layout macrotile
,
1075 unsigned stride_in_bytes_override
,
1076 struct pb_buffer
*buffer
)
1078 struct radeon_winsys
*rws
= rscreen
->rws
;
1079 struct r300_resource
*tex
= NULL
;
1080 struct radeon_bo_metadata tiling
= {};
1082 tex
= CALLOC_STRUCT(r300_resource
);
1087 pipe_reference_init(&tex
->b
.b
.reference
, 1);
1088 tex
->b
.b
.screen
= &rscreen
->screen
;
1089 tex
->b
.b
.usage
= base
->usage
;
1090 tex
->b
.b
.bind
= base
->bind
;
1091 tex
->b
.b
.flags
= base
->flags
;
1092 tex
->b
.vtbl
= &r300_texture_vtbl
;
1093 tex
->tex
.microtile
= microtile
;
1094 tex
->tex
.macrotile
[0] = macrotile
;
1095 tex
->tex
.stride_in_bytes_override
= stride_in_bytes_override
;
1096 tex
->domain
= (base
->flags
& R300_RESOURCE_FLAG_TRANSFER
||
1097 base
->usage
== PIPE_USAGE_STAGING
) ? RADEON_DOMAIN_GTT
:
1098 base
->nr_samples
> 1 ? RADEON_DOMAIN_VRAM
:
1099 RADEON_DOMAIN_VRAM
| RADEON_DOMAIN_GTT
;
1102 r300_texture_desc_init(rscreen
, tex
, base
);
1104 /* Figure out the ideal placement for the texture.. */
1105 if (tex
->domain
& RADEON_DOMAIN_VRAM
&&
1106 tex
->tex
.size_in_bytes
>= rscreen
->info
.vram_size
) {
1107 tex
->domain
&= ~RADEON_DOMAIN_VRAM
;
1108 tex
->domain
|= RADEON_DOMAIN_GTT
;
1110 if (tex
->domain
& RADEON_DOMAIN_GTT
&&
1111 tex
->tex
.size_in_bytes
>= rscreen
->info
.gart_size
) {
1112 tex
->domain
&= ~RADEON_DOMAIN_GTT
;
1114 /* Just fail if the texture is too large. */
1119 /* Create the backing buffer if needed. */
1121 tex
->buf
= rws
->buffer_create(rws
, tex
->tex
.size_in_bytes
, 2048,
1122 tex
->domain
, RADEON_FLAG_HANDLE
);
1129 if (SCREEN_DBG_ON(rscreen
, DBG_MSAA
) && base
->nr_samples
> 1) {
1130 fprintf(stderr
, "r300: %ix MSAA %s buffer created\n",
1132 util_format_is_depth_or_stencil(base
->format
) ? "depth" : "color");
1135 tiling
.microtile
= tex
->tex
.microtile
;
1136 tiling
.macrotile
= tex
->tex
.macrotile
[0];
1137 tiling
.stride
= tex
->tex
.stride_in_bytes
[0];
1138 rws
->buffer_set_metadata(tex
->buf
, &tiling
);
1145 pb_reference(&buffer
, NULL
);
1149 /* Create a new texture. */
1150 struct pipe_resource
*r300_texture_create(struct pipe_screen
*screen
,
1151 const struct pipe_resource
*base
)
1153 struct r300_screen
*rscreen
= r300_screen(screen
);
1154 enum radeon_bo_layout microtile
, macrotile
;
1156 if ((base
->flags
& R300_RESOURCE_FLAG_TRANSFER
) ||
1157 (base
->bind
& (PIPE_BIND_SCANOUT
| PIPE_BIND_LINEAR
))) {
1158 microtile
= RADEON_LAYOUT_LINEAR
;
1159 macrotile
= RADEON_LAYOUT_LINEAR
;
1161 /* This will make the texture_create_function select the layout. */
1162 microtile
= RADEON_LAYOUT_UNKNOWN
;
1163 macrotile
= RADEON_LAYOUT_UNKNOWN
;
1166 return (struct pipe_resource
*)
1167 r300_texture_create_object(rscreen
, base
, microtile
, macrotile
,
1171 struct pipe_resource
*r300_texture_from_handle(struct pipe_screen
*screen
,
1172 const struct pipe_resource
*base
,
1173 struct winsys_handle
*whandle
,
1176 struct r300_screen
*rscreen
= r300_screen(screen
);
1177 struct radeon_winsys
*rws
= rscreen
->rws
;
1178 struct pb_buffer
*buffer
;
1180 struct radeon_bo_metadata tiling
= {};
1182 /* Support only 2D textures without mipmaps */
1183 if ((base
->target
!= PIPE_TEXTURE_2D
&&
1184 base
->target
!= PIPE_TEXTURE_RECT
) ||
1185 base
->depth0
!= 1 ||
1186 base
->last_level
!= 0) {
1190 buffer
= rws
->buffer_from_handle(rws
, whandle
, &stride
, NULL
);
1194 rws
->buffer_get_metadata(buffer
, &tiling
);
1196 /* Enforce a microtiled zbuffer. */
1197 if (util_format_is_depth_or_stencil(base
->format
) &&
1198 tiling
.microtile
== RADEON_LAYOUT_LINEAR
) {
1199 switch (util_format_get_blocksize(base
->format
)) {
1201 tiling
.microtile
= RADEON_LAYOUT_TILED
;
1205 tiling
.microtile
= RADEON_LAYOUT_SQUARETILED
;
1210 return (struct pipe_resource
*)
1211 r300_texture_create_object(rscreen
, base
, tiling
.microtile
, tiling
.macrotile
,
1215 /* Not required to implement u_resource_vtbl, consider moving to another file:
1217 struct pipe_surface
* r300_create_surface_custom(struct pipe_context
* ctx
,
1218 struct pipe_resource
* texture
,
1219 const struct pipe_surface
*surf_tmpl
,
1220 unsigned width0_override
,
1221 unsigned height0_override
)
1223 struct r300_resource
* tex
= r300_resource(texture
);
1224 struct r300_surface
* surface
= CALLOC_STRUCT(r300_surface
);
1225 unsigned level
= surf_tmpl
->u
.tex
.level
;
1227 assert(surf_tmpl
->u
.tex
.first_layer
== surf_tmpl
->u
.tex
.last_layer
);
1230 uint32_t offset
, tile_height
;
1232 pipe_reference_init(&surface
->base
.reference
, 1);
1233 pipe_resource_reference(&surface
->base
.texture
, texture
);
1234 surface
->base
.context
= ctx
;
1235 surface
->base
.format
= surf_tmpl
->format
;
1236 surface
->base
.width
= u_minify(width0_override
, level
);
1237 surface
->base
.height
= u_minify(height0_override
, level
);
1238 surface
->base
.u
.tex
.level
= level
;
1239 surface
->base
.u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
1240 surface
->base
.u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
1242 surface
->buf
= tex
->buf
;
1243 surface
->buf
= tex
->buf
;
1245 /* Prefer VRAM if there are multiple domains to choose from. */
1246 surface
->domain
= tex
->domain
;
1247 if (surface
->domain
& RADEON_DOMAIN_VRAM
)
1248 surface
->domain
&= ~RADEON_DOMAIN_GTT
;
1250 surface
->offset
= r300_texture_get_offset(tex
, level
,
1251 surf_tmpl
->u
.tex
.first_layer
);
1252 r300_texture_setup_fb_state(surface
);
1254 /* Parameters for the CBZB clear. */
1255 surface
->cbzb_allowed
= tex
->tex
.cbzb_allowed
[level
];
1256 surface
->cbzb_width
= align(surface
->base
.width
, 64);
1258 /* Height must be aligned to the size of a tile. */
1259 tile_height
= r300_get_pixel_alignment(surface
->base
.format
,
1260 tex
->b
.b
.nr_samples
,
1262 tex
->tex
.macrotile
[level
],
1265 surface
->cbzb_height
= align((surface
->base
.height
+ 1) / 2,
1268 /* Offset must be aligned to 2K and must point at the beginning
1270 offset
= surface
->offset
+
1271 tex
->tex
.stride_in_bytes
[level
] * surface
->cbzb_height
;
1272 surface
->cbzb_midpoint_offset
= offset
& ~2047;
1274 surface
->cbzb_pitch
= surface
->pitch
& 0x1ffffc;
1276 if (util_format_get_blocksizebits(surface
->base
.format
) == 32)
1277 surface
->cbzb_format
= R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL
;
1279 surface
->cbzb_format
= R300_DEPTHFORMAT_16BIT_INT_Z
;
1281 DBG(r300_context(ctx
), DBG_CBZB
,
1282 "CBZB Allowed: %s, Dim: %ix%i, Misalignment: %i, Micro: %s, Macro: %s\n",
1283 surface
->cbzb_allowed
? "YES" : " NO",
1284 surface
->cbzb_width
, surface
->cbzb_height
,
1286 tex
->tex
.microtile
? "YES" : " NO",
1287 tex
->tex
.macrotile
[level
] ? "YES" : " NO");
1290 return &surface
->base
;
1293 struct pipe_surface
* r300_create_surface(struct pipe_context
* ctx
,
1294 struct pipe_resource
* texture
,
1295 const struct pipe_surface
*surf_tmpl
)
1297 return r300_create_surface_custom(ctx
, texture
, surf_tmpl
,
1302 /* Not required to implement u_resource_vtbl, consider moving to another file:
1304 void r300_surface_destroy(struct pipe_context
*ctx
, struct pipe_surface
* s
)
1306 pipe_resource_reference(&s
->texture
, NULL
);