BsGpuProgramManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Utility/BsModule.h"
  6. #include "Error/BsException.h"
  7. #include "RenderAPI/BsGpuProgram.h"
  8. namespace bs
  9. {
  10. /** @addtogroup RenderAPI-Internal
  11. * @{
  12. */
  13. /**
  14. * Manager responsible for creating GPU programs. It will automatically try to find the appropriate handler for a
  15. * specific GPU program language and create the program if possible.
  16. *
  17. * @note Sim thread only.
  18. */
  19. class BS_CORE_EXPORT GpuProgramManager : public Module<GpuProgramManager>
  20. {
  21. public:
  22. /** @copydoc GpuProgram::create */
  23. SPtr<GpuProgram> create(const GPU_PROGRAM_DESC& desc);
  24. /**
  25. * Creates a completely empty and uninitialized GpuProgram. Should only be used for specific purposes, like
  26. * deserialization, as it requires additional manual initialization that is not required normally.
  27. */
  28. SPtr<GpuProgram> createEmpty(const String& language, GpuProgramType type);
  29. };
  30. namespace ct
  31. {
  32. /** Factory responsible for creating GPU programs of a certain type. */
  33. class BS_CORE_EXPORT GpuProgramFactory
  34. {
  35. public:
  36. GpuProgramFactory() {}
  37. virtual ~GpuProgramFactory() { }
  38. /** @copydoc GpuProgram::create */
  39. virtual SPtr<GpuProgram> create(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  40. /** @copydoc bs::GpuProgramManager::createEmpty */
  41. virtual SPtr<GpuProgram> create(GpuProgramType type, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  42. };
  43. /**
  44. * Manager responsible for creating GPU programs. It will automatically try to find the appropriate handler for a
  45. * specific GPU program language and create the program if possible.
  46. *
  47. * @note Core thread only unless otherwise specified.
  48. */
  49. class BS_CORE_EXPORT GpuProgramManager : public Module<GpuProgramManager>
  50. {
  51. public:
  52. GpuProgramManager();
  53. virtual ~GpuProgramManager();
  54. /**
  55. * Registers a new factory that is able to create GPU programs for a certain language. If any other factory for the
  56. * same language exists, it will overwrite it.
  57. */
  58. void addFactory(const String& language, GpuProgramFactory* factory);
  59. /**
  60. * Unregisters a GPU program factory, essentially making it not possible to create GPU programs using the language
  61. * the factory supported.
  62. */
  63. void removeFactory(const String& language);
  64. /** Query if a GPU program language is supported (for example "hlsl", "glsl"). Thread safe. */
  65. bool isLanguageSupported(const String& language);
  66. /** @copydoc GpuProgram::create */
  67. SPtr<GpuProgram> create(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  68. protected:
  69. friend class bs::GpuProgram;
  70. /**
  71. * Creates a GPU program without initializing it.
  72. *
  73. * @see create
  74. */
  75. SPtr<GpuProgram> createInternal(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  76. /** Attempts to find a factory for the specified language. Returns null if it cannot find one. */
  77. GpuProgramFactory* getFactory(const String& language);
  78. protected:
  79. Mutex mMutex;
  80. UnorderedMap<String, GpuProgramFactory*> mFactories;
  81. GpuProgramFactory* mNullFactory; /**< Factory for dealing with GPU programs that can't be created. */
  82. };
  83. }
  84. /** @} */
  85. }