forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleESRAM12.h
166 lines (131 loc) · 6.6 KB
/
SimpleESRAM12.h
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
155
156
157
158
159
160
161
162
163
164
165
166
//--------------------------------------------------------------------------------------
// SimpleESRAM12.h
//
// This sample demonstrates the basics of utilizing ESRAM with DirectX12. It leverages the
// XG & XGMemory APIs to reserve virtual resource memory and subsequently map it to DRAM & ESRAM.
// A few different page mapping schemes are showcased to provide examples of how the XGMemory
// library can be used to customize resource layout between DRAM & ESRAM.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include "DeviceResources.h"
#include "PerformanceTimersXbox.h"
#include "StepTimer.h"
constexpr int PlaneCount = _countof(XG_RESOURCE_LAYOUT::Plane);
struct MetadataDesc
{
struct PageRange
{
int start;
int count;
int End() const { return start + count; }
};
int count;
PageRange ranges[PlaneCount];
int End() { assert(count > 0); return ranges[count - 1].End(); }
};
class Sample
{
public:
Sample();
// Initialization and management
void Initialize(IUnknown* window);
// 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 CreateDeviceDependentResources();
void CreateWindowSizeDependentResources();
void UpdateResourceMappings();
private:
// Enumerates the example ESRAM mapping schemes for the sample.
enum EsramMappingScheme
{
EMS_None = 0, // Maps all resource memory to DRAM.
EMS_Simple, // Maps a specified number of pages to ESRAM and the remaining pages to DRAM.
EMS_Split, // Splits the resource into a beginning DRAM section, a middle ESRAM section, and an ending DRAM section.
EMS_Metadata, // Only maps the resource metadata to ESRAM.
EMS_Random, // Performs a randomized per-page choice of DRAM or ESRAM according to a specified probability.
EMS_Count
};
// Represents an instance of a scene object.
struct ObjectInstance
{
using EffectList = std::vector<std::shared_ptr<DirectX::IEffect>>;
DirectX::SimpleMath::Matrix world;
DirectX::Model* model;
EffectList effects;
};
private:
// Device resources.
std::unique_ptr<DX::DeviceResources> m_deviceResources;
int m_displayWidth;
int 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::DescriptorPile> m_rtvPile;
std::unique_ptr<DirectX::DescriptorPile> m_dsvPile;
// 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::unique_ptr<DirectX::EffectTextureFactory> m_textureFactory;
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::BasicEffect> m_manualClearEffect;
std::unique_ptr<DirectX::BasicEffect> m_esramBlendEffect;
// Misc.
std::mt19937 m_generator;
//--------------------------------
// ESRAM-pertinent variables
bool m_showOverlay = false;
EsramMappingScheme m_mapScheme = EMS_None;
int m_colorEsramPageCount = 0; // Simple Mapping
int m_depthEsramPageCount = 0;
float m_bottomPercent = 0.2f; // Split Mapping
float m_topPercent = 0.8f;
bool m_metadataEnabled = true; // Metadata Mapping
float m_esramProbability = 0.5f; // Random Mapping
// XG Memory
XGMemoryLayoutEngine m_layoutEngine;
Microsoft::WRL::ComPtr<XGMemoryLayout> m_layout;
// Color & Depth Resources
int m_colorPageCount = 0;
MetadataDesc m_colorLayoutDesc;
int m_depthPageCount = 0;
MetadataDesc m_depthLayoutDesc;
int m_esramOverlayPageCount = 0;
// Main render targets.
D3D12_RESOURCE_DESC m_colorDesc;
D3D12_RESOURCE_DESC m_depthDesc;
D3D12_RESOURCE_DESC m_esramOverlayDesc;
Microsoft::WRL::ComPtr<ID3D12Resource> m_colorTexture;
Microsoft::WRL::ComPtr<ID3D12Resource> m_depthTexture;
Microsoft::WRL::ComPtr<ID3D12Resource> m_esramOverlayTexture;
};