tgsi/gs: bound max output vertices in shader
authorDave Airlie <airlied@redhat.com>
Wed, 11 Jun 2014 01:38:19 +0000 (11:38 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 11 Jun 2014 02:19:37 +0000 (12:19 +1000)
This limits the number of emitted vertices to the shaders max output
vertices, and avoids us writing things into memory that isn't big
enough for it.

Reviewed-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/auxiliary/tgsi/tgsi_exec.c
src/gallium/auxiliary/tgsi/tgsi_exec.h

index 9be1d138b8684cb4b94871e4ccf03c0f3ce6b0cf..19412af36bc143c5c1ed23ca230404fd2c2ecdf6 100644 (file)
@@ -789,6 +789,11 @@ tgsi_exec_machine_bind_shader(
          break;
 
       case TGSI_TOKEN_TYPE_PROPERTY:
+         if (mach->Processor == TGSI_PROCESSOR_GEOMETRY) {
+            if (parse.FullToken.FullProperty.Property.PropertyName == TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES) {
+               mach->MaxOutputVertices = parse.FullToken.FullProperty.u[0].Data;
+            }
+         }
          break;
 
       default:
@@ -1621,6 +1626,9 @@ emit_vertex(struct tgsi_exec_machine *mach)
          if ((mach->ExecMask & (1 << i)))
    */
    if (mach->ExecMask) {
+      if (mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]] >= mach->MaxOutputVertices)
+         return;
+
       mach->Temps[TEMP_OUTPUT_I].xyzw[TEMP_OUTPUT_C].u[0] += mach->NumOutputs;
       mach->Primitives[mach->Temps[TEMP_PRIMITIVE_I].xyzw[TEMP_PRIMITIVE_C].u[0]]++;
    }
index bb56934df6ce49f01eb513a441b2bd76a70a0e9f..a5369ae16a336fdb90fdc377c570a5b9b51347d4 100644 (file)
@@ -297,6 +297,7 @@ struct tgsi_exec_machine
    unsigned                      *Primitives;
    unsigned                       NumOutputs;
    unsigned                       MaxGeometryShaderOutputs;
+   unsigned                       MaxOutputVertices;
 
    /* FRAGMENT processor only. */
    const struct tgsi_interp_coef *InterpCoefs;