kepler_memory.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "core/core.h"
  7. #include "core/memory.h"
  8. #include "video_core/engines/kepler_memory.h"
  9. #include "video_core/engines/maxwell_3d.h"
  10. #include "video_core/rasterizer_interface.h"
  11. #include "video_core/renderer_base.h"
  12. namespace Tegra::Engines {
  13. KeplerMemory::KeplerMemory(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
  14. MemoryManager& memory_manager)
  15. : system{system}, memory_manager(memory_manager), rasterizer{rasterizer} {}
  16. KeplerMemory::~KeplerMemory() = default;
  17. void KeplerMemory::CallMethod(const GPU::MethodCall& method_call) {
  18. ASSERT_MSG(method_call.method < Regs::NUM_REGS,
  19. "Invalid KeplerMemory register, increase the size of the Regs structure");
  20. regs.reg_array[method_call.method] = method_call.argument;
  21. switch (method_call.method) {
  22. case KEPLERMEMORY_REG_INDEX(exec): {
  23. state.write_offset = 0;
  24. break;
  25. }
  26. case KEPLERMEMORY_REG_INDEX(data): {
  27. ProcessData(method_call.argument);
  28. break;
  29. }
  30. }
  31. }
  32. void KeplerMemory::ProcessData(u32 data) {
  33. ASSERT_MSG(regs.exec.linear, "Non-linear uploads are not supported");
  34. ASSERT(regs.dest.x == 0 && regs.dest.y == 0 && regs.dest.z == 0);
  35. const GPUVAddr address = regs.dest.Address();
  36. const auto dest_address =
  37. memory_manager.GpuToCpuAddress(address + state.write_offset * sizeof(u32));
  38. ASSERT_MSG(dest_address, "Invalid GPU address");
  39. // We have to invalidate the destination region to evict any outdated surfaces from the cache.
  40. // We do this before actually writing the new data because the destination address might contain
  41. // a dirty surface that will have to be written back to memory.
  42. system.Renderer().Rasterizer().InvalidateRegion(ToCacheAddr(Memory::GetPointer(*dest_address)),
  43. sizeof(u32));
  44. Memory::Write32(*dest_address, data);
  45. system.GPU().Maxwell3D().dirty_flags.OnMemoryWrite();
  46. state.write_offset++;
  47. }
  48. } // namespace Tegra::Engines