Skip to content

Commit

Permalink
xrRender/ShaderResourceTraits: allow searching shader entry point in …
Browse files Browse the repository at this point in the history
…the shader file
  • Loading branch information
Xottab-DUTY committed May 28, 2018
1 parent 4cfc50d commit d4548cd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Layers/xrRender/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class ECORE_API CResourceManager
T& GetShaderMap();

template <typename T>
T* CreateShader(const char* name);
T* CreateShader(const char* name, const bool searchForEntryAndTarget = false);

template <typename T>
void DestroyShader(const T* sh);
Expand Down
43 changes: 39 additions & 4 deletions src/Layers/xrRender/ShaderResourceTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ struct ShaderTypeTraits<SGS>
NODEFAULT;
return "gs_4_0";
}

static void GetCompilationTarget(const char*& target, const char*& entry, const char* /*data*/)
{
target = GetCompilationTarget();
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* gs = 0;
Expand All @@ -58,6 +65,13 @@ struct ShaderTypeTraits<SHS>

static inline const char* GetShaderExt() { return ".hs"; }
static inline const char* GetCompilationTarget() { return "hs_5_0"; }

static void GetCompilationTarget(const char*& target, const char*& entry, const char* /*data*/)
{
target = GetCompilationTarget();
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* hs = 0;
Expand All @@ -76,6 +90,13 @@ struct ShaderTypeTraits<SDS>

static inline const char* GetShaderExt() { return ".ds"; }
static inline const char* GetCompilationTarget() { return "ds_5_0"; }

static void GetCompilationTarget(const char*& target, const char*& entry, const char* /*data*/)
{
target = GetCompilationTarget();
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* hs = 0;
Expand All @@ -94,6 +115,13 @@ struct ShaderTypeTraits<SCS>

static inline const char* GetShaderExt() { return ".cs"; }
static inline const char* GetCompilationTarget() { return "cs_5_0"; }

static void GetCompilationTarget(const char*& target, const char*& entry, const char* /*data*/)
{
target = GetCompilationTarget();
entry = "main";
}

static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
{
DXIface* cs = 0;
Expand Down Expand Up @@ -134,7 +162,7 @@ inline CResourceManager::map_CS& CResourceManager::GetShaderMap()
#endif

template <typename T>
inline T* CResourceManager::CreateShader(const char* name)
inline T* CResourceManager::CreateShader(const char* name, const bool searchForEntryAndTarget /*= false*/)
{
ShaderTypeTraits<T>::MapType& sh_map = GetShaderMap<ShaderTypeTraits<T>::MapType>();
LPSTR N = LPSTR(name);
Expand Down Expand Up @@ -180,16 +208,23 @@ inline T* CResourceManager::CreateShader(const char* name)
}
R_ASSERT2(file, cname);

const auto size = file->length();
char* const data = (LPSTR)_alloca(size + 1);
CopyMemory(data, file->pointer(), size);
data[size] = 0;
FS.r_close(file);

// Select target
LPCSTR c_target = ShaderTypeTraits<T>::GetCompilationTarget();
LPCSTR c_entry = "main";

if (searchForEntryAndTarget)
ShaderTypeTraits<T>::GetCompilationTarget(c_target, c_entry, data);

// Compile
HRESULT const _hr = GEnv.Render->shader_compile(name, (DWORD const*)file->pointer(), file->length(),
HRESULT const _hr = GEnv.Render->shader_compile(name, (DWORD const*)data, size,
c_entry, c_target, D3D10_SHADER_PACK_MATRIX_ROW_MAJOR, (void*&)sh);

FS.r_close(file);

VERIFY(SUCCEEDED(_hr));

CHECK_OR_EXIT(!FAILED(_hr), "Your video card doesn't meet game requirements.\n\nTry to lower game settings.");
Expand Down

0 comments on commit d4548cd

Please sign in to comment.