Skip to content
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
32 changes: 30 additions & 2 deletions ZEngine/ZEngine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <chrono>
#include <filesystem>
#include <fstream>
#include <limits>

#ifdef __APPLE__
#include <mach/mach.h>
Expand All @@ -41,7 +42,7 @@ namespace ZEngine
// Read memory.geometry_streaming_mb from a project.json file.
// Returns 0 if the file is absent, unparseable, or the key is missing — callers
// treat 0 as "use auto-detection from device VRAM".
static VkDeviceSize ReadGeometryBudgetOverride(const char* config_file)
static VkDeviceSize ReadGeometryBudgetOverride(cstring config_file)
{
if (!config_file || config_file[0] == '\0')
return 0;
Expand All @@ -59,7 +60,7 @@ namespace ZEngine

// Read rendering.environment_lighting_quality from a project.json file.
// Missing, malformed, or unrecognized values retain the documented Standard tier.
static Rendering::EnvironmentLightingBakeSettings ReadEnvironmentLightingQuality(const char* config_file)
static Rendering::EnvironmentLightingBakeSettings ReadEnvironmentLightingQuality(cstring config_file)
{
const auto fallback = Rendering::ResolveEnvironmentLightingQuality(Rendering::EnvironmentLightingQualityTier::Standard);
if (!config_file || config_file[0] == '\0')
Expand All @@ -85,6 +86,32 @@ namespace ZEngine
return fallback;
}

// Read rendering.environment_lighting_budget_mb from project.json.
// Missing, malformed, zero, and overflowing values retain the documented default.
static VkDeviceSize ReadEnvironmentLightingMemoryBudget(cstring config_file)
{
if (!config_file || config_file[0] == '\0')
return Rendering::DefaultEnvironmentLightingMemoryBudget;

std::ifstream file(config_file);
if (!file.is_open())
return Rendering::DefaultEnvironmentLightingMemoryBudget;

const auto json = nlohmann::json::parse(file, nullptr, /*exceptions=*/false);
if (json.is_discarded() || !json.contains("rendering") || !json["rendering"].is_object())
return Rendering::DefaultEnvironmentLightingMemoryBudget;

const auto& rendering = json["rendering"];
if (!rendering.contains("environment_lighting_budget_mb") || !rendering["environment_lighting_budget_mb"].is_number_unsigned())
return Rendering::DefaultEnvironmentLightingMemoryBudget;

constexpr uint64_t bytes_per_megabyte = 1024ULL * 1024ULL;
const uint64_t megabytes = rendering["environment_lighting_budget_mb"].get<uint64_t>();
if (megabytes == 0 || megabytes > std::numeric_limits<uint64_t>::max() / bytes_per_megabyte)
return Rendering::DefaultEnvironmentLightingMemoryBudget;
return megabytes * bytes_per_megabyte;
}

void Engine::Initialize(Core::Memory::MemoryManager* memory, Windows::WindowConfigurationPtr window_cfg_ptr, Applications::GameApplicationPtr app)
{
ZENGINE_VALIDATE_ASSERT(memory != nullptr, "Engine::Initialize: memory is null — Obelisk must call MemoryManager::Initialize first")
Expand Down Expand Up @@ -184,6 +211,7 @@ namespace ZEngine
// since InitGlobalBuffers reads it during VkBuffer allocation.
g_engine_ctx->Device->GeometryStreamingBudget = ReadGeometryBudgetOverride(app->ConfigFile);
g_engine_ctx->Device->EnvironmentLightingBakeSettings = ReadEnvironmentLightingQuality(app->ConfigFile);
g_engine_ctx->Device->EnvironmentLightingMemoryBudget = ReadEnvironmentLightingMemoryBudget(app->ConfigFile);

// RenderResourceManager — GPU lifetime authority, bridges asset layer and VulkanDevice
g_engine_ctx->RenderResourceManager = ZPushStructCtor(&g_engine_ctx->AssetArena, Rendering::RenderResourceManager);
Expand Down
6 changes: 5 additions & 1 deletion ZEngine/ZEngine/Hardwares/VulkanDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@ namespace ZEngine::Hardwares
/// Set by Engine::Initialize from project.json memory.geometry_streaming_mb
/// before RenderResourceManager::Initialize runs.
VkDeviceSize GeometryStreamingBudget = 0;
/// @brief Project-selected IBL budget copied into each new SkyEnvironment revision.
/// @brief Project-selected IBL quality copied into each new SkyEnvironment revision.
Rendering::EnvironmentLightingBakeSettings EnvironmentLightingBakeSettings = {};
/// @brief Persistent fallback, published, and active-bake environment texture budget.
/// Set by Engine::Initialize from project.json
/// rendering.environment_lighting_budget_mb.
VkDeviceSize EnvironmentLightingMemoryBudget = Rendering::DefaultEnvironmentLightingMemoryBudget;
VkInstance Instance = VK_NULL_HANDLE;
VkSurfaceKHR Surface = VK_NULL_HANDLE;
VkSurfaceFormatKHR SurfaceFormat = {};
Expand Down
4 changes: 4 additions & 0 deletions ZEngine/ZEngine/Rendering/EnvironmentLighting.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once
#include <ZEngine/Rendering/Textures/Texture.h>
#include <ZEngine/ZEngineDef.h>
#include <cstdint>

namespace ZEngine::Rendering
{
/// @brief Default cap for persistent fallback, published, and baking environment textures.
inline constexpr uint64_t DefaultEnvironmentLightingMemoryBudget = ZMega(384ULL);

/// @brief Selects the fixed resource and sampling budget for environment IBL.
/// @details This is renderer/project policy, not serialized artistic scene data.
enum class EnvironmentLightingQualityTier : uint8_t
Expand Down
Loading
Loading