Skip to content

Commit

Permalink
Merge pull request #388 from carboncopies/378-update-asset-streaming-…
Browse files Browse the repository at this point in the history
…system

378 update asset streaming system
  • Loading branch information
datacrystals authored Sep 22, 2022
2 parents 3728303 + 7c01518 commit 2dad0ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
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;


};

0 comments on commit 2dad0ba

Please sign in to comment.