Skip to content

Commit

Permalink
Plane cache WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Oct 6, 2023
1 parent 4ced25c commit f4edc38
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
11 changes: 6 additions & 5 deletions saturnin/src/video/vdp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3280,8 +3280,12 @@ void Vdp2::readScrollScreenData(const ScrollScreen s) {
}
address_to_plane_data_.clear();

std::vector<PlaneDetail>().swap(planes_details_[util::toUnderlying(screen.scroll_screen)]);

// Each plane similar data is only read once, even if it's used multiple times.
for (const auto& [addr, offset] : start_addresses) {
planes_details_[util::toUnderlying(screen.scroll_screen)].emplace_back(addr, offset);

if (!address_to_plane_data_.contains(addr)) {
current_plane_address_ = addr;
readPlaneData(screen, addr, offset);
Expand Down Expand Up @@ -3829,11 +3833,8 @@ void Vdp2::saveCell(const ScrollScreenStatus& screen,
// screen.priority_number,
// screen.color_offset.as_float);

address_to_plane_data_[current_plane_address_].emplace_back(pnd,
pos,
key,
screen.priority_number,
screen.color_offset.as_float);
address_to_plane_data_[current_plane_address_]
.emplace_back(pnd, pos, key, screen.priority_number, screen.color_offset.as_float, current_plane_address_);
}

auto Vdp2::getColorRamAddressOffset(const u8 register_offset) const -> u16 {
Expand Down
16 changes: 16 additions & 0 deletions saturnin/src/video/vdp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,21 @@ struct CellData {
key(key){};
};

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \struct PlaneDetail
///
/// \brief Stores details of a plane, used for rendering.
///
/// \author Runik
/// \date 06/10/2023
////////////////////////////////////////////////////////////////////////////////////////////////////

struct PlaneDetail {
u32 start_address;
ScreenOffset screen_offset;
PlaneDetail(const u32 sa, const ScreenOffset so) : start_address(sa), screen_offset(so){};
};

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \struct PatternNameData2Words
///
Expand Down Expand Up @@ -1929,6 +1944,7 @@ class Vdp2 {
AddressToPlaneData address_to_plane_data_; ///< Stores plane data to improve performance when a same address is used multiple
u32 current_plane_address_; ///< The current plane address.
///< times in the same NBG / RBG.
std::array<std::vector<PlaneDetail>, 6> planes_details_; ///< Stores planes détails for every scroll.

ScrollScreen screen_in_debug_{ScrollScreen::none}; ///< Scroll screen currently viewed in debug.
DisabledScrollScreen disabled_scroll_screens_; ///< Disabling state of scroll screens.
Expand Down
6 changes: 4 additions & 2 deletions saturnin/src/video/vdp2_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ Vdp2Part::Vdp2Part(const PatternNameData& pnd,
const ScreenPos& pos,
const size_t texture_key,
const u8 priority,
const ColorF& color_offset) :
const ColorF& color_offset,
const u32 linked_plane_address) :
BaseRenderingPart(VdpType::vdp2, DrawType::textured_polygon, texture_key, priority, color_offset),
scroll_screen_pos_(pos),
character_number_(pnd.character_number),
palette_number_(pnd.palette_number),
is_horizontally_flipped_(pnd.is_horizontally_flipped),
is_vertically_flipped_(pnd.is_vertically_flipped) {
is_vertically_flipped_(pnd.is_vertically_flipped),
linked_plane_address_(linked_plane_address) {
// Vdp2 parts are 8*8 pixels squares
constexpr auto cell_width = u8{8};
constexpr auto cell_height = u8{8};
Expand Down
4 changes: 3 additions & 1 deletion saturnin/src/video/vdp2_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class Vdp2Part final : public BaseRenderingPart {
const ScreenPos& pos,
const size_t texture_key,
const u8 priority,
const ColorF& color_offset);
const ColorF& color_offset,
const u32 linked_plane_address);
Vdp2Part(size_t texture_key,
const u16 texture_width,
const u16 texture_height,
Expand All @@ -69,5 +70,6 @@ class Vdp2Part final : public BaseRenderingPart {
u16 palette_number_{}; ///< The palette number.
bool is_horizontally_flipped_{}; ///< True if the part is horizontally flipped.
bool is_vertically_flipped_{}; ///< True if the part is vertically flipped.
u32 linked_plane_address_{}; ///< Address of the linked plane, used to generate the plane texture while rendering.
};
} // namespace saturnin::video

0 comments on commit f4edc38

Please sign in to comment.