Repository: KhronosGroup/SPIRV-Tools (language: python)

Issue:
spirv-diff reports spurious differences in ray query instructions
When applied to the files in the attached zip, `spirv-diff` produces the following output, when it should report no changes:

```
 ; SPIR-V
 ; Version: 1.6
 ; Generator: Khronos SPIR-V Tools Assembler; 0
-; Bound: 45
+; Bound: 85
 ; Schema: 0
                OpCapability RayQueryKHR
                OpCapability Shader
                OpExtension "SPV_KHR_ray_query"
                OpMemoryModel Logical GLSL450
                OpEntryPoint GLCompute %43 "main"
                OpExecutionMode %43 LocalSize 1 1 1
           %2 = OpTypeVoid
-          %3 = OpTypeAccelerationStructureKHR
-         %13 = OpTypeRayQueryKHR
+         %46 = OpTypeAccelerationStructureKHR
+         %56 = OpTypeRayQueryKHR
          %44 = OpTypeFunction %2
          %43 = OpFunction %2 None %44
          %42 = OpLabel
                OpReturn
                OpFunctionEnd
```

[ray-query.zip](https://github.com/KhronosGroup/SPIRV-Tools/files/11669293/ray-query.zip)


Discussion / hints:

Fix patch:
diff --git a/source/diff/diff.cpp b/source/diff/diff.cpp
index 1cfffa96e4..9c30900a3c 100644
--- a/source/diff/diff.cpp
+++ b/source/diff/diff.cpp
@@ -2288,7 +2288,9 @@ void Differ::MatchTypeIds() {
         case spv::Op::OpTypeVoid:
         case spv::Op::OpTypeBool:
         case spv::Op::OpTypeSampler:
-          // void, bool and sampler are unique, match them.
+        case spv::Op::OpTypeAccelerationStructureNV:
+        case spv::Op::OpTypeRayQueryKHR:
+          // the above types have no operands and are unique, match them.
           return true;
         case spv::Op::OpTypeInt:
         case spv::Op::OpTypeFloat:


Test patch:
diff --git a/test/diff/diff_files/diff_test_files_autogen.cmake b/test/diff/diff_files/diff_test_files_autogen.cmake
index 6440d0b9ca..51cb62fab0 100644
--- a/test/diff/diff_files/diff_test_files_autogen.cmake
+++ b/test/diff/diff_files/diff_test_files_autogen.cmake
@@ -36,6 +36,7 @@ list(APPEND DIFF_TEST_FILES
 "diff_files/large_functions_small_diffs_autogen.cpp"
 "diff_files/multiple_different_entry_points_autogen.cpp"
 "diff_files/multiple_same_entry_points_autogen.cpp"
+"diff_files/ray_query_types_autogen.cpp"
 "diff_files/reordered_if_blocks_autogen.cpp"
 "diff_files/reordered_switch_blocks_autogen.cpp"
 "diff_files/small_functions_small_diffs_autogen.cpp"
diff --git a/test/diff/diff_files/ray_query_types_autogen.cpp b/test/diff/diff_files/ray_query_types_autogen.cpp
new file mode 100644
index 0000000000..76546d19ba
--- /dev/null
+++ b/test/diff/diff_files/ray_query_types_autogen.cpp
@@ -0,0 +1,150 @@
+// 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 {
+
+// Test that OpTypeAccelerationStructureNV and OpTypeRayQueryKHR are
+// matched.
+constexpr char kSrc[] = R"(OpCapability RayQueryKHR
+OpCapability Shader
+OpExtension "SPV_KHR_ray_query"
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %43 "main"
+OpExecutionMode %43 LocalSize 1 1 1
+%2 = OpTypeVoid
+%3 = OpTypeAccelerationStructureNV
+%13 = OpTypeRayQueryKHR
+%44 = OpTypeFunction %2
+%43 = OpFunction  %2  None %44
+%42 = OpLabel
+OpReturn
+OpFunctionEnd)";
+constexpr char kDst[] = R"(; SPIR-V
+; Version: 1.4
+; Generator: rspirv
+; Bound: 95
+OpCapability RayQueryKHR
+OpCapability Shader
+OpExtension "SPV_KHR_ray_query"
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %43 "main"
+OpExecutionMode %43 LocalSize 1 1 1
+%2 = OpTypeVoid
+%3 = OpTypeAccelerationStructureNV
+%13 = OpTypeRayQueryKHR
+%44 = OpTypeFunction %2
+%43 = OpFunction  %2  None %44
+%42 = OpLabel
+OpReturn
+OpFunctionEnd
+)";
+
+TEST(DiffTest, RayQueryTypes) {
+  constexpr char kDiff[] = R"( ; SPIR-V
+ ; Version: 1.6
+ ; Generator: Khronos SPIR-V Tools Assembler; 0
+-; Bound: 45
++; Bound: 83
+ ; Schema: 0
+ OpCapability RayQueryKHR
+ OpCapability Shader
+ OpExtension "SPV_KHR_ray_query"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %43 "main"
+ OpExecutionMode %43 LocalSize 1 1 1
+ %2 = OpTypeVoid
+ %3 = OpTypeAccelerationStructureKHR
+ %13 = OpTypeRayQueryKHR
+ %44 = OpTypeFunction %2
+ %43 = OpFunction %2 None %44
+ %42 = OpLabel
+ OpReturn
+ OpFunctionEnd
+)";
+  Options options;
+  DoStringDiffTest(kSrc, kDst, kDiff, options);
+}
+
+TEST(DiffTest, RayQueryTypesNoDebug) {
+  constexpr char kSrcNoDebug[] = R"(OpCapability RayQueryKHR
+OpCapability Shader
+OpExtension "SPV_KHR_ray_query"
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %43 "main"
+OpExecutionMode %43 LocalSize 1 1 1
+%2 = OpTypeVoid
+%3 = OpTypeAccelerationStructureNV
+%13 = OpTypeRayQueryKHR
+%44 = OpTypeFunction %2
+%43 = OpFunction  %2  None %44
+%42 = OpLabel
+OpReturn
+OpFunctionEnd
+)";
+  constexpr char kDstNoDebug[] = R"(; SPIR-V
+; Version: 1.4
+; Generator: rspirv
+; Bound: 95
+OpCapability RayQueryKHR
+OpCapability Shader
+OpExtension "SPV_KHR_ray_query"
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %43 "main"
+OpExecutionMode %43 LocalSize 1 1 1
+%2 = OpTypeVoid
+%3 = OpTypeAccelerationStructureNV
+%13 = OpTypeRayQueryKHR
+%44 = OpTypeFunction %2
+%43 = OpFunction  %2  None %44
+%42 = OpLabel
+OpReturn
+OpFunctionEnd
+)";
+  constexpr char kDiff[] = R"( ; SPIR-V
+ ; Version: 1.6
+ ; Generator: Khronos SPIR-V Tools Assembler; 0
+-; Bound: 45
++; Bound: 83
+ ; Schema: 0
+ OpCapability RayQueryKHR
+ OpCapability Shader
+ OpExtension "SPV_KHR_ray_query"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %43 "main"
+ OpExecutionMode %43 LocalSize 1 1 1
+ %2 = OpTypeVoid
+ %3 = OpTypeAccelerationStructureKHR
+ %13 = OpTypeRayQueryKHR
+ %44 = OpTypeFunction %2
+ %43 = OpFunction %2 None %44
+ %42 = OpLabel
+ OpReturn
+ OpFunctionEnd
+)";
+  Options options;
+  DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options);
+}
+
+}  // namespace
+}  // namespace diff
+}  // namespace spvtools
diff --git a/test/diff/diff_files/ray_query_types_dst.spvasm b/test/diff/diff_files/ray_query_types_dst.spvasm
new file mode 100644
index 0000000000..5f8be53d44
--- /dev/null
+++ b/test/diff/diff_files/ray_query_types_dst.spvasm
@@ -0,0 +1,18 @@
+; SPIR-V
+; Version: 1.4
+; Generator: rspirv
+; Bound: 95
+OpCapability RayQueryKHR
+OpCapability Shader
+OpExtension "SPV_KHR_ray_query"
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %43 "main"
+OpExecutionMode %43 LocalSize 1 1 1
+%2 = OpTypeVoid
+%3 = OpTypeAccelerationStructureNV
+%13 = OpTypeRayQueryKHR
+%44 = OpTypeFunction %2
+%43 = OpFunction  %2  None %44
+%42 = OpLabel
+OpReturn
+OpFunctionEnd
diff --git a/test/diff/diff_files/ray_query_types_src.spvasm b/test/diff/diff_files/ray_query_types_src.spvasm
new file mode 100644
index 0000000000..0b64015b56
--- /dev/null
+++ b/test/diff/diff_files/ray_query_types_src.spvasm
@@ -0,0 +1,16 @@
+;; Test that OpTypeAccelerationStructureNV and OpTypeRayQueryKHR are
+;; matched.
+OpCapability RayQueryKHR
+OpCapability Shader
+OpExtension "SPV_KHR_ray_query"
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %43 "main"
+OpExecutionMode %43 LocalSize 1 1 1
+%2 = OpTypeVoid
+%3 = OpTypeAccelerationStructureNV
+%13 = OpTypeRayQueryKHR
+%44 = OpTypeFunction %2
+%43 = OpFunction  %2  None %44
+%42 = OpLabel
+OpReturn
+OpFunctionEnd