Skip to content

Commit

Permalink
VDP2 cache WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Feb 21, 2024
1 parent 8887bfe commit fb8a7c5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
86 changes: 50 additions & 36 deletions saturnin/src/video/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,35 +296,15 @@ void Opengl::displayFramebuffer(core::EmulatorContext& state) {
// - displayFramebuffer() must generate one PartList by layer + priority to display to the FBO
// -

auto parts_list = PartsList{};
GlobalPartsList global_parts_list;

const auto addVdp2PartsToList = [&](const ScrollScreen s) {
const auto& vdp2_planes = state.vdp2()->vdp2Parts(s, VdpType::vdp2_cell);
if (!vdp2_planes.empty()) {
parts_list.reserve(parts_list.size() + vdp2_planes.size());
for (const auto& p : vdp2_planes) {
parts_list.emplace_back(p);
}
}

const auto& vdp2_bitmaps = state.vdp2()->vdp2Parts(s, VdpType::vdp2_bitmap);
if (!vdp2_bitmaps.empty()) {
parts_list.reserve(parts_list.size() + vdp2_bitmaps.size());
for (const auto& p : vdp2_bitmaps) {
parts_list.emplace_back(p);
}
}
};

const auto addVdp1PartsToList = [&]() {
const auto& vdp1_parts = state.vdp1()->vdp1Parts();
if (!vdp1_parts.empty()) {
parts_list.reserve(parts_list.size() + vdp1_parts.size());
for (const auto& p : vdp1_parts) {
parts_list.emplace_back(p);
}
}
};
std::unordered_map<ScrollScreen, Layer> screen_to_layer;
screen_to_layer[ScrollScreen::nbg3] = Layer::nbg3;
screen_to_layer[ScrollScreen::nbg2] = Layer::nbg2;
screen_to_layer[ScrollScreen::nbg1] = Layer::nbg1;
screen_to_layer[ScrollScreen::nbg0] = Layer::nbg0;
screen_to_layer[ScrollScreen::rbg1] = Layer::rbg1;
screen_to_layer[ScrollScreen::rbg0] = Layer::rbg0;

// Step one : get displayable layers
std::vector<ScrollScreen> screens_to_display;
Expand All @@ -338,26 +318,30 @@ void Opengl::displayFramebuffer(core::EmulatorContext& state) {
// Step two : populate one FBO for each priority + layer couple

const auto renderVdp1Parts = [&](const u32 priority) {
const auto& vdp1_parts = state.vdp1()->vdp1Parts(priority);
auto local_parts = PartsList();
const auto& vdp1_parts = state.vdp1()->vdp1Parts(priority);
if (!vdp1_parts.empty()) {
parts_list.reserve(parts_list.size() + vdp1_parts.size());
local_parts.reserve(vdp1_parts.size());
for (const auto& p : vdp1_parts) {
parts_list.emplace_back(p);
local_parts.emplace_back(p);
}
// Display current screen to FBO for current priority
renderToFbo(parts_list);
// renderToFbo(parts_list);
global_parts_list[{priority, Layer::sprite}] = std::move(local_parts);
}
};

const auto renderVdp2Parts = [&](const ScrollScreen screen, const u32 priority) {
const auto& vdp2_parts = state.vdp2()->vdp2Parts(screen, priority);
auto local_parts = PartsList();
const auto& vdp2_parts = state.vdp2()->vdp2Parts(screen, priority);
if (!vdp2_parts.empty()) {
parts_list.reserve(parts_list.size() + vdp2_parts.size());
local_parts.reserve(vdp2_parts.size());
for (const auto& p : vdp2_parts) {
parts_list.emplace_back(p);
local_parts.emplace_back(p);
}
// Display current screen to FBO for current priority
renderToFbo(parts_list);
// renderToFbo(parts_list);
global_parts_list[{priority, screen_to_layer[screen]}] = std::move(local_parts);
}
};

Expand All @@ -368,6 +352,36 @@ void Opengl::displayFramebuffer(core::EmulatorContext& state) {
renderVdp1Parts(priority);
}

auto parts_list = PartsList{};

const auto addVdp2PartsToList = [&](const ScrollScreen s) {
const auto& vdp2_planes = state.vdp2()->vdp2Parts(s, VdpType::vdp2_cell);
if (!vdp2_planes.empty()) {
parts_list.reserve(parts_list.size() + vdp2_planes.size());
for (const auto& p : vdp2_planes) {
parts_list.emplace_back(p);
}
}

const auto& vdp2_bitmaps = state.vdp2()->vdp2Parts(s, VdpType::vdp2_bitmap);
if (!vdp2_bitmaps.empty()) {
parts_list.reserve(parts_list.size() + vdp2_bitmaps.size());
for (const auto& p : vdp2_bitmaps) {
parts_list.emplace_back(p);
}
}
};

const auto addVdp1PartsToList = [&]() {
const auto& vdp1_parts = state.vdp1()->vdp1Parts();
if (!vdp1_parts.empty()) {
parts_list.reserve(parts_list.size() + vdp1_parts.size());
for (const auto& p : vdp1_parts) {
parts_list.emplace_back(p);
}
}
};

if (!state.vdp2()->isLayerDisabled(ScrollScreen::nbg3)) { addVdp2PartsToList(ScrollScreen::nbg3); }
if (!state.vdp2()->isLayerDisabled(ScrollScreen::nbg2)) { addVdp2PartsToList(ScrollScreen::nbg2); }
if (!state.vdp2()->isLayerDisabled(ScrollScreen::nbg1)) { addVdp2PartsToList(ScrollScreen::nbg1); }
Expand Down
8 changes: 5 additions & 3 deletions saturnin/src/video/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ struct RenderPart {
draw_type(p.common_vdp_data_.draw_type),
priority(p.common_vdp_data_.priority){};
};
using PartsList = std::vector<RenderPart>;

using PartsList = std::vector<RenderPart>;
using GlobalPartsList = std::map<PriorityKey, PartsList>; // Parts list by priority + layer

using LayerToTextures = std::unordered_map<Layer, std::vector<OpenglTexture>>;
using LayerToTextureArrayIndexes = std::unordered_map<Layer, std::vector<u8>>;
Expand Down Expand Up @@ -744,8 +746,8 @@ class Opengl {
ScreenResolution saturn_screen_resolution_{}; ///< Saturn screen resolution.
ScreenResolution host_screen_resolution_{}; ///< Host screen resolution.

PartsList parts_list_; // Will have to be moved to the platform agnostic renderer.
std::vector<PartsList> parts_list_by_type_;
PartsList parts_list_; // Will have to be moved to the platform agnostic renderer.
GlobalPartsList global_parts_list_; // Will have to be moved to the platform agnostic renderer.
Vdp1Part part_to_highlight_; ///< Part that will be highlighted during debug.
std::vector<DrawRange> draw_range_;

Expand Down

0 comments on commit fb8a7c5

Please sign in to comment.