/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include namespace AZ { namespace RPI { Data::Instance DefaultStreamingImageController::FindOrCreate(const Data::Asset& asset) { return azrtti_cast( Data::InstanceDatabase::Instance().FindOrCreate( Data::InstanceId::CreateFromAssetId(asset.GetId()), asset)); } AZ::Data::Instance DefaultStreamingImageController::CreateInternal(Data::AssetData* assetData) { DefaultStreamingImageControllerAsset* specificAsset = azrtti_cast(assetData); if (!specificAsset) { AZ_Error("DefaultStreamingImageController", false, "DefaultStreamingImageController instance requires a DefaultStreamingImageControllerAsset."); return nullptr; } Data::Instance instance = aznew DefaultStreamingImageController(); const RHI::ResultCode resultCode = instance->Init(*specificAsset); if (resultCode == RHI::ResultCode::Success) { return instance; } return nullptr; } RHI::ResultCode DefaultStreamingImageController::Init([[maybe_unused]] DefaultStreamingImageControllerAsset& imageControllerAsset) { return RHI::ResultCode::Success; } StreamingImageContextPtr DefaultStreamingImageController::CreateContextInternal() { StreamingImageContextPtr context = aznew StreamingImageContext(); m_recentlyAttachedContexts.emplace_back(context); return context; } void DefaultStreamingImageController::UpdateInternal(size_t timestamp, const StreamingImageContextList& contexts) { AZ_UNUSED(timestamp); AZ_UNUSED(contexts); const uint32_t maxExpandsCount = 20; uint32_t mipsExpandsPerUpdate = 0; // [GFX TODO] [ATOM-551] Streaming image control of DefaultStreamingImageController // For now we always stream in all the mips. Of course we need to make this smarter at some point. if (!m_recentlyAttachedContexts.empty()) { for (auto& context : m_recentlyAttachedContexts) { if (StreamingImage* image = context->TryGetImage()) { QueueExpandToMipChainLevel(image, 0); mipsExpandsPerUpdate++; if (mipsExpandsPerUpdate >= maxExpandsCount) { break; } } } m_recentlyAttachedContexts.erase(m_recentlyAttachedContexts.begin(), m_recentlyAttachedContexts.begin() + mipsExpandsPerUpdate); } } } }