2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-11-23 23:20:56 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-04-27 22:07:21 -04:00
|
|
|
#include <array>
|
2022-12-07 00:45:06 -05:00
|
|
|
#include <span>
|
2018-11-27 19:17:33 -05:00
|
|
|
#include <vector>
|
2023-05-23 09:45:54 -04:00
|
|
|
#include <boost/container/small_vector.hpp>
|
2018-11-23 23:20:56 -05:00
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_types.h"
|
2022-12-07 00:45:06 -05:00
|
|
|
#include "common/scratch_buffer.h"
|
2020-04-27 22:07:21 -04:00
|
|
|
#include "video_core/engines/engine_interface.h"
|
2021-11-05 10:52:31 -04:00
|
|
|
#include "video_core/engines/puller.h"
|
2018-11-23 23:20:56 -05:00
|
|
|
|
2020-04-19 16:12:06 -04:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
namespace Tegra {
|
|
|
|
|
2021-11-05 10:52:31 -04:00
|
|
|
namespace Control {
|
|
|
|
struct ChannelState;
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:41:16 -05:00
|
|
|
class GPU;
|
2021-11-05 10:52:31 -04:00
|
|
|
class MemoryManager;
|
2020-11-04 20:41:16 -05:00
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
enum class SubmissionMode : u32 {
|
|
|
|
IncreasingOld = 0,
|
|
|
|
Increasing = 1,
|
|
|
|
NonIncreasingOld = 2,
|
|
|
|
NonIncreasing = 3,
|
|
|
|
Inline = 4,
|
|
|
|
IncreaseOnce = 5
|
|
|
|
};
|
|
|
|
|
2020-10-27 01:11:41 -04:00
|
|
|
// Note that, traditionally, methods are treated as 4-byte addressable locations, and hence
|
|
|
|
// their numbers are written down multiplied by 4 in Docs. Here we are not multiply by 4.
|
|
|
|
// So the values you see in docs might be multiplied by 4.
|
2022-01-30 04:31:13 -05:00
|
|
|
// Register documentation:
|
|
|
|
// https://github.com/NVIDIA/open-gpu-doc/blob/ab27fc22db5de0d02a4cabe08e555663b62db4d4/classes/host/cla26f.h
|
|
|
|
//
|
|
|
|
// Register Description (approx):
|
|
|
|
// https://github.com/NVIDIA/open-gpu-doc/blob/ab27fc22db5de0d02a4cabe08e555663b62db4d4/manuals/volta/gv100/dev_pbdma.ref.txt
|
2020-10-27 01:11:41 -04:00
|
|
|
enum class BufferMethods : u32 {
|
|
|
|
BindObject = 0x0,
|
2022-01-30 04:31:13 -05:00
|
|
|
Illegal = 0x1,
|
2020-10-27 01:11:41 -04:00
|
|
|
Nop = 0x2,
|
|
|
|
SemaphoreAddressHigh = 0x4,
|
|
|
|
SemaphoreAddressLow = 0x5,
|
2022-01-30 04:31:13 -05:00
|
|
|
SemaphoreSequencePayload = 0x6,
|
|
|
|
SemaphoreOperation = 0x7,
|
|
|
|
NonStallInterrupt = 0x8,
|
2020-10-27 01:11:41 -04:00
|
|
|
WrcacheFlush = 0x9,
|
2022-01-30 04:31:13 -05:00
|
|
|
MemOpA = 0xA,
|
|
|
|
MemOpB = 0xB,
|
|
|
|
MemOpC = 0xC,
|
|
|
|
MemOpD = 0xD,
|
2020-10-27 01:11:41 -04:00
|
|
|
RefCnt = 0x14,
|
|
|
|
SemaphoreAcquire = 0x1A,
|
|
|
|
SemaphoreRelease = 0x1B,
|
2022-01-30 04:31:13 -05:00
|
|
|
SyncpointPayload = 0x1C,
|
|
|
|
SyncpointOperation = 0x1D,
|
|
|
|
WaitForIdle = 0x1E,
|
|
|
|
CRCCheck = 0x1F,
|
2020-10-27 01:11:41 -04:00
|
|
|
Yield = 0x20,
|
|
|
|
NonPullerMethods = 0x40,
|
|
|
|
};
|
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
struct CommandListHeader {
|
|
|
|
union {
|
|
|
|
u64 raw;
|
|
|
|
BitField<0, 40, GPUVAddr> addr;
|
|
|
|
BitField<41, 1, u64> is_non_main;
|
|
|
|
BitField<42, 21, u64> size;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
static_assert(sizeof(CommandListHeader) == sizeof(u64), "CommandListHeader is incorrect size");
|
|
|
|
|
|
|
|
union CommandHeader {
|
|
|
|
u32 argument;
|
|
|
|
BitField<0, 13, u32> method;
|
|
|
|
BitField<0, 24, u32> method_count_;
|
|
|
|
BitField<13, 3, u32> subchannel;
|
|
|
|
BitField<16, 13, u32> arg_count;
|
|
|
|
BitField<16, 13, u32> method_count;
|
|
|
|
BitField<29, 3, SubmissionMode> mode;
|
|
|
|
};
|
|
|
|
static_assert(std::is_standard_layout_v<CommandHeader>, "CommandHeader is not standard layout");
|
|
|
|
static_assert(sizeof(CommandHeader) == sizeof(u32), "CommandHeader has incorrect size!");
|
|
|
|
|
2020-11-04 20:41:16 -05:00
|
|
|
inline CommandHeader BuildCommandHeader(BufferMethods method, u32 arg_count, SubmissionMode mode) {
|
2020-10-30 00:13:04 -04:00
|
|
|
CommandHeader result{};
|
|
|
|
result.method.Assign(static_cast<u32>(method));
|
|
|
|
result.arg_count.Assign(arg_count);
|
|
|
|
result.mode.Assign(mode);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CommandList final {
|
|
|
|
CommandList() = default;
|
|
|
|
explicit CommandList(std::size_t size) : command_lists(size) {}
|
2023-05-23 09:45:54 -04:00
|
|
|
explicit CommandList(
|
|
|
|
boost::container::small_vector<CommandHeader, 512>&& prefetch_command_list_)
|
2020-12-04 14:39:12 -05:00
|
|
|
: prefetch_command_list{std::move(prefetch_command_list_)} {}
|
2020-10-30 00:13:04 -04:00
|
|
|
|
2023-05-23 09:45:54 -04:00
|
|
|
boost::container::small_vector<CommandListHeader, 512> command_lists;
|
|
|
|
boost::container::small_vector<CommandHeader, 512> prefetch_command_list;
|
2020-10-30 00:13:04 -04:00
|
|
|
};
|
2018-11-27 19:17:33 -05:00
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
/**
|
|
|
|
* The DmaPusher class implements DMA submission to FIFOs, providing an area of memory that the
|
|
|
|
* emulated app fills with commands and tells PFIFO to process. The pushbuffers are then assembled
|
|
|
|
* into a "command stream" consisting of 32-bit words that make up "commands".
|
|
|
|
* See https://envytools.readthedocs.io/en/latest/hw/fifo/dma-pusher.html#fifo-dma-pusher for
|
|
|
|
* details on this implementation.
|
|
|
|
*/
|
2020-10-30 00:13:04 -04:00
|
|
|
class DmaPusher final {
|
2018-11-23 23:20:56 -05:00
|
|
|
public:
|
2021-11-05 10:52:31 -04:00
|
|
|
explicit DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_,
|
|
|
|
Control::ChannelState& channel_state_);
|
2018-11-23 23:20:56 -05:00
|
|
|
~DmaPusher();
|
|
|
|
|
2018-11-27 19:17:33 -05:00
|
|
|
void Push(CommandList&& entries) {
|
|
|
|
dma_pushbuffer.push(std::move(entries));
|
2018-11-23 23:20:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchCalls();
|
|
|
|
|
2020-12-04 14:39:12 -05:00
|
|
|
void BindSubchannel(Engines::EngineInterface* engine, u32 subchannel_id) {
|
2020-04-27 22:07:21 -04:00
|
|
|
subchannels[subchannel_id] = engine;
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:52:31 -04:00
|
|
|
void BindRasterizer(VideoCore::RasterizerInterface* rasterizer);
|
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
private:
|
2020-04-27 22:07:21 -04:00
|
|
|
static constexpr u32 non_puller_methods = 0x40;
|
|
|
|
static constexpr u32 max_subchannels = 8;
|
2018-11-23 23:20:56 -05:00
|
|
|
bool Step();
|
2022-12-07 00:45:06 -05:00
|
|
|
void ProcessCommands(std::span<const CommandHeader> commands);
|
2018-11-23 23:20:56 -05:00
|
|
|
|
|
|
|
void SetState(const CommandHeader& command_header);
|
|
|
|
|
|
|
|
void CallMethod(u32 argument) const;
|
2020-04-20 02:16:56 -04:00
|
|
|
void CallMultiMethod(const u32* base_start, u32 num_methods) const;
|
2018-11-23 23:20:56 -05:00
|
|
|
|
2022-12-07 00:45:06 -05:00
|
|
|
Common::ScratchBuffer<CommandHeader>
|
|
|
|
command_headers; ///< Buffer for list of commands fetched at once
|
2019-02-19 03:44:33 -05:00
|
|
|
|
2018-11-27 19:17:33 -05:00
|
|
|
std::queue<CommandList> dma_pushbuffer; ///< Queue of command lists to be processed
|
|
|
|
std::size_t dma_pushbuffer_subindex{}; ///< Index within a command list within the pushbuffer
|
2018-11-23 23:20:56 -05:00
|
|
|
|
|
|
|
struct DmaState {
|
|
|
|
u32 method; ///< Current method
|
|
|
|
u32 subchannel; ///< Current subchannel
|
|
|
|
u32 method_count; ///< Current method count
|
|
|
|
u32 length_pending; ///< Large NI command length pending
|
2022-02-09 09:00:05 -05:00
|
|
|
GPUVAddr dma_get; ///< Currently read segment
|
2022-03-05 02:01:13 -05:00
|
|
|
u64 dma_word_offset; ///< Current word ofset from address
|
2019-01-30 12:36:28 -05:00
|
|
|
bool non_incrementing; ///< Current command's NI flag
|
2020-04-27 22:07:21 -04:00
|
|
|
bool is_last_call;
|
2018-11-23 23:20:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
DmaState dma_state{};
|
|
|
|
bool dma_increment_once{};
|
|
|
|
|
2022-12-07 00:45:06 -05:00
|
|
|
const bool ib_enable{true}; ///< IB mode enabled
|
2020-04-19 16:12:06 -04:00
|
|
|
|
2020-12-04 14:39:12 -05:00
|
|
|
std::array<Engines::EngineInterface*, max_subchannels> subchannels{};
|
2020-04-27 22:07:21 -04:00
|
|
|
|
2020-04-19 16:12:06 -04:00
|
|
|
GPU& gpu;
|
|
|
|
Core::System& system;
|
2021-11-05 10:52:31 -04:00
|
|
|
MemoryManager& memory_manager;
|
|
|
|
mutable Engines::Puller puller;
|
2018-11-23 23:20:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Tegra
|