2
0
Бранимир Караџић 1 жил өмнө
parent
commit
aace41236f
22 өөрчлөгдсөн 155 нэмэгдсэн , 1599 устгасан
  1. 1 1
      3rdparty/spirv-tools/include/generated/build-version.inc
  2. 1 1
      3rdparty/spirv-tools/include/generated/nonsemantic.vkspreflection.insts.inc
  3. 1 8
      3rdparty/spirv-tools/include/spirv-tools/instrument.hpp
  4. 4 0
      3rdparty/spirv-tools/include/spirv-tools/libspirv.h
  5. 8 7
      3rdparty/spirv-tools/include/spirv-tools/libspirv.hpp
  6. 10 9
      3rdparty/spirv-tools/include/spirv-tools/linker.hpp
  7. 2 2
      3rdparty/spirv-tools/include/spirv-tools/linter.hpp
  8. 3 50
      3rdparty/spirv-tools/include/spirv-tools/optimizer.hpp
  9. 0 128
      3rdparty/spirv-tools/source/opt/folding_rules.cpp
  10. 0 761
      3rdparty/spirv-tools/source/opt/inst_bindless_check_pass.cpp
  11. 0 130
      3rdparty/spirv-tools/source/opt/inst_bindless_check_pass.h
  12. 0 331
      3rdparty/spirv-tools/source/opt/inst_buff_addr_check_pass.cpp
  13. 0 130
      3rdparty/spirv-tools/source/opt/inst_buff_addr_check_pass.h
  14. 0 20
      3rdparty/spirv-tools/source/opt/optimizer.cpp
  15. 0 2
      3rdparty/spirv-tools/source/opt/passes.h
  16. 2 1
      3rdparty/spirv-tools/source/opt/trim_capabilities_pass.h
  17. 18 1
      3rdparty/spirv-tools/source/val/validate_decorations.cpp
  18. 63 12
      3rdparty/spirv-tools/source/val/validate_image.cpp
  19. 22 0
      3rdparty/spirv-tools/source/val/validate_interfaces.cpp
  20. 2 1
      3rdparty/spirv-tools/source/val/validate_memory.cpp
  21. 16 4
      3rdparty/spirv-tools/source/val/validate_misc.cpp
  22. 2 0
      3rdparty/spirv-tools/source/val/validation_state.cpp

+ 1 - 1
3rdparty/spirv-tools/include/generated/build-version.inc

@@ -1 +1 @@
-"v2024.1", "SPIRV-Tools v2024.1 v2024.1-24-g37e8c915"
+"v2024.2", "SPIRV-Tools v2024.2 v2024.2.rc1-12-g1e0a7201"

+ 1 - 1
3rdparty/spirv-tools/include/generated/nonsemantic.vkspreflection.insts.inc

@@ -1,7 +1,7 @@
 
 
 static const spv_ext_inst_desc_t nonsemantic_vkspreflection_entries[] = {
-  {"Configuration", 1, 0, nullptr, {SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_NONE}},
+  {"Configuration", 1, 0, nullptr, {SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_NONE}},
   {"StartCounter", 2, 0, nullptr, {SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_NONE}},
   {"StopCounter", 3, 0, nullptr, {SPV_OPERAND_TYPE_ID, SPV_OPERAND_TYPE_NONE}},
   {"PushConstants", 4, 0, nullptr, {SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_NONE}},

+ 1 - 8
3rdparty/spirv-tools/include/spirv-tools/instrument.hpp

@@ -22,8 +22,6 @@
 // This file provides an external interface for applications that wish to
 // communicate with shaders instrumented by passes created by:
 //
-//   CreateInstBindlessCheckPass
-//   CreateInstBuffAddrCheckPass
 //   CreateInstDebugPrintfPass
 //
 // More detailed documentation of these routines can be found in optimizer.hpp
@@ -34,17 +32,12 @@ namespace spvtools {
 //
 // The following values provide offsets into the output buffer struct
 // generated by InstrumentPass::GenDebugStreamWrite. This method is utilized
-// by InstBindlessCheckPass, InstBuffAddrCheckPass, and InstDebugPrintfPass.
+// by InstDebugPrintfPass.
 //
 // The 1st member of the debug output buffer contains a set of flags
 // controlling the behavior of instrumentation code.
 static const int kDebugOutputFlagsOffset = 0;
 
-// Values stored at kDebugOutputFlagsOffset
-enum kInstFlags : unsigned int {
-  kInstBufferOOBEnable = 0x1,
-};
-
 // The 2nd member of the debug output buffer contains the next available word
 // in the data stream to be written. Shaders will atomically read and update
 // this value so as not to overwrite each others records. This value must be

+ 4 - 0
3rdparty/spirv-tools/include/spirv-tools/libspirv.h

@@ -33,15 +33,19 @@ extern "C" {
 #else
 #define SPIRV_TOOLS_EXPORT __declspec(dllimport)
 #endif
+#define SPIRV_TOOLS_LOCAL
 #else
 #if defined(SPIRV_TOOLS_IMPLEMENTATION)
 #define SPIRV_TOOLS_EXPORT __attribute__((visibility("default")))
+#define SPIRV_TOOLS_LOCAL __attribute__((visibility("hidden")))
 #else
 #define SPIRV_TOOLS_EXPORT
+#define SPIRV_TOOLS_LOCAL
 #endif
 #endif
 #else
 #define SPIRV_TOOLS_EXPORT
+#define SPIRV_TOOLS_LOCAL
 #endif
 
 // Helpers

+ 8 - 7
3rdparty/spirv-tools/include/spirv-tools/libspirv.hpp

@@ -37,7 +37,7 @@ using InstructionParser =
     std::function<spv_result_t(const spv_parsed_instruction_t& instruction)>;
 
 // C++ RAII wrapper around the C context object spv_context.
-class Context {
+class SPIRV_TOOLS_EXPORT Context {
  public:
   // Constructs a context targeting the given environment |env|.
   //
@@ -73,7 +73,7 @@ class Context {
 };
 
 // A RAII wrapper around a validator options object.
-class ValidatorOptions {
+class SPIRV_TOOLS_EXPORT ValidatorOptions {
  public:
   ValidatorOptions() : options_(spvValidatorOptionsCreate()) {}
   ~ValidatorOptions() { spvValidatorOptionsDestroy(options_); }
@@ -163,7 +163,7 @@ class ValidatorOptions {
 };
 
 // A C++ wrapper around an optimization options object.
-class OptimizerOptions {
+class SPIRV_TOOLS_EXPORT OptimizerOptions {
  public:
   OptimizerOptions() : options_(spvOptimizerOptionsCreate()) {}
   ~OptimizerOptions() { spvOptimizerOptionsDestroy(options_); }
@@ -205,7 +205,7 @@ class OptimizerOptions {
 };
 
 // A C++ wrapper around a reducer options object.
-class ReducerOptions {
+class SPIRV_TOOLS_EXPORT ReducerOptions {
  public:
   ReducerOptions() : options_(spvReducerOptionsCreate()) {}
   ~ReducerOptions() { spvReducerOptionsDestroy(options_); }
@@ -236,7 +236,7 @@ class ReducerOptions {
 };
 
 // A C++ wrapper around a fuzzer options object.
-class FuzzerOptions {
+class SPIRV_TOOLS_EXPORT FuzzerOptions {
  public:
   FuzzerOptions() : options_(spvFuzzerOptionsCreate()) {}
   ~FuzzerOptions() { spvFuzzerOptionsDestroy(options_); }
@@ -283,7 +283,7 @@ class FuzzerOptions {
 // provides methods for assembling, disassembling, and validating.
 //
 // Instances of this class provide basic thread-safety guarantee.
-class SpirvTools {
+class SPIRV_TOOLS_EXPORT SpirvTools {
  public:
   enum {
     // Default assembling option used by assemble():
@@ -388,7 +388,8 @@ class SpirvTools {
   bool IsValid() const;
 
  private:
-  struct Impl;  // Opaque struct for holding the data fields used by this class.
+  struct SPIRV_TOOLS_LOCAL
+      Impl;  // Opaque struct for holding the data fields used by this class.
   std::unique_ptr<Impl> impl_;  // Unique pointer to implementation data.
 };
 

+ 10 - 9
3rdparty/spirv-tools/include/spirv-tools/linker.hpp

@@ -24,7 +24,7 @@
 
 namespace spvtools {
 
-class LinkerOptions {
+class SPIRV_TOOLS_EXPORT LinkerOptions {
  public:
   // Returns whether a library or an executable should be produced by the
   // linking phase.
@@ -84,14 +84,15 @@ class LinkerOptions {
 // * Some entry points were defined multiple times;
 // * Some imported symbols did not have an exported counterpart;
 // * Possibly other reasons.
-spv_result_t Link(const Context& context,
-                  const std::vector<std::vector<uint32_t>>& binaries,
-                  std::vector<uint32_t>* linked_binary,
-                  const LinkerOptions& options = LinkerOptions());
-spv_result_t Link(const Context& context, const uint32_t* const* binaries,
-                  const size_t* binary_sizes, size_t num_binaries,
-                  std::vector<uint32_t>* linked_binary,
-                  const LinkerOptions& options = LinkerOptions());
+SPIRV_TOOLS_EXPORT spv_result_t
+Link(const Context& context, const std::vector<std::vector<uint32_t>>& binaries,
+     std::vector<uint32_t>* linked_binary,
+     const LinkerOptions& options = LinkerOptions());
+SPIRV_TOOLS_EXPORT spv_result_t
+Link(const Context& context, const uint32_t* const* binaries,
+     const size_t* binary_sizes, size_t num_binaries,
+     std::vector<uint32_t>* linked_binary,
+     const LinkerOptions& options = LinkerOptions());
 
 }  // namespace spvtools
 

+ 2 - 2
3rdparty/spirv-tools/include/spirv-tools/linter.hpp

@@ -24,7 +24,7 @@ namespace spvtools {
 // provides a method for linting.
 //
 // Instances of this class provides basic thread-safety guarantee.
-class Linter {
+class SPIRV_TOOLS_EXPORT Linter {
  public:
   explicit Linter(spv_target_env env);
 
@@ -40,7 +40,7 @@ class Linter {
   bool Run(const uint32_t* binary, size_t binary_size);
 
  private:
-  struct Impl;
+  struct SPIRV_TOOLS_LOCAL Impl;
   std::unique_ptr<Impl> impl_;
 };
 }  // namespace spvtools

+ 3 - 50
3rdparty/spirv-tools/include/spirv-tools/optimizer.hpp

@@ -37,14 +37,14 @@ struct DescriptorSetAndBinding;
 // provides methods for registering optimization passes and optimizing.
 //
 // Instances of this class provides basic thread-safety guarantee.
-class Optimizer {
+class SPIRV_TOOLS_EXPORT Optimizer {
  public:
   // The token for an optimization pass. It is returned via one of the
   // Create*Pass() standalone functions at the end of this header file and
   // consumed by the RegisterPass() method. Tokens are one-time objects that
   // only support move; copying is not allowed.
   struct PassToken {
-    struct Impl;  // Opaque struct for holding internal data.
+    struct SPIRV_TOOLS_LOCAL Impl;  // Opaque struct for holding internal data.
 
     PassToken(std::unique_ptr<Impl>);
 
@@ -239,7 +239,7 @@ class Optimizer {
   Optimizer& SetValidateAfterAll(bool validate);
 
  private:
-  struct Impl;                  // Opaque struct for holding internal data.
+  struct SPIRV_TOOLS_LOCAL Impl;  // Opaque struct for holding internal data.
   std::unique_ptr<Impl> impl_;  // Unique pointer to internal data.
 };
 
@@ -747,53 +747,6 @@ Optimizer::PassToken CreateReduceLoadSizePass(
 // them into a single instruction where possible.
 Optimizer::PassToken CreateCombineAccessChainsPass();
 
-// Create a pass to instrument bindless descriptor checking
-// This pass instruments all bindless references to check that descriptor
-// array indices are inbounds, and if the descriptor indexing extension is
-// enabled, that the descriptor has been initialized. If the reference is
-// invalid, a record is written to the debug output buffer (if space allows)
-// and a null value is returned. This pass is designed to support bindless
-// validation in the Vulkan validation layers.
-//
-// TODO(greg-lunarg): Add support for buffer references. Currently only does
-// checking for image references.
-//
-// Dead code elimination should be run after this pass as the original,
-// potentially invalid code is not removed and could cause undefined behavior,
-// including crashes. It may also be beneficial to run Simplification
-// (ie Constant Propagation), DeadBranchElim and BlockMerge after this pass to
-// optimize instrument code involving the testing of compile-time constants.
-// It is also generally recommended that this pass (and all
-// instrumentation passes) be run after any legalization and optimization
-// passes. This will give better analysis for the instrumentation and avoid
-// potentially de-optimizing the instrument code, for example, inlining
-// the debug record output function throughout the module.
-//
-// The instrumentation will write |shader_id| in each output record
-// to identify the shader module which generated the record.
-Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t shader_id);
-
-// Create a pass to instrument physical buffer address checking
-// This pass instruments all physical buffer address references to check that
-// all referenced bytes fall in a valid buffer. If the reference is
-// invalid, a record is written to the debug output buffer (if space allows)
-// and a null value is returned. This pass is designed to support buffer
-// address validation in the Vulkan validation layers.
-//
-// Dead code elimination should be run after this pass as the original,
-// potentially invalid code is not removed and could cause undefined behavior,
-// including crashes. Instruction simplification would likely also be
-// beneficial. It is also generally recommended that this pass (and all
-// instrumentation passes) be run after any legalization and optimization
-// passes. This will give better analysis for the instrumentation and avoid
-// potentially de-optimizing the instrument code, for example, inlining
-// the debug record output function throughout the module.
-//
-// The instrumentation will read and write buffers in debug
-// descriptor set |desc_set|. It will write |shader_id| in each output record
-// to identify the shader module which generated the record.
-Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t shader_id);
-
 // Create a pass to instrument OpDebugPrintf instructions.
 // This pass replaces all OpDebugPrintf instructions with instructions to write
 // a record containing the string id and the all specified values into a special

+ 0 - 128
3rdparty/spirv-tools/source/opt/folding_rules.cpp

@@ -1459,132 +1459,6 @@ FoldingRule FactorAddMuls() {
   };
 }
 
-// Replaces |inst| inplace with an FMA instruction |(x*y)+a|.
-void ReplaceWithFma(Instruction* inst, uint32_t x, uint32_t y, uint32_t a) {
-  uint32_t ext =
-      inst->context()->get_feature_mgr()->GetExtInstImportId_GLSLstd450();
-
-  if (ext == 0) {
-    inst->context()->AddExtInstImport("GLSL.std.450");
-    ext = inst->context()->get_feature_mgr()->GetExtInstImportId_GLSLstd450();
-    assert(ext != 0 &&
-           "Could not add the GLSL.std.450 extended instruction set");
-  }
-
-  std::vector<Operand> operands;
-  operands.push_back({SPV_OPERAND_TYPE_ID, {ext}});
-  operands.push_back({SPV_OPERAND_TYPE_LITERAL_INTEGER, {GLSLstd450Fma}});
-  operands.push_back({SPV_OPERAND_TYPE_ID, {x}});
-  operands.push_back({SPV_OPERAND_TYPE_ID, {y}});
-  operands.push_back({SPV_OPERAND_TYPE_ID, {a}});
-
-  inst->SetOpcode(spv::Op::OpExtInst);
-  inst->SetInOperands(std::move(operands));
-}
-
-// Folds a multiple and add into an Fma.
-//
-// Cases:
-// (x * y) + a = Fma x y a
-// a + (x * y) = Fma x y a
-bool MergeMulAddArithmetic(IRContext* context, Instruction* inst,
-                           const std::vector<const analysis::Constant*>&) {
-  assert(inst->opcode() == spv::Op::OpFAdd);
-
-  if (!inst->IsFloatingPointFoldingAllowed()) {
-    return false;
-  }
-
-  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
-  for (int i = 0; i < 2; i++) {
-    uint32_t op_id = inst->GetSingleWordInOperand(i);
-    Instruction* op_inst = def_use_mgr->GetDef(op_id);
-
-    if (op_inst->opcode() != spv::Op::OpFMul) {
-      continue;
-    }
-
-    if (!op_inst->IsFloatingPointFoldingAllowed()) {
-      continue;
-    }
-
-    uint32_t x = op_inst->GetSingleWordInOperand(0);
-    uint32_t y = op_inst->GetSingleWordInOperand(1);
-    uint32_t a = inst->GetSingleWordInOperand((i + 1) % 2);
-    ReplaceWithFma(inst, x, y, a);
-    return true;
-  }
-  return false;
-}
-
-// Replaces |sub| inplace with an FMA instruction |(x*y)+a| where |a| first gets
-// negated if |negate_addition| is true, otherwise |x| gets negated.
-void ReplaceWithFmaAndNegate(Instruction* sub, uint32_t x, uint32_t y,
-                             uint32_t a, bool negate_addition) {
-  uint32_t ext =
-      sub->context()->get_feature_mgr()->GetExtInstImportId_GLSLstd450();
-
-  if (ext == 0) {
-    sub->context()->AddExtInstImport("GLSL.std.450");
-    ext = sub->context()->get_feature_mgr()->GetExtInstImportId_GLSLstd450();
-    assert(ext != 0 &&
-           "Could not add the GLSL.std.450 extended instruction set");
-  }
-
-  InstructionBuilder ir_builder(
-      sub->context(), sub,
-      IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
-
-  Instruction* neg = ir_builder.AddUnaryOp(sub->type_id(), spv::Op::OpFNegate,
-                                           negate_addition ? a : x);
-  uint32_t neg_op = neg->result_id();  // -a : -x
-
-  std::vector<Operand> operands;
-  operands.push_back({SPV_OPERAND_TYPE_ID, {ext}});
-  operands.push_back({SPV_OPERAND_TYPE_LITERAL_INTEGER, {GLSLstd450Fma}});
-  operands.push_back({SPV_OPERAND_TYPE_ID, {negate_addition ? x : neg_op}});
-  operands.push_back({SPV_OPERAND_TYPE_ID, {y}});
-  operands.push_back({SPV_OPERAND_TYPE_ID, {negate_addition ? neg_op : a}});
-
-  sub->SetOpcode(spv::Op::OpExtInst);
-  sub->SetInOperands(std::move(operands));
-}
-
-// Folds a multiply and subtract into an Fma and negation.
-//
-// Cases:
-// (x * y) - a = Fma x y -a
-// a - (x * y) = Fma -x y a
-bool MergeMulSubArithmetic(IRContext* context, Instruction* sub,
-                           const std::vector<const analysis::Constant*>&) {
-  assert(sub->opcode() == spv::Op::OpFSub);
-
-  if (!sub->IsFloatingPointFoldingAllowed()) {
-    return false;
-  }
-
-  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
-  for (int i = 0; i < 2; i++) {
-    uint32_t op_id = sub->GetSingleWordInOperand(i);
-    Instruction* mul = def_use_mgr->GetDef(op_id);
-
-    if (mul->opcode() != spv::Op::OpFMul) {
-      continue;
-    }
-
-    if (!mul->IsFloatingPointFoldingAllowed()) {
-      continue;
-    }
-
-    uint32_t x = mul->GetSingleWordInOperand(0);
-    uint32_t y = mul->GetSingleWordInOperand(1);
-    uint32_t a = sub->GetSingleWordInOperand((i + 1) % 2);
-    ReplaceWithFmaAndNegate(sub, x, y, a, i == 0);
-    return true;
-  }
-  return false;
-}
-
 FoldingRule IntMultipleBy1() {
   return [](IRContext*, Instruction* inst,
             const std::vector<const analysis::Constant*>& constants) {
@@ -2941,7 +2815,6 @@ void FoldingRules::AddFoldingRules() {
   rules_[spv::Op::OpFAdd].push_back(MergeAddSubArithmetic());
   rules_[spv::Op::OpFAdd].push_back(MergeGenericAddSubArithmetic());
   rules_[spv::Op::OpFAdd].push_back(FactorAddMuls());
-  rules_[spv::Op::OpFAdd].push_back(MergeMulAddArithmetic);
 
   rules_[spv::Op::OpFDiv].push_back(RedundantFDiv());
   rules_[spv::Op::OpFDiv].push_back(ReciprocalFDiv());
@@ -2962,7 +2835,6 @@ void FoldingRules::AddFoldingRules() {
   rules_[spv::Op::OpFSub].push_back(MergeSubNegateArithmetic());
   rules_[spv::Op::OpFSub].push_back(MergeSubAddArithmetic());
   rules_[spv::Op::OpFSub].push_back(MergeSubSubArithmetic());
-  rules_[spv::Op::OpFSub].push_back(MergeMulSubArithmetic);
 
   rules_[spv::Op::OpIAdd].push_back(RedundantIAdd());
   rules_[spv::Op::OpIAdd].push_back(MergeAddNegateArithmetic());

+ 0 - 761
3rdparty/spirv-tools/source/opt/inst_bindless_check_pass.cpp

@@ -1,761 +0,0 @@
-// Copyright (c) 2018 The Khronos Group Inc.
-// Copyright (c) 2018 Valve Corporation
-// Copyright (c) 2018 LunarG Inc.
-//
-// 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 "inst_bindless_check_pass.h"
-
-#include "source/spirv_constant.h"
-
-namespace spvtools {
-namespace opt {
-namespace {
-// Input Operand Indices
-constexpr int kSpvImageSampleImageIdInIdx = 0;
-constexpr int kSpvSampledImageImageIdInIdx = 0;
-constexpr int kSpvSampledImageSamplerIdInIdx = 1;
-constexpr int kSpvImageSampledImageIdInIdx = 0;
-constexpr int kSpvCopyObjectOperandIdInIdx = 0;
-constexpr int kSpvLoadPtrIdInIdx = 0;
-constexpr int kSpvAccessChainBaseIdInIdx = 0;
-constexpr int kSpvAccessChainIndex0IdInIdx = 1;
-constexpr int kSpvTypeArrayTypeIdInIdx = 0;
-constexpr int kSpvVariableStorageClassInIdx = 0;
-constexpr int kSpvTypePtrTypeIdInIdx = 1;
-constexpr int kSpvTypeImageDim = 1;
-constexpr int kSpvTypeImageDepth = 2;
-constexpr int kSpvTypeImageArrayed = 3;
-constexpr int kSpvTypeImageMS = 4;
-}  // namespace
-
-// This is a stub function for use with Import linkage
-// clang-format off
-// GLSL:
-//bool inst_bindless_check_desc(const uint shader_id, const uint inst_num, const uvec4 stage_info, const uint desc_set,
-//                              const uint binding, const uint desc_index, const uint byte_offset) {
-//}
-// clang-format on
-uint32_t InstBindlessCheckPass::GenDescCheckFunctionId() {
-  enum {
-    kShaderId = 0,
-    kInstructionIndex = 1,
-    kStageInfo = 2,
-    kDescSet = 3,
-    kDescBinding = 4,
-    kDescIndex = 5,
-    kByteOffset = 6,
-    kNumArgs
-  };
-  if (check_desc_func_id_ != 0) {
-    return check_desc_func_id_;
-  }
-
-  analysis::TypeManager* type_mgr = context()->get_type_mgr();
-  const analysis::Integer* uint_type = GetInteger(32, false);
-  const analysis::Vector v4uint(uint_type, 4);
-  const analysis::Type* v4uint_type = type_mgr->GetRegisteredType(&v4uint);
-  std::vector<const analysis::Type*> param_types(kNumArgs, uint_type);
-  param_types[2] = v4uint_type;
-
-  const uint32_t func_id = TakeNextId();
-  std::unique_ptr<Function> func =
-      StartFunction(func_id, type_mgr->GetBoolType(), param_types);
-
-  func->SetFunctionEnd(EndFunction());
-
-  static const std::string func_name{"inst_bindless_check_desc"};
-  context()->AddFunctionDeclaration(std::move(func));
-  context()->AddDebug2Inst(NewName(func_id, func_name));
-  std::vector<Operand> operands{
-      {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {func_id}},
-      {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER,
-       {uint32_t(spv::Decoration::LinkageAttributes)}},
-      {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_STRING,
-       utils::MakeVector(func_name.c_str())},
-      {spv_operand_type_t::SPV_OPERAND_TYPE_LINKAGE_TYPE,
-       {uint32_t(spv::LinkageType::Import)}},
-  };
-  get_decoration_mgr()->AddDecoration(spv::Op::OpDecorate, operands);
-
-  check_desc_func_id_ = func_id;
-  // Make sure function doesn't get processed by
-  // InstrumentPass::InstProcessCallTreeFromRoots()
-  param2output_func_id_[3] = func_id;
-  return check_desc_func_id_;
-}
-
-// clang-format off
-// GLSL:
-// result = inst_bindless_check_desc(shader_id, inst_idx, stage_info, desc_set, binding, desc_idx, offset);
-//
-// clang-format on
-uint32_t InstBindlessCheckPass::GenDescCheckCall(
-    uint32_t inst_idx, uint32_t stage_idx, uint32_t var_id,
-    uint32_t desc_idx_id, uint32_t offset_id, InstructionBuilder* builder) {
-  const uint32_t func_id = GenDescCheckFunctionId();
-  const std::vector<uint32_t> args = {
-      builder->GetUintConstantId(shader_id_),
-      builder->GetUintConstantId(inst_idx),
-      GenStageInfo(stage_idx, builder),
-      builder->GetUintConstantId(var2desc_set_[var_id]),
-      builder->GetUintConstantId(var2binding_[var_id]),
-      GenUintCastCode(desc_idx_id, builder),
-      offset_id};
-  return GenReadFunctionCall(GetBoolId(), func_id, args, builder);
-}
-
-uint32_t InstBindlessCheckPass::CloneOriginalImage(
-    uint32_t old_image_id, InstructionBuilder* builder) {
-  Instruction* new_image_inst;
-  Instruction* old_image_inst = get_def_use_mgr()->GetDef(old_image_id);
-  if (old_image_inst->opcode() == spv::Op::OpLoad) {
-    new_image_inst = builder->AddLoad(
-        old_image_inst->type_id(),
-        old_image_inst->GetSingleWordInOperand(kSpvLoadPtrIdInIdx));
-  } else if (old_image_inst->opcode() == spv::Op::OpSampledImage) {
-    uint32_t clone_id = CloneOriginalImage(
-        old_image_inst->GetSingleWordInOperand(kSpvSampledImageImageIdInIdx),
-        builder);
-    new_image_inst = builder->AddBinaryOp(
-        old_image_inst->type_id(), spv::Op::OpSampledImage, clone_id,
-        old_image_inst->GetSingleWordInOperand(kSpvSampledImageSamplerIdInIdx));
-  } else if (old_image_inst->opcode() == spv::Op::OpImage) {
-    uint32_t clone_id = CloneOriginalImage(
-        old_image_inst->GetSingleWordInOperand(kSpvImageSampledImageIdInIdx),
-        builder);
-    new_image_inst = builder->AddUnaryOp(old_image_inst->type_id(),
-                                         spv::Op::OpImage, clone_id);
-  } else {
-    assert(old_image_inst->opcode() == spv::Op::OpCopyObject &&
-           "expecting OpCopyObject");
-    uint32_t clone_id = CloneOriginalImage(
-        old_image_inst->GetSingleWordInOperand(kSpvCopyObjectOperandIdInIdx),
-        builder);
-    // Since we are cloning, no need to create new copy
-    new_image_inst = get_def_use_mgr()->GetDef(clone_id);
-  }
-  uid2offset_[new_image_inst->unique_id()] =
-      uid2offset_[old_image_inst->unique_id()];
-  uint32_t new_image_id = new_image_inst->result_id();
-  get_decoration_mgr()->CloneDecorations(old_image_id, new_image_id);
-  return new_image_id;
-}
-
-uint32_t InstBindlessCheckPass::CloneOriginalReference(
-    RefAnalysis* ref, InstructionBuilder* builder) {
-  // If original is image based, start by cloning descriptor load
-  uint32_t new_image_id = 0;
-  if (ref->desc_load_id != 0) {
-    uint32_t old_image_id =
-        ref->ref_inst->GetSingleWordInOperand(kSpvImageSampleImageIdInIdx);
-    new_image_id = CloneOriginalImage(old_image_id, builder);
-  }
-  // Clone original reference
-  std::unique_ptr<Instruction> new_ref_inst(ref->ref_inst->Clone(context()));
-  uint32_t ref_result_id = ref->ref_inst->result_id();
-  uint32_t new_ref_id = 0;
-  if (ref_result_id != 0) {
-    new_ref_id = TakeNextId();
-    new_ref_inst->SetResultId(new_ref_id);
-  }
-  // Update new ref with new image if created
-  if (new_image_id != 0)
-    new_ref_inst->SetInOperand(kSpvImageSampleImageIdInIdx, {new_image_id});
-  // Register new reference and add to new block
-  Instruction* added_inst = builder->AddInstruction(std::move(new_ref_inst));
-  uid2offset_[added_inst->unique_id()] =
-      uid2offset_[ref->ref_inst->unique_id()];
-  if (new_ref_id != 0)
-    get_decoration_mgr()->CloneDecorations(ref_result_id, new_ref_id);
-  return new_ref_id;
-}
-
-uint32_t InstBindlessCheckPass::GetImageId(Instruction* inst) {
-  switch (inst->opcode()) {
-    case spv::Op::OpImageSampleImplicitLod:
-    case spv::Op::OpImageSampleExplicitLod:
-    case spv::Op::OpImageSampleDrefImplicitLod:
-    case spv::Op::OpImageSampleDrefExplicitLod:
-    case spv::Op::OpImageSampleProjImplicitLod:
-    case spv::Op::OpImageSampleProjExplicitLod:
-    case spv::Op::OpImageSampleProjDrefImplicitLod:
-    case spv::Op::OpImageSampleProjDrefExplicitLod:
-    case spv::Op::OpImageGather:
-    case spv::Op::OpImageDrefGather:
-    case spv::Op::OpImageQueryLod:
-    case spv::Op::OpImageSparseSampleImplicitLod:
-    case spv::Op::OpImageSparseSampleExplicitLod:
-    case spv::Op::OpImageSparseSampleDrefImplicitLod:
-    case spv::Op::OpImageSparseSampleDrefExplicitLod:
-    case spv::Op::OpImageSparseSampleProjImplicitLod:
-    case spv::Op::OpImageSparseSampleProjExplicitLod:
-    case spv::Op::OpImageSparseSampleProjDrefImplicitLod:
-    case spv::Op::OpImageSparseSampleProjDrefExplicitLod:
-    case spv::Op::OpImageSparseGather:
-    case spv::Op::OpImageSparseDrefGather:
-    case spv::Op::OpImageFetch:
-    case spv::Op::OpImageRead:
-    case spv::Op::OpImageQueryFormat:
-    case spv::Op::OpImageQueryOrder:
-    case spv::Op::OpImageQuerySizeLod:
-    case spv::Op::OpImageQuerySize:
-    case spv::Op::OpImageQueryLevels:
-    case spv::Op::OpImageQuerySamples:
-    case spv::Op::OpImageSparseFetch:
-    case spv::Op::OpImageSparseRead:
-    case spv::Op::OpImageWrite:
-      return inst->GetSingleWordInOperand(kSpvImageSampleImageIdInIdx);
-    default:
-      break;
-  }
-  return 0;
-}
-
-Instruction* InstBindlessCheckPass::GetPointeeTypeInst(Instruction* ptr_inst) {
-  uint32_t pte_ty_id = GetPointeeTypeId(ptr_inst);
-  return get_def_use_mgr()->GetDef(pte_ty_id);
-}
-
-bool InstBindlessCheckPass::AnalyzeDescriptorReference(Instruction* ref_inst,
-                                                       RefAnalysis* ref) {
-  ref->ref_inst = ref_inst;
-  if (ref_inst->opcode() == spv::Op::OpLoad ||
-      ref_inst->opcode() == spv::Op::OpStore) {
-    ref->desc_load_id = 0;
-    ref->ptr_id = ref_inst->GetSingleWordInOperand(kSpvLoadPtrIdInIdx);
-    Instruction* ptr_inst = get_def_use_mgr()->GetDef(ref->ptr_id);
-    if (ptr_inst->opcode() != spv::Op::OpAccessChain) return false;
-    ref->var_id = ptr_inst->GetSingleWordInOperand(kSpvAccessChainBaseIdInIdx);
-    Instruction* var_inst = get_def_use_mgr()->GetDef(ref->var_id);
-    if (var_inst->opcode() != spv::Op::OpVariable) return false;
-    spv::StorageClass storage_class = spv::StorageClass(
-        var_inst->GetSingleWordInOperand(kSpvVariableStorageClassInIdx));
-    switch (storage_class) {
-      case spv::StorageClass::Uniform:
-      case spv::StorageClass::StorageBuffer:
-        break;
-      default:
-        return false;
-        break;
-    }
-    // Check for deprecated storage block form
-    if (storage_class == spv::StorageClass::Uniform) {
-      uint32_t var_ty_id = var_inst->type_id();
-      Instruction* var_ty_inst = get_def_use_mgr()->GetDef(var_ty_id);
-      uint32_t ptr_ty_id =
-          var_ty_inst->GetSingleWordInOperand(kSpvTypePtrTypeIdInIdx);
-      Instruction* ptr_ty_inst = get_def_use_mgr()->GetDef(ptr_ty_id);
-      spv::Op ptr_ty_op = ptr_ty_inst->opcode();
-      uint32_t block_ty_id =
-          (ptr_ty_op == spv::Op::OpTypeArray ||
-           ptr_ty_op == spv::Op::OpTypeRuntimeArray)
-              ? ptr_ty_inst->GetSingleWordInOperand(kSpvTypeArrayTypeIdInIdx)
-              : ptr_ty_id;
-      assert(get_def_use_mgr()->GetDef(block_ty_id)->opcode() ==
-                 spv::Op::OpTypeStruct &&
-             "unexpected block type");
-      bool block_found = get_decoration_mgr()->FindDecoration(
-          block_ty_id, uint32_t(spv::Decoration::Block),
-          [](const Instruction&) { return true; });
-      if (!block_found) {
-        // If block decoration not found, verify deprecated form of SSBO
-        bool buffer_block_found = get_decoration_mgr()->FindDecoration(
-            block_ty_id, uint32_t(spv::Decoration::BufferBlock),
-            [](const Instruction&) { return true; });
-        USE_ASSERT(buffer_block_found && "block decoration not found");
-        storage_class = spv::StorageClass::StorageBuffer;
-      }
-    }
-    ref->strg_class = uint32_t(storage_class);
-    Instruction* desc_type_inst = GetPointeeTypeInst(var_inst);
-    switch (desc_type_inst->opcode()) {
-      case spv::Op::OpTypeArray:
-      case spv::Op::OpTypeRuntimeArray:
-        // A load through a descriptor array will have at least 3 operands. We
-        // do not want to instrument loads of descriptors here which are part of
-        // an image-based reference.
-        if (ptr_inst->NumInOperands() < 3) return false;
-        ref->desc_idx_id =
-            ptr_inst->GetSingleWordInOperand(kSpvAccessChainIndex0IdInIdx);
-        break;
-      default:
-        break;
-    }
-    auto decos =
-        context()->get_decoration_mgr()->GetDecorationsFor(ref->var_id, false);
-    for (const auto& deco : decos) {
-      spv::Decoration d = spv::Decoration(deco->GetSingleWordInOperand(1u));
-      if (d == spv::Decoration::DescriptorSet) {
-        ref->set = deco->GetSingleWordInOperand(2u);
-      } else if (d == spv::Decoration::Binding) {
-        ref->binding = deco->GetSingleWordInOperand(2u);
-      }
-    }
-    return true;
-  }
-  // Reference is not load or store. If not an image-based reference, return.
-  ref->image_id = GetImageId(ref_inst);
-  if (ref->image_id == 0) return false;
-  // Search for descriptor load
-  uint32_t desc_load_id = ref->image_id;
-  Instruction* desc_load_inst;
-  for (;;) {
-    desc_load_inst = get_def_use_mgr()->GetDef(desc_load_id);
-    if (desc_load_inst->opcode() == spv::Op::OpSampledImage)
-      desc_load_id =
-          desc_load_inst->GetSingleWordInOperand(kSpvSampledImageImageIdInIdx);
-    else if (desc_load_inst->opcode() == spv::Op::OpImage)
-      desc_load_id =
-          desc_load_inst->GetSingleWordInOperand(kSpvImageSampledImageIdInIdx);
-    else if (desc_load_inst->opcode() == spv::Op::OpCopyObject)
-      desc_load_id =
-          desc_load_inst->GetSingleWordInOperand(kSpvCopyObjectOperandIdInIdx);
-    else
-      break;
-  }
-  if (desc_load_inst->opcode() != spv::Op::OpLoad) {
-    // TODO(greg-lunarg): Handle additional possibilities?
-    return false;
-  }
-  ref->desc_load_id = desc_load_id;
-  ref->ptr_id = desc_load_inst->GetSingleWordInOperand(kSpvLoadPtrIdInIdx);
-  Instruction* ptr_inst = get_def_use_mgr()->GetDef(ref->ptr_id);
-  if (ptr_inst->opcode() == spv::Op::OpVariable) {
-    ref->desc_idx_id = 0;
-    ref->var_id = ref->ptr_id;
-  } else if (ptr_inst->opcode() == spv::Op::OpAccessChain) {
-    if (ptr_inst->NumInOperands() != 2) {
-      assert(false && "unexpected bindless index number");
-      return false;
-    }
-    ref->desc_idx_id =
-        ptr_inst->GetSingleWordInOperand(kSpvAccessChainIndex0IdInIdx);
-    ref->var_id = ptr_inst->GetSingleWordInOperand(kSpvAccessChainBaseIdInIdx);
-    Instruction* var_inst = get_def_use_mgr()->GetDef(ref->var_id);
-    if (var_inst->opcode() != spv::Op::OpVariable) {
-      assert(false && "unexpected bindless base");
-      return false;
-    }
-  } else {
-    // TODO(greg-lunarg): Handle additional possibilities?
-    return false;
-  }
-  auto decos =
-      context()->get_decoration_mgr()->GetDecorationsFor(ref->var_id, false);
-  for (const auto& deco : decos) {
-    spv::Decoration d = spv::Decoration(deco->GetSingleWordInOperand(1u));
-    if (d == spv::Decoration::DescriptorSet) {
-      ref->set = deco->GetSingleWordInOperand(2u);
-    } else if (d == spv::Decoration::Binding) {
-      ref->binding = deco->GetSingleWordInOperand(2u);
-    }
-  }
-  return true;
-}
-
-uint32_t InstBindlessCheckPass::FindStride(uint32_t ty_id,
-                                           uint32_t stride_deco) {
-  uint32_t stride = 0xdeadbeef;
-  bool found = get_decoration_mgr()->FindDecoration(
-      ty_id, stride_deco, [&stride](const Instruction& deco_inst) {
-        stride = deco_inst.GetSingleWordInOperand(2u);
-        return true;
-      });
-  USE_ASSERT(found && "stride not found");
-  return stride;
-}
-
-uint32_t InstBindlessCheckPass::ByteSize(uint32_t ty_id, uint32_t matrix_stride,
-                                         bool col_major, bool in_matrix) {
-  analysis::TypeManager* type_mgr = context()->get_type_mgr();
-  const analysis::Type* sz_ty = type_mgr->GetType(ty_id);
-  if (sz_ty->kind() == analysis::Type::kPointer) {
-    // Assuming PhysicalStorageBuffer pointer
-    return 8;
-  }
-  if (sz_ty->kind() == analysis::Type::kMatrix) {
-    assert(matrix_stride != 0 && "missing matrix stride");
-    const analysis::Matrix* m_ty = sz_ty->AsMatrix();
-    if (col_major) {
-      return m_ty->element_count() * matrix_stride;
-    } else {
-      const analysis::Vector* v_ty = m_ty->element_type()->AsVector();
-      return v_ty->element_count() * matrix_stride;
-    }
-  }
-  uint32_t size = 1;
-  if (sz_ty->kind() == analysis::Type::kVector) {
-    const analysis::Vector* v_ty = sz_ty->AsVector();
-    size = v_ty->element_count();
-    const analysis::Type* comp_ty = v_ty->element_type();
-    // if vector in row major matrix, the vector is strided so return the
-    // number of bytes spanned by the vector
-    if (in_matrix && !col_major && matrix_stride > 0) {
-      uint32_t comp_ty_id = type_mgr->GetId(comp_ty);
-      return (size - 1) * matrix_stride + ByteSize(comp_ty_id, 0, false, false);
-    }
-    sz_ty = comp_ty;
-  }
-  switch (sz_ty->kind()) {
-    case analysis::Type::kFloat: {
-      const analysis::Float* f_ty = sz_ty->AsFloat();
-      size *= f_ty->width();
-    } break;
-    case analysis::Type::kInteger: {
-      const analysis::Integer* i_ty = sz_ty->AsInteger();
-      size *= i_ty->width();
-    } break;
-    default: { assert(false && "unexpected type"); } break;
-  }
-  size /= 8;
-  return size;
-}
-
-uint32_t InstBindlessCheckPass::GenLastByteIdx(RefAnalysis* ref,
-                                               InstructionBuilder* builder) {
-  // Find outermost buffer type and its access chain index
-  Instruction* var_inst = get_def_use_mgr()->GetDef(ref->var_id);
-  Instruction* desc_ty_inst = GetPointeeTypeInst(var_inst);
-  uint32_t buff_ty_id;
-  uint32_t ac_in_idx = 1;
-  switch (desc_ty_inst->opcode()) {
-    case spv::Op::OpTypeArray:
-    case spv::Op::OpTypeRuntimeArray:
-      buff_ty_id = desc_ty_inst->GetSingleWordInOperand(0);
-      ++ac_in_idx;
-      break;
-    default:
-      assert(desc_ty_inst->opcode() == spv::Op::OpTypeStruct &&
-             "unexpected descriptor type");
-      buff_ty_id = desc_ty_inst->result_id();
-      break;
-  }
-  // Process remaining access chain indices
-  Instruction* ac_inst = get_def_use_mgr()->GetDef(ref->ptr_id);
-  uint32_t curr_ty_id = buff_ty_id;
-  uint32_t sum_id = 0u;
-  uint32_t matrix_stride = 0u;
-  bool col_major = false;
-  uint32_t matrix_stride_id = 0u;
-  bool in_matrix = false;
-  while (ac_in_idx < ac_inst->NumInOperands()) {
-    uint32_t curr_idx_id = ac_inst->GetSingleWordInOperand(ac_in_idx);
-    Instruction* curr_ty_inst = get_def_use_mgr()->GetDef(curr_ty_id);
-    uint32_t curr_offset_id = 0;
-    switch (curr_ty_inst->opcode()) {
-      case spv::Op::OpTypeArray:
-      case spv::Op::OpTypeRuntimeArray: {
-        // Get array stride and multiply by current index
-        uint32_t arr_stride =
-            FindStride(curr_ty_id, uint32_t(spv::Decoration::ArrayStride));
-        uint32_t arr_stride_id = builder->GetUintConstantId(arr_stride);
-        uint32_t curr_idx_32b_id = Gen32BitCvtCode(curr_idx_id, builder);
-        Instruction* curr_offset_inst = builder->AddBinaryOp(
-            GetUintId(), spv::Op::OpIMul, arr_stride_id, curr_idx_32b_id);
-        curr_offset_id = curr_offset_inst->result_id();
-        // Get element type for next step
-        curr_ty_id = curr_ty_inst->GetSingleWordInOperand(0);
-      } break;
-      case spv::Op::OpTypeMatrix: {
-        assert(matrix_stride != 0 && "missing matrix stride");
-        matrix_stride_id = builder->GetUintConstantId(matrix_stride);
-        uint32_t vec_ty_id = curr_ty_inst->GetSingleWordInOperand(0);
-        // If column major, multiply column index by matrix stride, otherwise
-        // by vector component size and save matrix stride for vector (row)
-        // index
-        uint32_t col_stride_id;
-        if (col_major) {
-          col_stride_id = matrix_stride_id;
-        } else {
-          Instruction* vec_ty_inst = get_def_use_mgr()->GetDef(vec_ty_id);
-          uint32_t comp_ty_id = vec_ty_inst->GetSingleWordInOperand(0u);
-          uint32_t col_stride = ByteSize(comp_ty_id, 0u, false, false);
-          col_stride_id = builder->GetUintConstantId(col_stride);
-        }
-        uint32_t curr_idx_32b_id = Gen32BitCvtCode(curr_idx_id, builder);
-        Instruction* curr_offset_inst = builder->AddBinaryOp(
-            GetUintId(), spv::Op::OpIMul, col_stride_id, curr_idx_32b_id);
-        curr_offset_id = curr_offset_inst->result_id();
-        // Get element type for next step
-        curr_ty_id = vec_ty_id;
-        in_matrix = true;
-      } break;
-      case spv::Op::OpTypeVector: {
-        // If inside a row major matrix type, multiply index by matrix stride,
-        // else multiply by component size
-        uint32_t comp_ty_id = curr_ty_inst->GetSingleWordInOperand(0u);
-        uint32_t curr_idx_32b_id = Gen32BitCvtCode(curr_idx_id, builder);
-        if (in_matrix && !col_major) {
-          Instruction* curr_offset_inst = builder->AddBinaryOp(
-              GetUintId(), spv::Op::OpIMul, matrix_stride_id, curr_idx_32b_id);
-          curr_offset_id = curr_offset_inst->result_id();
-        } else {
-          uint32_t comp_ty_sz = ByteSize(comp_ty_id, 0u, false, false);
-          uint32_t comp_ty_sz_id = builder->GetUintConstantId(comp_ty_sz);
-          Instruction* curr_offset_inst = builder->AddBinaryOp(
-              GetUintId(), spv::Op::OpIMul, comp_ty_sz_id, curr_idx_32b_id);
-          curr_offset_id = curr_offset_inst->result_id();
-        }
-        // Get element type for next step
-        curr_ty_id = comp_ty_id;
-      } break;
-      case spv::Op::OpTypeStruct: {
-        // Get buffer byte offset for the referenced member
-        Instruction* curr_idx_inst = get_def_use_mgr()->GetDef(curr_idx_id);
-        assert(curr_idx_inst->opcode() == spv::Op::OpConstant &&
-               "unexpected struct index");
-        uint32_t member_idx = curr_idx_inst->GetSingleWordInOperand(0);
-        uint32_t member_offset = 0xdeadbeef;
-        bool found = get_decoration_mgr()->FindDecoration(
-            curr_ty_id, uint32_t(spv::Decoration::Offset),
-            [&member_idx, &member_offset](const Instruction& deco_inst) {
-              if (deco_inst.GetSingleWordInOperand(1u) != member_idx)
-                return false;
-              member_offset = deco_inst.GetSingleWordInOperand(3u);
-              return true;
-            });
-        USE_ASSERT(found && "member offset not found");
-        curr_offset_id = builder->GetUintConstantId(member_offset);
-        // Look for matrix stride for this member if there is one. The matrix
-        // stride is not on the matrix type, but in a OpMemberDecorate on the
-        // enclosing struct type at the member index. If none found, reset
-        // stride to 0.
-        found = get_decoration_mgr()->FindDecoration(
-            curr_ty_id, uint32_t(spv::Decoration::MatrixStride),
-            [&member_idx, &matrix_stride](const Instruction& deco_inst) {
-              if (deco_inst.GetSingleWordInOperand(1u) != member_idx)
-                return false;
-              matrix_stride = deco_inst.GetSingleWordInOperand(3u);
-              return true;
-            });
-        if (!found) matrix_stride = 0;
-        // Look for column major decoration
-        found = get_decoration_mgr()->FindDecoration(
-            curr_ty_id, uint32_t(spv::Decoration::ColMajor),
-            [&member_idx, &col_major](const Instruction& deco_inst) {
-              if (deco_inst.GetSingleWordInOperand(1u) != member_idx)
-                return false;
-              col_major = true;
-              return true;
-            });
-        if (!found) col_major = false;
-        // Get element type for next step
-        curr_ty_id = curr_ty_inst->GetSingleWordInOperand(member_idx);
-      } break;
-      default: { assert(false && "unexpected non-composite type"); } break;
-    }
-    if (sum_id == 0)
-      sum_id = curr_offset_id;
-    else {
-      Instruction* sum_inst =
-          builder->AddIAdd(GetUintId(), sum_id, curr_offset_id);
-      sum_id = sum_inst->result_id();
-    }
-    ++ac_in_idx;
-  }
-  // Add in offset of last byte of referenced object
-  uint32_t bsize = ByteSize(curr_ty_id, matrix_stride, col_major, in_matrix);
-  uint32_t last = bsize - 1;
-  uint32_t last_id = builder->GetUintConstantId(last);
-  Instruction* sum_inst = builder->AddIAdd(GetUintId(), sum_id, last_id);
-  return sum_inst->result_id();
-}
-
-void InstBindlessCheckPass::GenCheckCode(
-    uint32_t check_id, RefAnalysis* ref,
-    std::vector<std::unique_ptr<BasicBlock>>* new_blocks) {
-  BasicBlock* back_blk_ptr = &*new_blocks->back();
-  InstructionBuilder builder(
-      context(), back_blk_ptr,
-      IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
-  // Gen conditional branch on check_id. Valid branch generates original
-  // reference. Invalid generates debug output and zero result (if needed).
-  uint32_t merge_blk_id = TakeNextId();
-  uint32_t valid_blk_id = TakeNextId();
-  uint32_t invalid_blk_id = TakeNextId();
-  std::unique_ptr<Instruction> merge_label(NewLabel(merge_blk_id));
-  std::unique_ptr<Instruction> valid_label(NewLabel(valid_blk_id));
-  std::unique_ptr<Instruction> invalid_label(NewLabel(invalid_blk_id));
-  (void)builder.AddConditionalBranch(
-      check_id, valid_blk_id, invalid_blk_id, merge_blk_id,
-      uint32_t(spv::SelectionControlMask::MaskNone));
-  // Gen valid bounds branch
-  std::unique_ptr<BasicBlock> new_blk_ptr(
-      new BasicBlock(std::move(valid_label)));
-  builder.SetInsertPoint(&*new_blk_ptr);
-  uint32_t new_ref_id = CloneOriginalReference(ref, &builder);
-  uint32_t null_id = 0;
-  uint32_t ref_type_id = ref->ref_inst->type_id();
-  (void)builder.AddBranch(merge_blk_id);
-  new_blocks->push_back(std::move(new_blk_ptr));
-  // Gen invalid block
-  new_blk_ptr.reset(new BasicBlock(std::move(invalid_label)));
-  builder.SetInsertPoint(&*new_blk_ptr);
-
-  // Generate a ConstantNull, converting to uint64 if the type cannot be a null.
-  if (new_ref_id != 0) {
-    analysis::TypeManager* type_mgr = context()->get_type_mgr();
-    analysis::Type* ref_type = type_mgr->GetType(ref_type_id);
-    if (ref_type->AsPointer() != nullptr) {
-      context()->AddCapability(spv::Capability::Int64);
-      uint32_t null_u64_id = GetNullId(GetUint64Id());
-      Instruction* null_ptr_inst = builder.AddUnaryOp(
-          ref_type_id, spv::Op::OpConvertUToPtr, null_u64_id);
-      null_id = null_ptr_inst->result_id();
-    } else {
-      null_id = GetNullId(ref_type_id);
-    }
-  }
-  // Remember last invalid block id
-  uint32_t last_invalid_blk_id = new_blk_ptr->GetLabelInst()->result_id();
-  // Gen zero for invalid  reference
-  (void)builder.AddBranch(merge_blk_id);
-  new_blocks->push_back(std::move(new_blk_ptr));
-  // Gen merge block
-  new_blk_ptr.reset(new BasicBlock(std::move(merge_label)));
-  builder.SetInsertPoint(&*new_blk_ptr);
-  // Gen phi of new reference and zero, if necessary, and replace the
-  // result id of the original reference with that of the Phi. Kill original
-  // reference.
-  if (new_ref_id != 0) {
-    Instruction* phi_inst = builder.AddPhi(
-        ref_type_id, {new_ref_id, valid_blk_id, null_id, last_invalid_blk_id});
-    context()->ReplaceAllUsesWith(ref->ref_inst->result_id(),
-                                  phi_inst->result_id());
-  }
-  new_blocks->push_back(std::move(new_blk_ptr));
-  context()->KillInst(ref->ref_inst);
-}
-
-void InstBindlessCheckPass::GenDescCheckCode(
-    BasicBlock::iterator ref_inst_itr,
-    UptrVectorIterator<BasicBlock> ref_block_itr, uint32_t stage_idx,
-    std::vector<std::unique_ptr<BasicBlock>>* new_blocks) {
-  // Look for reference through descriptor. If not, return.
-  RefAnalysis ref;
-  if (!AnalyzeDescriptorReference(&*ref_inst_itr, &ref)) return;
-  std::unique_ptr<BasicBlock> new_blk_ptr;
-  // Move original block's preceding instructions into first new block
-  MovePreludeCode(ref_inst_itr, ref_block_itr, &new_blk_ptr);
-  InstructionBuilder builder(
-      context(), &*new_blk_ptr,
-      IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
-  new_blocks->push_back(std::move(new_blk_ptr));
-  // Determine if we can only do initialization check
-  uint32_t ref_id = builder.GetUintConstantId(0u);
-  spv::Op op = ref.ref_inst->opcode();
-  if (ref.desc_load_id != 0) {
-    uint32_t num_in_oprnds = ref.ref_inst->NumInOperands();
-    if ((op == spv::Op::OpImageRead && num_in_oprnds == 2) ||
-        (op == spv::Op::OpImageFetch && num_in_oprnds == 2) ||
-        (op == spv::Op::OpImageWrite && num_in_oprnds == 3)) {
-      Instruction* image_inst = get_def_use_mgr()->GetDef(ref.image_id);
-      uint32_t image_ty_id = image_inst->type_id();
-      Instruction* image_ty_inst = get_def_use_mgr()->GetDef(image_ty_id);
-      if (spv::Dim(image_ty_inst->GetSingleWordInOperand(kSpvTypeImageDim)) ==
-          spv::Dim::Buffer) {
-        if ((image_ty_inst->GetSingleWordInOperand(kSpvTypeImageDepth) == 0) &&
-            (image_ty_inst->GetSingleWordInOperand(kSpvTypeImageArrayed) ==
-             0) &&
-            (image_ty_inst->GetSingleWordInOperand(kSpvTypeImageMS) == 0)) {
-          ref_id = GenUintCastCode(ref.ref_inst->GetSingleWordInOperand(1),
-                                   &builder);
-        }
-      }
-    }
-  } else {
-    // For now, only do bounds check for non-aggregate types. Otherwise
-    // just do descriptor initialization check.
-    // TODO(greg-lunarg): Do bounds check for aggregate loads and stores
-    Instruction* ref_ptr_inst = get_def_use_mgr()->GetDef(ref.ptr_id);
-    Instruction* pte_type_inst = GetPointeeTypeInst(ref_ptr_inst);
-    spv::Op pte_type_op = pte_type_inst->opcode();
-    if (pte_type_op != spv::Op::OpTypeArray &&
-        pte_type_op != spv::Op::OpTypeRuntimeArray &&
-        pte_type_op != spv::Op::OpTypeStruct) {
-      ref_id = GenLastByteIdx(&ref, &builder);
-    }
-  }
-  // Read initialization/bounds from debug input buffer. If index id not yet
-  // set, binding is single descriptor, so set index to constant 0.
-  if (ref.desc_idx_id == 0) ref.desc_idx_id = builder.GetUintConstantId(0u);
-  uint32_t check_id =
-      GenDescCheckCall(ref.ref_inst->unique_id(), stage_idx, ref.var_id,
-                       ref.desc_idx_id, ref_id, &builder);
-
-  // Generate runtime initialization/bounds test code with true branch
-  // being full reference and false branch being zero
-  // for the referenced value.
-  GenCheckCode(check_id, &ref, new_blocks);
-
-  // Move original block's remaining code into remainder/merge block and add
-  // to new blocks
-  BasicBlock* back_blk_ptr = &*new_blocks->back();
-  MovePostludeCode(ref_block_itr, back_blk_ptr);
-}
-
-void InstBindlessCheckPass::InitializeInstBindlessCheck() {
-  // Initialize base class
-  InitializeInstrument();
-  for (auto& anno : get_module()->annotations()) {
-    if (anno.opcode() == spv::Op::OpDecorate) {
-      if (spv::Decoration(anno.GetSingleWordInOperand(1u)) ==
-          spv::Decoration::DescriptorSet) {
-        var2desc_set_[anno.GetSingleWordInOperand(0u)] =
-            anno.GetSingleWordInOperand(2u);
-      } else if (spv::Decoration(anno.GetSingleWordInOperand(1u)) ==
-                 spv::Decoration::Binding) {
-        var2binding_[anno.GetSingleWordInOperand(0u)] =
-            anno.GetSingleWordInOperand(2u);
-      }
-    }
-  }
-}
-
-Pass::Status InstBindlessCheckPass::ProcessImpl() {
-  // The memory model and linkage must always be updated for spirv-link to work
-  // correctly.
-  AddStorageBufferExt();
-  if (!get_feature_mgr()->HasExtension(kSPV_KHR_physical_storage_buffer)) {
-    context()->AddExtension("SPV_KHR_physical_storage_buffer");
-  }
-
-  context()->AddCapability(spv::Capability::PhysicalStorageBufferAddresses);
-  Instruction* memory_model = get_module()->GetMemoryModel();
-  memory_model->SetInOperand(
-      0u, {uint32_t(spv::AddressingModel::PhysicalStorageBuffer64)});
-
-  context()->AddCapability(spv::Capability::Linkage);
-
-  InstProcessFunction pfn =
-      [this](BasicBlock::iterator ref_inst_itr,
-             UptrVectorIterator<BasicBlock> ref_block_itr, uint32_t stage_idx,
-             std::vector<std::unique_ptr<BasicBlock>>* new_blocks) {
-        return GenDescCheckCode(ref_inst_itr, ref_block_itr, stage_idx,
-                                new_blocks);
-      };
-
-  InstProcessEntryPointCallTree(pfn);
-  // This pass always changes the memory model, so that linking will work
-  // properly.
-  return Status::SuccessWithChange;
-}
-
-Pass::Status InstBindlessCheckPass::Process() {
-  InitializeInstBindlessCheck();
-  return ProcessImpl();
-}
-
-}  // namespace opt
-}  // namespace spvtools

+ 0 - 130
3rdparty/spirv-tools/source/opt/inst_bindless_check_pass.h

@@ -1,130 +0,0 @@
-// Copyright (c) 2018 The Khronos Group Inc.
-// Copyright (c) 2018 Valve Corporation
-// Copyright (c) 2018 LunarG Inc.
-//
-// 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.
-
-#ifndef LIBSPIRV_OPT_INST_BINDLESS_CHECK_PASS_H_
-#define LIBSPIRV_OPT_INST_BINDLESS_CHECK_PASS_H_
-
-#include "instrument_pass.h"
-
-namespace spvtools {
-namespace opt {
-
-// This class/pass is designed to support the bindless (descriptor indexing)
-// GPU-assisted validation layer of
-// https://github.com/KhronosGroup/Vulkan-ValidationLayers. Its internal and
-// external design may change as the layer evolves.
-class InstBindlessCheckPass : public InstrumentPass {
- public:
-  InstBindlessCheckPass(uint32_t shader_id)
-      : InstrumentPass(0, shader_id, true, true) {}
-
-  ~InstBindlessCheckPass() override = default;
-
-  // See optimizer.hpp for pass user documentation.
-  Status Process() override;
-
-  const char* name() const override { return "inst-bindless-check-pass"; }
-
- private:
-  void GenDescCheckCode(BasicBlock::iterator ref_inst_itr,
-                        UptrVectorIterator<BasicBlock> ref_block_itr,
-                        uint32_t stage_idx,
-                        std::vector<std::unique_ptr<BasicBlock>>* new_blocks);
-
-  uint32_t GenDescCheckFunctionId();
-
-  uint32_t GenDescCheckCall(uint32_t inst_idx, uint32_t stage_idx,
-                            uint32_t var_id, uint32_t index_id,
-                            uint32_t byte_offset, InstructionBuilder* builder);
-
-  // Analysis data for descriptor reference components, generated by
-  // AnalyzeDescriptorReference. It is necessary and sufficient for further
-  // analysis and regeneration of the reference.
-  typedef struct RefAnalysis {
-    uint32_t desc_load_id{0};
-    uint32_t image_id{0};
-    uint32_t load_id{0};
-    uint32_t ptr_id{0};
-    uint32_t var_id{0};
-    uint32_t set{0};
-    uint32_t binding{0};
-    uint32_t desc_idx_id{0};
-    uint32_t strg_class{0};
-    Instruction* ref_inst{nullptr};
-  } RefAnalysis;
-
-  // Return size of type |ty_id| in bytes. Use |matrix_stride| and |col_major|
-  // for matrix type, or for vector type if vector is |in_matrix|.
-  uint32_t ByteSize(uint32_t ty_id, uint32_t matrix_stride, bool col_major,
-                    bool in_matrix);
-
-  // Return stride of type |ty_id| with decoration |stride_deco|. Return 0
-  // if not found
-  uint32_t FindStride(uint32_t ty_id, uint32_t stride_deco);
-
-  // Generate index of last byte referenced by buffer reference |ref|
-  uint32_t GenLastByteIdx(RefAnalysis* ref, InstructionBuilder* builder);
-
-  // Clone original image computation starting at |image_id| into |builder|.
-  // This may generate more than one instruction if necessary.
-  uint32_t CloneOriginalImage(uint32_t image_id, InstructionBuilder* builder);
-
-  // Clone original original reference encapsulated by |ref| into |builder|.
-  // This may generate more than one instruction if necessary.
-  uint32_t CloneOriginalReference(RefAnalysis* ref,
-                                  InstructionBuilder* builder);
-
-  // If |inst| references through an image, return the id of the image it
-  // references through. Else return 0.
-  uint32_t GetImageId(Instruction* inst);
-
-  // Get pointee type inst of pointer value |ptr_inst|.
-  Instruction* GetPointeeTypeInst(Instruction* ptr_inst);
-
-  // Analyze descriptor reference |ref_inst| and save components into |ref|.
-  // Return true if |ref_inst| is a descriptor reference, false otherwise.
-  bool AnalyzeDescriptorReference(Instruction* ref_inst, RefAnalysis* ref);
-
-  // Generate instrumentation code for generic test result |check_id|, starting
-  // with |builder| of block |new_blk_ptr|, adding new blocks to |new_blocks|.
-  // Generate conditional branch to a valid or invalid branch. Generate valid
-  // block which does original reference |ref|. Generate invalid block which
-  // writes debug error output utilizing |ref|, |error_id|, |length_id| and
-  // |stage_idx|. Generate merge block for valid and invalid branches. Kill
-  // original reference.
-  void GenCheckCode(uint32_t check_id, RefAnalysis* ref,
-                    std::vector<std::unique_ptr<BasicBlock>>* new_blocks);
-
-  // Initialize state for instrumenting bindless checking
-  void InitializeInstBindlessCheck();
-
-  // Apply GenDescIdxCheckCode to every instruction in module. Then apply
-  // GenDescInitCheckCode to every instruction in module.
-  Pass::Status ProcessImpl();
-
-  // Mapping from variable to descriptor set
-  std::unordered_map<uint32_t, uint32_t> var2desc_set_;
-
-  // Mapping from variable to binding
-  std::unordered_map<uint32_t, uint32_t> var2binding_;
-
-  uint32_t check_desc_func_id_{0};
-};
-
-}  // namespace opt
-}  // namespace spvtools
-
-#endif  // LIBSPIRV_OPT_INST_BINDLESS_CHECK_PASS_H_

+ 0 - 331
3rdparty/spirv-tools/source/opt/inst_buff_addr_check_pass.cpp

@@ -1,331 +0,0 @@
-// Copyright (c) 2019 The Khronos Group Inc.
-// Copyright (c) 2019 Valve Corporation
-// Copyright (c) 2019 LunarG Inc.
-//
-// 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 "inst_buff_addr_check_pass.h"
-
-namespace spvtools {
-namespace opt {
-
-uint32_t InstBuffAddrCheckPass::CloneOriginalReference(
-    Instruction* ref_inst, InstructionBuilder* builder) {
-  // Clone original ref with new result id (if load)
-  assert((ref_inst->opcode() == spv::Op::OpLoad ||
-          ref_inst->opcode() == spv::Op::OpStore) &&
-         "unexpected ref");
-  std::unique_ptr<Instruction> new_ref_inst(ref_inst->Clone(context()));
-  uint32_t ref_result_id = ref_inst->result_id();
-  uint32_t new_ref_id = 0;
-  if (ref_result_id != 0) {
-    new_ref_id = TakeNextId();
-    new_ref_inst->SetResultId(new_ref_id);
-  }
-  // Register new reference and add to new block
-  Instruction* added_inst = builder->AddInstruction(std::move(new_ref_inst));
-  uid2offset_[added_inst->unique_id()] = uid2offset_[ref_inst->unique_id()];
-  if (new_ref_id != 0)
-    get_decoration_mgr()->CloneDecorations(ref_result_id, new_ref_id);
-  return new_ref_id;
-}
-
-bool InstBuffAddrCheckPass::IsPhysicalBuffAddrReference(Instruction* ref_inst) {
-  if (ref_inst->opcode() != spv::Op::OpLoad &&
-      ref_inst->opcode() != spv::Op::OpStore)
-    return false;
-  uint32_t ptr_id = ref_inst->GetSingleWordInOperand(0);
-  analysis::DefUseManager* du_mgr = get_def_use_mgr();
-  Instruction* ptr_inst = du_mgr->GetDef(ptr_id);
-  if (ptr_inst->opcode() != spv::Op::OpAccessChain) return false;
-  uint32_t ptr_ty_id = ptr_inst->type_id();
-  Instruction* ptr_ty_inst = du_mgr->GetDef(ptr_ty_id);
-  if (spv::StorageClass(ptr_ty_inst->GetSingleWordInOperand(0)) !=
-      spv::StorageClass::PhysicalStorageBufferEXT)
-    return false;
-  return true;
-}
-
-// TODO(greg-lunarg): Refactor with InstBindlessCheckPass::GenCheckCode() ??
-void InstBuffAddrCheckPass::GenCheckCode(
-    uint32_t check_id, Instruction* ref_inst,
-    std::vector<std::unique_ptr<BasicBlock>>* new_blocks) {
-  BasicBlock* back_blk_ptr = &*new_blocks->back();
-  InstructionBuilder builder(
-      context(), back_blk_ptr,
-      IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
-  // Gen conditional branch on check_id. Valid branch generates original
-  // reference. Invalid generates debug output and zero result (if needed).
-  uint32_t merge_blk_id = TakeNextId();
-  uint32_t valid_blk_id = TakeNextId();
-  uint32_t invalid_blk_id = TakeNextId();
-  std::unique_ptr<Instruction> merge_label(NewLabel(merge_blk_id));
-  std::unique_ptr<Instruction> valid_label(NewLabel(valid_blk_id));
-  std::unique_ptr<Instruction> invalid_label(NewLabel(invalid_blk_id));
-  (void)builder.AddConditionalBranch(
-      check_id, valid_blk_id, invalid_blk_id, merge_blk_id,
-      uint32_t(spv::SelectionControlMask::MaskNone));
-  // Gen valid branch
-  std::unique_ptr<BasicBlock> new_blk_ptr(
-      new BasicBlock(std::move(valid_label)));
-  builder.SetInsertPoint(&*new_blk_ptr);
-  uint32_t new_ref_id = CloneOriginalReference(ref_inst, &builder);
-  (void)builder.AddBranch(merge_blk_id);
-  new_blocks->push_back(std::move(new_blk_ptr));
-  // Gen invalid block
-  new_blk_ptr.reset(new BasicBlock(std::move(invalid_label)));
-  builder.SetInsertPoint(&*new_blk_ptr);
-  // Gen zero for invalid load. If pointer type, need to convert uint64
-  // zero to pointer; cannot create ConstantNull of pointer type.
-  uint32_t null_id = 0;
-  if (new_ref_id != 0) {
-    uint32_t ref_type_id = ref_inst->type_id();
-    analysis::TypeManager* type_mgr = context()->get_type_mgr();
-    analysis::Type* ref_type = type_mgr->GetType(ref_type_id);
-    if (ref_type->AsPointer() != nullptr) {
-      uint32_t null_u64_id = GetNullId(GetUint64Id());
-      Instruction* null_ptr_inst = builder.AddUnaryOp(
-          ref_type_id, spv::Op::OpConvertUToPtr, null_u64_id);
-      null_id = null_ptr_inst->result_id();
-    } else {
-      null_id = GetNullId(ref_type_id);
-    }
-  }
-  (void)builder.AddBranch(merge_blk_id);
-  new_blocks->push_back(std::move(new_blk_ptr));
-  // Gen merge block
-  new_blk_ptr.reset(new BasicBlock(std::move(merge_label)));
-  builder.SetInsertPoint(&*new_blk_ptr);
-  // Gen phi of new reference and zero, if necessary, and replace the
-  // result id of the original reference with that of the Phi. Kill original
-  // reference.
-  if (new_ref_id != 0) {
-    Instruction* phi_inst =
-        builder.AddPhi(ref_inst->type_id(),
-                       {new_ref_id, valid_blk_id, null_id, invalid_blk_id});
-    context()->ReplaceAllUsesWith(ref_inst->result_id(), phi_inst->result_id());
-  }
-  new_blocks->push_back(std::move(new_blk_ptr));
-  context()->KillInst(ref_inst);
-}
-
-uint32_t InstBuffAddrCheckPass::GetTypeLength(uint32_t type_id) {
-  Instruction* type_inst = get_def_use_mgr()->GetDef(type_id);
-  switch (type_inst->opcode()) {
-    case spv::Op::OpTypeFloat:
-    case spv::Op::OpTypeInt:
-      return type_inst->GetSingleWordInOperand(0) / 8u;
-    case spv::Op::OpTypeVector:
-    case spv::Op::OpTypeMatrix:
-      return type_inst->GetSingleWordInOperand(1) *
-             GetTypeLength(type_inst->GetSingleWordInOperand(0));
-    case spv::Op::OpTypePointer:
-      assert(spv::StorageClass(type_inst->GetSingleWordInOperand(0)) ==
-                 spv::StorageClass::PhysicalStorageBufferEXT &&
-             "unexpected pointer type");
-      return 8u;
-    case spv::Op::OpTypeArray: {
-      uint32_t const_id = type_inst->GetSingleWordInOperand(1);
-      Instruction* const_inst = get_def_use_mgr()->GetDef(const_id);
-      uint32_t cnt = const_inst->GetSingleWordInOperand(0);
-      return cnt * GetTypeLength(type_inst->GetSingleWordInOperand(0));
-    }
-    case spv::Op::OpTypeStruct: {
-      // Figure out the location of the last byte of the last member of the
-      // structure.
-      uint32_t last_offset = 0, last_len = 0;
-
-      get_decoration_mgr()->ForEachDecoration(
-          type_id, uint32_t(spv::Decoration::Offset),
-          [&last_offset](const Instruction& deco_inst) {
-            last_offset = deco_inst.GetSingleWordInOperand(3);
-          });
-      type_inst->ForEachInId([&last_len, this](const uint32_t* iid) {
-        last_len = GetTypeLength(*iid);
-      });
-      return last_offset + last_len;
-    }
-    case spv::Op::OpTypeRuntimeArray:
-    default:
-      assert(false && "unexpected type");
-      return 0;
-  }
-}
-
-void InstBuffAddrCheckPass::AddParam(uint32_t type_id,
-                                     std::vector<uint32_t>* param_vec,
-                                     std::unique_ptr<Function>* input_func) {
-  uint32_t pid = TakeNextId();
-  param_vec->push_back(pid);
-  std::unique_ptr<Instruction> param_inst(new Instruction(
-      get_module()->context(), spv::Op::OpFunctionParameter, type_id, pid, {}));
-  get_def_use_mgr()->AnalyzeInstDefUse(&*param_inst);
-  (*input_func)->AddParameter(std::move(param_inst));
-}
-
-// This is a stub function for use with Import linkage
-// clang-format off
-// GLSL:
-//bool inst_bindless_search_and_test(const uint shader_id, const uint inst_num, const uvec4 stage_info,
-//				     const uint64 ref_ptr, const uint length) {
-//}
-// clang-format on
-uint32_t InstBuffAddrCheckPass::GetSearchAndTestFuncId() {
-  enum {
-    kShaderId = 0,
-    kInstructionIndex = 1,
-    kStageInfo = 2,
-    kRefPtr = 3,
-    kLength = 4,
-    kNumArgs
-  };
-  if (search_test_func_id_ != 0) {
-    return search_test_func_id_;
-  }
-  // Generate function "bool search_and_test(uint64_t ref_ptr, uint32_t len)"
-  // which searches input buffer for buffer which most likely contains the
-  // pointer value |ref_ptr| and verifies that the entire reference of
-  // length |len| bytes is contained in the buffer.
-  analysis::TypeManager* type_mgr = context()->get_type_mgr();
-  const analysis::Integer* uint_type = GetInteger(32, false);
-  const analysis::Vector v4uint(uint_type, 4);
-  const analysis::Type* v4uint_type = type_mgr->GetRegisteredType(&v4uint);
-
-  std::vector<const analysis::Type*> param_types = {
-      uint_type, uint_type, v4uint_type, type_mgr->GetType(GetUint64Id()),
-      uint_type};
-
-  const std::string func_name{"inst_buff_addr_search_and_test"};
-  const uint32_t func_id = TakeNextId();
-  std::unique_ptr<Function> func =
-      StartFunction(func_id, type_mgr->GetBoolType(), param_types);
-  func->SetFunctionEnd(EndFunction());
-  context()->AddFunctionDeclaration(std::move(func));
-  context()->AddDebug2Inst(NewName(func_id, func_name));
-
-  std::vector<Operand> operands{
-      {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {func_id}},
-      {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER,
-       {uint32_t(spv::Decoration::LinkageAttributes)}},
-      {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_STRING,
-       utils::MakeVector(func_name.c_str())},
-      {spv_operand_type_t::SPV_OPERAND_TYPE_LINKAGE_TYPE,
-       {uint32_t(spv::LinkageType::Import)}},
-  };
-  get_decoration_mgr()->AddDecoration(spv::Op::OpDecorate, operands);
-
-  search_test_func_id_ = func_id;
-  return search_test_func_id_;
-}
-
-uint32_t InstBuffAddrCheckPass::GenSearchAndTest(Instruction* ref_inst,
-                                                 InstructionBuilder* builder,
-                                                 uint32_t* ref_uptr_id,
-                                                 uint32_t stage_idx) {
-  // Enable Int64 if necessary
-  // Convert reference pointer to uint64
-  const uint32_t ref_ptr_id = ref_inst->GetSingleWordInOperand(0);
-  Instruction* ref_uptr_inst =
-      builder->AddUnaryOp(GetUint64Id(), spv::Op::OpConvertPtrToU, ref_ptr_id);
-  *ref_uptr_id = ref_uptr_inst->result_id();
-  // Compute reference length in bytes
-  analysis::DefUseManager* du_mgr = get_def_use_mgr();
-  Instruction* ref_ptr_inst = du_mgr->GetDef(ref_ptr_id);
-  const uint32_t ref_ptr_ty_id = ref_ptr_inst->type_id();
-  Instruction* ref_ptr_ty_inst = du_mgr->GetDef(ref_ptr_ty_id);
-  const uint32_t ref_len =
-      GetTypeLength(ref_ptr_ty_inst->GetSingleWordInOperand(1));
-  // Gen call to search and test function
-  const uint32_t func_id = GetSearchAndTestFuncId();
-  const std::vector<uint32_t> args = {
-      builder->GetUintConstantId(shader_id_),
-      builder->GetUintConstantId(ref_inst->unique_id()),
-      GenStageInfo(stage_idx, builder), *ref_uptr_id,
-      builder->GetUintConstantId(ref_len)};
-  return GenReadFunctionCall(GetBoolId(), func_id, args, builder);
-}
-
-void InstBuffAddrCheckPass::GenBuffAddrCheckCode(
-    BasicBlock::iterator ref_inst_itr,
-    UptrVectorIterator<BasicBlock> ref_block_itr, uint32_t stage_idx,
-    std::vector<std::unique_ptr<BasicBlock>>* new_blocks) {
-  // Look for reference through indexed descriptor. If found, analyze and
-  // save components. If not, return.
-  Instruction* ref_inst = &*ref_inst_itr;
-  if (!IsPhysicalBuffAddrReference(ref_inst)) return;
-  // Move original block's preceding instructions into first new block
-  std::unique_ptr<BasicBlock> new_blk_ptr;
-  MovePreludeCode(ref_inst_itr, ref_block_itr, &new_blk_ptr);
-  InstructionBuilder builder(
-      context(), &*new_blk_ptr,
-      IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping);
-  new_blocks->push_back(std::move(new_blk_ptr));
-  // Generate code to do search and test if all bytes of reference
-  // are within a listed buffer. Return reference pointer converted to uint64.
-  uint32_t ref_uptr_id;
-  uint32_t valid_id =
-      GenSearchAndTest(ref_inst, &builder, &ref_uptr_id, stage_idx);
-  // Generate test of search results with true branch
-  // being full reference and false branch being debug output and zero
-  // for the referenced value.
-  GenCheckCode(valid_id, ref_inst, new_blocks);
-
-  // Move original block's remaining code into remainder/merge block and add
-  // to new blocks
-  BasicBlock* back_blk_ptr = &*new_blocks->back();
-  MovePostludeCode(ref_block_itr, back_blk_ptr);
-}
-
-void InstBuffAddrCheckPass::InitInstBuffAddrCheck() {
-  // Initialize base class
-  InitializeInstrument();
-  // Initialize class
-  search_test_func_id_ = 0;
-}
-
-Pass::Status InstBuffAddrCheckPass::ProcessImpl() {
-  // The memory model and linkage must always be updated for spirv-link to work
-  // correctly.
-  AddStorageBufferExt();
-  if (!get_feature_mgr()->HasExtension(kSPV_KHR_physical_storage_buffer)) {
-    context()->AddExtension("SPV_KHR_physical_storage_buffer");
-  }
-
-  context()->AddCapability(spv::Capability::PhysicalStorageBufferAddresses);
-  Instruction* memory_model = get_module()->GetMemoryModel();
-  memory_model->SetInOperand(
-      0u, {uint32_t(spv::AddressingModel::PhysicalStorageBuffer64)});
-
-  context()->AddCapability(spv::Capability::Int64);
-  context()->AddCapability(spv::Capability::Linkage);
-  // Perform bindless bounds check on each entry point function in module
-  InstProcessFunction pfn =
-      [this](BasicBlock::iterator ref_inst_itr,
-             UptrVectorIterator<BasicBlock> ref_block_itr, uint32_t stage_idx,
-             std::vector<std::unique_ptr<BasicBlock>>* new_blocks) {
-        return GenBuffAddrCheckCode(ref_inst_itr, ref_block_itr, stage_idx,
-                                    new_blocks);
-      };
-  InstProcessEntryPointCallTree(pfn);
-  // This pass always changes the memory model, so that linking will work
-  // properly.
-  return Status::SuccessWithChange;
-}
-
-Pass::Status InstBuffAddrCheckPass::Process() {
-  InitInstBuffAddrCheck();
-  return ProcessImpl();
-}
-
-}  // namespace opt
-}  // namespace spvtools

+ 0 - 130
3rdparty/spirv-tools/source/opt/inst_buff_addr_check_pass.h

@@ -1,130 +0,0 @@
-// Copyright (c) 2019 The Khronos Group Inc.
-// Copyright (c) 2019 Valve Corporation
-// Copyright (c) 2019 LunarG Inc.
-//
-// 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.
-
-#ifndef LIBSPIRV_OPT_INST_BUFFER_ADDRESS_PASS_H_
-#define LIBSPIRV_OPT_INST_BUFFER_ADDRESS_PASS_H_
-
-#include "instrument_pass.h"
-
-namespace spvtools {
-namespace opt {
-
-// This class/pass is designed to support the GPU-assisted validation layer of
-// the Buffer Device Address (BDA) extension in
-// https://github.com/KhronosGroup/Vulkan-ValidationLayers. The internal and
-// external design of this class may change as the layer evolves.
-class InstBuffAddrCheckPass : public InstrumentPass {
- public:
-  // For test harness only
-  InstBuffAddrCheckPass() : InstrumentPass(0, 23, false, true) {}
-  // For all other interfaces
-  InstBuffAddrCheckPass(uint32_t shader_id)
-      : InstrumentPass(0, shader_id, false, true) {}
-
-  ~InstBuffAddrCheckPass() override = default;
-
-  // See optimizer.hpp for pass user documentation.
-  Status Process() override;
-
-  const char* name() const override { return "inst-buff-addr-check-pass"; }
-
- private:
-  // Return byte length of type |type_id|. Must be int, float, vector, matrix,
-  // struct, array or physical pointer. Uses std430 alignment and sizes.
-  uint32_t GetTypeLength(uint32_t type_id);
-
-  // Add |type_id| param to |input_func| and add id to |param_vec|.
-  void AddParam(uint32_t type_id, std::vector<uint32_t>* param_vec,
-                std::unique_ptr<Function>* input_func);
-
-  // Return id for search and test function. Generate it if not already gen'd.
-  uint32_t GetSearchAndTestFuncId();
-
-  // Generate code into |builder| to do search of the BDA debug input buffer
-  // for the buffer used by |ref_inst| and test that all bytes of reference
-  // are within the buffer. Returns id of boolean value which is true if
-  // search and test is successful, false otherwise.
-  uint32_t GenSearchAndTest(Instruction* ref_inst, InstructionBuilder* builder,
-                            uint32_t* ref_uptr_id, uint32_t stage_idx);
-
-  // This function does checking instrumentation on a single
-  // instruction which references through a physical storage buffer address.
-  // GenBuffAddrCheckCode generates code that checks that all bytes that
-  // are referenced fall within a buffer that was queried via
-  // the Vulkan API call vkGetBufferDeviceAddressEXT().
-  //
-  // The function is designed to be passed to
-  // InstrumentPass::InstProcessEntryPointCallTree(), which applies the
-  // function to each instruction in a module and replaces the instruction
-  // with instrumented code if warranted.
-  //
-  // If |ref_inst_itr| is a physical storage buffer reference, return in
-  // |new_blocks| the result of instrumenting it with validation code within
-  // its block at |ref_block_itr|.  The validation code first executes a check
-  // for the specific condition called for. If the check passes, it executes
-  // the remainder of the reference, otherwise writes a record to the debug
-  // output buffer stream including |function_idx, instruction_idx, stage_idx|
-  // and replaces the reference with the null value of the original type. The
-  // block at |ref_block_itr| can just be replaced with the blocks in
-  // |new_blocks|, which will contain at least two blocks. The last block will
-  // comprise all instructions following |ref_inst_itr|,
-  // preceded by a phi instruction if needed.
-  //
-  // This instrumentation function utilizes GenDebugStreamWrite() to write its
-  // error records. The validation-specific part of the error record will
-  // have the format:
-  //
-  //    Validation Error Code (=kInstErrorBuffAddr)
-  //    Buffer Address (lowest 32 bits)
-  //    Buffer Address (highest 32 bits)
-  //
-  void GenBuffAddrCheckCode(
-      BasicBlock::iterator ref_inst_itr,
-      UptrVectorIterator<BasicBlock> ref_block_itr, uint32_t stage_idx,
-      std::vector<std::unique_ptr<BasicBlock>>* new_blocks);
-
-  // Return true if |ref_inst| is a physical buffer address reference, false
-  // otherwise.
-  bool IsPhysicalBuffAddrReference(Instruction* ref_inst);
-
-  // Clone original reference |ref_inst| into |builder| and return id of result
-  uint32_t CloneOriginalReference(Instruction* ref_inst,
-                                  InstructionBuilder* builder);
-
-  // Generate instrumentation code for boolean test result |check_id|,
-  // adding new blocks to |new_blocks|. Generate conditional branch to valid
-  // or invalid reference blocks. Generate valid reference block which does
-  // original reference |ref_inst|. Then generate invalid reference block which
-  // writes debug error output utilizing |ref_inst|, |error_id| and
-  // |stage_idx|. Generate merge block for valid and invalid reference blocks.
-  // Kill original reference.
-  void GenCheckCode(uint32_t check_id, Instruction* ref_inst,
-                    std::vector<std::unique_ptr<BasicBlock>>* new_blocks);
-
-  // Initialize state for instrumenting physical buffer address checking
-  void InitInstBuffAddrCheck();
-
-  // Apply GenBuffAddrCheckCode to every instruction in module.
-  Pass::Status ProcessImpl();
-
-  // Id of search and test function, if already gen'd, else zero.
-  uint32_t search_test_func_id_;
-};
-
-}  // namespace opt
-}  // namespace spvtools
-
-#endif  // LIBSPIRV_OPT_INST_BUFFER_ADDRESS_PASS_H_

+ 0 - 20
3rdparty/spirv-tools/source/opt/optimizer.cpp

@@ -451,16 +451,6 @@ bool Optimizer::RegisterPassFromFlag(const std::string& flag,
     RegisterPass(CreateWorkaround1209Pass());
   } else if (pass_name == "replace-invalid-opcode") {
     RegisterPass(CreateReplaceInvalidOpcodePass());
-  } else if (pass_name == "inst-bindless-check" ||
-             pass_name == "inst-desc-idx-check" ||
-             pass_name == "inst-buff-oob-check") {
-    // preserve legacy names
-    RegisterPass(CreateInstBindlessCheckPass(23));
-    RegisterPass(CreateSimplificationPass());
-    RegisterPass(CreateDeadBranchElimPass());
-    RegisterPass(CreateBlockMergePass());
-  } else if (pass_name == "inst-buff-addr-check") {
-    RegisterPass(CreateInstBuffAddrCheckPass(23));
   } else if (pass_name == "convert-relaxed-to-half") {
     RegisterPass(CreateConvertRelaxedToHalfPass());
   } else if (pass_name == "relax-float-ops") {
@@ -1023,22 +1013,12 @@ Optimizer::PassToken CreateUpgradeMemoryModelPass() {
       MakeUnique<opt::UpgradeMemoryModel>());
 }
 
-Optimizer::PassToken CreateInstBindlessCheckPass(uint32_t shader_id) {
-  return MakeUnique<Optimizer::PassToken::Impl>(
-      MakeUnique<opt::InstBindlessCheckPass>(shader_id));
-}
-
 Optimizer::PassToken CreateInstDebugPrintfPass(uint32_t desc_set,
                                                uint32_t shader_id) {
   return MakeUnique<Optimizer::PassToken::Impl>(
       MakeUnique<opt::InstDebugPrintfPass>(desc_set, shader_id));
 }
 
-Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t shader_id) {
-  return MakeUnique<Optimizer::PassToken::Impl>(
-      MakeUnique<opt::InstBuffAddrCheckPass>(shader_id));
-}
-
 Optimizer::PassToken CreateConvertRelaxedToHalfPass() {
   return MakeUnique<Optimizer::PassToken::Impl>(
       MakeUnique<opt::ConvertToHalfPass>());

+ 0 - 2
3rdparty/spirv-tools/source/opt/passes.h

@@ -48,8 +48,6 @@
 #include "source/opt/if_conversion.h"
 #include "source/opt/inline_exhaustive_pass.h"
 #include "source/opt/inline_opaque_pass.h"
-#include "source/opt/inst_bindless_check_pass.h"
-#include "source/opt/inst_buff_addr_check_pass.h"
 #include "source/opt/inst_debug_printf_pass.h"
 #include "source/opt/interface_var_sroa.h"
 #include "source/opt/interp_fixup_pass.h"

+ 2 - 1
3rdparty/spirv-tools/source/opt/trim_capabilities_pass.h

@@ -98,7 +98,8 @@ class TrimCapabilitiesPass : public Pass {
       spv::Capability::StoragePushConstant16,
       spv::Capability::StorageUniform16,
       spv::Capability::StorageUniformBufferBlock16,
-      spv::Capability::VulkanMemoryModelDeviceScope
+      spv::Capability::VulkanMemoryModelDeviceScope,
+      spv::Capability::GroupNonUniformPartitionedNV
       // clang-format on
   };
 

+ 18 - 1
3rdparty/spirv-tools/source/val/validate_decorations.cpp

@@ -623,6 +623,14 @@ spv_result_t checkLayout(uint32_t struct_id, const char* storage_class_str,
 
           seen[next_offset % 16] = true;
         }
+      } else if (spv::Op::OpTypeMatrix == element_inst->opcode()) {
+        // Matrix stride would be on the array element in the struct.
+        const auto stride = constraint.matrix_stride;
+        if (!IsAlignedTo(stride, alignment)) {
+          return fail(memberIdx)
+                 << "is a matrix with stride " << stride
+                 << " not satisfying alignment to " << alignment;
+        }
       }
 
       // Proceed to the element in case it is an array.
@@ -675,7 +683,16 @@ bool checkForRequiredDecoration(uint32_t struct_id,
                                 spv::Op type, ValidationState_t& vstate) {
   const auto& members = getStructMembers(struct_id, vstate);
   for (size_t memberIdx = 0; memberIdx < members.size(); memberIdx++) {
-    const auto id = members[memberIdx];
+    auto id = members[memberIdx];
+    if (type == spv::Op::OpTypeMatrix) {
+      // Matrix decorations also apply to arrays of matrices.
+      auto memberInst = vstate.FindDef(id);
+      while (memberInst->opcode() == spv::Op::OpTypeArray ||
+             memberInst->opcode() == spv::Op::OpTypeRuntimeArray) {
+        memberInst = vstate.FindDef(memberInst->GetOperandAs<uint32_t>(1u));
+      }
+      id = memberInst->id();
+    }
     if (type != vstate.FindDef(id)->opcode()) continue;
     bool found = false;
     for (auto& dec : vstate.id_decorations(id)) {

+ 63 - 12
3rdparty/spirv-tools/source/val/validate_image.cpp

@@ -914,7 +914,15 @@ spv_result_t ValidateTypeImage(ValidationState_t& _, const Instruction* inst) {
 
     if (info.dim == spv::Dim::SubpassData && info.arrayed != 0) {
       return _.diag(SPV_ERROR_INVALID_DATA, inst)
-             << _.VkErrorID(6214) << "Dim SubpassData requires Arrayed to be 0";
+             << _.VkErrorID(6214)
+             << "Dim SubpassData requires Arrayed to be 0 in the Vulkan "
+                "environment";
+    }
+
+    if (info.dim == spv::Dim::Rect) {
+      return _.diag(SPV_ERROR_INVALID_DATA, inst)
+             << _.VkErrorID(9638)
+             << "Dim must not be Rect in the Vulkan environment";
     }
   }
 
@@ -2161,7 +2169,8 @@ spv_result_t ValidateImageProcessingQCOMDecoration(ValidationState_t& _, int id,
                                                    spv::Decoration decor) {
   const Instruction* si_inst = nullptr;
   const Instruction* ld_inst = _.FindDef(id);
-  if (ld_inst->opcode() == spv::Op::OpSampledImage) {
+  bool is_intf_obj = (ld_inst->opcode() == spv::Op::OpSampledImage);
+  if (is_intf_obj == true) {
     si_inst = ld_inst;
     int t_idx = si_inst->GetOperandAs<int>(2);  // texture
     ld_inst = _.FindDef(t_idx);
@@ -2178,6 +2187,56 @@ spv_result_t ValidateImageProcessingQCOMDecoration(ValidationState_t& _, int id,
   return SPV_SUCCESS;
 }
 
+spv_result_t ValidateImageProcessing2QCOMWindowDecoration(ValidationState_t& _,
+                                                          int id) {
+  const Instruction* ld_inst = _.FindDef(id);
+  bool is_intf_obj = (ld_inst->opcode() != spv::Op::OpSampledImage);
+  if (is_intf_obj == true) {
+    if (ld_inst->opcode() != spv::Op::OpLoad) {
+      return _.diag(SPV_ERROR_INVALID_DATA, ld_inst) << "Expect to see OpLoad";
+    }
+    int texture_id = ld_inst->GetOperandAs<int>(2);  // variable to load
+    spv::Decoration decor = spv::Decoration::BlockMatchTextureQCOM;
+    if (!_.HasDecoration(texture_id, decor)) {
+      return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
+             << "Missing decoration " << _.SpvDecorationString(decor);
+    }
+    decor = spv::Decoration::BlockMatchSamplerQCOM;
+    if (!_.HasDecoration(texture_id, decor)) {
+      return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
+             << "Missing decoration " << _.SpvDecorationString(decor);
+    }
+  } else {
+    const Instruction* si_inst = ld_inst;
+    int t_idx = si_inst->GetOperandAs<int>(2);  // texture
+    const Instruction* t_ld_inst = _.FindDef(t_idx);
+    if (t_ld_inst->opcode() != spv::Op::OpLoad) {
+      return _.diag(SPV_ERROR_INVALID_DATA, t_ld_inst)
+             << "Expect to see OpLoad";
+    }
+    int texture_id = t_ld_inst->GetOperandAs<int>(2);  // variable to load
+    spv::Decoration decor = spv::Decoration::BlockMatchTextureQCOM;
+    if (!_.HasDecoration(texture_id, decor)) {
+      return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
+             << "Missing decoration " << _.SpvDecorationString(decor);
+    }
+    int s_idx = si_inst->GetOperandAs<int>(3);  // sampler
+    const Instruction* s_ld_inst = _.FindDef(s_idx);
+    if (s_ld_inst->opcode() != spv::Op::OpLoad) {
+      return _.diag(SPV_ERROR_INVALID_DATA, s_ld_inst)
+             << "Expect to see OpLoad";
+    }
+    int sampler_id = s_ld_inst->GetOperandAs<int>(2);  // variable to load
+    decor = spv::Decoration::BlockMatchSamplerQCOM;
+    if (!_.HasDecoration(sampler_id, decor)) {
+      return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
+             << "Missing decoration " << _.SpvDecorationString(decor);
+    }
+  }
+
+  return SPV_SUCCESS;
+}
+
 spv_result_t ValidateImageProcessingQCOM(ValidationState_t& _,
                                          const Instruction* inst) {
   spv_result_t res = SPV_SUCCESS;
@@ -2203,18 +2262,10 @@ spv_result_t ValidateImageProcessingQCOM(ValidationState_t& _,
     case spv::Op::OpImageBlockMatchWindowSSDQCOM:
     case spv::Op::OpImageBlockMatchWindowSADQCOM: {
       int tgt_idx = inst->GetOperandAs<int>(2);  // target
-      res = ValidateImageProcessingQCOMDecoration(
-          _, tgt_idx, spv::Decoration::BlockMatchTextureQCOM);
-      if (res != SPV_SUCCESS) break;
-      res = ValidateImageProcessingQCOMDecoration(
-          _, tgt_idx, spv::Decoration::BlockMatchSamplerQCOM);
+      res = ValidateImageProcessing2QCOMWindowDecoration(_, tgt_idx);
       if (res != SPV_SUCCESS) break;
       int ref_idx = inst->GetOperandAs<int>(4);  // reference
-      res = ValidateImageProcessingQCOMDecoration(
-          _, ref_idx, spv::Decoration::BlockMatchTextureQCOM);
-      if (res != SPV_SUCCESS) break;
-      res = ValidateImageProcessingQCOMDecoration(
-          _, ref_idx, spv::Decoration::BlockMatchSamplerQCOM);
+      res = ValidateImageProcessing2QCOMWindowDecoration(_, ref_idx);
       break;
     }
     case spv::Op::OpImageBlockMatchGatherSSDQCOM:

+ 22 - 0
3rdparty/spirv-tools/source/val/validate_interfaces.cpp

@@ -519,6 +519,8 @@ spv_result_t ValidateLocations(ValidationState_t& _,
   std::unordered_set<uint32_t> input_locations;
   std::unordered_set<uint32_t> output_locations_index0;
   std::unordered_set<uint32_t> output_locations_index1;
+  std::unordered_set<uint32_t> patch_locations_index0;
+  std::unordered_set<uint32_t> patch_locations_index1;
   std::unordered_set<uint32_t> seen;
   for (uint32_t i = 3; i < entry_point->operands().size(); ++i) {
     auto interface_id = entry_point->GetOperandAs<uint32_t>(i);
@@ -534,6 +536,26 @@ spv_result_t ValidateLocations(ValidationState_t& _,
       continue;
     }
 
+    // The two Tessellation stages have a "Patch" variable that interface with
+    // the Location mechanism, but are not suppose to be tied to the "normal"
+    // input/output Location.
+    // TODO - SPIR-V allows the Patch decoration to be applied to struct
+    // members, but is not allowed in GLSL/HLSL
+    bool has_patch = false;
+    for (auto& dec : _.id_decorations(interface_var->id())) {
+      if (dec.dec_type() == spv::Decoration::Patch) {
+        has_patch = true;
+        if (auto error = GetLocationsForVariable(_, entry_point, interface_var,
+                                                 &patch_locations_index0,
+                                                 &patch_locations_index1))
+          return error;
+        break;
+      }
+    }
+    if (has_patch) {
+      continue;
+    }
+
     auto locations = (storage_class == spv::StorageClass::Input)
                          ? &input_locations
                          : &output_locations_index0;

+ 2 - 1
3rdparty/spirv-tools/source/val/validate_memory.cpp

@@ -349,7 +349,8 @@ spv_result_t CheckMemoryAccess(ValidationState_t& _, const Instruction* inst,
 
   if (mask & uint32_t(spv::MemoryAccessMask::MakePointerVisibleKHR)) {
     if (inst->opcode() == spv::Op::OpStore ||
-        inst->opcode() == spv::Op::OpCooperativeMatrixStoreNV) {
+        inst->opcode() == spv::Op::OpCooperativeMatrixStoreNV ||
+        inst->opcode() == spv::Op::OpCooperativeMatrixStoreKHR) {
       return _.diag(SPV_ERROR_INVALID_ID, inst)
              << "MakePointerVisibleKHR cannot be used with OpStore.";
     }

+ 16 - 4
3rdparty/spirv-tools/source/val/validate_misc.cpp

@@ -50,10 +50,22 @@ spv_result_t ValidateShaderClock(ValidationState_t& _,
   bool is_int32 = false, is_const_int32 = false;
   uint32_t value = 0;
   std::tie(is_int32, is_const_int32, value) = _.EvalInt32IfConst(scope);
-  if (is_const_int32 && spv::Scope(value) != spv::Scope::Subgroup &&
-      spv::Scope(value) != spv::Scope::Device) {
-    return _.diag(SPV_ERROR_INVALID_DATA, inst)
-           << _.VkErrorID(4652) << "Scope must be Subgroup or Device";
+  if (is_const_int32) {
+    spv::Scope scope_val{value};
+    if (spvIsVulkanEnv(_.context()->target_env)) {
+      if (scope_val != spv::Scope::Subgroup &&
+          scope_val != spv::Scope::Device) {
+        return _.diag(SPV_ERROR_INVALID_DATA, inst)
+               << _.VkErrorID(4652) << "Scope must be Subgroup or Device";
+      }
+    } else if (spvIsOpenCLEnv(_.context()->target_env)) {
+      if (scope_val != spv::Scope::Workgroup &&
+          scope_val != spv::Scope::Subgroup &&
+          scope_val != spv::Scope::Device) {
+        return _.diag(SPV_ERROR_INVALID_DATA, inst)
+               << "Scope must be Subgroup, Workgroup, or Device";
+      }
+    }
   }
 
   // Result Type must be a 64 - bit unsigned integer type or

+ 2 - 0
3rdparty/spirv-tools/source/val/validation_state.cpp

@@ -2351,6 +2351,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
       return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-08722);
     case 8973:
       return VUID_WRAP(VUID-StandaloneSpirv-Pointer-08973);
+    case 9638:
+      return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-09638);
     default:
       return "";  // unknown id
   }