2020-02-21 00:35:53 +01:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-02-21 05:19:07 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <iterator>
|
2020-02-21 00:35:53 +01:00
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/core.h"
|
2020-02-21 05:56:00 +01:00
|
|
|
#include "video_core/dirty_flags.h"
|
2020-02-21 00:35:53 +01:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
#include "video_core/gpu.h"
|
|
|
|
#include "video_core/renderer_vulkan/vk_state_tracker.h"
|
|
|
|
|
|
|
|
#define OFF(field_name) MAXWELL3D_REG_INDEX(field_name)
|
|
|
|
#define NUM(field_name) (sizeof(Maxwell3D::Regs::field_name) / sizeof(u32))
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using namespace Dirty;
|
|
|
|
using namespace VideoCommon::Dirty;
|
|
|
|
using Tegra::Engines::Maxwell3D;
|
|
|
|
using Regs = Maxwell3D::Regs;
|
2020-02-21 05:19:07 +01:00
|
|
|
using Tables = Maxwell3D::DirtyState::Tables;
|
|
|
|
using Table = Maxwell3D::DirtyState::Table;
|
|
|
|
using Flags = Maxwell3D::DirtyState::Flags;
|
2020-02-21 00:35:53 +01:00
|
|
|
|
|
|
|
Flags MakeInvalidationFlags() {
|
|
|
|
Flags flags{};
|
|
|
|
flags[Viewports] = true;
|
2020-02-21 02:19:57 +01:00
|
|
|
flags[Scissors] = true;
|
2020-02-21 04:28:45 +01:00
|
|
|
flags[DepthBias] = true;
|
2020-02-21 04:37:29 +01:00
|
|
|
flags[BlendConstants] = true;
|
2020-02-21 04:54:39 +01:00
|
|
|
flags[DepthBounds] = true;
|
2020-02-21 05:09:02 +01:00
|
|
|
flags[StencilProperties] = true;
|
2020-02-21 00:35:53 +01:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupDirtyViewports(Tables& tables) {
|
|
|
|
FillBlock(tables[0], OFF(viewport_transform), NUM(viewport_transform), Viewports);
|
|
|
|
FillBlock(tables[0], OFF(viewports), NUM(viewports), Viewports);
|
|
|
|
tables[0][OFF(viewport_transform_enabled)] = Viewports;
|
|
|
|
}
|
|
|
|
|
2020-02-21 02:19:57 +01:00
|
|
|
void SetupDirtyScissors(Tables& tables) {
|
|
|
|
FillBlock(tables[0], OFF(scissor_test), NUM(scissor_test), Scissors);
|
|
|
|
}
|
|
|
|
|
2020-02-21 04:28:45 +01:00
|
|
|
void SetupDirtyDepthBias(Tables& tables) {
|
|
|
|
auto& table = tables[0];
|
|
|
|
table[OFF(polygon_offset_units)] = DepthBias;
|
|
|
|
table[OFF(polygon_offset_clamp)] = DepthBias;
|
|
|
|
table[OFF(polygon_offset_factor)] = DepthBias;
|
|
|
|
}
|
|
|
|
|
2020-02-21 04:37:29 +01:00
|
|
|
void SetupDirtyBlendConstants(Tables& tables) {
|
|
|
|
FillBlock(tables[0], OFF(blend_color), NUM(blend_color), BlendConstants);
|
|
|
|
}
|
|
|
|
|
2020-02-21 04:54:39 +01:00
|
|
|
void SetupDirtyDepthBounds(Tables& tables) {
|
|
|
|
FillBlock(tables[0], OFF(depth_bounds), NUM(depth_bounds), DepthBounds);
|
|
|
|
}
|
|
|
|
|
2020-02-21 05:09:02 +01:00
|
|
|
void SetupDirtyStencilProperties(Tables& tables) {
|
|
|
|
auto& table = tables[0];
|
|
|
|
table[OFF(stencil_two_side_enable)] = StencilProperties;
|
|
|
|
table[OFF(stencil_front_func_ref)] = StencilProperties;
|
|
|
|
table[OFF(stencil_front_mask)] = StencilProperties;
|
|
|
|
table[OFF(stencil_front_func_mask)] = StencilProperties;
|
|
|
|
table[OFF(stencil_back_func_ref)] = StencilProperties;
|
|
|
|
table[OFF(stencil_back_mask)] = StencilProperties;
|
|
|
|
table[OFF(stencil_back_func_mask)] = StencilProperties;
|
|
|
|
}
|
|
|
|
|
2020-02-21 00:35:53 +01:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
StateTracker::StateTracker(Core::System& system)
|
|
|
|
: system{system}, invalidation_flags{MakeInvalidationFlags()} {}
|
|
|
|
|
|
|
|
void StateTracker::Initialize() {
|
|
|
|
auto& dirty = system.GPU().Maxwell3D().dirty;
|
|
|
|
auto& tables = dirty.tables;
|
|
|
|
SetupDirtyRenderTargets(tables);
|
|
|
|
SetupDirtyViewports(tables);
|
2020-02-21 02:19:57 +01:00
|
|
|
SetupDirtyScissors(tables);
|
2020-02-21 04:28:45 +01:00
|
|
|
SetupDirtyDepthBias(tables);
|
2020-02-21 04:37:29 +01:00
|
|
|
SetupDirtyBlendConstants(tables);
|
2020-02-21 04:54:39 +01:00
|
|
|
SetupDirtyDepthBounds(tables);
|
2020-02-21 05:09:02 +01:00
|
|
|
SetupDirtyStencilProperties(tables);
|
2020-02-21 00:35:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateTracker::InvalidateCommandBufferState() {
|
|
|
|
system.GPU().Maxwell3D().dirty.flags |= invalidation_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Vulkan
|