36
36
Draw loop:
37
37
1. BeginFrame() with the TileUpdateManager (TUM)
38
38
2. 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.
39
40
SRVs can be created using StreamingResource methods
40
41
3. EndFrame() (with the TUM) returns 2 command lists: beforeDraw and afterDraw
41
42
4. ExecuteCommandLists() with [beforeDraw, yourCommandList, afterDraw] command lists.
42
43
=============================================================================*/
43
44
44
45
#pragma once
45
46
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
49
51
50
52
// ==================================================
51
53
// a streaming resource is associated with a single heap (in this implementation)
52
54
// multiple streaming resources can use the same heap
53
55
// TileUpdateManager is used to create these
54
56
// ==================================================
55
- class StreamingHeap : private Streaming ::Heap
57
+ struct StreamingHeap
56
58
{
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;
70
62
};
71
63
72
64
// =============================================================================
73
65
// a fine-grained streaming, tiled resource
74
66
// TileUpdateManager is used to create these
75
67
// =============================================================================
76
- class StreamingResource : private Streaming ::StreamingResourceBase
68
+ struct StreamingResource
77
69
{
78
- public:
70
+ virtual void Destroy () = 0;
71
+
79
72
// --------------------------------------------
80
73
// applications need access to the resources to create descriptors
81
74
// --------------------------------------------
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 ;
84
77
85
78
// 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 ;
88
81
89
82
// shader reading min-mip-map buffer will need an offset into the min-mip-map (residency map)
90
83
// 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;
93
85
94
86
// 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 ;
96
88
97
89
// if a resource isn't visible, evict associated data
98
90
// call any time
99
- void QueueEviction ();
91
+ virtual void QueueEviction () = 0 ;
100
92
101
- ID3D12Resource* GetTiledResource () const ;
93
+ virtual ID3D12Resource* GetTiledResource () const = 0 ;
102
94
103
- ID3D12Resource* GetMinMipMap () const ;
95
+ virtual ID3D12Resource* GetMinMipMap () const = 0 ;
104
96
105
97
// --------------------------------------------
106
98
// for visualization
107
99
// --------------------------------------------
108
100
// number of tiles reserved (not necessarily committed) for this resource
109
- UINT GetNumTilesVirtual () const ;
101
+ virtual UINT GetNumTilesVirtual () const = 0 ;
110
102
#if RESOLVE_TO_TEXTURE
111
- ID3D12Resource* GetResolvedFeedback ();
103
+ virtual ID3D12Resource* GetResolvedFeedback () const = 0 ;
112
104
#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 ;
121
105
};
122
106
107
+ // =============================================================================
108
+ // describe TileUpdateManager (default values are recommended)
109
+ // =============================================================================
123
110
struct TileUpdateManagerDesc
124
111
{
125
112
// maximum number of in-flight batches
@@ -143,10 +130,12 @@ struct TileUpdateManagerDesc
143
130
bool m_useDirectStorage{ false };
144
131
};
145
132
146
- class TileUpdateManager : private Streaming ::TileUpdateManagerBase
133
+ // =============================================================================
134
+ // manages all the streaming resources
135
+ // =============================================================================
136
+ struct TileUpdateManager
147
137
{
148
- public:
149
- TileUpdateManager (
138
+ static TileUpdateManager* Create (
150
139
// query resource for tiling properties. use its device to create internal resources
151
140
ID3D12Device8* in_pDevice,
152
141
@@ -155,18 +144,18 @@ class TileUpdateManager : private Streaming::TileUpdateManagerBase
155
144
156
145
const TileUpdateManagerDesc& in_desc);
157
146
158
- virtual ~TileUpdateManager () ;
147
+ virtual void Destroy () = 0 ;
159
148
160
149
// --------------------------------------------
161
150
// Create a heap used by 1 or more StreamingResources
162
151
// parameter is number of 64KB tiles to manage
163
152
// --------------------------------------------
164
- StreamingHeap* CreateStreamingHeap (UINT in_maxNumTilesHeap);
153
+ virtual StreamingHeap* CreateStreamingHeap (UINT in_maxNumTilesHeap) = 0 ;
165
154
166
155
// --------------------------------------------
167
156
// Create StreamingResources using a common TileUpdateManager
168
157
// --------------------------------------------
169
- StreamingResource* CreateStreamingResource (const std::wstring& in_filename, StreamingHeap* in_pHeap);
158
+ virtual StreamingResource* CreateStreamingResource (const std::wstring& in_filename, StreamingHeap* in_pHeap) = 0 ;
170
159
171
160
// --------------------------------------------
172
161
// Call BeginFrame() first,
@@ -176,12 +165,12 @@ class TileUpdateManager : private Streaming::TileUpdateManagerBase
176
165
// (which only happens if StreamingResources are created/destroyed)
177
166
// NOTE: the root signature should set the associated descriptor range as descriptor and data volatile
178
167
// --------------------------------------------
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 ;
180
169
181
170
// application must explicitly request feedback for each resource each frame
182
171
// this allows the application to limit how much time is spent on feedback, or stop processing e.g. for off-screen objects
183
172
// 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 ;
185
174
186
175
// --------------------------------------------
187
176
// Call EndFrame() last, paired with each BeginFrame() and after all draw commands
@@ -198,39 +187,34 @@ class TileUpdateManager : private Streaming::TileUpdateManagerBase
198
187
ID3D12CommandList* m_beforeDrawCommands;
199
188
ID3D12CommandList* m_afterDrawCommands;
200
189
};
201
- CommandLists EndFrame ();
190
+ virtual CommandLists EndFrame () = 0 ;
202
191
203
192
// --------------------------------------------
204
193
// choose DirectStorage vs. manual tile loading
205
194
// --------------------------------------------
206
- void UseDirectStorage (bool in_useDS);
195
+ virtual void UseDirectStorage (bool in_useDS) = 0 ;
207
196
208
197
// --------------------------------------------
209
198
// are we between BeginFrame and EndFrame? useful for debugging
210
199
// --------------------------------------------
211
- bool GetWithinFrame () const ;
200
+ virtual bool GetWithinFrame () const = 0 ;
212
201
213
202
// --------------------------------------------
214
203
// GPU time for resolving feedback buffers last frame
215
204
// use this to time-limit gpu feedback processing
216
205
// to determine per-resolve time, divide this time by the number of QueueFeedback() calls during the frame
217
206
// --------------------------------------------
218
- float GetGpuTime () const ;
207
+ virtual float GetGpuTime () const = 0 ;
219
208
220
209
// --------------------------------------------
221
210
// for visualization
222
211
// --------------------------------------------
223
- void SetVisualizationMode (UINT in_mode);
212
+ virtual void SetVisualizationMode (UINT in_mode) = 0 ;
224
213
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
227
216
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;
236
220
};
0 commit comments