ShaderProgramCompiler.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/ShaderCompiler/ShaderProgramCompiler.h>
  6. #include <AnKi/ShaderCompiler/ShaderProgramParser.h>
  7. #include <AnKi/ShaderCompiler/Glslang.h>
  8. #include <AnKi/ShaderCompiler/ShaderProgramReflection.h>
  9. #include <AnKi/Util/Serializer.h>
  10. #include <AnKi/Util/HashMap.h>
  11. namespace anki
  12. {
  13. Error ShaderProgramBinaryWrapper::serializeToFile(CString fname) const
  14. {
  15. ANKI_ASSERT(m_binary);
  16. File file;
  17. ANKI_CHECK(file.open(fname, FileOpenFlag::WRITE | FileOpenFlag::BINARY));
  18. BinarySerializer serializer;
  19. HeapAllocator<U8> tmpAlloc(m_alloc.getMemoryPool().getAllocationCallback(),
  20. m_alloc.getMemoryPool().getAllocationCallbackUserData());
  21. ANKI_CHECK(serializer.serialize(*m_binary, tmpAlloc, file));
  22. return Error::NONE;
  23. }
  24. Error ShaderProgramBinaryWrapper::deserializeFromFile(CString fname)
  25. {
  26. cleanup();
  27. File file;
  28. ANKI_CHECK(file.open(fname, FileOpenFlag::READ | FileOpenFlag::BINARY));
  29. BinaryDeserializer deserializer;
  30. ANKI_CHECK(deserializer.deserialize(m_binary, m_alloc, file));
  31. m_singleAllocation = true;
  32. if(memcmp(SHADER_BINARY_MAGIC, &m_binary->m_magic[0], strlen(SHADER_BINARY_MAGIC)) != 0)
  33. {
  34. ANKI_SHADER_COMPILER_LOGE("Corrupted or wrong version of shader binary: %s. Clean the shader cache",
  35. fname.cstr());
  36. return Error::USER_DATA;
  37. }
  38. return Error::NONE;
  39. }
  40. void ShaderProgramBinaryWrapper::cleanup()
  41. {
  42. if(m_binary == nullptr)
  43. {
  44. return;
  45. }
  46. BaseMemoryPool& mempool = m_alloc.getMemoryPool();
  47. if(!m_singleAllocation)
  48. {
  49. for(ShaderProgramBinaryMutator& mutator : m_binary->m_mutators)
  50. {
  51. mempool.free(mutator.m_values.getBegin());
  52. }
  53. mempool.free(m_binary->m_mutators.getBegin());
  54. for(ShaderProgramBinaryCodeBlock& code : m_binary->m_codeBlocks)
  55. {
  56. mempool.free(code.m_binary.getBegin());
  57. }
  58. mempool.free(m_binary->m_codeBlocks.getBegin());
  59. for(ShaderProgramBinaryMutation& m : m_binary->m_mutations)
  60. {
  61. mempool.free(m.m_values.getBegin());
  62. }
  63. mempool.free(m_binary->m_mutations.getBegin());
  64. for(ShaderProgramBinaryBlock& block : m_binary->m_uniformBlocks)
  65. {
  66. mempool.free(block.m_variables.getBegin());
  67. }
  68. mempool.free(m_binary->m_uniformBlocks.getBegin());
  69. for(ShaderProgramBinaryBlock& block : m_binary->m_storageBlocks)
  70. {
  71. mempool.free(block.m_variables.getBegin());
  72. }
  73. mempool.free(m_binary->m_storageBlocks.getBegin());
  74. if(m_binary->m_pushConstantBlock)
  75. {
  76. mempool.free(m_binary->m_pushConstantBlock->m_variables.getBegin());
  77. mempool.free(m_binary->m_pushConstantBlock);
  78. }
  79. mempool.free(m_binary->m_opaques.getBegin());
  80. mempool.free(m_binary->m_constants.getBegin());
  81. for(ShaderProgramBinaryStruct& s : m_binary->m_structs)
  82. {
  83. mempool.free(s.m_members.getBegin());
  84. }
  85. mempool.free(m_binary->m_structs.getBegin());
  86. for(ShaderProgramBinaryVariant& variant : m_binary->m_variants)
  87. {
  88. for(ShaderProgramBinaryBlockInstance& block : variant.m_uniformBlocks)
  89. {
  90. mempool.free(block.m_variables.getBegin());
  91. }
  92. for(ShaderProgramBinaryBlockInstance& block : variant.m_storageBlocks)
  93. {
  94. mempool.free(block.m_variables.getBegin());
  95. }
  96. if(variant.m_pushConstantBlock)
  97. {
  98. mempool.free(variant.m_pushConstantBlock->m_variables.getBegin());
  99. }
  100. mempool.free(variant.m_uniformBlocks.getBegin());
  101. mempool.free(variant.m_storageBlocks.getBegin());
  102. mempool.free(variant.m_pushConstantBlock);
  103. mempool.free(variant.m_constants.getBegin());
  104. mempool.free(variant.m_opaques.getBegin());
  105. }
  106. mempool.free(m_binary->m_variants.getBegin());
  107. }
  108. mempool.free(m_binary);
  109. m_binary = nullptr;
  110. m_singleAllocation = false;
  111. }
  112. /// Spin the dials. Used to compute all mutator combinations.
  113. static Bool spinDials(DynamicArrayAuto<U32>& dials, ConstWeakArray<ShaderProgramParserMutator> mutators)
  114. {
  115. ANKI_ASSERT(dials.getSize() == mutators.getSize() && dials.getSize() > 0);
  116. Bool done = true;
  117. U32 crntDial = dials.getSize() - 1;
  118. while(true)
  119. {
  120. // Turn dial
  121. ++dials[crntDial];
  122. if(dials[crntDial] >= mutators[crntDial].getValues().getSize())
  123. {
  124. if(crntDial == 0)
  125. {
  126. // Reached the 1st dial, stop spinning
  127. done = true;
  128. break;
  129. }
  130. else
  131. {
  132. dials[crntDial] = 0;
  133. --crntDial;
  134. }
  135. }
  136. else
  137. {
  138. done = false;
  139. break;
  140. }
  141. }
  142. return done;
  143. }
  144. static Error compileSpirv(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParser& parser,
  145. GenericMemoryPoolAllocator<U8>& tmpAlloc,
  146. Array<DynamicArrayAuto<U8>, U32(ShaderType::COUNT)>& spirv)
  147. {
  148. // Generate the source and the rest for the variant
  149. ShaderProgramParserVariant parserVariant;
  150. ANKI_CHECK(parser.generateVariant(mutation, parserVariant));
  151. // Compile stages
  152. for(ShaderType shaderType : EnumIterable<ShaderType>())
  153. {
  154. if(!(ShaderTypeBit(1 << shaderType) & parser.getShaderTypes()))
  155. {
  156. continue;
  157. }
  158. // Compile
  159. ANKI_CHECK(compilerGlslToSpirv(parserVariant.getSource(shaderType), shaderType, tmpAlloc, spirv[shaderType]));
  160. ANKI_ASSERT(spirv[shaderType].getSize() > 0);
  161. }
  162. return Error::NONE;
  163. }
  164. static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParser& parser,
  165. ShaderProgramBinaryVariant& variant,
  166. DynamicArrayAuto<ShaderProgramBinaryCodeBlock>& codeBlocks,
  167. DynamicArrayAuto<U64>& codeBlockHashes, GenericMemoryPoolAllocator<U8>& tmpAlloc,
  168. GenericMemoryPoolAllocator<U8>& binaryAlloc,
  169. ShaderProgramAsyncTaskInterface& taskManager, Mutex& mtx, Atomic<I32>& error)
  170. {
  171. variant = {};
  172. class Ctx
  173. {
  174. public:
  175. GenericMemoryPoolAllocator<U8> m_tmpAlloc;
  176. GenericMemoryPoolAllocator<U8> m_binaryAlloc;
  177. DynamicArrayAuto<MutatorValue> m_mutation = {m_tmpAlloc};
  178. const ShaderProgramParser* m_parser;
  179. ShaderProgramBinaryVariant* m_variant;
  180. DynamicArrayAuto<ShaderProgramBinaryCodeBlock>* m_codeBlocks;
  181. DynamicArrayAuto<U64>* m_codeBlockHashes;
  182. Mutex* m_mtx;
  183. Atomic<I32>* m_err;
  184. Ctx(GenericMemoryPoolAllocator<U8> tmpAlloc)
  185. : m_tmpAlloc(tmpAlloc)
  186. {
  187. }
  188. };
  189. Ctx* ctx = tmpAlloc.newInstance<Ctx>(tmpAlloc);
  190. ctx->m_binaryAlloc = binaryAlloc;
  191. ctx->m_mutation.create(mutation.getSize());
  192. memcpy(ctx->m_mutation.getBegin(), mutation.getBegin(), mutation.getSizeInBytes());
  193. ctx->m_parser = &parser;
  194. ctx->m_variant = &variant;
  195. ctx->m_codeBlocks = &codeBlocks;
  196. ctx->m_codeBlockHashes = &codeBlockHashes;
  197. ctx->m_mtx = &mtx;
  198. ctx->m_err = &error;
  199. auto callback = [](void* userData) {
  200. Ctx& ctx = *static_cast<Ctx*>(userData);
  201. GenericMemoryPoolAllocator<U8>& tmpAlloc = ctx.m_tmpAlloc;
  202. if(ctx.m_err->load() != 0)
  203. {
  204. // Cleanup and return
  205. tmpAlloc.deleteInstance(&ctx);
  206. return;
  207. }
  208. // All good, compile the variant
  209. Array<DynamicArrayAuto<U8>, U32(ShaderType::COUNT)> spirvs = {{{tmpAlloc},
  210. {tmpAlloc},
  211. {tmpAlloc},
  212. {tmpAlloc},
  213. {tmpAlloc},
  214. {tmpAlloc},
  215. {tmpAlloc},
  216. {tmpAlloc},
  217. {tmpAlloc},
  218. {tmpAlloc},
  219. {tmpAlloc},
  220. {tmpAlloc}}};
  221. const Error err = compileSpirv(ctx.m_mutation, *ctx.m_parser, tmpAlloc, spirvs);
  222. if(!err)
  223. {
  224. // No error, check if the spirvs are common with some other variant and store it
  225. LockGuard<Mutex> lock(*ctx.m_mtx);
  226. for(ShaderType shaderType : EnumIterable<ShaderType>())
  227. {
  228. DynamicArrayAuto<U8>& spirv = spirvs[shaderType];
  229. if(spirv.isEmpty())
  230. {
  231. ctx.m_variant->m_codeBlockIndices[shaderType] = MAX_U32;
  232. continue;
  233. }
  234. // Check if the spirv is already generated
  235. const U64 newHash = computeHash(&spirv[0], spirv.getSize());
  236. Bool found = false;
  237. for(U32 i = 0; i < ctx.m_codeBlockHashes->getSize(); ++i)
  238. {
  239. if((*ctx.m_codeBlockHashes)[i] == newHash)
  240. {
  241. // Found it
  242. ctx.m_variant->m_codeBlockIndices[shaderType] = i;
  243. found = true;
  244. break;
  245. }
  246. }
  247. // Create it if not found
  248. if(!found)
  249. {
  250. U8* code = ctx.m_binaryAlloc.allocate(spirv.getSizeInBytes());
  251. memcpy(code, &spirv[0], spirv.getSizeInBytes());
  252. ShaderProgramBinaryCodeBlock block;
  253. block.m_binary.setArray(code, U32(spirv.getSizeInBytes()));
  254. block.m_hash = newHash;
  255. ctx.m_codeBlocks->emplaceBack(block);
  256. ctx.m_codeBlockHashes->emplaceBack(newHash);
  257. ctx.m_variant->m_codeBlockIndices[shaderType] = ctx.m_codeBlocks->getSize() - 1;
  258. }
  259. }
  260. }
  261. else
  262. {
  263. ctx.m_err->store(err._getCode());
  264. }
  265. // Cleanup
  266. tmpAlloc.deleteInstance(&ctx);
  267. };
  268. taskManager.enqueueTask(callback, ctx);
  269. }
  270. class Refl final : public ShaderReflectionVisitorInterface
  271. {
  272. public:
  273. GenericMemoryPoolAllocator<U8> m_alloc;
  274. const StringList* m_symbolsToReflect = nullptr;
  275. /// Will be stored in the binary
  276. /// @{
  277. /// [blockType][blockIdx]
  278. Array<DynamicArrayAuto<ShaderProgramBinaryBlock>, 3> m_blocks = {{m_alloc, m_alloc, m_alloc}};
  279. /// [blockType][blockIdx][varIdx]
  280. Array<DynamicArrayAuto<DynamicArrayAuto<ShaderProgramBinaryVariable>>, 3> m_vars = {
  281. {{m_alloc}, {m_alloc}, {m_alloc}}};
  282. DynamicArrayAuto<ShaderProgramBinaryOpaque> m_opaque = {m_alloc};
  283. DynamicArrayAuto<ShaderProgramBinaryConstant> m_consts = {m_alloc};
  284. DynamicArrayAuto<ShaderProgramBinaryStruct> m_structs = {m_alloc};
  285. /// [structIndex][memberIndex]
  286. DynamicArrayAuto<DynamicArrayAuto<ShaderProgramBinaryStructMember>> m_structMembers = {m_alloc};
  287. /// @}
  288. /// Will be stored in a variant
  289. /// @{
  290. /// [blockType][blockInstanceIdx]
  291. Array<DynamicArrayAuto<ShaderProgramBinaryBlockInstance>, 3> m_blockInstances = {{m_alloc, m_alloc, m_alloc}};
  292. DynamicArrayAuto<ShaderProgramBinaryOpaqueInstance> m_opaqueInstances = {m_alloc};
  293. DynamicArrayAuto<ShaderProgramBinaryConstantInstance> m_constInstances = {m_alloc};
  294. Array<U32, 3> m_workgroupSizes = {MAX_U32, MAX_U32, MAX_U32};
  295. Array<U32, 3> m_workgroupSizesConstants = {MAX_U32, MAX_U32, MAX_U32};
  296. /// @}
  297. Refl(const GenericMemoryPoolAllocator<U8>& alloc, const StringList* symbolsToReflect)
  298. : m_alloc(alloc)
  299. , m_symbolsToReflect(symbolsToReflect)
  300. {
  301. }
  302. Error setWorkgroupSizes(U32 x, U32 y, U32 z, U32 specConstMask) final
  303. {
  304. m_workgroupSizesConstants = {MAX_U32, MAX_U32, MAX_U32};
  305. m_workgroupSizes = {MAX_U32, MAX_U32, MAX_U32};
  306. const Array<U32, 3> input = {x, y, z};
  307. for(U32 i = 0; i < 3; ++i)
  308. {
  309. if(specConstMask & (1 << i))
  310. {
  311. for(const ShaderProgramBinaryConstantInstance& c : m_constInstances)
  312. {
  313. if(m_consts[c.m_index].m_constantId == input[i])
  314. {
  315. m_workgroupSizesConstants[i] = c.m_index;
  316. break;
  317. }
  318. }
  319. if(m_workgroupSizesConstants[i] == MAX_U32)
  320. {
  321. ANKI_SHADER_COMPILER_LOGE("Reflection identified workgroup size dimension %u as spec constant but "
  322. "not such spec constant was found",
  323. i);
  324. return Error::USER_DATA;
  325. }
  326. }
  327. else
  328. {
  329. m_workgroupSizes[i] = input[i];
  330. }
  331. }
  332. return Error::NONE;
  333. }
  334. Error setCounts(U32 uniformBlockCount, U32 storageBlockCount, U32 opaqueCount, Bool pushConstantBlock,
  335. U32 constCount, U32 structCount) final
  336. {
  337. m_blockInstances[0].create(uniformBlockCount);
  338. m_blockInstances[1].create(storageBlockCount);
  339. if(pushConstantBlock)
  340. {
  341. m_blockInstances[2].create(1);
  342. }
  343. m_opaqueInstances.create(opaqueCount);
  344. m_constInstances.create(constCount);
  345. return Error::NONE;
  346. }
  347. Error visitUniformBlock(U32 idx, CString name, U32 set, U32 binding, U32 size, U32 varCount) final
  348. {
  349. return visitAnyBlock(idx, name, set, binding, size, varCount, 0);
  350. }
  351. Error visitUniformVariable(U32 blockIdx, U32 idx, CString name, ShaderVariableDataType type,
  352. const ShaderVariableBlockInfo& blockInfo) final
  353. {
  354. return visitAnyVariable(blockIdx, idx, name, type, blockInfo, 0);
  355. }
  356. Error visitStorageBlock(U32 idx, CString name, U32 set, U32 binding, U32 size, U32 varCount) final
  357. {
  358. return visitAnyBlock(idx, name, set, binding, size, varCount, 1);
  359. }
  360. Error visitStorageVariable(U32 blockIdx, U32 idx, CString name, ShaderVariableDataType type,
  361. const ShaderVariableBlockInfo& blockInfo) final
  362. {
  363. return visitAnyVariable(blockIdx, idx, name, type, blockInfo, 1);
  364. }
  365. Error visitPushConstantsBlock(CString name, U32 size, U32 varCount) final
  366. {
  367. return visitAnyBlock(0, name, 0, 0, size, varCount, 2);
  368. }
  369. Error visitPushConstant(U32 idx, CString name, ShaderVariableDataType type,
  370. const ShaderVariableBlockInfo& blockInfo) final
  371. {
  372. return visitAnyVariable(0, idx, name, type, blockInfo, 2);
  373. }
  374. Error visitOpaque(U32 instanceIdx, CString name, ShaderVariableDataType type, U32 set, U32 binding,
  375. U32 arraySize) final
  376. {
  377. // Find the opaque
  378. U32 opaqueIdx = MAX_U32;
  379. for(U32 i = 0; i < m_opaque.getSize(); ++i)
  380. {
  381. if(name == m_opaque[i].m_name.getBegin())
  382. {
  383. if(type != m_opaque[i].m_type || set != m_opaque[i].m_set || binding != m_opaque[i].m_binding)
  384. {
  385. ANKI_SHADER_COMPILER_LOGE(
  386. "The set, binding and type can't difer between shader variants for opaque: %s", name.cstr());
  387. return Error::USER_DATA;
  388. }
  389. opaqueIdx = i;
  390. break;
  391. }
  392. }
  393. // Create the opaque
  394. if(opaqueIdx == MAX_U32)
  395. {
  396. ShaderProgramBinaryOpaque& o = *m_opaque.emplaceBack();
  397. ANKI_CHECK(setName(name, o.m_name));
  398. o.m_type = type;
  399. o.m_binding = binding;
  400. o.m_set = set;
  401. opaqueIdx = m_opaque.getSize() - 1;
  402. }
  403. // Create the instance
  404. ShaderProgramBinaryOpaqueInstance& instance = m_opaqueInstances[instanceIdx];
  405. instance.m_index = opaqueIdx;
  406. instance.m_arraySize = arraySize;
  407. return Error::NONE;
  408. }
  409. Bool skipSymbol(CString symbol) const final
  410. {
  411. Bool skip = true;
  412. for(const String& s : *m_symbolsToReflect)
  413. {
  414. if(symbol == s)
  415. {
  416. skip = false;
  417. break;
  418. }
  419. }
  420. return skip;
  421. }
  422. Error visitConstant(U32 instanceIdx, CString name, ShaderVariableDataType type, U32 constantId) final
  423. {
  424. // Find const
  425. U32 constIdx = MAX_U32;
  426. for(U32 i = 0; i < m_consts.getSize(); ++i)
  427. {
  428. if(name == m_consts[i].m_name.getBegin())
  429. {
  430. if(type != m_consts[i].m_type || constantId != m_consts[i].m_constantId)
  431. {
  432. ANKI_SHADER_COMPILER_LOGE(
  433. "The type, constantId and stages can't difer between shader variants for const: %s",
  434. name.cstr());
  435. return Error::USER_DATA;
  436. }
  437. constIdx = i;
  438. break;
  439. }
  440. }
  441. // Create the const
  442. if(constIdx == MAX_U32)
  443. {
  444. ShaderProgramBinaryConstant& c = *m_consts.emplaceBack();
  445. ANKI_CHECK(setName(name, c.m_name));
  446. c.m_type = type;
  447. c.m_constantId = constantId;
  448. constIdx = m_consts.getSize() - 1;
  449. }
  450. // Create the instance
  451. ShaderProgramBinaryConstantInstance& instance = m_constInstances[instanceIdx];
  452. instance.m_index = constIdx;
  453. return Error::NONE;
  454. }
  455. ANKI_USE_RESULT Bool findStruct(CString name, U32& idx) const
  456. {
  457. idx = MAX_U32;
  458. for(U32 i = 0; i < m_structs.getSize(); ++i)
  459. {
  460. const ShaderProgramBinaryStruct& s = m_structs[i];
  461. if(s.m_name.getBegin() == name)
  462. {
  463. idx = i;
  464. break;
  465. }
  466. }
  467. return idx != MAX_U32;
  468. }
  469. Error visitStruct(U32 idx, CString name, U32 memberCount, U32 size) final
  470. {
  471. // Init the block
  472. U32 structIdx;
  473. const Bool structFound = findStruct(name, structIdx);
  474. if(structFound)
  475. {
  476. if(memberCount != m_structMembers[structIdx].getSize())
  477. {
  478. ANKI_SHADER_COMPILER_LOGE("The number of members can't differ between shader variants for struct: %s",
  479. name.cstr());
  480. return Error::USER_DATA;
  481. }
  482. if(size != m_structs[structIdx].m_size)
  483. {
  484. ANKI_SHADER_COMPILER_LOGE("The size can't differ between shader variants for struct: %s", name.cstr());
  485. return Error::USER_DATA;
  486. }
  487. }
  488. else
  489. {
  490. // Create a new struct
  491. ShaderProgramBinaryStruct& s = *m_structs.emplaceBack();
  492. ANKI_CHECK(setName(name, s.m_name));
  493. s.m_size = size;
  494. // Allocate members
  495. m_structMembers.emplaceBack(m_alloc);
  496. m_structMembers.getBack().create(memberCount);
  497. }
  498. return Error::NONE;
  499. }
  500. Error visitStructMember(U32 structIdx, CString structName, U32 memberIdx, CString memberName,
  501. ShaderVariableDataType type, CString typeStructName, U32 offset, U32 arraySize) final
  502. {
  503. // Refresh the structIdx because we have a different global mapping
  504. const Bool structFound = findStruct(structName, structIdx);
  505. ANKI_ASSERT(structFound);
  506. (void)structFound;
  507. const ShaderProgramBinaryStruct& s = m_structs[structIdx];
  508. DynamicArrayAuto<ShaderProgramBinaryStructMember>& members = m_structMembers[structIdx];
  509. // Find member
  510. Bool found = false;
  511. for(U32 i = 0; i < members.getSize(); ++i)
  512. {
  513. if(memberName == &members[i].m_name[0])
  514. {
  515. if(members[i].m_type != type)
  516. {
  517. ANKI_SHADER_COMPILER_LOGE("Member %s of struct %s has different type between variants",
  518. memberName.cstr(), &s.m_name[0]);
  519. return Error::USER_DATA;
  520. }
  521. if(i != memberIdx)
  522. {
  523. ANKI_SHADER_COMPILER_LOGE("Member %s of struct %s is in different place between variants",
  524. memberName.cstr(), &s.m_name[0]);
  525. return Error::USER_DATA;
  526. }
  527. if(members[i].m_offset != offset)
  528. {
  529. ANKI_SHADER_COMPILER_LOGE("Member %s of struct %s has different offset between variants",
  530. memberName.cstr(), &s.m_name[0]);
  531. return Error::USER_DATA;
  532. }
  533. if(members[i].m_arraySize != arraySize)
  534. {
  535. ANKI_SHADER_COMPILER_LOGE("Member %s of struct %s has different array size between variants",
  536. memberName.cstr(), &s.m_name[0]);
  537. return Error::USER_DATA;
  538. }
  539. found = true;
  540. break;
  541. }
  542. }
  543. // Create if not found
  544. if(!found)
  545. {
  546. ShaderProgramBinaryStructMember& member = members[memberIdx];
  547. ANKI_CHECK(setName(memberName, member.m_name));
  548. member.m_type = type;
  549. member.m_offset = offset;
  550. member.m_arraySize = arraySize;
  551. if(type == ShaderVariableDataType::NONE)
  552. {
  553. // Type is a struct, find the right index
  554. const Bool structFound = findStruct(typeStructName, member.m_structIndex);
  555. ANKI_ASSERT(structFound);
  556. (void)structFound;
  557. }
  558. }
  559. return Error::NONE;
  560. }
  561. static ANKI_USE_RESULT Error setName(CString in, Array<char, MAX_SHADER_BINARY_NAME_LENGTH + 1>& out)
  562. {
  563. if(in.getLength() + 1 > MAX_SHADER_BINARY_NAME_LENGTH)
  564. {
  565. ANKI_SHADER_COMPILER_LOGE("Name too long: %s", in.cstr());
  566. return Error::USER_DATA;
  567. }
  568. else if(in.getLength() == 0)
  569. {
  570. ANKI_SHADER_COMPILER_LOGE("Found an empty string as name");
  571. return Error::USER_DATA;
  572. }
  573. else
  574. {
  575. memcpy(out.getBegin(), in.getBegin(), in.getLength() + 1);
  576. }
  577. return Error::NONE;
  578. }
  579. static ANKI_USE_RESULT Error findBlock(CString name, U32 set, U32 binding,
  580. ConstWeakArray<ShaderProgramBinaryBlock> arr, U32& idx)
  581. {
  582. idx = MAX_U32;
  583. for(U32 i = 0; i < arr.getSize(); ++i)
  584. {
  585. const ShaderProgramBinaryBlock& block = arr[i];
  586. if(block.m_name.getBegin() == name)
  587. {
  588. if(set != block.m_set || binding != block.m_binding)
  589. {
  590. ANKI_SHADER_COMPILER_LOGE("The set and binding can't difer between shader variants for block: %s",
  591. name.cstr());
  592. return Error::USER_DATA;
  593. }
  594. idx = i;
  595. break;
  596. }
  597. }
  598. return Error::NONE;
  599. }
  600. Error visitAnyBlock(U32 blockInstanceIdx, CString name, U32 set, U32 binding, U32 size, U32 varSize, U32 blockType)
  601. {
  602. // Init the block
  603. U32 blockIdx;
  604. ANKI_CHECK(findBlock(name, set, binding, m_blocks[blockType], blockIdx));
  605. if(blockIdx == MAX_U32)
  606. {
  607. // Not found, create it
  608. ShaderProgramBinaryBlock& block = *m_blocks[blockType].emplaceBack();
  609. ANKI_CHECK(setName(name, block.m_name));
  610. block.m_set = set;
  611. block.m_binding = binding;
  612. blockIdx = m_blocks[blockType].getSize() - 1;
  613. // Create some storage for vars as well
  614. m_vars[blockType].emplaceBack(m_alloc);
  615. ANKI_ASSERT(m_vars[blockType].getSize() == m_blocks[blockType].getSize());
  616. }
  617. // Init the instance
  618. ShaderProgramBinaryBlockInstance& instance = m_blockInstances[blockType][blockInstanceIdx];
  619. instance.m_index = blockIdx;
  620. instance.m_size = size;
  621. instance.m_variables.setArray(m_alloc.newArray<ShaderProgramBinaryVariableInstance>(varSize), varSize);
  622. return Error::NONE;
  623. }
  624. Error visitAnyVariable(U32 blockInstanceIdx, U32 varInstanceIdx, CString name, ShaderVariableDataType type,
  625. const ShaderVariableBlockInfo& blockInfo, U32 blockType)
  626. {
  627. // Find the variable
  628. U32 varIdx = MAX_U32;
  629. const U32 blockIdx = m_blockInstances[blockType][blockInstanceIdx].m_index;
  630. for(U32 i = 0; i < m_vars[blockType][blockIdx].getSize(); ++i)
  631. {
  632. const ShaderProgramBinaryVariable& var = m_vars[blockType][blockIdx][i];
  633. if(var.m_name.getBegin() == name)
  634. {
  635. if(var.m_type != type)
  636. {
  637. ANKI_SHADER_COMPILER_LOGE("The type should not differ between variants for variable: %s",
  638. name.cstr());
  639. return Error::USER_DATA;
  640. }
  641. varIdx = i;
  642. break;
  643. }
  644. }
  645. // Create the variable
  646. if(varIdx == MAX_U32)
  647. {
  648. ShaderProgramBinaryVariable& var = *m_vars[blockType][blockIdx].emplaceBack();
  649. ANKI_CHECK(setName(name, var.m_name));
  650. var.m_type = type;
  651. varIdx = m_vars[blockType][blockIdx].getSize() - 1;
  652. }
  653. // Init the instance
  654. ShaderProgramBinaryVariableInstance& instance =
  655. m_blockInstances[blockType][blockInstanceIdx].m_variables[varInstanceIdx];
  656. instance.m_blockInfo = blockInfo;
  657. instance.m_index = varIdx;
  658. return Error::NONE;
  659. }
  660. };
  661. static Error doReflection(const StringList& symbolsToReflect, ShaderProgramBinary& binary,
  662. GenericMemoryPoolAllocator<U8>& tmpAlloc, GenericMemoryPoolAllocator<U8>& binaryAlloc)
  663. {
  664. ANKI_ASSERT(binary.m_variants.getSize() > 0);
  665. Refl refl(binaryAlloc, &symbolsToReflect);
  666. for(ShaderProgramBinaryVariant& variant : binary.m_variants)
  667. {
  668. Array<ConstWeakArray<U8>, U32(ShaderType::COUNT)> spirvs;
  669. for(ShaderType stage : EnumIterable<ShaderType>())
  670. {
  671. if(variant.m_codeBlockIndices[stage] != MAX_U32)
  672. {
  673. spirvs[stage] = binary.m_codeBlocks[variant.m_codeBlockIndices[stage]].m_binary;
  674. }
  675. }
  676. ANKI_CHECK(performSpirvReflection(spirvs, tmpAlloc, refl));
  677. // Store the instances
  678. if(refl.m_blockInstances[0].getSize())
  679. {
  680. ShaderProgramBinaryBlockInstance* instances;
  681. U32 size, storageSize;
  682. refl.m_blockInstances[0].moveAndReset(instances, size, storageSize);
  683. variant.m_uniformBlocks.setArray(instances, size);
  684. }
  685. if(refl.m_blockInstances[1].getSize())
  686. {
  687. ShaderProgramBinaryBlockInstance* instances;
  688. U32 size, storageSize;
  689. refl.m_blockInstances[1].moveAndReset(instances, size, storageSize);
  690. variant.m_storageBlocks.setArray(instances, size);
  691. }
  692. if(refl.m_blockInstances[2].getSize())
  693. {
  694. ShaderProgramBinaryBlockInstance* instances;
  695. U32 size, storageSize;
  696. refl.m_blockInstances[2].moveAndReset(instances, size, storageSize);
  697. ANKI_ASSERT(size == 1);
  698. variant.m_pushConstantBlock = instances;
  699. }
  700. if(refl.m_opaqueInstances.getSize())
  701. {
  702. ShaderProgramBinaryOpaqueInstance* instances;
  703. U32 size, storageSize;
  704. refl.m_opaqueInstances.moveAndReset(instances, size, storageSize);
  705. variant.m_opaques.setArray(instances, size);
  706. }
  707. if(refl.m_constInstances.getSize())
  708. {
  709. ShaderProgramBinaryConstantInstance* instances;
  710. U32 size, storageSize;
  711. refl.m_constInstances.moveAndReset(instances, size, storageSize);
  712. variant.m_constants.setArray(instances, size);
  713. }
  714. variant.m_workgroupSizes = refl.m_workgroupSizes;
  715. variant.m_workgroupSizesConstants = refl.m_workgroupSizesConstants;
  716. }
  717. if(refl.m_blocks[0].getSize())
  718. {
  719. ShaderProgramBinaryBlock* blocks;
  720. U32 size, storageSize;
  721. refl.m_blocks[0].moveAndReset(blocks, size, storageSize);
  722. binary.m_uniformBlocks.setArray(blocks, size);
  723. for(U32 i = 0; i < size; ++i)
  724. {
  725. ShaderProgramBinaryVariable* vars;
  726. U32 varSize, varStorageSize;
  727. refl.m_vars[0][i].moveAndReset(vars, varSize, varStorageSize);
  728. binary.m_uniformBlocks[i].m_variables.setArray(vars, varSize);
  729. }
  730. }
  731. if(refl.m_blocks[1].getSize())
  732. {
  733. ShaderProgramBinaryBlock* blocks;
  734. U32 size, storageSize;
  735. refl.m_blocks[1].moveAndReset(blocks, size, storageSize);
  736. binary.m_storageBlocks.setArray(blocks, size);
  737. for(U32 i = 0; i < size; ++i)
  738. {
  739. ShaderProgramBinaryVariable* vars;
  740. U32 varSize, varStorageSize;
  741. refl.m_vars[1][i].moveAndReset(vars, varSize, varStorageSize);
  742. binary.m_storageBlocks[i].m_variables.setArray(vars, varSize);
  743. }
  744. }
  745. if(refl.m_blocks[2].getSize())
  746. {
  747. ShaderProgramBinaryBlock* blocks;
  748. U32 size, storageSize;
  749. refl.m_blocks[2].moveAndReset(blocks, size, storageSize);
  750. ANKI_ASSERT(size == 1);
  751. binary.m_pushConstantBlock = blocks;
  752. ShaderProgramBinaryVariable* vars;
  753. U32 varSize, varStorageSize;
  754. refl.m_vars[2][0].moveAndReset(vars, varSize, varStorageSize);
  755. binary.m_pushConstantBlock->m_variables.setArray(vars, varSize);
  756. }
  757. if(refl.m_opaque.getSize())
  758. {
  759. ShaderProgramBinaryOpaque* opaques;
  760. U32 size, storageSize;
  761. refl.m_opaque.moveAndReset(opaques, size, storageSize);
  762. binary.m_opaques.setArray(opaques, size);
  763. }
  764. if(refl.m_consts.getSize())
  765. {
  766. ShaderProgramBinaryConstant* consts;
  767. U32 size, storageSize;
  768. refl.m_consts.moveAndReset(consts, size, storageSize);
  769. binary.m_constants.setArray(consts, size);
  770. }
  771. if(refl.m_structs.getSize())
  772. {
  773. ShaderProgramBinaryStruct* storage;
  774. U32 size, storageSize;
  775. refl.m_structs.moveAndReset(storage, size, storageSize);
  776. binary.m_structs.setArray(storage, size);
  777. for(U32 i = 0; i < size; ++i)
  778. {
  779. ShaderProgramBinaryStructMember* memberStorage;
  780. U32 memberSize, memberStorageSize;
  781. refl.m_structMembers[i].moveAndReset(memberStorage, memberSize, memberStorageSize);
  782. binary.m_structs[i].m_members.setArray(memberStorage, memberSize);
  783. }
  784. }
  785. return Error::NONE;
  786. }
  787. Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem,
  788. ShaderProgramPostParseInterface* postParseCallback,
  789. ShaderProgramAsyncTaskInterface* taskManager_,
  790. GenericMemoryPoolAllocator<U8> tempAllocator,
  791. const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binaryW)
  792. {
  793. // Initialize the binary
  794. binaryW.cleanup();
  795. binaryW.m_singleAllocation = false;
  796. GenericMemoryPoolAllocator<U8> binaryAllocator = binaryW.m_alloc;
  797. binaryW.m_binary = binaryAllocator.newInstance<ShaderProgramBinary>();
  798. ShaderProgramBinary& binary = *binaryW.m_binary;
  799. binary = {};
  800. memcpy(&binary.m_magic[0], SHADER_BINARY_MAGIC, 8);
  801. // Parse source
  802. ShaderProgramParser parser(fname, &fsystem, tempAllocator, compilerOptions);
  803. ANKI_CHECK(parser.parse());
  804. if(postParseCallback && postParseCallback->skipCompilation(parser.getHash()))
  805. {
  806. return Error::NONE;
  807. }
  808. // Get mutators
  809. U32 mutationCount = 0;
  810. if(parser.getMutators().getSize() > 0)
  811. {
  812. binary.m_mutators.setArray(binaryAllocator.newArray<ShaderProgramBinaryMutator>(parser.getMutators().getSize()),
  813. parser.getMutators().getSize());
  814. for(U32 i = 0; i < binary.m_mutators.getSize(); ++i)
  815. {
  816. ShaderProgramBinaryMutator& out = binary.m_mutators[i];
  817. const ShaderProgramParserMutator& in = parser.getMutators()[i];
  818. ANKI_ASSERT(in.getName().getLength() < out.m_name.getSize());
  819. memcpy(&out.m_name[0], in.getName().cstr(), in.getName().getLength() + 1);
  820. out.m_values.setArray(binaryAllocator.newArray<I32>(in.getValues().getSize()), in.getValues().getSize());
  821. memcpy(out.m_values.getBegin(), in.getValues().getBegin(), in.getValues().getSizeInBytes());
  822. // Update the count
  823. mutationCount = (i == 0) ? out.m_values.getSize() : mutationCount * out.m_values.getSize();
  824. }
  825. }
  826. else
  827. {
  828. ANKI_ASSERT(binary.m_mutators.getSize() == 0);
  829. }
  830. // Create all variants
  831. Mutex mtx;
  832. Atomic<I32> errorAtomic(0);
  833. class SyncronousShaderProgramAsyncTaskInterface : public ShaderProgramAsyncTaskInterface
  834. {
  835. public:
  836. void enqueueTask(void (*callback)(void* userData), void* userData) final
  837. {
  838. callback(userData);
  839. }
  840. Error joinTasks() final
  841. {
  842. // Nothing
  843. return Error::NONE;
  844. }
  845. } syncTaskManager;
  846. ShaderProgramAsyncTaskInterface& taskManager = (taskManager_) ? *taskManager_ : syncTaskManager;
  847. if(parser.getMutators().getSize() > 0)
  848. {
  849. // Initialize
  850. DynamicArrayAuto<MutatorValue> originalMutationValues(tempAllocator, parser.getMutators().getSize());
  851. DynamicArrayAuto<MutatorValue> rewrittenMutationValues(tempAllocator, parser.getMutators().getSize());
  852. DynamicArrayAuto<U32> dials(tempAllocator, parser.getMutators().getSize(), 0);
  853. DynamicArrayAuto<ShaderProgramBinaryVariant> variants(binaryAllocator);
  854. DynamicArrayAuto<ShaderProgramBinaryCodeBlock> codeBlocks(binaryAllocator);
  855. DynamicArrayAuto<ShaderProgramBinaryMutation> mutations(binaryAllocator, mutationCount);
  856. DynamicArrayAuto<U64> codeBlockHashes(tempAllocator);
  857. HashMapAuto<U64, U32> mutationHashToIdx(tempAllocator);
  858. // Grow the storage of the variants array. Can't have it resize, threads will work on stale data
  859. variants.resizeStorage(mutationCount);
  860. const ShaderProgramBinaryVariant* baseVariant = nullptr;
  861. mutationCount = 0;
  862. // Spin for all possible combinations of mutators and
  863. // - Create the spirv
  864. // - Populate the binary variant
  865. do
  866. {
  867. // Create the mutation
  868. for(U32 i = 0; i < parser.getMutators().getSize(); ++i)
  869. {
  870. originalMutationValues[i] = parser.getMutators()[i].getValues()[dials[i]];
  871. rewrittenMutationValues[i] = originalMutationValues[i];
  872. }
  873. ShaderProgramBinaryMutation& mutation = mutations[mutationCount++];
  874. mutation.m_values.setArray(binaryAllocator.newArray<MutatorValue>(originalMutationValues.getSize()),
  875. originalMutationValues.getSize());
  876. memcpy(mutation.m_values.getBegin(), originalMutationValues.getBegin(),
  877. originalMutationValues.getSizeInBytes());
  878. mutation.m_hash = computeHash(originalMutationValues.getBegin(), originalMutationValues.getSizeInBytes());
  879. ANKI_ASSERT(mutation.m_hash > 0);
  880. const Bool rewritten = parser.rewriteMutation(
  881. WeakArray<MutatorValue>(rewrittenMutationValues.getBegin(), rewrittenMutationValues.getSize()));
  882. // Create the variant
  883. if(!rewritten)
  884. {
  885. // New and unique mutation and thus variant, add it
  886. ShaderProgramBinaryVariant& variant = *variants.emplaceBack();
  887. baseVariant = (baseVariant == nullptr) ? variants.getBegin() : baseVariant;
  888. compileVariantAsync(originalMutationValues, parser, variant, codeBlocks, codeBlockHashes, tempAllocator,
  889. binaryAllocator, taskManager, mtx, errorAtomic);
  890. mutation.m_variantIndex = variants.getSize() - 1;
  891. ANKI_ASSERT(mutationHashToIdx.find(mutation.m_hash) == mutationHashToIdx.getEnd());
  892. mutationHashToIdx.emplace(mutation.m_hash, mutationCount - 1);
  893. }
  894. else
  895. {
  896. // Check if the rewritten mutation exists
  897. const U64 otherMutationHash =
  898. computeHash(rewrittenMutationValues.getBegin(), rewrittenMutationValues.getSizeInBytes());
  899. auto it = mutationHashToIdx.find(otherMutationHash);
  900. ShaderProgramBinaryVariant* variant = nullptr;
  901. if(it == mutationHashToIdx.getEnd())
  902. {
  903. // Rewrite variant not found, create it
  904. variant = variants.emplaceBack();
  905. baseVariant = (baseVariant == nullptr) ? variants.getBegin() : baseVariant;
  906. compileVariantAsync(originalMutationValues, parser, *variant, codeBlocks, codeBlockHashes,
  907. tempAllocator, binaryAllocator, taskManager, mtx, errorAtomic);
  908. ShaderProgramBinaryMutation& otherMutation = mutations[mutationCount++];
  909. otherMutation.m_values.setArray(
  910. binaryAllocator.newArray<MutatorValue>(rewrittenMutationValues.getSize()),
  911. rewrittenMutationValues.getSize());
  912. memcpy(otherMutation.m_values.getBegin(), rewrittenMutationValues.getBegin(),
  913. rewrittenMutationValues.getSizeInBytes());
  914. mutation.m_hash = otherMutationHash;
  915. mutation.m_variantIndex = variants.getSize() - 1;
  916. it = mutationHashToIdx.emplace(otherMutationHash, mutationCount - 1);
  917. }
  918. // Setup the new mutation
  919. mutation.m_variantIndex = mutations[*it].m_variantIndex;
  920. mutationHashToIdx.emplace(mutation.m_hash, U32(&mutation - mutations.getBegin()));
  921. }
  922. } while(!spinDials(dials, parser.getMutators()));
  923. ANKI_ASSERT(mutationCount == mutations.getSize());
  924. ANKI_ASSERT(baseVariant == variants.getBegin() && "Can't have the variants array grow");
  925. // Done, wait the threads
  926. ANKI_CHECK(taskManager.joinTasks());
  927. ANKI_CHECK(Error(errorAtomic.getNonAtomically()));
  928. // Store temp containers to binary
  929. U32 size, storage;
  930. ShaderProgramBinaryVariant* firstVariant;
  931. variants.moveAndReset(firstVariant, size, storage);
  932. binary.m_variants.setArray(firstVariant, size);
  933. ShaderProgramBinaryCodeBlock* firstCodeBlock;
  934. codeBlocks.moveAndReset(firstCodeBlock, size, storage);
  935. binary.m_codeBlocks.setArray(firstCodeBlock, size);
  936. ShaderProgramBinaryMutation* firstMutation;
  937. mutations.moveAndReset(firstMutation, size, storage);
  938. binary.m_mutations.setArray(firstMutation, size);
  939. }
  940. else
  941. {
  942. DynamicArrayAuto<MutatorValue> mutation(tempAllocator);
  943. DynamicArrayAuto<ShaderProgramBinaryCodeBlock> codeBlocks(binaryAllocator);
  944. DynamicArrayAuto<U64> codeBlockHashes(tempAllocator);
  945. binary.m_variants.setArray(binaryAllocator.newInstance<ShaderProgramBinaryVariant>(), 1);
  946. compileVariantAsync(mutation, parser, binary.m_variants[0], codeBlocks, codeBlockHashes, tempAllocator,
  947. binaryAllocator, taskManager, mtx, errorAtomic);
  948. ANKI_CHECK(taskManager.joinTasks());
  949. ANKI_CHECK(Error(errorAtomic.getNonAtomically()));
  950. ANKI_ASSERT(codeBlocks.getSize() == U32(__builtin_popcount(U32(parser.getShaderTypes()))));
  951. ShaderProgramBinaryCodeBlock* firstCodeBlock;
  952. U32 size, storage;
  953. codeBlocks.moveAndReset(firstCodeBlock, size, storage);
  954. binary.m_codeBlocks.setArray(firstCodeBlock, size);
  955. binary.m_mutations.setArray(binaryAllocator.newInstance<ShaderProgramBinaryMutation>(), 1);
  956. binary.m_mutations[0].m_hash = 1;
  957. binary.m_mutations[0].m_variantIndex = 0;
  958. }
  959. // Sort the mutations
  960. std::sort(
  961. binary.m_mutations.getBegin(), binary.m_mutations.getEnd(),
  962. [](const ShaderProgramBinaryMutation& a, const ShaderProgramBinaryMutation& b) { return a.m_hash < b.m_hash; });
  963. // Lib name
  964. if(parser.getLibraryName().getLength() > 0)
  965. {
  966. if(parser.getLibraryName().getLength() >= sizeof(binary.m_libraryName))
  967. {
  968. ANKI_SHADER_COMPILER_LOGE("Library name too long: %s", parser.getLibraryName().cstr());
  969. return Error::USER_DATA;
  970. }
  971. memcpy(&binary.m_libraryName[0], &parser.getLibraryName()[0], parser.getLibraryName().getLength());
  972. }
  973. binary.m_rayType = parser.getRayType();
  974. // Misc
  975. binary.m_presentShaderTypes = parser.getShaderTypes();
  976. // Reflection
  977. ANKI_CHECK(doReflection(parser.getSymbolsToReflect(), binary, tempAllocator, binaryAllocator));
  978. return Error::NONE;
  979. }
  980. Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
  981. ShaderProgramPostParseInterface* postParseCallback,
  982. ShaderProgramAsyncTaskInterface* taskManager, GenericMemoryPoolAllocator<U8> tempAllocator,
  983. const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binaryW)
  984. {
  985. const Error err = compileShaderProgramInternal(fname, fsystem, postParseCallback, taskManager, tempAllocator,
  986. compilerOptions, binaryW);
  987. if(err)
  988. {
  989. ANKI_SHADER_COMPILER_LOGE("Failed to compile: %s", fname.cstr());
  990. }
  991. return err;
  992. }
  993. } // end namespace anki