[Mesa-dev] [PATCH v3 07/13] gallium/tgsi: Add support for raw resources.

Francisco Jerez currojerez at riseup.net
Tue May 1 08:27:45 PDT 2012


Normal resource access (e.g. the LOAD TGSI opcode) is supposed to
perform a series of conversions to turn the texture data as it's found
in memory into the target data type.

In compute programs it's often the case that we only want to access
the raw bits as they're stored in some buffer object, and any kind of
channel conversion and scaling is harmful or inefficient, especially
in implementations that lack proper hardware support to take care of
it -- in those cases the conversion has to be implemented in software
and it's likely to result in a performance hit even if the pipe_buffer
and declaration data types are set up in a way that would just pass
the data through.

Add a declaration flag that marks a resource as typeless.  No channel
conversion will be performed in that case, and the X coordinate of the
address vector will be interpreted in byte units instead of elements
for obvious reasons.

This is similar to D3D11's ByteAddressBuffer, and will be used to
implement OpenCL's constant arguments.  The remaining four compute
memory spaces can also be understood as raw resources.
---
v3: Split sampler views from shader resources.

 src/gallium/auxiliary/tgsi/tgsi_build.c    |    4 ++++
 src/gallium/auxiliary/tgsi/tgsi_dump.c     |    2 ++
 src/gallium/auxiliary/tgsi/tgsi_text.c     |   20 ++++++++++++++++++--
 src/gallium/docs/source/tgsi.rst           |   15 ++++++++++++++-
 src/gallium/include/pipe/p_shader_tokens.h |    3 ++-
 5 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c
index 1bcdef2..2945a0d 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_build.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_build.c
@@ -257,12 +257,14 @@ tgsi_default_declaration_resource(void)
    struct tgsi_declaration_resource dr;
 
    dr.Resource = TGSI_BUFFER;
+   dr.Raw = 0;
 
    return dr;
 }
 
 static struct tgsi_declaration_resource
 tgsi_build_declaration_resource(unsigned texture,
+                                unsigned raw,
                                 struct tgsi_declaration *declaration,
                                 struct tgsi_header *header)
 {
@@ -270,6 +272,7 @@ tgsi_build_declaration_resource(unsigned texture,
 
    dr = tgsi_default_declaration_resource();
    dr.Resource = texture;
+   dr.Raw = raw;
 
    declaration_grow(declaration, header);
 
@@ -439,6 +442,7 @@ tgsi_build_full_declaration(
       size++;
 
       *dr = tgsi_build_declaration_resource(full_decl->Resource.Resource,
+                                            full_decl->Resource.Raw,
                                             declaration,
                                             header);
    }
diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
index 328dfb1..f48e390 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
@@ -285,6 +285,8 @@ iter_declaration(
    if (decl->Declaration.File == TGSI_FILE_RESOURCE) {
       TXT(", ");
       ENM(decl->Resource.Resource, tgsi_texture_names);
+      if (decl->Resource.Raw)
+         TXT(", RAW");
    }
 
    if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index 0486275..ad9b304 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -1015,7 +1015,7 @@ static boolean parse_declaration( struct translate_ctx *ctx )
    struct parsed_dcl_bracket brackets[2];
    int num_brackets;
    uint writemask;
-   const char *cur;
+   const char *cur, *cur2;
    uint advance;
    boolean is_vs_input;
    boolean is_imm_array;
@@ -1069,6 +1069,22 @@ static boolean parse_declaration( struct translate_ctx *ctx )
             return FALSE;
          }
 
+         cur2 = cur;
+         eat_opt_white(&cur2);
+         while (*cur2 == ',') {
+            cur2++;
+            eat_opt_white(&cur2);
+            if (str_match_no_case(&cur2, "RAW") &&
+                !is_digit_alpha_underscore(cur2)) {
+               decl.Resource.Raw = 1;
+
+            } else {
+               break;
+            }
+            cur = cur2;
+            eat_opt_white(&cur2);
+         }
+
          ctx->cur = cur;
 
       } else if (file == TGSI_FILE_SAMPLER_VIEW) {
@@ -1122,7 +1138,7 @@ static boolean parse_declaration( struct translate_ctx *ctx )
                }
                break;
             } else {
-               const char *cur2 = cur;
+               cur2 = cur;
                eat_opt_white( &cur2 );
                if (*cur2 == ',') {
                   cur2++;
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index 6a1cb7e..eb8be46 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1745,7 +1745,7 @@ Declaration Resource
 
    Follows Declaration token if file is TGSI_FILE_RESOURCE.
 
-   DCL RES[#], resource
+   DCL RES[#], resource [, RAW]
 
    Declares a shader input resource and assigns it to a RES[#]
    register.
@@ -1753,6 +1753,19 @@ Declaration Resource
    resource can be one of BUFFER, 1D, 2D, 3D, CUBE, 1DArray and
    2DArray.
 
+   If the RAW keyword is not specified, the texture data will be
+   subject to conversion, swizzling and scaling as required to yield
+   the specified data type from the physical data format of the bound
+   resource.
+
+   If the RAW keyword is specified, no channel conversion will be
+   performed: the values read for each of the channels (X,Y,Z,W) will
+   correspond to consecutive words in the same order and format
+   they're found in memory.  No element-to-address conversion will be
+   performed either: the value of the provided X coordinate will be
+   interpreted in byte units instead of texel units.  The result of
+   accessing a misaligned address is undefined.
+
 
 Properties
 ^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
index a62d7a2..3fc7a47 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -169,7 +169,8 @@ struct tgsi_declaration_semantic
 
 struct tgsi_declaration_resource {
    unsigned Resource    : 8; /**< one of TGSI_TEXTURE_ */
-   unsigned Padding     : 24;
+   unsigned Raw         : 1;
+   unsigned Padding     : 23;
 };
 
 struct tgsi_declaration_sampler_view {
-- 
1.7.10



More information about the mesa-dev mailing list