Skip to content

Commit ae00a3e

Browse files
committed
Merge remote-tracking branch 'upstream/xd_dev' into xd_dev
2 parents 6189ed7 + c5a5899 commit ae00a3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1109
-670
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 2.8.0)
22
project(OpenXRay)
33

4+
include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake)
45
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
56

67
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++17")

cmake/utils.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
macro(add_dir DIRS)
2+
foreach(dir ${DIRS})
3+
message( "adding " ${dir} )
4+
include_directories (${dir} )
5+
file( GLOB ${dir}__INCLUDES_H ${dir} *.h)
6+
file( GLOB ${dir}__INCLUDES_HPP ${dir} *.hpp)
7+
list( APPEND XRCORE__INCLUDES ${${dir}__INCLUDES_H} ${${dir}__INCLUDES_HPP} )
8+
file( GLOB ${dir}__SOURCES ${dir} *.cpp)
9+
list( APPEND XRCORE__SOURCES ${${dir}__SOURCES} )
10+
endforeach()
11+
endmacro()

src/Common/PlatformLinux.inl

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
#define __cdecl
4545
#define __stdcall
4646
#define __fastcall
47+
4748
//#define __declspec
4849
#define __forceinline FORCE_INLINE
49-
#define __pragma
50+
#define __pragma(...) _Pragma(#__VA_ARGS__)
5051
#define __declspec(x)
5152
#define CALLBACK
5253

54+
#define __except(X) catch(X)
55+
5356
/*
5457
static inline long InterlockedExchange(volatile long *val, long new_val)
5558
{
@@ -60,11 +63,6 @@ static inline long InterlockedExchange(volatile long *val, long new_val)
6063
return old_val;
6164
}
6265
*/
63-
//TODO: Implement more platform independend atomic operations: https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/Common/Atomic_GCC.h
64-
inline void InterlockedExchange(volatile unsigned int& target, unsigned int value)
65-
{
66-
__sync_add_and_fetch(&target, value);
67-
}
6866

6967
inline pthread_t GetCurrentThreadId()
7068
{
@@ -89,9 +87,14 @@ inline unsigned long GetLastError()
8987
return 0;
9088
}
9189

90+
inline int GetExceptionCode()
91+
{
92+
return 0;
93+
}
94+
9295
#define xr_unlink unlink
9396

94-
typedef int BOOL;
97+
typedef char BOOL;
9598
typedef char* LPSTR;
9699
typedef char* PSTR;
97100
typedef char* LPTSTR;
@@ -103,17 +106,16 @@ typedef unsigned int UINT;
103106
typedef int INT;
104107
typedef long LONG;
105108
typedef unsigned long ULONG;
106-
typedef unsigned long ULONG_PTR, *PULONG_PTR;
107-
//typedef unsigned long& ULONG_PTR;
108-
//typedef long long int LARGE_INTEGER;
109-
//typedef unsigned long long int ULARGE_INTEGER;
109+
typedef unsigned long& ULONG_PTR;
110+
typedef long long int LARGE_INTEGER;
111+
typedef unsigned long long int ULARGE_INTEGER;
110112

111113
typedef unsigned short WORD;
112114
typedef unsigned short* LPWORD;
113115
typedef unsigned long DWORD;
114116
typedef unsigned long* LPDWORD;
115117
typedef const void *LPCVOID;
116-
//typedef long long int *PLARGE_INTEGER;
118+
typedef long long int *PLARGE_INTEGER;
117119

118120
typedef wchar_t WCHAR;
119121

@@ -142,7 +144,7 @@ typedef unsigned int UINT_PTR;
142144
typedef long LONG_PTR;
143145
#endif // XR_X64
144146

145-
typedef void *HANDLE;
147+
typedef int HANDLE;
146148
typedef void *HMODULE;
147149
typedef void *LPVOID;
148150
typedef UINT_PTR WPARAM;
@@ -216,6 +218,12 @@ typedef dirent DirEntryType;
216218
#define _close close
217219
#define _sopen open
218220
#define _sopen_s(handle, filename, ...) open(filename, O_RDONLY)
221+
inline int _filelength(int fd)
222+
{
223+
struct stat file_info;
224+
::fstat(fd, &file_info);
225+
return file_info.st_size;
226+
}
219227
#define _fdopen fdopen
220228
#define _rmdir rmdir
221229
#define _write write
@@ -230,6 +238,10 @@ typedef dirent DirEntryType;
230238
#undef max
231239
#define __max(a, b) std::max(a, b)
232240
#define __min(a, b) std::min(a, b)
241+
#define _utime utime
242+
#define _utimbuf utimbuf
243+
244+
#define xr_itoa SDL_itoa
233245

234246
#define ZeroMemory(p, sz) memset((p), 0, (sz))
235247
#define CopyMemory(d, s, n) memcpy(d, s, n)
@@ -241,14 +253,7 @@ typedef dirent DirEntryType;
241253
#define S_FALSE 0x10000000
242254
#define E_FAIL 0x80004005
243255

244-
#define STUBBED(txt) do { \
245-
static bool already_seen = false; \
246-
if (!already_seen) { \
247-
already_seen = true; \
248-
fprintf(stderr, "STUBBED: %s in %s, line %d.\n", txt, __FILE__, __LINE__); \
249-
} \
250-
} while (0)
251-
252-
#if __EXCEPTIONS
253-
#define _CPPUNWIND 1
254-
#endif
256+
#define _MAX_DRIVE 3
257+
#define _MAX_DIR 256
258+
#define _MAX_FNAME 256
259+
#define _MAX_EXT 256

src/Layers/xrRender/HW.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ CHW::~CHW() {}
2121
void CHW::CreateD3D()
2222
{
2323
hD3D = XRay::LoadModule(GEnv.isDedicatedServer ? "xrD3D9-Null" : "d3d9.dll");
24-
R_ASSERT2(hD3D->exist(), "Can't find 'd3d9.dll'\nPlease install latest version of DirectX before running this program");
24+
R_ASSERT2(hD3D->IsLoaded(), "Can't find 'd3d9.dll'\nPlease install latest version of DirectX before running this program");
2525

2626
using _Direct3DCreate9 = IDirect3D9* WINAPI(UINT SDKVersion);
27-
auto createD3D = (_Direct3DCreate9*)hD3D->getProcAddress("Direct3DCreate9");
27+
auto createD3D = (_Direct3DCreate9*)hD3D->GetProcAddress("Direct3DCreate9");
2828
R_ASSERT(createD3D);
2929
pD3D = createD3D(D3D_SDK_VERSION);
3030
R_ASSERT2(pD3D, "Please install DirectX 9.0c");

src/Layers/xrRender/R_Backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class ECORE_API CBackend
322322
#else
323323
ICF void set_GS(ID3DGeometryShader* _gs, LPCSTR _n = nullptr);
324324
#endif // USE_OGL
325-
ICF void set_GS(ref_gs& _gs) { set_GS(_gs->gs, _gs->cName.c_str()); }
325+
ICF void set_GS(ref_gs& _gs) { set_GS(_gs->sh, _gs->cName.c_str()); }
326326

327327
# ifdef USE_DX11
328328
ICF void set_HS(ID3D11HullShader* _hs, LPCSTR _n = nullptr);

src/Layers/xrRender/ResourceManager.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ECORE_API CResourceManager
3737
using map_RT = xr_map<const char*, CRT*, str_pred>;
3838
// DX10 cut DEFINE_MAP_PRED(const char*,CRTC*, map_RTC, map_RTCIt, str_pred);
3939
using map_VS = xr_map<const char*, SVS*, str_pred>;
40+
4041
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
4142
using map_GS = xr_map<const char*, SGS*, str_pred>;
4243
#endif // USE_DX10
@@ -59,9 +60,17 @@ class ECORE_API CResourceManager
5960
// DX10 cut map_RTC m_rtargets_c;
6061
map_VS m_vs;
6162
map_PS m_ps;
63+
6264
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
6365
map_GS m_gs;
64-
#endif // USE_DX10
66+
#endif
67+
68+
#if defined(USE_DX11)
69+
map_DS m_ds;
70+
map_HS m_hs;
71+
map_CS m_cs;
72+
#endif
73+
6574
map_TD m_td;
6675

6776
xr_vector<SState*> v_states;
@@ -239,11 +248,7 @@ class ECORE_API CResourceManager
239248
void Dump(bool bBrief);
240249

241250
private:
242-
#ifdef USE_DX11
243-
map_DS m_ds;
244-
map_HS m_hs;
245-
map_CS m_cs;
246-
251+
#if defined(USE_DX10) || defined(USE_DX11)
247252
template <typename T>
248253
T& GetShaderMap();
249254

@@ -252,8 +257,7 @@ class ECORE_API CResourceManager
252257

253258
template <typename T>
254259
void DestroyShader(const T* sh);
255-
256-
#endif // USE_DX10
260+
#endif
257261
};
258262

259263
#endif // ResourceManagerH

src/Layers/xrRender/SH_Atomic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ SPS::~SPS()
6666
SGS::~SGS()
6767
{
6868
#ifdef USE_OGL
69-
CHK_GL(glDeleteProgram(gs));
69+
CHK_GL(glDeleteProgram(sh));
7070
#else
71-
_RELEASE(gs);
71+
_RELEASE(sh);
7272
#endif // USE_OGL
7373
RImplementation.Resources->_DeleteGS(this);
7474
}

src/Layers/xrRender/SH_Atomic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ typedef resptr_core<SPS, resptr_base<SPS>> ref_ps;
5858
struct ECORE_API SGS : public xr_resource_named
5959
{
6060
#ifdef USE_OGL
61-
GLuint gs;
61+
GLuint sh;
6262
#else
63-
ID3DGeometryShader* gs;
63+
ID3DGeometryShader* sh;
6464
#endif
6565
R_constant_table constants;
6666
~SGS();

src/Layers/xrRender/ShaderResourceTraits.h

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,55 @@
11
#pragma once
22

3-
#ifdef USE_DX11
3+
#if defined(USE_DX10) || defined(USE_DX11)
44

55
#include "ResourceManager.h"
66

77
template <typename T>
88
struct 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
1053
template <>
1154
struct 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)
64117
template <>
65118
inline 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

82136
template <typename T>
83137
inline 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)
137201
template <typename T>
138202
inline 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

Comments
 (0)