1
0
Fork 1
forked from suyu/suyu

nvdec cleanup

This commit is contained in:
ameerj 2020-11-23 13:25:01 -05:00 committed by ameerj
parent 83227ad981
commit ac265a72ce
8 changed files with 38 additions and 43 deletions

View file

@ -28,8 +28,14 @@ NvResult nvhost_vic::Ioctl1(Ioctl command, const std::vector<u8>& input, std::ve
return GetWaitbase(input, output); return GetWaitbase(input, output);
case 0x9: case 0x9:
return MapBuffer(input, output); return MapBuffer(input, output);
case 0xa: case 0xa: {
if (command.length == 0x1c) {
Tegra::ChCommandHeaderList cmdlist(1);
cmdlist[0] = Tegra::ChCommandHeader{0xDEADB33F};
system.GPU().PushCommandBuffer(cmdlist);
}
return UnmapBuffer(input, output); return UnmapBuffer(input, output);
}
default: default:
break; break;
} }

View file

@ -37,20 +37,7 @@ CDmaPusher::CDmaPusher(GPU& gpu_)
CDmaPusher::~CDmaPusher() = default; CDmaPusher::~CDmaPusher() = default;
void CDmaPusher::Push(ChCommandHeaderList&& entries) { void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) {
cdma_queue.push(std::move(entries));
}
void CDmaPusher::DispatchCalls() {
while (!cdma_queue.empty()) {
Step();
}
}
void CDmaPusher::Step() {
const auto entries{cdma_queue.front()};
cdma_queue.pop();
std::vector<u32> values(entries.size()); std::vector<u32> values(entries.size());
std::memcpy(values.data(), entries.data(), entries.size() * sizeof(u32)); std::memcpy(values.data(), entries.data(), entries.size() * sizeof(u32));

View file

@ -99,19 +99,13 @@ public:
explicit CDmaPusher(GPU& gpu_); explicit CDmaPusher(GPU& gpu_);
~CDmaPusher(); ~CDmaPusher();
/// Push NVDEC command buffer entries into queue /// Process the command entry
void Push(ChCommandHeaderList&& entries); void ProcessEntries(ChCommandHeaderList&& entries);
/// Process queued command buffer entries
void DispatchCalls();
/// Process one queue element
void Step();
private:
/// Invoke command class devices to execute the command based on the current state /// Invoke command class devices to execute the command based on the current state
void ExecuteCommand(u32 state_offset, u32 data); void ExecuteCommand(u32 state_offset, u32 data);
private:
/// Write arguments value to the ThiRegisters member at the specified offset /// Write arguments value to the ThiRegisters member at the specified offset
void ThiStateWrite(ThiRegisters& state, u32 state_offset, const std::vector<u32>& arguments); void ThiStateWrite(ThiRegisters& state, u32 state_offset, const std::vector<u32>& arguments);
@ -128,9 +122,6 @@ private:
s32 offset{}; s32 offset{};
u32 mask{}; u32 mask{};
bool incrementing{}; bool incrementing{};
// Queue of command lists to be processed
std::queue<ChCommandHeaderList> cdma_queue;
}; };
} // namespace Tegra } // namespace Tegra

View file

@ -44,8 +44,10 @@ Codec::~Codec() {
} }
void Codec::SetTargetCodec(NvdecCommon::VideoCodec codec) { void Codec::SetTargetCodec(NvdecCommon::VideoCodec codec) {
LOG_INFO(Service_NVDRV, "NVDEC video codec initialized to {}", codec); if (current_codec != codec) {
current_codec = codec; LOG_INFO(Service_NVDRV, "NVDEC video codec initialized to {}", static_cast<u32>(codec));
current_codec = codec;
}
} }
void Codec::StateWrite(u32 offset, u64 arguments) { void Codec::StateWrite(u32 offset, u64 arguments) {
@ -55,7 +57,6 @@ void Codec::StateWrite(u32 offset, u64 arguments) {
void Codec::Decode() { void Codec::Decode() {
bool is_first_frame = false; bool is_first_frame = false;
if (!initialized) { if (!initialized) {
if (current_codec == NvdecCommon::VideoCodec::H264) { if (current_codec == NvdecCommon::VideoCodec::H264) {
av_codec = avcodec_find_decoder(AV_CODEC_ID_H264); av_codec = avcodec_find_decoder(AV_CODEC_ID_H264);

View file

@ -18,7 +18,10 @@ extern "C" {
namespace Tegra { namespace Tegra {
Vic::Vic(GPU& gpu_, std::shared_ptr<Nvdec> nvdec_processor_) Vic::Vic(GPU& gpu_, std::shared_ptr<Nvdec> nvdec_processor_)
: gpu(gpu_), nvdec_processor(std::move(nvdec_processor_)) {} : gpu(gpu_),
nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free}
{}
Vic::~Vic() = default; Vic::~Vic() = default;
void Vic::VicStateWrite(u32 offset, u32 arguments) { void Vic::VicStateWrite(u32 offset, u32 arguments) {
@ -89,8 +92,10 @@ void Vic::Execute() {
// Get Converted frame // Get Converted frame
const std::size_t linear_size = frame->width * frame->height * 4; const std::size_t linear_size = frame->width * frame->height * 4;
using AVMallocPtr = std::unique_ptr<u8, decltype(&av_free)>; // Only allocate frame_buffer once per stream, as the size is not expected to change
AVMallocPtr converted_frame_buffer{static_cast<u8*>(av_malloc(linear_size)), av_free}; if (!converted_frame_buffer) {
converted_frame_buffer = AVMallocPtr{static_cast<u8*>(av_malloc(linear_size)), av_free};
}
const int converted_stride{frame->width * 4}; const int converted_stride{frame->width * 4};
u8* const converted_frame_buf_addr{converted_frame_buffer.get()}; u8* const converted_frame_buf_addr{converted_frame_buffer.get()};
@ -104,12 +109,12 @@ void Vic::Execute() {
const u32 block_height = static_cast<u32>(config.block_linear_height_log2); const u32 block_height = static_cast<u32>(config.block_linear_height_log2);
const auto size = Tegra::Texture::CalculateSize(true, 4, frame->width, frame->height, 1, const auto size = Tegra::Texture::CalculateSize(true, 4, frame->width, frame->height, 1,
block_height, 0); block_height, 0);
std::vector<u8> swizzled_data(size); luma_buffer.resize(size);
Tegra::Texture::SwizzleSubrect(frame->width, frame->height, frame->width * 4, Tegra::Texture::SwizzleSubrect(frame->width, frame->height, frame->width * 4,
frame->width, 4, swizzled_data.data(), frame->width, 4, luma_buffer.data(),
converted_frame_buffer.get(), block_height, 0, 0); converted_frame_buffer.get(), block_height, 0, 0);
gpu.MemoryManager().WriteBlock(output_surface_luma_address, swizzled_data.data(), size); gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(), size);
} else { } else {
// send pitch linear frame // send pitch linear frame
gpu.MemoryManager().WriteBlock(output_surface_luma_address, converted_frame_buf_addr, gpu.MemoryManager().WriteBlock(output_surface_luma_address, converted_frame_buf_addr,
@ -132,8 +137,8 @@ void Vic::Execute() {
const auto stride = frame->linesize[0]; const auto stride = frame->linesize[0];
const auto half_stride = frame->linesize[1]; const auto half_stride = frame->linesize[1];
std::vector<u8> luma_buffer(aligned_width * surface_height); luma_buffer.resize(aligned_width * surface_height);
std::vector<u8> chroma_buffer(aligned_width * half_height); chroma_buffer.resize(aligned_width * half_height);
// Populate luma buffer // Populate luma buffer
for (std::size_t y = 0; y < surface_height - 1; ++y) { for (std::size_t y = 0; y < surface_height - 1; ++y) {

View file

@ -97,6 +97,13 @@ private:
GPU& gpu; GPU& gpu;
std::shared_ptr<Tegra::Nvdec> nvdec_processor; std::shared_ptr<Tegra::Nvdec> nvdec_processor;
/// Avoid reallocation of the following buffers every frame, as their
/// size does not change during a stream
using AVMallocPtr = std::unique_ptr<u8, decltype(&av_free)>;
AVMallocPtr converted_frame_buffer;
std::vector<u8> luma_buffer;
std::vector<u8> chroma_buffer;
GPUVAddr config_struct_address{}; GPUVAddr config_struct_address{};
GPUVAddr output_surface_luma_address{}; GPUVAddr output_surface_luma_address{};
GPUVAddr output_surface_chroma_u_address{}; GPUVAddr output_surface_chroma_u_address{};

View file

@ -30,8 +30,7 @@ MICROPROFILE_DEFINE(GPU_wait, "GPU", "Wait for the GPU", MP_RGB(128, 128, 192));
GPU::GPU(Core::System& system_, bool is_async_, bool use_nvdec_) GPU::GPU(Core::System& system_, bool is_async_, bool use_nvdec_)
: system{system_}, memory_manager{std::make_unique<Tegra::MemoryManager>(system)}, : system{system_}, memory_manager{std::make_unique<Tegra::MemoryManager>(system)},
dma_pusher{std::make_unique<Tegra::DmaPusher>(system, *this)}, dma_pusher{std::make_unique<Tegra::DmaPusher>(system, *this)}, use_nvdec{use_nvdec_},
cdma_pusher{std::make_unique<Tegra::CDmaPusher>(*this)}, use_nvdec{use_nvdec_},
maxwell_3d{std::make_unique<Engines::Maxwell3D>(system, *memory_manager)}, maxwell_3d{std::make_unique<Engines::Maxwell3D>(system, *memory_manager)},
fermi_2d{std::make_unique<Engines::Fermi2D>()}, fermi_2d{std::make_unique<Engines::Fermi2D>()},
kepler_compute{std::make_unique<Engines::KeplerCompute>(system, *memory_manager)}, kepler_compute{std::make_unique<Engines::KeplerCompute>(system, *memory_manager)},

View file

@ -48,9 +48,8 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer,
dma_pusher.DispatchCalls(); dma_pusher.DispatchCalls();
} else if (auto* command_list = std::get_if<SubmitChCommandEntries>(&next.data)) { } else if (auto* command_list = std::get_if<SubmitChCommandEntries>(&next.data)) {
// NVDEC // NVDEC
cdma_pusher.Push(std::move(command_list->entries)); cdma_pusher.ProcessEntries(std::move(command_list->entries));
cdma_pusher.DispatchCalls(); } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) {
} else if (const auto* data = std::get_if<SwapBuffersCommand>(&next.data)) {
renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr); renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr);
} else if (std::holds_alternative<OnCommandListEndCommand>(next.data)) { } else if (std::holds_alternative<OnCommandListEndCommand>(next.data)) {
rasterizer->ReleaseFences(); rasterizer->ReleaseFences();