diff --git a/sdk/include/DirectXMesh/FlexibleVertexFormat.h b/sdk/include/DirectXMesh/FlexibleVertexFormat.h index 14d8779bbf3..6a9b8eebb10 100644 --- a/sdk/include/DirectXMesh/FlexibleVertexFormat.h +++ b/sdk/include/DirectXMesh/FlexibleVertexFormat.h @@ -16,8 +16,8 @@ #endif #if !__has_include() -#define _In_reads_() -#define _Success_() +#define _In_reads_(size) +#define _Success_(expr) #endif #include diff --git a/src/Layers/xrRenderDX9/dx9shader_utils.h b/src/Layers/xrRenderDX9/dx9shader_utils.h index aa74660160c..384ebeeffcd 100644 --- a/src/Layers/xrRenderDX9/dx9shader_utils.h +++ b/src/Layers/xrRenderDX9/dx9shader_utils.h @@ -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 { @@ -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); @@ -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; @@ -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, diff --git a/src/Layers/xrRenderPC_R1/FStaticRender_Shaders.cpp b/src/Layers/xrRenderPC_R1/FStaticRender_Shaders.cpp index ef0cd0e4da9..0230963c5d1 100644 --- a/src/Layers/xrRenderPC_R1/FStaticRender_Shaders.cpp +++ b/src/Layers/xrRenderPC_R1/FStaticRender_Shaders.cpp @@ -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; @@ -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] = ""; @@ -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); diff --git a/src/Layers/xrRenderPC_R2/r2_shaders.cpp b/src/Layers/xrRenderPC_R2/r2_shaders.cpp index 0a3832b33c2..b0ac98feb71 100644 --- a/src/Layers/xrRenderPC_R2/r2_shaders.cpp +++ b/src/Layers/xrRenderPC_R2/r2_shaders.cpp @@ -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; @@ -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! @@ -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);