Mesa (master): r300/compiler: add emulation of all mirrored-clamp wrap modes for NPOT textures

Marek Olšák mareko at kemper.freedesktop.org
Sat Apr 17 00:48:14 UTC 2010


Module: Mesa
Branch: master
Commit: 411d5063323ccdb85ec090f1c852fcc8e9cd0e64
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=411d5063323ccdb85ec090f1c852fcc8e9cd0e64

Author: Marek Olšák <maraeo at gmail.com>
Date:   Sat Apr 17 02:43:47 2010 +0200

r300/compiler: add emulation of all mirrored-clamp wrap modes for NPOT textures

---

 src/gallium/drivers/r300/r300_fs.c                 |    6 +++++-
 src/mesa/drivers/dri/r300/compiler/radeon_code.h   |    3 ++-
 .../drivers/dri/r300/compiler/radeon_program_tex.c |   18 +++++++++++++++++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c
index a37f23a..4d61f63 100644
--- a/src/gallium/drivers/r300/r300_fs.c
+++ b/src/gallium/drivers/r300/r300_fs.c
@@ -169,10 +169,14 @@ static void get_external_state(
                         break;
 
                     case PIPE_TEX_WRAP_MIRROR_REPEAT:
+                        state->unit[i].wrap_mode = RC_WRAP_MIRRORED_REPEAT;
+                        state->unit[i].fake_npot = TRUE;
+                        break;
+
                     case PIPE_TEX_WRAP_MIRROR_CLAMP:
                     case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
                     case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
-                        state->unit[i].wrap_mode = RC_WRAP_MIRROR;
+                        state->unit[i].wrap_mode = RC_WRAP_MIRRORED_CLAMP;
                         state->unit[i].fake_npot = TRUE;
                         break;
 
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_code.h b/src/mesa/drivers/dri/r300/compiler/radeon_code.h
index 28bcd10..27274f0 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_code.h
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_code.h
@@ -115,7 +115,8 @@ typedef enum {
 typedef enum {
 	RC_WRAP_NONE = 0,
 	RC_WRAP_REPEAT,
-	RC_WRAP_MIRROR
+	RC_WRAP_MIRRORED_REPEAT,
+	RC_WRAP_MIRRORED_CLAMP
 } rc_wrap_mode;
 
 /**
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_program_tex.c b/src/mesa/drivers/dri/r300/compiler/radeon_program_tex.c
index a8927ac..0ca95d4 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_program_tex.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_program_tex.c
@@ -233,7 +233,7 @@ int radeonTransformTEX(
 				inst_frc->U.I.DstReg.Index = temp;
 				inst_frc->U.I.DstReg.WriteMask = RC_MASK_XYZ;
 				inst_frc->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
-			} else if (wrapmode == RC_WRAP_MIRROR) {
+			} else if (wrapmode == RC_WRAP_MIRRORED_REPEAT) {
 				/*
 				 * Function:
 				 *   f(v) = 1 - abs(frac(v * 0.5) * 2 - 1)
@@ -295,6 +295,22 @@ int radeonTransformTEX(
 				inst_add->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_XYZ0;
 				inst_add->U.I.SrcReg[1].Abs = 1;
 				inst_add->U.I.SrcReg[1].Negate = RC_MASK_XYZ;
+			} else if (wrapmode == RC_WRAP_MIRRORED_CLAMP) {
+				/*
+				 * Mirrored clamp modes are bloody simple, we just use abs
+				 * to mirror [0, 1] into [-1, 0]. This works for
+				 * all modes i.e. CLAMP, CLAMP_TO_EDGE, and CLAMP_TO_BORDER.
+				 */
+				struct rc_instruction *inst_mov;
+
+				inst_mov = rc_insert_new_instruction(c, inst->Prev);
+
+				inst_mov->U.I.Opcode = RC_OPCODE_MOV;
+				inst_mov->U.I.DstReg.File = RC_FILE_TEMPORARY;
+				inst_mov->U.I.DstReg.Index = temp;
+				inst_mov->U.I.DstReg.WriteMask = RC_MASK_XYZ;
+				inst_mov->U.I.SrcReg[0] = inst->U.I.SrcReg[0];
+				inst_mov->U.I.SrcReg[0].Abs = 1;
 			}
 
 			/* Preserve W for TXP/TXB. */




More information about the mesa-commit mailing list