fermi_2d.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "video_core/engines/fermi_2d.h"
  7. #include "video_core/memory_manager.h"
  8. #include "video_core/rasterizer_interface.h"
  9. namespace Tegra::Engines {
  10. Fermi2D::Fermi2D(VideoCore::RasterizerInterface& rasterizer) : rasterizer{rasterizer} {}
  11. void Fermi2D::CallMethod(const GPU::MethodCall& method_call) {
  12. ASSERT_MSG(method_call.method < Regs::NUM_REGS,
  13. "Invalid Fermi2D register, increase the size of the Regs structure");
  14. regs.reg_array[method_call.method] = method_call.argument;
  15. switch (method_call.method) {
  16. // Trigger the surface copy on the last register write. This is blit_src_y, but this is 64-bit,
  17. // so trigger on the second 32-bit write.
  18. case FERMI2D_REG_INDEX(blit_src_y) + 1: {
  19. HandleSurfaceCopy();
  20. break;
  21. }
  22. }
  23. }
  24. static std::pair<u32, u32> DelimitLine(u32 src_1, u32 src_2, u32 dst_1, u32 dst_2, u32 src_line) {
  25. const u32 line_a = src_2 - src_1;
  26. const u32 line_b = dst_2 - dst_1;
  27. const u32 excess = std::max<s32>(0, line_a - src_line + src_1);
  28. return {line_b - (excess * line_b) / line_a, excess};
  29. }
  30. void Fermi2D::HandleSurfaceCopy() {
  31. LOG_DEBUG(HW_GPU, "Requested a surface copy with operation {}",
  32. static_cast<u32>(regs.operation));
  33. // TODO(Subv): Only raw copies are implemented.
  34. ASSERT(regs.operation == Operation::SrcCopy);
  35. const u32 src_blit_x1{static_cast<u32>(regs.blit_src_x >> 32)};
  36. const u32 src_blit_y1{static_cast<u32>(regs.blit_src_y >> 32)};
  37. u32 src_blit_x2, src_blit_y2;
  38. if (regs.blit_control.origin == Origin::Corner) {
  39. src_blit_x2 =
  40. static_cast<u32>((regs.blit_src_x + (regs.blit_du_dx * regs.blit_dst_width)) >> 32);
  41. src_blit_y2 =
  42. static_cast<u32>((regs.blit_src_y + (regs.blit_dv_dy * regs.blit_dst_height)) >> 32);
  43. } else {
  44. src_blit_x2 = static_cast<u32>((regs.blit_src_x >> 32) + regs.blit_dst_width);
  45. src_blit_y2 = static_cast<u32>((regs.blit_src_y >> 32) + regs.blit_dst_height);
  46. }
  47. u32 dst_blit_x2 = regs.blit_dst_x + regs.blit_dst_width;
  48. u32 dst_blit_y2 = regs.blit_dst_y + regs.blit_dst_height;
  49. const auto [new_dst_w, src_excess_x] =
  50. DelimitLine(src_blit_x1, src_blit_x2, regs.blit_dst_x, dst_blit_x2, regs.src.width);
  51. const auto [new_dst_h, src_excess_y] =
  52. DelimitLine(src_blit_y1, src_blit_y2, regs.blit_dst_y, dst_blit_y2, regs.src.height);
  53. dst_blit_x2 = new_dst_w + regs.blit_dst_x;
  54. src_blit_x2 = src_blit_x2 - src_excess_x;
  55. dst_blit_y2 = new_dst_h + regs.blit_dst_y;
  56. src_blit_y2 = src_blit_y2 - src_excess_y;
  57. const auto [new_src_w, dst_excess_x] =
  58. DelimitLine(regs.blit_dst_x, dst_blit_x2, src_blit_x1, src_blit_x2, regs.dst.width);
  59. const auto [new_src_h, dst_excess_y] =
  60. DelimitLine(regs.blit_dst_y, dst_blit_y2, src_blit_y1, src_blit_y2, regs.dst.height);
  61. src_blit_x2 = new_src_w + src_blit_x1;
  62. dst_blit_x2 = dst_blit_x2 - dst_excess_x;
  63. src_blit_y2 = new_src_h + src_blit_y1;
  64. dst_blit_y2 = dst_blit_y2 - dst_excess_y;
  65. const Common::Rectangle<u32> src_rect{src_blit_x1, src_blit_y1, src_blit_x2, src_blit_y2};
  66. const Common::Rectangle<u32> dst_rect{regs.blit_dst_x, regs.blit_dst_y, dst_blit_x2,
  67. dst_blit_y2};
  68. Config copy_config;
  69. copy_config.operation = regs.operation;
  70. copy_config.filter = regs.blit_control.filter;
  71. copy_config.src_rect = src_rect;
  72. copy_config.dst_rect = dst_rect;
  73. if (!rasterizer.AccelerateSurfaceCopy(regs.src, regs.dst, copy_config)) {
  74. UNIMPLEMENTED();
  75. }
  76. }
  77. } // namespace Tegra::Engines