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"
38 #include "pipe/p_screen.h"
40 /* These formats are supported by swapping their bytes.
41 * The swizzles must be set exactly like their non-swapped counterparts,
42 * because byte-swapping is what reverses the component order, not swizzling.
44 * This function returns the format that must be used to program CB and TX
47 static enum pipe_format
r300_unbyteswap_array_format(enum pipe_format format
)
49 /* FIXME: Disabled on little endian because of a reported regression:
50 * https://bugs.freedesktop.org/show_bug.cgi?id=98869 */
51 if (PIPE_ENDIAN_NATIVE
!= PIPE_ENDIAN_BIG
)
54 /* Only BGRA 8888 array formats are supported for simplicity of
55 * the implementation. */
57 case PIPE_FORMAT_A8R8G8B8_UNORM
:
58 return PIPE_FORMAT_B8G8R8A8_UNORM
;
59 case PIPE_FORMAT_A8R8G8B8_SRGB
:
60 return PIPE_FORMAT_B8G8R8A8_SRGB
;
61 case PIPE_FORMAT_X8R8G8B8_UNORM
:
62 return PIPE_FORMAT_B8G8R8X8_UNORM
;
63 case PIPE_FORMAT_X8R8G8B8_SRGB
:
64 return PIPE_FORMAT_B8G8R8X8_SRGB
;
70 static unsigned r300_get_endian_swap(enum pipe_format format
)
72 const struct util_format_description
*desc
;
75 if (r300_unbyteswap_array_format(format
) != format
)
76 return R300_SURF_DWORD_SWAP
;
78 if (PIPE_ENDIAN_NATIVE
!= PIPE_ENDIAN_BIG
)
79 return R300_SURF_NO_SWAP
;
81 desc
= util_format_description(format
);
83 return R300_SURF_NO_SWAP
;
85 /* Compressed formats should be in the little endian format. */
86 if (desc
->block
.width
!= 1 || desc
->block
.height
!= 1)
87 return R300_SURF_NO_SWAP
;
89 swap_size
= desc
->is_array
? desc
->channel
[0].size
: desc
->block
.bits
;
92 default: /* shouldn't happen? */
94 return R300_SURF_NO_SWAP
;
96 return R300_SURF_WORD_SWAP
;
98 return R300_SURF_DWORD_SWAP
;
102 unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format
,
103 const unsigned char *swizzle_view
,
104 boolean dxtc_swizzle
)
107 unsigned char swizzle
[4];
109 const uint32_t swizzle_shift
[4] = {
110 R300_TX_FORMAT_R_SHIFT
,
111 R300_TX_FORMAT_G_SHIFT
,
112 R300_TX_FORMAT_B_SHIFT
,
113 R300_TX_FORMAT_A_SHIFT
115 uint32_t swizzle_bit
[4] = {
116 dxtc_swizzle
? R300_TX_FORMAT_Z
: R300_TX_FORMAT_X
,
118 dxtc_swizzle
? R300_TX_FORMAT_X
: R300_TX_FORMAT_Z
,
123 /* Combine two sets of swizzles. */
124 util_format_compose_swizzles(swizzle_format
, swizzle_view
, swizzle
);
126 memcpy(swizzle
, swizzle_format
, 4);
130 for (i
= 0; i
< 4; i
++) {
131 switch (swizzle
[i
]) {
133 result
|= swizzle_bit
[1] << swizzle_shift
[i
];
136 result
|= swizzle_bit
[2] << swizzle_shift
[i
];
139 result
|= swizzle_bit
[3] << swizzle_shift
[i
];
142 result
|= R300_TX_FORMAT_ZERO
<< swizzle_shift
[i
];
145 result
|= R300_TX_FORMAT_ONE
<< swizzle_shift
[i
];
147 default: /* PIPE_SWIZZLE_X */
148 result
|= swizzle_bit
[0] << swizzle_shift
[i
];
154 /* Translate a pipe_format into a useful texture format for sampling.
156 * Some special formats are translated directly using R300_EASY_TX_FORMAT,
157 * but the majority of them is translated in a generic way, automatically
158 * supporting all the formats hw can support.
160 * R300_EASY_TX_FORMAT swizzles the texture.
161 * Note the signature of R300_EASY_TX_FORMAT:
162 * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT);
164 * The FORMAT specifies how the texture sampler will treat the texture, and
165 * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */
166 uint32_t r300_translate_texformat(enum pipe_format format
,
167 const unsigned char *swizzle_view
,
169 boolean dxtc_swizzle
)
172 const struct util_format_description
*desc
;
174 boolean uniform
= TRUE
;
175 const uint32_t sign_bit
[4] = {
176 R300_TX_FORMAT_SIGNED_W
,
177 R300_TX_FORMAT_SIGNED_Z
,
178 R300_TX_FORMAT_SIGNED_Y
,
179 R300_TX_FORMAT_SIGNED_X
,
182 format
= r300_unbyteswap_array_format(format
);
183 desc
= util_format_description(format
);
185 /* Colorspace (return non-RGB formats directly). */
186 switch (desc
->colorspace
) {
187 /* Depth stencil formats.
188 * Swizzles are added in r300_merge_textures_and_samplers. */
189 case UTIL_FORMAT_COLORSPACE_ZS
:
191 case PIPE_FORMAT_Z16_UNORM
:
192 return R300_TX_FORMAT_X16
;
193 case PIPE_FORMAT_X8Z24_UNORM
:
194 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
196 return R500_TX_FORMAT_Y8X24
;
198 return R300_TX_FORMAT_Y16X16
;
200 return ~0; /* Unsupported. */
204 case UTIL_FORMAT_COLORSPACE_YUV
:
205 result
|= R300_TX_FORMAT_YUV_TO_RGB
;
208 case PIPE_FORMAT_UYVY
:
209 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, YVYU422
) | result
;
210 case PIPE_FORMAT_YUYV
:
211 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, VYUY422
) | result
;
213 return ~0; /* Unsupported/unknown. */
216 /* Add gamma correction. */
217 case UTIL_FORMAT_COLORSPACE_SRGB
:
218 result
|= R300_TX_FORMAT_GAMMA
;
223 /* Same as YUV but without the YUR->RGB conversion. */
224 case PIPE_FORMAT_R8G8_B8G8_UNORM
:
225 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, YVYU422
) | result
;
226 case PIPE_FORMAT_G8R8_G8B8_UNORM
:
227 return R300_EASY_TX_FORMAT(X
, Y
, Z
, ONE
, VYUY422
) | result
;
233 /* The RGTC1_SNORM and LATC1_SNORM swizzle is done in the shader. */
234 if (util_format_is_compressed(format
) &&
236 format
!= PIPE_FORMAT_RGTC2_UNORM
&&
237 format
!= PIPE_FORMAT_RGTC2_SNORM
&&
238 format
!= PIPE_FORMAT_LATC2_UNORM
&&
239 format
!= PIPE_FORMAT_LATC2_SNORM
&&
240 format
!= PIPE_FORMAT_RGTC1_UNORM
&&
241 format
!= PIPE_FORMAT_RGTC1_SNORM
&&
242 format
!= PIPE_FORMAT_LATC1_UNORM
&&
243 format
!= PIPE_FORMAT_LATC1_SNORM
) {
244 result
|= r300_get_swizzle_combined(desc
->swizzle
, swizzle_view
,
247 result
|= r300_get_swizzle_combined(desc
->swizzle
, swizzle_view
,
252 if (desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
253 if (!util_format_s3tc_enabled
) {
254 return ~0; /* Unsupported. */
258 case PIPE_FORMAT_DXT1_RGB
:
259 case PIPE_FORMAT_DXT1_RGBA
:
260 case PIPE_FORMAT_DXT1_SRGB
:
261 case PIPE_FORMAT_DXT1_SRGBA
:
262 return R300_TX_FORMAT_DXT1
| result
;
263 case PIPE_FORMAT_DXT3_RGBA
:
264 case PIPE_FORMAT_DXT3_SRGBA
:
265 return R300_TX_FORMAT_DXT3
| result
;
266 case PIPE_FORMAT_DXT5_RGBA
:
267 case PIPE_FORMAT_DXT5_SRGBA
:
268 return R300_TX_FORMAT_DXT5
| result
;
270 return ~0; /* Unsupported/unknown. */
275 if (desc
->layout
== UTIL_FORMAT_LAYOUT_RGTC
) {
277 case PIPE_FORMAT_RGTC1_SNORM
:
278 case PIPE_FORMAT_LATC1_SNORM
:
279 result
|= sign_bit
[0];
280 case PIPE_FORMAT_LATC1_UNORM
:
281 case PIPE_FORMAT_RGTC1_UNORM
:
282 return R500_TX_FORMAT_ATI1N
| result
;
284 case PIPE_FORMAT_RGTC2_SNORM
:
285 case PIPE_FORMAT_LATC2_SNORM
:
286 result
|= sign_bit
[1] | sign_bit
[0];
287 case PIPE_FORMAT_RGTC2_UNORM
:
288 case PIPE_FORMAT_LATC2_UNORM
:
289 return R400_TX_FORMAT_ATI2N
| result
;
292 return ~0; /* Unsupported/unknown. */
296 /* This is truly a special format.
297 * It stores R8G8 and B is computed using sqrt(1 - R^2 - G^2)
298 * in the sampler unit. Also known as D3DFMT_CxV8U8. */
299 if (format
== PIPE_FORMAT_R8G8Bx_SNORM
) {
300 return R300_TX_FORMAT_CxV8U8
| result
;
303 /* Integer and fixed-point 16.16 textures are not supported. */
304 for (i
= 0; i
< 4; i
++) {
305 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FIXED
||
306 ((desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
||
307 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
) &&
308 (!desc
->channel
[i
].normalized
||
309 desc
->channel
[i
].pure_integer
))) {
310 return ~0; /* Unsupported/unknown. */
315 for (i
= 0; i
< desc
->nr_channels
; i
++) {
316 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
317 result
|= sign_bit
[i
];
321 /* See whether the components are of the same size. */
322 for (i
= 1; i
< desc
->nr_channels
; i
++) {
323 uniform
= uniform
&& desc
->channel
[0].size
== desc
->channel
[i
].size
;
326 /* Non-uniform formats. */
328 switch (desc
->nr_channels
) {
330 if (desc
->channel
[0].size
== 5 &&
331 desc
->channel
[1].size
== 6 &&
332 desc
->channel
[2].size
== 5) {
333 return R300_TX_FORMAT_Z5Y6X5
| result
;
335 if (desc
->channel
[0].size
== 5 &&
336 desc
->channel
[1].size
== 5 &&
337 desc
->channel
[2].size
== 6) {
338 return R300_TX_FORMAT_Z6Y5X5
| result
;
340 if (desc
->channel
[0].size
== 2 &&
341 desc
->channel
[1].size
== 3 &&
342 desc
->channel
[2].size
== 3) {
343 return R300_TX_FORMAT_Z3Y3X2
| result
;
345 return ~0; /* Unsupported/unknown. */
348 if (desc
->channel
[0].size
== 5 &&
349 desc
->channel
[1].size
== 5 &&
350 desc
->channel
[2].size
== 5 &&
351 desc
->channel
[3].size
== 1) {
352 return R300_TX_FORMAT_W1Z5Y5X5
| result
;
354 if (desc
->channel
[0].size
== 10 &&
355 desc
->channel
[1].size
== 10 &&
356 desc
->channel
[2].size
== 10 &&
357 desc
->channel
[3].size
== 2) {
358 return R300_TX_FORMAT_W2Z10Y10X10
| result
;
361 return ~0; /* Unsupported/unknown. */
364 /* Find the first non-VOID channel. */
365 for (i
= 0; i
< 4; i
++) {
366 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
372 return ~0; /* Unsupported/unknown. */
374 /* And finally, uniform formats. */
375 switch (desc
->channel
[i
].type
) {
376 case UTIL_FORMAT_TYPE_UNSIGNED
:
377 case UTIL_FORMAT_TYPE_SIGNED
:
378 if (!desc
->channel
[i
].normalized
&&
379 desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_SRGB
) {
383 switch (desc
->channel
[i
].size
) {
385 switch (desc
->nr_channels
) {
387 return R300_TX_FORMAT_Y4X4
| result
;
389 return R300_TX_FORMAT_W4Z4Y4X4
| result
;
394 switch (desc
->nr_channels
) {
396 return R300_TX_FORMAT_X8
| result
;
398 return R300_TX_FORMAT_Y8X8
| result
;
400 return R300_TX_FORMAT_W8Z8Y8X8
| result
;
405 switch (desc
->nr_channels
) {
407 return R300_TX_FORMAT_X16
| result
;
409 return R300_TX_FORMAT_Y16X16
| result
;
411 return R300_TX_FORMAT_W16Z16Y16X16
| result
;
416 case UTIL_FORMAT_TYPE_FLOAT
:
417 switch (desc
->channel
[i
].size
) {
419 switch (desc
->nr_channels
) {
421 return R300_TX_FORMAT_16F
| result
;
423 return R300_TX_FORMAT_16F_16F
| result
;
425 return R300_TX_FORMAT_16F_16F_16F_16F
| result
;
430 switch (desc
->nr_channels
) {
432 return R300_TX_FORMAT_32F
| result
;
434 return R300_TX_FORMAT_32F_32F
| result
;
436 return R300_TX_FORMAT_32F_32F_32F_32F
| result
;
441 return ~0; /* Unsupported/unknown. */
444 uint32_t r500_tx_format_msb_bit(enum pipe_format format
)
447 case PIPE_FORMAT_RGTC1_UNORM
:
448 case PIPE_FORMAT_RGTC1_SNORM
:
449 case PIPE_FORMAT_LATC1_UNORM
:
450 case PIPE_FORMAT_LATC1_SNORM
:
451 case PIPE_FORMAT_X8Z24_UNORM
:
452 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
453 return R500_TXFORMAT_MSB
;
459 /* Buffer formats. */
461 /* Colorbuffer formats. This is the unswizzled format of the RB3D block's
462 * output. For the swizzling of the targets, check the shader's format. */
463 static uint32_t r300_translate_colorformat(enum pipe_format format
)
465 format
= r300_unbyteswap_array_format(format
);
469 case PIPE_FORMAT_A8_UNORM
:
470 case PIPE_FORMAT_A8_SNORM
:
471 case PIPE_FORMAT_I8_UNORM
:
472 case PIPE_FORMAT_I8_SNORM
:
473 case PIPE_FORMAT_L8_UNORM
:
474 case PIPE_FORMAT_L8_SNORM
:
475 case PIPE_FORMAT_R8_UNORM
:
476 case PIPE_FORMAT_R8_SNORM
:
477 return R300_COLOR_FORMAT_I8
;
479 /* 16-bit buffers. */
480 case PIPE_FORMAT_L8A8_UNORM
:
481 case PIPE_FORMAT_L8A8_SNORM
:
482 case PIPE_FORMAT_R8G8_UNORM
:
483 case PIPE_FORMAT_R8G8_SNORM
:
484 case PIPE_FORMAT_R8A8_UNORM
:
485 case PIPE_FORMAT_R8A8_SNORM
:
486 /* These formats work fine with UV88 if US_OUT_FMT is set correctly. */
487 case PIPE_FORMAT_A16_UNORM
:
488 case PIPE_FORMAT_A16_SNORM
:
489 case PIPE_FORMAT_A16_FLOAT
:
490 case PIPE_FORMAT_L16_UNORM
:
491 case PIPE_FORMAT_L16_SNORM
:
492 case PIPE_FORMAT_L16_FLOAT
:
493 case PIPE_FORMAT_I16_UNORM
:
494 case PIPE_FORMAT_I16_SNORM
:
495 case PIPE_FORMAT_I16_FLOAT
:
496 case PIPE_FORMAT_R16_UNORM
:
497 case PIPE_FORMAT_R16_SNORM
:
498 case PIPE_FORMAT_R16_FLOAT
:
499 return R300_COLOR_FORMAT_UV88
;
501 case PIPE_FORMAT_B5G6R5_UNORM
:
502 return R300_COLOR_FORMAT_RGB565
;
504 case PIPE_FORMAT_B5G5R5A1_UNORM
:
505 case PIPE_FORMAT_B5G5R5X1_UNORM
:
506 return R300_COLOR_FORMAT_ARGB1555
;
508 case PIPE_FORMAT_B4G4R4A4_UNORM
:
509 case PIPE_FORMAT_B4G4R4X4_UNORM
:
510 return R300_COLOR_FORMAT_ARGB4444
;
512 /* 32-bit buffers. */
513 case PIPE_FORMAT_B8G8R8A8_UNORM
:
514 /*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
515 case PIPE_FORMAT_B8G8R8X8_UNORM
:
516 /*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
517 case PIPE_FORMAT_R8G8B8A8_UNORM
:
518 case PIPE_FORMAT_R8G8B8A8_SNORM
:
519 case PIPE_FORMAT_R8G8B8X8_UNORM
:
520 case PIPE_FORMAT_R8G8B8X8_SNORM
:
521 /* These formats work fine with ARGB8888 if US_OUT_FMT is set
523 case PIPE_FORMAT_R16G16_UNORM
:
524 case PIPE_FORMAT_R16G16_SNORM
:
525 case PIPE_FORMAT_R16G16_FLOAT
:
526 case PIPE_FORMAT_L16A16_UNORM
:
527 case PIPE_FORMAT_L16A16_SNORM
:
528 case PIPE_FORMAT_L16A16_FLOAT
:
529 case PIPE_FORMAT_R16A16_UNORM
:
530 case PIPE_FORMAT_R16A16_SNORM
:
531 case PIPE_FORMAT_R16A16_FLOAT
:
532 case PIPE_FORMAT_A32_FLOAT
:
533 case PIPE_FORMAT_L32_FLOAT
:
534 case PIPE_FORMAT_I32_FLOAT
:
535 case PIPE_FORMAT_R32_FLOAT
:
536 return R300_COLOR_FORMAT_ARGB8888
;
538 case PIPE_FORMAT_R10G10B10A2_UNORM
:
539 case PIPE_FORMAT_R10G10B10X2_SNORM
:
540 case PIPE_FORMAT_B10G10R10A2_UNORM
:
541 case PIPE_FORMAT_B10G10R10X2_UNORM
:
542 return R500_COLOR_FORMAT_ARGB2101010
; /* R5xx-only? */
544 /* 64-bit buffers. */
545 case PIPE_FORMAT_R16G16B16A16_UNORM
:
546 case PIPE_FORMAT_R16G16B16A16_SNORM
:
547 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
548 case PIPE_FORMAT_R16G16B16X16_UNORM
:
549 case PIPE_FORMAT_R16G16B16X16_SNORM
:
550 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
551 /* These formats work fine with ARGB16161616 if US_OUT_FMT is set
553 case PIPE_FORMAT_R32G32_FLOAT
:
554 case PIPE_FORMAT_L32A32_FLOAT
:
555 case PIPE_FORMAT_R32A32_FLOAT
:
556 return R300_COLOR_FORMAT_ARGB16161616
;
558 /* 128-bit buffers. */
559 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
560 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
561 return R300_COLOR_FORMAT_ARGB32323232
;
564 case PIPE_FORMAT_UYVY
:
565 return R300_COLOR_FORMAT_YVYU
;
566 case PIPE_FORMAT_YUYV
:
567 return R300_COLOR_FORMAT_VYUY
;
569 return ~0; /* Unsupported. */
573 /* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */
574 static uint32_t r300_translate_zsformat(enum pipe_format format
)
577 /* 16-bit depth, no stencil */
578 case PIPE_FORMAT_Z16_UNORM
:
579 return R300_DEPTHFORMAT_16BIT_INT_Z
;
580 /* 24-bit depth, ignored stencil */
581 case PIPE_FORMAT_X8Z24_UNORM
:
582 /* 24-bit depth, 8-bit stencil */
583 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
584 return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL
;
586 return ~0; /* Unsupported. */
590 /* Shader output formats. This is essentially the swizzle from the shader
593 * Note that formats are stored from C3 to C0. */
594 static uint32_t r300_translate_out_fmt(enum pipe_format format
)
596 uint32_t modifier
= 0;
598 const struct util_format_description
*desc
;
599 boolean uniform_sign
;
601 format
= r300_unbyteswap_array_format(format
);
602 desc
= util_format_description(format
);
604 /* Find the first non-VOID channel. */
605 for (i
= 0; i
< 4; i
++) {
606 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
612 return ~0; /* Unsupported/unknown. */
614 /* Specifies how the shader output is written to the fog unit. */
615 switch (desc
->channel
[i
].type
) {
616 case UTIL_FORMAT_TYPE_FLOAT
:
617 switch (desc
->channel
[i
].size
) {
619 switch (desc
->nr_channels
) {
621 modifier
|= R300_US_OUT_FMT_C_32_FP
;
624 modifier
|= R300_US_OUT_FMT_C2_32_FP
;
627 modifier
|= R300_US_OUT_FMT_C4_32_FP
;
633 switch (desc
->nr_channels
) {
635 modifier
|= R300_US_OUT_FMT_C_16_FP
;
638 modifier
|= R300_US_OUT_FMT_C2_16_FP
;
641 modifier
|= R300_US_OUT_FMT_C4_16_FP
;
649 switch (desc
->channel
[i
].size
) {
651 switch (desc
->nr_channels
) {
653 modifier
|= R300_US_OUT_FMT_C_16
;
656 modifier
|= R300_US_OUT_FMT_C2_16
;
659 modifier
|= R300_US_OUT_FMT_C4_16
;
665 modifier
|= R300_US_OUT_FMT_C4_10
;
669 /* C4_8 seems to be used for the formats whose pixel size
671 modifier
|= R300_US_OUT_FMT_C4_8
;
678 for (i
= 0; i
< desc
->nr_channels
; i
++)
679 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_SIGNED
)
680 uniform_sign
= FALSE
;
683 modifier
|= R300_OUT_SIGN(0xf);
685 /* Add swizzles and return. */
687 /*** Special cases (non-standard channel mapping) ***/
690 * COLORFORMAT_I8 stores the Z component (C2). */
691 case PIPE_FORMAT_A8_UNORM
:
692 case PIPE_FORMAT_A8_SNORM
:
693 return modifier
| R300_C2_SEL_A
;
694 case PIPE_FORMAT_I8_UNORM
:
695 case PIPE_FORMAT_I8_SNORM
:
696 case PIPE_FORMAT_L8_UNORM
:
697 case PIPE_FORMAT_L8_SNORM
:
698 case PIPE_FORMAT_R8_UNORM
:
699 case PIPE_FORMAT_R8_SNORM
:
700 return modifier
| R300_C2_SEL_R
;
703 * COLORFORMAT_UV88 stores ZX (C2 and C0). */
704 case PIPE_FORMAT_L8A8_SNORM
:
705 case PIPE_FORMAT_L8A8_UNORM
:
706 case PIPE_FORMAT_R8A8_SNORM
:
707 case PIPE_FORMAT_R8A8_UNORM
:
708 return modifier
| R300_C0_SEL_A
| R300_C2_SEL_R
;
709 case PIPE_FORMAT_R8G8_SNORM
:
710 case PIPE_FORMAT_R8G8_UNORM
:
711 return modifier
| R300_C0_SEL_G
| R300_C2_SEL_R
;
714 * ARGB16161616 stores XZ for RG32F */
715 case PIPE_FORMAT_R32G32_FLOAT
:
716 return modifier
| R300_C0_SEL_R
| R300_C2_SEL_G
;
718 /*** Generic cases (standard channel mapping) ***/
721 case PIPE_FORMAT_B5G6R5_UNORM
:
722 case PIPE_FORMAT_B5G5R5A1_UNORM
:
723 case PIPE_FORMAT_B5G5R5X1_UNORM
:
724 case PIPE_FORMAT_B4G4R4A4_UNORM
:
725 case PIPE_FORMAT_B4G4R4X4_UNORM
:
726 case PIPE_FORMAT_B8G8R8A8_UNORM
:
727 /*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
728 case PIPE_FORMAT_B8G8R8X8_UNORM
:
729 /*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
730 case PIPE_FORMAT_B10G10R10A2_UNORM
:
731 case PIPE_FORMAT_B10G10R10X2_UNORM
:
733 R300_C0_SEL_B
| R300_C1_SEL_G
|
734 R300_C2_SEL_R
| R300_C3_SEL_A
;
737 case PIPE_FORMAT_A16_UNORM
:
738 case PIPE_FORMAT_A16_SNORM
:
739 case PIPE_FORMAT_A16_FLOAT
:
740 case PIPE_FORMAT_A32_FLOAT
:
742 R300_C0_SEL_A
| R300_C1_SEL_R
|
743 R300_C2_SEL_G
| R300_C3_SEL_B
;
746 case PIPE_FORMAT_R8G8B8X8_UNORM
:
747 case PIPE_FORMAT_R8G8B8X8_SNORM
:
748 case PIPE_FORMAT_R8G8B8A8_UNORM
:
749 case PIPE_FORMAT_R8G8B8A8_SNORM
:
750 case PIPE_FORMAT_R10G10B10A2_UNORM
:
751 case PIPE_FORMAT_R10G10B10X2_SNORM
:
752 case PIPE_FORMAT_R16_UNORM
:
753 case PIPE_FORMAT_R16G16_UNORM
:
754 case PIPE_FORMAT_R16G16B16A16_UNORM
:
755 case PIPE_FORMAT_R16_SNORM
:
756 case PIPE_FORMAT_R16G16_SNORM
:
757 case PIPE_FORMAT_R16G16B16A16_SNORM
:
758 case PIPE_FORMAT_R16_FLOAT
:
759 case PIPE_FORMAT_R16G16_FLOAT
:
760 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
761 case PIPE_FORMAT_R32_FLOAT
:
762 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
763 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
764 case PIPE_FORMAT_L16_UNORM
:
765 case PIPE_FORMAT_L16_SNORM
:
766 case PIPE_FORMAT_L16_FLOAT
:
767 case PIPE_FORMAT_L32_FLOAT
:
768 case PIPE_FORMAT_I16_UNORM
:
769 case PIPE_FORMAT_I16_SNORM
:
770 case PIPE_FORMAT_I16_FLOAT
:
771 case PIPE_FORMAT_I32_FLOAT
:
772 case PIPE_FORMAT_R16G16B16X16_UNORM
:
773 case PIPE_FORMAT_R16G16B16X16_SNORM
:
774 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
776 R300_C0_SEL_R
| R300_C1_SEL_G
|
777 R300_C2_SEL_B
| R300_C3_SEL_A
;
780 case PIPE_FORMAT_L16A16_UNORM
:
781 case PIPE_FORMAT_L16A16_SNORM
:
782 case PIPE_FORMAT_L16A16_FLOAT
:
783 case PIPE_FORMAT_R16A16_UNORM
:
784 case PIPE_FORMAT_R16A16_SNORM
:
785 case PIPE_FORMAT_R16A16_FLOAT
:
786 case PIPE_FORMAT_L32A32_FLOAT
:
787 case PIPE_FORMAT_R32A32_FLOAT
:
789 R300_C0_SEL_R
| R300_C1_SEL_A
;
792 return ~0; /* Unsupported. */
796 static uint32_t r300_translate_colormask_swizzle(enum pipe_format format
)
798 format
= r300_unbyteswap_array_format(format
);
801 case PIPE_FORMAT_A8_UNORM
:
802 case PIPE_FORMAT_A8_SNORM
:
803 case PIPE_FORMAT_A16_UNORM
:
804 case PIPE_FORMAT_A16_SNORM
:
805 case PIPE_FORMAT_A16_FLOAT
:
806 case PIPE_FORMAT_A32_FLOAT
:
807 return COLORMASK_AAAA
;
809 case PIPE_FORMAT_I8_UNORM
:
810 case PIPE_FORMAT_I8_SNORM
:
811 case PIPE_FORMAT_L8_UNORM
:
812 case PIPE_FORMAT_L8_SNORM
:
813 case PIPE_FORMAT_R8_UNORM
:
814 case PIPE_FORMAT_R8_SNORM
:
815 case PIPE_FORMAT_R32_FLOAT
:
816 case PIPE_FORMAT_L32_FLOAT
:
817 case PIPE_FORMAT_I32_FLOAT
:
818 return COLORMASK_RRRR
;
820 case PIPE_FORMAT_L8A8_SNORM
:
821 case PIPE_FORMAT_L8A8_UNORM
:
822 case PIPE_FORMAT_R8A8_UNORM
:
823 case PIPE_FORMAT_R8A8_SNORM
:
824 case PIPE_FORMAT_L16A16_UNORM
:
825 case PIPE_FORMAT_L16A16_SNORM
:
826 case PIPE_FORMAT_L16A16_FLOAT
:
827 case PIPE_FORMAT_R16A16_UNORM
:
828 case PIPE_FORMAT_R16A16_SNORM
:
829 case PIPE_FORMAT_R16A16_FLOAT
:
830 case PIPE_FORMAT_L32A32_FLOAT
:
831 case PIPE_FORMAT_R32A32_FLOAT
:
832 return COLORMASK_ARRA
;
834 case PIPE_FORMAT_R8G8_SNORM
:
835 case PIPE_FORMAT_R8G8_UNORM
:
836 case PIPE_FORMAT_R16G16_UNORM
:
837 case PIPE_FORMAT_R16G16_SNORM
:
838 case PIPE_FORMAT_R16G16_FLOAT
:
839 case PIPE_FORMAT_R32G32_FLOAT
:
840 return COLORMASK_GRRG
;
842 case PIPE_FORMAT_B5G5R5X1_UNORM
:
843 case PIPE_FORMAT_B4G4R4X4_UNORM
:
844 case PIPE_FORMAT_B8G8R8X8_UNORM
:
845 /*case PIPE_FORMAT_B8G8R8X8_SNORM:*/
846 case PIPE_FORMAT_B10G10R10X2_UNORM
:
847 return COLORMASK_BGRX
;
849 case PIPE_FORMAT_B5G6R5_UNORM
:
850 case PIPE_FORMAT_B5G5R5A1_UNORM
:
851 case PIPE_FORMAT_B4G4R4A4_UNORM
:
852 case PIPE_FORMAT_B8G8R8A8_UNORM
:
853 /*case PIPE_FORMAT_B8G8R8A8_SNORM:*/
854 case PIPE_FORMAT_B10G10R10A2_UNORM
:
855 return COLORMASK_BGRA
;
857 case PIPE_FORMAT_R8G8B8X8_UNORM
:
858 /* RGBX_SNORM formats are broken for an unknown reason */
859 /*case PIPE_FORMAT_R8G8B8X8_SNORM:*/
860 /*case PIPE_FORMAT_R10G10B10X2_SNORM:*/
861 case PIPE_FORMAT_R16G16B16X16_UNORM
:
862 /*case PIPE_FORMAT_R16G16B16X16_SNORM:*/
863 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
864 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
865 return COLORMASK_RGBX
;
867 case PIPE_FORMAT_R8G8B8A8_UNORM
:
868 case PIPE_FORMAT_R8G8B8A8_SNORM
:
869 case PIPE_FORMAT_R10G10B10A2_UNORM
:
870 case PIPE_FORMAT_R16_UNORM
:
871 case PIPE_FORMAT_R16G16B16A16_UNORM
:
872 case PIPE_FORMAT_R16_SNORM
:
873 case PIPE_FORMAT_R16G16B16A16_SNORM
:
874 case PIPE_FORMAT_R16_FLOAT
:
875 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
876 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
877 case PIPE_FORMAT_L16_UNORM
:
878 case PIPE_FORMAT_L16_SNORM
:
879 case PIPE_FORMAT_L16_FLOAT
:
880 case PIPE_FORMAT_I16_UNORM
:
881 case PIPE_FORMAT_I16_SNORM
:
882 case PIPE_FORMAT_I16_FLOAT
:
883 return COLORMASK_RGBA
;
886 return ~0; /* Unsupported. */
890 boolean
r300_is_colorbuffer_format_supported(enum pipe_format format
)
892 return r300_translate_colorformat(format
) != ~0 &&
893 r300_translate_out_fmt(format
) != ~0 &&
894 r300_translate_colormask_swizzle(format
) != ~0;
897 boolean
r300_is_zs_format_supported(enum pipe_format format
)
899 return r300_translate_zsformat(format
) != ~0;
902 boolean
r300_is_sampler_format_supported(enum pipe_format format
)
904 return r300_translate_texformat(format
, 0, TRUE
, FALSE
) != ~0;
907 void r300_texture_setup_format_state(struct r300_screen
*screen
,
908 struct r300_resource
*tex
,
909 enum pipe_format format
,
911 unsigned width0_override
,
912 unsigned height0_override
,
913 struct r300_texture_format_state
*out
)
915 struct pipe_resource
*pt
= &tex
->b
.b
;
916 struct r300_texture_desc
*desc
= &tex
->tex
;
917 boolean is_r500
= screen
->caps
.is_r500
;
918 unsigned width
, height
, depth
;
919 unsigned txwidth
, txheight
, txdepth
;
921 width
= u_minify(width0_override
, level
);
922 height
= u_minify(height0_override
, level
);
923 depth
= u_minify(desc
->depth0
, level
);
925 txwidth
= (width
- 1) & 0x7ff;
926 txheight
= (height
- 1) & 0x7ff;
927 txdepth
= util_logbase2(depth
) & 0xf;
929 /* Mask out all the fields we change. */
931 out
->format1
&= ~R300_TX_FORMAT_TEX_COORD_TYPE_MASK
;
932 out
->format2
&= R500_TXFORMAT_MSB
;
933 out
->tile_config
= 0;
935 /* Set sampler state. */
937 R300_TX_WIDTH(txwidth
) |
938 R300_TX_HEIGHT(txheight
) |
939 R300_TX_DEPTH(txdepth
);
941 if (desc
->uses_stride_addressing
) {
943 r300_stride_to_width(format
, desc
->stride_in_bytes
[level
]);
944 /* rectangles love this */
945 out
->format0
|= R300_TX_PITCH_EN
;
946 out
->format2
= (stride
- 1) & 0x1fff;
949 if (pt
->target
== PIPE_TEXTURE_CUBE
) {
950 out
->format1
|= R300_TX_FORMAT_CUBIC_MAP
;
952 if (pt
->target
== PIPE_TEXTURE_3D
) {
953 out
->format1
|= R300_TX_FORMAT_3D
;
956 /* large textures on r500 */
959 unsigned us_width
= txwidth
;
960 unsigned us_height
= txheight
;
961 unsigned us_depth
= txdepth
;
964 out
->format2
|= R500_TXWIDTH_BIT11
;
967 out
->format2
|= R500_TXHEIGHT_BIT11
;
970 /* The US_FORMAT register fixes an R500 TX addressing bug.
971 * Don't ask why it must be set like this. I don't know it either. */
973 us_width
= (0x000007FF + us_width
) >> 1;
974 us_depth
|= 0x0000000D;
977 us_height
= (0x000007FF + us_height
) >> 1;
978 us_depth
|= 0x0000000E;
982 R300_TX_WIDTH(us_width
) |
983 R300_TX_HEIGHT(us_height
) |
984 R300_TX_DEPTH(us_depth
);
987 out
->tile_config
= R300_TXO_MACRO_TILE(desc
->macrotile
[level
]) |
988 R300_TXO_MICRO_TILE(desc
->microtile
) |
989 R300_TXO_ENDIAN(r300_get_endian_swap(format
));
992 static void r300_texture_setup_fb_state(struct r300_surface
*surf
)
994 struct r300_resource
*tex
= r300_resource(surf
->base
.texture
);
995 unsigned level
= surf
->base
.u
.tex
.level
;
997 r300_stride_to_width(surf
->base
.format
, tex
->tex
.stride_in_bytes
[level
]);
999 /* Set framebuffer state. */
1000 if (util_format_is_depth_or_stencil(surf
->base
.format
)) {
1003 R300_DEPTHMACROTILE(tex
->tex
.macrotile
[level
]) |
1004 R300_DEPTHMICROTILE(tex
->tex
.microtile
) |
1005 R300_DEPTHENDIAN(r300_get_endian_swap(surf
->base
.format
));
1006 surf
->format
= r300_translate_zsformat(surf
->base
.format
);
1007 surf
->pitch_zmask
= tex
->tex
.zmask_stride_in_pixels
[level
];
1008 surf
->pitch_hiz
= tex
->tex
.hiz_stride_in_pixels
[level
];
1010 enum pipe_format format
= util_format_linear(surf
->base
.format
);
1014 r300_translate_colorformat(format
) |
1015 R300_COLOR_TILE(tex
->tex
.macrotile
[level
]) |
1016 R300_COLOR_MICROTILE(tex
->tex
.microtile
) |
1017 R300_COLOR_ENDIAN(r300_get_endian_swap(format
));
1018 surf
->format
= r300_translate_out_fmt(format
);
1019 surf
->colormask_swizzle
=
1020 r300_translate_colormask_swizzle(format
);
1021 surf
->pitch_cmask
= tex
->tex
.cmask_stride_in_pixels
;
1025 static void r300_texture_destroy(struct pipe_screen
*screen
,
1026 struct pipe_resource
* texture
)
1028 struct r300_screen
*rscreen
= r300_screen(screen
);
1029 struct r300_resource
* tex
= (struct r300_resource
*)texture
;
1031 if (tex
->tex
.cmask_dwords
) {
1032 mtx_lock(&rscreen
->cmask_mutex
);
1033 if (texture
== rscreen
->cmask_resource
) {
1034 rscreen
->cmask_resource
= NULL
;
1036 mtx_unlock(&rscreen
->cmask_mutex
);
1038 pb_reference(&tex
->buf
, NULL
);
1042 boolean
r300_resource_get_handle(struct pipe_screen
* screen
,
1043 struct pipe_context
*ctx
,
1044 struct pipe_resource
*texture
,
1045 struct winsys_handle
*whandle
,
1048 struct radeon_winsys
*rws
= r300_screen(screen
)->rws
;
1049 struct r300_resource
* tex
= (struct r300_resource
*)texture
;
1055 return rws
->buffer_get_handle(tex
->buf
, tex
->tex
.stride_in_bytes
[0],
1059 static const struct u_resource_vtbl r300_texture_vtbl
=
1061 NULL
, /* get_handle */
1062 r300_texture_destroy
, /* resource_destroy */
1063 r300_texture_transfer_map
, /* transfer_map */
1064 NULL
, /* transfer_flush_region */
1065 r300_texture_transfer_unmap
, /* transfer_unmap */
1068 /* The common texture constructor. */
1069 static struct r300_resource
*
1070 r300_texture_create_object(struct r300_screen
*rscreen
,
1071 const struct pipe_resource
*base
,
1072 enum radeon_bo_layout microtile
,
1073 enum radeon_bo_layout macrotile
,
1074 unsigned stride_in_bytes_override
,
1075 struct pb_buffer
*buffer
)
1077 struct radeon_winsys
*rws
= rscreen
->rws
;
1078 struct r300_resource
*tex
= NULL
;
1079 struct radeon_bo_metadata tiling
= {};
1081 tex
= CALLOC_STRUCT(r300_resource
);
1086 pipe_reference_init(&tex
->b
.b
.reference
, 1);
1087 tex
->b
.b
.screen
= &rscreen
->screen
;
1088 tex
->b
.b
.usage
= base
->usage
;
1089 tex
->b
.b
.bind
= base
->bind
;
1090 tex
->b
.b
.flags
= base
->flags
;
1091 tex
->b
.vtbl
= &r300_texture_vtbl
;
1092 tex
->tex
.microtile
= microtile
;
1093 tex
->tex
.macrotile
[0] = macrotile
;
1094 tex
->tex
.stride_in_bytes_override
= stride_in_bytes_override
;
1095 tex
->domain
= (base
->flags
& R300_RESOURCE_FLAG_TRANSFER
||
1096 base
->usage
== PIPE_USAGE_STAGING
) ? RADEON_DOMAIN_GTT
:
1097 base
->nr_samples
> 1 ? RADEON_DOMAIN_VRAM
:
1098 RADEON_DOMAIN_VRAM
| RADEON_DOMAIN_GTT
;
1101 r300_texture_desc_init(rscreen
, tex
, base
);
1103 /* Figure out the ideal placement for the texture.. */
1104 if (tex
->domain
& RADEON_DOMAIN_VRAM
&&
1105 tex
->tex
.size_in_bytes
>= rscreen
->info
.vram_size
) {
1106 tex
->domain
&= ~RADEON_DOMAIN_VRAM
;
1107 tex
->domain
|= RADEON_DOMAIN_GTT
;
1109 if (tex
->domain
& RADEON_DOMAIN_GTT
&&
1110 tex
->tex
.size_in_bytes
>= rscreen
->info
.gart_size
) {
1111 tex
->domain
&= ~RADEON_DOMAIN_GTT
;
1113 /* Just fail if the texture is too large. */
1118 /* Create the backing buffer if needed. */
1120 tex
->buf
= rws
->buffer_create(rws
, tex
->tex
.size_in_bytes
, 2048,
1121 tex
->domain
, RADEON_FLAG_NO_SUBALLOC
);
1128 if (SCREEN_DBG_ON(rscreen
, DBG_MSAA
) && base
->nr_samples
> 1) {
1129 fprintf(stderr
, "r300: %ix MSAA %s buffer created\n",
1131 util_format_is_depth_or_stencil(base
->format
) ? "depth" : "color");
1134 tiling
.u
.legacy
.microtile
= tex
->tex
.microtile
;
1135 tiling
.u
.legacy
.macrotile
= tex
->tex
.macrotile
[0];
1136 tiling
.u
.legacy
.stride
= tex
->tex
.stride_in_bytes
[0];
1137 rws
->buffer_set_metadata(tex
->buf
, &tiling
);
1144 pb_reference(&buffer
, NULL
);
1148 /* Create a new texture. */
1149 struct pipe_resource
*r300_texture_create(struct pipe_screen
*screen
,
1150 const struct pipe_resource
*base
)
1152 struct r300_screen
*rscreen
= r300_screen(screen
);
1153 enum radeon_bo_layout microtile
, macrotile
;
1155 if ((base
->flags
& R300_RESOURCE_FLAG_TRANSFER
) ||
1156 (base
->bind
& (PIPE_BIND_SCANOUT
| PIPE_BIND_LINEAR
))) {
1157 microtile
= RADEON_LAYOUT_LINEAR
;
1158 macrotile
= RADEON_LAYOUT_LINEAR
;
1160 /* This will make the texture_create_function select the layout. */
1161 microtile
= RADEON_LAYOUT_UNKNOWN
;
1162 macrotile
= RADEON_LAYOUT_UNKNOWN
;
1165 return (struct pipe_resource
*)
1166 r300_texture_create_object(rscreen
, base
, microtile
, macrotile
,
1170 struct pipe_resource
*r300_texture_from_handle(struct pipe_screen
*screen
,
1171 const struct pipe_resource
*base
,
1172 struct winsys_handle
*whandle
,
1175 struct r300_screen
*rscreen
= r300_screen(screen
);
1176 struct radeon_winsys
*rws
= rscreen
->rws
;
1177 struct pb_buffer
*buffer
;
1179 struct radeon_bo_metadata tiling
= {};
1181 /* Support only 2D textures without mipmaps */
1182 if ((base
->target
!= PIPE_TEXTURE_2D
&&
1183 base
->target
!= PIPE_TEXTURE_RECT
) ||
1184 base
->depth0
!= 1 ||
1185 base
->last_level
!= 0) {
1189 buffer
= rws
->buffer_from_handle(rws
, whandle
, &stride
, NULL
);
1193 rws
->buffer_get_metadata(buffer
, &tiling
);
1195 /* Enforce a microtiled zbuffer. */
1196 if (util_format_is_depth_or_stencil(base
->format
) &&
1197 tiling
.u
.legacy
.microtile
== RADEON_LAYOUT_LINEAR
) {
1198 switch (util_format_get_blocksize(base
->format
)) {
1200 tiling
.u
.legacy
.microtile
= RADEON_LAYOUT_TILED
;
1204 tiling
.u
.legacy
.microtile
= RADEON_LAYOUT_SQUARETILED
;
1209 return (struct pipe_resource
*)
1210 r300_texture_create_object(rscreen
, base
, tiling
.u
.legacy
.microtile
, tiling
.u
.legacy
.macrotile
,
1214 /* Not required to implement u_resource_vtbl, consider moving to another file:
1216 struct pipe_surface
* r300_create_surface_custom(struct pipe_context
* ctx
,
1217 struct pipe_resource
* texture
,
1218 const struct pipe_surface
*surf_tmpl
,
1219 unsigned width0_override
,
1220 unsigned height0_override
)
1222 struct r300_resource
* tex
= r300_resource(texture
);
1223 struct r300_surface
* surface
= CALLOC_STRUCT(r300_surface
);
1224 unsigned level
= surf_tmpl
->u
.tex
.level
;
1226 assert(surf_tmpl
->u
.tex
.first_layer
== surf_tmpl
->u
.tex
.last_layer
);
1229 uint32_t offset
, tile_height
;
1231 pipe_reference_init(&surface
->base
.reference
, 1);
1232 pipe_resource_reference(&surface
->base
.texture
, texture
);
1233 surface
->base
.context
= ctx
;
1234 surface
->base
.format
= surf_tmpl
->format
;
1235 surface
->base
.width
= u_minify(width0_override
, level
);
1236 surface
->base
.height
= u_minify(height0_override
, level
);
1237 surface
->base
.u
.tex
.level
= level
;
1238 surface
->base
.u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
1239 surface
->base
.u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
1241 surface
->buf
= tex
->buf
;
1242 surface
->buf
= tex
->buf
;
1244 /* Prefer VRAM if there are multiple domains to choose from. */
1245 surface
->domain
= tex
->domain
;
1246 if (surface
->domain
& RADEON_DOMAIN_VRAM
)
1247 surface
->domain
&= ~RADEON_DOMAIN_GTT
;
1249 surface
->offset
= r300_texture_get_offset(tex
, level
,
1250 surf_tmpl
->u
.tex
.first_layer
);
1251 r300_texture_setup_fb_state(surface
);
1253 /* Parameters for the CBZB clear. */
1254 surface
->cbzb_allowed
= tex
->tex
.cbzb_allowed
[level
];
1255 surface
->cbzb_width
= align(surface
->base
.width
, 64);
1257 /* Height must be aligned to the size of a tile. */
1258 tile_height
= r300_get_pixel_alignment(surface
->base
.format
,
1259 tex
->b
.b
.nr_samples
,
1261 tex
->tex
.macrotile
[level
],
1264 surface
->cbzb_height
= align((surface
->base
.height
+ 1) / 2,
1267 /* Offset must be aligned to 2K and must point at the beginning
1269 offset
= surface
->offset
+
1270 tex
->tex
.stride_in_bytes
[level
] * surface
->cbzb_height
;
1271 surface
->cbzb_midpoint_offset
= offset
& ~2047;
1273 surface
->cbzb_pitch
= surface
->pitch
& 0x1ffffc;
1275 if (util_format_get_blocksizebits(surface
->base
.format
) == 32)
1276 surface
->cbzb_format
= R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL
;
1278 surface
->cbzb_format
= R300_DEPTHFORMAT_16BIT_INT_Z
;
1280 DBG(r300_context(ctx
), DBG_CBZB
,
1281 "CBZB Allowed: %s, Dim: %ix%i, Misalignment: %i, Micro: %s, Macro: %s\n",
1282 surface
->cbzb_allowed
? "YES" : " NO",
1283 surface
->cbzb_width
, surface
->cbzb_height
,
1285 tex
->tex
.microtile
? "YES" : " NO",
1286 tex
->tex
.macrotile
[level
] ? "YES" : " NO");
1289 return &surface
->base
;
1292 struct pipe_surface
* r300_create_surface(struct pipe_context
* ctx
,
1293 struct pipe_resource
* texture
,
1294 const struct pipe_surface
*surf_tmpl
)
1296 return r300_create_surface_custom(ctx
, texture
, surf_tmpl
,
1301 /* Not required to implement u_resource_vtbl, consider moving to another file:
1303 void r300_surface_destroy(struct pipe_context
*ctx
, struct pipe_surface
* s
)
1305 pipe_resource_reference(&s
->texture
, NULL
);