UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WindowsD3D12DiskCache.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Implementation of D3D12 Disk caching functions to preserve state across runs
4
5#pragma once
6
7#include "HAL/Platform.h"
10
11#define IL_MAX_SEMANTIC_NAME 255
12
14{
15 // Increment this if changes are made to the
16 // disk caches so stale caches get updated correctly
17 static const uint32 mCurrentHeaderVersion = 11;
18 struct FDiskCacheHeader
19 {
20 uint32 mHeaderVersion;
21 uint32 mNumPsos;
22 size_t mSizeInBytes; // The number of bytes after the header
23 };
24
25private:
26 FString mFileName;
27 uint8* mFileStart;
28 HANDLE mFile;
29 HANDLE mMemoryMap;
30 HANDLE mMapAddress;
31 SIZE_T mCurrentFileMapSize;
32 SIZE_T mCurrentOffset;
33 bool mCacheExists;
34 bool mInErrorState;
35 bool mEnableDiskCache;
36 FDiskCacheHeader mHeader;
37
38 // There is the potential for the file mapping to grow
39 // in that case all of the pointers will be invalid. Back
40 // some of the pointers we might read again (i.e. shade byte
41 // code for PSO mapping) in persitent system memory.
42 TArray<void*> mBackedMemory;
43
44 static const SIZE_T mFileGrowSize = (1024 * 1024); // 1 megabyte;
45
46 void GrowMapping(SIZE_T size, bool firstrun);
47
48public:
54
55 bool AppendData(const void* pData, size_t size);
56 bool SetPointerAndAdvanceFilePosition(void** pDest, size_t size, bool backWithSystemMemory = false);
57 void Reset(RESET_TYPE type);
58 void Init(FString &filename, bool bEnable = true);
61 void ClearDiskCache();
62
64 {
65 // Must call the normal Init() first.
66 if (ensure(!mFileName.IsEmpty()))
67 {
69 Init(mFileName, mEnableDiskCache);
70 }
71 }
72
74 {
75 return mHeader.mNumPsos;
76 }
77
79 {
80 return mHeader.mSizeInBytes;
81 }
82
84 {
85 return mInErrorState;
86 }
87
88 SIZE_T GetCurrentOffset() const { return mCurrentOffset; }
89
90 void* GetDataAt(SIZE_T Offset) const;
91 void* GetDataAtStart() const;
92
94 {
95 for (void* memory : mBackedMemory)
96 {
97 if (memory)
98 {
100 }
101 }
102 }
103};
#define ensure( InExpression)
Definition AssertionMacros.h:464
#define FORCEINLINE_DEBUGGABLE
Definition CoreMiscDefines.h:74
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
JsonWriter Close()
void Init()
Definition LockFreeList.h:4
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition WindowsD3D12DiskCache.h:14
uint32 GetSizeInBytes() const
Definition WindowsD3D12DiskCache.h:78
void ClearAndReinitialize()
Definition WindowsD3D12DiskCache.h:63
bool SetPointerAndAdvanceFilePosition(void **pDest, size_t size, bool backWithSystemMemory=false)
Definition WindowsD3D12DiskCache.cpp:157
FORCEINLINE_DEBUGGABLE bool IsInErrorState() const
Definition WindowsD3D12DiskCache.h:83
bool AppendData(const void *pData, size_t size)
Definition WindowsD3D12DiskCache.cpp:143
void * GetDataAt(SIZE_T Offset) const
Definition WindowsD3D12DiskCache.cpp:284
RESET_TYPE
Definition WindowsD3D12DiskCache.h:50
@ RESET_TO_FIRST_OBJECT
Definition WindowsD3D12DiskCache.h:51
@ RESET_TO_AFTER_LAST_OBJECT
Definition WindowsD3D12DiskCache.h:52
void * GetDataAtStart() const
Definition WindowsD3D12DiskCache.cpp:292
void ClearDiskCache()
Definition WindowsD3D12DiskCache.cpp:238
SIZE_T GetCurrentOffset() const
Definition WindowsD3D12DiskCache.h:88
uint32 GetNumPSOs() const
Definition WindowsD3D12DiskCache.h:73
~FDiskCacheInterface()
Definition WindowsD3D12DiskCache.h:93
Definition Array.h:670
static FORCENOINLINE CORE_API void Free(void *Original)
Definition UnrealMemory.cpp:685