Skip to content

Commit

Permalink
RGL: preparations to use ShaderRecourceTraits
Browse files Browse the repository at this point in the history
Allowed Hull, Domain and Compute shaders for OpenGL Renderer
  • Loading branch information
Xottab-DUTY committed May 28, 2018
1 parent 33cf655 commit d21e34a
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/Layers/xrRender/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ECORE_API CResourceManager
using map_GS = xr_map<const char*, SGS*, str_pred>;
#endif

#if defined(USE_DX11)
#if defined(USE_DX11) || defined(USE_OGL)
using map_HS = xr_map<const char*, SHS*, str_pred>;
using map_DS = xr_map<const char*, SDS*, str_pred>;
using map_CS = xr_map<const char*, SCS*, str_pred>;
Expand All @@ -66,7 +66,7 @@ class ECORE_API CResourceManager
map_GS m_gs;
#endif

#if defined(USE_DX11)
#if defined(USE_DX11) || defined(USE_OGL)
map_DS m_ds;
map_HS m_hs;
map_CS m_cs;
Expand Down Expand Up @@ -164,7 +164,7 @@ class ECORE_API CResourceManager
void _DeleteGS(const SGS* GS);
#endif // USE_DX10

#if defined(USE_DX11)
#if defined(USE_DX11) || defined(USE_OGL)
SHS* _CreateHS(LPCSTR Name);
void _DeleteHS(const SHS* HS);

Expand Down
3 changes: 1 addition & 2 deletions src/Layers/xrRender/SH_Atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ struct ECORE_API SGS : public xr_resource_named
typedef resptr_core<SGS, resptr_base<SGS>> ref_gs;
#endif // USE_DX10

#if defined(USE_DX11)

#if defined(USE_DX11) || defined(USE_OGL)
struct ECORE_API SHS : public xr_resource_named
{
#ifdef USE_OGL
Expand Down
104 changes: 77 additions & 27 deletions src/Layers/xrRender/ShaderResourceTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ template <>
struct ShaderTypeTraits<SVS>
{
typedef CResourceManager::map_VS MapType;
typedef ID3DVertexShader DXIface;

#ifdef USE_OGL
using HWShaderType = GLuint;
#else
using HWShaderType = ID3DVertexShader*;
#endif

static inline const char* GetShaderExt() { return ".vs"; }
static inline const char* GetCompilationTarget()
Expand Down Expand Up @@ -37,10 +42,12 @@ struct ShaderTypeTraits<SVS>
}
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* vs = 0;
#ifdef USE_DX11
HWShaderType vs = 0;
#ifdef USE_OGL
vs = glCreateShader(GL_VERTEX_SHADER);
#elif defined(USE_DX11)
R_CHK(HW.pDevice->CreateVertexShader(buffer, size, 0, &vs));
#elif defined(USE_DX10)
R_CHK(HW.pDevice->CreateVertexShader(buffer, size, &vs));
Expand All @@ -57,7 +64,12 @@ template <>
struct ShaderTypeTraits<SPS>
{
typedef CResourceManager::map_PS MapType;
typedef ID3DPixelShader DXIface;

#ifdef USE_OGL
using HWShaderType = GLuint;
#else
using HWShaderType = ID3DPixelShader*;
#endif

static inline const char* GetShaderExt() { return ".ps"; }
static inline const char* GetCompilationTarget()
Expand Down Expand Up @@ -94,10 +106,12 @@ struct ShaderTypeTraits<SPS>
}
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* ps = 0;
#ifdef USE_DX11
HWShaderType ps = 0;
#ifdef USE_OGL
ps = glCreateShader(GL_FRAGMENT_SHADER);
#elif defined(USE_DX11)
R_CHK(HW.pDevice->CreatePixelShader(buffer, size, 0, &ps));
#elif defined(USE_DX10)
R_CHK(HW.pDevice->CreatePixelShader(buffer, size, &ps));
Expand All @@ -110,18 +124,24 @@ struct ShaderTypeTraits<SPS>
static inline u32 GetShaderDest() { return RC_dest_pixel; }
};

#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
template <>
struct ShaderTypeTraits<SGS>
{
typedef CResourceManager::map_GS MapType;
typedef ID3DGeometryShader DXIface;

#ifdef USE_OGL
using HWShaderType = GLuint;
#else
using HWShaderType = ID3DGeometryShader*;
#endif


static inline const char* GetShaderExt() { return ".gs"; }
static inline const char* GetCompilationTarget()
{
#ifdef USE_DX10
if (HW.pDevice1 == 0)
if (HW.pDevice1 == nullptr)
return D3D10GetGeometryShaderProfile(HW.pDevice);
else
return "gs_4_1";
Expand All @@ -144,27 +164,34 @@ struct ShaderTypeTraits<SGS>
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* gs = 0;
#ifdef USE_DX11
HWShaderType gs = 0;
#ifdef USE_OGL
gs = glCreateShader(GL_GEOMETRY_SHADER);
#elif defined(USE_DX11)
R_CHK(HW.pDevice->CreateGeometryShader(buffer, size, 0, &gs));
#else
R_CHK(HW.pDevice->CreateGeometryShader(buffer, size, &gs));
#endif
#endif
return gs;
}

static inline u32 GetShaderDest() { return RC_dest_geometry; }
};
#endif

#ifdef USE_DX11
#if defined(USE_DX11) || defined(USE_OGL)
template <>
struct ShaderTypeTraits<SHS>
{
typedef CResourceManager::map_HS MapType;
typedef ID3D11HullShader DXIface;

#ifdef USE_OGL
using HWShaderType = GLuint;
#else
using HWShaderType = ID3D11HullShader*;
#endif

static inline const char* GetShaderExt() { return ".hs"; }
static inline const char* GetCompilationTarget() { return "hs_5_0"; }
Expand All @@ -175,10 +202,14 @@ struct ShaderTypeTraits<SHS>
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* hs = 0;
HWShaderType hs = 0;
#ifdef USE_OGL
hs = glCreateShader(GL_TESS_CONTROL_SHADER);
#else
R_CHK(HW.pDevice->CreateHullShader(buffer, size, NULL, &hs));
#endif
return hs;
}

Expand All @@ -189,7 +220,12 @@ template <>
struct ShaderTypeTraits<SDS>
{
typedef CResourceManager::map_DS MapType;
typedef ID3D11DomainShader DXIface;

#ifdef USE_OGL
using HWShaderType = GLuint;
#else
using HWShaderType = ID3D11DomainShader*;
#endif

static inline const char* GetShaderExt() { return ".ds"; }
static inline const char* GetCompilationTarget() { return "ds_5_0"; }
Expand All @@ -200,10 +236,14 @@ struct ShaderTypeTraits<SDS>
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* hs = 0;
HWShaderType hs = 0;
#ifdef USE_OGL
hs = glCreateShader(GL_TESS_EVALUATION_SHADER);
#else
R_CHK(HW.pDevice->CreateDomainShader(buffer, size, NULL, &hs));
#endif
return hs;
}

Expand All @@ -214,7 +254,12 @@ template <>
struct ShaderTypeTraits<SCS>
{
typedef CResourceManager::map_CS MapType;
typedef ID3D11ComputeShader DXIface;

#ifdef USE_OGL
using HWShaderType = GLuint;
#else
using HWShaderType = ID3D11ComputeShader*;
#endif

static inline const char* GetShaderExt() { return ".cs"; }
static inline const char* GetCompilationTarget() { return "cs_5_0"; }
Expand All @@ -225,10 +270,15 @@ struct ShaderTypeTraits<SCS>
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* cs = 0;
HWShaderType cs = 0;

#ifdef USE_OGL
cs = glCreateShader(GL_COMPUTE_SHADER);
#else
R_CHK(HW.pDevice->CreateComputeShader(buffer, size, NULL, &cs));
#endif
return cs;
}

Expand All @@ -248,15 +298,15 @@ inline CResourceManager::map_VS& CResourceManager::GetShaderMap()
return m_vs;
}

#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
template <>
inline CResourceManager::map_GS& CResourceManager::GetShaderMap()
{
return m_gs;
}
#endif

#if defined(USE_DX11)
#if defined(USE_DX11) || defined(USE_OGL)
template <>
inline CResourceManager::map_DS& CResourceManager::GetShaderMap()
{
Expand Down
51 changes: 13 additions & 38 deletions src/Layers/xrRenderPC_GL/glResourceManager_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "../xrRender/tss.h"
#include "../xrRender/blenders/blender.h"
#include "../xrRender/blenders/blender_recorder.h"

#include "../xrRenderGL/glBufferUtils.h"
#include "Layers/xrRender/ShaderResourceTraits.h"

void fix_texture_name(LPSTR fn);

Expand Down Expand Up @@ -242,19 +242,7 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
return _vs;
}

void CResourceManager::_DeleteVS(const SVS* vs)
{
if (0 == (vs->dwFlags & xr_resource_flagged::RF_REGISTERED)) return;
LPSTR N = LPSTR(*vs->cName);
map_VS::iterator I = m_vs.find(N);
if (I != m_vs.end())
{
m_vs.erase(I);
return;
}
Msg("! ERROR: Failed to find compiled vertex-shader '%s'", *vs->cName);
}

void CResourceManager::_DeleteVS(const SVS* vs) { DestroyShader(vs); }
//--------------------------------------------------------------------------------------------------------------
SPS* CResourceManager::_CreatePS(LPCSTR _name)
{
Expand Down Expand Up @@ -337,18 +325,7 @@ SPS* CResourceManager::_CreatePS(LPCSTR _name)
return _ps;
}

void CResourceManager::_DeletePS(const SPS* ps)
{
if (0 == (ps->dwFlags & xr_resource_flagged::RF_REGISTERED)) return;
LPSTR N = LPSTR(*ps->cName);
map_PS::iterator I = m_ps.find(N);
if (I != m_ps.end())
{
m_ps.erase(I);
return;
}
Msg("! ERROR: Failed to find compiled pixel-shader '%s'", *ps->cName);
}
void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }

//--------------------------------------------------------------------------------------------------------------
SGS* CResourceManager::_CreateGS(LPCSTR name)
Expand Down Expand Up @@ -418,18 +395,16 @@ SGS* CResourceManager::_CreateGS(LPCSTR name)
return _gs;
}

void CResourceManager::_DeleteGS(const SGS* gs)
{
if (0 == (gs->dwFlags & xr_resource_flagged::RF_REGISTERED)) return;
LPSTR N = LPSTR(*gs->cName);
map_GS::iterator I = m_gs.find(N);
if (I != m_gs.end())
{
m_gs.erase(I);
return;
}
Msg("! ERROR: Failed to find compiled geometry shader '%s'", *gs->cName);
}
void CResourceManager::_DeleteGS(const SGS* gs) { DestroyShader(gs); }

SHS* CResourceManager::_CreateHS(LPCSTR Name) { return CreateShader<SHS>(Name); }
void CResourceManager::_DeleteHS(const SHS* HS) { DestroyShader(HS); }

SDS* CResourceManager::_CreateDS(LPCSTR Name) { return CreateShader<SDS>(Name); }
void CResourceManager::_DeleteDS(const SDS* DS) { DestroyShader(DS); }

SCS* CResourceManager::_CreateCS(LPCSTR Name) { return CreateShader<SCS>(Name); }
void CResourceManager::_DeleteCS(const SCS* CS) { DestroyShader(CS); }

R_constant_table* CResourceManager::_CreateConstantTable(R_constant_table& C)
{
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_GL/rgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Layers/xrRender/LightTrack.h"
#include "Layers/xrRender/dxWallMarkArray.h"
#include "Layers/xrRender/dxUIShader.h"
#include "Layers/xrRender/ShaderResourceTraits.h"

CRender RImplementation;

Expand Down

0 comments on commit d21e34a

Please sign in to comment.