gpu_asynch.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/core.h"
  5. #include "core/hardware_interrupt_manager.h"
  6. #include "video_core/gpu_asynch.h"
  7. #include "video_core/gpu_thread.h"
  8. #include "video_core/renderer_base.h"
  9. namespace VideoCommon {
  10. GPUAsynch::GPUAsynch(Core::System& system, bool use_nvdec)
  11. : GPU{system, true, use_nvdec}, gpu_thread{system} {}
  12. GPUAsynch::~GPUAsynch() = default;
  13. void GPUAsynch::Start() {
  14. gpu_thread.StartThread(*renderer, renderer->Context(), *dma_pusher, *cdma_pusher);
  15. cpu_context = renderer->GetRenderWindow().CreateSharedContext();
  16. cpu_context->MakeCurrent();
  17. }
  18. void GPUAsynch::ObtainContext() {
  19. cpu_context->MakeCurrent();
  20. }
  21. void GPUAsynch::ReleaseContext() {
  22. cpu_context->DoneCurrent();
  23. }
  24. void GPUAsynch::PushGPUEntries(Tegra::CommandList&& entries) {
  25. gpu_thread.SubmitList(std::move(entries));
  26. }
  27. void GPUAsynch::PushCommandBuffer(Tegra::ChCommandHeaderList& entries) {
  28. if (!use_nvdec) {
  29. return;
  30. }
  31. // This condition fires when a video stream ends, clear all intermediary data
  32. if (entries[0].raw == 0xDEADB33F) {
  33. cdma_pusher.reset();
  34. return;
  35. }
  36. if (!cdma_pusher) {
  37. cdma_pusher = std::make_unique<Tegra::CDmaPusher>(*this);
  38. }
  39. // SubmitCommandBuffer would make the nvdec operations async, this is not currently working
  40. // TODO(ameerj): RE proper async nvdec operation
  41. // gpu_thread.SubmitCommandBuffer(std::move(entries));
  42. cdma_pusher->Push(std::move(entries));
  43. cdma_pusher->DispatchCalls();
  44. }
  45. void GPUAsynch::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
  46. gpu_thread.SwapBuffers(framebuffer);
  47. }
  48. void GPUAsynch::FlushRegion(VAddr addr, u64 size) {
  49. gpu_thread.FlushRegion(addr, size);
  50. }
  51. void GPUAsynch::InvalidateRegion(VAddr addr, u64 size) {
  52. gpu_thread.InvalidateRegion(addr, size);
  53. }
  54. void GPUAsynch::FlushAndInvalidateRegion(VAddr addr, u64 size) {
  55. gpu_thread.FlushAndInvalidateRegion(addr, size);
  56. }
  57. void GPUAsynch::TriggerCpuInterrupt(const u32 syncpoint_id, const u32 value) const {
  58. auto& interrupt_manager = system.InterruptManager();
  59. interrupt_manager.GPUInterruptSyncpt(syncpoint_id, value);
  60. }
  61. void GPUAsynch::WaitIdle() const {
  62. gpu_thread.WaitIdle();
  63. }
  64. void GPUAsynch::OnCommandListEnd() {
  65. gpu_thread.OnCommandListEnd();
  66. }
  67. } // namespace VideoCommon