]> git.tdb.fi Git - libs/gl.git/commitdiff
Handle OpPhi when specializing SPIR-V modules
authorMikko Rasa <tdb@tdb.fi>
Mon, 3 Oct 2022 20:43:33 +0000 (23:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 3 Oct 2022 22:24:29 +0000 (01:24 +0300)
source/core/module.cpp

index 5a7369147c104558f89eebf717ef87d840db3cb5..04a37fcc3d7bd25265160b9117c5975a734a1e42 100644 (file)
@@ -38,6 +38,8 @@ enum SpirVConstants
        OP_ACCESS_CHAIN = 65,
        OP_DECORATE = 71,
        OP_MEMBER_DECORATE = 72,
+       OP_COPY_OBJECT = 83,
+       OP_PHI = 245,
        OP_SELECTION_MERGE = 247,
        OP_LABEL = 248,
        OP_BRANCH = 249,
@@ -393,6 +395,26 @@ SpirVModule *SpirVModule::specialize(const map<string, int> &spec_values) const
                                        }
                                }
                        }
+                       else if(opcode==OP_PHI)
+                       {
+                               unsigned active_count = 0;
+                               unsigned result_id = 0;
+                               for(unsigned i=3; i<word_count; i+=2)
+                                       if(flags[*(op+i+1)])
+                                       {
+                                               ++active_count;
+                                               result_id = *(op+i);
+                                       }
+
+                               if(active_count==1)
+                               {
+                                       new_code.push_back(0x40000 | OP_COPY_OBJECT);
+                                       new_code.push_back(*(op+1));
+                                       new_code.push_back(*(op+2));
+                                       new_code.push_back(result_id);
+                                       copy = false;
+                               }
+                       }
                }
 
                if(copy)