r300g: fix texture swizzling with compressed textures on r400-r500

This fixes all S3TC piglit/texwrap tests.

NOTE: This is a candidate for the 7.9 branch.
This commit is contained in:
Marek Olšák 2010-11-30 23:28:43 +01:00
parent c92550be64
commit 6478a4de14
7 changed files with 28 additions and 13 deletions

View file

@ -424,4 +424,5 @@ void r300_parse_chipset(struct r300_capabilities* caps)
}
caps->is_rv350 = caps->family >= CHIP_FAMILY_RV350;
caps->dxtc_swizzle = caps->is_r400 || caps->is_r500;
}

View file

@ -79,6 +79,8 @@ struct r300_capabilities {
boolean is_r500;
/* Whether or not the second pixel pipe is accessed with the high bit */
boolean high_second_pipe;
/* DXTC texture swizzling. */
boolean dxtc_swizzle;
};
/* Enumerations for legibility and telling which card we're running on. */

View file

@ -1520,11 +1520,11 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
# define R300_TX_TRI_PERF_3_8 (3<<15)
# define R300_ANISO_THRESHOLD_MASK (7<<17)
# define R400_DXTC_SWIZZLE_ENABLE (1<<21)
# define R500_MACRO_SWITCH (1<<22)
# define R500_TX_MAX_ANISO(x) ((x) << 23)
# define R500_TX_MAX_ANISO_MASK (63 << 23)
# define R500_TX_ANISO_HIGH_QUALITY (1 << 30)
# define R500_BORDER_FIX (1<<31)
#define R300_TX_FORMAT0_0 0x4480

View file

@ -1347,6 +1347,7 @@ r300_create_sampler_view(struct pipe_context *pipe,
struct r300_sampler_view *view = CALLOC_STRUCT(r300_sampler_view);
struct r300_texture *tex = r300_texture(texture);
boolean is_r500 = r300_screen(pipe->screen)->caps.is_r500;
boolean dxtc_swizzle = r300_screen(pipe->screen)->caps.dxtc_swizzle;
if (view) {
view->base = *templ;
@ -1363,7 +1364,8 @@ r300_create_sampler_view(struct pipe_context *pipe,
view->format = tex->tx_format;
view->format.format1 |= r300_translate_texformat(templ->format,
view->swizzle,
is_r500);
is_r500,
dxtc_swizzle);
if (is_r500) {
view->format.format2 |= r500_tx_format_msb_bit(templ->format);
}

View file

@ -764,13 +764,18 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
if (sampler->state.compare_mode == PIPE_TEX_COMPARE_NONE) {
texstate->format.format1 |=
r300_get_swizzle_combined(depth_swizzle,
view->swizzle);
view->swizzle, FALSE);
} else {
texstate->format.format1 |=
r300_get_swizzle_combined(depth_swizzle, 0);
r300_get_swizzle_combined(depth_swizzle, 0, FALSE);
}
}
if (r300->screen->caps.dxtc_swizzle &&
util_format_is_compressed(tex->desc.b.b.format)) {
texstate->filter1 |= R400_DXTC_SWIZZLE_ENABLE;
}
/* to emulate 1D textures through 2D ones correctly */
if (tex->desc.b.b.target == PIPE_TEXTURE_1D) {
texstate->filter0 &= ~R300_TX_WRAP_T_MASK;

View file

@ -40,7 +40,8 @@
#include "pipe/p_screen.h"
unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format,
const unsigned char *swizzle_view)
const unsigned char *swizzle_view,
boolean dxtc_swizzle)
{
unsigned i;
unsigned char swizzle[4];
@ -51,10 +52,10 @@ unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format,
R300_TX_FORMAT_B_SHIFT,
R300_TX_FORMAT_A_SHIFT
};
const uint32_t swizzle_bit[4] = {
R300_TX_FORMAT_X,
uint32_t swizzle_bit[4] = {
dxtc_swizzle ? R300_TX_FORMAT_Z : R300_TX_FORMAT_X,
R300_TX_FORMAT_Y,
R300_TX_FORMAT_Z,
dxtc_swizzle ? R300_TX_FORMAT_X : R300_TX_FORMAT_Z,
R300_TX_FORMAT_W
};
@ -107,7 +108,8 @@ unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format,
* makes available X, Y, Z, W, ZERO, and ONE for swizzling. */
uint32_t r300_translate_texformat(enum pipe_format format,
const unsigned char *swizzle_view,
boolean is_r500)
boolean is_r500,
boolean dxtc_swizzle)
{
uint32_t result = 0;
const struct util_format_description *desc;
@ -169,7 +171,8 @@ uint32_t r300_translate_texformat(enum pipe_format format,
}
}
result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view);
result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view,
util_format_is_compressed(format) && dxtc_swizzle);
/* S3TC formats. */
if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
@ -571,7 +574,7 @@ boolean r300_is_zs_format_supported(enum pipe_format format)
boolean r300_is_sampler_format_supported(enum pipe_format format)
{
return r300_translate_texformat(format, 0, TRUE) != ~0;
return r300_translate_texformat(format, 0, TRUE, FALSE) != ~0;
}
void r300_texture_setup_format_state(struct r300_screen *screen,

View file

@ -35,11 +35,13 @@ struct r300_texture;
struct r300_screen;
unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format,
const unsigned char *swizzle_view);
const unsigned char *swizzle_view,
boolean dxtc_swizzle);
uint32_t r300_translate_texformat(enum pipe_format format,
const unsigned char *swizzle_view,
boolean is_r500);
boolean is_r500,
boolean dxtc_swizzle);
uint32_t r500_tx_format_msb_bit(enum pipe_format format);