2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-02-21 05:56:00 +01:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/dirty_flags.h"
|
|
|
|
|
|
|
|
#define OFF(field_name) MAXWELL3D_REG_INDEX(field_name)
|
2020-11-15 01:01:33 +01:00
|
|
|
#define NUM(field_name) (sizeof(::Tegra::Engines::Maxwell3D::Regs::field_name) / (sizeof(u32)))
|
2020-02-21 05:56:00 +01:00
|
|
|
|
|
|
|
namespace VideoCommon::Dirty {
|
2021-01-17 00:48:58 +01:00
|
|
|
namespace {
|
2020-02-21 05:56:00 +01:00
|
|
|
using Tegra::Engines::Maxwell3D;
|
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
void SetupDirtyVertexBuffers(Maxwell3D::DirtyState::Tables& tables) {
|
|
|
|
static constexpr std::size_t num_array = 3;
|
|
|
|
for (std::size_t i = 0; i < Maxwell3D::Regs::NumVertexArrays; ++i) {
|
2022-08-12 11:58:09 +02:00
|
|
|
const std::size_t array_offset = OFF(vertex_streams) + i * NUM(vertex_streams[0]);
|
|
|
|
const std::size_t limit_offset =
|
|
|
|
OFF(vertex_stream_limits) + i * NUM(vertex_stream_limits[0]);
|
2021-01-17 00:48:58 +01:00
|
|
|
|
|
|
|
FillBlock(tables, array_offset, num_array, VertexBuffer0 + i, VertexBuffers);
|
2022-08-12 11:58:09 +02:00
|
|
|
FillBlock(tables, limit_offset, NUM(vertex_stream_limits), VertexBuffer0 + i,
|
|
|
|
VertexBuffers);
|
2021-01-17 00:48:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupIndexBuffer(Maxwell3D::DirtyState::Tables& tables) {
|
2022-08-12 11:58:09 +02:00
|
|
|
FillBlock(tables[0], OFF(index_buffer), NUM(index_buffer), IndexBuffer);
|
2021-01-17 00:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupDirtyDescriptors(Maxwell3D::DirtyState::Tables& tables) {
|
2022-08-12 11:58:09 +02:00
|
|
|
FillBlock(tables[0], OFF(tex_header), NUM(tex_header), Descriptors);
|
|
|
|
FillBlock(tables[0], OFF(tex_sampler), NUM(tex_sampler), Descriptors);
|
2021-01-17 00:48:58 +01:00
|
|
|
}
|
2020-12-30 06:25:23 +01:00
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
void SetupDirtyRenderTargets(Maxwell3D::DirtyState::Tables& tables) {
|
2020-02-21 05:56:00 +01:00
|
|
|
static constexpr std::size_t num_per_rt = NUM(rt[0]);
|
|
|
|
static constexpr std::size_t begin = OFF(rt);
|
|
|
|
static constexpr std::size_t num = num_per_rt * Maxwell3D::Regs::NumRenderTargets;
|
|
|
|
for (std::size_t rt = 0; rt < Maxwell3D::Regs::NumRenderTargets; ++rt) {
|
|
|
|
FillBlock(tables[0], begin + rt * num_per_rt, num_per_rt, ColorBuffer0 + rt);
|
|
|
|
}
|
|
|
|
FillBlock(tables[1], begin, num, RenderTargets);
|
2022-08-12 11:58:09 +02:00
|
|
|
FillBlock(tables[0], OFF(surface_clip), NUM(surface_clip), RenderTargets);
|
2020-12-30 06:25:23 +01:00
|
|
|
|
|
|
|
tables[0][OFF(rt_control)] = RenderTargets;
|
|
|
|
tables[1][OFF(rt_control)] = RenderTargetControl;
|
2020-02-21 05:56:00 +01:00
|
|
|
|
|
|
|
static constexpr std::array zeta_flags{ZetaBuffer, RenderTargets};
|
|
|
|
for (std::size_t i = 0; i < std::size(zeta_flags); ++i) {
|
|
|
|
const u8 flag = zeta_flags[i];
|
|
|
|
auto& table = tables[i];
|
|
|
|
table[OFF(zeta_enable)] = flag;
|
2022-08-12 11:58:09 +02:00
|
|
|
table[OFF(zeta_size.width)] = flag;
|
|
|
|
table[OFF(zeta_size.height)] = flag;
|
2020-02-21 05:56:00 +01:00
|
|
|
FillBlock(table, OFF(zeta), NUM(zeta), flag);
|
|
|
|
}
|
|
|
|
}
|
2021-04-24 23:27:25 +02:00
|
|
|
|
|
|
|
void SetupDirtyShaders(Maxwell3D::DirtyState::Tables& tables) {
|
2022-08-12 11:58:09 +02:00
|
|
|
FillBlock(tables[0], OFF(pipelines), NUM(pipelines) * Maxwell3D::Regs::MaxShaderProgram,
|
|
|
|
Shaders);
|
2021-04-24 23:27:25 +02:00
|
|
|
}
|
2021-01-17 00:48:58 +01:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
void SetupDirtyFlags(Maxwell3D::DirtyState::Tables& tables) {
|
|
|
|
SetupDirtyVertexBuffers(tables);
|
|
|
|
SetupIndexBuffer(tables);
|
|
|
|
SetupDirtyDescriptors(tables);
|
|
|
|
SetupDirtyRenderTargets(tables);
|
2021-04-24 23:27:25 +02:00
|
|
|
SetupDirtyShaders(tables);
|
2021-01-17 00:48:58 +01:00
|
|
|
}
|
2020-02-21 05:56:00 +01:00
|
|
|
|
|
|
|
} // namespace VideoCommon::Dirty
|