Skip to content

Commit 8193c66

Browse files
authored
Update CMake to specify FXC.EXE to use (#502)
1 parent 55b93ef commit 8193c66

12 files changed

+139
-20
lines changed

.github/workflows/test.yml

+37-1
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,45 @@ jobs:
9191
with:
9292
arch: ${{ matrix.arch }}
9393

94+
- name: 'Set triplet'
95+
shell: pwsh
96+
run: |
97+
if ("${{ matrix.arch }}" -eq "amd64")
98+
{
99+
echo "VCPKG_DEFAULT_TRIPLET=x64-windows" >> $env:GITHUB_ENV
100+
}
101+
elseif ("${{ matrix.arch }}" -eq "amd64_x86")
102+
{
103+
echo "VCPKG_DEFAULT_TRIPLET=x86-windows" >> $env:GITHUB_ENV
104+
}
105+
elseif ("${{ matrix.arch }}" -eq "amd64_arm64")
106+
{
107+
if ("${{ matrix.build_type }}" -match "^arm64ec")
108+
{
109+
echo "VCPKG_DEFAULT_TRIPLET=arm64ec-windows" >> $env:GITHUB_ENV
110+
}
111+
else
112+
{
113+
echo "VCPKG_DEFAULT_TRIPLET=arm64-windows" >> $env:GITHUB_ENV
114+
}
115+
}
116+
else
117+
{
118+
echo "::error Unknown architecture/build-type triplet mapping"
119+
}
120+
121+
- uses: lukka/run-vcpkg@v11
122+
with:
123+
runVcpkgInstall: true
124+
vcpkgJsonGlob: '**/build/vcpkg.json'
125+
vcpkgGitCommitId: '7516a02de04e8f8ff4e4beb8f5bac0565f9bf9da'
126+
94127
- name: 'Configure CMake'
95128
working-directory: ${{ github.workspace }}
96-
run: cmake --preset=${{ matrix.build_type }} -DBUILD_TESTING=ON -DBUILD_TOOLS=OFF -DBUILD_SAMPLE=OFF
129+
run: >
130+
cmake --preset=${{ matrix.build_type }} -DBUILD_TESTING=ON -DBUILD_TOOLS=OFF -DBUILD_SAMPLE=OFF -DENABLE_LIBJPEG_SUPPORT=ON -DENABLE_LIBPNG_SUPPORT=ON
131+
-DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR="${{ github.workspace }}/build"
132+
-DVCPKG_TARGET_TRIPLET="${env:VCPKG_DEFAULT_TRIPLET}"
97133
98134
- name: 'Build'
99135
working-directory: ${{ github.workspace }}

.github/workflows/wsl.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
#
4+
# http://go.microsoft.com/fwlink/?LinkId=248926
5+
6+
name: 'CMake (WSL)'
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
branches: [ "main" ]
13+
paths-ignore:
14+
- '*.md'
15+
- LICENSE
16+
- '.nuget/*'
17+
- build/*.cmd
18+
- build/*.json
19+
- build/*.props
20+
- build/*.ps1
21+
- build/*.targets
22+
- build/*.yml
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
fail-fast: false
30+
31+
matrix:
32+
build_type: [x64-Debug-Linux, x64-Release-Linux]
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- uses: seanmiddleditch/gha-setup-ninja@v5
38+
39+
- uses: lukka/run-vcpkg@v11
40+
with:
41+
runVcpkgInstall: true
42+
vcpkgJsonGlob: '**/build/vcpkg.json'
43+
vcpkgGitCommitId: '7516a02de04e8f8ff4e4beb8f5bac0565f9bf9da'
44+
45+
- name: 'Configure CMake'
46+
working-directory: ${{ github.workspace }}
47+
run: >
48+
cmake --preset=${{ matrix.build_type }} -DENABLE_OPENEXR_SUPPORT=ON -DENABLE_LIBJPEG_SUPPORT=ON -DENABLE_LIBPNG_SUPPORT=ON
49+
-DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR="${{ github.workspace }}/build"
50+
-DVCPKG_TARGET_TRIPLET="x64-linux"
51+
52+
- name: 'Build'
53+
working-directory: ${{ github.workspace }}
54+
run: cmake --build out/build/${{ matrix.build_type }}

Auxiliary/DirectXTexPNG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace
8686
void OnPNGRead(png_structp st, png_bytep ptr, size_t len)
8787
{
8888
FILE* fin = reinterpret_cast<FILE*>(png_get_io_ptr(st));
89-
fread(ptr, len, 1, fin);
89+
std::ignore = fread(ptr, len, 1, fin);
9090
}
9191

9292

CMakeLists.txt

+18-13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ if((DEFINED XBOX_CONSOLE_TARGET) AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango
7373
endif()
7474

7575
include(GNUInstallDirs)
76+
include(build/CompilerAndLinker.cmake)
7677

7778
#--- Library
7879
set(LIBRARY_HEADERS
@@ -142,16 +143,17 @@ elseif((BUILD_XBOX_EXTS_XBOXONE OR BUILD_XBOX_EXTS_SCARLETT) AND WIN32)
142143
Auxiliary/DirectXTexXboxTile.cpp)
143144
endif()
144145

145-
set(SHADER_SOURCES
146-
DirectXTex/Shaders/BC6HEncode.hlsl
147-
DirectXTex/Shaders/BC7Encode.hlsl)
148146

149-
if(BUILD_DX11 AND WIN32)
150-
list(APPEND LIBRARY_SOURCES
151-
DirectXTex/BCDirectCompute.h
152-
DirectXTex/BCDirectCompute.cpp
153-
DirectXTex/DirectXTexCompressGPU.cpp
154-
DirectXTex/DirectXTexD3D11.cpp)
147+
if(BUILD_DX11 AND WIN32 AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango")))
148+
set(SHADER_SOURCES
149+
DirectXTex/Shaders/BC6HEncode.hlsl
150+
DirectXTex/Shaders/BC7Encode.hlsl)
151+
152+
list(APPEND LIBRARY_SOURCES
153+
DirectXTex/BCDirectCompute.h
154+
DirectXTex/BCDirectCompute.cpp
155+
DirectXTex/DirectXTexCompressGPU.cpp
156+
DirectXTex/DirectXTexD3D11.cpp)
155157
endif()
156158

157159
if(BUILD_DX12)
@@ -183,7 +185,7 @@ if(ENABLE_LIBPNG_SUPPORT)
183185
list(APPEND LIBRARY_SOURCES Auxiliary/DirectXTexPNG.cpp)
184186
endif()
185187

186-
if(BUILD_DX11 AND WIN32)
188+
if(BUILD_DX11 AND WIN32 AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango")))
187189
if(NOT COMPILED_SHADERS)
188190
if(USE_PREBUILT_SHADERS)
189191
message(FATAL_ERROR "ERROR: Using prebuilt shaders requires the COMPILED_SHADERS variable is set")
@@ -197,12 +199,16 @@ if(BUILD_DX11 AND WIN32)
197199
list(APPEND LIBRARY_SOURCES ${COMPILED_SHADERS}/BC6HEncode_EncodeBlockCS.inc)
198200

199201
if(NOT USE_PREBUILT_SHADERS)
202+
find_program(DIRECTX_FXC_TOOL FXC.EXE
203+
HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}"
204+
"C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}")
205+
message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}")
200206
add_custom_command(
201207
OUTPUT "${COMPILED_SHADERS}/BC6HEncode_EncodeBlockCS.inc"
202208
MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders/CompileShaders.cmd"
203209
DEPENDS ${SHADER_SOURCES}
204210
COMMENT "Generating HLSL shaders..."
205-
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders.log"
211+
COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders.log"
206212
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders"
207213
USES_TERMINAL)
208214
endif()
@@ -319,6 +325,7 @@ if(directx-headers_FOUND)
319325
message(STATUS "Using DirectX-Headers package")
320326
target_link_libraries(${PROJECT_NAME} PUBLIC Microsoft::DirectX-Headers)
321327
target_compile_definitions(${PROJECT_NAME} PUBLIC USING_DIRECTX_HEADERS)
328+
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC,Intel>:/wd4062> $<$<CXX_COMPILER_ID:Clang,IntelLLVM>:-Wno-switch-enum>)
322329
endif()
323330

324331
#--- Package
@@ -520,8 +527,6 @@ if(MSVC)
520527
endif()
521528
endif()
522529

523-
include(build/CompilerAndLinker.cmake)
524-
525530
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
526531
target_compile_definitions(${t} PRIVATE ${COMPILER_DEFINES})
527532
target_compile_options(${t} PRIVATE ${COMPILER_SWITCHES})

DirectXTex/DirectXTexDDS.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,8 @@ namespace
13691369
int8_t v = ((((t >> 5) & 0x1f) ^ m) - m) + 16;
13701370
int8_t u = (((t & 0x1f) ^ m) - m) + 16;
13711371

1372-
uint32_t t2 = u << 3 | u >> 2;
1373-
uint32_t t3 = v << 3 | v >> 2;
1372+
auto t2 = static_cast<uint32_t>(u << 3 | u >> 2);
1373+
auto t3 = static_cast<uint32_t>(v << 3 | v >> 2);
13741374

13751375
*(dPtr++) = t1 | (t2 << 8) | (t3 << 16) | 0xff000000;
13761376
}

DirectXTex/Shaders/CompileShaders.cmd

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if %PROCESSOR_ARCHITECTURE%.==ARM64. (set FXCARCH=arm64) else (if %PROCESSOR_ARC
99

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

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

1920
set PCFXC=fxc.exe
21+
goto continue
22+
23+
:fxcviaenv
24+
set PCFXC="%LegacyShaderCompiler%"
25+
if not exist %PCFXC% goto needfxc
26+
goto continue
2027

2128
:continue
2229
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
@@ -54,3 +61,7 @@ echo %fxc%
5461
echo %fxc4%
5562
%fxc4% || set error=1
5663
exit /b
64+
65+
:needfxc
66+
echo ERROR: CompileShaders requires FXC.EXE
67+
exit /b 1

build/CompilerAndLinker.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64EC$")
3232
set(DIRECTX_ARCH arm64ec)
3333
endif()
3434

35+
#--- Determines host architecture
36+
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "[Aa][Rr][Mm]64|aarch64|arm64")
37+
set(DIRECTX_HOST_ARCH arm64)
38+
else()
39+
set(DIRECTX_HOST_ARCH x64)
40+
endif()
41+
3542
#--- Build with Unicode Win32 APIs per "UTF-8 Everywhere"
3643
if(WIN32)
3744
list(APPEND COMPILER_DEFINES _UNICODE UNICODE)

build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pr:
2424
- build/*.cmake
2525
- build/*.in
2626
- build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml
27+
- DirectXTex/Shaders/CompileShaders.cmd
2728

2829
resources:
2930
repositories:

build/DirectXTex-GitHub-Dev17.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pr:
2121
paths:
2222
include:
2323
- build/DirectXTex-GitHub-Dev17.yml
24+
- DirectXTex/Shaders/CompileShaders.cmd
2425

2526
resources:
2627
repositories:

build/DirectXTex-GitHub-GDK-Dev17.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pr:
2525
- build/*.in
2626
- build/*.cmake
2727
- build/SetupBWOI.*
28+
- DirectXTex/Shaders/CompileShaders.cmd
2829

2930
resources:
3031
repositories:

build/DirectXTex-GitHub.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pr:
2121
paths:
2222
include:
2323
- build/DirectXTex-GitHub.yml
24+
- DirectXTex/Shaders/CompileShaders.cmd
2425

2526
resources:
2627
repositories:

build/vcpkg.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"dependencies": [
44
"directxmath",
55
"directx-headers",
6-
"openexr",
6+
{
7+
"name": "openexr",
8+
"platform": "linux | (windows & !arm64ec)"
9+
},
710
"libpng",
811
"libjpeg-turbo"
912
]
10-
}
11-
13+
}

0 commit comments

Comments
 (0)