nir/spirv: Add explicit handling for all decorations
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 24 May 2016 20:59:10 +0000 (13:59 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 25 May 2016 04:12:56 +0000 (21:12 -0700)
From time to time we have had cases where glslang has added a decoration we
don't handle and it has caused problems.  This audit ensures that, for
every decoration, we either handle it or hit an unreachable() with an
accurate description of why we don't have to.

src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_variables.c

index 359fa5c583a68b8cf2058b78ba372a46ffb9d407..4061b8a20141fdc326171a5ecb63d46b0e557214 100644 (file)
@@ -457,6 +457,9 @@ struct_member_decoration_cb(struct vtn_builder *b,
    case SpvDecorationNonWritable:
    case SpvDecorationNonReadable:
    case SpvDecorationRelaxedPrecision:
+   case SpvDecorationVolatile:
+   case SpvDecorationCoherent:
+   case SpvDecorationUniform:
       break; /* FIXME: Do nothing with this for now. */
    case SpvDecorationNoPerspective:
       ctx->fields[member].interpolation = INTERP_QUALIFIER_NOPERSPECTIVE;
@@ -470,9 +473,15 @@ struct_member_decoration_cb(struct vtn_builder *b,
    case SpvDecorationSample:
       ctx->fields[member].sample = true;
       break;
+   case SpvDecorationStream:
+      /* Vulkan only allows one GS stream */
+      assert(dec->literals[0] == 0);
+      break;
    case SpvDecorationLocation:
       ctx->fields[member].location = dec->literals[0];
       break;
+   case SpvDecorationComponent:
+      break; /* FIXME: What should we do with these? */
    case SpvDecorationBuiltIn:
       ctx->type->members[member] = vtn_type_copy(b, ctx->type->members[member]);
       ctx->type->members[member]->is_builtin = true;
@@ -490,6 +499,39 @@ struct_member_decoration_cb(struct vtn_builder *b,
    case SpvDecorationRowMajor:
       mutable_matrix_member(b, ctx->type, member)->row_major = true;
       break;
+
+   case SpvDecorationPatch:
+      unreachable("Tessellation not yet supported");
+
+   case SpvDecorationSpecId:
+   case SpvDecorationBlock:
+   case SpvDecorationBufferBlock:
+   case SpvDecorationArrayStride:
+   case SpvDecorationGLSLShared:
+   case SpvDecorationGLSLPacked:
+   case SpvDecorationInvariant:
+   case SpvDecorationRestrict:
+   case SpvDecorationAliased:
+   case SpvDecorationConstant:
+   case SpvDecorationIndex:
+   case SpvDecorationBinding:
+   case SpvDecorationDescriptorSet:
+   case SpvDecorationNoContraction:
+   case SpvDecorationInputAttachmentIndex:
+      unreachable("Decoration not allowed on struct members");
+
+   case SpvDecorationXfbBuffer:
+   case SpvDecorationXfbStride:
+      unreachable("Vulkan does not have transform feedback");
+
+   case SpvDecorationCPacked:
+   case SpvDecorationSaturatedConversion:
+   case SpvDecorationFuncParamAttr:
+   case SpvDecorationFPRoundingMode:
+   case SpvDecorationFPFastMathMode:
+   case SpvDecorationAlignment:
+      unreachable("Decoraiton only allowed for CL-style kernels");
+
    default:
       unreachable("Unhandled member decoration");
    }
@@ -520,12 +562,49 @@ type_decoration_cb(struct vtn_builder *b,
       /* Ignore these, since we get explicit offsets anyways */
       break;
 
+   case SpvDecorationRowMajor:
+   case SpvDecorationColMajor:
+   case SpvDecorationMatrixStride:
+   case SpvDecorationBuiltIn:
+   case SpvDecorationNoPerspective:
+   case SpvDecorationFlat:
+   case SpvDecorationPatch:
+   case SpvDecorationCentroid:
+   case SpvDecorationSample:
+   case SpvDecorationVolatile:
+   case SpvDecorationCoherent:
+   case SpvDecorationNonWritable:
+   case SpvDecorationNonReadable:
+   case SpvDecorationUniform:
    case SpvDecorationStream:
-      assert(dec->literals[0] == 0);
-      break;
+   case SpvDecorationLocation:
+   case SpvDecorationComponent:
+   case SpvDecorationOffset:
+   case SpvDecorationXfbBuffer:
+   case SpvDecorationXfbStride:
+      unreachable("Decoraiton only allowed for struct members");
 
-   default:
-      unreachable("Unhandled type decoration");
+   case SpvDecorationRelaxedPrecision:
+   case SpvDecorationSpecId:
+   case SpvDecorationInvariant:
+   case SpvDecorationRestrict:
+   case SpvDecorationAliased:
+   case SpvDecorationConstant:
+   case SpvDecorationIndex:
+   case SpvDecorationBinding:
+   case SpvDecorationDescriptorSet:
+   case SpvDecorationLinkageAttributes:
+   case SpvDecorationNoContraction:
+   case SpvDecorationInputAttachmentIndex:
+      unreachable("Decoraiton not allowed on types");
+
+   case SpvDecorationCPacked:
+   case SpvDecorationSaturatedConversion:
+   case SpvDecorationFuncParamAttr:
+   case SpvDecorationFPRoundingMode:
+   case SpvDecorationFPFastMathMode:
+   case SpvDecorationAlignment:
+      unreachable("Decoraiton only allowed for CL-style kernels");
    }
 }
 
index 0c7f0f76718188edf1c4b72047a87d197e5b5145..d156fb468c82bf4e94dfc2313b93fa59dbf74a3d 100644 (file)
@@ -895,9 +895,6 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
 
    /* Handle decorations that apply to a vtn_variable as a whole */
    switch (dec->decoration) {
-   case SpvDecorationNonWritable:
-      /* Do nothing with this for now */
-      return;
    case SpvDecorationBinding:
       vtn_var->binding = dec->literals[0];
       return;
@@ -1021,30 +1018,47 @@ var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
          nir_var->data.pixel_center_integer = b->pixel_center_integer;
       break;
    }
+
+   case SpvDecorationSpecId:
    case SpvDecorationRowMajor:
    case SpvDecorationColMajor:
-   case SpvDecorationGLSLShared:
-   case SpvDecorationPatch:
+   case SpvDecorationMatrixStride:
    case SpvDecorationRestrict:
    case SpvDecorationAliased:
    case SpvDecorationVolatile:
    case SpvDecorationCoherent:
    case SpvDecorationNonReadable:
    case SpvDecorationUniform:
-      /* This is really nice but we have no use for it right now. */
-   case SpvDecorationCPacked:
-   case SpvDecorationSaturatedConversion:
    case SpvDecorationStream:
    case SpvDecorationOffset:
+   case SpvDecorationLinkageAttributes:
+      break; /* Do nothing with these here */
+
+   case SpvDecorationPatch:
+      unreachable("Tessellation not yet supported");
+
+   case SpvDecorationBlock:
+   case SpvDecorationBufferBlock:
+   case SpvDecorationArrayStride:
+   case SpvDecorationGLSLShared:
+   case SpvDecorationGLSLPacked:
+   case SpvDecorationBinding:
+   case SpvDecorationDescriptorSet:
+   case SpvDecorationNoContraction:
+   case SpvDecorationInputAttachmentIndex:
+      unreachable("Decoration not allowed for variable or structure member");
+
    case SpvDecorationXfbBuffer:
+   case SpvDecorationXfbStride:
+      unreachable("Vulkan does not have transform feedback");
+
+   case SpvDecorationCPacked:
+   case SpvDecorationSaturatedConversion:
    case SpvDecorationFuncParamAttr:
    case SpvDecorationFPRoundingMode:
    case SpvDecorationFPFastMathMode:
-   case SpvDecorationLinkageAttributes:
-   case SpvDecorationSpecId:
-      break;
-   default:
-      unreachable("Unhandled variable decoration");
+   case SpvDecorationAlignment:
+      unreachable("Decoraiton only allowed for CL-style kernels");
    }
 }