fermi_2d.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "core/memory.h"
  5. #include "video_core/engines/fermi_2d.h"
  6. #include "video_core/textures/decoders.h"
  7. namespace Tegra {
  8. namespace Engines {
  9. Fermi2D::Fermi2D(MemoryManager& memory_manager) : memory_manager(memory_manager) {}
  10. void Fermi2D::WriteReg(u32 method, u32 value) {
  11. ASSERT_MSG(method < Regs::NUM_REGS,
  12. "Invalid Fermi2D register, increase the size of the Regs structure");
  13. regs.reg_array[method] = value;
  14. switch (method) {
  15. case FERMI2D_REG_INDEX(trigger): {
  16. HandleSurfaceCopy();
  17. break;
  18. }
  19. }
  20. }
  21. void Fermi2D::HandleSurfaceCopy() {
  22. NGLOG_WARNING(HW_GPU, "Requested a surface copy with operation {}",
  23. static_cast<u32>(regs.operation));
  24. const GPUVAddr source = regs.src.Address();
  25. const GPUVAddr dest = regs.dst.Address();
  26. // TODO(Subv): Only same-format and same-size copies are allowed for now.
  27. ASSERT(regs.src.format == regs.dst.format);
  28. ASSERT(regs.src.width * regs.src.height == regs.dst.width * regs.dst.height);
  29. // TODO(Subv): Only raw copies are implemented.
  30. ASSERT(regs.operation == Regs::Operation::SrcCopy);
  31. const VAddr source_cpu = *memory_manager.GpuToCpuAddress(source);
  32. const VAddr dest_cpu = *memory_manager.GpuToCpuAddress(dest);
  33. u32 src_bytes_per_pixel = RenderTargetBytesPerPixel(regs.src.format);
  34. u32 dst_bytes_per_pixel = RenderTargetBytesPerPixel(regs.dst.format);
  35. if (regs.src.linear == regs.dst.linear) {
  36. // If the input layout and the output layout are the same, just perform a raw copy.
  37. Memory::CopyBlock(dest_cpu, source_cpu,
  38. src_bytes_per_pixel * regs.dst.width * regs.dst.height);
  39. return;
  40. }
  41. u8* src_buffer = Memory::GetPointer(source_cpu);
  42. u8* dst_buffer = Memory::GetPointer(dest_cpu);
  43. if (!regs.src.linear && regs.dst.linear) {
  44. // If the input is tiled and the output is linear, deswizzle the input and copy it over.
  45. Texture::CopySwizzledData(regs.src.width, regs.src.height, src_bytes_per_pixel,
  46. dst_bytes_per_pixel, src_buffer, dst_buffer, true,
  47. regs.src.block_height);
  48. } else {
  49. // If the input is linear and the output is tiled, swizzle the input and copy it over.
  50. Texture::CopySwizzledData(regs.src.width, regs.src.height, src_bytes_per_pixel,
  51. dst_bytes_per_pixel, dst_buffer, src_buffer, false,
  52. regs.dst.block_height);
  53. }
  54. }
  55. } // namespace Engines
  56. } // namespace Tegra