maxwell_dma.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/maxwell_dma.h"
  6. #include "video_core/textures/decoders.h"
  7. namespace Tegra {
  8. namespace Engines {
  9. MaxwellDMA::MaxwellDMA(MemoryManager& memory_manager) : memory_manager(memory_manager) {}
  10. void MaxwellDMA::WriteReg(u32 method, u32 value) {
  11. ASSERT_MSG(method < Regs::NUM_REGS,
  12. "Invalid MaxwellDMA register, increase the size of the Regs structure");
  13. regs.reg_array[method] = value;
  14. #define MAXWELLDMA_REG_INDEX(field_name) \
  15. (offsetof(Tegra::Engines::MaxwellDMA::Regs, field_name) / sizeof(u32))
  16. switch (method) {
  17. case MAXWELLDMA_REG_INDEX(exec): {
  18. HandleCopy();
  19. break;
  20. }
  21. }
  22. #undef MAXWELLDMA_REG_INDEX
  23. }
  24. void MaxwellDMA::HandleCopy() {
  25. LOG_WARNING(HW_GPU, "Requested a DMA copy");
  26. const GPUVAddr source = regs.src_address.Address();
  27. const GPUVAddr dest = regs.dst_address.Address();
  28. const VAddr source_cpu = *memory_manager.GpuToCpuAddress(source);
  29. const VAddr dest_cpu = *memory_manager.GpuToCpuAddress(dest);
  30. // TODO(Subv): Perform more research and implement all features of this engine.
  31. ASSERT(regs.exec.enable_swizzle == 0);
  32. ASSERT(regs.exec.query_mode == Regs::QueryMode::None);
  33. ASSERT(regs.exec.query_intr == Regs::QueryIntr::None);
  34. ASSERT(regs.exec.copy_mode == Regs::CopyMode::Unk2);
  35. ASSERT(regs.src_params.pos_x == 0);
  36. ASSERT(regs.src_params.pos_y == 0);
  37. ASSERT(regs.dst_params.pos_x == 0);
  38. ASSERT(regs.dst_params.pos_y == 0);
  39. if (regs.exec.is_dst_linear == regs.exec.is_src_linear) {
  40. size_t copy_size = regs.x_count;
  41. // When the enable_2d bit is disabled, the copy is performed as if we were copying a 1D
  42. // buffer of length `x_count`, otherwise we copy a 2D buffer of size (x_count, y_count).
  43. if (regs.exec.enable_2d) {
  44. copy_size = copy_size * regs.y_count;
  45. }
  46. Memory::CopyBlock(dest_cpu, source_cpu, copy_size);
  47. return;
  48. }
  49. ASSERT(regs.exec.enable_2d == 1);
  50. u8* src_buffer = Memory::GetPointer(source_cpu);
  51. u8* dst_buffer = Memory::GetPointer(dest_cpu);
  52. if (regs.exec.is_dst_linear && !regs.exec.is_src_linear) {
  53. // If the input is tiled and the output is linear, deswizzle the input and copy it over.
  54. Texture::CopySwizzledData(regs.src_params.size_x, regs.src_params.size_y, 1, 1, src_buffer,
  55. dst_buffer, true, regs.src_params.BlockHeight());
  56. } else {
  57. // If the input is linear and the output is tiled, swizzle the input and copy it over.
  58. Texture::CopySwizzledData(regs.dst_params.size_x, regs.dst_params.size_y, 1, 1, dst_buffer,
  59. src_buffer, false, regs.dst_params.BlockHeight());
  60. }
  61. }
  62. } // namespace Engines
  63. } // namespace Tegra