[Mesa-dev] [PATCH v3 08/13] gallium/tgsi: Add resource write-back support.

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


Define a new STORE opcode with a role dual to the LOAD opcode, and add
flags to specify that a shader resource is intended for writing.
---
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_info.c     |    1 +
 src/gallium/auxiliary/tgsi/tgsi_text.c     |    4 ++++
 src/gallium/docs/source/context.rst        |    3 ++-
 src/gallium/docs/source/tgsi.rst           |   28 +++++++++++++++++++++++++++-
 src/gallium/include/pipe/p_shader_tokens.h |    6 ++++--
 src/gallium/include/pipe/p_state.h         |    1 +
 8 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c
index 2945a0d..8378075 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_build.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_build.c
@@ -258,6 +258,7 @@ tgsi_default_declaration_resource(void)
 
    dr.Resource = TGSI_BUFFER;
    dr.Raw = 0;
+   dr.Writable = 0;
 
    return dr;
 }
@@ -265,6 +266,7 @@ tgsi_default_declaration_resource(void)
 static struct tgsi_declaration_resource
 tgsi_build_declaration_resource(unsigned texture,
                                 unsigned raw,
+                                unsigned writable,
                                 struct tgsi_declaration *declaration,
                                 struct tgsi_header *header)
 {
@@ -273,6 +275,7 @@ tgsi_build_declaration_resource(unsigned texture,
    dr = tgsi_default_declaration_resource();
    dr.Resource = texture;
    dr.Raw = raw;
+   dr.Writable = writable;
 
    declaration_grow(declaration, header);
 
@@ -443,6 +446,7 @@ tgsi_build_full_declaration(
 
       *dr = tgsi_build_declaration_resource(full_decl->Resource.Resource,
                                             full_decl->Resource.Raw,
+                                            full_decl->Resource.Writable,
                                             declaration,
                                             header);
    }
diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
index f48e390..3685946 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.Writable)
+         TXT(", WR");
       if (decl->Resource.Raw)
          TXT(", RAW");
    }
diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c b/src/gallium/auxiliary/tgsi/tgsi_info.c
index c41288f..46a9df1 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_info.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_info.c
@@ -200,6 +200,7 @@ static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] =
    { 1, 1, 0, 0, 0, 0, COMP, "IABS", TGSI_OPCODE_IABS },
    { 1, 1, 0, 0, 0, 0, COMP, "ISSG", TGSI_OPCODE_ISSG },
    { 1, 2, 0, 0, 0, 0, OTHR, "LOAD", TGSI_OPCODE_LOAD },
+   { 1, 2, 0, 0, 0, 0, OTHR, "STORE", TGSI_OPCODE_STORE },
 };
 
 const struct tgsi_opcode_info *
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index ad9b304..52e30b4 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -1078,6 +1078,10 @@ static boolean parse_declaration( struct translate_ctx *ctx )
                 !is_digit_alpha_underscore(cur2)) {
                decl.Resource.Raw = 1;
 
+            } else if (str_match_no_case(&cur2, "WR") &&
+                !is_digit_alpha_underscore(cur2)) {
+               decl.Resource.Writable = 1;
+
             } else {
                break;
             }
diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst
index eae400d..d17ea42 100644
--- a/src/gallium/docs/source/context.rst
+++ b/src/gallium/docs/source/context.rst
@@ -134,7 +134,8 @@ the ``level``, ``first_layer`` and ``last_layer`` pipe_surface fields
 specify the mipmap level and the range of layers the texture will be
 constrained to.  In the case of buffers, ``first_element`` and
 ``last_element`` specify the range within the buffer that will be used
-by the shader resource.
+by the shader resource.  Writes to a shader resource are only allowed
+when the ``writable`` flag is set.
 
 Surfaces
 ^^^^^^^^
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index eb8be46..f32aff1 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1490,6 +1490,29 @@ Resource Access Opcodes
                texture arrays and 2D textures.  address.w is always
                ignored.
 
+.. opcode:: STORE - Write data to a shader resource
+
+               Syntax: ``STORE resource, address, src``
+
+               Example: ``STORE RES[0], TEMP[0], TEMP[1]``
+
+               Using the provided integer address, STORE writes data
+               to the specified buffer or texture.
+
+               The 'address' is specified as a vector of unsigned
+               integers.  If the 'address' is out of range the result
+               is unspecified.
+
+               Only the first mipmap level of a resource can be
+               written to using this instruction.
+
+               For 1D or 2D texture arrays, the array index is
+               provided as an unsigned integer in address.y or
+               address.z, respectively.  address.yz are ignored for
+               buffers and 1D textures.  address.z is ignored for 1D
+               texture arrays and 2D textures.  address.w is always
+               ignored.
+
 
 Explanation of symbols used
 ------------------------------
@@ -1745,7 +1768,7 @@ Declaration Resource
 
    Follows Declaration token if file is TGSI_FILE_RESOURCE.
 
-   DCL RES[#], resource [, RAW]
+   DCL RES[#], resource [, WR] [, RAW]
 
    Declares a shader input resource and assigns it to a RES[#]
    register.
@@ -1766,6 +1789,9 @@ Declaration Resource
    interpreted in byte units instead of texel units.  The result of
    accessing a misaligned address is undefined.
 
+   Usage of the STORE opcode is only allowed if the WR (writable) flag
+   is set.
+
 
 Properties
 ^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
index 3fc7a47..d45a914 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -170,7 +170,8 @@ struct tgsi_declaration_semantic
 struct tgsi_declaration_resource {
    unsigned Resource    : 8; /**< one of TGSI_TEXTURE_ */
    unsigned Raw         : 1;
-   unsigned Padding     : 23;
+   unsigned Writable    : 1;
+   unsigned Padding     : 22;
 };
 
 struct tgsi_declaration_sampler_view {
@@ -406,8 +407,9 @@ struct tgsi_property_data {
 #define TGSI_OPCODE_ISSG                160
 
 #define TGSI_OPCODE_LOAD                161
+#define TGSI_OPCODE_STORE               162
 
-#define TGSI_OPCODE_LAST                162
+#define TGSI_OPCODE_LAST                163
 
 #define TGSI_SAT_NONE            0  /* do not saturate */
 #define TGSI_SAT_ZERO_ONE        1  /* clamp to [0,1] */
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index 788ded5..7e741cf 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -338,6 +338,7 @@ struct pipe_surface
    unsigned height;              /**< logical height in pixels */
 
    unsigned usage;               /**< bitmask of PIPE_BIND_x */
+   unsigned writable:1;          /**< writable shader resource */
 
    union {
       struct {
-- 
1.7.10



More information about the mesa-dev mailing list