Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMake to specify FXC.EXE to use #502

Merged
merged 18 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/wsl.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion Auxiliary/DirectXTexPNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace
void OnPNGRead(png_structp st, png_bytep ptr, size_t len)
{
FILE* fin = reinterpret_cast<FILE*>(png_get_io_ptr(st));
fread(ptr, len, 1, fin);
std::ignore = fread(ptr, len, 1, fin);
}


Expand Down
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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}" $<$<BOOL:${DIRECTX_FXC_TOOL}>:LegacyShaderCompiler=${DIRECTX_FXC_TOOL}> CompileShaders.cmd > "${COMPILED_SHADERS}/compileshaders.log"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/DirectXTex/Shaders"
USES_TERMINAL)
endif()
Expand Down Expand Up @@ -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 $<$<CXX_COMPILER_ID:MSVC,Intel>:/wd4062> $<$<CXX_COMPILER_ID:Clang,IntelLLVM>:-Wno-switch-enum>)
endif()

#--- Package
Expand Down Expand Up @@ -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})
Expand Down
4 changes: 2 additions & 2 deletions DirectXTex/DirectXTexDDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(u << 3 | u >> 2);
auto t3 = static_cast<uint32_t>(v << 3 | v >> 2);

*(dPtr++) = t1 | (t2 << 8) | (t3 << 16) | 0xff000000;
}
Expand Down
11 changes: 11 additions & 0 deletions DirectXTex/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 Down Expand Up @@ -54,3 +61,7 @@ echo %fxc%
echo %fxc4%
%fxc4% || set error=1
exit /b

:needfxc
echo ERROR: CompileShaders requires FXC.EXE
exit /b 1
7 changes: 7 additions & 0 deletions build/CompilerAndLinker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pr:
- build/*.cmake
- build/*.in
- build/DirectXTex-GitHub-CMake-Xbox-Dev17.yml
- DirectXTex/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTex-GitHub-Dev17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pr:
paths:
include:
- build/DirectXTex-GitHub-Dev17.yml
- DirectXTex/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTex-GitHub-GDK-Dev17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pr:
- build/*.in
- build/*.cmake
- build/SetupBWOI.*
- DirectXTex/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down
1 change: 1 addition & 0 deletions build/DirectXTex-GitHub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pr:
paths:
include:
- build/DirectXTex-GitHub.yml
- DirectXTex/Shaders/CompileShaders.cmd

resources:
repositories:
Expand Down
8 changes: 5 additions & 3 deletions build/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"dependencies": [
"directxmath",
"directx-headers",
"openexr",
{
"name": "openexr",
"platform": "linux | (windows & !arm64ec)"
},
"libpng",
"libjpeg-turbo"
]
}

}
Loading