GenericCompute.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2009-2020, 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. {
  11. GenericCompute::~GenericCompute()
  12. {
  13. }
  14. void GenericCompute::populateRenderGraph(RenderingContext& ctx)
  15. {
  16. if(ctx.m_renderQueue->m_genericGpuComputeJobs.getSize() == 0)
  17. {
  18. return;
  19. }
  20. m_runCtx.m_ctx = &ctx;
  21. ComputeRenderPassDescription& pass = ctx.m_renderGraphDescr.newComputeRenderPass("Generic compute");
  22. pass.setWork(
  23. [](RenderPassWorkContext& rgraphCtx) {
  24. GenericCompute* const self = static_cast<GenericCompute*>(rgraphCtx.m_userData);
  25. self->run(rgraphCtx);
  26. },
  27. this, 0);
  28. pass.newDependency({m_r->getDepthDownscale().getHiZRt(), TextureUsageBit::SAMPLED_COMPUTE});
  29. }
  30. void GenericCompute::run(RenderPassWorkContext& rgraphCtx)
  31. {
  32. ANKI_ASSERT(m_runCtx.m_ctx->m_renderQueue->m_genericGpuComputeJobs.getSize() > 0);
  33. GenericGpuComputeJobQueueElementContext elementCtx;
  34. elementCtx.m_commandBuffer = rgraphCtx.m_commandBuffer;
  35. elementCtx.m_stagingGpuAllocator = &m_r->getStagingGpuMemoryManager();
  36. elementCtx.m_viewMatrix = m_runCtx.m_ctx->m_matrices.m_view;
  37. elementCtx.m_viewProjectionMatrix = m_runCtx.m_ctx->m_matrices.m_viewProjection;
  38. elementCtx.m_projectionMatrix = m_runCtx.m_ctx->m_matrices.m_projection;
  39. elementCtx.m_previousViewProjectionMatrix = m_runCtx.m_ctx->m_prevMatrices.m_viewProjection;
  40. elementCtx.m_cameraTransform = m_runCtx.m_ctx->m_matrices.m_cameraTransform;
  41. // Bind some state
  42. rgraphCtx.bindTexture(0, 0, m_r->getDepthDownscale().getHiZRt(), TextureSubresourceInfo());
  43. for(const GenericGpuComputeJobQueueElement& element : m_runCtx.m_ctx->m_renderQueue->m_genericGpuComputeJobs)
  44. {
  45. ANKI_ASSERT(element.m_callback);
  46. element.m_callback(elementCtx, element.m_userData);
  47. }
  48. }
  49. } // end namespace anki