Skip to content

Commit

Permalink
This should finally fix build in all cases
Browse files Browse the repository at this point in the history
(place your bets, ladies and gentlemen)
  • Loading branch information
Xottab-DUTY committed Oct 23, 2023
1 parent e9ec3d3 commit a9faefe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
4 changes: 2 additions & 2 deletions sdk/include/DirectXMesh/FlexibleVertexFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#endif

#if !__has_include(<sal.h>)
#define _In_reads_()
#define _Success_()
#define _In_reads_(size)
#define _Success_(expr)
#endif

#include <cstdint>
Expand Down
61 changes: 36 additions & 25 deletions src/Layers/xrRenderDX9/dx9shader_utils.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
#pragma once

#ifdef USE_D3DX
using ID3DBlob = ID3DXBuffer;
using ID3DInclude = ID3DXInclude;
using D3D_SHADER_MACRO = D3DXMACRO;
using D3D_INCLUDE_TYPE = D3DXINCLUDE_TYPE;
// When building with Unity build, d3dx9.h and d3dcompiler.h both get included in files
// So we cannot just declare:
// using D3D_SHADER_MACRO = D3DXMACRO;
// because it would conflict.
// I could exclude some files from Unity build, but why?
// Let's just make it robustly compileable in all cases.
using IShaderBlob = ID3DXBuffer;
using IShaderIncluder = ID3DXInclude;
using SHADER_MACRO = D3DXMACRO;
using INCLUDE_TYPE = D3DXINCLUDE_TYPE;
#else
// Errors
#define _FACDD 0x876
#define MAKE_DDHRESULT(code) MAKE_HRESULT(1, _FACDD, code)

enum _D3DXERR
{
D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900),
D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901),
D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902),
D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903),
D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904),
D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905),
D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906),
D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907),
D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908),
};
using IShaderBlob = ID3DBlob;
using IShaderIncluder = ID3DInclude;
using SHADER_MACRO = D3D_SHADER_MACRO;
using INCLUDE_TYPE = D3D_INCLUDE_TYPE;

typedef struct _D3DXSHADER_CONSTANTTABLE
{
Expand Down Expand Up @@ -113,13 +107,30 @@ typedef enum D3DXPARAMETER_TYPE
D3DXPT_UNSUPPORTED,
D3DXPT_FORCE_DWORD = 0x7fffffff
} D3DXPARAMETER_TYPE, * LPD3DXPARAMETER_TYPE;

// Errors
#define _FACDD 0x876
#define MAKE_DDHRESULT(code) MAKE_HRESULT(1, _FACDD, code)

enum _D3DXERR
{
D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900),
D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901),
D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902),
D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903),
D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904),
D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905),
D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906),
D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907),
D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908),
};
#endif

class ShaderIncluder final : public ID3DInclude
class ShaderIncluder final : public IShaderIncluder
{
public:
HRESULT __stdcall Open(
D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) noexcept override
INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) noexcept override
{
string_path pname;
strconcat(sizeof(pname), pname, GEnv.Render->getShaderPath(), pFileName);
Expand Down Expand Up @@ -205,7 +216,7 @@ inline HRESULT WINAPI FindShaderComment(const DWORD* byte_code, DWORD fourcc, co
}

inline HRESULT WINAPI DisassembleShader(CONST DWORD* pShader, SIZE_T SrcDataSize,
BOOL EnableColorCode, LPCSTR pComments, ID3DBlob** ppDisassembly)
BOOL EnableColorCode, LPCSTR pComments, IShaderBlob** ppDisassembly)
{
#ifdef USE_D3DX
std::ignore = SrcDataSize;
Expand All @@ -216,9 +227,9 @@ inline HRESULT WINAPI DisassembleShader(CONST DWORD* pShader, SIZE_T SrcDataSize
}

inline HRESULT WINAPI CompileShader(LPCVOID pSrcData, SIZE_T SrcDataSize,
CONST D3D_SHADER_MACRO* pDefines, ID3DInclude* pInclude,
CONST SHADER_MACRO* pDefines, IShaderIncluder* pInclude,
LPCSTR pEntrypoint, LPCSTR pTarget, DWORD Flags,
ID3DBlob** ppCode, ID3DBlob** ppErrorMsgs)
IShaderBlob** ppCode, IShaderBlob** ppErrorMsgs)
{
#ifdef USE_D3DX
return D3DXCompileShader((LPCSTR)pSrcData, SrcDataSize, pDefines, pInclude,
Expand Down
8 changes: 4 additions & 4 deletions src/Layers/xrRenderPC_R1/FStaticRender_Shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons

if (disasm)
{
ID3DBlob* blob = nullptr;
IShaderBlob* blob = nullptr;
DisassembleShader(buffer, buffer_size, FALSE, nullptr, &blob);
if (!blob)
return _hr;
Expand Down Expand Up @@ -61,7 +61,7 @@ inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons

HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName, pcstr pTarget, u32 Flags, void*& result)
{
D3D_SHADER_MACRO defines[128];
SHADER_MACRO defines[128];
int def_it = 0;

char sh_name[MAX_PATH] = "";
Expand Down Expand Up @@ -200,8 +200,8 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName, pc
if (FAILED(_result))
{
ShaderIncluder includer;
ID3DBlob* pShaderBuf = nullptr;
ID3DBlob* pErrorBuf = nullptr;
IShaderBlob* pShaderBuf = nullptr;
IShaderBlob* pErrorBuf = nullptr;

_result = CompileShader(fs->pointer(), fs->length(), defines, &includer,
pFunctionName, pTarget, Flags, &pShaderBuf, &pErrorBuf);
Expand Down
8 changes: 4 additions & 4 deletions src/Layers/xrRenderPC_R2/r2_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons

if (disasm)
{
ID3DBlob* blob = nullptr;
IShaderBlob* blob = nullptr;
DisassembleShader(buffer, buffer_size, FALSE, nullptr, &blob);
if (!blob)
return _hr;
Expand Down Expand Up @@ -62,7 +62,7 @@ inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
HRESULT CRender::shader_compile(
pcstr name, IReader* fs, pcstr pFunctionName, pcstr pTarget, u32 Flags, void*& result)
{
D3D_SHADER_MACRO defines[128];
SHADER_MACRO defines[128];
int def_it = 0;

// Don't move these variables to lower scope!
Expand Down Expand Up @@ -466,8 +466,8 @@ HRESULT CRender::shader_compile(
if (FAILED(_result))
{
ShaderIncluder includer;
ID3DBlob* pShaderBuf = nullptr;
ID3DBlob* pErrorBuf = nullptr;
IShaderBlob* pShaderBuf = nullptr;
IShaderBlob* pErrorBuf = nullptr;

_result = CompileShader(fs->pointer(), fs->length(), defines, &includer,
pFunctionName, pTarget, Flags, &pShaderBuf, &pErrorBuf);
Expand Down

0 comments on commit a9faefe

Please sign in to comment.