kepler_compute.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. upload_state.ProcessExec(regs.exec_upload.linear != 0);
  38. break;
  39. }
  40. case KEPLER_COMPUTE_REG_INDEX(data_upload): {
  41. upload_state.ProcessData(method_argument, is_last_call);
  42. break;
  43. }
  44. case KEPLER_COMPUTE_REG_INDEX(launch):
  45. ProcessLaunch();
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. void KeplerCompute::CallMultiMethod(u32 method, const u32* base_start, u32 amount,
  52. u32 methods_pending) {
  53. switch (method) {
  54. case KEPLER_COMPUTE_REG_INDEX(data_upload):
  55. upload_state.ProcessData(base_start, amount);
  56. return;
  57. default:
  58. for (u32 i = 0; i < amount; i++) {
  59. CallMethod(method, base_start[i], methods_pending - i <= 1);
  60. }
  61. break;
  62. }
  63. }
  64. void KeplerCompute::ProcessLaunch() {
  65. const GPUVAddr launch_desc_loc = regs.launch_desc_loc.Address();
  66. memory_manager.ReadBlockUnsafe(launch_desc_loc, &launch_description,
  67. LaunchParams::NUM_LAUNCH_PARAMETERS * sizeof(u32));
  68. rasterizer->DispatchCompute();
  69. }
  70. Texture::TICEntry KeplerCompute::GetTICEntry(u32 tic_index) const {
  71. const GPUVAddr tic_address_gpu{regs.tic.Address() + tic_index * sizeof(Texture::TICEntry)};
  72. Texture::TICEntry tic_entry;
  73. memory_manager.ReadBlockUnsafe(tic_address_gpu, &tic_entry, sizeof(Texture::TICEntry));
  74. return tic_entry;
  75. }
  76. Texture::TSCEntry KeplerCompute::GetTSCEntry(u32 tsc_index) const {
  77. const GPUVAddr tsc_address_gpu{regs.tsc.Address() + tsc_index * sizeof(Texture::TSCEntry)};
  78. Texture::TSCEntry tsc_entry;
  79. memory_manager.ReadBlockUnsafe(tsc_address_gpu, &tsc_entry, sizeof(Texture::TSCEntry));
  80. return tsc_entry;
  81. }
  82. } // namespace Tegra::Engines