Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit fdbd5b4

Browse files
Re-arch SamplerFeedbackStreaming.h toward a dll-ready interface. Bug fix with barriers for uploading static assets (e.g. index buffers / vertex buffers).
1 parent 5f75c37 commit fdbd5b4

15 files changed

+233
-206
lines changed

TileUpdateManager/InternalResources.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030

3131
#include "Streaming.h"
3232

33-
// FIXME: resolve to buffer only supported in Win11 and some insider versions of Win10
34-
// When resolving to texture, must copy to cpu-readable buffer from gpu texture (which cannot be in the readback heap)
35-
// Buffer mode resolves directly to cpu-readable buffer
36-
#define RESOLVE_TO_TEXTURE 1
33+
#include "SamplerFeedbackStreaming.h" // for RESOLVE_TO_TEXTURE
3734

3835
namespace Streaming
3936
{

TileUpdateManager/SamplerFeedbackStreaming.h

Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,90 +36,77 @@
3636
Draw loop:
3737
1. BeginFrame() with the TileUpdateManager (TUM)
3838
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.
3940
SRVs can be created using StreamingResource methods
4041
3. EndFrame() (with the TUM) returns 2 command lists: beforeDraw and afterDraw
4142
4. 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+
//=============================================================================
123110
struct 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
};

TileUpdateManager/StreamingHeap.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828

2929
#include "StreamingHeap.h"
3030

31+
//-----------------------------------------------------------------------------
32+
// call destructor on derived object
33+
//-----------------------------------------------------------------------------
34+
void Streaming::Heap::Destroy()
35+
{
36+
delete this;
37+
}
38+
3139
//-----------------------------------------------------------------------------
3240
// create an "atlas" texture that covers the entire heap
3341
//-----------------------------------------------------------------------------
@@ -218,12 +226,3 @@ ID3D12Resource* Streaming::Heap::ComputeCoordFromTileIndex(D3D12_TILED_RESOURCE_
218226

219227
return pAtlas->ComputeCoordFromTileIndex(out_coord, in_index);
220228
}
221-
222-
//-----------------------------------------------------------------------------
223-
// public API implementation
224-
//-----------------------------------------------------------------------------
225-
#include "SamplerFeedbackStreaming.h"
226-
UINT StreamingHeap::GetNumTilesAllocated()
227-
{
228-
return GetAllocator().GetAllocated();
229-
}

TileUpdateManager/StreamingHeap.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "Streaming.h" // for ComPtr
3030
#include "SimpleAllocator.h"
31+
#include "SamplerFeedbackStreaming.h"
3132

3233
//==================================================
3334
// Streaming Heap wraps the D3D heap, Allocator, and Atlas
@@ -60,9 +61,18 @@ namespace Streaming
6061

6162
// Heap to hold tiles for 1 or more resources
6263
// contains atlases for the format(s) of the resources
63-
class Heap
64+
class Heap : public ::StreamingHeap
6465
{
6566
public:
67+
//-----------------------------------------------------------------
68+
// external APIs
69+
//-----------------------------------------------------------------
70+
virtual void Destroy() override;
71+
virtual UINT GetNumTilesAllocated() const override { return m_heapAllocator.GetAllocated(); }
72+
//-----------------------------------------------------------------
73+
// end external APIs
74+
//-----------------------------------------------------------------
75+
6676
Heap(ID3D12CommandQueue* in_pQueue, UINT in_maxNumTilesHeap);
6777
virtual ~Heap();
6878

@@ -72,6 +82,7 @@ namespace Streaming
7282
ID3D12Resource* ComputeCoordFromTileIndex(D3D12_TILED_RESOURCE_COORDINATE& out_coord, UINT in_index, const DXGI_FORMAT in_format);
7383
ID3D12Heap* GetHeap() const { return m_tileHeap.Get(); }
7484
SimpleAllocator& GetAllocator() { return m_heapAllocator; }
85+
7586
private:
7687
SimpleAllocator m_heapAllocator;
7788

0 commit comments

Comments
 (0)