fixed textures overlapping

This commit is contained in:
h4570
2022-07-29 19:04:55 +02:00
parent 7ec6bb71b8
commit 97946e1c6d
16 changed files with 221 additions and 434 deletions
@@ -11,6 +11,7 @@
#pragma once
#include "renderer/renderer_settings.hpp"
#include "./renderer_core_gs_vram.hpp"
namespace Tyra {
@@ -22,23 +23,16 @@ class RendererCoreGS {
prim_t prim;
lod_t lod;
zbuffer_t zBuffer;
RendererCoreGSVRam vram;
void init(RendererSettings* settings);
void flipBuffers();
float getVRamFreeSpaceInMB() const {
return 4.0F - spaceOccupiedByFrameBuffers - spaceOccupiedByZBuffer -
vramMargin;
}
private:
constexpr static float gsCenter = 4096.0F;
constexpr static float screenCenter = gsCenter / 2.0F;
constexpr static float vramMargin =
0.003F; // We don't have perfectly 4MB of VRAM
float spaceOccupiedByFrameBuffers, spaceOccupiedByZBuffer;
RendererSettings* settings;
framebuffer_t frameBuffers[2];
packet2_t* flipPacket;
@@ -0,0 +1,49 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include "renderer/renderer_settings.hpp"
#include "renderer/core/texture/models/texture.hpp"
namespace Tyra {
class RendererCoreGSVRam {
public:
RendererCoreGSVRam();
~RendererCoreGSVRam();
const float& getFreeSpaceInMB();
float getSizeInMB(const Texture& texture);
float getSizeInMB(const TextureData& texData);
float getSizeInMB(int width, const int& height, const int& psm,
const int& alignment);
int allocate(const TextureData& texData);
int allocateBuffer(const int& width, const int& height, const int& psm);
/** Free texture, FIFO order */
void free(const int& address);
private:
int allocate(const int& width, const int& height, const int& psm,
const int& alignment);
int getSize(int width, const int& height, const int& psm,
const int& alignment);
static constexpr float ptr2MB = 262144.0F;
bool touched;
int pointer;
float cachedFreeSpace;
};
} // namespace Tyra
@@ -1,48 +0,0 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <tamtypes.h>
#include <draw_buffers.h>
#include <vector>
#include "renderer/core/texture/models/texture.hpp"
#include "./renderer_texture_cm_analysis.hpp"
#include "../renderer_core_texture_buffers.hpp"
namespace Tyra {
class RendererTextureCacheManager {
public:
RendererTextureCacheManager();
~RendererTextureCacheManager();
void onFrameChange();
void addRequestedTexture(Texture* texture);
u32 getTextureIdToDealloc(
const std::vector<RendererCoreTextureBuffers>& currentAllocs);
private:
RendererTextureCMAnalysis statistics;
void tryAddIdThatNotExistInAnalysis(
std::vector<u32>* result,
const std::vector<RendererCoreTextureBuffers>& currentAllocs,
const std::vector<u32>& analysis);
void addIdThatExistInAnalysisButIsOnTheBottom(
std::vector<u32>* result,
const std::vector<RendererCoreTextureBuffers>& currentAllocs,
const std::vector<u32>& analysis);
};
} // namespace Tyra
@@ -1,73 +0,0 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <algorithm>
#include "debug/debug.hpp"
#include <tamtypes.h>
#include <vector>
namespace Tyra {
struct RendererTextureCMAnalysisWeight {
u32 id;
u16 weight;
};
struct RendererTextureCMAnalysisOccurence {
u32 id;
u8 occurence;
};
class RendererTextureCMAnalysis {
public:
RendererTextureCMAnalysis();
~RendererTextureCMAnalysis();
void changeFrame();
void addNewRequest(const u32& id);
/**
* @brief Returns top list (from most used to least used) of textures to be
* deallocated.
*
* @param count Number of textures to be returned.
*/
std::vector<u32> getTopTextureIdsForNextChanges(const u8& count);
bool isReady();
bool isProbablyNotCorrect();
private:
std::vector<u32>*current, *last;
std::vector<u32> buffers[2];
u32 currentIndex;
void flipBuffers();
std::vector<u32> getNextTextureIds(const u8& count);
std::vector<RendererTextureCMAnalysisOccurence> getOccurencesForTextureIds(
const std::vector<u32>& textureIds);
std::vector<u32> getTextureIdsUnique(const std::vector<u32>& textureIds);
std::vector<RendererTextureCMAnalysisWeight> getWeights(
const std::vector<u32>& uniqueTexIds,
const std::vector<RendererTextureCMAnalysisOccurence>& occurencies);
std::vector<u32> weightsToResult(
std::vector<RendererTextureCMAnalysisWeight>* weights);
};
} // namespace Tyra
@@ -47,7 +47,7 @@ class Texture {
const TextureData& getCoreData() const { return *core; }
TextureData* getClutData() { return clut; }
const TextureData* getClutData() const { return clut; }
/**
* Get texture name.
@@ -15,7 +15,6 @@
#include "./texture_repository.hpp"
#include "./renderer_core_texture_sender.hpp"
#include "renderer/core/paths/path3/path3.hpp"
#include "./cache_manager/renderer_texture_cache_manager.hpp"
#include "./renderer_core_texture_buffers.hpp"
namespace Tyra {
@@ -33,14 +32,10 @@ class RendererCoreTexture {
/** Called by renderer during initialization */
void init(RendererCoreGS* gs, Path3* path3);
/** Called by renderer during beginFrame() */
void onFrameChange();
/** Called by renderer during rendering */
void updateClutBuffer(texbuffer_t* clutBuffer);
private:
RendererTextureCacheManager cacheManager;
std::vector<RendererCoreTextureBuffers> currentAllocations;
void initClut();
@@ -48,6 +43,7 @@ class RendererCoreTexture {
void unregisterAllocation(const u32& textureId);
RendererCoreTextureBuffers getAllocatedBuffersByTextureId(const u32& id);
RendererCoreGS* gs;
RendererCoreTextureSender sender;
Path3* path3;
};
@@ -31,19 +31,14 @@ class RendererCoreTextureSender {
void deallocate(const RendererCoreTextureBuffers& texBuffers);
float getFreeVRamInMB();
float getSizeInMB(texbuffer_t* texBuffer);
private:
float allocatedVRamMemForTextures;
RendererCoreGS* gs;
Path3* path3;
TextureBpp getBppByPsm(const u32& psm);
texbuffer_t* allocateTextureCore(Texture* t_texture);
texbuffer_t* allocateTextureClut(Texture* t_texture);
u8 isTextureVRAMAllocated, isVSyncEnabled;
};
} // namespace Tyra