GrCommon.h 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright (C) 2009-2022, 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/Gr.h>
  6. #include <AnKi/ShaderCompiler.h>
  7. #include <AnKi/ShaderCompiler/ShaderProgramParser.h>
  8. #include <AnKi/ShaderCompiler/Glslang.h>
  9. #include <Tests/Framework/Framework.h>
  10. namespace anki {
  11. inline ShaderPtr createShader(CString src, ShaderType type, GrManager& gr,
  12. ConstWeakArray<ShaderSpecializationConstValue> specVals = {})
  13. {
  14. HeapAllocator<U8> alloc(allocAligned, nullptr);
  15. StringAuto header(alloc);
  16. ShaderCompilerOptions compilerOptions;
  17. ShaderProgramParser::generateAnkiShaderHeader(type, compilerOptions, header);
  18. header.append(src);
  19. DynamicArrayAuto<U8> spirv(alloc);
  20. StringAuto errorLog(alloc);
  21. ANKI_TEST_EXPECT_NO_ERR(compilerGlslToSpirv(header, type, alloc, spirv, errorLog));
  22. ShaderInitInfo initInf(type, spirv);
  23. initInf.m_constValues = specVals;
  24. return gr.newShader(initInf);
  25. }
  26. } // end namespace anki