11#pragma once
22
3- #ifdef USE_DX11
3+ #if defined(USE_DX10) || defined( USE_DX11)
44
55#include " ResourceManager.h"
66
77template <typename T>
88struct ShaderTypeTraits ;
99
10+ #if defined(USE_DX10) || defined(USE_DX11)
11+ template <>
12+ struct ShaderTypeTraits <SGS>
13+ {
14+ typedef CResourceManager::map_GS MapType;
15+ typedef ID3DGeometryShader DXIface;
16+
17+ static inline const char * GetShaderExt () { return " .gs" ; }
18+ static inline const char * GetCompilationTarget ()
19+ {
20+ #ifdef USE_DX10
21+ if (HW.pDevice1 == 0 )
22+ return D3D10GetGeometryShaderProfile (HW.pDevice );
23+ else
24+ return " gs_4_1" ;
25+ #endif
26+ #ifdef USE_DX11
27+ if (HW.FeatureLevel == D3D_FEATURE_LEVEL_10_0)
28+ return " gs_4_0" ;
29+ else if (HW.FeatureLevel == D3D_FEATURE_LEVEL_10_1)
30+ return " gs_4_1" ;
31+ else if (HW.FeatureLevel == D3D_FEATURE_LEVEL_11_0)
32+ return " gs_5_0" ;
33+ #endif
34+ NODEFAULT;
35+ return " gs_4_0" ;
36+ }
37+ static inline DXIface* CreateHWShader (DWORD const * buffer, size_t size)
38+ {
39+ DXIface* gs = 0 ;
40+ #ifdef USE_DX11
41+ R_CHK (HW.pDevice ->CreateGeometryShader (buffer, size, 0 , &gs));
42+ #else
43+ R_CHK (HW.pDevice ->CreateGeometryShader (buffer, size, &gs));
44+ #endif
45+ return gs;
46+ }
47+
48+ static inline u32 GetShaderDest () { return RC_dest_geometry; }
49+ };
50+ #endif
51+
52+ #ifdef USE_DX11
1053template <>
1154struct ShaderTypeTraits <SHS>
1255{
@@ -60,7 +103,17 @@ struct ShaderTypeTraits<SCS>
60103
61104 static inline u32 GetShaderDest () { return RC_dest_compute; }
62105};
106+ #endif
107+
108+ #if defined(USE_DX10) || defined(USE_DX11)
109+ template <>
110+ inline CResourceManager::map_GS& CResourceManager::GetShaderMap ()
111+ {
112+ return m_gs;
113+ }
114+ #endif
63115
116+ #if defined(USE_DX11)
64117template <>
65118inline CResourceManager::map_DS& CResourceManager::GetShaderMap ()
66119{
@@ -78,16 +131,17 @@ inline CResourceManager::map_CS& CResourceManager::GetShaderMap()
78131{
79132 return m_cs;
80133}
134+ #endif
81135
82136template <typename T>
83137inline T* CResourceManager::CreateShader (const char * name)
84138{
85139 ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
86140 LPSTR N = LPSTR (name);
87- ShaderTypeTraits<T>::MapType::iterator I = sh_map.find (N);
141+ auto iterator = sh_map.find (N);
88142
89- if (I != sh_map.end ())
90- return I ->second ;
143+ if (iterator != sh_map.end ())
144+ return iterator ->second ;
91145 else
92146 {
93147 T* sh = new T ();
@@ -100,6 +154,7 @@ inline T* CResourceManager::CreateShader(const char* name)
100154 return sh;
101155 }
102156
157+ // Remove ( and everything after it
103158 string_path shName;
104159 const char * pchr = strchr (name, ' (' );
105160 ptrdiff_t strSize = pchr ? pchr - name : xr_strlen (name);
@@ -114,6 +169,15 @@ inline T* CResourceManager::CreateShader(const char* name)
114169
115170 // duplicate and zero-terminate
116171 IReader* file = FS.r_open (cname);
172+ if (!file && strstr (Core.Params , " -lack_of_shaders" ))
173+ {
174+ string1024 tmp;
175+ xr_sprintf (tmp, " CreateShader: %s is missing. Replacing it with stub_default%s" , cname, ShaderTypeTraits<T>::GetShaderExt ());
176+ Msg (tmp);
177+ strconcat (sizeof (cname), cname, GEnv.Render ->getShaderPath (), " stub_default" , ShaderTypeTraits<T>::GetShaderExt ());
178+ FS.update_path (cname, " $game_shaders$" , cname);
179+ file = FS.r_open (cname);
180+ }
117181 R_ASSERT2 (file, cname);
118182
119183 // Select target
@@ -137,17 +201,17 @@ inline T* CResourceManager::CreateShader(const char* name)
137201template <typename T>
138202inline void CResourceManager::DestroyShader (const T* sh)
139203{
140- ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
141-
142204 if (0 == (sh->dwFlags & xr_resource_flagged::RF_REGISTERED))
143205 return ;
144206
207+ ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
208+
145209 LPSTR N = LPSTR (*sh->cName );
146- typename ShaderTypeTraits<T>::MapType:: iterator I = sh_map.find (N);
210+ auto iterator = sh_map.find (N);
147211
148- if (I != sh_map.end ())
212+ if (iterator != sh_map.end ())
149213 {
150- sh_map.erase (I );
214+ sh_map.erase (iterator );
151215 return ;
152216 }
153217 Msg (" ! ERROR: Failed to find compiled geometry shader '%s'" , *sh->cName );
0 commit comments