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
|
// Copyright 2014 Intel Corporation All Rights Reserved
//
// Intel makes no representations about the suitability of this software for any purpose.
// THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES,
// FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY
// RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Intel does not assume any responsibility for any errors which may appear in this software
// nor any responsibility to update it.
#pragma once
#include "RenderDevice.h"
#include "SwapChain.h"
#include "DeviceContext.h"
#include "RefCntAutoPtr.hpp"
#include "ThreadSignal.hpp"
#include <map>
#include <mutex>
#include <atomic>
#include "camera.h"
#include "settings.h"
#include "simulation.h"
#include "util.h"
#include "gui.h"
namespace AsteroidsDE {
class Asteroids {
public:
Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, GUI* gui, HWND hWnd, Diligent::RENDER_DEVICE_TYPE DevType);
~Asteroids();
void Render(float frameTime, const OrbitCamera& camera, const Settings& settings);
void ResizeSwapChain(HWND outputWindow, unsigned int width, unsigned int height);
void GetPerfCounters(float &UpdateTime, float &RenderTime);
private:
void CreateMeshes();
void InitializeTextureData();
void CreateGUIResources();
void RenderSubset(Diligent::Uint32 SubsetNum, Diligent::IDeviceContext *pCtx, const OrbitCamera& camera, Diligent::Uint32 startIdx, Diligent::Uint32 numAsteroids);
void InitDevice(HWND hWnd, Diligent::RENDER_DEVICE_TYPE DevType);
enum class BindingMode
{
Dynamic = 0,
Mutable,
TextureMutable,
Bindless
}m_BindingMode = BindingMode::TextureMutable;
AsteroidsSimulation* mAsteroids = nullptr;
GUI* mGUI = nullptr;
Diligent::RefCntAutoPtr<Diligent::ISwapChain> mSwapChain;
Diligent::RefCntAutoPtr<Diligent::IRenderDevice> mDevice;
Diligent::RefCntAutoPtr<Diligent::IDeviceContext> mDeviceCtxt;
std::vector< Diligent::RefCntAutoPtr<Diligent::IDeviceContext> > mDeferredCtxt;
std::vector< Diligent::RefCntAutoPtr<Diligent::ICommandList> > mCmdLists;
std::vector< Diligent::ICommandList* > mCmdListPtrs;
Diligent::Uint32 mBackBufferWidth, mBackBufferHeight;
Diligent::Uint32 mNumSubsets = 0;
std::vector<std::thread> mWorkerThreads;
std::mutex mMutex;
std::condition_variable mCondVar;
ThreadingTools::Signal mUpdateSubsetsSignal;
ThreadingTools::Signal mRenderSubsetsSignal;
std::atomic_int m_NumThreadsCompleted;
static void WorkerThreadFunc(Asteroids *pThis, Diligent::Uint32 ThreadNum);
struct FrameAttribs
{
float frameTime;
const OrbitCamera* camera;
const Settings* settings;
}mFrameAttribs;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mIndexBuffer;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mVertexBuffer;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mInstanceIDBuffer;
std::vector<Diligent::RefCntAutoPtr<Diligent::IBuffer>> mAsteroidsDataBuffers;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mDrawConstantBuffer;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mSpriteVertexBuffer;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mSkyboxConstantBuffer;
Diligent::RefCntAutoPtr<Diligent::IBuffer> mSkyboxVertexBuffer;
Diligent::RefCntAutoPtr<Diligent::IPipelineState> mAsteroidsPSO;
std::vector< Diligent::RefCntAutoPtr<Diligent::IShaderResourceBinding> > mAsteroidsSRBs;
Diligent::RefCntAutoPtr<Diligent::IPipelineState> mFontPSO;
Diligent::RefCntAutoPtr<Diligent::IPipelineState> mSpritePSO;
Diligent::RefCntAutoPtr<Diligent::IShaderResourceBinding> mSpriteSRB;
Diligent::RefCntAutoPtr<Diligent::IShaderResourceBinding> mFontSRB;
Diligent::RefCntAutoPtr<Diligent::IPipelineState> mSkyboxPSO;
Diligent::RefCntAutoPtr<Diligent::IShaderResourceBinding> mSkyboxSRB;
std::map<std::string, Diligent::RefCntAutoPtr<Diligent::ITextureView>> mSpriteTextures;
Diligent::RefCntAutoPtr<Diligent::ITextureView> mSkyboxSRV;
Diligent::RefCntAutoPtr<Diligent::ITextureView> mFontTextureSRV;
Diligent::RefCntAutoPtr<Diligent::ITexture> mTextures[NUM_UNIQUE_TEXTURES];
Diligent::RefCntAutoPtr<Diligent::ITextureView> mTextureSRVs[NUM_UNIQUE_TEXTURES];
Diligent::RefCntAutoPtr<Diligent::ISampler> mSamplerState;
std::unique_ptr<GUISprite> mSprite;
UINT64 mPerfCounterFreq = 0;
volatile LONG64 mUpdateTicks = 0, mRenderTicks = 0;
};
} // namespace AsteroidsD3D11
|