From fbf2402969ed9aec34a8f8b4f5afab342319f07b Mon Sep 17 00:00:00 2001 From: alan-baker Date: Wed, 5 Jun 2024 11:46:40 -0400 Subject: [PATCH] Enforce grammar naming conventions for aliases (#432) * Enforce grammar naming conventions for aliases Fixes #429 * Enforce Core -> KHR -> EXT -> Vendor conventions for aliased names * Update grammar to satisfy these conventions and regenerate headers * Prevent duplicate (token,name) pairs --- .../spirv/unified1/spirv.core.grammar.json | 124 +++++++++--------- include/spirv/unified1/spirv.h | 4 +- include/spirv/unified1/spirv.hpp | 4 +- include/spirv/unified1/spirv.hpp11 | 4 +- tools/buildHeaders/jsonToSpirv.cpp | 63 ++++++++- 5 files changed, 128 insertions(+), 71 deletions(-) diff --git a/include/spirv/unified1/spirv.core.grammar.json b/include/spirv/unified1/spirv.core.grammar.json index 5fc3c1a96..42eddc931 100644 --- a/include/spirv/unified1/spirv.core.grammar.json +++ b/include/spirv/unified1/spirv.core.grammar.json @@ -5938,7 +5938,7 @@ "version" : "None" }, { - "opname" : "OpReportIntersectionNV", + "opname" : "OpReportIntersectionKHR", "class" : "Reserved", "opcode" : 5334, "operands" : [ @@ -5952,7 +5952,7 @@ "version" : "None" }, { - "opname" : "OpReportIntersectionKHR", + "opname" : "OpReportIntersectionNV", "class" : "Reserved", "opcode" : 5334, "operands" : [ @@ -6069,7 +6069,7 @@ "version" : "None" }, { - "opname" : "OpTypeAccelerationStructureNV", + "opname" : "OpTypeAccelerationStructureKHR", "class" : "Type-Declaration", "opcode" : 5341, "operands" : [ @@ -6080,7 +6080,7 @@ "version" : "None" }, { - "opname" : "OpTypeAccelerationStructureKHR", + "opname" : "OpTypeAccelerationStructureNV", "class" : "Type-Declaration", "opcode" : 5341, "operands" : [ @@ -10887,73 +10887,73 @@ "version" : "None" }, { - "enumerant" : "RayGenerationNV", + "enumerant" : "RayGenerationKHR", "value" : 5313, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "RayGenerationKHR", + "enumerant" : "RayGenerationNV", "value" : 5313, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "IntersectionNV", + "enumerant" : "IntersectionKHR", "value" : 5314, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "IntersectionKHR", + "enumerant" : "IntersectionNV", "value" : 5314, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "AnyHitNV", + "enumerant" : "AnyHitKHR", "value" : 5315, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "AnyHitKHR", + "enumerant" : "AnyHitNV", "value" : 5315, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "ClosestHitNV", + "enumerant" : "ClosestHitKHR", "value" : 5316, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "ClosestHitKHR", + "enumerant" : "ClosestHitNV", "value" : 5316, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "MissNV", + "enumerant" : "MissKHR", "value" : 5317, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "MissKHR", + "enumerant" : "MissNV", "value" : 5317, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "CallableNV", + "enumerant" : "CallableKHR", "value" : 5318, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "CallableKHR", + "enumerant" : "CallableNV", "value" : 5318, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" @@ -11511,21 +11511,21 @@ "version" : "None" }, { - "enumerant" : "OutputLinesNV", + "enumerant" : "OutputLinesEXT", "value" : 5269, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "extensions" : [ "SPV_NV_mesh_shader", "SPV_EXT_mesh_shader" ], "version" : "None" }, { - "enumerant" : "OutputLinesEXT", + "enumerant" : "OutputLinesNV", "value" : 5269, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "extensions" : [ "SPV_NV_mesh_shader", "SPV_EXT_mesh_shader" ], "version" : "None" }, { - "enumerant" : "OutputPrimitivesNV", + "enumerant" : "OutputPrimitivesEXT", "value" : 5270, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "parameters" : [ @@ -11535,7 +11535,7 @@ "version" : "None" }, { - "enumerant" : "OutputPrimitivesEXT", + "enumerant" : "OutputPrimitivesNV", "value" : 5270, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "parameters" : [ @@ -11559,14 +11559,14 @@ "version" : "None" }, { - "enumerant" : "OutputTrianglesNV", + "enumerant" : "OutputTrianglesEXT", "value" : 5298, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "extensions" : [ "SPV_NV_mesh_shader", "SPV_EXT_mesh_shader" ], "version" : "None" }, { - "enumerant" : "OutputTrianglesEXT", + "enumerant" : "OutputTrianglesNV", "value" : 5298, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "extensions" : [ "SPV_NV_mesh_shader", "SPV_EXT_mesh_shader" ], @@ -11879,84 +11879,84 @@ "version" : "None" }, { - "enumerant" : "CallableDataNV", + "enumerant" : "CallableDataKHR", "value" : 5328, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "CallableDataKHR", + "enumerant" : "CallableDataNV", "value" : 5328, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "IncomingCallableDataNV", + "enumerant" : "IncomingCallableDataKHR", "value" : 5329, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "IncomingCallableDataKHR", + "enumerant" : "IncomingCallableDataNV", "value" : 5329, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "RayPayloadNV", + "enumerant" : "RayPayloadKHR", "value" : 5338, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "RayPayloadKHR", + "enumerant" : "RayPayloadNV", "value" : 5338, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "HitAttributeNV", + "enumerant" : "HitAttributeKHR", "value" : 5339, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "HitAttributeKHR", + "enumerant" : "HitAttributeNV", "value" : 5339, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "IncomingRayPayloadNV", + "enumerant" : "IncomingRayPayloadKHR", "value" : 5342, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "IncomingRayPayloadKHR", + "enumerant" : "IncomingRayPayloadNV", "value" : 5342, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "ShaderRecordBufferNV", + "enumerant" : "ShaderRecordBufferKHR", "value" : 5343, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "version" : "None" }, { - "enumerant" : "ShaderRecordBufferKHR", + "enumerant" : "ShaderRecordBufferNV", "value" : 5343, "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], @@ -13313,14 +13313,14 @@ ] }, { - "enumerant" : "PerPrimitiveNV", + "enumerant" : "PerPrimitiveEXT", "value" : 5271, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "extensions" : [ "SPV_NV_mesh_shader", "SPV_EXT_mesh_shader" ], "version" : "None" }, { - "enumerant" : "PerPrimitiveEXT", + "enumerant" : "PerPrimitiveNV", "value" : 5271, "capabilities" : [ "MeshShadingNV", "MeshShadingEXT" ], "extensions" : [ "SPV_NV_mesh_shader", "SPV_EXT_mesh_shader" ], @@ -14620,154 +14620,154 @@ "version" : "None" }, { - "enumerant" : "LaunchIdNV", + "enumerant" : "LaunchIdKHR", "value" : 5319, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "LaunchIdKHR", + "enumerant" : "LaunchIdNV", "value" : 5319, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "LaunchSizeNV", + "enumerant" : "LaunchSizeKHR", "value" : 5320, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "LaunchSizeKHR", + "enumerant" : "LaunchSizeNV", "value" : 5320, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "WorldRayOriginNV", + "enumerant" : "WorldRayOriginKHR", "value" : 5321, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "WorldRayOriginKHR", + "enumerant" : "WorldRayOriginNV", "value" : 5321, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "WorldRayDirectionNV", + "enumerant" : "WorldRayDirectionKHR", "value" : 5322, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "WorldRayDirectionKHR", + "enumerant" : "WorldRayDirectionNV", "value" : 5322, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "ObjectRayOriginNV", + "enumerant" : "ObjectRayOriginKHR", "value" : 5323, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "ObjectRayOriginKHR", + "enumerant" : "ObjectRayOriginNV", "value" : 5323, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "ObjectRayDirectionNV", + "enumerant" : "ObjectRayDirectionKHR", "value" : 5324, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "ObjectRayDirectionKHR", + "enumerant" : "ObjectRayDirectionNV", "value" : 5324, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "RayTminNV", + "enumerant" : "RayTminKHR", "value" : 5325, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "RayTminKHR", + "enumerant" : "RayTminNV", "value" : 5325, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "RayTmaxNV", + "enumerant" : "RayTmaxKHR", "value" : 5326, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "RayTmaxKHR", + "enumerant" : "RayTmaxNV", "value" : 5326, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "InstanceCustomIndexNV", + "enumerant" : "InstanceCustomIndexKHR", "value" : 5327, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "InstanceCustomIndexKHR", + "enumerant" : "InstanceCustomIndexNV", "value" : 5327, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "ObjectToWorldNV", + "enumerant" : "ObjectToWorldKHR", "value" : 5330, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "ObjectToWorldKHR", + "enumerant" : "ObjectToWorldNV", "value" : 5330, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "WorldToObjectNV", + "enumerant" : "WorldToObjectKHR", "value" : 5331, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "WorldToObjectKHR", + "enumerant" : "WorldToObjectNV", "value" : 5331, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], @@ -14781,14 +14781,14 @@ "version" : "None" }, { - "enumerant" : "HitKindNV", + "enumerant" : "HitKindKHR", "value" : 5333, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "HitKindKHR", + "enumerant" : "HitKindNV", "value" : 5333, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], @@ -14820,14 +14820,14 @@ "version" : "None" }, { - "enumerant" : "IncomingRayFlagsNV", + "enumerant" : "IncomingRayFlagsKHR", "value" : 5351, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], "version" : "None" }, { - "enumerant" : "IncomingRayFlagsKHR", + "enumerant" : "IncomingRayFlagsNV", "value" : 5351, "capabilities" : [ "RayTracingNV" , "RayTracingKHR" ], "extensions" : [ "SPV_NV_ray_tracing" , "SPV_KHR_ray_tracing" ], diff --git a/include/spirv/unified1/spirv.h b/include/spirv/unified1/spirv.h index 980373d10..d696ef724 100644 --- a/include/spirv/unified1/spirv.h +++ b/include/spirv/unified1/spirv.h @@ -2615,14 +2615,14 @@ inline void SpvHasResultAndType(SpvOp opcode, bool *hasResult, bool *hasResultTy case SpvOpWritePackedPrimitiveIndices4x8NV: *hasResult = false; *hasResultType = false; break; case SpvOpFetchMicroTriangleVertexPositionNV: *hasResult = true; *hasResultType = true; break; case SpvOpFetchMicroTriangleVertexBarycentricNV: *hasResult = true; *hasResultType = true; break; - case SpvOpReportIntersectionNV: *hasResult = true; *hasResultType = true; break; + case SpvOpReportIntersectionKHR: *hasResult = true; *hasResultType = true; break; case SpvOpIgnoreIntersectionNV: *hasResult = false; *hasResultType = false; break; case SpvOpTerminateRayNV: *hasResult = false; *hasResultType = false; break; case SpvOpTraceNV: *hasResult = false; *hasResultType = false; break; case SpvOpTraceMotionNV: *hasResult = false; *hasResultType = false; break; case SpvOpTraceRayMotionNV: *hasResult = false; *hasResultType = false; break; case SpvOpRayQueryGetIntersectionTriangleVertexPositionsKHR: *hasResult = true; *hasResultType = true; break; - case SpvOpTypeAccelerationStructureNV: *hasResult = true; *hasResultType = false; break; + case SpvOpTypeAccelerationStructureKHR: *hasResult = true; *hasResultType = false; break; case SpvOpExecuteCallableNV: *hasResult = false; *hasResultType = false; break; case SpvOpTypeCooperativeMatrixNV: *hasResult = true; *hasResultType = false; break; case SpvOpCooperativeMatrixLoadNV: *hasResult = true; *hasResultType = true; break; diff --git a/include/spirv/unified1/spirv.hpp b/include/spirv/unified1/spirv.hpp index fd3ded43f..9696e07c9 100644 --- a/include/spirv/unified1/spirv.hpp +++ b/include/spirv/unified1/spirv.hpp @@ -2611,14 +2611,14 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) { case OpWritePackedPrimitiveIndices4x8NV: *hasResult = false; *hasResultType = false; break; case OpFetchMicroTriangleVertexPositionNV: *hasResult = true; *hasResultType = true; break; case OpFetchMicroTriangleVertexBarycentricNV: *hasResult = true; *hasResultType = true; break; - case OpReportIntersectionNV: *hasResult = true; *hasResultType = true; break; + case OpReportIntersectionKHR: *hasResult = true; *hasResultType = true; break; case OpIgnoreIntersectionNV: *hasResult = false; *hasResultType = false; break; case OpTerminateRayNV: *hasResult = false; *hasResultType = false; break; case OpTraceNV: *hasResult = false; *hasResultType = false; break; case OpTraceMotionNV: *hasResult = false; *hasResultType = false; break; case OpTraceRayMotionNV: *hasResult = false; *hasResultType = false; break; case OpRayQueryGetIntersectionTriangleVertexPositionsKHR: *hasResult = true; *hasResultType = true; break; - case OpTypeAccelerationStructureNV: *hasResult = true; *hasResultType = false; break; + case OpTypeAccelerationStructureKHR: *hasResult = true; *hasResultType = false; break; case OpExecuteCallableNV: *hasResult = false; *hasResultType = false; break; case OpTypeCooperativeMatrixNV: *hasResult = true; *hasResultType = false; break; case OpCooperativeMatrixLoadNV: *hasResult = true; *hasResultType = true; break; diff --git a/include/spirv/unified1/spirv.hpp11 b/include/spirv/unified1/spirv.hpp11 index 4087933ec..7a5f8dc97 100644 --- a/include/spirv/unified1/spirv.hpp11 +++ b/include/spirv/unified1/spirv.hpp11 @@ -2611,14 +2611,14 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) { case Op::OpWritePackedPrimitiveIndices4x8NV: *hasResult = false; *hasResultType = false; break; case Op::OpFetchMicroTriangleVertexPositionNV: *hasResult = true; *hasResultType = true; break; case Op::OpFetchMicroTriangleVertexBarycentricNV: *hasResult = true; *hasResultType = true; break; - case Op::OpReportIntersectionNV: *hasResult = true; *hasResultType = true; break; + case Op::OpReportIntersectionKHR: *hasResult = true; *hasResultType = true; break; case Op::OpIgnoreIntersectionNV: *hasResult = false; *hasResultType = false; break; case Op::OpTerminateRayNV: *hasResult = false; *hasResultType = false; break; case Op::OpTraceNV: *hasResult = false; *hasResultType = false; break; case Op::OpTraceMotionNV: *hasResult = false; *hasResultType = false; break; case Op::OpTraceRayMotionNV: *hasResult = false; *hasResultType = false; break; case Op::OpRayQueryGetIntersectionTriangleVertexPositionsKHR: *hasResult = true; *hasResultType = true; break; - case Op::OpTypeAccelerationStructureNV: *hasResult = true; *hasResultType = false; break; + case Op::OpTypeAccelerationStructureKHR: *hasResult = true; *hasResultType = false; break; case Op::OpExecuteCallableNV: *hasResult = false; *hasResultType = false; break; case Op::OpTypeCooperativeMatrixNV: *hasResult = true; *hasResultType = false; break; case Op::OpCooperativeMatrixLoadNV: *hasResult = true; *hasResultType = true; break; diff --git a/tools/buildHeaders/jsonToSpirv.cpp b/tools/buildHeaders/jsonToSpirv.cpp index 34e097294..22beba79f 100644 --- a/tools/buildHeaders/jsonToSpirv.cpp +++ b/tools/buildHeaders/jsonToSpirv.cpp @@ -471,6 +471,37 @@ unsigned int NumberStringToBit(const std::string& str) return bit; } +// Given two pairs (name and in core) compares if the order is correct for naming +// conventions. The conventions are: +// * Core +// * KHR +// * EXT +// * Vendor (no preference between vendors) +// +// Returns true if the order is valid. +bool SuffixComparison(const std::string& prev, bool prevCore, + const std::string& cur, bool curCore) +{ + // Duplicate entry + if (prev == cur) return false; + + if (prevCore) return true; + if (curCore) return false; + + // Both are suffixed names. + const bool prevKHR = prev.substr(prev.size() - 3) == "KHR"; + const bool prevEXT = prev.substr(prev.size() - 3) == "EXT"; + const bool curKHR = cur.substr(cur.size() - 3) == "KHR"; + const bool curEXT = cur.substr(cur.size() - 3) == "EXT"; + + if (prevKHR) return true; + if (curKHR) return false; + if (prevEXT) return true; + if (curEXT) return false; + + return true; +} + void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders) { // only do this once. @@ -547,6 +578,8 @@ void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders) // process the instructions const Json::Value insts = root["instructions"]; unsigned maxOpcode = 0; + std::string maxName = ""; + bool maxCore = false; bool firstOpcode = true; for (const auto& inst : insts) { const auto printingClass = inst["class"].asString(); @@ -565,8 +598,11 @@ void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders) } const auto opcode = inst["opcode"].asUInt(); const std::string name = inst["opname"].asString(); + std::string version = inst["version"].asString(); if (firstOpcode) { maxOpcode = opcode; + maxName = name; + maxCore = version != "None"; firstOpcode = false; } else { if (maxOpcode > opcode) { @@ -574,12 +610,20 @@ void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders) << " is out of order. It follows the instruction with opcode " << maxOpcode << std::endl; std::exit(1); + } else if (maxOpcode == opcode && + !SuffixComparison(maxName, maxCore, name, + version != "None")) { + std::cerr << "Error: " << name + << " is out of order. It follows alias " << maxName + << std::endl; + std::exit(1); } else { maxOpcode = opcode; + maxName = name; + maxCore = version != "None"; } } EnumCaps caps = getCaps(inst); - std::string version = inst["version"].asString(); std::string lastVersion = inst["lastVersion"].asString(); Extensions exts = getExts(inst); OperandParameters operands; @@ -625,28 +669,41 @@ void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders) }; unsigned maxValue = 0; + std::string maxName = ""; + bool maxCore = false; bool firstValue = true; for (const auto& enumerant : source["enumerants"]) { unsigned value; bool skip_zero_in_bitfield; std::tie(value, skip_zero_in_bitfield) = getValue(enumerant); + std::string name = enumerant["enumerant"].asString(); + std::string version = enumerant["version"].asString(); if (skip_zero_in_bitfield) continue; if (firstValue) { maxValue = value; + maxName = name; + maxCore = version != "None"; firstValue = false; } else { if (maxValue > value) { - std::cerr << "Error: " << source["kind"] << " enumerant " << enumerant["enumerant"] + std::cerr << "Error: " << source["kind"] << " enumerant " << name << " is out of order. It has value " << value << " but follows the enumerant with value " << maxValue << std::endl; std::exit(1); + } else if (maxValue == value && + !SuffixComparison(maxName, maxCore, name, + version != "None")) { + std::cerr << "Error: " << source["kind"] << " enumerant " << name + << " is out of order. It follows alias " << maxName << std::endl; + std::exit(1); } else { maxValue = value; + maxName = name; + maxCore = version != "None"; } } EnumCaps caps(getCaps(enumerant)); - std::string version = enumerant["version"].asString(); std::string lastVersion = enumerant["lastVersion"].asString(); Extensions exts(getExts(enumerant)); OperandParameters params;