gallium/tgsi: add support for stencil writes.
authorDave Airlie <airlied@redhat.com>
Tue, 5 Oct 2010 23:28:46 +0000 (09:28 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 12 Oct 2010 23:30:02 +0000 (09:30 +1000)
this adds the capability + a stencil semantic id, + tgsi scan support.

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/auxiliary/tgsi/tgsi_dump.c
src/gallium/auxiliary/tgsi/tgsi_scan.c
src/gallium/auxiliary/tgsi/tgsi_scan.h
src/gallium/docs/source/tgsi.rst
src/gallium/drivers/softpipe/sp_fs_exec.c
src/gallium/include/pipe/p_defines.h
src/gallium/include/pipe/p_shader_tokens.h

index 9b61797ace9c8435d46b0fa87f0e04e7163895d4..77bde86684efc68f7608cf2bc83896fdb3d86177 100644 (file)
@@ -126,7 +126,8 @@ static const char *semantic_names[] =
    "FACE",
    "EDGEFLAG",
    "PRIM_ID",
-   "INSTANCEID"
+   "INSTANCEID",
+   "STENCIL"
 };
 
 static const char *immediate_type_names[] =
index 90198a4f6049a6f265da80648b84c9865f086087..538274887b9829c2b6f0808c40b3fefd06ebf538 100644 (file)
@@ -157,9 +157,11 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
 
                   /* extra info for special outputs */
                   if (procType == TGSI_PROCESSOR_FRAGMENT &&
-                      fulldecl->Semantic.Name == TGSI_SEMANTIC_POSITION) {
-                     info->writes_z = TRUE;
-                  }
+                      fulldecl->Semantic.Name == TGSI_SEMANTIC_POSITION)
+                        info->writes_z = TRUE;
+                  if (procType == TGSI_PROCESSOR_FRAGMENT &&
+                      fulldecl->Semantic.Name == TGSI_SEMANTIC_STENCIL)
+                        info->writes_stencil = TRUE;
                   if (procType == TGSI_PROCESSOR_VERTEX &&
                       fulldecl->Semantic.Name == TGSI_SEMANTIC_EDGEFLAG) {
                      info->writes_edgeflag = TRUE;
index f8aa90cf065095cbbde51601fc30cab11870793b..374c7ed551db2dcc4836e40ae4ab0cec1338b8df 100644 (file)
@@ -60,6 +60,7 @@ struct tgsi_shader_info
    uint opcode_count[TGSI_OPCODE_LAST];  /**< opcode histogram */
 
    boolean writes_z;  /**< does fragment shader write Z value? */
+   boolean writes_stencil; /**< does fragment shader write stencil value? */
    boolean writes_edgeflag; /**< vertex shader outputs edgeflag */
    boolean uses_kill;  /**< KIL or KILP instruction used? */
 
index 9e02d43ab74ba5ab89ca58e0ebbaedbd4e962d0a..c767680c62a6a925e84f2ef44f177d4f52a030c5 100644 (file)
@@ -1415,6 +1415,12 @@ Edge flags are used to control which lines or points are actually
 drawn when the polygon mode converts triangles/quads/polygons into
 points or lines.
 
+TGSI_SEMANTIC_STENCIL
+""""""""""""""""""""""
+
+For fragment shaders, this semantic label indicates than an output
+is a writable stencil reference value. Only the Y component is writable.
+This allows the fragment shader to change the fragments stencilref value.
 
 
 Properties
index 67e2c8f8bc4223737fe3b24d0e6a4a7900b810f3..346e1b402baba023916102fdc59789429216e3ab 100644 (file)
@@ -158,9 +158,17 @@ exec_run( const struct sp_fragment_shader *base,
          case TGSI_SEMANTIC_POSITION:
             {
                uint j;
-               for (j = 0; j < 4; j++) {
+
+               for (j = 0; j < 4; j++)
                   quad->output.depth[j] = machine->Outputs[i].xyzw[2].f[j];
-               }
+            }
+            break;
+         case TGSI_SEMANTIC_STENCIL:
+            {
+               uint j;
+
+               for (j = 0; j < 4; j++)
+                  quad->output.stencil[j] = (unsigned)machine->Outputs[i].xyzw[1].f[j];
             }
             break;
          }
index 8b4663742fa5bd4fcfee53b4143c197095dd6907..b6894c09e827cf81de18feb2409043398dd31dba 100644 (file)
@@ -464,7 +464,8 @@ enum pipe_cap {
    PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT,
    PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER,
    PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER,
-   PIPE_CAP_DEPTH_CLAMP
+   PIPE_CAP_DEPTH_CLAMP,
+   PIPE_CAP_SHADER_STENCIL_EXPORT,
 };
 
 /* Shader caps not specific to any single stage */
index 74488de17ebda12e19ccefff9634cc8dd5263f62..ba433b2bd2aa7928a8565e618f0398aa43e897bb 100644 (file)
@@ -143,7 +143,8 @@ struct tgsi_declaration_dimension
 #define TGSI_SEMANTIC_EDGEFLAG   8
 #define TGSI_SEMANTIC_PRIMID     9
 #define TGSI_SEMANTIC_INSTANCEID 10
-#define TGSI_SEMANTIC_COUNT      11 /**< number of semantic values */
+#define TGSI_SEMANTIC_STENCIL    11
+#define TGSI_SEMANTIC_COUNT      12 /**< number of semantic values */
 
 struct tgsi_declaration_semantic
 {