DepthDownscale.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2009-2022, 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/Renderer/RendererObject.h>
  7. #include <AnKi/Gr.h>
  8. #include <AnKi/Resource/ImageResource.h>
  9. namespace anki {
  10. /// @addtogroup renderer
  11. /// @{
  12. /// Downscales the depth buffer a few times.
  13. class DepthDownscale : public RendererObject
  14. {
  15. public:
  16. DepthDownscale(Renderer* r)
  17. : RendererObject(r)
  18. {
  19. }
  20. ~DepthDownscale();
  21. Error init();
  22. /// Import render targets
  23. void importRenderTargets(RenderingContext& ctx);
  24. /// Populate the rendergraph.
  25. void populateRenderGraph(RenderingContext& ctx);
  26. /// Return a FP color render target with hierarchical Z (min Z) in it's mips.
  27. RenderTargetHandle getHiZRt() const
  28. {
  29. return m_runCtx.m_hizRt;
  30. }
  31. U32 getMipmapCount() const
  32. {
  33. return m_mipCount;
  34. }
  35. void getClientDepthMapInfo(F32*& depthValues, U32& width, U32& height) const
  36. {
  37. width = m_lastMipSize.x();
  38. height = m_lastMipSize.y();
  39. ANKI_ASSERT(m_clientBuffer);
  40. m_clientBuffer->invalidate(0, MAX_PTR_SIZE);
  41. depthValues = static_cast<F32*>(m_clientBufferAddr);
  42. }
  43. private:
  44. TexturePtr m_hizTex;
  45. Bool m_hizTexImportedOnce = false;
  46. ShaderProgramResourcePtr m_prog;
  47. ShaderProgramPtr m_grProg;
  48. ShaderProgramPtr m_firstMipGrProg;
  49. BufferPtr m_counterBuffer;
  50. Bool m_counterBufferZeroed = false;
  51. BufferPtr m_clientBuffer;
  52. void* m_clientBufferAddr = nullptr;
  53. SamplerPtr m_reductionSampler;
  54. DynamicArray<FramebufferDescription> m_fbDescrs;
  55. UVec2 m_lastMipSize;
  56. U32 m_mipCount = 0;
  57. class
  58. {
  59. public:
  60. RenderTargetHandle m_hizRt;
  61. } m_runCtx; ///< Run context.
  62. Error initInternal();
  63. void runCompute(RenderPassWorkContext& rgraphCtx);
  64. void runGraphics(U32 mip, RenderPassWorkContext& rgraphCtx);
  65. };
  66. /// @}
  67. } // end namespace anki