Mesa (main): pan/bi: Model Valhall source formats

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 30 22:27:58 UTC 2022


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

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Mon May 30 15:29:56 2022 -0400

pan/bi: Model Valhall source formats

LD_VAR_BUF instructions on Valhall take a source format, indicating the
in-memory format of the varying independent from the register format, which we
still model within the compiler for compatibility with Bifrost. (Prior to
Valhall, source format is specified in the attribute descriptor as a physical
pixel format.)

Model this information, allowing us to generate fp16 LD_VAR_BUF instructions
correctly on Valhall.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16752>

---

 src/panfrost/bifrost/ISA.xml                       | 24 ++++++++++++++++++++++
 src/panfrost/bifrost/bifrost_compile.c             | 14 ++++++++-----
 src/panfrost/bifrost/compiler.h                    |  3 ++-
 src/panfrost/bifrost/valhall/test/test-packing.cpp |  3 +++
 src/panfrost/bifrost/valhall/va_pack.c             | 14 ++++++-------
 5 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/src/panfrost/bifrost/ISA.xml b/src/panfrost/bifrost/ISA.xml
index 7abe88f58ba..8be9a1e88e0 100644
--- a/src/panfrost/bifrost/ISA.xml
+++ b/src/panfrost/bifrost/ISA.xml
@@ -8593,6 +8593,12 @@
       <opt>u32</opt>
       <opt>u16</opt>
     </mod>
+    <mod name="source_format" size="2">
+      <opt>flat32</opt>
+      <opt>flat16</opt>
+      <opt>f32</opt>
+      <opt>f16</opt>
+    </mod>
     <mod name="sample" size="3">
       <opt>center</opt>
       <opt>centroid</opt>
@@ -8623,6 +8629,12 @@
       <opt>u32</opt>
       <opt>u16</opt>
     </mod>
+    <mod name="source_format" size="2">
+      <opt>flat32</opt>
+      <opt>flat16</opt>
+      <opt>f32</opt>
+      <opt>f16</opt>
+    </mod>
     <mod name="sample" size="3">
       <opt>center</opt>
       <opt>centroid</opt>
@@ -8653,6 +8665,12 @@
       <opt>u32</opt>
       <opt>u16</opt>
     </mod>
+    <mod name="source_format" size="2">
+      <opt>flat32</opt>
+      <opt>flat16</opt>
+      <opt>f32</opt>
+      <opt>f16</opt>
+    </mod>
     <mod name="sample" size="3">
       <opt>center</opt>
       <opt>centroid</opt>
@@ -8683,6 +8701,12 @@
       <opt>u32</opt>
       <opt>u16</opt>
     </mod>
+    <mod name="source_format" size="2">
+      <opt>flat32</opt>
+      <opt>flat16</opt>
+      <opt>f32</opt>
+      <opt>f16</opt>
+    </mod>
     <mod name="sample" size="3">
       <opt>center</opt>
       <opt>centroid</opt>
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 4ea115a15d3..305d6e19db0 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -552,6 +552,9 @@ bi_emit_load_vary(bi_builder *b, nir_intrinsic_instr *instr)
                 b->shader->info.bifrost->uses_flat_shading = true;
         }
 
+        enum bi_source_format source_format =
+                smooth ? BI_SOURCE_FORMAT_F32 : BI_SOURCE_FORMAT_FLAT32;
+
         nir_src *offset = nir_get_io_offset_src(instr);
         unsigned imm_index = 0;
         bool immediate = bi_is_intr_immediate(instr, &imm_index, 20);
@@ -559,9 +562,9 @@ bi_emit_load_vary(bi_builder *b, nir_intrinsic_instr *instr)
 
         if (b->shader->malloc_idvs && immediate) {
                 /* Immediate index given in bytes. */
-                bi_ld_var_buf_imm_f32_to(b, dest, src0, regfmt, sample, update,
-                                         vecsize,
-                                         bi_varying_offset(b->shader, instr));
+                bi_ld_var_buf_imm_to(b, sz, dest, src0, regfmt,
+                                     sample, source_format, update, vecsize,
+                                     bi_varying_offset(b->shader, instr));
         } else if (immediate && smooth) {
                 I = bi_ld_var_imm_to(b, dest, src0, regfmt, sample, update,
                                      vecsize, imm_index);
@@ -582,8 +585,9 @@ bi_emit_load_vary(bi_builder *b, nir_intrinsic_instr *instr)
                         if (vbase != 0)
                                 idx_bytes = bi_iadd_u32(b, idx, bi_imm_u32(vbase), false);
 
-                        bi_ld_var_buf_f32_to(b, dest, src0, idx_bytes, regfmt,
-                                             sample, update, vecsize);
+                        bi_ld_var_buf_to(b, sz, dest, src0, idx_bytes, regfmt,
+                                         sample, source_format, update,
+                                         vecsize);
                 } else if (smooth) {
                         if (base != 0)
                                 idx = bi_iadd_u32(b, idx, bi_imm_u32(base), false);
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index bfdd27c4d81..a2eb6b1b092 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -487,6 +487,7 @@ typedef struct {
                         enum bi_varying_name varying_name; /* LD_VAR_SPECIAL */
                         bool skip; /* VAR_TEX, TEXS, TEXC */
                         bool lod_mode; /* VAR_TEX, TEXS, implicitly for TEXC */
+                        enum bi_source_format source_format; /* LD_VAR_BUF */
 
                         /* Used for valhall texturing */
                         bool shadow;
@@ -500,7 +501,7 @@ typedef struct {
                 };
 
                 /* Maximum size, for hashing */
-                unsigned flags[11];
+                unsigned flags[14];
 
                 struct {
                         enum bi_subgroup subgroup; /* WMASK, CLPER */
diff --git a/src/panfrost/bifrost/valhall/test/test-packing.cpp b/src/panfrost/bifrost/valhall/test/test-packing.cpp
index ce46da36422..7d44bac1320 100644
--- a/src/panfrost/bifrost/valhall/test/test-packing.cpp
+++ b/src/panfrost/bifrost/valhall/test/test-packing.cpp
@@ -258,16 +258,19 @@ TEST_F(ValhallPacking, LdAttrImm) {
 TEST_F(ValhallPacking, LdVarBufImmF16) {
    CASE(bi_ld_var_buf_imm_f16_to(b, bi_register(2), bi_register(61),
                                  BI_REGISTER_FORMAT_F16, BI_SAMPLE_CENTER,
+                                 BI_SOURCE_FORMAT_F16,
                                  BI_UPDATE_RETRIEVE, BI_VECSIZE_V4, 0),
         0x005d82143300003d);
 
    CASE(bi_ld_var_buf_imm_f16_to(b, bi_register(0), bi_register(61),
                                  BI_REGISTER_FORMAT_F16, BI_SAMPLE_SAMPLE,
+                                 BI_SOURCE_FORMAT_F16,
                                  BI_UPDATE_STORE, BI_VECSIZE_V4, 0),
          0x005d80843300003d);
 
    CASE(bi_ld_var_buf_imm_f16_to(b, bi_register(0), bi_register(61),
                                  BI_REGISTER_FORMAT_F16, BI_SAMPLE_CENTROID,
+                                 BI_SOURCE_FORMAT_F16,
                                  BI_UPDATE_STORE, BI_VECSIZE_V4, 8),
          0x005d80443308003d);
 }
diff --git a/src/panfrost/bifrost/valhall/va_pack.c b/src/panfrost/bifrost/valhall/va_pack.c
index 5f37934692d..b0df089f26f 100644
--- a/src/panfrost/bifrost/valhall/va_pack.c
+++ b/src/panfrost/bifrost/valhall/va_pack.c
@@ -266,14 +266,14 @@ va_pack_combine(enum bi_swizzle swz)
 static enum va_source_format
 va_pack_source_format(const bi_instr *I)
 {
-   switch (I->register_format) {
-   case BI_REGISTER_FORMAT_AUTO:
-   case BI_REGISTER_FORMAT_S32:
-   case BI_REGISTER_FORMAT_U32: return VA_SOURCE_FORMAT_SRC_FLAT32;
-   case BI_REGISTER_FORMAT_F32: return VA_SOURCE_FORMAT_SRC_F32;
-   case BI_REGISTER_FORMAT_F16: return VA_SOURCE_FORMAT_SRC_F16;
-   default: unreachable("unhandled register format");
+   switch (I->source_format) {
+   case BI_SOURCE_FORMAT_FLAT32: return VA_SOURCE_FORMAT_SRC_FLAT32;
+   case BI_SOURCE_FORMAT_FLAT16: return VA_SOURCE_FORMAT_SRC_FLAT16;
+   case BI_SOURCE_FORMAT_F32: return VA_SOURCE_FORMAT_SRC_F32;
+   case BI_SOURCE_FORMAT_F16: return VA_SOURCE_FORMAT_SRC_F16;
    }
+
+   unreachable("unhandled source format");
 }
 
 static uint64_t



More information about the mesa-commit mailing list