From 1fb4a1aabc3c7dcc4fe836374214219a4c7c3aaa Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Mon, 16 Sep 2024 14:07:57 -0700 Subject: [PATCH] Update for recent tool improvements --- CMakeLists.txt | 5 ++-- Texenvmap/Shaders/CompileShaders.cmd | 13 +++++++++- .../Shaders/{Texenvmap.fx => Texenvmap.hlsl} | 0 Texenvmap/Texenvmap_Desktop_2019.vcxproj | 7 ++++-- .../Texenvmap_Desktop_2019_Win10.vcxproj | 7 ++++-- Texenvmap/Texenvmap_Desktop_2022.vcxproj | 7 ++++-- .../Texenvmap_Desktop_2022_Win10.vcxproj | 7 ++++-- Texenvmap/texenvmap.cpp | 25 +++++++++++-------- 8 files changed, 48 insertions(+), 23 deletions(-) rename Texenvmap/Shaders/{Texenvmap.fx => Texenvmap.hlsl} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67342b9b..722fc378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}" $<$:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders_envmap.log" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/Texenvmap/Shaders" USES_TERMINAL) endif() diff --git a/Texenvmap/Shaders/CompileShaders.cmd b/Texenvmap/Shaders/CompileShaders.cmd index 0fe9f983..373b84cb 100644 --- a/Texenvmap/Shaders/CompileShaders.cmd +++ b/Texenvmap/Shaders/CompileShaders.cmd @@ -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" @@ -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 @@ -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 diff --git a/Texenvmap/Shaders/Texenvmap.fx b/Texenvmap/Shaders/Texenvmap.hlsl similarity index 100% rename from Texenvmap/Shaders/Texenvmap.fx rename to Texenvmap/Shaders/Texenvmap.hlsl diff --git a/Texenvmap/Texenvmap_Desktop_2019.vcxproj b/Texenvmap/Texenvmap_Desktop_2019.vcxproj index 3b77960f..072d45bf 100644 --- a/Texenvmap/Texenvmap_Desktop_2019.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2019.vcxproj @@ -306,10 +306,13 @@ <_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0]) <_ATGFXCPath>$(_ATGFXCPath.Replace("x64","")) <_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\ + <_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`)) + <_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\ - + <_ATGFXCPath /> + <_ATGFXCVer /> @@ -319,5 +322,5 @@ - + \ No newline at end of file diff --git a/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj b/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj index 8def2554..bb037b1f 100644 --- a/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2019_Win10.vcxproj @@ -436,10 +436,13 @@ <_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0]) <_ATGFXCPath>$(_ATGFXCPath.Replace("x64","")) <_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\ + <_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`)) + <_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\ - + <_ATGFXCPath /> + <_ATGFXCVer /> @@ -449,5 +452,5 @@ - + \ No newline at end of file diff --git a/Texenvmap/Texenvmap_Desktop_2022.vcxproj b/Texenvmap/Texenvmap_Desktop_2022.vcxproj index 2f86903a..b9fecf77 100644 --- a/Texenvmap/Texenvmap_Desktop_2022.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2022.vcxproj @@ -306,10 +306,13 @@ <_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0]) <_ATGFXCPath>$(_ATGFXCPath.Replace("x64","")) <_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\ + <_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`)) + <_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\ - + <_ATGFXCPath /> + <_ATGFXCVer /> @@ -319,5 +322,5 @@ - + \ No newline at end of file diff --git a/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj b/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj index e28f6a84..1b938a36 100644 --- a/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj +++ b/Texenvmap/Texenvmap_Desktop_2022_Win10.vcxproj @@ -436,10 +436,13 @@ <_ATGFXCPath>$(WindowsSDK_ExecutablePath_x64.Split(';')[0]) <_ATGFXCPath>$(_ATGFXCPath.Replace("x64","")) <_ATGFXCPath Condition="'$(_ATGFXCPath)' != '' and !HasTrailingSlash('$(_ATGFXCPath)')">$(_ATGFXCPath)\ + <_ATGFXCVer>$([System.Text.RegularExpressions.Regex]::Match($(_ATGFXCPath), `10\.0\.\d+\.0`)) + <_ATGFXCVer Condition="'$(_ATGFXCVer)' != '' and !HasTrailingSlash('$(_ATGFXCVer)')">$(_ATGFXCVer)\ - + <_ATGFXCPath /> + <_ATGFXCVer /> @@ -449,5 +452,5 @@ - + \ No newline at end of file diff --git a/Texenvmap/texenvmap.cpp b/Texenvmap/texenvmap.cpp index 46d2d5c9..7428166a 100644 --- a/Texenvmap/texenvmap.cpp +++ b/Texenvmap/texenvmap.cpp @@ -64,9 +64,6 @@ #include "DirectXTex.h" -//Uncomment to add support for OpenEXR (.exr) -//#define USE_OPENEXR - #ifdef USE_OPENEXR // See for details #include "DirectXTexEXR.h" @@ -242,7 +239,6 @@ namespace #ifdef USE_OPENEXR #define CODEC_EXR 0xFFFF0006 #endif - #ifdef USE_LIBJPEG #define CODEC_JPEG 0xFFFF0007 #endif @@ -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) { @@ -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(hr), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&errorText), 0, nullptr); @@ -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; @@ -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 @@ -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) @@ -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 srv; auto& input = loadedImages[face];