MCPcopy Create free account
hub / github.com/a2flo/floor / load_binary

Function load_binary

compute/spirv_handler.cpp:25–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace spirv_handler {
24
25unique_ptr<uint32_t[]> load_binary(const string& file_name, size_t& code_size) {
26 unique_ptr<uint32_t[]> code;
27
28 file_io binary(file_name, file_io::OPEN_TYPE::READ_BINARY);
29 if(!binary.is_open()) {
30 log_error("failed to load spir-v binary (\"$\")", file_name);
31 return {};
32 }
33
34 code_size = (size_t)binary.get_filesize();
35 if(code_size % 4u != 0u) {
36 log_error("invalid spir-v binary size $ (\"$\"): must be a multiple of 4!", code_size, file_name);
37 return {};
38 }
39
40 code = make_unique<uint32_t[]>(code_size / 4u);
41 binary.get_block((char*)code.get(), (streamsize)code_size);
42 const auto read_size = binary.get_filestream()->gcount();
43 if(read_size != (decltype(read_size))code_size) {
44 log_error("failed to read spir-v binary (\"$\"): expected $ bytes, but only read $ bytes", file_name, code_size, read_size);
45 return {};
46 }
47
48 return code;
49}
50
51spirv_handler::container load_container(const string& file_name) {
52 string data { "" };

Callers 2

create_opencl_programMethod · 0.85

Calls 5

is_openMethod · 0.80
get_filesizeMethod · 0.80
get_blockMethod · 0.80
get_filestreamMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected