From 8193c668888747482428e93b197afa12a87deb4d Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 3 Sep 2024 23:09:35 -0700 Subject: [PATCH] Update CMake to specify FXC.EXE to use (#502) --- .github/workflows/test.yml | 38 +++++++++++++- .github/workflows/wsl.yml | 54 ++++++++++++++++++++ Auxiliary/DirectXTexPNG.cpp | 2 +- CMakeLists.txt | 31 ++++++----- DirectXTex/DirectXTexDDS.cpp | 4 +- DirectXTex/Shaders/CompileShaders.cmd | 11 ++++ build/CompilerAndLinker.cmake | 7 +++ build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml | 1 + build/DirectXTex-GitHub-Dev17.yml | 1 + build/DirectXTex-GitHub-GDK-Dev17.yml | 1 + build/DirectXTex-GitHub.yml | 1 + build/vcpkg.json | 8 +-- 12 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/wsl.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 330494e..93b5689 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,9 +91,45 @@ jobs: with: arch: ${{ matrix.arch }} + - name: 'Set triplet' + shell: pwsh + run: | + if ("${{ matrix.arch }}" -eq "amd64") + { + echo "VCPKG_DEFAULT_TRIPLET=x64-windows" >> $env:GITHUB_ENV + } + elseif ("${{ matrix.arch }}" -eq "amd64_x86") + { + echo "VCPKG_DEFAULT_TRIPLET=x86-windows" >> $env:GITHUB_ENV + } + elseif ("${{ matrix.arch }}" -eq "amd64_arm64") + { + if ("${{ matrix.build_type }}" -match "^arm64ec") + { + echo "VCPKG_DEFAULT_TRIPLET=arm64ec-windows" >> $env:GITHUB_ENV + } + else + { + echo "VCPKG_DEFAULT_TRIPLET=arm64-windows" >> $env:GITHUB_ENV + } + } + else + { + echo "::error Unknown architecture/build-type triplet mapping" + } + + - uses: lukka/run-vcpkg@v11 + with: + runVcpkgInstall: true + vcpkgJsonGlob: '**/build/vcpkg.json' + vcpkgGitCommitId: '7516a02de04e8f8ff4e4beb8f5bac0565f9bf9da' + - name: 'Configure CMake' working-directory: ${{ github.workspace }} - run: cmake --preset=${{ matrix.build_type }} -DBUILD_TESTING=ON -DBUILD_TOOLS=OFF -DBUILD_SAMPLE=OFF + run: > + cmake --preset=${{ matrix.build_type }} -DBUILD_TESTING=ON -DBUILD_TOOLS=OFF -DBUILD_SAMPLE=OFF -DENABLE_LIBJPEG_SUPPORT=ON -DENABLE_LIBPNG_SUPPORT=ON + -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR="${{ github.workspace }}/build" + -DVCPKG_TARGET_TRIPLET="${env:VCPKG_DEFAULT_TRIPLET}" - name: 'Build' working-directory: ${{ github.workspace }} diff --git a/.github/workflows/wsl.yml b/.github/workflows/wsl.yml new file mode 100644 index 0000000..e0107f0 --- /dev/null +++ b/.github/workflows/wsl.yml @@ -0,0 +1,54 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# +# http://go.microsoft.com/fwlink/?LinkId=248926 + +name: 'CMake (WSL)' + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + paths-ignore: + - '*.md' + - LICENSE + - '.nuget/*' + - build/*.cmd + - build/*.json + - build/*.props + - build/*.ps1 + - build/*.targets + - build/*.yml + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + + matrix: + build_type: [x64-Debug-Linux, x64-Release-Linux] + + steps: + - uses: actions/checkout@v4 + + - uses: seanmiddleditch/gha-setup-ninja@v5 + + - uses: lukka/run-vcpkg@v11 + with: + runVcpkgInstall: true + vcpkgJsonGlob: '**/build/vcpkg.json' + vcpkgGitCommitId: '7516a02de04e8f8ff4e4beb8f5bac0565f9bf9da' + + - name: 'Configure CMake' + working-directory: ${{ github.workspace }} + run: > + cmake --preset=${{ matrix.build_type }} -DENABLE_OPENEXR_SUPPORT=ON -DENABLE_LIBJPEG_SUPPORT=ON -DENABLE_LIBPNG_SUPPORT=ON + -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR="${{ github.workspace }}/build" + -DVCPKG_TARGET_TRIPLET="x64-linux" + + - name: 'Build' + working-directory: ${{ github.workspace }} + run: cmake --build out/build/${{ matrix.build_type }} diff --git a/Auxiliary/DirectXTexPNG.cpp b/Auxiliary/DirectXTexPNG.cpp index 9188b3e..bc76475 100644 --- a/Auxiliary/DirectXTexPNG.cpp +++ b/Auxiliary/DirectXTexPNG.cpp @@ -86,7 +86,7 @@ namespace void OnPNGRead(png_structp st, png_bytep ptr, size_t len) { FILE* fin = reinterpret_cast(png_get_io_ptr(st)); - fread(ptr, len, 1, fin); + std::ignore = fread(ptr, len, 1, fin); } diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f240c6..96eb3d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ if((DEFINED XBOX_CONSOLE_TARGET) AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango endif() include(GNUInstallDirs) +include(build/CompilerAndLinker.cmake) #--- Library set(LIBRARY_HEADERS @@ -142,16 +143,17 @@ elseif((BUILD_XBOX_EXTS_XBOXONE OR BUILD_XBOX_EXTS_SCARLETT) AND WIN32) Auxiliary/DirectXTexXboxTile.cpp) endif() -set(SHADER_SOURCES - DirectXTex/Shaders/BC6HEncode.hlsl - DirectXTex/Shaders/BC7Encode.hlsl) -if(BUILD_DX11 AND WIN32) - list(APPEND LIBRARY_SOURCES - DirectXTex/BCDirectCompute.h - DirectXTex/BCDirectCompute.cpp - DirectXTex/DirectXTexCompressGPU.cpp - DirectXTex/DirectXTexD3D11.cpp) +if(BUILD_DX11 AND WIN32 AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango"))) + set(SHADER_SOURCES + DirectXTex/Shaders/BC6HEncode.hlsl + DirectXTex/Shaders/BC7Encode.hlsl) + + list(APPEND LIBRARY_SOURCES + DirectXTex/BCDirectCompute.h + DirectXTex/BCDirectCompute.cpp + DirectXTex/DirectXTexCompressGPU.cpp + DirectXTex/DirectXTexD3D11.cpp) endif() if(BUILD_DX12) @@ -183,7 +185,7 @@ if(ENABLE_LIBPNG_SUPPORT) list(APPEND LIBRARY_SOURCES Auxiliary/DirectXTexPNG.cpp) endif() -if(BUILD_DX11 AND WIN32) +if(BUILD_DX11 AND WIN32 AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango"))) if(NOT COMPILED_SHADERS) if(USE_PREBUILT_SHADERS) message(FATAL_ERROR "ERROR: Using prebuilt shaders requires the COMPILED_SHADERS variable is set") @@ -197,12 +199,16 @@ if(BUILD_DX11 AND WIN32) list(APPEND LIBRARY_SOURCES ${COMPILED_SHADERS}/BC6HEncode_EncodeBlockCS.inc) if(NOT USE_PREBUILT_SHADERS) + find_program(DIRECTX_FXC_TOOL FXC.EXE + HINTS "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_SYSTEM_VERSION}/${DIRECTX_HOST_ARCH}" + "C:/Program Files (x86)/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/${DIRECTX_HOST_ARCH}") + message(STATUS "Using LegacyShaderCompiler found in ${DIRECTX_FXC_TOOL}") add_custom_command( OUTPUT "${COMPILED_SHADERS}/BC6HEncode_EncodeBlockCS.inc" MAIN_DEPENDENCY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders/CompileShaders.cmd" DEPENDS ${SHADER_SOURCES} COMMENT "Generating HLSL shaders..." - COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders.log" + COMMAND ${CMAKE_COMMAND} -E env CompileShadersOutput="${COMPILED_SHADERS}" $<$:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders.log" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders" USES_TERMINAL) endif() @@ -319,6 +325,7 @@ if(directx-headers_FOUND) message(STATUS "Using DirectX-Headers package") target_link_libraries(${PROJECT_NAME} PUBLIC Microsoft::DirectX-Headers) target_compile_definitions(${PROJECT_NAME} PUBLIC USING_DIRECTX_HEADERS) + target_compile_options(${PROJECT_NAME} PRIVATE $<$:/wd4062> $<$:-Wno-switch-enum>) endif() #--- Package @@ -520,8 +527,6 @@ if(MSVC) endif() endif() -include(build/CompilerAndLinker.cmake) - foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) target_compile_definitions(${t} PRIVATE ${COMPILER_DEFINES}) target_compile_options(${t} PRIVATE ${COMPILER_SWITCHES}) diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index de5deb0..91a1f9b 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -1369,8 +1369,8 @@ namespace int8_t v = ((((t >> 5) & 0x1f) ^ m) - m) + 16; int8_t u = (((t & 0x1f) ^ m) - m) + 16; - uint32_t t2 = u << 3 | u >> 2; - uint32_t t3 = v << 3 | v >> 2; + auto t2 = static_cast(u << 3 | u >> 2); + auto t3 = static_cast(v << 3 | v >> 2); *(dPtr++) = t1 | (t2 << 8) | (t3 << 16) | 0xff000000; } diff --git a/DirectXTex/Shaders/CompileShaders.cmd b/DirectXTex/Shaders/CompileShaders.cmd index 14a599b..4314406 100644 --- a/DirectXTex/Shaders/CompileShaders.cmd +++ b/DirectXTex/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 @@ -54,3 +61,7 @@ echo %fxc% echo %fxc4% %fxc4% || set error=1 exit /b + +:needfxc +echo ERROR: CompileShaders requires FXC.EXE +exit /b 1 diff --git a/build/CompilerAndLinker.cmake b/build/CompilerAndLinker.cmake index 1826feb..6fb5447 100644 --- a/build/CompilerAndLinker.cmake +++ b/build/CompilerAndLinker.cmake @@ -32,6 +32,13 @@ elseif(CMAKE_VS_PLATFORM_NAME_DEFAULT MATCHES "^[Aa][Rr][Mm]64EC$") set(DIRECTX_ARCH arm64ec) endif() +#--- Determines host architecture +if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "[Aa][Rr][Mm]64|aarch64|arm64") + set(DIRECTX_HOST_ARCH arm64) +else() + set(DIRECTX_HOST_ARCH x64) +endif() + #--- Build with Unicode Win32 APIs per "UTF-8 Everywhere" if(WIN32) list(APPEND COMPILER_DEFINES _UNICODE UNICODE) diff --git a/build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml b/build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml index 995f8bd..a1beda2 100644 --- a/build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml +++ b/build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml @@ -24,6 +24,7 @@ pr: - build/*.cmake - build/*.in - build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml + - DirectXTex/Shaders/CompileShaders.cmd resources: repositories: diff --git a/build/DirectXTex-GitHub-Dev17.yml b/build/DirectXTex-GitHub-Dev17.yml index 5a39c05..2660d8d 100644 --- a/build/DirectXTex-GitHub-Dev17.yml +++ b/build/DirectXTex-GitHub-Dev17.yml @@ -21,6 +21,7 @@ pr: paths: include: - build/DirectXTex-GitHub-Dev17.yml + - DirectXTex/Shaders/CompileShaders.cmd resources: repositories: diff --git a/build/DirectXTex-GitHub-GDK-Dev17.yml b/build/DirectXTex-GitHub-GDK-Dev17.yml index df93d41..ffd57a8 100644 --- a/build/DirectXTex-GitHub-GDK-Dev17.yml +++ b/build/DirectXTex-GitHub-GDK-Dev17.yml @@ -25,6 +25,7 @@ pr: - build/*.in - build/*.cmake - build/SetupBWOI.* + - DirectXTex/Shaders/CompileShaders.cmd resources: repositories: diff --git a/build/DirectXTex-GitHub.yml b/build/DirectXTex-GitHub.yml index 79f4f52..4aa756d 100644 --- a/build/DirectXTex-GitHub.yml +++ b/build/DirectXTex-GitHub.yml @@ -21,6 +21,7 @@ pr: paths: include: - build/DirectXTex-GitHub.yml + - DirectXTex/Shaders/CompileShaders.cmd resources: repositories: diff --git a/build/vcpkg.json b/build/vcpkg.json index 552566d..9892de6 100644 --- a/build/vcpkg.json +++ b/build/vcpkg.json @@ -3,9 +3,11 @@ "dependencies": [ "directxmath", "directx-headers", - "openexr", + { + "name": "openexr", + "platform": "linux | (windows & !arm64ec)" + }, "libpng", "libjpeg-turbo" ] - } - \ No newline at end of file +}