kepler_compute.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <bitset>
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "core/core.h"
  7. #include "video_core/engines/kepler_compute.h"
  8. #include "video_core/engines/maxwell_3d.h"
  9. #include "video_core/memory_manager.h"
  10. #include "video_core/rasterizer_interface.h"
  11. #include "video_core/textures/decoders.h"
  12. namespace Tegra::Engines {
  13. KeplerCompute::KeplerCompute(Core::System& system_, MemoryManager& memory_manager_)
  14. : system{system_}, memory_manager{memory_manager_}, upload_state{memory_manager, regs.upload} {
  15. execution_mask.reset();
  16. execution_mask[KEPLER_COMPUTE_REG_INDEX(exec_upload)] = true;
  17. execution_mask[KEPLER_COMPUTE_REG_INDEX(data_upload)] = true;
  18. execution_mask[KEPLER_COMPUTE_REG_INDEX(launch)] = true;
  19. }
  20. KeplerCompute::~KeplerCompute() = default;
  21. void KeplerCompute::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
  22. rasterizer = rasterizer_;
  23. upload_state.BindRasterizer(rasterizer);
  24. }
  25. void KeplerCompute::ConsumeSinkImpl() {
  26. for (auto [method, value] : method_sink) {
  27. regs.reg_array[method] = value;
  28. }
  29. method_sink.clear();
  30. }
  31. void KeplerCompute::CallMethod(u32 method, u32 method_argument, bool is_last_call) {
  32. ASSERT_MSG(method < Regs::NUM_REGS,
  33. "Invalid KeplerCompute register, increase the size of the Regs structure");
  34. regs.reg_array[method] = method_argument;
  35. switch (method) {
  36. case KEPLER_COMPUTE_REG_INDEX(exec_upload): {
  37. UploadInfo info{.upload_address = upload_address,
  38. .exec_address = upload_state.ExecTargetAddress(),
  39. .copy_size = upload_state.GetUploadSize()};
  40. uploads.push_back(info);
  41. upload_state.ProcessExec(regs.exec_upload.linear != 0);
  42. break;
  43. }
  44. case KEPLER_COMPUTE_REG_INDEX(data_upload): {
  45. upload_address = current_dma_segment;
  46. upload_state.ProcessData(method_argument, is_last_call);
  47. break;
  48. }
  49. case KEPLER_COMPUTE_REG_INDEX(launch): {
  50. const GPUVAddr launch_desc_loc = regs.launch_desc_loc.Address();
  51. for (auto& data : uploads) {
  52. const GPUVAddr offset = data.exec_address - launch_desc_loc;
  53. if (offset / sizeof(u32) == LAUNCH_REG_INDEX(grid_dim_x) &&
  54. memory_manager.IsMemoryDirty(data.upload_address, data.copy_size)) {
  55. indirect_compute = {data.upload_address};
  56. }
  57. }
  58. uploads.clear();
  59. ProcessLaunch();
  60. indirect_compute = std::nullopt;
  61. break;
  62. }
  63. default:
  64. break;
  65. }
  66. }
  67. void KeplerCompute::CallMultiMethod(u32 method, const u32* base_start, u32 amount,
  68. u32 methods_pending) {
  69. switch (method) {
  70. case KEPLER_COMPUTE_REG_INDEX(data_upload):
  71. upload_address = current_dma_segment;
  72. upload_state.ProcessData(base_start, amount);
  73. return;
  74. default:
  75. for (u32 i = 0; i < amount; i++) {
  76. CallMethod(method, base_start[i], methods_pending - i <= 1);
  77. }
  78. break;
  79. }
  80. }
  81. void KeplerCompute::ProcessLaunch() {
  82. const GPUVAddr launch_desc_loc = regs.launch_desc_loc.Address();
  83. memory_manager.ReadBlockUnsafe(launch_desc_loc, &launch_description,
  84. LaunchParams::NUM_LAUNCH_PARAMETERS * sizeof(u32));
  85. rasterizer->DispatchCompute();
  86. }
  87. Texture::TICEntry KeplerCompute::GetTICEntry(u32 tic_index) const {
  88. const GPUVAddr tic_address_gpu{regs.tic.Address() + tic_index * sizeof(Texture::TICEntry)};
  89. Texture::TICEntry tic_entry;
  90. memory_manager.ReadBlockUnsafe(tic_address_gpu, &tic_entry, sizeof(Texture::TICEntry));
  91. return tic_entry;
  92. }
  93. Texture::TSCEntry KeplerCompute::GetTSCEntry(u32 tsc_index) const {
  94. const GPUVAddr tsc_address_gpu{regs.tsc.Address() + tsc_index * sizeof(Texture::TSCEntry)};
  95. Texture::TSCEntry tsc_entry;
  96. memory_manager.ReadBlockUnsafe(tsc_address_gpu, &tsc_entry, sizeof(Texture::TSCEntry));
  97. return tsc_entry;
  98. }
  99. } // namespace Tegra::Engines