MCPcopy Create free account
hub / github.com/BabylonJS/BabylonNative / AppendUniformBuffer

Function AppendUniformBuffer

Plugins/NativeEngine/Source/NativeEngine.cpp:61–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 }
60
61 void AppendUniformBuffer(std::vector<uint8_t>& bytes, const spirv_cross::Compiler& compiler, const spirv_cross::Resource& uniformBuffer, bool isFragment)
62 {
63 const uint8_t fragmentBit = (isFragment ? BGFX_UNIFORM_FRAGMENTBIT : 0);
64
65 const spirv_cross::SPIRType& type = compiler.get_type(uniformBuffer.base_type_id);
66 for (uint32_t index = 0; index < type.member_types.size(); ++index)
67 {
68 auto name = compiler.get_member_name(uniformBuffer.base_type_id, index);
69 auto offset = compiler.get_member_decoration(uniformBuffer.base_type_id, index, spv::DecorationOffset);
70 auto memberType = compiler.get_type(type.member_types[index]);
71
72 bgfx::UniformType::Enum bgfxType;
73 uint16_t regCount;
74
75 if (memberType.basetype != spirv_cross::SPIRType::Float)
76 {
77 throw std::exception(); // Not supported
78 }
79
80 if (memberType.columns == 1 && 1 <= memberType.vecsize && memberType.vecsize <= 4)
81 {
82 bgfxType = bgfx::UniformType::Vec4;
83 regCount = 1;
84 }
85 else if (memberType.columns == 4 && memberType.vecsize == 4)
86 {
87 bgfxType = bgfx::UniformType::Mat4;
88 regCount = 4;
89 }
90 else
91 {
92 throw std::exception();
93 }
94
95 for (const auto size : memberType.array)
96 {
97 regCount *= static_cast<uint16_t>(size);
98 }
99
100 AppendBytes(bytes, static_cast<uint8_t>(name.size()));
101 AppendBytes(bytes, name);
102 AppendBytes(bytes, static_cast<uint8_t>(bgfxType | fragmentBit));
103 AppendBytes(bytes, static_cast<uint8_t>(0)); // Value "num" not used by D3D11 pipeline.
104 AppendBytes(bytes, static_cast<uint16_t>(offset));
105 AppendBytes(bytes, static_cast<uint16_t>(regCount));
106 }
107 }
108
109 void AppendSamplers(std::vector<uint8_t>& bytes, const spirv_cross::Compiler& compiler, const spirv_cross::SmallVector<spirv_cross::Resource>& samplers, bool /*isFragment*/, std::unordered_map<std::string, UniformInfo>& cache)
110 {

Callers 1

CreateProgramMethod · 0.85

Calls 1

AppendBytesFunction · 0.85

Tested by

no test coverage detected