3636Draw loop:
37371. BeginFrame() with the TileUpdateManager (TUM)
38382. Draw your assets using the streaming textures, min-mip-map, and sampler feedback SRVs
39+ Optionally call TUM::QueueFeedback() to get sampler feedback for this draw.
3940 SRVs can be created using StreamingResource methods
40413. EndFrame() (with the TUM) returns 2 command lists: beforeDraw and afterDraw
41424. ExecuteCommandLists() with [beforeDraw, yourCommandList, afterDraw] command lists.
4243=============================================================================*/
4344
4445#pragma once
4546
46- #include " TileUpdateManagerBase.h"
47- #include " StreamingResourceBase.h"
48- #include " StreamingHeap.h"
47+ // FIXME: resolve to buffer only supported in Win11 and some insider versions of Win10
48+ // When resolving to texture, must copy to cpu-readable buffer from gpu texture (which cannot be in the readback heap)
49+ // Setting this to 0 resolves directly to cpu-readable buffer
50+ #define RESOLVE_TO_TEXTURE 1
4951
5052// ==================================================
5153// a streaming resource is associated with a single heap (in this implementation)
5254// multiple streaming resources can use the same heap
5355// TileUpdateManager is used to create these
5456// ==================================================
55- class StreamingHeap : private Streaming ::Heap
57+ struct StreamingHeap
5658{
57- public:
58- virtual ~StreamingHeap () {}
59-
60- UINT GetNumTilesAllocated ();
61- private:
62- StreamingHeap () = delete ;
63- StreamingHeap (const StreamingHeap&) = delete ;
64- StreamingHeap (StreamingHeap&&) = delete ;
65- StreamingHeap& operator =(const StreamingHeap&) = delete ;
66- StreamingHeap& operator =(StreamingHeap&&) = delete ;
67-
68- // required to cast to base class
69- friend class TileUpdateManager ;
59+ virtual void Destroy () = 0;
60+
61+ virtual UINT GetNumTilesAllocated () const = 0;
7062};
7163
7264// =============================================================================
7365// a fine-grained streaming, tiled resource
7466// TileUpdateManager is used to create these
7567// =============================================================================
76- class StreamingResource : private Streaming ::StreamingResourceBase
68+ struct StreamingResource
7769{
78- public:
70+ virtual void Destroy () = 0;
71+
7972 // --------------------------------------------
8073 // applications need access to the resources to create descriptors
8174 // --------------------------------------------
82- void CreateFeedbackView (ID3D12Device* in_pDevice, D3D12_CPU_DESCRIPTOR_HANDLE in_descriptor);
83- void CreateStreamingView (ID3D12Device* in_pDevice, D3D12_CPU_DESCRIPTOR_HANDLE in_descriptor);
75+ virtual void CreateFeedbackView (ID3D12Device* in_pDevice, D3D12_CPU_DESCRIPTOR_HANDLE in_descriptor) = 0 ;
76+ virtual void CreateStreamingView (ID3D12Device* in_pDevice, D3D12_CPU_DESCRIPTOR_HANDLE in_descriptor) = 0 ;
8477
8578 // shader reading min-mip-map buffer will want its dimensions
86- UINT GetMinMipMapWidth () const ;
87- UINT GetMinMipMapHeight () const ;
79+ virtual UINT GetMinMipMapWidth () const = 0 ;
80+ virtual UINT GetMinMipMapHeight () const = 0 ;
8881
8982 // shader reading min-mip-map buffer will need an offset into the min-mip-map (residency map)
9083 // NOTE: all min mip maps are stored in a single buffer. offset into the buffer.
91- // this saves a massive amount of GPU memory, since each min mip map is much smaller than 64KB
92- UINT GetMinMipMapOffset () const ;
84+ virtual UINT GetMinMipMapOffset () const = 0;
9385
9486 // check if the packed mips are loaded. application likely will not want to use this texture before they have loaded
95- bool GetPackedMipsResident () const ;
87+ virtual bool GetPackedMipsResident () const = 0 ;
9688
9789 // if a resource isn't visible, evict associated data
9890 // call any time
99- void QueueEviction ();
91+ virtual void QueueEviction () = 0 ;
10092
101- ID3D12Resource* GetTiledResource () const ;
93+ virtual ID3D12Resource* GetTiledResource () const = 0 ;
10294
103- ID3D12Resource* GetMinMipMap () const ;
95+ virtual ID3D12Resource* GetMinMipMap () const = 0 ;
10496
10597 // --------------------------------------------
10698 // for visualization
10799 // --------------------------------------------
108100 // number of tiles reserved (not necessarily committed) for this resource
109- UINT GetNumTilesVirtual () const ;
101+ virtual UINT GetNumTilesVirtual () const = 0 ;
110102#if RESOLVE_TO_TEXTURE
111- ID3D12Resource* GetResolvedFeedback ();
103+ virtual ID3D12Resource* GetResolvedFeedback () const = 0 ;
112104#endif
113-
114- virtual ~StreamingResource ();
115- private:
116- StreamingResource () = delete ;
117- StreamingResource (const StreamingResource&) = delete ;
118- StreamingResource (StreamingResource&&) = delete ;
119- StreamingResource& operator =(const StreamingResource&) = delete ;
120- StreamingResource& operator =(StreamingResource&&) = delete ;
121105};
122106
107+ // =============================================================================
108+ // describe TileUpdateManager (default values are recommended)
109+ // =============================================================================
123110struct TileUpdateManagerDesc
124111{
125112 // maximum number of in-flight batches
@@ -143,10 +130,12 @@ struct TileUpdateManagerDesc
143130 bool m_useDirectStorage{ false };
144131};
145132
146- class TileUpdateManager : private Streaming ::TileUpdateManagerBase
133+ // =============================================================================
134+ // manages all the streaming resources
135+ // =============================================================================
136+ struct TileUpdateManager
147137{
148- public:
149- TileUpdateManager (
138+ static TileUpdateManager* Create (
150139 // query resource for tiling properties. use its device to create internal resources
151140 ID3D12Device8* in_pDevice,
152141
@@ -155,18 +144,18 @@ class TileUpdateManager : private Streaming::TileUpdateManagerBase
155144
156145 const TileUpdateManagerDesc& in_desc);
157146
158- virtual ~TileUpdateManager () ;
147+ virtual void Destroy () = 0 ;
159148
160149 // --------------------------------------------
161150 // Create a heap used by 1 or more StreamingResources
162151 // parameter is number of 64KB tiles to manage
163152 // --------------------------------------------
164- StreamingHeap* CreateStreamingHeap (UINT in_maxNumTilesHeap);
153+ virtual StreamingHeap* CreateStreamingHeap (UINT in_maxNumTilesHeap) = 0 ;
165154
166155 // --------------------------------------------
167156 // Create StreamingResources using a common TileUpdateManager
168157 // --------------------------------------------
169- StreamingResource* CreateStreamingResource (const std::wstring& in_filename, StreamingHeap* in_pHeap);
158+ virtual StreamingResource* CreateStreamingResource (const std::wstring& in_filename, StreamingHeap* in_pHeap) = 0 ;
170159
171160 // --------------------------------------------
172161 // Call BeginFrame() first,
@@ -176,12 +165,12 @@ class TileUpdateManager : private Streaming::TileUpdateManagerBase
176165 // (which only happens if StreamingResources are created/destroyed)
177166 // NOTE: the root signature should set the associated descriptor range as descriptor and data volatile
178167 // --------------------------------------------
179- void BeginFrame (ID3D12DescriptorHeap* in_pDescriptorHeap, D3D12_CPU_DESCRIPTOR_HANDLE in_minmipmapDescriptorHandle);
168+ virtual void BeginFrame (ID3D12DescriptorHeap* in_pDescriptorHeap, D3D12_CPU_DESCRIPTOR_HANDLE in_minmipmapDescriptorHandle) = 0 ;
180169
181170 // application must explicitly request feedback for each resource each frame
182171 // this allows the application to limit how much time is spent on feedback, or stop processing e.g. for off-screen objects
183172 // descriptor required to create Clear() and Resolve() commands
184- void QueueFeedback (StreamingResource* in_pResource, D3D12_GPU_DESCRIPTOR_HANDLE in_gpuDescriptor);
173+ virtual void QueueFeedback (StreamingResource* in_pResource, D3D12_GPU_DESCRIPTOR_HANDLE in_gpuDescriptor) = 0 ;
185174
186175 // --------------------------------------------
187176 // Call EndFrame() last, paired with each BeginFrame() and after all draw commands
@@ -198,39 +187,34 @@ class TileUpdateManager : private Streaming::TileUpdateManagerBase
198187 ID3D12CommandList* m_beforeDrawCommands;
199188 ID3D12CommandList* m_afterDrawCommands;
200189 };
201- CommandLists EndFrame ();
190+ virtual CommandLists EndFrame () = 0 ;
202191
203192 // --------------------------------------------
204193 // choose DirectStorage vs. manual tile loading
205194 // --------------------------------------------
206- void UseDirectStorage (bool in_useDS);
195+ virtual void UseDirectStorage (bool in_useDS) = 0 ;
207196
208197 // --------------------------------------------
209198 // are we between BeginFrame and EndFrame? useful for debugging
210199 // --------------------------------------------
211- bool GetWithinFrame () const ;
200+ virtual bool GetWithinFrame () const = 0 ;
212201
213202 // --------------------------------------------
214203 // GPU time for resolving feedback buffers last frame
215204 // use this to time-limit gpu feedback processing
216205 // to determine per-resolve time, divide this time by the number of QueueFeedback() calls during the frame
217206 // --------------------------------------------
218- float GetGpuTime () const ;
207+ virtual float GetGpuTime () const = 0 ;
219208
220209 // --------------------------------------------
221210 // for visualization
222211 // --------------------------------------------
223- void SetVisualizationMode (UINT in_mode);
212+ virtual void SetVisualizationMode (UINT in_mode) = 0 ;
224213
225- float GetGpuStreamingTime () const ;
226- float GetCpuProcessFeedbackTime (); // approx. cpu time spent processing feedback last frame. expected usage is to average over many frames
214+ virtual float GetGpuStreamingTime () const = 0 ;
215+ virtual float GetCpuProcessFeedbackTime () = 0 ; // approx. cpu time spent processing feedback last frame. expected usage is to average over many frames
227216
228- UINT GetTotalNumUploads () const ;
229- UINT GetTotalNumEvictions () const ;
230- float GetTotalTileCopyLatency () const ;
231- private:
232- TileUpdateManager (const TileUpdateManager&) = delete ;
233- TileUpdateManager (TileUpdateManager&&) = delete ;
234- TileUpdateManager& operator =(const TileUpdateManager&) = delete ;
235- TileUpdateManager& operator =(TileUpdateManager&&) = delete ;
217+ virtual UINT GetTotalNumUploads () const = 0;
218+ virtual UINT GetTotalNumEvictions () const = 0;
219+ virtual float GetTotalTileCopyLatency () const = 0;
236220};
0 commit comments