Skip to content

Commit

Permalink
Update for recent tool improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Sep 16, 2024
1 parent a0eba39 commit 1fb4a1a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 23 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,9 @@ if(BUILD_TOOLS AND BUILD_DX11 AND WIN32)
add_custom_command(
OUTPUT "${COMPILED_SHADERS}/Texenvmap_VSBasic.inc"
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/Texenvmap/Shaders/CompileShaders.cmd"
DEPENDS "${PROJECT_SOURCE_DIR}/Texenvmap/Shaders/Texenvmap.fx"
DEPENDS "Texenvmap/Shaders/Texenvmap.hlsl"
COMMENT "Generating HLSL shaders for texenvmap..."
COMMAND set CompileShadersOutput=${COMPILED_SHADERS}
COMMAND CompileShaders.cmd
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders_envmap.log"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/Texenvmap/Shaders"
USES_TERMINAL)
endif()
Expand Down
13 changes: 12 additions & 1 deletion Texenvmap/Shaders/CompileShaders.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if %PROCESSOR_ARCHITECTURE%.==ARM64. (set FXCARCH=arm64) else (if %PROCESSOR_ARC

set FXCOPTS=/nologo /WX /Ges /Zi /Zpc /Qstrip_reflect /Qstrip_debug

if defined LegacyShaderCompiler goto fxcviaenv
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
Expand All @@ -17,6 +18,12 @@ set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue

set PCFXC=fxc.exe
goto continue

:fxcviaenv
set PCFXC="%LegacyShaderCompiler%"
if not exist %PCFXC% goto needfxc
goto continue

:continue
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
Expand All @@ -42,8 +49,12 @@ endlocal
exit /b 0

:CompileShader
set fxc=%PCFXC% %1.fx %FXCOPTS% /T%2_4_0 /E%3 /Fh%CompileShadersOutput%\%1_%3.inc /Fd%CompileShadersOutput%\%1_%3.pdb /Vn%1_%3
set fxc=%PCFXC% "%1.hlsl" %FXCOPTS% /T%2_4_0 /E%3 "/Fh%CompileShadersOutput%\%1_%3.inc" "/Fd%CompileShadersOutput%\%1_%3.pdb" /Vn%1_%3
echo.
echo %fxc%
%fxc% || set error=1
exit /b

:needfxc
echo ERROR: CompileShaders requires FXC.EXE
exit /b 1
File renamed without changes.
7 changes: 5 additions & 2 deletions Texenvmap/Texenvmap_Desktop_2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" />
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Shaders/Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">
Expand All @@ -319,5 +322,5 @@
</ItemGroup>
<Delete Files="@(_ATGShaderHeaders)" />
<Delete Files="@(_ATGShaderSymbols)" />
</Target>
</Target>
</Project>
7 changes: 5 additions & 2 deletions Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" />
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Shaders/Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">
Expand All @@ -449,5 +452,5 @@
</ItemGroup>
<Delete Files="@(_ATGShaderHeaders)" />
<Delete Files="@(_ATGShaderSymbols)" />
</Target>
</Target>
</Project>
7 changes: 5 additions & 2 deletions Texenvmap/Texenvmap_Desktop_2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" />
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Shaders/Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">
Expand All @@ -319,5 +322,5 @@
</ItemGroup>
<Delete Files="@(_ATGShaderHeaders)" />
<Delete Files="@(_ATGShaderSymbols)" />
</Target>
</Target>
</Project>
7 changes: 5 additions & 2 deletions Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,13 @@
<_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0])</_ATGFXCPath>
<_ATGFXCPath>$(_ATGFXCPath.Replace("x64",""))</_ATGFXCPath>
<_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\</_ATGFXCPath>
<_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`))</_ATGFXCVer>
<_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\</_ATGFXCVer>
</PropertyGroup>
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" />
<Exec Condition="!Exists('Shaders/Compiled/Texenvmap_VSBasic.inc')" WorkingDirectory="$(ProjectDir)Shaders" Command="CompileShaders" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)Shaders/Compiled" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">
Expand All @@ -449,5 +452,5 @@
</ItemGroup>
<Delete Files="@(_ATGShaderHeaders)" />
<Delete Files="@(_ATGShaderSymbols)" />
</Target>
</Target>
</Project>
25 changes: 14 additions & 11 deletions Texenvmap/texenvmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@

#include "DirectXTex.h"

//Uncomment to add support for OpenEXR (.exr)
//#define USE_OPENEXR

#ifdef USE_OPENEXR
// See <https://github.com/Microsoft/DirectXTex/wiki/Adding-OpenEXR> for details
#include "DirectXTexEXR.h"
Expand Down Expand Up @@ -242,7 +239,6 @@ namespace
#ifdef USE_OPENEXR
#define CODEC_EXR 0xFFFF0006
#endif

#ifdef USE_LIBJPEG
#define CODEC_JPEG 0xFFFF0007
#endif
Expand Down Expand Up @@ -537,7 +533,7 @@ namespace
{
while (pValue->name)
{
size_t cchName = wcslen(pValue->name);
const size_t cchName = wcslen(pValue->name);

if (cch + cchName + 2 >= 80)
{
Expand Down Expand Up @@ -602,7 +598,7 @@ namespace

LPWSTR errorText = nullptr;

DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
const DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr, static_cast<DWORD>(hr),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);

Expand All @@ -613,14 +609,21 @@ namespace
swprintf_s(desc, L": %ls", errorText);

size_t len = wcslen(desc);
if (len >= 2)
if (len >= 1)
{
desc[len - 2] = 0;
desc[len - 1] = 0;
}

if (errorText)
LocalFree(errorText);

for (wchar_t* ptr = desc; *ptr != 0; ++ptr)
{
if (*ptr == L'\r' || *ptr == L'\n')
{
*ptr = L' ';
}
}
}

return desc;
Expand Down Expand Up @@ -1763,7 +1766,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
}
#endif

else
{
// WIC shares the same filter values for mode and dither
Expand Down Expand Up @@ -1961,7 +1964,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (info.width > maxWidth)
maxWidth = info.width;
if (info.height > maxHeight)
maxHeight = info.height;
maxHeight = info.height;
}

if (images > 6)
Expand Down Expand Up @@ -2024,7 +2027,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
pContext->RSSetState(stateObjects.CullNone());
auto linear = stateObjects.LinearClamp();

for (size_t face = 0; face < 6; ++face)
for (size_t face = 0; face < 6; ++face)
{
ComPtr<ID3D11ShaderResourceView> srv;
auto& input = loadedImages[face];
Expand Down

0 comments on commit 1fb4a1a

Please sign in to comment.