@@ -34,6 +34,13 @@ struct ShaderTypeTraits<SGS>
3434 NODEFAULT;
3535 return " gs_4_0" ;
3636 }
37+
38+ static void GetCompilationTarget (const char *& target, const char *& entry, const char * /* data*/ )
39+ {
40+ target = GetCompilationTarget ();
41+ entry = " main" ;
42+ }
43+
3744 static inline DXIface* CreateHWShader (DWORD const * buffer, size_t size)
3845 {
3946 DXIface* gs = 0 ;
@@ -58,6 +65,13 @@ struct ShaderTypeTraits<SHS>
5865
5966 static inline const char * GetShaderExt () { return " .hs" ; }
6067 static inline const char * GetCompilationTarget () { return " hs_5_0" ; }
68+
69+ static void GetCompilationTarget (const char *& target, const char *& entry, const char * /* data*/ )
70+ {
71+ target = GetCompilationTarget ();
72+ entry = " main" ;
73+ }
74+
6175 static inline DXIface* CreateHWShader (DWORD const * buffer, size_t size)
6276 {
6377 DXIface* hs = 0 ;
@@ -76,6 +90,13 @@ struct ShaderTypeTraits<SDS>
7690
7791 static inline const char * GetShaderExt () { return " .ds" ; }
7892 static inline const char * GetCompilationTarget () { return " ds_5_0" ; }
93+
94+ static void GetCompilationTarget (const char *& target, const char *& entry, const char * /* data*/ )
95+ {
96+ target = GetCompilationTarget ();
97+ entry = " main" ;
98+ }
99+
79100 static inline DXIface* CreateHWShader (DWORD const * buffer, size_t size)
80101 {
81102 DXIface* hs = 0 ;
@@ -94,6 +115,13 @@ struct ShaderTypeTraits<SCS>
94115
95116 static inline const char * GetShaderExt () { return " .cs" ; }
96117 static inline const char * GetCompilationTarget () { return " cs_5_0" ; }
118+
119+ static void GetCompilationTarget (const char *& target, const char *& entry, const char * /* data*/ )
120+ {
121+ target = GetCompilationTarget ();
122+ entry = " main" ;
123+ }
124+
97125 static inline DXIface* CreateHWShader (DWORD const * buffer, size_t size)
98126 {
99127 DXIface* cs = 0 ;
@@ -134,7 +162,7 @@ inline CResourceManager::map_CS& CResourceManager::GetShaderMap()
134162#endif
135163
136164template <typename T>
137- inline T* CResourceManager::CreateShader (const char * name)
165+ inline T* CResourceManager::CreateShader (const char * name, const bool searchForEntryAndTarget /* = false */ )
138166{
139167 ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
140168 LPSTR N = LPSTR (name);
@@ -180,16 +208,23 @@ inline T* CResourceManager::CreateShader(const char* name)
180208 }
181209 R_ASSERT2 (file, cname);
182210
211+ const auto size = file->length ();
212+ char * const data = (LPSTR)_alloca (size + 1 );
213+ CopyMemory (data, file->pointer (), size);
214+ data[size] = 0 ;
215+ FS.r_close (file);
216+
183217 // Select target
184218 LPCSTR c_target = ShaderTypeTraits<T>::GetCompilationTarget ();
185219 LPCSTR c_entry = " main" ;
220+
221+ if (searchForEntryAndTarget)
222+ ShaderTypeTraits<T>::GetCompilationTarget (c_target, c_entry, data);
186223
187224 // Compile
188- HRESULT const _hr = GEnv.Render ->shader_compile (name, (DWORD const *)file-> pointer (), file-> length () ,
225+ HRESULT const _hr = GEnv.Render ->shader_compile (name, (DWORD const *)data, size ,
189226 c_entry, c_target, D3D10_SHADER_PACK_MATRIX_ROW_MAJOR, (void *&)sh);
190227
191- FS.r_close (file);
192-
193228 VERIFY (SUCCEEDED (_hr));
194229
195230 CHECK_OR_EXIT (!FAILED (_hr), " Your video card doesn't meet game requirements.\n\n Try to lower game settings." );
0 commit comments