Common.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (C) 2009-present, 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/Gr.h>
  7. #include <AnKi/Util/Ptr.h>
  8. #include <AnKi/Util/CVarSet.h>
  9. #include <AnKi/Shaders/Include/MiscRendererTypes.h>
  10. #include <AnKi/Shaders/Include/ClusteredShadingTypes.h>
  11. #include <AnKi/Scene/GpuSceneArray.h>
  12. namespace anki {
  13. // Forward
  14. #define ANKI_RENDERER_OBJECT_DEF(name, name2, initCondition) class name;
  15. #include <AnKi/Renderer/RendererObject.def.h>
  16. class Renderer;
  17. class RendererObject;
  18. class RenderQueue;
  19. /// @addtogroup renderer
  20. /// @{
  21. #define ANKI_R_LOGI(...) ANKI_LOG("REND", kNormal, __VA_ARGS__)
  22. #define ANKI_R_LOGE(...) ANKI_LOG("REND", kError, __VA_ARGS__)
  23. #define ANKI_R_LOGW(...) ANKI_LOG("REND", kWarning, __VA_ARGS__)
  24. #define ANKI_R_LOGF(...) ANKI_LOG("REND", kFatal, __VA_ARGS__)
  25. #define ANKI_R_LOGV(...) ANKI_LOG("REND", kVerbose, __VA_ARGS__)
  26. class RendererMemoryPool : public HeapMemoryPool, public MakeSingleton<RendererMemoryPool>
  27. {
  28. template<typename>
  29. friend class MakeSingleton;
  30. private:
  31. RendererMemoryPool(AllocAlignedCallback allocCb, void* allocCbUserData)
  32. : HeapMemoryPool(allocCb, allocCbUserData, "RendererMemPool")
  33. {
  34. }
  35. ~RendererMemoryPool() = default;
  36. };
  37. ANKI_DEFINE_SUBMODULE_UTIL_CONTAINERS(Renderer, RendererMemoryPool)
  38. /// Don't create second level command buffers if they contain more drawcalls than this constant.
  39. constexpr U32 kMinDrawcallsPerSecondaryCommandBuffer = 16;
  40. /// Bloom size is rendererSize/kBloomFraction.
  41. constexpr U32 kBloomFraction = 4;
  42. /// Computes the 'a' and 'b' numbers for linearizeDepthOptimal (see shaders)
  43. inline void computeLinearizeDepthOptimal(F32 near, F32 far, F32& a, F32& b)
  44. {
  45. a = (near - far) / near;
  46. b = far / near;
  47. }
  48. constexpr U32 kGBufferColorRenderTargetCount = 4;
  49. /// Downsample and blur down to a texture with size kDownscaleBurDownTo
  50. constexpr U32 kDownscaleBurDownTo = 32;
  51. inline constexpr Array<Format, kGBufferColorRenderTargetCount> kGBufferColorRenderTargetFormats = {
  52. {Format::kR8G8B8A8_Unorm, Format::kR8G8B8A8_Unorm, Format::kA2B10G10R10_Unorm_Pack32, Format::kR16G16_Snorm}};
  53. /// Rendering context.
  54. class RenderingContext
  55. {
  56. public:
  57. RenderGraphBuilder m_renderGraphDescr;
  58. CommonMatrices m_matrices;
  59. CommonMatrices m_prevMatrices;
  60. /// The render target that the Renderer will populate.
  61. RenderTargetHandle m_swapchainRenderTarget;
  62. Array<Mat4, kMaxShadowCascades> m_dirLightTextureMatrices;
  63. Array<F32, kMaxShadowCascades> m_dirLightFarPlanes = {};
  64. Array<F32, kMaxShadowCascades> m_dirLightPcfTexelRadius = {};
  65. BufferView m_globalRenderingConstantsBuffer;
  66. RenderingContext(StackMemoryPool* pool)
  67. : m_renderGraphDescr(pool)
  68. {
  69. }
  70. RenderingContext(const RenderingContext&) = delete;
  71. RenderingContext& operator=(const RenderingContext&) = delete;
  72. };
  73. /// Choose the detail of a shadow cascade. 0 means high detail and >0 is progressively lower.
  74. inline U32 chooseDirectionalLightShadowCascadeDetail(U32 cascade)
  75. {
  76. return (cascade <= 1) ? 0 : 1;
  77. }
  78. /// @}
  79. } // end namespace anki