fermi_2d.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/rasterizer_interface.h"
  7. #include "video_core/textures/decoders.h"
  8. namespace Tegra::Engines {
  9. Fermi2D::Fermi2D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager)
  10. : memory_manager(memory_manager), rasterizer{rasterizer} {}
  11. void Fermi2D::WriteReg(u32 method, u32 value) {
  12. ASSERT_MSG(method < Regs::NUM_REGS,
  13. "Invalid Fermi2D register, increase the size of the Regs structure");
  14. regs.reg_array[method] = value;
  15. switch (method) {
  16. case FERMI2D_REG_INDEX(trigger): {
  17. HandleSurfaceCopy();
  18. break;
  19. }
  20. }
  21. }
  22. void Fermi2D::HandleSurfaceCopy() {
  23. LOG_WARNING(HW_GPU, "Requested a surface copy with operation {}",
  24. static_cast<u32>(regs.operation));
  25. const GPUVAddr source = regs.src.Address();
  26. const GPUVAddr dest = regs.dst.Address();
  27. // TODO(Subv): Only same-format and same-size copies are allowed for now.
  28. ASSERT(regs.src.format == regs.dst.format);
  29. ASSERT(regs.src.width * regs.src.height == regs.dst.width * regs.dst.height);
  30. // TODO(Subv): Only raw copies are implemented.
  31. ASSERT(regs.operation == Regs::Operation::SrcCopy);
  32. const VAddr source_cpu = *memory_manager.GpuToCpuAddress(source);
  33. const VAddr dest_cpu = *memory_manager.GpuToCpuAddress(dest);
  34. u32 src_bytes_per_pixel = RenderTargetBytesPerPixel(regs.src.format);
  35. u32 dst_bytes_per_pixel = RenderTargetBytesPerPixel(regs.dst.format);
  36. if (!rasterizer.AccelerateSurfaceCopy(regs.src, regs.dst)) {
  37. // TODO(bunnei): The below implementation currently will not get hit, as
  38. // AccelerateSurfaceCopy tries to always copy and will always return success. This should be
  39. // changed once we properly support flushing.
  40. if (regs.src.linear == regs.dst.linear) {
  41. // If the input layout and the output layout are the same, just perform a raw copy.
  42. ASSERT(regs.src.BlockHeight() == regs.dst.BlockHeight());
  43. Memory::CopyBlock(dest_cpu, source_cpu,
  44. src_bytes_per_pixel * regs.dst.width * regs.dst.height);
  45. return;
  46. }
  47. u8* src_buffer = Memory::GetPointer(source_cpu);
  48. u8* dst_buffer = Memory::GetPointer(dest_cpu);
  49. if (!regs.src.linear && regs.dst.linear) {
  50. // If the input is tiled and the output is linear, deswizzle the input and copy it over.
  51. Texture::CopySwizzledData(regs.src.width, regs.src.height, regs.src.depth,
  52. src_bytes_per_pixel, dst_bytes_per_pixel, src_buffer,
  53. dst_buffer, true, regs.src.BlockHeight(),
  54. regs.src.BlockDepth());
  55. } else {
  56. // If the input is linear and the output is tiled, swizzle the input and copy it over.
  57. Texture::CopySwizzledData(regs.src.width, regs.src.height, regs.src.depth,
  58. src_bytes_per_pixel, dst_bytes_per_pixel, dst_buffer,
  59. src_buffer, false, regs.dst.BlockHeight(),
  60. regs.dst.BlockDepth());
  61. }
  62. }
  63. }
  64. } // namespace Tegra::Engines