void IncrementBufferMemory(GLenum Type, bool bStructuredBuffer, uint32 NumBytes) { if (bStructuredBuffer) { check(Type == GL_ARRAY_BUFFER); INC_MEMORY_STAT_BY(STAT_StructuredBufferMemory,NumBytes); } else if (Type == GL_UNIFORM_BUFFER) { INC_MEMORY_STAT_BY(STAT_UniformBufferMemory,NumBytes); } else if (Type == GL_ELEMENT_ARRAY_BUFFER) { INC_MEMORY_STAT_BY(STAT_IndexBufferMemory,NumBytes); } else if (Type == GL_PIXEL_UNPACK_BUFFER) { INC_MEMORY_STAT_BY(STAT_PixelBufferMemory,NumBytes); } else { check(Type == GL_ARRAY_BUFFER); INC_MEMORY_STAT_BY(STAT_VertexBufferMemory,NumBytes); } }
void FMemStack::AllocateNewChunk( int32 MinSize ) { FTaggedMemory* Chunk=NULL; for( FTaggedMemory** Link=&UnusedChunks; *Link; Link=&(*Link)->Next ) { // Find existing chunk. if( (*Link)->DataSize >= MinSize ) { Chunk = *Link; *Link = (*Link)->Next; break; } } if( !Chunk ) { // Create new chunk. const int32 DataSize = AlignArbitrary<int32>( MinSize + (int32)sizeof(FTaggedMemory), DefaultChunkSize ) - sizeof(FTaggedMemory); const uint32 AllocSize = DataSize + sizeof(FTaggedMemory); Chunk = (FTaggedMemory*)FMemory::Malloc( AllocSize ); Chunk->DataSize = DataSize; INC_MEMORY_STAT_BY( STAT_MemStackAllocated, AllocSize ); } if( Chunk != TopChunk ) { INC_MEMORY_STAT_BY( STAT_MemStackUsed, Chunk->DataSize ); } Chunk->Next = TopChunk; TopChunk = Chunk; Top = Chunk->Data; End = Top + Chunk->DataSize; }
void UpdateBufferStats(TRefCountPtr<ID3D11Buffer> Buffer, bool bAllocating) { D3D11_BUFFER_DESC Desc; Buffer->GetDesc(&Desc); const bool bUniformBuffer = !!(Desc.BindFlags & D3D11_BIND_CONSTANT_BUFFER); const bool bIndexBuffer = !!(Desc.BindFlags & D3D11_BIND_INDEX_BUFFER); const bool bVertexBuffer = !!(Desc.BindFlags & D3D11_BIND_VERTEX_BUFFER); if (bAllocating) { if (bUniformBuffer) { INC_MEMORY_STAT_BY(STAT_UniformBufferMemory,Desc.ByteWidth); } else if (bIndexBuffer) { INC_MEMORY_STAT_BY(STAT_IndexBufferMemory,Desc.ByteWidth); } else if (bVertexBuffer) { INC_MEMORY_STAT_BY(STAT_VertexBufferMemory,Desc.ByteWidth); } else { INC_MEMORY_STAT_BY(STAT_StructuredBufferMemory,Desc.ByteWidth); } } else { //-V523 if (bUniformBuffer) { DEC_MEMORY_STAT_BY(STAT_UniformBufferMemory,Desc.ByteWidth); } else if (bIndexBuffer) { DEC_MEMORY_STAT_BY(STAT_IndexBufferMemory,Desc.ByteWidth); } else if (bVertexBuffer) { DEC_MEMORY_STAT_BY(STAT_VertexBufferMemory,Desc.ByteWidth); } else { DEC_MEMORY_STAT_BY(STAT_StructuredBufferMemory,Desc.ByteWidth); } } }
void FReflectionCaptureFullHDRDerivedData::InitializeFromUncompressedData(const TArray<uint8>& UncompressedData) { DEC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory, CompressedCapturedData.GetAllocatedSize()); int32 UncompressedSize = UncompressedData.Num() * UncompressedData.GetTypeSize(); TArray<uint8> TempCompressedMemory; // Compressed can be slightly larger than uncompressed TempCompressedMemory.Empty(UncompressedSize * 4 / 3); TempCompressedMemory.AddUninitialized(UncompressedSize * 4 / 3); int32 CompressedSize = TempCompressedMemory.Num() * TempCompressedMemory.GetTypeSize(); verify(FCompression::CompressMemory( (ECompressionFlags)(COMPRESS_ZLIB | COMPRESS_BiasMemory), TempCompressedMemory.GetData(), CompressedSize, UncompressedData.GetData(), UncompressedSize)); // Note: change REFLECTIONCAPTURE_FULL_DERIVEDDATA_VER when modifying the serialization layout FMemoryWriter FinalArchive(CompressedCapturedData, true); FinalArchive << UncompressedSize; FinalArchive << CompressedSize; FinalArchive.Serialize(TempCompressedMemory.GetData(), CompressedSize); INC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory, CompressedCapturedData.GetAllocatedSize()); }
void FNavigationOctree::AddNode(UObject* ElementOb, INavRelevantInterface* NavElement, const FBox& Bounds, FNavigationOctreeElement& Data) { Data.Owner = ElementOb; Data.Bounds = Bounds; UActorComponent* ActorComp = Cast<UActorComponent>(ElementOb); if (bGatherGeometry && ActorComp) { ComponentExportDelegate.ExecuteIfBound(ActorComp, Data.Data); } if (NavElement) { SCOPE_CYCLE_COUNTER(STAT_Navigation_GatheringNavigationModifiersSync); NavElement->GetNavigationData(Data.Data); } // shrink arrays before counting memory // it will be reallocated when adding to octree and RemoveNode will have different value returned by GetAllocatedSize() Data.Shrink(); const int32 ElementMemory = Data.GetAllocatedSize(); NodesMemory += ElementMemory; INC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, ElementMemory); AddElement(Data); }
void FNavigationOctree::AppendToNode(const FOctreeElementId& Id, INavRelevantInterface* NavElement, const FBox& Bounds, FNavigationOctreeElement& Element) { FNavigationOctreeElement OrgData = GetElementById(Id); Element = OrgData; Element.Bounds = Bounds + OrgData.Bounds.GetBox(); if (NavElement) { SCOPE_CYCLE_COUNTER(STAT_Navigation_GatheringNavigationModifiersSync); NavElement->GetNavigationData(*Element.Data); } // shrink arrays before counting memory // it will be reallocated when adding to octree and RemoveNode will have different value returned by GetAllocatedSize() Element.Shrink(); const int32 OrgElementMemory = OrgData.GetAllocatedSize(); const int32 NewElementMemory = Element.GetAllocatedSize(); const int32 MemoryDelta = NewElementMemory - OrgElementMemory; NodesMemory += MemoryDelta; INC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, MemoryDelta); RemoveElement(Id); AddElement(Element); }
FD3D11UniformBuffer::~FD3D11UniformBuffer() { // Do not return the allocation to the pool if it is in the dynamic constant buffer! if (!RingAllocation.IsValid() && Resource != nullptr) { check(IsInRenderingThread()); D3D11_BUFFER_DESC Desc; Resource->GetDesc(&Desc); // Return this uniform buffer to the free pool if (Desc.CPUAccessFlags == D3D11_CPU_ACCESS_WRITE && Desc.Usage == D3D11_USAGE_DYNAMIC) { check(IsValidRef(Resource)); FPooledUniformBuffer NewEntry; NewEntry.Buffer = Resource; NewEntry.FrameFreed = GFrameNumberRenderThread; NewEntry.CreatedSize = Desc.ByteWidth; // Add to this frame's array of free uniform buffers const int32 SafeFrameIndex = (GFrameNumberRenderThread - 1) % NumSafeFrames; const uint32 BucketIndex = GetPoolBucketIndex(Desc.ByteWidth); int32 LastNum = SafeUniformBufferPools[SafeFrameIndex][BucketIndex].Num(); check(Desc.ByteWidth <= GetPoolBucketSize(Desc.ByteWidth)); SafeUniformBufferPools[SafeFrameIndex][BucketIndex].Add(NewEntry); INC_DWORD_STAT(STAT_D3D11NumFreeUniformBuffers); INC_MEMORY_STAT_BY(STAT_D3D11FreeUniformBufferMemory, Desc.ByteWidth); FPlatformMisc::MemoryBarrier(); // check for unwanted concurrency check(SafeUniformBufferPools[SafeFrameIndex][BucketIndex].Num() == LastNum + 1); } } }
void UpdateBufferStats(FD3D12ResourceLocation* ResourceLocation, bool bAllocating, uint32 BufferType) { uint64 RequestedSize = ResourceLocation->GetSize(); const bool bUniformBuffer = BufferType == D3D12_BUFFER_TYPE_CONSTANT; const bool bIndexBuffer = BufferType == D3D12_BUFFER_TYPE_INDEX; const bool bVertexBuffer = BufferType == D3D12_BUFFER_TYPE_VERTEX; if (bAllocating) { if (bUniformBuffer) { INC_MEMORY_STAT_BY(STAT_UniformBufferMemory, RequestedSize); } else if (bIndexBuffer) { INC_MEMORY_STAT_BY(STAT_IndexBufferMemory, RequestedSize); } else if (bVertexBuffer) { INC_MEMORY_STAT_BY(STAT_VertexBufferMemory, RequestedSize); } else { INC_MEMORY_STAT_BY(STAT_StructuredBufferMemory, RequestedSize); } } else { if (bUniformBuffer) { DEC_MEMORY_STAT_BY(STAT_UniformBufferMemory, RequestedSize); } else if (bIndexBuffer) { DEC_MEMORY_STAT_BY(STAT_IndexBufferMemory, RequestedSize); } else if (bVertexBuffer) { DEC_MEMORY_STAT_BY(STAT_VertexBufferMemory, RequestedSize); } else { DEC_MEMORY_STAT_BY(STAT_StructuredBufferMemory, RequestedSize); } } }
void FEnvQueryInstance::ReserveItemData(int32 NumAdditionalItems) { DEC_MEMORY_STAT_BY(STAT_AI_EnvQuery_InstanceMemory, RawData.GetAllocatedSize()); RawData.Reserve((RawData.Num() + NumAdditionalItems) * ValueSize); INC_MEMORY_STAT_BY(STAT_AI_EnvQuery_InstanceMemory, RawData.GetAllocatedSize()); }
virtual void InitRHI() { TextureCubeRHI = RHICreateTextureCube(Size, Format, NumMips, 0, NULL); TextureRHI = TextureCubeRHI; if (SourceData) { check(SourceData->Num() > 0); const int32 BlockBytes = GPixelFormats[Format].BlockBytes; int32 MipBaseIndex = 0; for (int32 MipIndex = 0; MipIndex < NumMips; MipIndex++) { const int32 MipSize = 1 << (NumMips - MipIndex - 1); const int32 CubeFaceBytes = MipSize * MipSize * BlockBytes; for (int32 CubeFace = 0; CubeFace < CubeFace_MAX; CubeFace++) { uint32 DestStride = 0; uint8* DestBuffer = (uint8*)RHILockTextureCubeFace(TextureCubeRHI, CubeFace, 0, MipIndex, RLM_WriteOnly, DestStride, false); // Handle DestStride by copying each row for (int32 Y = 0; Y < MipSize; Y++) { uint8* DestPtr = ((uint8*)DestBuffer + Y * DestStride); const int32 SourceIndex = MipBaseIndex + CubeFace * CubeFaceBytes + Y * MipSize * BlockBytes; const uint8* SourcePtr = &(*SourceData)[SourceIndex]; FMemory::Memcpy(DestPtr, SourcePtr, MipSize * BlockBytes); } RHIUnlockTextureCubeFace(TextureCubeRHI, CubeFace, 0, MipIndex, false); } MipBaseIndex += CubeFaceBytes * CubeFace_MAX; } if (!GIsEditor) { // Toss the source data now that we've created the cubemap // Note: can't do this if we ever use this texture resource in the editor and want to save the data later DEC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,SourceData->GetAllocatedSize()); SourceData->Empty(); } } // Create the sampler state RHI resource. FSamplerStateInitializerRHI SamplerStateInitializer ( SF_Trilinear, AM_Clamp, AM_Clamp, AM_Clamp ); SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer); INC_MEMORY_STAT_BY(STAT_ReflectionCaptureTextureMemory,CalcTextureSize(Size,Size,Format,NumMips) * 6); }
void FNavigationOctree::AddNode(FNavigationOctreeElement& Data) { #if NAVOCTREE_CONTAINS_COLLISION_DATA const int32 ElementMemory = Data.GetAllocatedSize(); NodesMemory += ElementMemory; INC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, ElementMemory); #endif AddElement(Data); }
void FSlateTextureAtlas::InitAtlasData() { check(RootNode == nullptr && AtlasData.Num() == 0); RootNode = new FAtlasedTextureSlot(0, 0, AtlasWidth, AtlasHeight, GetPaddingAmount()); AtlasData.Reserve(AtlasWidth * AtlasHeight * BytesPerPixel); AtlasData.AddZeroed(AtlasWidth * AtlasHeight * BytesPerPixel); check(IsInGameThread() || IsInRenderingThread()); AtlasOwnerThread = (IsInGameThread()) ? ESlateTextureAtlasOwnerThread::Game : ESlateTextureAtlasOwnerThread::Render; INC_MEMORY_STAT_BY(STAT_SlateTextureAtlasMemory, AtlasData.GetAllocatedSize()); }
void FNavigationOctree::AddNode(UObject* ElementOb, INavRelevantInterface* NavElement, const FBox& Bounds, FNavigationOctreeElement& Element) { // we assume NavElement is ElementOb already cast Element.Bounds = Bounds; if (NavElement) { const ENavDataGatheringMode GatheringMode = NavElement->GetGeometryGatheringMode(); bool bDoInstantGathering = ((GatheringMode == ENavDataGatheringMode::Default && DefaultGeometryGatheringMode == ENavDataGatheringMode::Instant) || GatheringMode == ENavDataGatheringMode::Instant); if (bGatherGeometry) { UActorComponent* ActorComp = Cast<UActorComponent>(ElementOb); if (ActorComp) { if (bDoInstantGathering) { ComponentExportDelegate.ExecuteIfBound(ActorComp, *Element.Data); } else { Element.Data->bPendingLazyGeometryGathering = true; Element.Data->bSupportsGatheringGeometrySlices = NavElement && NavElement->SupportsGatheringGeometrySlices(); } } } SCOPE_CYCLE_COUNTER(STAT_Navigation_GatheringNavigationModifiersSync); if (bDoInstantGathering) { NavElement->GetNavigationData(*Element.Data); } else { Element.Data->bPendingLazyModifiersGathering = true; } } // shrink arrays before counting memory // it will be reallocated when adding to octree and RemoveNode will have different value returned by GetAllocatedSize() Element.Shrink(); const int32 ElementMemory = Element.GetAllocatedSize(); NodesMemory += ElementMemory; INC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, ElementMemory); AddElement(Element); }
void FNavigationOctree::DemandLazyDataGathering(FNavigationRelevantData& ElementData) { UObject* ElementOb = ElementData.GetOwner(); if (ElementOb == nullptr) { return; } bool bShrink = false; const int32 OrgElementMemory = ElementData.GetGeometryAllocatedSize(); if (ElementData.IsPendingLazyGeometryGathering() == true && ElementData.SupportsGatheringGeometrySlices() == false) { QUICK_SCOPE_CYCLE_COUNTER(STAT_RecastNavMeshGenerator_LazyGeometryExport); UActorComponent& ActorComp = *CastChecked<UActorComponent>(ElementOb); ComponentExportDelegate.ExecuteIfBound(&ActorComp, ElementData); bShrink = true; // mark this element as no longer needing geometry gathering ElementData.bPendingLazyGeometryGathering = false; } if (ElementData.IsPendingLazyModifiersGathering()) { QUICK_SCOPE_CYCLE_COUNTER(STAT_RecastNavMeshGenerator_LazyModifiersExport); INavRelevantInterface* NavElement = Cast<INavRelevantInterface>(ElementOb); check(NavElement); NavElement->GetNavigationData(ElementData); ElementData.bPendingLazyModifiersGathering = false; bShrink = true; } if (bShrink) { // shrink arrays before counting memory // it will be reallocated when adding to octree and RemoveNode will have different value returned by GetAllocatedSize() ElementData.Shrink(); } const int32 ElementMemoryChange = ElementData.GetGeometryAllocatedSize() - OrgElementMemory; const_cast<FNavigationOctree*>(this)->NodesMemory += ElementMemoryChange; INC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, ElementMemoryChange); }
TRefCountPtr<FReflectionCaptureEncodedHDRDerivedData> FReflectionCaptureEncodedHDRDerivedData::GenerateEncodedHDRData(const FReflectionCaptureFullHDRDerivedData& FullHDRData, const FGuid& StateId, float Brightness) { TRefCountPtr<FReflectionCaptureEncodedHDRDerivedData> EncodedHDRData = new FReflectionCaptureEncodedHDRDerivedData(); const FString KeyString = GetDDCKeyString(StateId); if (!GetDerivedDataCacheRef().GetSynchronous(*KeyString, EncodedHDRData->CapturedData)) { EncodedHDRData->GenerateFromDerivedDataSource(FullHDRData, Brightness); if (EncodedHDRData->CapturedData.Num() > 0) { GetDerivedDataCacheRef().Put(*KeyString, EncodedHDRData->CapturedData); } } check(EncodedHDRData->CapturedData.Num() > 0); INC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,EncodedHDRData->CapturedData.GetAllocatedSize()); return EncodedHDRData; }
void UEnvQueryManager::CreateOptionInstance(UEnvQueryOption* OptionTemplate, const TArray<UEnvQueryTest*>& SortedTests, FEnvQueryInstance& Instance) { FEnvQueryOptionInstance OptionInstance; OptionInstance.Generator = OptionTemplate->Generator; OptionInstance.ItemType = OptionTemplate->Generator->ItemType; OptionInstance.Tests.AddZeroed(SortedTests.Num()); for (int32 TestIndex = 0; TestIndex < SortedTests.Num(); TestIndex++) { UEnvQueryTest* TestOb = SortedTests[TestIndex]; OptionInstance.Tests[TestIndex] = TestOb; } DEC_MEMORY_STAT_BY(STAT_AI_EQS_InstanceMemory, Instance.Options.GetAllocatedSize()); const int32 AddedIdx = Instance.Options.Add(OptionInstance); INC_MEMORY_STAT_BY(STAT_AI_EQS_InstanceMemory, Instance.Options.GetAllocatedSize() + Instance.Options[AddedIdx].GetAllocatedSize()); }
bool FEnvQueryInstance::PrepareContext(UClass* ContextClass, FEnvQueryContextData& ContextData) { if (ContextClass == NULL) { return false; } if (ContextClass != UEnvQueryContext_Item::StaticClass()) { FEnvQueryContextData* CachedData = ContextCache.Find(ContextClass); if (CachedData == NULL) { UEnvQueryContext* ContextOb = ContextClass->GetDefaultObject<UEnvQueryContext>(); ContextOb->ProvideDelegate.ExecuteIfBound(*this, ContextData); DEC_MEMORY_STAT_BY(STAT_AI_EnvQuery_InstanceMemory, GetContextAllocatedSize()); ContextCache.Add(ContextClass, ContextData); INC_MEMORY_STAT_BY(STAT_AI_EnvQuery_InstanceMemory, GetContextAllocatedSize()); } else { ContextData = *CachedData; } } if (ContextData.NumValues == 0) { UE_LOG(LogEQS, Warning, TEXT("Query [%s] is missing values for context [%s], skipping test %d:%d [%s]"), *QueryName, *UEnvQueryTypes::GetShortTypeName(ContextClass), OptionIndex, CurrentTest, *UEnvQueryTypes::GetShortTypeName(Options[OptionIndex].TestDelegates[CurrentTest].GetUObject())); return false; } return true; }
TSharedPtr<FEnvQueryInstance> UEnvQueryManager::PrepareQueryInstance(const FEnvQueryRequest& Request, EEnvQueryRunMode::Type RunMode) { TSharedPtr<FEnvQueryInstance> QueryInstance = CreateQueryInstance(Request.QueryTemplate, RunMode); if (!QueryInstance.IsValid()) { return NULL; } QueryInstance->World = Cast<UWorld>(GetOuter()); QueryInstance->Owner = Request.Owner; DEC_MEMORY_STAT_BY(STAT_AI_EQS_InstanceMemory, QueryInstance->NamedParams.GetAllocatedSize()); // @TODO: interface for providing default named params (like custom ranges in AI) QueryInstance->NamedParams = Request.NamedParams; INC_MEMORY_STAT_BY(STAT_AI_EQS_InstanceMemory, QueryInstance->NamedParams.GetAllocatedSize()); QueryInstance->QueryID = NextQueryID++; return QueryInstance; }
void FPrimitiveSceneInfo::AddToScene(bool bUpdateStaticDrawLists) { check(IsInRenderingThread()); // If we are attaching a primitive that should be statically lit but has unbuilt lighting, // Allocate space in the indirect lighting cache so that it can be used for previewing indirect lighting if (Proxy->HasStaticLighting() && Proxy->NeedsUnbuiltPreviewLighting() && IsIndirectLightingCacheAllowed()) { FIndirectLightingCacheAllocation* PrimitiveAllocation = Scene->IndirectLightingCache.FindPrimitiveAllocation(PrimitiveComponentId); if (PrimitiveAllocation) { IndirectLightingCacheAllocation = PrimitiveAllocation; PrimitiveAllocation->SetDirty(); } else { PrimitiveAllocation = Scene->IndirectLightingCache.AllocatePrimitive(this, true); PrimitiveAllocation->SetDirty(); IndirectLightingCacheAllocation = PrimitiveAllocation; } } if (bUpdateStaticDrawLists) { AddStaticMeshes(); } // create potential storage for our compact info FPrimitiveSceneInfoCompact LocalCompactPrimitiveSceneInfo; FPrimitiveSceneInfoCompact* CompactPrimitiveSceneInfo = &LocalCompactPrimitiveSceneInfo; // if we are being added directly to the Octree, initialize the temp compact scene info, // and let the Octree make a copy of it LocalCompactPrimitiveSceneInfo.Init(this); // Add the primitive to the octree. check(!OctreeId.IsValidId()); Scene->PrimitiveOctree.AddElement(LocalCompactPrimitiveSceneInfo); check(OctreeId.IsValidId()); // Set bounds. FPrimitiveBounds& PrimitiveBounds = Scene->PrimitiveBounds[PackedIndex]; FBoxSphereBounds BoxSphereBounds = Proxy->GetBounds(); PrimitiveBounds.Origin = BoxSphereBounds.Origin; PrimitiveBounds.SphereRadius = BoxSphereBounds.SphereRadius; PrimitiveBounds.BoxExtent = BoxSphereBounds.BoxExtent; PrimitiveBounds.MinDrawDistanceSq = FMath::Square(Proxy->GetMinDrawDistance()); PrimitiveBounds.MaxDrawDistance = Proxy->GetMaxDrawDistance(); // Store precomputed visibility ID. int32 VisibilityBitIndex = Proxy->GetVisibilityId(); FPrimitiveVisibilityId& VisibilityId = Scene->PrimitiveVisibilityIds[PackedIndex]; VisibilityId.ByteIndex = VisibilityBitIndex / 8; VisibilityId.BitMask = (1 << (VisibilityBitIndex & 0x7)); // Store occlusion flags. uint8 OcclusionFlags = EOcclusionFlags::None; if (Proxy->CanBeOccluded()) { OcclusionFlags |= EOcclusionFlags::CanBeOccluded; } if (Proxy->AllowApproximateOcclusion() // Allow approximate occlusion if attached, even if the parent does not have bLightAttachmentsAsGroup enabled || LightingAttachmentRoot.IsValid()) { OcclusionFlags |= EOcclusionFlags::AllowApproximateOcclusion; } if (VisibilityBitIndex >= 0) { OcclusionFlags |= EOcclusionFlags::HasPrecomputedVisibility; } Scene->PrimitiveOcclusionFlags[PackedIndex] = OcclusionFlags; // Store occlusion bounds. FBoxSphereBounds OcclusionBounds = BoxSphereBounds; if (Proxy->HasCustomOcclusionBounds()) { OcclusionBounds = Proxy->GetCustomOcclusionBounds(); } OcclusionBounds.BoxExtent.X = OcclusionBounds.BoxExtent.X + OCCLUSION_SLOP; OcclusionBounds.BoxExtent.Y = OcclusionBounds.BoxExtent.Y + OCCLUSION_SLOP; OcclusionBounds.BoxExtent.Z = OcclusionBounds.BoxExtent.Z + OCCLUSION_SLOP; OcclusionBounds.SphereRadius = OcclusionBounds.SphereRadius + OCCLUSION_SLOP; Scene->PrimitiveOcclusionBounds[PackedIndex] = OcclusionBounds; // Store the component. Scene->PrimitiveComponentIds[PackedIndex] = PrimitiveComponentId; bNeedsCachedReflectionCaptureUpdate = true; { FMemMark MemStackMark(FMemStack::Get()); // Find lights that affect the primitive in the light octree. for (FSceneLightOctree::TConstElementBoxIterator<SceneRenderingAllocator> LightIt(Scene->LightOctree, Proxy->GetBounds().GetBox()); LightIt.HasPendingElements(); LightIt.Advance()) { const FLightSceneInfoCompact& LightSceneInfoCompact = LightIt.GetCurrentElement(); if (LightSceneInfoCompact.AffectsPrimitive(*CompactPrimitiveSceneInfo)) { FLightPrimitiveInteraction::Create(LightSceneInfoCompact.LightSceneInfo,this); } } } INC_MEMORY_STAT_BY(STAT_PrimitiveInfoMemory, sizeof(*this) + StaticMeshes.GetAllocatedSize() + Proxy->GetMemoryFootprint()); }
void UReflectionCaptureComponent::PostLoad() { Super::PostLoad(); // If we're loading on a platform that doesn't require cooked data, attempt to load missing data from the DDC if (!FPlatformProperties::RequiresCookedData()) { // Only check the DDC if we don't already have it loaded // If we are loading cooked then FullHDRDerivedData might be setup already (FullHDRDerivedData is set in Serialize) if (!FullHDRDerivedData) { FullHDRDerivedData = new FReflectionCaptureFullHDRDerivedData(); // Attempt to load the full HDR data from the DDC if (!GetDerivedDataCacheRef().GetSynchronous(*FReflectionCaptureFullHDRDerivedData::GetDDCKeyString(StateId), FullHDRDerivedData->CompressedCapturedData)) { bDerivedDataDirty = true; delete FullHDRDerivedData; FullHDRDerivedData = NULL; if (!FApp::CanEverRender()) { // Warn, especially when running the DDC commandlet to build a DDC for the binary version of UE4. UE_LOG(LogMaterial, Warning, TEXT("Reflection capture was loaded without any valid capture data and will be black. This can happen if the DDC was not up to date during cooking. Load the map in the editor once before cooking to fix. %s."), *GetFullName()); } } } // If we have full HDR data but not encoded HDR data, generate the encoded data now if (FullHDRDerivedData && !EncodedHDRDerivedData && GRHIFeatureLevel == ERHIFeatureLevel::ES2) { EncodedHDRDerivedData = FReflectionCaptureEncodedHDRDerivedData::GenerateEncodedHDRData(*FullHDRDerivedData, StateId, Brightness); } } // Initialize rendering resources for the current feature level, and toss data only needed by other feature levels if (FullHDRDerivedData && GRHIFeatureLevel >= ERHIFeatureLevel::SM4) { // Don't need encoded HDR data for rendering on this feature level INC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,FullHDRDerivedData->CompressedCapturedData.GetAllocatedSize()); EncodedHDRDerivedData = NULL; if (GRHIFeatureLevel == ERHIFeatureLevel::SM4) { SM4FullHDRCubemapTexture = new FReflectionTextureCubeResource(); SM4FullHDRCubemapTexture->SetupParameters(GReflectionCaptureSize, FMath::CeilLogTwo(GReflectionCaptureSize) + 1, PF_FloatRGBA, &FullHDRDerivedData->GetCapturedDataForSM4Load()); BeginInitResource(SM4FullHDRCubemapTexture); } } else if (EncodedHDRDerivedData && GRHIFeatureLevel == ERHIFeatureLevel::ES2) { if (FPlatformProperties::RequiresCookedData()) { INC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,EncodedHDRDerivedData->CapturedData.GetAllocatedSize()); } // Create a cubemap texture out of the encoded HDR data EncodedHDRCubemapTexture = new FReflectionTextureCubeResource(); EncodedHDRCubemapTexture->SetupParameters(GReflectionCaptureSize, FMath::CeilLogTwo(GReflectionCaptureSize) + 1, PF_B8G8R8A8, &EncodedHDRDerivedData->CapturedData); BeginInitResource(EncodedHDRCubemapTexture); // Don't need the full HDR data for rendering on this feature level delete FullHDRDerivedData; FullHDRDerivedData = NULL; } // PostLoad was called, so we can make a proper decision based on visibility of whether or not to update ReflectionCapturesToUpdateNewlyCreated.Remove(this); // Add ourselves to the global list of reflection captures that need to be uploaded to the scene or recaptured if (bVisible) { ReflectionCapturesToUpdateForLoad.AddUnique(this); bCaptureDirty = true; } }