Repository navigation
Expand file tree
/
Copy pathDXXModule.cpp
More file actions
executable file
·160 lines (130 loc) · 3.22 KB
/
Copy pathDXXModule.cpp
File metadata and controls
executable file
·160 lines (130 loc) · 3.22 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
155
156
157
158
159
160
//==============================================================================
// Copyright (c) 2011-2016 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools
/// \file
/// \brief This class manages the dynamic loading of atidxx{32,64}.dll
//==============================================================================
#include <string>
#include "DXXModule.h"
#if _WIN64
const char* AMDDXXModule::s_DefaultModuleName = "atidxx64.dll";
#else
const char* AMDDXXModule::s_DefaultModuleName = "atidxx32.dll";
#endif
AMDDXXModule::AMDDXXModule(const std::string& moduleName)
{
Initialize();
LoadModule(moduleName);
}
AMDDXXModule::AMDDXXModule()
{
}
AMDDXXModule::~AMDDXXModule()
{
UnloadModule();
}
void AMDDXXModule::Initialize()
{
#define X(SYM) SYM = NULL;
AMDDXX_INTERFACE_TABLE;
#undef X
m_ModuleLoaded = false;
}
void AMDDXXModule::UnloadModule()
{
m_DynamicLibraryHelper.UnloadModule();
Initialize();
}
bool
AMDDXXModule::LoadModule(
const std::string& moduleName)
{
if (m_ModuleLoaded)
{
UnloadModule();
}
if (m_DynamicLibraryHelper.LoadModule(moduleName))
{
#define MAKE_STRING(s) #s
#define X(SYM) SYM = (Pfn##SYM) m_DynamicLibraryHelper.GetProcAddress(MAKE_STRING(SYM));
AMDDXX_INTERFACE_TABLE;
#undef X
#undef MAKE_STRING
// Decide if we got everything
#define X(SYM) && SYM != NULL
m_ModuleLoaded = 1 AMDDXX_INTERFACE_TABLE;
#undef X
// If we failed, clean up.
if (!m_ModuleLoaded)
{
UnloadModule();
}
}
return m_ModuleLoaded;
}
// This will be something like: "d3dcompiler_43.dll".
#if _WIN64
const char* D3DCompileModule::s_DefaultModuleName = "d3dcompiler_47.dll";
#else
const char* D3DCompileModule::s_DefaultModuleName = "d3dcompiler_47.dll";
#endif
D3DCompileModule::D3DCompileModule(const std::string& moduleName)
{
Initialize();
LoadModule(moduleName);
}
D3DCompileModule::~D3DCompileModule()
{
UnloadModule();
}
void D3DCompileModule::Initialize()
{
#define X(SYM) SYM = NULL;
D3DCOMPILE_INTERFACE_TABLE;
#undef X
m_isModuleLoaded = false;
}
void D3DCompileModule::UnloadModule()
{
m_DynamicLibraryHelper.UnloadModule();
Initialize();
}
bool D3DCompileModule::LoadModule(const std::string& name /*= s_DefaultModuleName*/, int* pErrorCode /* = NULL*/)
{
if (m_isModuleLoaded)
{
UnloadModule();
}
if (pErrorCode)
{
*pErrorCode = 0;
}
if (m_DynamicLibraryHelper.LoadModule(name))
{
#define MAKE_STRING(s) #s
#define X(SYM) SYM = (p##SYM) m_DynamicLibraryHelper.GetProcAddress(MAKE_STRING(SYM));
D3DCOMPILE_INTERFACE_TABLE;
#undef X
#undef MAKE_STRING
m_isModuleLoaded = (D3DCompile != NULL) &&
(D3DDisassemble != NULL) &&
(D3DCompressShaders != NULL);
// If we failed, clean up.
if (!m_isModuleLoaded)
{
if (pErrorCode)
{
*pErrorCode = GetLastError();
}
UnloadModule();
}
}
else
{
if (pErrorCode)
{
*pErrorCode = GetLastError();
}
}
return m_isModuleLoaded;
}