ShaderProgramCompiler.h 2.2 KB

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