Răsfoiți Sursa

shaderpipeline: Fix `remove_unused_variables()` corrupting SPIR-V

rdb 2 ani în urmă
părinte
comite
05fbb1f708
1 a modificat fișierele cu 24 adăugiri și 0 ștergeri
  1. 24 0
      panda/src/shaderpipeline/shaderModuleSpirV.cxx

+ 24 - 0
panda/src/shaderpipeline/shaderModuleSpirV.cxx

@@ -907,6 +907,28 @@ remove_unused_variables() {
     Instruction op = *it;
 
     switch (op.opcode) {
+    case spv::OpEntryPoint:
+      {
+        // Skip the string literal by skipping words until we have a zero byte.
+        uint32_t i = 2;
+        while (i < op.nargs
+            && (op.args[i] & 0x000000ff) != 0
+            && (op.args[i] & 0x0000ff00) != 0
+            && (op.args[i] & 0x00ff0000) != 0
+            && (op.args[i] & 0xff000000) != 0) {
+          ++i;
+        }
+        // Remove the deleted IDs from the entry point interface.
+        while (i < (*it).nargs) {
+          if (delete_ids.count((*it).args[i])) {
+            it = _instructions.erase_arg(it, i);
+          } else {
+            ++i;
+          }
+        }
+      }
+      break;
+
     case spv::OpName:
     case spv::OpMemberName:
     case spv::OpDecorate:
@@ -921,6 +943,7 @@ remove_unused_variables() {
     case spv::OpVariable:
       if (op.nargs >= 2 && delete_ids.count(op.args[1])) {
         it = _instructions.erase(it);
+        continue;
       }
       break;
 
@@ -934,6 +957,7 @@ remove_unused_variables() {
       if (delete_ids.count(op.args[2])) {
         delete_ids.insert(op.args[1]);
         it = _instructions.erase(it);
+        continue;
       }
       break;