Skip to content

Commit

Permalink
Update DDSView hlsl.cmd to match recent changes to CompileShaders
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Sep 16, 2024
1 parent 3fb3c1e commit 62c47b0
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 36 deletions.
21 changes: 5 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,33 +483,22 @@ endif()
if(BUILD_SAMPLE AND BUILD_DX11 AND WIN32)
list(APPEND TOOL_EXES ddsview)

if(NOT COMPILED_DDSVIEW_SHADERS)
if(USE_PREBUILT_SHADERS)
message(FATAL_ERROR "ERROR: Using prebuilt shaders requires the COMPILED_DDSVIEW_SHADERS variable is set")
endif()
set(COMPILED_DDSVIEW_SHADERS ${CMAKE_CURRENT_BINARY_DIR}/Shaders/Compiled)
file(MAKE_DIRECTORY ${COMPILED_DDSVIEW_SHADERS})
else()
file(TO_CMAKE_PATH ${COMPILED_DDSVIEW_SHADERS} COMPILED_DDSVIEW_SHADERS)
endif()

add_executable(ddsview WIN32
DDSView/ddsview.cpp
DDSView/ddsview.rc
${COMPILED_DDSVIEW_SHADERS}/ddsview_ps1D.inc)
${COMPILED_SHADERS}/ddsview_ps1D.inc)
target_link_libraries(ddsview PRIVATE ${PROJECT_NAME} d3d11.lib ole32.lib)
source_group(ddsview REGULAR_EXPRESSION DDSView/*.*)

target_include_directories(ddsview PRIVATE ${COMPILED_DDSVIEW_SHADERS})
target_include_directories(ddsview PRIVATE ${COMPILED_SHADERS})

if(NOT USE_PREBUILT_SHADERS)
#TODO: DIRECTX_FXC_TOOL
add_custom_command(
OUTPUT "${COMPILED_DDSVIEW_SHADERS}/ddsview_ps1D.inc"
OUTPUT "${COMPILED_SHADERS}/ddsview_ps1D.inc"
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/DDSView/hlsl.cmd"
DEPENDS "${PROJECT_SOURCE_DIR}/DDSView/ddsview.fx"
DEPENDS "DDSView/ddsview.hlsl"
COMMENT "Generating HLSL shaders for DDSView..."
COMMAND COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_DDSVIEW_SHADERS}" hlsl.cmd > "${COMPILED_DDSVIEW_SHADERS}/hlsl.log"
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> hlsl.cmd > "${COMPILED_SHADERS}/hlsl_ddsview.log"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/DDSView"
USES_TERMINAL)
endif()
Expand Down
2 changes: 1 addition & 1 deletion Common/CmdLineHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,4 @@ namespace Helpers

return desc;
}
}
}
7 changes: 5 additions & 2 deletions DDSView/DDSView_Desktop_2019.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
<None Include="ddsview.hlsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
Expand All @@ -300,10 +300,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/ddsview_vs.inc')" WorkingDirectory="$(ProjectDir)" Command="hlsl" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" LogStandardErrorAsError="true" />
<Exec Condition="!Exists('Shaders/ddsview_vs.inc')" WorkingDirectory="$(ProjectDir)" Command="hlsl" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)\Shaders" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">
Expand Down
2 changes: 1 addition & 1 deletion DDSView/DDSView_Desktop_2019.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
<None Include="ddsview.hlsl" />
</ItemGroup>
</Project>
7 changes: 5 additions & 2 deletions DDSView/DDSView_Desktop_2022.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
<None Include="ddsview.hlsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
Expand All @@ -300,10 +300,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/ddsview_vs.inc')" WorkingDirectory="$(ProjectDir)" Command="hlsl" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath)" LogStandardErrorAsError="true" />
<Exec Condition="!Exists('Shaders/ddsview_vs.inc')" WorkingDirectory="$(ProjectDir)" Command="hlsl" EnvironmentVariables="WindowsSdkVerBinPath=$(_ATGFXCPath);WindowsSDKVersion=$(_ATGFXCVer);CompileShadersOutput=$(ProjectDir)\Shaders" LogStandardErrorAsError="true" />
<PropertyGroup>
<_ATGFXCPath />
<_ATGFXCVer />
</PropertyGroup>
</Target>
<Target Name="ATGDeleteShaders" AfterTargets="Clean">
Expand Down
2 changes: 1 addition & 1 deletion DDSView/DDSView_Desktop_2022.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="ddsview.fx" />
<None Include="ddsview.hlsl" />
</ItemGroup>
</Project>
File renamed without changes.
40 changes: 27 additions & 13 deletions DDSView/hlsl.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ rem Licensed under the MIT License.
setlocal
set error=0

if %PROCESSOR_ARCHITECTURE%.==ARM64. (set FXCARCH=arm64) else (if %PROCESSOR_ARCHITECTURE%.==AMD64. (set FXCARCH=x64) else (set FXCARCH=x86))

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

set PCFXC="%WindowsSdkVerBinPath%x86\fxc.exe"
if defined LegacyShaderCompiler goto fxcviaenv
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\x86\fxc.exe"
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
if exist %PCFXC% goto continue
set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\x86\fxc.exe"
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=Shaders
Expand All @@ -23,45 +32,50 @@ set StrTrim=%StrTrim: ##=%
set CompileShadersOutput=%StrTrim:##=%
@if not exist "%CompileShadersOutput%" mkdir "%CompileShadersOutput%"


set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EVS /Tvs_4_1 /Fh%CompileShadersOutput%\ddsview_vs.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EVS /Tvs_4_1 /Fh%CompileShadersOutput%\ddsview_vs.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EPS_1D /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps1D.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EPS_1D /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps1D.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EPS_1DArray /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps1Darray.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EPS_1DArray /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps1Darray.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EPS_2D /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps2D.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EPS_2D /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps2D.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EPS_2DArray /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps2Darray.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EPS_2DArray /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps2Darray.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EPS_3D /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps3D.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EPS_3D /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_ps3D.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

set FXC=%PCFXC% ddsview.fx %FXCOPTS% /EPS_Cube /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_psCube.inc
set FXC=%PCFXC% ddsview.hlsl %FXCOPTS% /EPS_Cube /Tps_4_1 /Fh%CompileShadersOutput%\ddsview_psCube.inc
echo %FXC%
%FXC%
@if ERRORLEVEL 1 goto error

@echo --- Shaders built ok ---
@goto end
endlocal
exit /b 0

:error
@echo --- ERROR: Shader build failed ---
exit /b 1
:end

:needfxc
echo ERROR: CompileShaders requires FXC.EXE
exit /b 1
:end
2 changes: 2 additions & 0 deletions Texassemble/texassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ namespace
{ nullptr, DXGI_FORMAT_UNKNOWN }
};

#undef DEFFMT

const SValue<DXGI_FORMAT> g_pFormatAliases[] =
{
{ L"RGBA", DXGI_FORMAT_R8G8B8A8_UNORM },
Expand Down
2 changes: 2 additions & 0 deletions Texconv/texconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ namespace
{ nullptr, DXGI_FORMAT_UNKNOWN }
};

#undef DEFFMT

const SValue<uint32_t> g_pFilters[] =
{
{ L"POINT", TEX_FILTER_POINT },
Expand Down
2 changes: 2 additions & 0 deletions Texdiag/texdiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ namespace
{ nullptr, DXGI_FORMAT_UNKNOWN }
};

#undef DEFFMT

const SValue<uint32_t> g_pFilters[] =
{
{ L"POINT", TEX_FILTER_POINT },
Expand Down

0 comments on commit 62c47b0

Please sign in to comment.