ShaderProgramCompiler.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. {
  11. /// @addtogroup shader_compiler
  12. /// @{
  13. extern const U32 SHADER_BINARY_VERSION;
  14. /// A wrapper over the POD ShaderProgramBinary class.
  15. /// @memberof ShaderProgramCompiler
  16. class ShaderProgramBinaryWrapper : public NonCopyable
  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()
  30. {
  31. cleanup();
  32. }
  33. ANKI_USE_RESULT Error serializeToFile(CString fname) const;
  34. ANKI_USE_RESULT Error deserializeFromFile(CString fname);
  35. const ShaderProgramBinary& getBinary() const
  36. {
  37. ANKI_ASSERT(m_binary);
  38. return *m_binary;
  39. }
  40. private:
  41. GenericMemoryPoolAllocator<U8> m_alloc;
  42. ShaderProgramBinary* m_binary = nullptr;
  43. Bool m_singleAllocation = false;
  44. void cleanup();
  45. };
  46. /// Takes an AnKi special shader program and spits a binary.
  47. ANKI_USE_RESULT Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
  48. ShaderProgramPostParseInterface* postParseCallback,
  49. ShaderProgramAsyncTaskInterface* taskManager,
  50. GenericMemoryPoolAllocator<U8> tempAllocator,
  51. const ShaderCompilerOptions& compilerOptions,
  52. ShaderProgramBinaryWrapper& binary);
  53. /// @}
  54. } // end namespace anki