]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/module.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / module.cpp
index f42a0da76a17d75f30c2da746fcf35f061a8e1ae..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,
@@ -48,6 +50,8 @@ enum SpirVConstants
        OP_RETURN_VALUE = 254,
        OP_UNREACHABLE = 255,
 
+       EXEC_LOCAL_SIZE = 17,
+
        DECO_SPEC_ID = 1,
        DECO_ARRAY_STRIDE = 6,
        DECO_MATRIX_STRIDE = 7,
@@ -313,12 +317,13 @@ SpirVModule *SpirVModule::specialize(const map<string, int> &spec_values) const
                                unsigned func_id = *(op+2);
                                new_code.push_back(func_id);
 
-                               unsigned i=3;
+                               unsigned i = 3;
                                while(i<word_count)
                                {
                                        unsigned word = *(op+i++);
                                        new_code.push_back(word);
-                                       if(!(word&(word>>8)&(word>>16)&(word>>24)&0xFF))
+                                       // Strings are nul-terminated and nul-padded
+                                       if(!(word>>24))
                                                break;
                                }
 
@@ -390,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)
@@ -513,6 +538,7 @@ void SpirVModule::Reflection::reflect_code(const vector<uint32_t> &code)
                case OP_NAME: reflect_name(op); break;
                case OP_MEMBER_NAME: reflect_member_name(op); break;
                case OP_ENTRY_POINT: reflect_entry_point(op); break;
+               case OP_EXECUTION_MODE: reflect_execution_mode(op); break;
                case OP_TYPE_VOID: reflect_void_type(op); break;
                case OP_TYPE_BOOL: reflect_bool_type(op); break;
                case OP_TYPE_INT: reflect_int_type(op); break;
@@ -579,6 +605,18 @@ void SpirVModule::Reflection::reflect_entry_point(CodeIterator op)
                entry.globals.push_back(&variables[*op]);
 }
 
+void SpirVModule::Reflection::reflect_execution_mode(CodeIterator op)
+{
+       EntryPoint &entry = entry_points[*(op+1)];
+       unsigned mode = *(op+2);
+       if(mode==EXEC_LOCAL_SIZE)
+       {
+               entry.compute_local_size.x = *(op+3);
+               entry.compute_local_size.y = *(op+4);
+               entry.compute_local_size.z = *(op+5);
+       }
+}
+
 void SpirVModule::Reflection::reflect_void_type(CodeIterator op)
 {
        types[*(op+1)].type = VOID;
@@ -623,11 +661,13 @@ void SpirVModule::Reflection::reflect_matrix_type(CodeIterator op)
 void SpirVModule::Reflection::reflect_image_type(CodeIterator op)
 {
        TypeInfo &type = types[*(op+1)];
-       DataType sample = types[*(op+2)].type;
+       DataType sample_type = types[*(op+2)].type;
        unsigned dimensions = *(op+3);
        bool depth = *(op+4)==1;
        bool array = *(op+5);
-       type.type = static_cast<DataType>((depth*0x200000) | (array*0x80000) | ((dimensions+1)<<16) | sample);
+       bool sampled = *(op+7)==1;
+       type.type = static_cast<DataType>((depth*0x200000) | (sampled*0x100000) | (array*0x80000) |
+               ((dimensions+1)<<16) | sample_type);
 }
 
 void SpirVModule::Reflection::reflect_sampled_image_type(CodeIterator op)