fermi_2d.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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::Engines {
  8. Fermi2D::Fermi2D(MemoryManager& memory_manager) : memory_manager(memory_manager) {}
  9. void Fermi2D::WriteReg(u32 method, u32 value) {
  10. ASSERT_MSG(method < Regs::NUM_REGS,
  11. "Invalid Fermi2D register, increase the size of the Regs structure");
  12. regs.reg_array[method] = value;
  13. switch (method) {
  14. case FERMI2D_REG_INDEX(trigger): {
  15. HandleSurfaceCopy();
  16. break;
  17. }
  18. }
  19. }
  20. void Fermi2D::HandleSurfaceCopy() {
  21. LOG_WARNING(HW_GPU, "Requested a surface copy with operation {}",
  22. static_cast<u32>(regs.operation));
  23. const GPUVAddr source = regs.src.Address();
  24. const GPUVAddr dest = regs.dst.Address();
  25. // TODO(Subv): Only same-format and same-size copies are allowed for now.
  26. ASSERT(regs.src.format == regs.dst.format);
  27. ASSERT(regs.src.width * regs.src.height == regs.dst.width * regs.dst.height);
  28. // TODO(Subv): Only raw copies are implemented.
  29. ASSERT(regs.operation == Regs::Operation::SrcCopy);
  30. const VAddr source_cpu = *memory_manager.GpuToCpuAddress(source);
  31. const VAddr dest_cpu = *memory_manager.GpuToCpuAddress(dest);
  32. u32 src_bytes_per_pixel = RenderTargetBytesPerPixel(regs.src.format);
  33. u32 dst_bytes_per_pixel = RenderTargetBytesPerPixel(regs.dst.format);
  34. if (regs.src.linear == regs.dst.linear) {
  35. // If the input layout and the output layout are the same, just perform a raw copy.
  36. ASSERT(regs.src.BlockHeight() == regs.dst.BlockHeight());
  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.BlockHeight());
  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.BlockHeight());
  53. }
  54. }
  55. } // namespace Tegra::Engines