Module: Mesa
Branch: main
Commit: 9eb8a0b16ac829397bba49818f41c454deb7394b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9eb8a0b16ac829397bba49818f41c454deb7394b

Author: Yonggang Luo <[email protected]>
Date:   Wed Aug  2 19:36:27 2023 +0800

intel/brw: Define and use BRW_SWIZZLE_* instead of SWIZZLE_*

This is for avoid #include "program/prog_instrunction.h" in intel/brw code

Signed-off-by: Yonggang Luo <[email protected]>
Reviewed-by: Faith Ekstrand <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24438>

---

 src/intel/compiler/brw_reg.h                      |  9 +++++
 src/intel/compiler/brw_vec4_nir.cpp               |  8 ++--
 src/intel/compiler/brw_vec4_visitor.cpp           |  2 +-
 src/intel/compiler/test_vec4_copy_propagation.cpp | 48 +++++++++++------------
 4 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/src/intel/compiler/brw_reg.h b/src/intel/compiler/brw_reg.h
index 47ea456b265..49f2a97392d 100644
--- a/src/intel/compiler/brw_reg.h
+++ b/src/intel/compiler/brw_reg.h
@@ -69,6 +69,15 @@ struct intel_device_info;
  */
 #define GFX7_MRF_HACK_START 112
 
+/**
+ * BRW hardware swizzles.
+ * Only defines XYZW to ensure it can be contained in 2 bits
+ */
+#define BRW_SWIZZLE_X 0
+#define BRW_SWIZZLE_Y 1
+#define BRW_SWIZZLE_Z 2
+#define BRW_SWIZZLE_W 3
+
 /** Number of message register file registers */
 #define BRW_MAX_MRF(gen) (gen == 6 ? 24 : 16)
 
diff --git a/src/intel/compiler/brw_vec4_nir.cpp 
b/src/intel/compiler/brw_vec4_nir.cpp
index b1f6aa59f5f..5bc0440dedc 100644
--- a/src/intel/compiler/brw_vec4_nir.cpp
+++ b/src/intel/compiler/brw_vec4_nir.cpp
@@ -2146,8 +2146,8 @@ vec4_visitor::nir_emit_texture(nir_tex_instr *instr)
          const brw_reg_type type = lod.type;
 
         if (devinfo->ver >= 5) {
-           lod.swizzle = BRW_SWIZZLE4(SWIZZLE_X,SWIZZLE_X,SWIZZLE_Y,SWIZZLE_Y);
-           lod2.swizzle = 
BRW_SWIZZLE4(SWIZZLE_X,SWIZZLE_X,SWIZZLE_Y,SWIZZLE_Y);
+           lod.swizzle = 
BRW_SWIZZLE4(BRW_SWIZZLE_X,BRW_SWIZZLE_X,BRW_SWIZZLE_Y,BRW_SWIZZLE_Y);
+           lod2.swizzle = 
BRW_SWIZZLE4(BRW_SWIZZLE_X,BRW_SWIZZLE_X,BRW_SWIZZLE_Y,BRW_SWIZZLE_Y);
            emit(MOV(dst_reg(MRF, param_base + 1, type, WRITEMASK_XZ), lod));
            emit(MOV(dst_reg(MRF, param_base + 1, type, WRITEMASK_YW), lod2));
            inst->mlen++;
@@ -2204,8 +2204,8 @@ vec4_visitor::nir_emit_texture(nir_tex_instr *instr)
    if (instr->op == nir_texop_query_levels) {
       /* # levels is in .w */
       src_reg swizzled(dest);
-      swizzled.swizzle = BRW_SWIZZLE4(SWIZZLE_W, SWIZZLE_W,
-                                      SWIZZLE_W, SWIZZLE_W);
+      swizzled.swizzle = BRW_SWIZZLE4(BRW_SWIZZLE_W, BRW_SWIZZLE_W,
+                                      BRW_SWIZZLE_W, BRW_SWIZZLE_W);
       emit(MOV(dest, swizzled));
    }
 }
diff --git a/src/intel/compiler/brw_vec4_visitor.cpp 
b/src/intel/compiler/brw_vec4_visitor.cpp
index 971b5f655bc..9f31c5fe654 100644
--- a/src/intel/compiler/brw_vec4_visitor.cpp
+++ b/src/intel/compiler/brw_vec4_visitor.cpp
@@ -819,7 +819,7 @@ vec4_visitor::emit_ndc_computation()
    dst_reg ndc_w = ndc;
    ndc_w.writemask = WRITEMASK_W;
    src_reg pos_w = pos;
-   pos_w.swizzle = BRW_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W);
+   pos_w.swizzle = BRW_SWIZZLE4(BRW_SWIZZLE_W, BRW_SWIZZLE_W, BRW_SWIZZLE_W, 
BRW_SWIZZLE_W);
    emit_math(SHADER_OPCODE_RCP, ndc_w, pos_w);
 
    dst_reg ndc_xyz = ndc;
diff --git a/src/intel/compiler/test_vec4_copy_propagation.cpp 
b/src/intel/compiler/test_vec4_copy_propagation.cpp
index 7ed6880a4e4..3c8f66e292e 100644
--- a/src/intel/compiler/test_vec4_copy_propagation.cpp
+++ b/src/intel/compiler/test_vec4_copy_propagation.cpp
@@ -144,25 +144,25 @@ TEST_F(copy_propagation_vec4_test, test_swizzle_swizzle)
 
    v->emit(v->ADD(a, src_reg(a), src_reg(a)));
 
-   v->emit(v->MOV(b, swizzle(src_reg(a), BRW_SWIZZLE4(SWIZZLE_Y,
-                                                      SWIZZLE_Z,
-                                                      SWIZZLE_W,
-                                                      SWIZZLE_X))));
+   v->emit(v->MOV(b, swizzle(src_reg(a), BRW_SWIZZLE4(BRW_SWIZZLE_Y,
+                                                      BRW_SWIZZLE_Z,
+                                                      BRW_SWIZZLE_W,
+                                                      BRW_SWIZZLE_X))));
 
    vec4_instruction *test_mov =
-      v->MOV(c, swizzle(src_reg(b), BRW_SWIZZLE4(SWIZZLE_Y,
-                                                 SWIZZLE_Z,
-                                                 SWIZZLE_W,
-                                                 SWIZZLE_X)));
+      v->MOV(c, swizzle(src_reg(b), BRW_SWIZZLE4(BRW_SWIZZLE_Y,
+                                                 BRW_SWIZZLE_Z,
+                                                 BRW_SWIZZLE_W,
+                                                 BRW_SWIZZLE_X)));
    v->emit(test_mov);
 
    copy_propagation(v);
 
    EXPECT_EQ(test_mov->src[0].nr, a.nr);
-   EXPECT_EQ(test_mov->src[0].swizzle, BRW_SWIZZLE4(SWIZZLE_Z,
-                                                    SWIZZLE_W,
-                                                    SWIZZLE_X,
-                                                    SWIZZLE_Y));
+   EXPECT_EQ(test_mov->src[0].swizzle, BRW_SWIZZLE4(BRW_SWIZZLE_Z,
+                                                    BRW_SWIZZLE_W,
+                                                    BRW_SWIZZLE_X,
+                                                    BRW_SWIZZLE_Y));
 }
 
 TEST_F(copy_propagation_vec4_test, test_swizzle_writemask)
@@ -171,26 +171,26 @@ TEST_F(copy_propagation_vec4_test, test_swizzle_writemask)
    dst_reg b = dst_reg(v, glsl_type::vec4_type);
    dst_reg c = dst_reg(v, glsl_type::vec4_type);
 
-   v->emit(v->MOV(b, swizzle(src_reg(a), BRW_SWIZZLE4(SWIZZLE_X,
-                                                      SWIZZLE_Y,
-                                                      SWIZZLE_X,
-                                                      SWIZZLE_Z))));
+   v->emit(v->MOV(b, swizzle(src_reg(a), BRW_SWIZZLE4(BRW_SWIZZLE_X,
+                                                      BRW_SWIZZLE_Y,
+                                                      BRW_SWIZZLE_X,
+                                                      BRW_SWIZZLE_Z))));
 
    v->emit(v->MOV(writemask(a, WRITEMASK_XYZ), brw_imm_f(1.0f)));
 
    vec4_instruction *test_mov =
-      v->MOV(c, swizzle(src_reg(b), BRW_SWIZZLE4(SWIZZLE_W,
-                                                 SWIZZLE_W,
-                                                 SWIZZLE_W,
-                                                 SWIZZLE_W)));
+      v->MOV(c, swizzle(src_reg(b), BRW_SWIZZLE4(BRW_SWIZZLE_W,
+                                                 BRW_SWIZZLE_W,
+                                                 BRW_SWIZZLE_W,
+                                                 BRW_SWIZZLE_W)));
    v->emit(test_mov);
 
    copy_propagation(v);
 
    /* should not copy propagate */
    EXPECT_EQ(test_mov->src[0].nr, b.nr);
-   EXPECT_EQ(test_mov->src[0].swizzle, BRW_SWIZZLE4(SWIZZLE_W,
-                                                    SWIZZLE_W,
-                                                    SWIZZLE_W,
-                                                    SWIZZLE_W));
+   EXPECT_EQ(test_mov->src[0].swizzle, BRW_SWIZZLE4(BRW_SWIZZLE_W,
+                                                    BRW_SWIZZLE_W,
+                                                    BRW_SWIZZLE_W,
+                                                    BRW_SWIZZLE_W));
 }

Reply via email to