diff --git a/source/diff/diff.cpp b/source/diff/diff.cpp index 13e1ffa9..3b4c24ed 100644 --- a/source/diff/diff.cpp +++ b/source/diff/diff.cpp @@ -307,6 +307,7 @@ class Differ { const opt::Operand& dst_operand); bool DoInstructionsMatchFuzzy(const opt::Instruction* src_inst, const opt::Instruction* dst_inst); + bool AreIdenticalUintConstants(uint32_t src_id, uint32_t dst_id); bool DoDebugAndAnnotationInstructionsMatch(const opt::Instruction* src_inst, const opt::Instruction* dst_inst); bool AreVariablesMatchable(uint32_t src_id, uint32_t dst_id, @@ -840,10 +841,8 @@ bool Differ::DoIdsMatchFuzzy(uint32_t src_id, uint32_t dst_id) { } // Int and Uint constants are interchangeable, match them in that case. - if (IsConstantUint(src_id_to_, src_id) && - IsConstantUint(dst_id_to_, dst_id)) { - return GetConstantUint(src_id_to_, src_id) == - GetConstantUint(dst_id_to_, dst_id); + if (AreIdenticalUintConstants(src_id, dst_id)) { + return true; } return false; @@ -911,6 +910,13 @@ bool Differ::DoInstructionsMatchFuzzy(const opt::Instruction* src_inst, return match; } +bool Differ::AreIdenticalUintConstants(uint32_t src_id, uint32_t dst_id) { + return IsConstantUint(src_id_to_, src_id) && + IsConstantUint(dst_id_to_, dst_id) && + GetConstantUint(src_id_to_, src_id) == + GetConstantUint(dst_id_to_, dst_id); +} + bool Differ::DoDebugAndAnnotationInstructionsMatch( const opt::Instruction* src_inst, const opt::Instruction* dst_inst) { if (src_inst->opcode() != dst_inst->opcode()) { @@ -2001,9 +2007,14 @@ void Differ::MatchTypeIds() { return false; } - return GetConstantUint(src_id_to_, - src_inst->GetInOperand(1).AsId()) == - GetConstantUint(dst_id_to_, dst_inst->GetInOperand(1).AsId()); + if (AreIdenticalUintConstants(src_inst->GetInOperand(1).AsId(), + dst_inst->GetInOperand(1).AsId())) { + return true; + } + + // If size is not OpConstant, expect the ids to match exactly (for + // example if a spec contant is used). + return DoOperandsMatch(src_inst, dst_inst, 1, 1); case SpvOpTypeStruct: return MatchOpTypeStruct(src_inst, dst_inst, flexibility); diff --git a/test/diff/diff_files/constant_array_size_autogen.cpp b/test/diff/diff_files/constant_array_size_autogen.cpp new file mode 100644 index 00000000..16975ff4 --- /dev/null +++ b/test/diff/diff_files/constant_array_size_autogen.cpp @@ -0,0 +1,306 @@ +// GENERATED FILE - DO NOT EDIT. +// Generated by generate_tests.py +// +// Copyright (c) 2022 Google LLC. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "../diff_test_utils.h" + +#include "gtest/gtest.h" + +namespace spvtools { +namespace diff { +namespace { + +// Tests that identical integer constants are matched when used as array size, +// regardless of int or uint. +constexpr char kSrc[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd)"; +constexpr char kDst[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%6 = OpTypeInt 32 1 +%8 = OpTypeVector %5 4 +%15 = OpConstant %6 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd +)"; + +TEST(DiffTest, ConstantArraySize) { + constexpr char kDiff[] = R"( ; SPIR-V + ; Version: 1.6 + ; Generator: Khronos SPIR-V Tools Assembler; 0 +-; Bound: 27 ++; Bound: 34 + ; Schema: 0 + OpCapability Shader + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %22 "main" %4 %19 + OpSource GLSL 450 + OpName %4 "_ua_position" + OpName %17 "gl_PerVertex" + OpMemberName %17 0 "gl_Position" + OpMemberName %17 1 "gl_PointSize" + OpMemberName %17 2 "gl_ClipDistance" + OpMemberName %17 3 "gl_CullDistance" + OpName %19 "" + OpName %22 "main" + OpDecorate %4 Location 0 + OpMemberDecorate %17 1 RelaxedPrecision + OpMemberDecorate %17 0 BuiltIn Position + OpMemberDecorate %17 1 BuiltIn PointSize + OpMemberDecorate %17 2 BuiltIn ClipDistance + OpMemberDecorate %17 3 BuiltIn CullDistance + OpDecorate %17 Block + %1 = OpTypeFloat 32 + %2 = OpTypeVector %1 4 + %5 = OpTypeInt 32 0 ++%27 = OpTypeInt 32 1 + %8 = OpTypeVector %5 4 +-%15 = OpConstant %5 8 ++%15 = OpConstant %27 8 + %16 = OpTypeArray %1 %15 + %17 = OpTypeStruct %2 %1 %16 %16 + %20 = OpTypeVoid + %25 = OpConstant %5 0 + %3 = OpTypePointer Input %2 + %13 = OpTypePointer Output %2 + %18 = OpTypePointer Output %17 + %21 = OpTypeFunction %20 + %4 = OpVariable %3 Input + %19 = OpVariable %18 Output + %22 = OpFunction %20 None %21 + %23 = OpLabel + %24 = OpLoad %2 %4 + %26 = OpAccessChain %13 %19 %25 + OpStore %26 %24 + OpReturn + OpFunctionEnd +)"; + Options options; + DoStringDiffTest(kSrc, kDst, kDiff, options); +} + +TEST(DiffTest, ConstantArraySizeNoDebug) { + constexpr char kSrcNoDebug[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd +)"; + constexpr char kDstNoDebug[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%6 = OpTypeInt 32 1 +%8 = OpTypeVector %5 4 +%15 = OpConstant %6 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd +)"; + constexpr char kDiff[] = R"( ; SPIR-V + ; Version: 1.6 + ; Generator: Khronos SPIR-V Tools Assembler; 0 +-; Bound: 27 ++; Bound: 34 + ; Schema: 0 + OpCapability Shader + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %22 "main" %4 %19 + OpSource GLSL 450 + OpDecorate %4 Location 0 + OpMemberDecorate %17 1 RelaxedPrecision + OpMemberDecorate %17 0 BuiltIn Position + OpMemberDecorate %17 1 BuiltIn PointSize + OpMemberDecorate %17 2 BuiltIn ClipDistance + OpMemberDecorate %17 3 BuiltIn CullDistance + OpDecorate %17 Block + %1 = OpTypeFloat 32 + %2 = OpTypeVector %1 4 + %5 = OpTypeInt 32 0 ++%27 = OpTypeInt 32 1 + %8 = OpTypeVector %5 4 +-%15 = OpConstant %5 8 ++%15 = OpConstant %27 8 + %16 = OpTypeArray %1 %15 + %17 = OpTypeStruct %2 %1 %16 %16 + %20 = OpTypeVoid + %25 = OpConstant %5 0 + %3 = OpTypePointer Input %2 + %13 = OpTypePointer Output %2 + %18 = OpTypePointer Output %17 + %21 = OpTypeFunction %20 + %4 = OpVariable %3 Input + %19 = OpVariable %18 Output + %22 = OpFunction %20 None %21 + %23 = OpLabel + %24 = OpLoad %2 %4 + %26 = OpAccessChain %13 %19 %25 + OpStore %26 %24 + OpReturn + OpFunctionEnd +)"; + Options options; + DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options); +} + +} // namespace +} // namespace diff +} // namespace spvtools diff --git a/test/diff/diff_files/constant_array_size_dst.spvasm b/test/diff/diff_files/constant_array_size_dst.spvasm new file mode 100644 index 00000000..a432b612 --- /dev/null +++ b/test/diff/diff_files/constant_array_size_dst.spvasm @@ -0,0 +1,47 @@ +; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%6 = OpTypeInt 32 1 +%8 = OpTypeVector %5 4 +%15 = OpConstant %6 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd diff --git a/test/diff/diff_files/constant_array_size_src.spvasm b/test/diff/diff_files/constant_array_size_src.spvasm new file mode 100644 index 00000000..4e1ba646 --- /dev/null +++ b/test/diff/diff_files/constant_array_size_src.spvasm @@ -0,0 +1,48 @@ +;; Tests that identical integer constants are matched when used as array size, +;; regardless of int or uint. +; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd diff --git a/test/diff/diff_files/diff_test_files_autogen.cmake b/test/diff/diff_files/diff_test_files_autogen.cmake index 9c72448a..7887f106 100644 --- a/test/diff/diff_files/diff_test_files_autogen.cmake +++ b/test/diff/diff_files/diff_test_files_autogen.cmake @@ -19,6 +19,7 @@ list(APPEND DIFF_TEST_FILES "diff_files/OpExtInst_in_dst_only_autogen.cpp" "diff_files/OpExtInst_in_src_only_autogen.cpp" "diff_files/basic_autogen.cpp" +"diff_files/constant_array_size_autogen.cpp" "diff_files/different_decorations_fragment_autogen.cpp" "diff_files/different_decorations_vertex_autogen.cpp" "diff_files/extra_if_block_autogen.cpp" @@ -31,5 +32,6 @@ list(APPEND DIFF_TEST_FILES "diff_files/reordered_if_blocks_autogen.cpp" "diff_files/reordered_switch_blocks_autogen.cpp" "diff_files/small_functions_small_diffs_autogen.cpp" +"diff_files/spec_constant_array_size_autogen.cpp" "diff_files/unrelated_shaders_autogen.cpp" ) diff --git a/test/diff/diff_files/spec_constant_array_size_autogen.cpp b/test/diff/diff_files/spec_constant_array_size_autogen.cpp new file mode 100644 index 00000000..1962d27e --- /dev/null +++ b/test/diff/diff_files/spec_constant_array_size_autogen.cpp @@ -0,0 +1,310 @@ +// GENERATED FILE - DO NOT EDIT. +// Generated by generate_tests.py +// +// Copyright (c) 2022 Google LLC. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "../diff_test_utils.h" + +#include "gtest/gtest.h" + +namespace spvtools { +namespace diff { +namespace { + +// Tests that identical specialization constants are not matched with constants +// when used as array size. +constexpr char kSrc[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd)"; +constexpr char kDst[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpDecorate %15 SpecId 4 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpSpecConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd +)"; + +TEST(DiffTest, SpecConstantArraySize) { + constexpr char kDiff[] = R"( ; SPIR-V + ; Version: 1.6 + ; Generator: Khronos SPIR-V Tools Assembler; 0 +-; Bound: 27 ++; Bound: 36 + ; Schema: 0 + OpCapability Shader + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %22 "main" %4 %19 + OpSource GLSL 450 + OpName %4 "_ua_position" + OpName %17 "gl_PerVertex" + OpMemberName %17 0 "gl_Position" + OpMemberName %17 1 "gl_PointSize" + OpMemberName %17 2 "gl_ClipDistance" + OpMemberName %17 3 "gl_CullDistance" + OpName %19 "" + OpName %22 "main" + OpDecorate %4 Location 0 ++OpDecorate %34 SpecId 4 + OpMemberDecorate %17 1 RelaxedPrecision + OpMemberDecorate %17 0 BuiltIn Position + OpMemberDecorate %17 1 BuiltIn PointSize + OpMemberDecorate %17 2 BuiltIn ClipDistance + OpMemberDecorate %17 3 BuiltIn CullDistance + OpDecorate %17 Block + %1 = OpTypeFloat 32 + %2 = OpTypeVector %1 4 + %5 = OpTypeInt 32 0 + %8 = OpTypeVector %5 4 +-%15 = OpConstant %5 8 +-%16 = OpTypeArray %1 %15 ++%34 = OpSpecConstant %5 8 ++%35 = OpTypeArray %1 %34 +-%17 = OpTypeStruct %2 %1 %16 %16 ++%17 = OpTypeStruct %2 %1 %35 %35 + %20 = OpTypeVoid + %25 = OpConstant %5 0 + %3 = OpTypePointer Input %2 + %13 = OpTypePointer Output %2 + %18 = OpTypePointer Output %17 + %21 = OpTypeFunction %20 + %4 = OpVariable %3 Input + %19 = OpVariable %18 Output + %22 = OpFunction %20 None %21 + %23 = OpLabel + %24 = OpLoad %2 %4 + %26 = OpAccessChain %13 %19 %25 + OpStore %26 %24 + OpReturn + OpFunctionEnd +)"; + Options options; + DoStringDiffTest(kSrc, kDst, kDiff, options); +} + +TEST(DiffTest, SpecConstantArraySizeNoDebug) { + constexpr char kSrcNoDebug[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd +)"; + constexpr char kDstNoDebug[] = R"(; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpDecorate %4 Location 0 +OpDecorate %15 SpecId 4 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpSpecConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd +)"; + constexpr char kDiff[] = R"( ; SPIR-V + ; Version: 1.6 + ; Generator: Khronos SPIR-V Tools Assembler; 0 +-; Bound: 27 ++; Bound: 36 + ; Schema: 0 + OpCapability Shader + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %22 "main" %4 %19 + OpSource GLSL 450 + OpDecorate %4 Location 0 ++OpDecorate %34 SpecId 4 + OpMemberDecorate %17 1 RelaxedPrecision + OpMemberDecorate %17 0 BuiltIn Position + OpMemberDecorate %17 1 BuiltIn PointSize + OpMemberDecorate %17 2 BuiltIn ClipDistance + OpMemberDecorate %17 3 BuiltIn CullDistance + OpDecorate %17 Block + %1 = OpTypeFloat 32 + %2 = OpTypeVector %1 4 + %5 = OpTypeInt 32 0 + %8 = OpTypeVector %5 4 +-%15 = OpConstant %5 8 +-%16 = OpTypeArray %1 %15 ++%34 = OpSpecConstant %5 8 ++%35 = OpTypeArray %1 %34 +-%17 = OpTypeStruct %2 %1 %16 %16 ++%17 = OpTypeStruct %2 %1 %35 %35 + %20 = OpTypeVoid + %25 = OpConstant %5 0 + %3 = OpTypePointer Input %2 + %13 = OpTypePointer Output %2 + %18 = OpTypePointer Output %17 + %21 = OpTypeFunction %20 + %4 = OpVariable %3 Input + %19 = OpVariable %18 Output + %22 = OpFunction %20 None %21 + %23 = OpLabel + %24 = OpLoad %2 %4 + %26 = OpAccessChain %13 %19 %25 + OpStore %26 %24 + OpReturn + OpFunctionEnd +)"; + Options options; + DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options); +} + +} // namespace +} // namespace diff +} // namespace spvtools diff --git a/test/diff/diff_files/spec_constant_array_size_dst.spvasm b/test/diff/diff_files/spec_constant_array_size_dst.spvasm new file mode 100644 index 00000000..7cedf083 --- /dev/null +++ b/test/diff/diff_files/spec_constant_array_size_dst.spvasm @@ -0,0 +1,47 @@ +; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpDecorate %15 SpecId 4 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpSpecConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd diff --git a/test/diff/diff_files/spec_constant_array_size_src.spvasm b/test/diff/diff_files/spec_constant_array_size_src.spvasm new file mode 100644 index 00000000..e17e04ac --- /dev/null +++ b/test/diff/diff_files/spec_constant_array_size_src.spvasm @@ -0,0 +1,48 @@ +;; Tests that identical specialization constants are not matched with constants +;; when used as array size. +; SPIR-V +; Version: 1.0 +; Generator: Google ANGLE Shader Compiler; 0 +; Bound: 27 +; Schema: 0 +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %22 "main" %4 %19 +OpSource GLSL 450 +OpName %4 "_ua_position" +OpName %17 "gl_PerVertex" +OpMemberName %17 0 "gl_Position" +OpMemberName %17 1 "gl_PointSize" +OpMemberName %17 2 "gl_ClipDistance" +OpMemberName %17 3 "gl_CullDistance" +OpName %19 "" +OpName %22 "main" +OpDecorate %4 Location 0 +OpMemberDecorate %17 1 RelaxedPrecision +OpMemberDecorate %17 0 BuiltIn Position +OpMemberDecorate %17 1 BuiltIn PointSize +OpMemberDecorate %17 2 BuiltIn ClipDistance +OpMemberDecorate %17 3 BuiltIn CullDistance +OpDecorate %17 Block +%1 = OpTypeFloat 32 +%2 = OpTypeVector %1 4 +%5 = OpTypeInt 32 0 +%8 = OpTypeVector %5 4 +%15 = OpConstant %5 8 +%16 = OpTypeArray %1 %15 +%17 = OpTypeStruct %2 %1 %16 %16 +%20 = OpTypeVoid +%25 = OpConstant %5 0 +%3 = OpTypePointer Input %2 +%13 = OpTypePointer Output %2 +%18 = OpTypePointer Output %17 +%21 = OpTypeFunction %20 +%4 = OpVariable %3 Input +%19 = OpVariable %18 Output +%22 = OpFunction %20 None %21 +%23 = OpLabel +%24 = OpLoad %2 %4 +%26 = OpAccessChain %13 %19 %25 +OpStore %26 %24 +OpReturn +OpFunctionEnd