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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-21 05:19:07 +01:00
|
|
|
#include <cstddef>
|
|
|
|
#include <limits>
|
2020-02-21 00:35:53 +01:00
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "video_core/dirty_flags.h"
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
|
|
|
namespace Dirty {
|
|
|
|
|
|
|
|
enum : u8 {
|
|
|
|
First = VideoCommon::Dirty::LastCommonEntry,
|
|
|
|
|
|
|
|
Viewports,
|
2020-02-21 02:19:57 +01:00
|
|
|
Scissors,
|
2020-02-21 04:28:45 +01:00
|
|
|
DepthBias,
|
2020-02-21 04:37:29 +01:00
|
|
|
BlendConstants,
|
2020-02-21 04:54:39 +01:00
|
|
|
DepthBounds,
|
2020-02-21 05:09:02 +01:00
|
|
|
StencilProperties,
|
2020-02-21 05:19:07 +01:00
|
|
|
|
2020-06-22 08:03:27 +02:00
|
|
|
CullMode,
|
|
|
|
DepthBoundsEnable,
|
|
|
|
DepthTestEnable,
|
|
|
|
DepthWriteEnable,
|
|
|
|
DepthCompareOp,
|
|
|
|
FrontFace,
|
|
|
|
StencilOp,
|
|
|
|
StencilTestEnable,
|
|
|
|
|
2020-02-21 05:19:07 +01:00
|
|
|
Last
|
2020-02-21 00:35:53 +01:00
|
|
|
};
|
2020-02-21 05:19:07 +01:00
|
|
|
static_assert(Last <= std::numeric_limits<u8>::max());
|
2020-02-21 00:35:53 +01:00
|
|
|
|
|
|
|
} // namespace Dirty
|
|
|
|
|
|
|
|
class StateTracker {
|
2020-08-21 04:07:30 +02:00
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
|
|
|
|
2020-02-21 00:35:53 +01:00
|
|
|
public:
|
2020-06-12 02:24:45 +02:00
|
|
|
explicit StateTracker(Tegra::GPU& gpu);
|
2020-02-21 00:35:53 +01:00
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
void InvalidateCommandBufferState() {
|
|
|
|
flags |= invalidation_flags;
|
|
|
|
current_topology = INVALID_TOPOLOGY;
|
|
|
|
}
|
2020-02-21 00:35:53 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
void InvalidateViewports() {
|
|
|
|
flags[Dirty::Viewports] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InvalidateScissors() {
|
|
|
|
flags[Dirty::Scissors] = true;
|
|
|
|
}
|
|
|
|
|
2020-02-21 00:35:53 +01:00
|
|
|
bool TouchViewports() {
|
|
|
|
return Exchange(Dirty::Viewports, false);
|
|
|
|
}
|
|
|
|
|
2020-02-21 02:19:57 +01:00
|
|
|
bool TouchScissors() {
|
|
|
|
return Exchange(Dirty::Scissors, false);
|
|
|
|
}
|
|
|
|
|
2020-02-21 04:28:45 +01:00
|
|
|
bool TouchDepthBias() {
|
|
|
|
return Exchange(Dirty::DepthBias, false);
|
|
|
|
}
|
|
|
|
|
2020-02-21 04:37:29 +01:00
|
|
|
bool TouchBlendConstants() {
|
|
|
|
return Exchange(Dirty::BlendConstants, false);
|
|
|
|
}
|
|
|
|
|
2020-02-21 04:54:39 +01:00
|
|
|
bool TouchDepthBounds() {
|
|
|
|
return Exchange(Dirty::DepthBounds, false);
|
|
|
|
}
|
|
|
|
|
2020-02-21 05:09:02 +01:00
|
|
|
bool TouchStencilProperties() {
|
|
|
|
return Exchange(Dirty::StencilProperties, false);
|
|
|
|
}
|
|
|
|
|
2020-06-22 08:03:27 +02:00
|
|
|
bool TouchCullMode() {
|
|
|
|
return Exchange(Dirty::CullMode, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchDepthBoundsTestEnable() {
|
|
|
|
return Exchange(Dirty::DepthBoundsEnable, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchDepthTestEnable() {
|
|
|
|
return Exchange(Dirty::DepthTestEnable, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchDepthBoundsEnable() {
|
|
|
|
return Exchange(Dirty::DepthBoundsEnable, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchDepthWriteEnable() {
|
|
|
|
return Exchange(Dirty::DepthWriteEnable, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchDepthCompareOp() {
|
|
|
|
return Exchange(Dirty::DepthCompareOp, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchFrontFace() {
|
|
|
|
return Exchange(Dirty::FrontFace, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchStencilOp() {
|
|
|
|
return Exchange(Dirty::StencilOp, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TouchStencilTestEnable() {
|
|
|
|
return Exchange(Dirty::StencilTestEnable, false);
|
|
|
|
}
|
|
|
|
|
2020-08-21 04:07:30 +02:00
|
|
|
bool ChangePrimitiveTopology(Maxwell::PrimitiveTopology new_topology) {
|
|
|
|
const bool has_changed = current_topology != new_topology;
|
|
|
|
current_topology = new_topology;
|
|
|
|
return has_changed;
|
|
|
|
}
|
|
|
|
|
2020-02-21 00:35:53 +01:00
|
|
|
private:
|
2020-08-21 04:07:30 +02:00
|
|
|
static constexpr auto INVALID_TOPOLOGY = static_cast<Maxwell::PrimitiveTopology>(~0u);
|
|
|
|
|
2020-02-21 00:35:53 +01:00
|
|
|
bool Exchange(std::size_t id, bool new_value) const noexcept {
|
|
|
|
const bool is_dirty = flags[id];
|
|
|
|
flags[id] = new_value;
|
|
|
|
return is_dirty;
|
|
|
|
}
|
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
Tegra::Engines::Maxwell3D::DirtyState::Flags& flags;
|
2020-02-21 05:19:07 +01:00
|
|
|
Tegra::Engines::Maxwell3D::DirtyState::Flags invalidation_flags;
|
2020-08-21 04:07:30 +02:00
|
|
|
Maxwell::PrimitiveTopology current_topology = INVALID_TOPOLOGY;
|
2020-02-21 00:35:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|