forked from microsoft/Xbox-GDK-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedESRAM.h
More file actions
154 lines (127 loc) · 6.1 KB
/
AdvancedESRAM.h
File metadata and controls
154 lines (127 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//--------------------------------------------------------------------------------------
// AdvancedESRAM.h
//
// This sample showcases an advanced, fragmentless allocation scheme in DirectX12. It leverages
// the ID3D12CommandQueue::CopyPageMappingsBatchX(...) API to implement a transient D3D resource
// allocator (TransientAllocator.h). A transient resource is any resource that doesn't persist
// between frames, such as G-Buffers and intermediate post-process targets.
//
// The TransientAllocator functions similarly to the XGMemory library, mapping resources to memory
// on a page-by-page basis, dynamically choosing ESRAM or DRAM depending on user specification and
// availability. The difference here being the mapping of the resource's virtual memory space occurs
// on the GPU timeline instead of the CPU. This allows the mapping to be determined dynamically during
// command list recording instead of requiring a pre-configured memory layout beforehand.
//
// No copy-in/-out ESRAM functionality is implemented for brevity's sake. A copy-in extension could
// be highly effective since read-only resources can be copied into memory far in advance, referenced
// in shaders, then discarded and reused at no additional GPU cost.
//
// The structures presented in the sample are single-thread ready only. Extending this to recording
// multiple command lists in parallel over one queue shouldn't be too painful - extension to 2+ queues
// would be an additional challenge.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include "DeviceResources.h"
#include "StepTimer.h"
#include "EsramVisualizeEffect.h"
#include "TransientAllocator.h"
enum SceneTexture : uint32_t
{
ST_Color,
ST_Depth,
ST_Outline0,
ST_Outline1,
ST_Bloom0,
ST_Bloom1,
ST_Count,
};
class Sample
{
public:
Sample();
~Sample();
// Initialization and management
void Initialize(HWND window);
void Uninitialize();
// Basic Sample loop
void Tick();
// Messages
void OnSuspending();
void OnResuming();
// Properties
bool RequestHDRMode() const { return m_deviceResources ? (m_deviceResources->GetDeviceOptions() & DX::DeviceResources::c_EnableHDR) != 0 : false; }
private:
void Update(const DX::StepTimer& timer);
void Render();
void DrawHUD(ID3D12GraphicsCommandList* commandList);
void CreateDeviceDependentResources();
void CreateWindowSizeDependentResources();
ATG::TransientResource AcquireTransientTexture(ID3D12GraphicsCommandList* list, const ATG::TransientDesc& desc, const D3D12_RESOURCE_STATES& initialState, SceneTexture tex);
void UpdateVisualizerRanges(const ATG::ResourceHandle(&handles)[ST_Count]);
void UpdateVisualizerTimings();
private:
// Represents an instance of a scene object.
struct ObjectInstance
{
using EffectList = DirectX::Model::EffectCollection;
DirectX::SimpleMath::Matrix world;
DirectX::Model* model;
EffectList effects;
};
private:
// Device resources.
std::unique_ptr<DX::DeviceResources> m_deviceResources;
uint32_t m_displayWidth;
uint32_t m_displayHeight;
// Rendering loop timer.
uint64_t m_frame;
DX::StepTimer m_timer;
std::unique_ptr<DX::GPUTimer> m_profiler;
// Input devices.
DirectX::GamePad m_gamePad;
DirectX::GamePad::ButtonStateTracker m_gamePadButtons;
// DirectXTK objects.
std::unique_ptr<DirectX::GraphicsMemory> m_graphicsMemory;
std::unique_ptr<DirectX::CommonStates> m_commonStates;
std::unique_ptr<DirectX::DescriptorPile> m_srvPile;
std::unique_ptr<DirectX::EffectTextureFactory> m_textureFactory;
// HUD
std::unique_ptr<DirectX::SpriteBatch> m_hudBatch;
std::unique_ptr<DirectX::SpriteFont> m_smallFont;
std::unique_ptr<DirectX::SpriteFont> m_ctrlFont;
// Camera
float m_theta;
float m_phi;
float m_radius;
DirectX::SimpleMath::Matrix m_proj;
DirectX::SimpleMath::Matrix m_view;
// Assets & Scene
std::vector<std::unique_ptr<DirectX::Model>> m_models;
std::vector<ObjectInstance> m_scene;
// Post Processing
std::unique_ptr<DirectX::GeometricPrimitive> m_fullScreenTri;
std::unique_ptr<DirectX::ToneMapPostProcess> m_tonemapEffect;
std::unique_ptr<DirectX::BasicPostProcess> m_blurEffect;
std::unique_ptr<DirectX::BasicPostProcess> m_bloomExtractEffect;
std::unique_ptr<DirectX::BasicPostProcess> m_bloomBlurEffect;
std::unique_ptr<DirectX::DualPostProcess> m_bloomCombineEffect;
std::unique_ptr<DirectX::BasicEffect> m_alphaCompositeEffect;
std::unique_ptr<DirectX::BasicEffect> m_emissiveEffect;
// Sample Variables
std::unique_ptr<ATG::TransientAllocator> m_allocator;
ATG::TransientDesc m_colorDesc;
ATG::TransientDesc m_depthDesc;
ATG::TransientDesc m_outlineDesc;
ATG::TransientDesc m_bloomDesc;
std::unique_ptr<ATG::EsramVisualizeEffect> m_esramVisualizeEffect;
float m_esramRatios[ST_Count];
float m_esramChangeRate;
size_t m_outlineObjectIndex;
bool m_updateStats;
#pragma warning(disable : 4324)
ATG::EsramVisualizeEffect::Constants m_visData;
#pragma warning(default : 4324)
};