GenericCompute.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Renderer/GenericCompute.h>
  6. #include <AnKi/Renderer/Renderer.h>
  7. #include <AnKi/Renderer/DepthDownscale.h>
  8. #include <AnKi/Renderer/RenderQueue.h>
  9. namespace anki {
  10. GenericCompute::~GenericCompute()
  11. {
  12. }
  13. void GenericCompute::populateRenderGraph(RenderingContext& ctx)
  14. {
  15. if(ctx.m_renderQueue->m_genericGpuComputeJobs.getSize() == 0)
  16. {
  17. return;
  18. }
  19. ComputeRenderPassDescription& pass = ctx.m_renderGraphDescr.newComputeRenderPass("Generic compute");
  20. pass.setWork([this, &ctx](RenderPassWorkContext& rgraphCtx) {
  21. run(ctx, rgraphCtx);
  22. });
  23. pass.newTextureDependency(m_r->getDepthDownscale().getHiZRt(), TextureUsageBit::kSampledCompute);
  24. }
  25. void GenericCompute::run(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx)
  26. {
  27. ANKI_ASSERT(ctx.m_renderQueue->m_genericGpuComputeJobs.getSize() > 0);
  28. GenericGpuComputeJobQueueElementContext elementCtx;
  29. elementCtx.m_commandBuffer = rgraphCtx.m_commandBuffer;
  30. elementCtx.m_rebarStagingPool = &RebarStagingGpuMemoryPool::getSingleton();
  31. elementCtx.m_viewMatrix = ctx.m_matrices.m_view;
  32. elementCtx.m_viewProjectionMatrix = ctx.m_matrices.m_viewProjection;
  33. elementCtx.m_projectionMatrix = ctx.m_matrices.m_projection;
  34. elementCtx.m_previousViewProjectionMatrix = ctx.m_prevMatrices.m_viewProjection;
  35. elementCtx.m_cameraTransform = ctx.m_matrices.m_cameraTransform;
  36. // Bind some state
  37. rgraphCtx.bindColorTexture(0, 0, m_r->getDepthDownscale().getHiZRt());
  38. for(const GenericGpuComputeJobQueueElement& element : ctx.m_renderQueue->m_genericGpuComputeJobs)
  39. {
  40. ANKI_ASSERT(element.m_callback);
  41. element.m_callback(elementCtx, element.m_userData);
  42. }
  43. }
  44. } // end namespace anki