Skip to content

Commit

Permalink
VDP2 cache WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoumazet committed Oct 20, 2023
1 parent a9ea0bb commit 602c3ec
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
16 changes: 15 additions & 1 deletion saturnin/src/video/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,21 @@ void Opengl::generatePlanesTextures() {
auto address_to_plane_data = std::move(Texture::getPlaneData());
for (const auto& [addr, data] : address_to_plane_data) {
for (const auto& part_pos : data) {
// part_pos.
const auto tex = Texture::getTexture(part_pos.key);
if (tex) {
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
0,
part_pos.plane_position.x,
part_pos.plane_position.y,
current_index,
8,
8,
1,
GLenum::GL_RGBA,
GLenum::GL_UNSIGNED_BYTE,
(*tex)->rawData().data());
checkGlError();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion saturnin/src/video/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ auto Texture::statistics() -> std::vector<std::string> {
stats.push_back(uti::format("Number of VDP1 textures : {}", vdp1_nb));

const auto vdp2_nb
= std::ranges::count_if(texture_storage_, [](const auto& t) { return t.second.vdpType() == VdpType::vdp2; });
= std::ranges::count_if(texture_storage_, [](const auto& t) { return t.second.vdpType() == VdpType::vdp2_cell; });
stats.push_back(uti::format("Number of VDP2 textures : {}", vdp2_nb));

auto max_width = 0;
Expand Down
20 changes: 11 additions & 9 deletions saturnin/src/video/vdp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ void Vdp2::calculateDisplayDuration() {

void Vdp2::onVblankIn() {
calculateFps();
Texture::cleanCache(modules_.opengl(), VdpType::vdp2);
Texture::cleanCache(modules_.opengl(), VdpType::vdp2_cell);
updateResolution();
updateRamStatus();
Texture::setCache(VdpType::vdp2);
Texture::setCache(VdpType::vdp2_cell);
populateRenderData();
resetCacheState();
}
Expand Down Expand Up @@ -3343,7 +3343,7 @@ void Vdp2::readBitmapData(const ScrollScreenStatus& screen) {
// const auto texture_size = texture_width * texture_height * 4;
std::vector<u8> texture_data;
// texture_data.reserve(texture_size);
const auto key = Texture::calculateKey(VdpType::vdp2,
const auto key = Texture::calculateKey(VdpType::vdp2_cell,
screen.bitmap_start_address,
toUnderlying(screen.character_color_number),
screen.bitmap_palette_number);
Expand Down Expand Up @@ -3418,7 +3418,7 @@ void Vdp2::readBitmapData(const ScrollScreenStatus& screen) {
}
}
}
Texture::storeTexture(Texture(VdpType::vdp2,
Texture::storeTexture(Texture(VdpType::vdp2_cell,
scrollScreenToLayer(screen.scroll_screen),
screen.bitmap_start_address,
toUnderlying(screen.character_color_number),
Expand Down Expand Up @@ -3657,8 +3657,10 @@ void Vdp2::readCellDispatch(const ScrollScreenStatus& screen,
const PatternNameData& pnd,
const u32 cell_address,
const ScreenOffset& cell_offset) {
const auto key
= Texture::calculateKey(VdpType::vdp2, cell_address, toUnderlying(screen.character_color_number), pnd.palette_number);
const auto key = Texture::calculateKey(VdpType::vdp2_cell,
cell_address,
toUnderlying(screen.character_color_number),
pnd.palette_number);

if (Texture::isTextureLoadingNeeded(key)) {
if (use_concurrent_read_for_cells) {
Expand Down Expand Up @@ -3737,7 +3739,7 @@ void Vdp2::readCell(const ScrollScreenStatus& screen, const PatternNameData& pnd
}
}

Texture::storeTexture(Texture(VdpType::vdp2,
Texture::storeTexture(Texture(VdpType::vdp2_cell,
scrollScreenToLayer(screen.scroll_screen),
cell_address,
static_cast<u8>(toUnderlying(screen.character_color_number)),
Expand Down Expand Up @@ -3804,7 +3806,7 @@ void Vdp2::readCellMT(const ScrollScreenStatus& screen,
Log::warning(Logger::vdp2, tr("Character color number invalid !"));
}
}
Texture::storeTexture(Texture(VdpType::vdp2,
Texture::storeTexture(Texture(VdpType::vdp2_cell,
scrollScreenToLayer(screen.scroll_screen),
cell_address,
static_cast<u8>(toUnderlying(screen.character_color_number)),
Expand Down Expand Up @@ -3912,7 +3914,7 @@ auto Vdp2::isCacheDirty(const ScrollScreen screen) -> bool {

void Vdp2::discardCache([[maybe_unused]] const ScrollScreen screen) const {
// 1) Textures used by the vdp2 parts of the screen are discarded
Texture::discardCache(VdpType::vdp2);
Texture::discardCache(VdpType::vdp2_cell);

// 2) Vdp2 parts are deleted
// clearRenderData(screen);
Expand Down
4 changes: 2 additions & 2 deletions saturnin/src/video/vdp2_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Vdp2Part::Vdp2Part(const PatternNameData& pnd,
const u8 priority,
const ColorF& color_offset,
const u32 linked_plane_address) :
BaseRenderingPart(VdpType::vdp2, DrawType::textured_polygon, texture_key, priority, color_offset),
BaseRenderingPart(VdpType::vdp2_cell, DrawType::textured_polygon, texture_key, priority, color_offset),
scroll_screen_pos_(pos),
character_number_(pnd.character_number),
palette_number_(pnd.palette_number),
Expand Down Expand Up @@ -69,7 +69,7 @@ Vdp2Part::Vdp2Part(const size_t texture_key,
const u16 texture_height,
const u8 priority,
const ColorF& color_offset) :
BaseRenderingPart(VdpType::vdp2, DrawType::textured_polygon, texture_key, priority, color_offset),
BaseRenderingPart(VdpType::vdp2_cell, DrawType::textured_polygon, texture_key, priority, color_offset),
scroll_screen_pos_({0, 0}),
character_number_(0),
palette_number_(0),
Expand Down
2 changes: 1 addition & 1 deletion saturnin/src/video/vdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ constexpr auto gouraud_offset = s8{0x10};
/// \brief Values that represent VDP types
////////////////////////////////////////////////////////////////////////////////////////////////////

enum class VdpType { not_set, vdp1, vdp2 };
enum class VdpType { not_set, vdp1, vdp2_cell, vdp2_plane };

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \enum Layer
Expand Down

0 comments on commit 602c3ec

Please sign in to comment.