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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef SHADERDEVICEBASE_H
#define SHADERDEVICEBASE_H
#ifdef _WIN32
#pragma once
#endif
#include "togl/rendermechanism.h"
#include "shaderapi/IShaderDevice.h"
#include "IHardwareConfigInternal.h"
#include "bitmap/imageformat.h"
#include "materialsystem/imaterialsystem.h"
#include "hardwareconfig.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class KeyValues;
//-----------------------------------------------------------------------------
// define this if you want to run with NVPERFHUD
//-----------------------------------------------------------------------------
//#define NVPERFHUD 1
//-----------------------------------------------------------------------------
// Uncomment this to activate the reference rasterizer
//-----------------------------------------------------------------------------
//#define USE_REFERENCE_RASTERIZER 1
//-----------------------------------------------------------------------------
// Uncomment to check for -nulldevice on command line and use D3DDEVTYPE_NULLREF.
//-----------------------------------------------------------------------------
#define ENABLE_NULLREF_DEVICE_SUPPORT
//-----------------------------------------------------------------------------
// The Base implementation of the shader device
//-----------------------------------------------------------------------------
class CShaderDeviceMgrBase : public IShaderDeviceMgr
{
public:
// constructor, destructor
CShaderDeviceMgrBase();
virtual ~CShaderDeviceMgrBase();
// Methods of IAppSystem
virtual bool Connect( CreateInterfaceFn factory );
virtual void Disconnect();
virtual void *QueryInterface( const char *pInterfaceName );
// Methods of IShaderDeviceMgr
virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pCongifuration );
virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func );
virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func );
// Reads in the hardware caps from the dxsupport.cfg file
void ReadHardwareCaps( HardwareCaps_t &caps, int nDxLevel );
// Reads in the max + preferred DX support level
void ReadDXSupportLevels( HardwareCaps_t &caps );
// Returns the hardware caps for a particular adapter
const HardwareCaps_t& GetHardwareCaps( int nAdapter ) const;
// Invokes mode change callbacks
void InvokeModeChangeCallbacks();
// Factory to return from SetMode
static void* ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode );
// Returns only valid dx levels
int GetClosestActualDXLevel( int nDxLevel ) const;
protected:
struct AdapterInfo_t
{
HardwareCaps_t m_ActualCaps;
};
private:
// Reads in the dxsupport.cfg keyvalues
KeyValues *ReadDXSupportKeyValues();
// Reads in ConVars + config variables
void LoadConfig( KeyValues *pKeyValues, KeyValues *pConfiguration );
// Loads the hardware caps, for cases in which the D3D caps lie or where we need to augment the caps
void LoadHardwareCaps( KeyValues *pGroup, HardwareCaps_t &caps );
// Gets the recommended configuration associated with a particular dx level
bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, int nVendorID, int nDeviceID, KeyValues *pConfiguration );
// Returns the amount of video memory in bytes for a particular adapter
virtual int GetVidMemBytes( int nAdapter ) const = 0;
// Looks for override keyvalues in the dxsupport cfg keyvalues
KeyValues *FindDXLevelSpecificConfig( KeyValues *pKeyValues, int nDxLevel );
KeyValues *FindDXLevelAndVendorSpecificConfig( KeyValues *pKeyValues, int nDxLevel, int nVendorID );
KeyValues *FindCPUSpecificConfig( KeyValues *pKeyValues, int nCPUMhz, bool bAMD );
KeyValues *FindMemorySpecificConfig( KeyValues *pKeyValues, int nSystemRamMB );
KeyValues *FindVidMemSpecificConfig( KeyValues *pKeyValues, int nVideoRamMB );
KeyValues *FindCardSpecificConfig( KeyValues *pKeyValues, int nVendorID, int nDeviceID );
protected:
// Stores adapter info for all adapters
CUtlVector<AdapterInfo_t> m_Adapters;
// Installed mode change callbacks
CUtlVector< ShaderModeChangeCallbackFunc_t > m_ModeChangeCallbacks;
KeyValues *m_pDXSupport;
};
//-----------------------------------------------------------------------------
// The Base implementation of the shader device
//-----------------------------------------------------------------------------
class CShaderDeviceBase : public IShaderDevice
{
public:
enum IPCMessage_t
{
RELEASE_MESSAGE = 0x5E740DE0,
REACQUIRE_MESSAGE = 0x5E740DE1,
EVICT_MESSAGE = 0x5E740DE2,
};
// Methods of IShaderDevice
public:
virtual ImageFormat GetBackBufferFormat() const;
virtual int StencilBufferBits() const;
virtual bool IsAAEnabled() const;
virtual bool AddView( void* hWnd );
virtual void RemoveView( void* hWnd );
virtual void SetView( void* hWnd );
virtual void GetWindowSize( int& nWidth, int& nHeight ) const;
// Methods exposed to the rest of shader api
virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) = 0;
virtual void ShutdownDevice() = 0;
virtual bool IsDeactivated() const = 0;
public:
// constructor, destructor
CShaderDeviceBase();
virtual ~CShaderDeviceBase();
virtual void OtherAppInitializing( bool initializing ) {}
virtual void EvictManagedResourcesInternal() {}
void* GetIPCHWnd();
void SendIPCMessage( IPCMessage_t message );
protected:
// IPC communication for multiple shaderapi apps
void InstallWindowHook( void *hWnd );
void RemoveWindowHook( void *hWnd );
void SetCurrentThreadAsOwner();
void RemoveThreadOwner();
bool ThreadOwnsDevice();
// Finds a child window
int FindView( void* hWnd ) const;
int m_nAdapter;
void *m_hWnd;
void* m_hWndCookie;
bool m_bInitialized : 1;
bool m_bIsMinimized : 1;
// The current view hwnd
void* m_ViewHWnd;
int m_nWindowWidth;
int m_nWindowHeight;
uint32 m_dwThreadId;
};
//-----------------------------------------------------------------------------
// Inline methods
//-----------------------------------------------------------------------------
inline void* CShaderDeviceBase::GetIPCHWnd()
{
return m_hWndCookie;
}
//-----------------------------------------------------------------------------
// Helper class to reduce code related to shader buffers
//-----------------------------------------------------------------------------
template< class T >
class CShaderBuffer : public IShaderBuffer
{
public:
CShaderBuffer( T *pBlob ) : m_pBlob( pBlob ) {}
virtual size_t GetSize() const
{
return m_pBlob ? m_pBlob->GetBufferSize() : 0;
}
virtual const void* GetBits() const
{
return m_pBlob ? m_pBlob->GetBufferPointer() : NULL;
}
virtual void Release()
{
if ( m_pBlob )
{
m_pBlob->Release();
}
delete this;
}
private:
T *m_pBlob;
};
#endif // SHADERDEVICEBASE_H
|