]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/module.cpp
Always set uniform array size to at least one
[libs/gl.git] / source / core / module.cpp
index 601aae99c8952e355016562d4589e333cfbd2798..4afbc53403d4f283cd57277a5436a64775b1bc3e 100644 (file)
@@ -37,6 +37,7 @@ enum SpirVConstants
        DECO_SPEC_ID = 1,
        DECO_ARRAY_STRIDE = 6,
        DECO_MATRIX_STRIDE = 7,
+       DECO_BUILTIN = 11,
        DECO_LOCATION = 30,
        DECO_BINDING = 33,
        DECO_DESCRIPTOR_SET = 34,
@@ -117,7 +118,7 @@ void SpirVModule::remap_pointers_from(const SpirVModule &other)
 
 void SpirVModule::load_code(IO::Base &io)
 {
-       UInt32 buffer[1024];
+       uint32_t buffer[1024];
        while(1)
        {
                unsigned len = io.read(reinterpret_cast<char *>(buffer), sizeof(buffer));
@@ -145,7 +146,7 @@ void SpirVModule::reflect()
 
        if(code[0]==SPIRV_MAGIC_REVERSED)
        {
-               for(UInt32 &c: code)
+               for(uint32_t &c: code)
                        c = ((c&0xFF)<<24) || ((c&0xFF00)<<8) | ((c>>8)&0xFF00) | ((c>>24)&0xFF);
        }
        else if(code[0]!=SPIRV_MAGIC)
@@ -245,30 +246,6 @@ void SpirVModule::reflect()
 }
 
 
-SpirVModule::EntryPoint::EntryPoint():
-       stage(VERTEX)
-{ }
-
-
-SpirVModule::StructMember::StructMember():
-       type(VOID),
-       struct_type(0),
-       offset(0),
-       array_size(0),
-       array_size_spec(0),
-       array_stride(0),
-       matrix_stride(0)
-{ }
-
-
-SpirVModule::Variable::Variable():
-       type(VOID),
-       struct_type(0),
-       location(-1),
-       descriptor_set(-1),
-       binding(-1)
-{ }
-
 bool SpirVModule::Variable::operator==(const Variable &other) const
 {
        if(storage!=UNIFORM_CONSTANT && storage!=UNIFORM)
@@ -281,17 +258,7 @@ bool SpirVModule::Variable::operator==(const Variable &other) const
 }
 
 
-SpirVModule::TypeInfo::TypeInfo():
-       type(VOID),
-       struct_type(0),
-       array_size_spec(0),
-       array_size(0),
-       array_stride(0),
-       storage(static_cast<StorageClass>(-1))
-{ }
-
-
-UInt32 SpirVModule::Reflection::get_opcode(UInt32 op)
+uint32_t SpirVModule::Reflection::get_opcode(uint32_t op)
 {
        return op&0xFFFF;
 }
@@ -323,7 +290,7 @@ string SpirVModule::Reflection::read_string(CodeIterator &op, const CodeIterator
        throw invalid_module("Unterminated SPIR-V string literal");
 }
 
-void SpirVModule::Reflection::reflect_code(const vector<UInt32> &code)
+void SpirVModule::Reflection::reflect_code(const vector<uint32_t> &code)
 {
        for(CodeIterator op=code.begin()+5; op!=code.end(); )
        {
@@ -341,7 +308,7 @@ void SpirVModule::Reflection::reflect_code(const vector<UInt32> &code)
                case OP_TYPE_INT: reflect_int_type(op); break;
                case OP_TYPE_FLOAT: reflect_float_type(op); break;
                case OP_TYPE_VECTOR: reflect_vector_type(op); break;
-               case OP_TYPE_MATRIX: reflect_vector_type(op); break;
+               case OP_TYPE_MATRIX: reflect_matrix_type(op); break;
                case OP_TYPE_IMAGE: reflect_image_type(op); break;
                case OP_TYPE_SAMPLED_IMAGE: reflect_sampled_image_type(op); break;
                case OP_TYPE_ARRAY: reflect_array_type(op); break;
@@ -424,7 +391,7 @@ void SpirVModule::Reflection::reflect_vector_type(CodeIterator op)
        TypeInfo &type = types[*(op+1)];
        DataType component = types[*(op+2)].type;
        unsigned count = *(op+3);
-       type.type = static_cast<DataType>((count<<12) | (component&0xF00) | ((component&0xFF)*count));
+       type.type = static_cast<DataType>(((count-1)<<12) | (component&0xF00) | ((component&0xFF)*count));
 }
 
 void SpirVModule::Reflection::reflect_matrix_type(CodeIterator op)
@@ -432,7 +399,7 @@ void SpirVModule::Reflection::reflect_matrix_type(CodeIterator op)
        TypeInfo &type = types[*(op+1)];
        DataType column = types[*(op+2)].type;
        unsigned count = *(op+3);
-       type.type = static_cast<DataType>((count<<16) | (column&0xF00) | ((column&0xFF)*count));
+       type.type = static_cast<DataType>(((count-1)<<14) | (column&0x3F00) | ((column&0xFF)*count));
 }
 
 void SpirVModule::Reflection::reflect_image_type(CodeIterator op)
@@ -538,6 +505,9 @@ void SpirVModule::Reflection::reflect_decorate(CodeIterator op)
        case DECO_ARRAY_STRIDE:
                types[id].array_stride = *op;
                break;
+       case DECO_BUILTIN:
+               variables[id].builtin = static_cast<BuiltinSemantic>(*op);
+               break;
        case DECO_LOCATION:
                variables[id].location = *op;
                break;
@@ -565,6 +535,9 @@ void SpirVModule::Reflection::reflect_member_decorate(CodeIterator op)
        case DECO_MATRIX_STRIDE:
                member.matrix_stride = *op;
                break;
+       case DECO_BUILTIN:
+               member.builtin = static_cast<BuiltinSemantic>(*op);
+               break;
        case DECO_OFFSET:
                member.offset = *op;
                break;