]> git.tdb.fi Git - libs/gl.git/blob - source/core/reflectdata.cpp
Create specialized versions of SPIR-V modules with default spec values
[libs/gl.git] / source / core / reflectdata.cpp
1 #include <msp/core/algorithm.h>
2 #include <msp/core/hash.h>
3 #include <msp/strings/format.h>
4 #include "reflectdata.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 void ReflectData::update_layout_hash()
12 {
13         layout_hash = hash<32>(uniform_blocks.size());
14         for(const UniformBlockInfo &b: uniform_blocks)
15         {
16                 layout_hash = hash_update<32>(layout_hash, b.bind_point);
17                 layout_hash = hash_update<32>(layout_hash, b.layout_hash);
18         }
19 }
20
21 void ReflectData::update_used_bindings()
22 {
23         for(const UniformInfo &u: uniforms)
24                 if(u.binding>=0 && is_image(u.type))
25                         used_bindings.push_back(u.binding|TEXTURE_BINDING);
26         for(const UniformBlockInfo &b: uniform_blocks)
27                 used_bindings.push_back(b.bind_point|UNIFORM_BLOCK_BINDING);
28         sort(used_bindings);
29 }
30
31
32 void ReflectData::UniformBlockInfo::sort_uniforms()
33 {
34         sort(uniforms, [](const UniformInfo *u1, const UniformInfo *u2){ return u1->location<u2->location; });
35 }
36
37 void ReflectData::UniformBlockInfo::update_layout_hash()
38 {
39         layout_hash = hash<32>(uniforms.size());
40         for(const UniformInfo *u: uniforms)
41         {
42                 layout_hash = hash_update<32>(layout_hash, u->location);
43                 layout_hash = hash_update<32>(layout_hash, u->name);
44                 layout_hash = hash_update<32>(layout_hash, u->type);
45                 layout_hash = hash_update<32>(layout_hash, u->array_size);
46         }
47 }
48
49 } // namespace GL
50 } // namespace Msp