Skip to content

Commit 205fab5

Browse files
committed
Fixid shader compilation issues for all renderers
1 parent f94da38 commit 205fab5

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/Layers/xrRender/ResourceManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class ECORE_API CResourceManager
255255
T& GetShaderMap();
256256

257257
template <typename T>
258-
T* CreateShader(const char* name, const bool searchForEntryAndTarget = false);
258+
T* CreateShader(const char* name, const char* filename = nullptr, const bool searchForEntryAndTarget = false);
259259

260260
template <typename T>
261261
void DestroyShader(const T* sh);

src/Layers/xrRender/ResourceManager_Resources.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
172172
if (4 == GEnv.Render->m_skinning)
173173
xr_strcat(name, "_4");
174174

175-
return CreateShader<SVS>(name, true);
175+
return CreateShader<SVS>(name, _name, true);
176176
}
177177

178178
void CResourceManager::_DeleteVS(const SVS* vs) { DestroyShader(vs); }
179179

180-
SPS* CResourceManager::_CreatePS(LPCSTR name) { return CreateShader<SPS>(name, true); }
180+
SPS* CResourceManager::_CreatePS(LPCSTR name) { return CreateShader<SPS>(name, nullptr, true); }
181181
void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }
182182

183183
R_constant_table* CResourceManager::_CreateConstantTable(R_constant_table& C)

src/Layers/xrRender/ShaderResourceTraits.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ inline CResourceManager::map_CS& CResourceManager::GetShaderMap()
338338
#endif
339339

340340
template <typename T>
341-
inline T* CResourceManager::CreateShader(const char* name, const bool searchForEntryAndTarget /*= false*/)
341+
inline T* CResourceManager::CreateShader(const char* name, const char* filename /*= nullptr*/, const bool searchForEntryAndTarget /*= false*/)
342342
{
343343
ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
344344
LPSTR N = LPSTR(name);
@@ -360,26 +360,24 @@ inline T* CResourceManager::CreateShader(const char* name, const bool searchForE
360360

361361
// Remove ( and everything after it
362362
string_path shName;
363-
const char* pchr = strchr(name, '(');
364-
ptrdiff_t strSize = pchr ? pchr - name : xr_strlen(name);
365-
strncpy(shName, name, strSize);
366-
shName[strSize] = 0;
363+
{
364+
if (filename == nullptr)
365+
filename = name;
366+
367+
pcstr pchr = strchr(filename, '(');
368+
ptrdiff_t size = pchr ? pchr - filename : xr_strlen(filename);
369+
strncpy(shName, filename, size);
370+
shName[size] = 0;
371+
}
367372

368373
// Open file
369374
string_path cname;
370-
strconcat(sizeof(cname), cname, GEnv.Render->getShaderPath(), /*name*/ shName,
375+
strconcat(sizeof(cname), cname, GEnv.Render->getShaderPath(), shName,
371376
ShaderTypeTraits<T>::GetShaderExt());
372377
FS.update_path(cname, "$game_shaders$", cname);
373378

374379
// Try to open
375380
IReader* file = FS.r_open(cname);
376-
if (!file)
377-
{
378-
// Cut last two chars and try again
379-
// Needed for R1 vertex shaders
380-
cname[xr_strlen(cname) - 2] = '\0';
381-
file = FS.r_open(cname);
382-
}
383381

384382
bool fallback = strstr(Core.Params, "-lack_of_shaders");
385383
if (!file && fallback)

src/Layers/xrRenderDX10/dx10ResourceManager_Resources.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
135135
if (4 == GEnv.Render->m_skinning)
136136
xr_strcat(name, "_4");
137137

138-
return CreateShader<SVS>(name, true);
138+
return CreateShader<SVS>(name, _name, true);
139139
}
140140

141141
void CResourceManager::_DeleteVS(const SVS* vs)
@@ -189,7 +189,7 @@ SPS* CResourceManager::_CreatePS(LPCSTR _name)
189189
if (7 == GEnv.Render->m_MSAASample)
190190
xr_strcat(name, "_7");
191191

192-
return CreateShader<SPS>(name, true);
192+
return CreateShader<SPS>(name, _name, true);
193193
}
194194

195195
void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }

0 commit comments

Comments
 (0)