Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

378 update asset streaming system #388

Merged
merged 4 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,41 @@ void ERS_CLASS_AssetStreamingManager::SortSceneModels(std::map<unsigned int, int
}

ResourceMonitor_->UpdateTotals();
CheckHardwareLimitations();
CheckHardwareLimitations(Scene);


}

void ERS_CLASS_AssetStreamingManager::CheckHardwareLimitations() {
void ERS_CLASS_AssetStreamingManager::CheckHardwareLimitations(ERS_STRUCT_Scene* Scene) {

// Get Current Free RAM Value
ERS_STRUCT_HardwareInfo HWInfo = SystemUtils_->ERS_CLASS_HardwareInformation_->GetHWInfo();
unsigned long long int FreeRAM = HWInfo.Dynamic_.PhysicalMemoryFree;

// Start Reducing Target Texture Levels
if (FreeRAM < SystemUtils_->RendererSettings_->WarningLowRAMBytes) {
for (unsigned int i = 0; i < Scene->Models.size(); i++) {
if (Scene->Models[i]->Textures_.size() > 0) {

// Calculate Max Allowed Texture Level
int TotalLevels = Scene->Models[i]->Textures_[0].TextureLevels.size();
unsigned long long int WarningThreshold = SystemUtils_->RendererSettings_->WarningLowRAMBytes;
int MaxTextureLevel = FreeRAM / ((double)WarningThreshold / (double)TotalLevels);

// Enforce Limit
Scene->Models[i]->TargetTextureLevelRAM = std::min(Scene->Models[i]->TargetTextureLevelRAM, MaxTextureLevel);
Scene->Models[i]->TargetTextureLevelVRAM = std::min(Scene->Models[i]->TargetTextureLevelVRAM, MaxTextureLevel);

}
}
}

// Hard RAM Cap (256MiB), Stops Any New Textures From Being Loaded
if (FreeRAM < SystemUtils_->RendererSettings_->CriticalLowRAMBytes){
AsyncTextureUpdater_->QueuePanic();
}


}

// todo: create function to go through textures with high levels and unload them if under a certain ram/vram threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ERS_CLASS_AssetStreamingManager {
* @brief Checks to ensure that there's available hardware resources to continue loading.
*
*/
void CheckHardwareLimitations();
void CheckHardwareLimitations(ERS_STRUCT_Scene* Scene);

/**
* @brief Sorts the models in the given scene based on their distance from the camera.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void ERS_CLASS_ViewportOverlay::DrawOverlay(ERS_STRUCT_Viewport* Viewport) {

// Low VRAM Warning
long long unsigned int FreeVRAM = SystemUtils_->RendererSettings_->VRAMBudget_ - SystemUtils_->RendererSettings_->CurrentVRAMUsage_;
long long unsigned int FreeVRAMWarning = SystemUtils_->RendererSettings_->WarningLowRAMBytes;
long long unsigned int FreeVRAMWarning = SystemUtils_->RendererSettings_->WarningLowVRAMBytes;

if (FreeVRAM < FreeVRAMWarning) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ struct ERS_STRUCT_RendererSettings {
unsigned long long CurrentVRAMUsage_ = 0;
unsigned long long CurrentRAMUsage_ = 0;

// Low RAM Thresholds
unsigned long long int WarningLowRAMBytes = 2147483648;
unsigned long long int CriticalLowRAMBytes = 536870912;
// Low Resource Thresholds
unsigned long long int WarningLowRAMBytes = 4294967296;
unsigned long long int CriticalLowRAMBytes = 1073741824;
unsigned long long int FatalLowRAMBytes = 268435456;
unsigned long long int TerminateLowRAMBytes = 67108864;

unsigned long long int WarningLowVRAMBytes = 1073741824;


};