diff options
author | Marek Olšák <[email protected]> | 2011-04-05 06:21:26 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2011-04-05 06:36:56 +0200 |
commit | b3011ea60cc36a888da031ebac932d67473f4521 (patch) | |
tree | e858f95c29dfae18805140a6a731f0cf139c1788 /src/gallium | |
parent | 20141d9efdf674a3c7a13a75fabe533665d02cd0 (diff) |
r300g: fix RG/LATC1_SNORM by doing UNORM->SNORM conversion in the shader
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/drivers/r300/r300_fs.c | 37 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_state_derived.c | 7 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_texture.c | 45 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_texture.h | 4 |
4 files changed, 63 insertions, 30 deletions
diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c index 37fe6622cd7..e3a1bc4a0f4 100644 --- a/src/gallium/drivers/r300/r300_fs.c +++ b/src/gallium/drivers/r300/r300_fs.c @@ -22,6 +22,7 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" @@ -34,6 +35,7 @@ #include "r300_screen.h" #include "r300_fs.h" #include "r300_reg.h" +#include "r300_texture.h" #include "r300_tgsi_to_rc.h" #include "radeon_code.h" @@ -148,7 +150,6 @@ static void get_external_state( struct r300_textures_state *texstate = r300->textures_state.state; struct r300_rs_state *rs = r300->rs_state.state; unsigned i; - unsigned char *swizzle; state->frag_clamp = rs ? rs->rs.clamp_fragment_color : 0; @@ -161,27 +162,37 @@ static void get_external_state( continue; } - t = r300_resource(texstate->sampler_views[i]->base.texture); + t = r300_resource(v->base.texture); if (s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { state->unit[i].compare_mode_enabled = 1; - /* Pass depth texture swizzling to the compiler. */ - if (texstate->sampler_views[i]) { - swizzle = texstate->sampler_views[i]->swizzle; - - state->unit[i].depth_texture_swizzle = - RC_MAKE_SWIZZLE(swizzle[0], swizzle[1], - swizzle[2], swizzle[3]); - } else { - state->unit[i].depth_texture_swizzle = RC_SWIZZLE_XYZW; - } - /* Fortunately, no need to translate this. */ state->unit[i].texture_compare_func = s->state.compare_func; } state->unit[i].non_normalized_coords = !s->state.normalized_coords; + state->unit[i].convert_unorm_to_snorm = + v->base.format == PIPE_FORMAT_RGTC1_SNORM || + v->base.format == PIPE_FORMAT_LATC1_SNORM; + + /* Pass texture swizzling to the compiler, some lowering passes need it. */ + if (v->base.format == PIPE_FORMAT_RGTC1_SNORM || + v->base.format == PIPE_FORMAT_LATC1_SNORM) { + unsigned char swizzle[4]; + + util_format_combine_swizzles(swizzle, + util_format_description(v->base.format)->swizzle, + v->swizzle); + + state->unit[i].texture_swizzle = + RC_MAKE_SWIZZLE(swizzle[0], swizzle[1], + swizzle[2], swizzle[3]); + } else if (state->unit[i].compare_mode_enabled) { + state->unit[i].texture_swizzle = + RC_MAKE_SWIZZLE(v->swizzle[0], v->swizzle[1], + v->swizzle[2], v->swizzle[3]); + } /* XXX this should probably take into account STR, not just S. */ if (t->tex.is_npot) { diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 50cde5528ef..02fc1219e95 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -650,8 +650,13 @@ static uint32_t r300_get_border_color(enum pipe_format format, if (util_format_is_compressed(format)) { switch (format) { case PIPE_FORMAT_RGTC1_SNORM: - case PIPE_FORMAT_RGTC1_UNORM: case PIPE_FORMAT_LATC1_SNORM: + border_swizzled[0] = border_swizzled[0] < 0 ? + border_swizzled[0]*0.5+1 : + border_swizzled[0]*0.5; + /* Pass through. */ + + case PIPE_FORMAT_RGTC1_UNORM: case PIPE_FORMAT_LATC1_UNORM: /* Add 1/32 to round the border color instead of truncating. */ /* The Y component is used for the border color. */ diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 62143808223..ea6d9824030 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -39,6 +39,18 @@ #include "pipe/p_screen.h" +void util_format_combine_swizzles(unsigned char *dst, + const unsigned char *swz1, + const unsigned char *swz2) +{ + unsigned i; + + for (i = 0; i < 4; i++) { + dst[i] = swz2[i] <= UTIL_FORMAT_SWIZZLE_W ? + swz1[swz2[i]] : swz2[i]; + } +} + unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, const unsigned char *swizzle_view, boolean dxtc_swizzle) @@ -61,10 +73,7 @@ unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, if (swizzle_view) { /* Combine two sets of swizzles. */ - for (i = 0; i < 4; i++) { - swizzle[i] = swizzle_view[i] <= UTIL_FORMAT_SWIZZLE_W ? - swizzle_format[swizzle_view[i]] : swizzle_view[i]; - } + util_format_combine_swizzles(swizzle, swizzle_format, swizzle_view); } else { memcpy(swizzle, swizzle_format, 4); } @@ -171,17 +180,22 @@ uint32_t r300_translate_texformat(enum pipe_format format, } } - if (util_format_is_compressed(format) && - dxtc_swizzle && - format != PIPE_FORMAT_RGTC2_UNORM && - format != PIPE_FORMAT_RGTC2_SNORM && - format != PIPE_FORMAT_LATC2_UNORM && - format != PIPE_FORMAT_LATC2_SNORM) { - result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, - TRUE); - } else { - result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, - FALSE); + /* Add swizzling. */ + /* The RGTC1_SNORM and LATC1_SNORM swizzle is done in the shader. */ + if (format != PIPE_FORMAT_RGTC1_SNORM && + format != PIPE_FORMAT_LATC1_SNORM) { + if (util_format_is_compressed(format) && + dxtc_swizzle && + format != PIPE_FORMAT_RGTC2_UNORM && + format != PIPE_FORMAT_RGTC2_SNORM && + format != PIPE_FORMAT_LATC2_UNORM && + format != PIPE_FORMAT_LATC2_SNORM) { + result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, + TRUE); + } else { + result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, + FALSE); + } } /* S3TC formats. */ @@ -212,7 +226,6 @@ uint32_t r300_translate_texformat(enum pipe_format format, switch (format) { case PIPE_FORMAT_RGTC1_SNORM: case PIPE_FORMAT_LATC1_SNORM: - result |= sign_bit[2]; case PIPE_FORMAT_LATC1_UNORM: case PIPE_FORMAT_RGTC1_UNORM: return R500_TX_FORMAT_ATI1N | result; diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h index 158a387478f..4586bb2e4dc 100644 --- a/src/gallium/drivers/r300/r300_texture.h +++ b/src/gallium/drivers/r300/r300_texture.h @@ -35,6 +35,10 @@ struct r300_texture_desc; struct r300_resource; struct r300_screen; +void util_format_combine_swizzles(unsigned char *dst, + const unsigned char *swz1, + const unsigned char *swz2); + unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, const unsigned char *swizzle_view, boolean dxtc_swizzle); |