yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeCache and reuse glsl module. (#6152)8000e0ede

master
1.6 KiB64 linesraw
1#include "decoder-helper.h"
2
3#include "parameter-decoder.h"
4
5#include <cstdlib>
6#include <vector>
7
8namespace SlangRecord
9{
10DecoderAllocatorSingleton* DecoderAllocatorSingleton::getInstance()
11{
12    thread_local DecoderAllocatorSingleton instance;
13    return &instance;
14}
15
16void* DecoderAllocatorSingleton::allocate(size_t size)
17{
18    void* data = calloc(1, size);
19
20    if (!data)
21    {
22        slangRecordLog(LogLevel::Error, "Failed to allocate memory\n");
23        std::abort();
24    }
25
26    m_allocations.add(data);
27    return data;
28}
29
30DecoderAllocatorSingleton::~DecoderAllocatorSingleton()
31{
32    for (auto allocation : m_allocations)
33    {
34        free(allocation);
35    }
36}
37
38template<typename T, typename U>
39size_t StructDecoder<T, U>::decode(const uint8_t* buffer, int64_t bufferSize)
40{
41    return ParameterDecoder::decodeStruct(buffer, bufferSize, *this);
42}
43
44size_t BlobDecoder::decode(const uint8_t* buffer, int64_t bufferSize)
45{
46    size_t readByte = 0;
47    readByte = ParameterDecoder::decodeAddress(buffer, bufferSize, m_address);
48
49    if (!m_address)
50    {
51        readByte +=
52            ParameterDecoder::decodePointer(buffer + readByte, bufferSize - readByte, m_blobData);
53    }
54    return readByte;
55}
56
57template class StructDecoder<SlangGlobalSessionDesc>;
58template class StructDecoder<slang::SessionDesc>;
59template class StructDecoder<slang::PreprocessorMacroDesc>;
60template class StructDecoder<slang::CompilerOptionEntry>;
61template class StructDecoder<slang::CompilerOptionValue>;
62template class StructDecoder<slang::TargetDesc>;
63template class StructDecoder<slang::SpecializationArg>;
64} // namespace SlangRecord