ShaderProgramCompiler.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #pragma once
  6. #include <AnKi/ShaderCompiler/ShaderProgramDump.h>
  7. #include <AnKi/Util/String.h>
  8. #include <AnKi/Gr/Common.h>
  9. namespace anki {
  10. /// @addtogroup shader_compiler
  11. /// @{
  12. constexpr const char* SHADER_BINARY_MAGIC = "ANKISDR7"; ///< WARNING: If changed change SHADER_BINARY_VERSION
  13. constexpr U32 SHADER_BINARY_VERSION = 7;
  14. /// A wrapper over the POD ShaderProgramBinary class.
  15. /// @memberof ShaderProgramCompiler
  16. class ShaderProgramBinaryWrapper
  17. {
  18. friend Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem,
  19. ShaderProgramPostParseInterface* postParseCallback,
  20. ShaderProgramAsyncTaskInterface* taskManager,
  21. GenericMemoryPoolAllocator<U8> tempAllocator,
  22. const ShaderCompilerOptions& compilerOptions,
  23. ShaderProgramBinaryWrapper& binary);
  24. public:
  25. ShaderProgramBinaryWrapper(GenericMemoryPoolAllocator<U8> alloc)
  26. : m_alloc(alloc)
  27. {
  28. }
  29. ShaderProgramBinaryWrapper(const ShaderProgramBinaryWrapper&) = delete; // Non-copyable
  30. ~ShaderProgramBinaryWrapper()
  31. {
  32. cleanup();
  33. }
  34. ShaderProgramBinaryWrapper& operator=(const ShaderProgramBinaryWrapper&) = delete; // Non-copyable
  35. ANKI_USE_RESULT Error serializeToFile(CString fname) const;
  36. ANKI_USE_RESULT Error deserializeFromFile(CString fname);
  37. const ShaderProgramBinary& getBinary() const
  38. {
  39. ANKI_ASSERT(m_binary);
  40. return *m_binary;
  41. }
  42. private:
  43. GenericMemoryPoolAllocator<U8> m_alloc;
  44. ShaderProgramBinary* m_binary = nullptr;
  45. Bool m_singleAllocation = false;
  46. void cleanup();
  47. };
  48. /// Takes an AnKi special shader program and spits a binary.
  49. ANKI_USE_RESULT Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
  50. ShaderProgramPostParseInterface* postParseCallback,
  51. ShaderProgramAsyncTaskInterface* taskManager,
  52. GenericMemoryPoolAllocator<U8> tempAllocator,
  53. const ShaderCompilerOptions& compilerOptions,
  54. ShaderProgramBinaryWrapper& binary);
  55. /// @}
  56. } // end namespace anki