From f2867d748531aa22f56d7ce6cdf06c881322df14 Mon Sep 17 00:00:00 2001 From: Ehsan Nasiri Date: Thu, 9 Feb 2017 16:23:40 -0500 Subject: [PATCH] The Signedness in OpTypeInt must always be 0. When Kernel capability is used, The Signedness in OpTypeInt must always be 0. Fixes issue #492. --- source/validate_instruction.cpp | 9 ++ test/val/val_capability_test.cpp | 230 +++++++++++++++++++++++---------------- test/val/val_cfg_test.cpp | 2 +- test/val/val_data_test.cpp | 5 +- test/val/val_id_test.cpp | 93 +++++++++------- test/val/val_ssa_test.cpp | 117 ++++++++++---------- test/val/val_storage_test.cpp | 6 +- 7 files changed, 262 insertions(+), 200 deletions(-) diff --git a/source/validate_instruction.cpp b/source/validate_instruction.cpp index dab28a1..e75bbb8 100644 --- a/source/validate_instruction.cpp +++ b/source/validate_instruction.cpp @@ -348,6 +348,15 @@ spv_result_t InstructionPass(ValidationState_t& _, } } + // SPIR-V Spec 2.16.3: Validation Rules for Kernel Capabilities: The + // Signedness in OpTypeInt must always be 0. + if (SpvOpTypeInt == inst->opcode && _.HasCapability(SpvCapabilityKernel) && + inst->words[inst->operands[2].offset] != 0u) { + return _.diag(SPV_ERROR_INVALID_BINARY) << "The Signedness in OpTypeInt " + "must always be 0 when Kernel " + "capability is used."; + } + // In order to validate decoration rules, we need to know all the decorations // that are applied to any given . RegisterDecorations(_, inst); diff --git a/test/val/val_capability_test.cpp b/test/val/val_capability_test.cpp index 65345d6..6ffded7 100644 --- a/test/val/val_capability_test.cpp +++ b/test/val/val_capability_test.cpp @@ -37,6 +37,7 @@ using std::string; using std::tuple; using std::vector; using testing::Combine; +using testing::HasSubstr; using testing::Values; using testing::ValuesIn; @@ -812,207 +813,207 @@ INSTANTIATE_TEST_CASE_P(Decoration, ValidateCapability, make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt RelaxedPrecision\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Block\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt BufferBlock\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt RowMajor\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), MatrixDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt ColMajor\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), MatrixDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt ArrayStride 1\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt MatrixStride 1\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), MatrixDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt GLSLShared\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt GLSLPacked\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt CPacked\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt NoPerspective\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Flat\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Patch\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), TessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Centroid\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Sample\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"SampleRateShading"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Invariant\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Restrict\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Aliased\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Volatile\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt Constant\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Coherent\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt NonWritable\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt NonReadable\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Uniform\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt SaturatedConversion\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Stream 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"GeometryStreams"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Location 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Component 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Index 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Binding 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt DescriptorSet 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt Offset 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt XfbBuffer 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"TransformFeedback"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt XfbStride 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"TransformFeedback"}), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt FuncParamAttr Zext\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt FPRoundingMode RTE\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt FPFastMathMode Fast\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt LinkageAttributes \"other\" Import\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"Linkage"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt NoContraction\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt InputAttachmentIndex 0\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"InputAttachment"}), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt Alignment 4\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()) )),); @@ -1023,7 +1024,7 @@ INSTANTIATE_TEST_CASE_P( Values(make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt SpecId 1\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()))), ); INSTANTIATE_TEST_CASE_P( @@ -1032,7 +1033,7 @@ INSTANTIATE_TEST_CASE_P( Values(make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %p MaxByteOffset 0 " - "%i32 = OpTypeInt 32 1 " + "%i32 = OpTypeInt 32 0 " "%pi32 = OpTypePointer Workgroup %i32 " "%p = OpVariable %pi32 Workgroup " + string(kVoidFVoid), @@ -1043,13 +1044,13 @@ INSTANTIATE_TEST_CASE_P( make_pair(string("OpMemoryModel Logical OpenCL " "OpEntryPoint Kernel %func \"compute\" \n" "OpDecorate %intt SpecId 1 " - "%intt = OpTypeInt 32 1 ") + + "%intt = OpTypeInt 32 0 ") + string(kVoidFVoid), KernelDependencies()), make_pair(string("OpMemoryModel Logical Simple " "OpEntryPoint Vertex %func \"shader\" \n" "OpDecorate %intt SpecId 1 " - "%intt = OpTypeInt 32 1 ") + + "%intt = OpTypeInt 32 0 ") + string(kVoidFVoid), ShaderDependencies()))), ); // clang-format off @@ -1061,7 +1062,7 @@ INSTANTIATE_TEST_CASE_P(BuiltIn, ValidateCapability, make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn Position\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), // Just mentioning PointSize, ClipDistance, or CullDistance as a BuiltIn does // not trigger the requirement for the associated capability. @@ -1069,212 +1070,212 @@ make_pair(string(kOpenCLMemoryModel) + make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn PointSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn ClipDistance\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn CullDistance\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn VertexId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn InstanceId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn PrimitiveId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), GeometryTessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn InvocationId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), GeometryTessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn Layer\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), GeometryDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn ViewportIndex\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"MultiViewport"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn TessLevelOuter\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), TessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn TessLevelInner\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), TessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn TessCoord\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), TessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn PatchVertices\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), TessellationDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn FragCoord\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn PointCoord\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn FrontFacing\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn SampleId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"SampleRateShading"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn SamplePosition\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"SampleRateShading"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn SampleMask\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), vector{"SampleRateShading"}), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn FragDepth\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn HelperInvocation\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn VertexIndex\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn InstanceIndex\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn NumWorkgroups\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn WorkgroupSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn WorkgroupId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn LocalInvocationId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn GlobalInvocationId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn LocalInvocationIndex\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllCapabilities()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn WorkDim\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn GlobalSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn EnqueuedWorkgroupSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn GlobalOffset\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn GlobalLinearId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn SubgroupSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn SubgroupMaxSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn NumSubgroups\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn NumEnqueuedSubgroups\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn SubgroupId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn SubgroupLocalInvocationId\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), KernelDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn VertexIndex\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()), make_pair(string(kOpenCLMemoryModel) + "OpEntryPoint Kernel %func \"compute\" \n" + "OpDecorate %intt BuiltIn InstanceIndex\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), ShaderDependencies()) )),); @@ -1290,17 +1291,17 @@ INSTANTIATE_TEST_CASE_P(BuiltIn, ValidateCapabilityVulkan10, make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn PointSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllV10Capabilities()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn ClipDistance\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllV10Capabilities()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn CullDistance\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllV10Capabilities()) )),); @@ -1312,17 +1313,17 @@ INSTANTIATE_TEST_CASE_P(BuiltIn, ValidateCapabilityOpenGL40, make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn PointSize\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllV10Capabilities()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn ClipDistance\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllV10Capabilities()), make_pair(string(kGLSL450MemoryModel) + "OpEntryPoint Vertex %func \"shader\" \n" + "OpDecorate %intt BuiltIn CullDistance\n" - "%intt = OpTypeInt 32 1\n" + string(kVoidFVoid), + "%intt = OpTypeInt 32 0\n" + string(kVoidFVoid), AllV10Capabilities()) )),); @@ -1360,7 +1361,7 @@ OpCapability Kernel OpCapability Linkage OpMemoryModel Logical OpenCL -%i32 = OpTypeInt 32 1 +%i32 = OpTypeInt 32 0 %f32 = OpTypeFloat 32 %v4i32 = OpTypeVector %i32 4 %timg = OpTypeImage %i32 2D 0 0 0 0 Unknown @@ -1455,7 +1456,7 @@ OpCapability Linkage OpMemoryModel Logical OpenCL ; %i32 has ID 1 -%i32 = OpTypeInt 32 1 +%i32 = OpTypeInt 32 0 %tf = OpTypeFunction %i32 %pi32 = OpTypePointer CrossWorkgroup %i32 %var = OpVariable %pi32 CrossWorkgroup @@ -1483,4 +1484,41 @@ OpFunctionEnd ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); } +TEST_F(ValidateCapability, IntSignednessKernelGood) { + const std::string spirv = R"( +OpCapability Kernel +OpCapability Linkage +OpMemoryModel Logical OpenCL +%i32 = OpTypeInt 32 0 +)"; + CompileSuccessfully(spirv); + EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + +TEST_F(ValidateCapability, IntSignednessKernelBad) { + const std::string spirv = R"( +OpCapability Kernel +OpCapability Linkage +OpMemoryModel Logical OpenCL +%i32 = OpTypeInt 32 1 +)"; + CompileSuccessfully(spirv); + EXPECT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions()); + EXPECT_THAT(getDiagnosticString(), + HasSubstr("The Signedness in OpTypeInt must always be 0 when " + "Kernel capability is used.")); +} + +TEST_F(ValidateCapability, IntSignednessShaderGood) { + const std::string spirv = R"( +OpCapability Shader +OpCapability Linkage +OpMemoryModel Logical GLSL450 +%u32 = OpTypeInt 32 0 +%i32 = OpTypeInt 32 1 +)"; + CompileSuccessfully(spirv); + EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + } // namespace anonymous diff --git a/test/val/val_cfg_test.cpp b/test/val/val_cfg_test.cpp index 069d019..ac2a863 100644 --- a/test/val/val_cfg_test.cpp +++ b/test/val/val_cfg_test.cpp @@ -170,7 +170,7 @@ const char* types_consts() { static const char* types = "%voidt = OpTypeVoid\n" "%boolt = OpTypeBool\n" - "%intt = OpTypeInt 32 1\n" + "%intt = OpTypeInt 32 0\n" "%one = OpConstant %intt 1\n" "%two = OpConstant %intt 2\n" "%ptrt = OpTypePointer Function %intt\n" diff --git a/test/val/val_data_test.cpp b/test/val/val_data_test.cpp index 82d5d00..d1be941 100644 --- a/test/val/val_data_test.cpp +++ b/test/val/val_data_test.cpp @@ -22,6 +22,8 @@ #include "unit_spirv.h" #include "val_fixtures.h" +namespace { + using ::testing::HasSubstr; using ::testing::MatchesRegex; @@ -170,7 +172,7 @@ TEST_F(ValidateData, vec15) { } TEST_F(ValidateData, int8_good) { - string str = header_with_int8 + "%2 = OpTypeInt 8 1"; + string str = header_with_int8 + "%2 = OpTypeInt 8 0"; CompileSuccessfully(str.c_str()); ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); } @@ -471,3 +473,4 @@ OpTypeForwardPointer %_ptr_Generic_struct_A Generic ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); } +} // anonymous namespace diff --git a/test/val/val_id_test.cpp b/test/val/val_id_test.cpp index c8c72cf..71a2128 100644 --- a/test/val/val_id_test.cpp +++ b/test/val/val_id_test.cpp @@ -451,7 +451,7 @@ TEST_F(ValidateIdWithMessage, OpTypeVectorFloat) { TEST_F(ValidateIdWithMessage, OpTypeVectorInt) { string spirv = kGLSL450MemoryModel + R"( -%1 = OpTypeInt 32 1 +%1 = OpTypeInt 32 0 %2 = OpTypeVector %1 4)"; CompileSuccessfully(spirv.c_str()); EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); @@ -537,9 +537,16 @@ enum Signed { kSigned, kUnsigned }; // Creates an assembly snippet declaring OpTypeArray with the given length. string MakeArrayLength(const string& len, Signed isSigned, int width) { ostringstream ss; - ss << kGLSL450MemoryModel; - ss << " %t = OpTypeInt " << width << (isSigned == kSigned ? " 1" : " 0") - << " %l = OpConstant %t " << len << " %a = OpTypeArray %t %l"; + ss << R"( + OpCapability Shader + OpCapability Linkage + OpCapability Int16 + OpCapability Int64 + )"; + ss << "OpMemoryModel Logical GLSL450\n"; + ss << " %t = OpTypeInt " << width << (isSigned == kSigned ? " 1" : " 0"); + ss << " %l = OpConstant %t " << len; + ss << " %a = OpTypeArray %t %l"; return ss.str(); } @@ -627,12 +634,16 @@ TEST_P(OpTypeArrayLengthTest, LengthNegative) { } // The only valid widths for integers are 8, 16, 32, and 64. +// Since the Int8 capability requires the Kernel capability, and the Kernel +// capability prohibits usage of signed integers, we can skip 8-bit integers +// here since the purpose of these tests is to check the validity of +// OpTypeArray, not OpTypeInt. INSTANTIATE_TEST_CASE_P(Widths, OpTypeArrayLengthTest, - ValuesIn(vector{8, 16, 32, 64})); + ValuesIn(vector{16, 32, 64})); TEST_F(ValidateIdWithMessage, OpTypeArrayLengthNull) { string spirv = kGLSL450MemoryModel + R"( -%i32 = OpTypeInt 32 1 +%i32 = OpTypeInt 32 0 %len = OpConstantNull %i32 %ary = OpTypeArray %i32 %len)"; CompileSuccessfully(spirv.c_str()); @@ -645,7 +656,7 @@ TEST_F(ValidateIdWithMessage, OpTypeArrayLengthNull) { TEST_F(ValidateIdWithMessage, OpTypeArrayLengthSpecConst) { string spirv = kGLSL450MemoryModel + R"( -%i32 = OpTypeInt 32 1 +%i32 = OpTypeInt 32 0 %len = OpSpecConstant %i32 2 %ary = OpTypeArray %i32 %len)"; CompileSuccessfully(spirv.c_str()); @@ -654,7 +665,7 @@ TEST_F(ValidateIdWithMessage, OpTypeArrayLengthSpecConst) { TEST_F(ValidateIdWithMessage, OpTypeArrayLengthSpecConstOp) { string spirv = kGLSL450MemoryModel + R"( -%i32 = OpTypeInt 32 1 +%i32 = OpTypeInt 32 0 %c1 = OpConstant %i32 1 %c2 = OpConstant %i32 2 %len = OpSpecConstantOp %i32 IAdd %c1 %c2 @@ -1029,7 +1040,7 @@ TEST_F(ValidateIdWithMessage, OpConstantCompositeArrayConstituentUndefTypeBad) { TEST_F(ValidateIdWithMessage, OpConstantCompositeStructGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpConstant %1 42 %5 = OpConstant %2 4300000000 @@ -1040,7 +1051,7 @@ TEST_F(ValidateIdWithMessage, OpConstantCompositeStructGood) { TEST_F(ValidateIdWithMessage, OpConstantCompositeStructUndefGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpConstant %1 42 %5 = OpUndef %2 @@ -1051,7 +1062,7 @@ TEST_F(ValidateIdWithMessage, OpConstantCompositeStructUndefGood) { TEST_F(ValidateIdWithMessage, OpConstantCompositeStructMemberTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpConstant %1 42 %5 = OpConstant %2 4300000000 @@ -1066,7 +1077,7 @@ TEST_F(ValidateIdWithMessage, OpConstantCompositeStructMemberTypeBad) { TEST_F(ValidateIdWithMessage, OpConstantCompositeStructMemberUndefTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpConstant %1 42 %5 = OpUndef %2 @@ -1596,7 +1607,7 @@ TEST_F(ValidateIdWithMessage, TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpConstant %1 42 %5 = OpSpecConstant %2 4300000000 @@ -1626,7 +1637,7 @@ TEST_F(ValidateIdWithMessage, TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructUndefGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpSpecConstant %1 42 %5 = OpUndef %2 @@ -1639,7 +1650,7 @@ TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructUndefGood) { TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructNonConstBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpSpecConstant %1 42 %5 = OpUndef %2 @@ -1656,7 +1667,7 @@ TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructNonConstBad) { TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructMemberTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpConstant %1 42 %5 = OpSpecConstant %2 4300000000 @@ -1673,7 +1684,7 @@ TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructMemberTypeBad) { TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructMemberUndefTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeInt 32 0 -%2 = OpTypeInt 64 1 +%2 = OpTypeInt 64 0 %3 = OpTypeStruct %1 %1 %2 %4 = OpSpecConstant %1 42 %5 = OpUndef %2 @@ -1690,7 +1701,7 @@ TEST_F(ValidateIdWithMessage, OpSpecConstantCompositeStructMemberUndefTypeBad) { TEST_F(ValidateIdWithMessage, OpVariableGood) { string spirv = kGLSL450MemoryModel + R"( -%1 = OpTypeInt 32 1 +%1 = OpTypeInt 32 0 %2 = OpTypePointer Input %1 %3 = OpVariable %2 Input)"; CompileSuccessfully(spirv.c_str()); @@ -1698,7 +1709,7 @@ TEST_F(ValidateIdWithMessage, OpVariableGood) { } TEST_F(ValidateIdWithMessage, OpVariableInitializerConstantGood) { string spirv = kGLSL450MemoryModel + R"( -%1 = OpTypeInt 32 1 +%1 = OpTypeInt 32 0 %2 = OpTypePointer Input %1 %3 = OpConstant %1 42 %4 = OpVariable %2 Input %3)"; @@ -1707,7 +1718,7 @@ TEST_F(ValidateIdWithMessage, OpVariableInitializerConstantGood) { } TEST_F(ValidateIdWithMessage, OpVariableInitializerGlobalVariableGood) { string spirv = kGLSL450MemoryModel + R"( -%1 = OpTypeInt 32 1 +%1 = OpTypeInt 32 0 %2 = OpTypePointer Uniform %1 %3 = OpVariable %2 Uniform %4 = OpTypePointer Uniform %2 ; pointer to pointer @@ -1718,7 +1729,7 @@ TEST_F(ValidateIdWithMessage, OpVariableInitializerGlobalVariableGood) { // TODO: Positive test OpVariable with OpConstantNull of OpTypePointer TEST_F(ValidateIdWithMessage, OpVariableResultTypeBad) { string spirv = kGLSL450MemoryModel + R"( -%1 = OpTypeInt 32 1 +%1 = OpTypeInt 32 0 %2 = OpVariable %1 Input)"; CompileSuccessfully(spirv.c_str()); EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); @@ -1728,7 +1739,7 @@ TEST_F(ValidateIdWithMessage, OpVariableResultTypeBad) { } TEST_F(ValidateIdWithMessage, OpVariableInitializerIsTypeBad) { string spirv = kGLSL450MemoryModel + R"( -%1 = OpTypeInt 32 1 +%1 = OpTypeInt 32 0 %2 = OpTypePointer Input %1 %3 = OpVariable %2 Input %2)"; CompileSuccessfully(spirv.c_str()); @@ -1740,7 +1751,7 @@ TEST_F(ValidateIdWithMessage, OpVariableInitializerIsTypeBad) { TEST_F(ValidateIdWithMessage, OpVariableInitializerIsFunctionVarBad) { string spirv = kGLSL450MemoryModel + R"( -%int = OpTypeInt 32 1 +%int = OpTypeInt 32 0 %ptrint = OpTypePointer Function %int %ptrptrint = OpTypePointer Function %ptrint %void = OpTypeVoid @@ -1761,7 +1772,7 @@ OpFunctionEnd TEST_F(ValidateIdWithMessage, OpVariableInitializerIsModuleVarGood) { string spirv = kGLSL450MemoryModel + R"( -%int = OpTypeInt 32 1 +%int = OpTypeInt 32 0 %ptrint = OpTypePointer Uniform %int %mvar = OpVariable %ptrint Uniform %ptrptrint = OpTypePointer Function %ptrint @@ -1780,7 +1791,7 @@ OpFunctionEnd TEST_F(ValidateIdWithMessage, OpLoadGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid - %2 = OpTypeInt 32 1 + %2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %5 = OpVariable %3 UniformConstant @@ -1796,7 +1807,7 @@ TEST_F(ValidateIdWithMessage, OpLoadGood) { TEST_F(ValidateIdWithMessage, OpLoadResultTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %5 = OpVariable %3 UniformConstant @@ -1815,7 +1826,7 @@ TEST_F(ValidateIdWithMessage, OpLoadResultTypeBad) { TEST_F(ValidateIdWithMessage, OpLoadPointerBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %9 = OpTypeFloat 32 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 @@ -1834,7 +1845,7 @@ TEST_F(ValidateIdWithMessage, OpLoadPointerBad) { TEST_F(ValidateIdWithMessage, OpStoreGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %5 = OpConstant %2 42 @@ -1850,7 +1861,7 @@ TEST_F(ValidateIdWithMessage, OpStoreGood) { TEST_F(ValidateIdWithMessage, OpStorePointerBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %5 = OpConstant %2 42 @@ -1868,7 +1879,7 @@ TEST_F(ValidateIdWithMessage, OpStorePointerBad) { TEST_F(ValidateIdWithMessage, OpStoreObjectGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %5 = OpConstant %2 42 @@ -1886,7 +1897,7 @@ TEST_F(ValidateIdWithMessage, OpStoreObjectGood) { TEST_F(ValidateIdWithMessage, OpStoreTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %9 = OpTypeFloat 32 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 @@ -1907,7 +1918,7 @@ TEST_F(ValidateIdWithMessage, OpStoreTypeBad) { TEST_F(ValidateIdWithMessage, OpStoreVoid) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %6 = OpVariable %3 UniformConstant @@ -1926,7 +1937,7 @@ TEST_F(ValidateIdWithMessage, OpStoreVoid) { TEST_F(ValidateIdWithMessage, OpStoreLabel) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %1 %6 = OpVariable %3 UniformConstant @@ -1945,7 +1956,7 @@ TEST_F(ValidateIdWithMessage, OpStoreLabel) { // https://cvs.khronos.org/bugzilla/show_bug.cgi?id=15404 TEST_F(ValidateIdWithMessage, DISABLED_OpStoreFunction) { string spirv = kGLSL450MemoryModel + R"( -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypePointer UniformConstant %2 %4 = OpTypeFunction %2 %5 = OpConstant %2 123 @@ -2593,7 +2604,7 @@ INSTANTIATE_TEST_CASE_P( TEST_F(ValidateIdWithMessage, OpFunctionGood) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %3 = OpTypeFunction %1 %2 %2 %4 = OpFunction %1 None %3 OpFunctionEnd)"; @@ -2603,7 +2614,7 @@ TEST_F(ValidateIdWithMessage, OpFunctionGood) { TEST_F(ValidateIdWithMessage, OpFunctionResultTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %5 = OpConstant %2 42 %3 = OpTypeFunction %1 %2 %2 %4 = OpFunction %2 None %3 @@ -2617,7 +2628,7 @@ TEST_F(ValidateIdWithMessage, OpFunctionResultTypeBad) { TEST_F(ValidateIdWithMessage, OpFunctionFunctionTypeBad) { string spirv = kGLSL450MemoryModel + R"( %1 = OpTypeVoid -%2 = OpTypeInt 32 1 +%2 = OpTypeInt 32 0 %4 = OpFunction %1 None %2 OpFunctionEnd)"; CompileSuccessfully(spirv.c_str()); @@ -3609,7 +3620,7 @@ TEST_F(ValidateIdWithMessage, OpPtrAccessChainGood) { TEST_F(ValidateIdWithMessage, OpLoadBitcastPointerGood) { string spirv = kOpenCLMemoryModel64 + R"( %2 = OpTypeVoid -%3 = OpTypeInt 32 1 +%3 = OpTypeInt 32 0 %4 = OpTypeFloat 32 %5 = OpTypePointer UniformConstant %3 %6 = OpTypePointer UniformConstant %4 @@ -3627,7 +3638,7 @@ TEST_F(ValidateIdWithMessage, OpLoadBitcastPointerGood) { TEST_F(ValidateIdWithMessage, OpLoadBitcastNonPointerBad) { string spirv = kOpenCLMemoryModel64 + R"( %2 = OpTypeVoid -%3 = OpTypeInt 32 1 +%3 = OpTypeInt 32 0 %4 = OpTypeFloat 32 %5 = OpTypePointer UniformConstant %3 %6 = OpTypeFunction %2 @@ -3648,7 +3659,7 @@ TEST_F(ValidateIdWithMessage, OpLoadBitcastNonPointerBad) { TEST_F(ValidateIdWithMessage, OpStoreBitcastPointerGood) { string spirv = kOpenCLMemoryModel64 + R"( %2 = OpTypeVoid -%3 = OpTypeInt 32 1 +%3 = OpTypeInt 32 0 %4 = OpTypeFloat 32 %5 = OpTypePointer Function %3 %6 = OpTypePointer Function %4 @@ -3667,7 +3678,7 @@ TEST_F(ValidateIdWithMessage, OpStoreBitcastPointerGood) { TEST_F(ValidateIdWithMessage, OpStoreBitcastNonPointerBad) { string spirv = kOpenCLMemoryModel64 + R"( %2 = OpTypeVoid -%3 = OpTypeInt 32 1 +%3 = OpTypeInt 32 0 %4 = OpTypeFloat 32 %5 = OpTypePointer Function %4 %6 = OpTypeFunction %2 diff --git a/test/val/val_ssa_test.cpp b/test/val/val_ssa_test.cpp index affc5a4..b2074b5 100644 --- a/test/val/val_ssa_test.cpp +++ b/test/val/val_ssa_test.cpp @@ -543,6 +543,8 @@ TEST_F(ValidateSSA, ForwardBranchConditionalMissingTargetBad) { EXPECT_THAT(getDiagnosticString(), HasSubstr("missing")); } +// Since Int8 requires the Kernel capability, the signedness of int types may +// not be "1". const string kHeader = R"( OpCapability Int8 OpCapability DeviceEnqueue @@ -554,13 +556,12 @@ const string kBasicTypes = R"( %voidt = OpTypeVoid %boolt = OpTypeBool %int8t = OpTypeInt 8 0 -%intt = OpTypeInt 32 1 %uintt = OpTypeInt 32 0 %vfunct = OpTypeFunction %voidt -%intptrt = OpTypePointer UniformConstant %intt -%zero = OpConstant %intt 0 -%one = OpConstant %intt 1 -%ten = OpConstant %intt 10 +%intptrt = OpTypePointer UniformConstant %uintt +%zero = OpConstant %uintt 0 +%one = OpConstant %uintt 1 +%ten = OpConstant %uintt 10 %false = OpConstantFalse %boolt )"; @@ -568,23 +569,23 @@ const string kKernelTypesAndConstants = R"( %queuet = OpTypeQueue %three = OpConstant %uintt 3 -%arr3t = OpTypeArray %intt %three -%ndt = OpTypeStruct %intt %arr3t %arr3t %arr3t +%arr3t = OpTypeArray %uintt %three +%ndt = OpTypeStruct %uintt %arr3t %arr3t %arr3t %eventt = OpTypeEvent -%offset = OpConstant %intt 0 -%local = OpConstant %intt 1 -%gl = OpConstant %intt 1 +%offset = OpConstant %uintt 0 +%local = OpConstant %uintt 1 +%gl = OpConstant %uintt 1 -%nevent = OpConstant %intt 0 +%nevent = OpConstant %uintt 0 %event = OpConstantNull %eventt %firstp = OpConstant %int8t 0 -%psize = OpConstant %intt 0 -%palign = OpConstant %intt 32 -%lsize = OpConstant %intt 1 -%flags = OpConstant %intt 0 ; NoWait +%psize = OpConstant %uintt 0 +%palign = OpConstant %uintt 32 +%lsize = OpConstant %uintt 1 +%flags = OpConstant %uintt 0 ; NoWait %kfunct = OpTypeFunction %voidt %intptrt )"; @@ -720,7 +721,7 @@ TEST_F(ValidateSSA, ForwardEnqueueKernelNonDominantParameter4Bad) { %err = OpEnqueueKernel %uintt %dqueue %flags %ndval %nevent2 %event %revent %kfunc %firstp %psize %palign %lsize - %nevent2 = OpCopyObject %intt %nevent + %nevent2 = OpCopyObject %uintt %nevent OpReturn OpFunctionEnd )"; @@ -776,7 +777,7 @@ TEST_F(ValidateSSA, ForwardEnqueueKernelNonDominantParameter9Bad) { %err = OpEnqueueKernel %uintt %dqueue %flags %ndval %nevent %event %revent %kfunc %firstp %psize2 %palign %lsize - %psize2 = OpCopyObject %intt %psize + %psize2 = OpCopyObject %uintt %psize OpReturn OpFunctionEnd )"; @@ -790,7 +791,7 @@ TEST_F(ValidateSSA, ForwardEnqueueKernelNonDominantParameter10Bad) { %err = OpEnqueueKernel %uintt %dqueue %flags %ndval %nevent %event %revent %kfunc %firstp %psize %palign2 %lsize - %palign2 = OpCopyObject %intt %palign + %palign2 = OpCopyObject %uintt %palign OpReturn OpFunctionEnd )"; @@ -804,7 +805,7 @@ TEST_F(ValidateSSA, ForwardEnqueueKernelNonDominantParameter11Bad) { %err = OpEnqueueKernel %uintt %dqueue %flags %ndval %nevent %event %revent %kfunc %firstp %psize %palign %lsize2 - %lsize2 = OpCopyObject %intt %lsize + %lsize2 = OpCopyObject %uintt %lsize OpReturn OpFunctionEnd )"; @@ -949,7 +950,7 @@ TEST_P(ValidateSSA, // clang-format off ss << forwardKernelNonDominantParameterBaseCode("psize2") + " %numsg = " << instruction + " %uintt" + ndrange_param + "%kfunc %firstp %psize2 %palign" - << "\n %psize2 = OpCopyObject %intt %psize" + << "\n %psize2 = OpCopyObject %uintt %psize" << return_instructions; // clang-format on @@ -968,7 +969,7 @@ TEST_P(ValidateSSA, // clang-format off ss << forwardKernelNonDominantParameterBaseCode("palign2") + " %numsg = " << instruction + " %uintt" + ndrange_param + "%kfunc %firstp %psize %palign2" - << "\n %palign2 = OpCopyObject %intt %palign" + << "\n %palign2 = OpCopyObject %uintt %palign" << return_instructions; // clang-format on @@ -984,11 +985,11 @@ TEST_F(ValidateSSA, PhiGood) { R"( %func = OpFunction %voidt None %vfunct %preheader = OpLabel -%init = OpCopyObject %intt %zero +%init = OpCopyObject %uintt %zero OpBranch %loop %loop = OpLabel -%i = OpPhi %intt %init %preheader %loopi %loop -%loopi = OpIAdd %intt %i %one +%i = OpPhi %uintt %init %preheader %loopi %loop +%loopi = OpIAdd %uintt %i %one OpNop %cond = OpSLessThan %boolt %i %ten OpLoopMerge %endl %loop None @@ -1007,11 +1008,11 @@ TEST_F(ValidateSSA, PhiMissingTypeBad) { R"( %func = OpFunction %voidt None %vfunct %preheader = OpLabel -%init = OpCopyObject %intt %zero +%init = OpCopyObject %uintt %zero OpBranch %loop %loop = OpLabel %i = OpPhi %missing %init %preheader %loopi %loop -%loopi = OpIAdd %intt %i %one +%loopi = OpIAdd %uintt %i %one OpNop %cond = OpSLessThan %boolt %i %ten OpLoopMerge %endl %loop None @@ -1031,11 +1032,11 @@ TEST_F(ValidateSSA, PhiMissingIdBad) { R"( %func = OpFunction %voidt None %vfunct %preheader = OpLabel -%init = OpCopyObject %intt %zero +%init = OpCopyObject %uintt %zero OpBranch %loop %loop = OpLabel -%i = OpPhi %intt %missing %preheader %loopi %loop -%loopi = OpIAdd %intt %i %one +%i = OpPhi %uintt %missing %preheader %loopi %loop +%loopi = OpIAdd %uintt %i %one OpNop %cond = OpSLessThan %boolt %i %ten OpLoopMerge %endl %loop None @@ -1055,11 +1056,11 @@ TEST_F(ValidateSSA, PhiMissingLabelBad) { R"( %func = OpFunction %voidt None %vfunct %preheader = OpLabel -%init = OpCopyObject %intt %zero +%init = OpCopyObject %uintt %zero OpBranch %loop %loop = OpLabel -%i = OpPhi %intt %init %missing %loopi %loop -%loopi = OpIAdd %intt %i %one +%i = OpPhi %uintt %init %missing %loopi %loop +%loopi = OpIAdd %uintt %i %one OpNop %cond = OpSLessThan %boolt %i %ten OpLoopMerge %endl %loop None @@ -1079,15 +1080,15 @@ TEST_F(ValidateSSA, IdDominatesItsUseGood) { R"( %func = OpFunction %voidt None %vfunct %entry = OpLabel -%cond = OpSLessThan %intt %one %ten -%eleven = OpIAdd %intt %one %ten +%cond = OpSLessThan %uintt %one %ten +%eleven = OpIAdd %uintt %one %ten OpSelectionMerge %merge None OpBranchConditional %cond %t %f %t = OpLabel -%twelve = OpIAdd %intt %eleven %one +%twelve = OpIAdd %uintt %eleven %one OpBranch %merge %f = OpLabel -%twentytwo = OpIAdd %intt %eleven %ten +%twentytwo = OpIAdd %uintt %eleven %ten OpBranch %merge %merge = OpLabel OpReturn @@ -1107,15 +1108,15 @@ TEST_F(ValidateSSA, IdDoesNotDominateItsUseBad) { R"( %func = OpFunction %voidt None %vfunct %entry = OpLabel -%cond = OpSLessThan %intt %one %ten +%cond = OpSLessThan %uintt %one %ten OpSelectionMerge %merge None OpBranchConditional %cond %true_block %false_block %true_block = OpLabel -%eleven = OpIAdd %intt %one %ten -%twelve = OpIAdd %intt %eleven %one +%eleven = OpIAdd %uintt %one %ten +%twelve = OpIAdd %uintt %eleven %one OpBranch %merge %false_block = OpLabel -%twentytwo = OpIAdd %intt %eleven %ten +%twentytwo = OpIAdd %uintt %eleven %ten OpBranch %merge %merge = OpLabel OpReturn @@ -1135,17 +1136,17 @@ TEST_F(ValidateSSA, PhiUseDoesntDominateDefinitionGood) { %func = OpFunction %voidt None %vfunct %entry = OpLabel %var_one = OpVariable %intptrt Function %one -%one_val = OpLoad %intt %var_one +%one_val = OpLoad %uintt %var_one OpBranch %loop %loop = OpLabel -%i = OpPhi %intt %one_val %entry %inew %cont -%cond = OpSLessThan %intt %one %ten +%i = OpPhi %uintt %one_val %entry %inew %cont +%cond = OpSLessThan %uintt %one %ten OpLoopMerge %merge %cont None OpBranchConditional %cond %body %merge %body = OpLabel OpBranch %cont %cont = OpLabel -%inew = OpIAdd %intt %i %one +%inew = OpIAdd %uintt %i %one OpBranch %loop %merge = OpLabel OpReturn @@ -1163,18 +1164,18 @@ TEST_F(ValidateSSA, %func = OpFunction %voidt None %vfunct %entry = OpLabel %var_one = OpVariable %intptrt Function %one -%one_val = OpLoad %intt %var_one +%one_val = OpLoad %uintt %var_one OpBranch %loop %loop = OpLabel -%i = OpPhi %intt %one_val %entry %inew %cont -%bad = OpIAdd %intt %inew %one -%cond = OpSLessThan %intt %one %ten +%i = OpPhi %uintt %one_val %entry %inew %cont +%bad = OpIAdd %uintt %inew %one +%cond = OpSLessThan %uintt %one %ten OpLoopMerge %merge %cont None OpBranchConditional %cond %body %merge %body = OpLabel OpBranch %cont %cont = OpLabel -%inew = OpIAdd %intt %i %one +%inew = OpIAdd %uintt %i %one OpBranch %loop %merge = OpLabel OpReturn @@ -1321,14 +1322,14 @@ TEST_F(ValidateSSA, DominanceCheckIgnoresUsesInUnreachableBlocksDefIsParamGood) { string str = kHeader + kBasicTypes + R"( -%void_fn_int = OpTypeFunction %voidt %intt +%void_fn_int = OpTypeFunction %voidt %uintt %func = OpFunction %voidt None %void_fn_int -%int_param = OpFunctionParameter %intt +%int_param = OpFunctionParameter %uintt %entry = OpLabel OpReturn %unreach = OpLabel -%use = OpCopyObject %intt %int_param +%use = OpCopyObject %uintt %int_param OpReturn OpFunctionEnd )"; @@ -1343,16 +1344,16 @@ TEST_F(ValidateSSA, UseFunctionParameterFromOtherFunctionBad) { "OpName %func \"func\"\n" + "OpName %func2 \"func2\"\n" + kBasicTypes + R"( -%viifunct = OpTypeFunction %voidt %intt %intt +%viifunct = OpTypeFunction %voidt %uintt %uintt %func = OpFunction %voidt None %viifunct -%first = OpFunctionParameter %intt -%second = OpFunctionParameter %intt +%first = OpFunctionParameter %uintt +%second = OpFunctionParameter %uintt OpFunctionEnd %func2 = OpFunction %voidt None %viifunct -%first2 = OpFunctionParameter %intt -%second2 = OpFunctionParameter %intt +%first2 = OpFunctionParameter %uintt +%second2 = OpFunctionParameter %uintt %entry2 = OpLabel -%baduse = OpIAdd %intt %first %first2 +%baduse = OpIAdd %uintt %first %first2 OpReturn OpFunctionEnd )"; diff --git a/test/val/val_storage_test.cpp b/test/val/val_storage_test.cpp index 5c7a4e3..579c381 100644 --- a/test/val/val_storage_test.cpp +++ b/test/val/val_storage_test.cpp @@ -77,7 +77,7 @@ TEST_F(ValidateStorage, OtherStorageOutsideFunction) { OpCapability AtomicStorage OpCapability Linkage OpMemoryModel Logical GLSL450 -%intt = OpTypeInt 32 1 +%intt = OpTypeInt 32 0 %voidt = OpTypeVoid %vfunct = OpTypeFunction %voidt %ptrt = OpTypePointer Function %intt @@ -110,7 +110,7 @@ TEST_P(ValidateStorage, OtherStorageInsideFunction) { OpCapability AtomicStorage OpCapability Linkage OpMemoryModel Logical GLSL450 -%intt = OpTypeInt 32 1 +%intt = OpTypeInt 32 0 %voidt = OpTypeVoid %vfunct = OpTypeFunction %voidt %ptrt = OpTypePointer Function %intt @@ -145,7 +145,7 @@ TEST_F(ValidateStorage, GenericVariableOutsideFunction) { OpCapability Kernel OpCapability Linkage OpMemoryModel Logical OpenCL -%intt = OpTypeInt 32 1 +%intt = OpTypeInt 32 0 %ptrt = OpTypePointer Function %intt %var = OpVariable %ptrt Generic )"; -- 2.7.4