Бранимир Караџић 5 лет назад
Родитель
Сommit
d99a5b2f91

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

@@ -1 +1 @@
-"v2020.6", "SPIRV-Tools v2020.6 8c2b99d81e7a2a212e18d68f42f6e85763705093"
+"v2020.6", "SPIRV-Tools v2020.6 25b32b391d8d2cf07c95edd7d164911cb00b4bc5"

+ 2 - 1
3rdparty/spirv-tools/include/generated/generators.inc

@@ -23,4 +23,5 @@
 {22, "Google", "MLIR SPIR-V Serializer", "Google MLIR SPIR-V Serializer"},
 {23, "Google", "Tint Compiler", "Google Tint Compiler"},
 {24, "Google", "ANGLE Shader Compiler", "Google ANGLE Shader Compiler"},
-{25, "Netease Games", "Messiah Shader Compiler", "Netease Games Messiah Shader Compiler"},
+{25, "Netease Games", "Messiah Shader Compiler", "Netease Games Messiah Shader Compiler"},
+{26, "Xenia", "Xenia Emulator Microcode Translator", "Xenia Xenia Emulator Microcode Translator"},

+ 31 - 8
3rdparty/spirv-tools/source/opt/debug_info_manager.cpp

@@ -40,6 +40,7 @@ static const uint32_t kDebugLocalVariableOperandParentIndex = 9;
 static const uint32_t kExtInstInstructionInIdx = 1;
 static const uint32_t kDebugGlobalVariableOperandFlagsIndex = 12;
 static const uint32_t kDebugLocalVariableOperandFlagsIndex = 10;
+static const uint32_t kDebugLocalVariableOperandArgNumberIndex = 11;
 
 namespace spvtools {
 namespace opt {
@@ -440,15 +441,27 @@ bool DebugInfoManager::IsAncestorOfScope(uint32_t scope, uint32_t ancestor) {
   return false;
 }
 
-bool DebugInfoManager::IsDeclareVisibleToInstr(Instruction* dbg_declare,
-                                               uint32_t instr_scope_id) {
-  if (instr_scope_id == kNoDebugScope) return false;
-
+Instruction* DebugInfoManager::GetDebugLocalVariableFromDeclare(
+    Instruction* dbg_declare) {
+  assert(dbg_declare);
   uint32_t dbg_local_var_id =
       dbg_declare->GetSingleWordOperand(kDebugDeclareOperandLocalVariableIndex);
   auto dbg_local_var_itr = id_to_dbg_inst_.find(dbg_local_var_id);
   assert(dbg_local_var_itr != id_to_dbg_inst_.end());
-  uint32_t decl_scope_id = dbg_local_var_itr->second->GetSingleWordOperand(
+  return dbg_local_var_itr->second;
+}
+
+bool DebugInfoManager::IsFunctionParameter(Instruction* dbg_local_var) const {
+  // If a DebugLocalVariable has ArgNumber operand, it is a function parameter.
+  return dbg_local_var->NumOperands() >
+         kDebugLocalVariableOperandArgNumberIndex;
+}
+
+bool DebugInfoManager::IsLocalVariableVisibleToInstr(Instruction* dbg_local_var,
+                                                     uint32_t instr_scope_id) {
+  if (instr_scope_id == kNoDebugScope) return false;
+
+  uint32_t decl_scope_id = dbg_local_var->GetSingleWordOperand(
       kDebugLocalVariableOperandParentIndex);
 
   // If the scope of DebugDeclare is an ancestor scope of the instruction's
@@ -502,11 +515,20 @@ void DebugInfoManager::AddDebugValueIfVarDeclIsVisible(
 
   uint32_t instr_scope_id = scope_and_line->GetDebugScope().GetLexicalScope();
   for (auto* dbg_decl_or_val : dbg_decl_itr->second) {
-    if (!IsDeclareVisibleToInstr(dbg_decl_or_val, instr_scope_id)) continue;
+    // If it declares a function parameter, the store instruction for the
+    // function parameter can exist out of the function parameter's scope
+    // because of the function inlining. We always add DebugValue for a
+    // function parameter next to the DebugDeclare regardless of the scope.
+    auto* dbg_local_var = GetDebugLocalVariableFromDeclare(dbg_decl_or_val);
+    bool is_function_param = IsFunctionParameter(dbg_local_var);
+    if (!is_function_param &&
+        !IsLocalVariableVisibleToInstr(dbg_local_var, instr_scope_id))
+      continue;
 
     // Avoid inserting the new DebugValue between OpPhi or OpVariable
     // instructions.
-    Instruction* insert_before = insert_pos->NextNode();
+    Instruction* insert_before = is_function_param ? dbg_decl_or_val->NextNode()
+                                                   : insert_pos->NextNode();
     while (insert_before->opcode() == SpvOpPhi ||
            insert_before->opcode() == SpvOpVariable) {
       insert_before = insert_before->NextNode();
@@ -523,7 +545,8 @@ void DebugInfoManager::AddDebugValueIfVarDeclIsVisible(
                                    kDebugValueOperandLocalVariableIndex),
                                value_id, 0, index_id, insert_before);
     assert(added_dbg_value != nullptr);
-    added_dbg_value->UpdateDebugInfoFrom(scope_and_line);
+    added_dbg_value->UpdateDebugInfoFrom(is_function_param ? dbg_decl_or_val
+                                                           : scope_and_line);
     AnalyzeDebugInst(added_dbg_value);
   }
 }

+ 11 - 4
3rdparty/spirv-tools/source/opt/debug_info_manager.h

@@ -215,10 +215,17 @@ class DebugInfoManager {
   // of |scope|.
   bool IsAncestorOfScope(uint32_t scope, uint32_t ancestor);
 
-  // Returns true if the declaration of a local variable |dbg_declare|
-  // is visible in the scope of an instruction |instr_scope_id|.
-  bool IsDeclareVisibleToInstr(Instruction* dbg_declare,
-                               uint32_t instr_scope_id);
+  // Returns the DebugLocalVariable declared by |dbg_declare|.
+  Instruction* GetDebugLocalVariableFromDeclare(Instruction* dbg_declare);
+
+  // Returns true if the DebugLocalVariable |dbg_local_var| is a function
+  // parameter.
+  bool IsFunctionParameter(Instruction* dbg_local_var) const;
+
+  // Returns true if the DebugLocalVariable |dbg_local_var| is visible
+  // in the scope of an instruction |instr_scope_id|.
+  bool IsLocalVariableVisibleToInstr(Instruction* dbg_local_var,
+                                     uint32_t instr_scope_id);
 
   // Returns the parent scope of the scope |child_scope|.
   uint32_t GetParentScope(uint32_t child_scope);