Skip to content

Commit 6da29d8

Browse files
committed
Merge remote-tracking branch 'upstream/xd_dev' into xd_dev
2 parents af404e3 + 5187620 commit 6da29d8

File tree

17 files changed

+313
-562
lines changed

17 files changed

+313
-562
lines changed

src/Layers/xrRender/R_Backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class ECORE_API CBackend
314314
#else
315315
ICF void set_PS(ID3DPixelShader* _ps, LPCSTR _n = nullptr);
316316
#endif // USE_OGL
317-
ICF void set_PS(ref_ps& _ps) { set_PS(_ps->ps, _ps->cName.c_str()); }
317+
ICF void set_PS(ref_ps& _ps) { set_PS(_ps->sh, _ps->cName.c_str()); }
318318

319319
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
320320
#ifdef USE_OGL

src/Layers/xrRender/ResourceManager.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class ECORE_API CResourceManager
4040

4141
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
4242
using map_GS = xr_map<const char*, SGS*, str_pred>;
43-
#endif // USE_DX10
44-
#ifdef USE_DX11
43+
#endif
44+
45+
#if defined(USE_DX11)
4546
using map_HS = xr_map<const char*, SHS*, str_pred>;
4647
using map_DS = xr_map<const char*, SDS*, str_pred>;
4748
using map_CS = xr_map<const char*, SCS*, str_pred>;
@@ -163,7 +164,7 @@ class ECORE_API CResourceManager
163164
void _DeleteGS(const SGS* GS);
164165
#endif // USE_DX10
165166

166-
#ifdef USE_DX11
167+
#if defined(USE_DX11)
167168
SHS* _CreateHS(LPCSTR Name);
168169
void _DeleteHS(const SHS* HS);
169170

@@ -172,7 +173,7 @@ class ECORE_API CResourceManager
172173

173174
SCS* _CreateCS(LPCSTR Name);
174175
void _DeleteCS(const SCS* CS);
175-
#endif // USE_DX10
176+
#endif
176177

177178
SPS* _CreatePS(LPCSTR Name);
178179
void _DeletePS(const SPS* PS);
@@ -189,7 +190,8 @@ class ECORE_API CResourceManager
189190

190191
#ifdef USE_OGL
191192
SDeclaration* _CreateDecl (u32 FVF);
192-
#endif // USE_OGL
193+
#endif
194+
193195
SDeclaration* _CreateDecl(D3DVERTEXELEMENT9* dcl);
194196
void _DeleteDecl(const SDeclaration* dcl);
195197

@@ -237,7 +239,8 @@ class ECORE_API CResourceManager
237239
#else
238240
SGeometry* CreateGeom(D3DVERTEXELEMENT9* decl, ID3DVertexBuffer* vb, ID3DIndexBuffer* ib);
239241
SGeometry* CreateGeom(u32 FVF, ID3DVertexBuffer* vb, ID3DIndexBuffer* ib);
240-
#endif // USE_OGL
242+
#endif
243+
241244
void DeleteGeom(const SGeometry* VS);
242245
void DeferredLoad(BOOL E) { bDeferredLoad = E; }
243246
void DeferredUpload();
@@ -248,16 +251,14 @@ class ECORE_API CResourceManager
248251
void Dump(bool bBrief);
249252

250253
private:
251-
#if defined(USE_DX10) || defined(USE_DX11)
252254
template <typename T>
253255
T& GetShaderMap();
254256

255257
template <typename T>
256-
T* CreateShader(const char* name);
258+
T* CreateShader(const char* name, const bool searchForEntryAndTarget = false);
257259

258260
template <typename T>
259261
void DestroyShader(const T* sh);
260-
#endif
261262
};
262263

263264
#endif // ResourceManagerH

src/Layers/xrRender/ResourceManager_Resources.cpp

Lines changed: 6 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "tss.h"
1515
#include "blenders/blender.h"
1616
#include "blenders/blender_recorder.h"
17+
#include "ShaderResourceTraits.h"
1718

1819
void fix_texture_name(LPSTR fn);
1920

@@ -156,7 +157,6 @@ void CResourceManager::_DeleteDecl(const SDeclaration* dcl)
156157
}
157158

158159
//--------------------------------------------------------------------------------------------------------------
159-
#ifndef _EDITOR
160160
SVS* CResourceManager::_CreateVS(LPCSTR _name)
161161
{
162162
string_path name;
@@ -171,179 +171,14 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
171171
xr_strcat(name, "_3");
172172
if (4 == GEnv.Render->m_skinning)
173173
xr_strcat(name, "_4");
174-
LPSTR N = LPSTR(name);
175-
map_VS::iterator I = m_vs.find(N);
176-
if (I != m_vs.end())
177-
return I->second;
178-
else
179-
{
180-
SVS* _vs = new SVS();
181-
_vs->dwFlags |= xr_resource_flagged::RF_REGISTERED;
182-
m_vs.insert(std::make_pair(_vs->set_name(name), _vs));
183-
if (0 == xr_stricmp(_name, "null"))
184-
{
185-
_vs->vs = nullptr;
186-
return _vs;
187-
}
188-
189-
string_path cname;
190-
strconcat(sizeof(cname), cname, GEnv.Render->getShaderPath(), _name, ".vs");
191-
FS.update_path(cname, "$game_shaders$", cname);
192-
// LPCSTR target = NULL;
193-
194-
IReader* fs = FS.r_open(cname);
195-
R_ASSERT3(fs, "shader file doesnt exist", cname);
196-
197-
// Select target
198-
LPCSTR c_target = "vs_2_0";
199-
LPCSTR c_entry = "main";
200-
if (HW.Caps.geometry_major >= 2)
201-
c_target = "vs_2_0";
202-
else
203-
c_target = "vs_1_1";
204-
205-
// duplicate and zero-terminate
206-
IReader* file = FS.r_open(cname);
207-
R_ASSERT2(file, cname);
208-
u32 const size = file->length();
209-
char* const data = (LPSTR)_alloca(size + 1);
210-
CopyMemory(data, file->pointer(), size);
211-
data[size] = 0;
212-
FS.r_close(file);
213-
214-
if (strstr(data, "main_vs_1_1"))
215-
{
216-
c_target = "vs_1_1";
217-
c_entry = "main_vs_1_1";
218-
}
219-
if (strstr(data, "main_vs_2_0"))
220-
{
221-
c_target = "vs_2_0";
222-
c_entry = "main_vs_2_0";
223-
}
224-
225-
Msg("compiling shader %s", name);
226-
HRESULT const _hr = GEnv.Render->shader_compile(name, (DWORD const*)data, size, c_entry, c_target,
227-
D3DXSHADER_DEBUG | D3DXSHADER_PACKMATRIX_ROWMAJOR, (void*&)_vs);
228-
229-
if (FAILED(_hr))
230-
{
231-
FlushLog();
232-
}
233-
234-
CHECK_OR_EXIT(!FAILED(_hr), "Your video card doesn't meet game requirements.\n\nTry to lower game settings.");
235-
236-
return _vs;
237-
}
174+
175+
return CreateShader<SVS>(name, true);
238176
}
239-
#endif
240-
241-
void CResourceManager::_DeleteVS(const SVS* vs)
242-
{
243-
if (0 == (vs->dwFlags & xr_resource_flagged::RF_REGISTERED))
244-
return;
245-
LPSTR N = LPSTR(*vs->cName);
246-
map_VS::iterator I = m_vs.find(N);
247-
if (I != m_vs.end())
248-
{
249-
m_vs.erase(I);
250-
return;
251-
}
252-
Msg("! ERROR: Failed to find compiled vertex-shader '%s'", *vs->cName);
253-
}
254-
255-
#ifndef _EDITOR
256-
//--------------------------------------------------------------------------------------------------------------
257-
SPS* CResourceManager::_CreatePS(LPCSTR name)
258-
{
259-
LPSTR N = LPSTR(name);
260-
map_PS::iterator I = m_ps.find(N);
261-
if (I != m_ps.end())
262-
return I->second;
263-
else
264-
{
265-
SPS* _ps = new SPS();
266-
_ps->dwFlags |= xr_resource_flagged::RF_REGISTERED;
267-
m_ps.insert(std::make_pair(_ps->set_name(name), _ps));
268-
if (0 == xr_stricmp(name, "null"))
269-
{
270-
_ps->ps = nullptr;
271-
return _ps;
272-
}
273-
274-
// Open file
275-
string_path cname;
276-
LPCSTR shader_path = GEnv.Render->getShaderPath();
277-
strconcat(sizeof(cname), cname, shader_path, name, ".ps");
278-
FS.update_path(cname, "$game_shaders$", cname);
279177

280-
// duplicate and zero-terminate
281-
IReader* file = FS.r_open(cname);
282-
R_ASSERT2(file, cname);
283-
u32 const size = file->length();
284-
char* const data = (LPSTR)_alloca(size + 1);
285-
CopyMemory(data, file->pointer(), size);
286-
data[size] = 0;
287-
FS.r_close(file);
178+
void CResourceManager::_DeleteVS(const SVS* vs) { DestroyShader(vs); }
288179

289-
// Select target
290-
LPCSTR c_target = "ps_2_0";
291-
LPCSTR c_entry = "main";
292-
if (strstr(data, "main_ps_1_1"))
293-
{
294-
c_target = "ps_1_1";
295-
c_entry = "main_ps_1_1";
296-
}
297-
if (strstr(data, "main_ps_1_2"))
298-
{
299-
c_target = "ps_1_2";
300-
c_entry = "main_ps_1_2";
301-
}
302-
if (strstr(data, "main_ps_1_3"))
303-
{
304-
c_target = "ps_1_3";
305-
c_entry = "main_ps_1_3";
306-
}
307-
if (strstr(data, "main_ps_1_4"))
308-
{
309-
c_target = "ps_1_4";
310-
c_entry = "main_ps_1_4";
311-
}
312-
if (strstr(data, "main_ps_2_0"))
313-
{
314-
c_target = "ps_2_0";
315-
c_entry = "main_ps_2_0";
316-
}
317-
318-
Msg("compiling shader %s", name);
319-
HRESULT const _hr = GEnv.Render->shader_compile(name, (DWORD const*)data, size, c_entry, c_target,
320-
D3DXSHADER_DEBUG | D3DXSHADER_PACKMATRIX_ROWMAJOR, (void*&)_ps);
321-
322-
if (FAILED(_hr))
323-
{
324-
FlushLog();
325-
}
326-
327-
CHECK_OR_EXIT(!FAILED(_hr), "Your video card doesn't meet game requirements.\n\nTry to lower game settings.");
328-
329-
return _ps;
330-
}
331-
}
332-
#endif
333-
334-
void CResourceManager::_DeletePS(const SPS* ps)
335-
{
336-
if (0 == (ps->dwFlags & xr_resource_flagged::RF_REGISTERED))
337-
return;
338-
LPSTR N = LPSTR(*ps->cName);
339-
map_PS::iterator I = m_ps.find(N);
340-
if (I != m_ps.end())
341-
{
342-
m_ps.erase(I);
343-
return;
344-
}
345-
Msg("! ERROR: Failed to find compiled pixel-shader '%s'", *ps->cName);
346-
}
180+
SPS* CResourceManager::_CreatePS(LPCSTR name) { return CreateShader<SPS>(name, true); }
181+
void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }
347182

348183
R_constant_table* CResourceManager::_CreateConstantTable(R_constant_table& C)
349184
{

src/Layers/xrRender/SH_Atomic.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
///////////////////////////////////////////////////////////////////////
3030
// SVS
31-
SVS::SVS() : vs(0)
31+
SVS::SVS() : sh(0)
3232
#if defined(USE_DX10) || defined(USE_DX11)
3333
// ,signature(0)
3434
#endif // USE_DX10
@@ -37,26 +37,29 @@ SVS::SVS() : vs(0)
3737
SVS::~SVS()
3838
{
3939
RImplementation.Resources->_DeleteVS(this);
40+
4041
#if defined(USE_DX10) || defined(USE_DX11)
4142
//_RELEASE(signature);
4243
// Now it is release automatically
43-
#endif //USE_DX10
44+
#endif
45+
4446
#ifdef USE_OGL
45-
CHK_GL(glDeleteProgram(vs));
47+
CHK_GL(glDeleteProgram(sh));
4648
#else
47-
_RELEASE(vs);
48-
#endif // USE_OGL
49+
_RELEASE(sh);
50+
#endif
4951
}
5052

5153
///////////////////////////////////////////////////////////////////////
5254
// SPS
5355
SPS::~SPS()
5456
{
5557
#ifdef USE_OGL
56-
CHK_GL(glDeleteProgram(ps));
58+
CHK_GL(glDeleteProgram(sh));
5759
#else
58-
_RELEASE(ps);
59-
#endif // USE_OGL
60+
_RELEASE(sh);
61+
#endif
62+
6063
RImplementation.Resources->_DeletePS(this);
6164
}
6265

@@ -69,26 +72,42 @@ SGS::~SGS()
6972
CHK_GL(glDeleteProgram(sh));
7073
#else
7174
_RELEASE(sh);
72-
#endif // USE_OGL
75+
#endif
76+
7377
RImplementation.Resources->_DeleteGS(this);
7478
}
7579

76-
#ifdef USE_DX11
80+
#if defined(USE_DX11)
7781
SHS::~SHS()
7882
{
83+
#ifdef USE_OGL
84+
CHK_GL(glDeleteProgram(sh));
85+
#else
7986
_RELEASE(sh);
87+
#endif
88+
8089
RImplementation.Resources->_DeleteHS(this);
8190
}
8291

8392
SDS::~SDS()
8493
{
94+
#ifdef USE_OGL
95+
CHK_GL(glDeleteProgram(sh));
96+
#else
8597
_RELEASE(sh);
98+
#endif
99+
86100
RImplementation.Resources->_DeleteDS(this);
87101
}
88102

89103
SCS::~SCS()
90104
{
105+
#ifdef USE_OGL
106+
CHK_GL(glDeleteProgram(sh));
107+
#else
91108
_RELEASE(sh);
109+
#endif
110+
92111
RImplementation.Resources->_DeleteCS(this);
93112
}
94113
#endif

0 commit comments

Comments
 (0)