2018-11-24 04:20:56 +00:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-04-28 02:07:21 +00:00
|
|
|
#include <array>
|
2018-11-28 00:17:33 +00:00
|
|
|
#include <vector>
|
2018-11-24 04:20:56 +00:00
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_types.h"
|
2020-04-28 02:07:21 +00:00
|
|
|
#include "video_core/engines/engine_interface.h"
|
2018-11-24 04:20:56 +00:00
|
|
|
|
2020-04-19 20:12:06 +00:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2018-11-24 04:20:56 +00:00
|
|
|
namespace Tegra {
|
|
|
|
|
|
|
|
enum class SubmissionMode : u32 {
|
|
|
|
IncreasingOld = 0,
|
|
|
|
Increasing = 1,
|
|
|
|
NonIncreasingOld = 2,
|
|
|
|
NonIncreasing = 3,
|
|
|
|
Inline = 4,
|
|
|
|
IncreaseOnce = 5
|
|
|
|
};
|
|
|
|
|
2020-10-27 05:11:41 +00: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.
|
|
|
|
enum class BufferMethods : u32 {
|
|
|
|
BindObject = 0x0,
|
|
|
|
Nop = 0x2,
|
|
|
|
SemaphoreAddressHigh = 0x4,
|
|
|
|
SemaphoreAddressLow = 0x5,
|
|
|
|
SemaphoreSequence = 0x6,
|
|
|
|
SemaphoreTrigger = 0x7,
|
|
|
|
NotifyIntr = 0x8,
|
|
|
|
WrcacheFlush = 0x9,
|
|
|
|
Unk28 = 0xA,
|
|
|
|
UnkCacheFlush = 0xB,
|
|
|
|
RefCnt = 0x14,
|
|
|
|
SemaphoreAcquire = 0x1A,
|
|
|
|
SemaphoreRelease = 0x1B,
|
|
|
|
FenceValue = 0x1C,
|
|
|
|
FenceAction = 0x1D,
|
|
|
|
WaitForInterrupt = 0x1E,
|
|
|
|
Unk7c = 0x1F,
|
|
|
|
Yield = 0x20,
|
|
|
|
NonPullerMethods = 0x40,
|
|
|
|
};
|
|
|
|
|
2018-11-24 04:20:56 +00: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-10-30 04:13:04 +00:00
|
|
|
static constexpr CommandHeader BuildCommandHeader(BufferMethods method, u32 arg_count,
|
|
|
|
SubmissionMode mode) {
|
|
|
|
CommandHeader result{};
|
|
|
|
result.method.Assign(static_cast<u32>(method));
|
|
|
|
result.arg_count.Assign(arg_count);
|
|
|
|
result.mode.Assign(mode);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-11-24 04:20:56 +00:00
|
|
|
class GPU;
|
|
|
|
|
2020-10-30 04:13:04 +00:00
|
|
|
struct CommandList final {
|
|
|
|
CommandList() = default;
|
|
|
|
explicit CommandList(std::size_t size) : command_lists(size) {}
|
|
|
|
explicit CommandList(std::vector<Tegra::CommandHeader>&& prefetch_command_list)
|
|
|
|
: prefetch_command_list{std::move(prefetch_command_list)} {}
|
|
|
|
|
2020-10-30 04:13:48 +00:00
|
|
|
void RefreshIntegrityChecks(GPU& gpu);
|
|
|
|
|
2020-10-30 04:13:04 +00:00
|
|
|
std::vector<Tegra::CommandListHeader> command_lists;
|
2020-10-30 04:13:48 +00:00
|
|
|
std::vector<u64> command_list_hashes;
|
2020-10-30 04:13:04 +00:00
|
|
|
std::vector<Tegra::CommandHeader> prefetch_command_list;
|
|
|
|
};
|
2018-11-28 00:17:33 +00:00
|
|
|
|
2018-11-24 04:20:56 +00: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 04:13:04 +00:00
|
|
|
class DmaPusher final {
|
2018-11-24 04:20:56 +00:00
|
|
|
public:
|
2020-04-19 20:12:06 +00:00
|
|
|
explicit DmaPusher(Core::System& system, GPU& gpu);
|
2018-11-24 04:20:56 +00:00
|
|
|
~DmaPusher();
|
|
|
|
|
2018-11-28 00:17:33 +00:00
|
|
|
void Push(CommandList&& entries) {
|
|
|
|
dma_pushbuffer.push(std::move(entries));
|
2018-11-24 04:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchCalls();
|
|
|
|
|
2020-04-28 02:07:21 +00:00
|
|
|
void BindSubchannel(Tegra::Engines::EngineInterface* engine, u32 subchannel_id) {
|
|
|
|
subchannels[subchannel_id] = engine;
|
|
|
|
}
|
|
|
|
|
2018-11-24 04:20:56 +00:00
|
|
|
private:
|
2020-04-28 02:07:21 +00:00
|
|
|
static constexpr u32 non_puller_methods = 0x40;
|
|
|
|
static constexpr u32 max_subchannels = 8;
|
2018-11-24 04:20:56 +00:00
|
|
|
bool Step();
|
|
|
|
|
|
|
|
void SetState(const CommandHeader& command_header);
|
|
|
|
|
|
|
|
void CallMethod(u32 argument) const;
|
2020-04-20 06:16:56 +00:00
|
|
|
void CallMultiMethod(const u32* base_start, u32 num_methods) const;
|
2018-11-24 04:20:56 +00:00
|
|
|
|
2019-02-19 08:44:33 +00:00
|
|
|
std::vector<CommandHeader> command_headers; ///< Buffer for list of commands fetched at once
|
|
|
|
|
2018-11-28 00:17:33 +00: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-24 04:20:56 +00: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
|
2019-01-30 17:36:28 +00:00
|
|
|
bool non_incrementing; ///< Current command's NI flag
|
2020-04-28 02:07:21 +00:00
|
|
|
bool is_last_call;
|
2018-11-24 04:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DmaState dma_state{};
|
|
|
|
bool dma_increment_once{};
|
|
|
|
|
|
|
|
bool ib_enable{true}; ///< IB mode enabled
|
2020-04-19 20:12:06 +00:00
|
|
|
|
2020-04-28 02:07:21 +00:00
|
|
|
std::array<Tegra::Engines::EngineInterface*, max_subchannels> subchannels{};
|
|
|
|
|
2020-04-19 20:12:06 +00:00
|
|
|
GPU& gpu;
|
|
|
|
Core::System& system;
|
2018-11-24 04:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Tegra
|