From d6ec5b61d75661edf12bf80adc08856644ea93cd Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 2 May 2025 21:14:28 -0700 Subject: [PATCH 1/8] Steps towards making using nuget warp the default - remove special cases for warp - move the generic sounding "nuget.cmake" closer to where it is used, and rename to DownloadWarp.cmake - rearrange clang/test/CMakeLists.txt to make logic clearer about what is / isn't executed when using a multi-config generator --- azure-pipelines.yml | 4 +- tools/clang/test/CMakeLists.txt | 82 +++++++++---------- .../clang/test/taef_exec/DownloadWarp.cmake | 0 utils/hct/hcttest.cmd | 17 ---- 4 files changed, 42 insertions(+), 61 deletions(-) rename cmake/modules/Nuget.cmake => tools/clang/test/taef_exec/DownloadWarp.cmake (100%) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7967fa03e3..9146b4e1db 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -44,8 +44,8 @@ stages: displayName: 'DXIL Tests' - script: | call utils\hct\hctstart.cmd %HLSL_SRC_DIR% %HLSL_BLD_DIR% - call utils\hct\hcttest.cmd -$(configuration) exec-warp - displayName: 'DXIL Execution Tests (Nuget WARP)' + call utils\hct\hcttest.cmd -$(configuration) exec + displayName: 'DXIL Execution Tests' - job: Nix timeoutInMinutes: 120 diff --git a/tools/clang/test/CMakeLists.txt b/tools/clang/test/CMakeLists.txt index 6b0aa32fbc..7b141f4c27 100644 --- a/tools/clang/test/CMakeLists.txt +++ b/tools/clang/test/CMakeLists.txt @@ -122,54 +122,52 @@ add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR} FOLDER "Clang tests/Suites" ) -# Manually generate targets that we need to expose in visual studio builds. - -# The code below here _ONLY_ executes when building with Visual Studio or Xcode. -if (NOT CMAKE_CONFIGURATION_TYPES) - return() +# Use a custom target so we can depend on it and re-run the cmake logic which downloads warp +# from nuget if requested. +add_custom_target(WarpFromNuget + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} + -DBUILD_TYPE=${CMAKE_BUILD_TYPE} + -DBINARY_DIR=${CMAKE_BINARY_DIR} + -P "${CMAKE_CURRENT_SOURCE_DIR}/taef_exec/DownloadWarp.cmake") + +if(NOT CMAKE_CONFIGURATION_TYPES) + add_dependencies(check-clang-taef_exec WarpFromNuget) endif() -# Add the unit test suite -add_lit_target("check-clang-unit" "Running lit suite clang-unit" - ${CMAKE_CURRENT_SOURCE_DIR}/Unit - PARAMS ${CLANG_TEST_PARAMS} - DEPENDS ClangUnitTests - ARGS ${CLANG_TEST_EXTRA_ARGS} - ) +# add_lit_testsuites doesn't generate targets for Visual Studio or Xcode builds +# (since these IDEs cannot handle the huge number of targets it generates). +# +# We must manually generate targets that we want to expose in visual studio +# builds. +if(CMAKE_CONFIGURATION_TYPES) -# Add TAEF targets -if (WIN32) - add_lit_target("check-clang-taef" "Running lit suite hlsl" - ${CMAKE_CURRENT_SOURCE_DIR}/taef - PARAMS ${CLANG_TEST_PARAMS} - DEPENDS ClangHLSLTests - ARGS ${CLANG_TEST_EXTRA_ARGS} - ) - set(TAEF_EXEC_ADAPTER "" CACHE STRING "adapter for taef exec test") - - # Use a custom target so we can depend on it and re-run the cmake logic which downloads warp - # from nuget if requested. - add_custom_target(WarpFromNuget - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} - -DBUILD_TYPE=${CMAKE_BUILD_TYPE} - -DBINARY_DIR=${CMAKE_BINARY_DIR} - -P "${CMAKE_SOURCE_DIR}/cmake/modules/nuget.cmake") - - add_lit_target("check-clang-taef-exec" "Running lit suite hlsl execution test" - ${CMAKE_CURRENT_SOURCE_DIR}/taef_exec + # Add the unit test suite + add_lit_target("check-clang-unit" "Running lit suite clang-unit" + ${CMAKE_CURRENT_SOURCE_DIR}/Unit PARAMS ${CLANG_TEST_PARAMS} - adapter=${TAEF_EXEC_ADAPTER} - DEPENDS ExecHLSLTests dxexp + DEPENDS ClangUnitTests ARGS ${CLANG_TEST_EXTRA_ARGS} ) - add_lit_target("check-clang-taef-exec-warp" "Running lit suite hlsl execution test with D3D WARP from nuget" - ${CMAKE_CURRENT_SOURCE_DIR}/taef_exec - PARAMS ${CLANG_TEST_PARAMS} - adapter=${TAEF_EXEC_ADAPTER} - DEPENDS ExecHLSLTests dxexp WarpFromNuget - ARGS ${CLANG_TEST_EXTRA_ARGS} - ) + # Add TAEF targets + if(WIN32) + add_lit_target("check-clang-taef" "Running lit suite hlsl" + ${CMAKE_CURRENT_SOURCE_DIR}/taef + PARAMS ${CLANG_TEST_PARAMS} + DEPENDS ClangHLSLTests + ARGS ${CLANG_TEST_EXTRA_ARGS} + ) + set(TAEF_EXEC_ADAPTER "" CACHE STRING "adapter for taef exec test") + + add_lit_target("check-clang-taef-exec" "Running lit suite hlsl execution test" + ${CMAKE_CURRENT_SOURCE_DIR}/taef_exec + PARAMS ${CLANG_TEST_PARAMS} + adapter=${TAEF_EXEC_ADAPTER} + DEPENDS WarpFromNuget ExecHLSLTests dxexp + ARGS ${CLANG_TEST_EXTRA_ARGS} + ) + endif() endif() + # HLSL Change End diff --git a/cmake/modules/Nuget.cmake b/tools/clang/test/taef_exec/DownloadWarp.cmake similarity index 100% rename from cmake/modules/Nuget.cmake rename to tools/clang/test/taef_exec/DownloadWarp.cmake diff --git a/utils/hct/hcttest.cmd b/utils/hct/hcttest.cmd index 3e536d199f..b9e05ce524 100644 --- a/utils/hct/hcttest.cmd +++ b/utils/hct/hcttest.cmd @@ -37,7 +37,6 @@ set TEST_MANUAL_FILE_CHECK=0 set SINGLE_FILE_CHECK_NAME=0 set CUSTOM_BIN_SET= set USE_AGILITY_SDK= -set USE_WARP_FROM_NUGET= set EXEC_TEST_TARGET="check-clang-taef-exec" rem Begin SPIRV change @@ -134,22 +133,6 @@ if "%1"=="-clean" ( set TEST_ALL=0 set TEST_EXEC=1 set TEST_EXEC_REQUIRED=1 -) else if "%1"=="exec-warp" ( - rem If exec-warp is explicitly supplied, hcttest will fail if machine is not configured - rem to run execution tests, otherwise, execution tests would be skipped. - set TEST_ALL=0 - set TEST_EXEC=1 - set USE_WARP_FROM_NUGET=LATEST_RELEASE - set TEST_EXEC_REQUIRED=1 - set EXEC_TEST_TARGET="check-clang-taef-exec-warp" -) else if "%1"=="exec-warp-preview" ( - rem If exec-warp-preview is explicitly supplied, hcttest will fail if machine is not configured - rem to run execution tests, otherwise, execution tests would be skipped. - set TEST_ALL=0 - set TEST_EXEC=1 - set USE_WARP_FROM_NUGET=LATEST_PREVIEW - set TEST_EXEC_REQUIRED=1 - set EXEC_TEST_TARGET="check-clang-taef-exec-warp" ) else if "%1"=="exec-filter" ( set TEST_ALL=0 set TEST_EXEC=1 From c17e2c9fdc169d977d4ebfe82e91204e7741f25f Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 2 May 2025 22:38:09 -0700 Subject: [PATCH 2/8] WIP - install the nuget package --- tools/clang/test/CMakeLists.txt | 24 +- tools/clang/test/taef_exec/DownloadWarp.cmake | 465 +++++++++--------- 2 files changed, 260 insertions(+), 229 deletions(-) diff --git a/tools/clang/test/CMakeLists.txt b/tools/clang/test/CMakeLists.txt index 7b141f4c27..697d5e6eac 100644 --- a/tools/clang/test/CMakeLists.txt +++ b/tools/clang/test/CMakeLists.txt @@ -122,18 +122,22 @@ add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR} FOLDER "Clang tests/Suites" ) +include(taef_exec/DownloadWarp.cmake) + # Use a custom target so we can depend on it and re-run the cmake logic which downloads warp # from nuget if requested. -add_custom_target(WarpFromNuget - COMMAND "${CMAKE_COMMAND}" - -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} - -DBUILD_TYPE=${CMAKE_BUILD_TYPE} - -DBINARY_DIR=${CMAKE_BINARY_DIR} - -P "${CMAKE_CURRENT_SOURCE_DIR}/taef_exec/DownloadWarp.cmake") - -if(NOT CMAKE_CONFIGURATION_TYPES) - add_dependencies(check-clang-taef_exec WarpFromNuget) -endif() +# add_custom_target(WarpFromNuget +# COMMAND "${CMAKE_COMMAND}" +# -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} +# -DBUILD_TYPE=${CMAKE_BUILD_TYPE} +# -DBINARY_DIR=${CMAKE_BINARY_DIR} +# -P "${CMAKE_CURRENT_SOURCE_DIR}/taef_exec/DownloadWarp.cmake") + +# if(NOT CMAKE_CONFIGURATION_TYPES) +# add_dependencies(check-clang-taef_exec WarpFromNuget) +# endif() + +# add_custom_target(TestWarp COMMAND echo "$ENV{ALLUSERSPROFILE} $ENV{MY_TEST}" DEPENDS WarpFromNuget) # add_lit_testsuites doesn't generate targets for Visual Studio or Xcode builds # (since these IDEs cannot handle the huge number of targets it generates). diff --git a/tools/clang/test/taef_exec/DownloadWarp.cmake b/tools/clang/test/taef_exec/DownloadWarp.cmake index 5c8aaea337..d1dd200b7c 100644 --- a/tools/clang/test/taef_exec/DownloadWarp.cmake +++ b/tools/clang/test/taef_exec/DownloadWarp.cmake @@ -1,233 +1,260 @@ -include_guard(GLOBAL) +# This script is run at configure time to install the latest WARP. +# +# NOTE: !! describe the environment variable that can be used to override which +# WARP is used during testing. !! -if(NOT DEFINED BINARY_DIR) - message(SEND_ERROR "Callers must provide BINARY_DIR") -endif() +include_guard(GLOBAL) -if(NOT DEFINED BUILD_TYPE) - message(SEND_ERROR "Callers must provide BUILD_TYPE") +find_program(NUGET_EXE nuget.exe HINTS ${CMAKE_BINARY_DIR}/nuget) +if(NOT NUGET_EXE) + message(STATUS "nuget.exe not found in, download nuget.exe to ${CMAKE_BINARY_DIR}/nuget/nuget.exe...") + file(DOWNLOAD + https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + ${CMAKE_BINARY_DIR}/nuget/nuget.exe + ) + find_program(NUGET_EXE nuget.exe HINTS ${CMAKE_BINARY_DIR}/nuget) + if(NOT NUGET_EXE) + message(FATAL_ERROR "nuget.exe not found in ${CMAKE_BINARY_DIR}/nuget/nuget.exe") + endif() endif() -if(NOT DEFINED ENV{USE_WARP_FROM_NUGET}) - message(SEND_ERROR "Callers must set a string value for the environment variable USE_WARP_FROM_NUGET." - "Either 'LATEST_RELEASE' or 'LATEST_PREVIEW'") +# Install the WARP nuget package. The NUGET_WARP_EXTRA_ARGS cmake variable can +# be use to specify additional arguments to the nuget.exe command line. For +# example, to install a specific version of WARP, set NUGET_WARP_EXTRA_ARGS to +# "-Version 1.0.13". +set(NUGET_WARP_EXTRA_ARGS "" CACHE STRING + "Extra arguments to pass to nuget.exe when installing Microsoft.Direct3D.WARP.") + +execute_process( + COMMAND ${NUGET_EXE} install -ForceEnglishOutput Microsoft.Direct3D.WARP -OutputDirectory ${CMAKE_BINARY_DIR}/nuget ${NUGET_WARP_EXTRA_ARGS} + COMMAND_ERROR_IS_FATAL ANY + RESULT_VARIABLE result + OUTPUT_VARIABLE nuget_output + ERROR_VARIABLE nuget_output) + +if(NOT result EQUAL 0) + message(FATAL_ERROR "nuget install Microsoft.Direct3D.WARP failed with exit code ${result}.") endif() -set(USE_WARP_FROM_NUGET $ENV{USE_WARP_FROM_NUGET}) - -# Downloads nuget.exe to the given path if it doesn't exist yet. -function(EnsureNugetExists target_path) - # Download the latest nuget.exe to the given path. - if(NOT EXISTS ${target_path}) - message(STATUS "Installing nuget.exe to ${target_path}...") - file(DOWNLOAD - https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - ${target_path} - ) - endif() -endfunction() - -# Download the latest nuget package for the given ID. Can pass in a custom source, defaults to nuget public feed. -function(GetNuGetPackageLatestVersion) - set(params NAME ID SOURCE OUTPUT_DIR OUTPUT_VARIABLE PREVIEW) - cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${params}" "") - - if(NOT ARG_OUTPUT_DIR) - set(ARG_OUTPUT_DIR ) - endif() - - set(nuget_exe_path "${ARG_OUTPUT_DIR}\\nuget.exe install") - EnsureNugetExists(${nuget_exe_path}) - - if (${ARG_ID}_LATEST_VERSION) - set(${ARG_OUTPUT_VARIABLE} ${${ARG_ID}_LATEST_VERSION} PARENT_SCOPE) +string(REGEX MATCH "Package \"(Microsoft.Direct3D.WARP..+)\" is already installed" IGNORED_OUTPUT ${nuget_output}) +if(CMAKE_MATCH_1) + set(WARP_PACKAGE ${CMAKE_MATCH_1}) +else() + string(REGEX MATCH "Added package '(Microsoft.Direct3D.WARP..+)' to folder" IGNORED_OUTPUT ${nuget_output}) + if (CMAKE_MATCH_1) + set(WARP_PACKAGE ${CMAKE_MATCH_1}) else() - if(NOT ARG_SOURCE) - set(ARG_SOURCE https://api.nuget.org/v3/index.json) - endif() - - if(NOT ARG_PREVIEW) - set(ARG_PREVIEW OFF) - endif() - - if(ARG_PREVIEW) - # Note that '-Prerelease' options will only return a prerelease package if that is also the latest. - # If you want a prerelease package with an older version number than the latest release package then you - # need to pass a specific version number. - message("Will add '-Prelease' to nuget list command") - set(prerelease "-Prerelease") - endif() - - execute_process( - COMMAND ${nuget_exe_path} - list ${ARG_ID} - -Source ${ARG_SOURCE} - ${prerelease} - RESULT_VARIABLE result - OUTPUT_VARIABLE nuget_list_output - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - if(NOT ${result} STREQUAL "0") - message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID} with exit code ${result}.") - endif() - - # Get last line of running nuget.exe list . - string(REPLACE "\n" ";" nuget_list_output ${nuget_list_output}) - list(POP_BACK nuget_list_output nuget_list_last_line) - if(nuget_list_last_line STREQUAL "No packages found.") - message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID}.") - endif() - - # The last line should have the format - string(REPLACE " " ";" nuget_list_last_line ${nuget_list_last_line}) - list(POP_BACK nuget_list_last_line nuget_version) - - if(NOT nuget_version) - message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID}.") - endif() - - message("Nuget found version:${nuget_version} for ${ARG_ID}") - - # Save output variable and cache the result so subsequent calls to the version-unspecified package - # are faster. - set(${ARG_OUTPUT_VARIABLE} ${nuget_version} PARENT_SCOPE) - set(${ARG_ID}_LATEST_VERSION ${nuget_version} CACHE INTERNAL "") - endif() -endfunction() - -# Installs a NuGet package under OUTPUT_DIR. -# -# FetchNuGetPackage( -# ID Microsoft.Direct3D.WARP -# VERSION 1.0.13 -# SOURCE https://api.nuget.org/v3/index.json -# ) -# -# This function sets a variable _SOURCE_DIR (e.g. Microsoft.Direct3D.WARP_SOURCE_DIR in above example) to the -# extract NuGet package contents. -function(FetchNuGetPackage) - set(params NAME ID VERSION SOURCE OUTPUT_DIR RELEASE_TYPE) - cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${params}" "") - - # The NAME parameter is optional: if it's not set then the package ID is used as the name. The - # reason for having a separate NAME is to allow a consistent identifier for packages whose ID - # changes with each release (e.g. GDK). - if(NOT ARG_NAME) - set(ARG_NAME ${ARG_ID}) + message(FATAL_ERROR "Failed to find package install named in nuget output:\n ${nuget_output}") endif() +endif() - if(NOT ARG_OUTPUT_DIR) - set(ARG_OUTPUT_DIR ${BINARY_DIR}/temp) - endif() +set(WARP_DIR ${CMAKE_BINARY_DIR}/nuget/${WARP_PACKAGE}) + + + + + +# # Download the latest nuget package for the given ID. Can pass in a custom source, defaults to nuget public feed. +# function(GetNuGetPackageLatestVersion) +# set(params NAME ID SOURCE OUTPUT_DIR OUTPUT_VARIABLE PREVIEW) +# cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${params}" "") + +# if(NOT ARG_OUTPUT_DIR) +# set(ARG_OUTPUT_DIR ) +# endif() + +# set(nuget_exe_path "${ARG_OUTPUT_DIR}\\nuget.exe install") +# EnsureNugetExists(${nuget_exe_path}) + +# if (${ARG_ID}_LATEST_VERSION) +# set(${ARG_OUTPUT_VARIABLE} ${${ARG_ID}_LATEST_VERSION} PARENT_SCOPE) +# else() +# if(NOT ARG_SOURCE) +# set(ARG_SOURCE https://api.nuget.org/v3/index.json) +# endif() + +# if(NOT ARG_PREVIEW) +# set(ARG_PREVIEW OFF) +# endif() + +# if(ARG_PREVIEW) +# # Note that '-Prerelease' options will only return a prerelease package if that is also the latest. +# # If you want a prerelease package with an older version number than the latest release package then you +# # need to pass a specific version number. +# message("Will add '-Prelease' to nuget list command") +# set(prerelease "-Prerelease") +# endif() + +# execute_process( +# COMMAND ${nuget_exe_path} +# list ${ARG_ID} +# -Source ${ARG_SOURCE} +# ${prerelease} +# RESULT_VARIABLE result +# OUTPUT_VARIABLE nuget_list_output +# OUTPUT_STRIP_TRAILING_WHITESPACE +# ) + +# if(NOT ${result} STREQUAL "0") +# message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID} with exit code ${result}.") +# endif() + +# # Get last line of running nuget.exe list . +# string(REPLACE "\n" ";" nuget_list_output ${nuget_list_output}) +# list(POP_BACK nuget_list_output nuget_list_last_line) +# if(nuget_list_last_line STREQUAL "No packages found.") +# message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID}.") +# endif() + +# # The last line should have the format +# string(REPLACE " " ";" nuget_list_last_line ${nuget_list_last_line}) +# list(POP_BACK nuget_list_last_line nuget_version) + +# if(NOT nuget_version) +# message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID}.") +# endif() + +# message("Nuget found version:${nuget_version} for ${ARG_ID}") + +# # Save output variable and cache the result so subsequent calls to the version-unspecified package +# # are faster. +# set(${ARG_OUTPUT_VARIABLE} ${nuget_version} PARENT_SCOPE) +# set(${ARG_ID}_LATEST_VERSION ${nuget_version} CACHE INTERNAL "") +# endif() +# endfunction() + +# # Installs a NuGet package under OUTPUT_DIR. +# # +# # FetchNuGetPackage( +# # ID Microsoft.Direct3D.WARP +# # VERSION 1.0.13 +# # SOURCE https://api.nuget.org/v3/index.json +# # ) +# # +# # This function sets a variable _SOURCE_DIR (e.g. Microsoft.Direct3D.WARP_SOURCE_DIR in above example) to the +# # extract NuGet package contents. +# function(FetchNuGetPackage) +# set(params NAME ID VERSION SOURCE OUTPUT_DIR RELEASE_TYPE) +# cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${params}" "") + +# # The NAME parameter is optional: if it's not set then the package ID is used as the name. The +# # reason for having a separate NAME is to allow a consistent identifier for packages whose ID +# # changes with each release (e.g. GDK). +# if(NOT ARG_NAME) +# set(ARG_NAME ${ARG_ID}) +# endif() + +# if(NOT ARG_OUTPUT_DIR) +# set(ARG_OUTPUT_DIR ${BINARY_DIR}/temp) +# endif() - set(nuget_exe_path ${ARG_OUTPUT_DIR}/nuget.exe) +# set(nuget_exe_path ${ARG_OUTPUT_DIR}/nuget.exe) - if(NOT ARG_SOURCE) - set(ARG_SOURCE https://api.nuget.org/v3/index.json) - endif() +# if(NOT ARG_SOURCE) +# set(ARG_SOURCE https://api.nuget.org/v3/index.json) +# endif() - if(NOT ARG_RELEASE_TYPE) - set(ARG_RELEASE_TYPE "LATEST_RELEASE") - endif() +# if(NOT ARG_RELEASE_TYPE) +# set(ARG_RELEASE_TYPE "LATEST_RELEASE") +# endif() - set(PREVIEW OFF) +# set(PREVIEW OFF) - if(${ARG_RELEASE_TYPE} STREQUAL "LATEST_PREVIEW") - set(PREVIEW ON) - endif() - - # Default to latest version - if(NOT ARG_VERSION) - GetNuGetPackageLatestVersion( - ID ${ARG_ID} - SOURCE ${ARG_SOURCE} - PREVIEW ${PREVIEW} - OUTPUT_DIR ${ARG_OUTPUT_DIR} - OUTPUT_VARIABLE ARG_VERSION - ) - endif() - - set(nupkg_path ${ARG_OUTPUT_DIR}/${ARG_ID}.${ARG_VERSION}/${ARG_ID}.${ARG_VERSION}.nupkg) - - if(NOT EXISTS ${nupkg_path}) - message(STATUS "NuGet: adding package ${ARG_ID}.${ARG_VERSION}") - - EnsureNugetExists(${nuget_exe_path}) - - set(retry_count 0) - set(max_retries 10) - set(retry_delay 10) - set(result 1) - - # Run NuGet CLI to download the package. - while(NOT ${result} STREQUAL "0" AND ${retry_count} LESS ${max_retries}) - message(STATUS "'${nuget_exe_path}' install '${ARG_ID}' -Version '${ARG_VERSION}' -Source '${ARG_SOURCE}' -OutputDirectory '${ARG_OUTPUT_DIR}' -DependencyVersion Ignore -Verbosity quiet") - execute_process( - COMMAND - ${nuget_exe_path} - install ${ARG_ID} - -Version ${ARG_VERSION} - -Source ${ARG_SOURCE} - -OutputDirectory ${ARG_OUTPUT_DIR} - -DependencyVersion Ignore - -Verbosity quiet - RESULT_VARIABLE result - ) - if(NOT ${result} STREQUAL "0") - math(EXPR retry_count "${retry_count} + 1") - - message(STATUS "Nuget failed: '${result}'. Retrying in ${retry_delay} seconds...") - execute_process( - COMMAND - ${CMAKE_COMMAND} -E sleep ${retry_delay} - ) - endif() - endwhile() - - if(NOT ${result} STREQUAL "0") - message(FATAL_ERROR "NuGet failed: '${result}' Package '${ARG_NAME}' (${ARG_ID}.${ARG_VERSION})") - endif() - endif() - - # Set output variable. The NAME parameter is optional: if it's not set then the package ID is used as the - # name. The reason for having a separate NAME is for packages whose IDs change (e.g. GDK) so that callers - # can use a fixed name in dependents. Example, targets can reference gdk_SOURCE_DIR with the snippet below - # instead of having to reference Microsoft.GDK.PC.230300_SOURCE_DIR. - # - # FetchNuGetPackage( - # NAME gdk - # ID Microsoft.GDK.PC.220300 - # VERSION 10.0.22621.3049 - # ) - set(${ARG_NAME}_SOURCE_DIR ${ARG_OUTPUT_DIR}/${ARG_ID}.${ARG_VERSION} PARENT_SCOPE) -endfunction() - -# Begin the 'main' logic of this file. Previous code is all defintions. -message("USE_WARP_FROM_NUGET: ${USE_WARP_FROM_NUGET}") -if(${USE_WARP_FROM_NUGET} STREQUAL "LATEST_RELEASE" OR ${USE_WARP_FROM_NUGET} STREQUAL "LATEST_PREVIEW") - - message("Fetching warp from nuget") - - FetchNuGetPackage(ID Microsoft.Direct3D.WARP OUTPUT_DIR ${BINARY_DIR}/temp RELEASE_TYPE ${USE_WARP_FROM_NUGET}) - - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - set(ARCH "x64") - endif() - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "X86") - set(ARCH "win32") - endif() - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64") - set(ARCH "arm64") - endif() - - set(WARP_SOURCE_PATH "${Microsoft.Direct3D.WARP_SOURCE_DIR}/build/native/bin/${ARCH}") - set(WARP_DEST_PATH "${BINARY_DIR}/${BUILD_TYPE}/bin/") - message("Copying d3d10warp.dll and d3d10warp.pdb \n" - " from: ${WARP_SOURCE_PATH}\n" - " to: ${WARP_DEST_PATH}") - file(COPY "${WARP_SOURCE_PATH}/d3d10warp.dll" - DESTINATION "${WARP_DEST_PATH}") - file(COPY "${WARP_SOURCE_PATH}/d3d10warp.pdb" - DESTINATION "${WARP_DEST_PATH}") -endif() +# if(${ARG_RELEASE_TYPE} STREQUAL "LATEST_PREVIEW") +# set(PREVIEW ON) +# endif() + +# # Default to latest version +# if(NOT ARG_VERSION) +# GetNuGetPackageLatestVersion( +# ID ${ARG_ID} +# SOURCE ${ARG_SOURCE} +# PREVIEW ${PREVIEW} +# OUTPUT_DIR ${ARG_OUTPUT_DIR} +# OUTPUT_VARIABLE ARG_VERSION +# ) +# endif() + +# set(nupkg_path ${ARG_OUTPUT_DIR}/${ARG_ID}.${ARG_VERSION}/${ARG_ID}.${ARG_VERSION}.nupkg) + +# if(NOT EXISTS ${nupkg_path}) +# message(STATUS "NuGet: adding package ${ARG_ID}.${ARG_VERSION}") + +# EnsureNugetExists(${nuget_exe_path}) + +# set(retry_count 0) +# set(max_retries 10) +# set(retry_delay 10) +# set(result 1) + +# # Run NuGet CLI to download the package. +# while(NOT ${result} STREQUAL "0" AND ${retry_count} LESS ${max_retries}) +# message(STATUS "'${nuget_exe_path}' install '${ARG_ID}' -Version '${ARG_VERSION}' -Source '${ARG_SOURCE}' -OutputDirectory '${ARG_OUTPUT_DIR}' -DependencyVersion Ignore -Verbosity quiet") +# execute_process( +# COMMAND +# ${nuget_exe_path} +# install ${ARG_ID} +# -Version ${ARG_VERSION} +# -Source ${ARG_SOURCE} +# -OutputDirectory ${ARG_OUTPUT_DIR} +# -DependencyVersion Ignore +# -Verbosity quiet +# RESULT_VARIABLE result +# ) +# if(NOT ${result} STREQUAL "0") +# math(EXPR retry_count "${retry_count} + 1") + +# message(STATUS "Nuget failed: '${result}'. Retrying in ${retry_delay} seconds...") +# execute_process( +# COMMAND +# ${CMAKE_COMMAND} -E sleep ${retry_delay} +# ) +# endif() +# endwhile() + +# if(NOT ${result} STREQUAL "0") +# message(FATAL_ERROR "NuGet failed: '${result}' Package '${ARG_NAME}' (${ARG_ID}.${ARG_VERSION})") +# endif() +# endif() + +# # Set output variable. The NAME parameter is optional: if it's not set then the package ID is used as the +# # name. The reason for having a separate NAME is for packages whose IDs change (e.g. GDK) so that callers +# # can use a fixed name in dependents. Example, targets can reference gdk_SOURCE_DIR with the snippet below +# # instead of having to reference Microsoft.GDK.PC.230300_SOURCE_DIR. +# # +# # FetchNuGetPackage( +# # NAME gdk +# # ID Microsoft.GDK.PC.220300 +# # VERSION 10.0.22621.3049 +# # ) +# set(${ARG_NAME}_SOURCE_DIR ${ARG_OUTPUT_DIR}/${ARG_ID}.${ARG_VERSION} PARENT_SCOPE) +# endfunction() + +# # Begin the 'main' logic of this file. Previous code is all defintions. +# message("USE_WARP_FROM_NUGET: ${USE_WARP_FROM_NUGET}") +# if(${USE_WARP_FROM_NUGET} STREQUAL "LATEST_RELEASE" OR ${USE_WARP_FROM_NUGET} STREQUAL "LATEST_PREVIEW") + +# message("Fetching warp from nuget") + +# FetchNuGetPackage(ID Microsoft.Direct3D.WARP OUTPUT_DIR ${BINARY_DIR}/temp RELEASE_TYPE ${USE_WARP_FROM_NUGET}) + +# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") +# set(ARCH "x64") +# endif() +# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "X86") +# set(ARCH "win32") +# endif() +# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64") +# set(ARCH "arm64") +# endif() + +# set(WARP_SOURCE_PATH "${Microsoft.Direct3D.WARP_SOURCE_DIR}/build/native/bin/${ARCH}") +# set(WARP_DEST_PATH "${BINARY_DIR}/${BUILD_TYPE}/bin/") +# message("Copying d3d10warp.dll and d3d10warp.pdb \n" +# " from: ${WARP_SOURCE_PATH}\n" +# " to: ${WARP_DEST_PATH}") +# file(COPY "${WARP_SOURCE_PATH}/d3d10warp.dll" +# DESTINATION "${WARP_DEST_PATH}") +# file(COPY "${WARP_SOURCE_PATH}/d3d10warp.pdb" +# DESTINATION "${WARP_DEST_PATH}") +# endif() From cb5b88f6ddb9dabd5657ec644f937a5cf55f9760 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 2 May 2025 23:08:43 -0700 Subject: [PATCH 3/8] Install the nuget package, and update the lit site config for the dll location --- tools/clang/test/CMakeLists.txt | 7 +- tools/clang/test/taef_exec/DownloadWarp.cmake | 227 ++---------------- tools/clang/test/taef_exec/lit.site.cfg.in | 1 + 3 files changed, 25 insertions(+), 210 deletions(-) diff --git a/tools/clang/test/CMakeLists.txt b/tools/clang/test/CMakeLists.txt index 697d5e6eac..f34d8cfff4 100644 --- a/tools/clang/test/CMakeLists.txt +++ b/tools/clang/test/CMakeLists.txt @@ -26,6 +26,12 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_BINARY_DIR}/taef/lit.site.cfg ) +# HLSL Change begin +# This must be done before configuring taef_exec's lit.site.cfg. +include(taef_exec/DownloadWarp.cmake) +# HLSL Change end + + configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/taef_exec/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/taef_exec/lit.site.cfg @@ -122,7 +128,6 @@ add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR} FOLDER "Clang tests/Suites" ) -include(taef_exec/DownloadWarp.cmake) # Use a custom target so we can depend on it and re-run the cmake logic which downloads warp # from nuget if requested. diff --git a/tools/clang/test/taef_exec/DownloadWarp.cmake b/tools/clang/test/taef_exec/DownloadWarp.cmake index d1dd200b7c..646d6509fc 100644 --- a/tools/clang/test/taef_exec/DownloadWarp.cmake +++ b/tools/clang/test/taef_exec/DownloadWarp.cmake @@ -25,15 +25,20 @@ endif() set(NUGET_WARP_EXTRA_ARGS "" CACHE STRING "Extra arguments to pass to nuget.exe when installing Microsoft.Direct3D.WARP.") +# NUGET_WARP_EXTRA_ARGS gets passed as a single command-line argument. In cmake, +# lists are items separated by semicolons, so these will become separate +# arguments. +string(REPLACE " " ";" NUGET_WARP_EXTRA_ARGS_LIST ${NUGET_WARP_EXTRA_ARGS}) + execute_process( - COMMAND ${NUGET_EXE} install -ForceEnglishOutput Microsoft.Direct3D.WARP -OutputDirectory ${CMAKE_BINARY_DIR}/nuget ${NUGET_WARP_EXTRA_ARGS} - COMMAND_ERROR_IS_FATAL ANY + COMMAND ${NUGET_EXE} install -ForceEnglishOutput Microsoft.Direct3D.WARP -OutputDirectory ${CMAKE_BINARY_DIR}/nuget ${NUGET_WARP_EXTRA_ARGS_LIST} RESULT_VARIABLE result OUTPUT_VARIABLE nuget_output ERROR_VARIABLE nuget_output) if(NOT result EQUAL 0) - message(FATAL_ERROR "nuget install Microsoft.Direct3D.WARP failed with exit code ${result}.") + message(FATAL_ERROR "nuget install Microsoft.Direct3D.WARP failed with exit code ${result}.\n${nuget_output}") + endif() string(REGEX MATCH "Package \"(Microsoft.Direct3D.WARP..+)\" is already installed" IGNORED_OUTPUT ${nuget_output}) @@ -50,211 +55,15 @@ endif() set(WARP_DIR ${CMAKE_BINARY_DIR}/nuget/${WARP_PACKAGE}) +if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") + set(WARP_ARCH "x64") +endif() +if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "X86") + set(WARP_ARCH "win32") +endif() +if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64") + set(WARP_ARCH "arm64") +endif() +set(WARP_DLL ${WARP_DIR}/build/native/bin/${WARP_ARCH}/d3d10warp.dll) - - -# # Download the latest nuget package for the given ID. Can pass in a custom source, defaults to nuget public feed. -# function(GetNuGetPackageLatestVersion) -# set(params NAME ID SOURCE OUTPUT_DIR OUTPUT_VARIABLE PREVIEW) -# cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${params}" "") - -# if(NOT ARG_OUTPUT_DIR) -# set(ARG_OUTPUT_DIR ) -# endif() - -# set(nuget_exe_path "${ARG_OUTPUT_DIR}\\nuget.exe install") -# EnsureNugetExists(${nuget_exe_path}) - -# if (${ARG_ID}_LATEST_VERSION) -# set(${ARG_OUTPUT_VARIABLE} ${${ARG_ID}_LATEST_VERSION} PARENT_SCOPE) -# else() -# if(NOT ARG_SOURCE) -# set(ARG_SOURCE https://api.nuget.org/v3/index.json) -# endif() - -# if(NOT ARG_PREVIEW) -# set(ARG_PREVIEW OFF) -# endif() - -# if(ARG_PREVIEW) -# # Note that '-Prerelease' options will only return a prerelease package if that is also the latest. -# # If you want a prerelease package with an older version number than the latest release package then you -# # need to pass a specific version number. -# message("Will add '-Prelease' to nuget list command") -# set(prerelease "-Prerelease") -# endif() - -# execute_process( -# COMMAND ${nuget_exe_path} -# list ${ARG_ID} -# -Source ${ARG_SOURCE} -# ${prerelease} -# RESULT_VARIABLE result -# OUTPUT_VARIABLE nuget_list_output -# OUTPUT_STRIP_TRAILING_WHITESPACE -# ) - -# if(NOT ${result} STREQUAL "0") -# message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID} with exit code ${result}.") -# endif() - -# # Get last line of running nuget.exe list . -# string(REPLACE "\n" ";" nuget_list_output ${nuget_list_output}) -# list(POP_BACK nuget_list_output nuget_list_last_line) -# if(nuget_list_last_line STREQUAL "No packages found.") -# message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID}.") -# endif() - -# # The last line should have the format -# string(REPLACE " " ";" nuget_list_last_line ${nuget_list_last_line}) -# list(POP_BACK nuget_list_last_line nuget_version) - -# if(NOT nuget_version) -# message(FATAL_ERROR "NuGet failed to find latest version of package ${ARG_ID}.") -# endif() - -# message("Nuget found version:${nuget_version} for ${ARG_ID}") - -# # Save output variable and cache the result so subsequent calls to the version-unspecified package -# # are faster. -# set(${ARG_OUTPUT_VARIABLE} ${nuget_version} PARENT_SCOPE) -# set(${ARG_ID}_LATEST_VERSION ${nuget_version} CACHE INTERNAL "") -# endif() -# endfunction() - -# # Installs a NuGet package under OUTPUT_DIR. -# # -# # FetchNuGetPackage( -# # ID Microsoft.Direct3D.WARP -# # VERSION 1.0.13 -# # SOURCE https://api.nuget.org/v3/index.json -# # ) -# # -# # This function sets a variable _SOURCE_DIR (e.g. Microsoft.Direct3D.WARP_SOURCE_DIR in above example) to the -# # extract NuGet package contents. -# function(FetchNuGetPackage) -# set(params NAME ID VERSION SOURCE OUTPUT_DIR RELEASE_TYPE) -# cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${params}" "") - -# # The NAME parameter is optional: if it's not set then the package ID is used as the name. The -# # reason for having a separate NAME is to allow a consistent identifier for packages whose ID -# # changes with each release (e.g. GDK). -# if(NOT ARG_NAME) -# set(ARG_NAME ${ARG_ID}) -# endif() - -# if(NOT ARG_OUTPUT_DIR) -# set(ARG_OUTPUT_DIR ${BINARY_DIR}/temp) -# endif() - -# set(nuget_exe_path ${ARG_OUTPUT_DIR}/nuget.exe) - -# if(NOT ARG_SOURCE) -# set(ARG_SOURCE https://api.nuget.org/v3/index.json) -# endif() - -# if(NOT ARG_RELEASE_TYPE) -# set(ARG_RELEASE_TYPE "LATEST_RELEASE") -# endif() - -# set(PREVIEW OFF) - -# if(${ARG_RELEASE_TYPE} STREQUAL "LATEST_PREVIEW") -# set(PREVIEW ON) -# endif() - -# # Default to latest version -# if(NOT ARG_VERSION) -# GetNuGetPackageLatestVersion( -# ID ${ARG_ID} -# SOURCE ${ARG_SOURCE} -# PREVIEW ${PREVIEW} -# OUTPUT_DIR ${ARG_OUTPUT_DIR} -# OUTPUT_VARIABLE ARG_VERSION -# ) -# endif() - -# set(nupkg_path ${ARG_OUTPUT_DIR}/${ARG_ID}.${ARG_VERSION}/${ARG_ID}.${ARG_VERSION}.nupkg) - -# if(NOT EXISTS ${nupkg_path}) -# message(STATUS "NuGet: adding package ${ARG_ID}.${ARG_VERSION}") - -# EnsureNugetExists(${nuget_exe_path}) - -# set(retry_count 0) -# set(max_retries 10) -# set(retry_delay 10) -# set(result 1) - -# # Run NuGet CLI to download the package. -# while(NOT ${result} STREQUAL "0" AND ${retry_count} LESS ${max_retries}) -# message(STATUS "'${nuget_exe_path}' install '${ARG_ID}' -Version '${ARG_VERSION}' -Source '${ARG_SOURCE}' -OutputDirectory '${ARG_OUTPUT_DIR}' -DependencyVersion Ignore -Verbosity quiet") -# execute_process( -# COMMAND -# ${nuget_exe_path} -# install ${ARG_ID} -# -Version ${ARG_VERSION} -# -Source ${ARG_SOURCE} -# -OutputDirectory ${ARG_OUTPUT_DIR} -# -DependencyVersion Ignore -# -Verbosity quiet -# RESULT_VARIABLE result -# ) -# if(NOT ${result} STREQUAL "0") -# math(EXPR retry_count "${retry_count} + 1") - -# message(STATUS "Nuget failed: '${result}'. Retrying in ${retry_delay} seconds...") -# execute_process( -# COMMAND -# ${CMAKE_COMMAND} -E sleep ${retry_delay} -# ) -# endif() -# endwhile() - -# if(NOT ${result} STREQUAL "0") -# message(FATAL_ERROR "NuGet failed: '${result}' Package '${ARG_NAME}' (${ARG_ID}.${ARG_VERSION})") -# endif() -# endif() - -# # Set output variable. The NAME parameter is optional: if it's not set then the package ID is used as the -# # name. The reason for having a separate NAME is for packages whose IDs change (e.g. GDK) so that callers -# # can use a fixed name in dependents. Example, targets can reference gdk_SOURCE_DIR with the snippet below -# # instead of having to reference Microsoft.GDK.PC.230300_SOURCE_DIR. -# # -# # FetchNuGetPackage( -# # NAME gdk -# # ID Microsoft.GDK.PC.220300 -# # VERSION 10.0.22621.3049 -# # ) -# set(${ARG_NAME}_SOURCE_DIR ${ARG_OUTPUT_DIR}/${ARG_ID}.${ARG_VERSION} PARENT_SCOPE) -# endfunction() - -# # Begin the 'main' logic of this file. Previous code is all defintions. -# message("USE_WARP_FROM_NUGET: ${USE_WARP_FROM_NUGET}") -# if(${USE_WARP_FROM_NUGET} STREQUAL "LATEST_RELEASE" OR ${USE_WARP_FROM_NUGET} STREQUAL "LATEST_PREVIEW") - -# message("Fetching warp from nuget") - -# FetchNuGetPackage(ID Microsoft.Direct3D.WARP OUTPUT_DIR ${BINARY_DIR}/temp RELEASE_TYPE ${USE_WARP_FROM_NUGET}) - -# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") -# set(ARCH "x64") -# endif() -# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "X86") -# set(ARCH "win32") -# endif() -# if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64") -# set(ARCH "arm64") -# endif() - -# set(WARP_SOURCE_PATH "${Microsoft.Direct3D.WARP_SOURCE_DIR}/build/native/bin/${ARCH}") -# set(WARP_DEST_PATH "${BINARY_DIR}/${BUILD_TYPE}/bin/") -# message("Copying d3d10warp.dll and d3d10warp.pdb \n" -# " from: ${WARP_SOURCE_PATH}\n" -# " to: ${WARP_DEST_PATH}") -# file(COPY "${WARP_SOURCE_PATH}/d3d10warp.dll" -# DESTINATION "${WARP_DEST_PATH}") -# file(COPY "${WARP_SOURCE_PATH}/d3d10warp.pdb" -# DESTINATION "${WARP_DEST_PATH}") -# endif() diff --git a/tools/clang/test/taef_exec/lit.site.cfg.in b/tools/clang/test/taef_exec/lit.site.cfg.in index d4d914ead9..d987a82d07 100644 --- a/tools/clang/test/taef_exec/lit.site.cfg.in +++ b/tools/clang/test/taef_exec/lit.site.cfg.in @@ -7,6 +7,7 @@ config.llvm_obj_root = "@LLVM_BINARY_DIR@" config.llvm_build_mode = "@LLVM_BUILD_MODE@" config.te = "@TAEF_EXECUTABLE@" config.taef_arch = "@TAEF_ARCH@" +config.warp_dll = "@WARP_DLL@" config.verbose = True # Support substitution of the tools_dir, libs_dirs, and build_mode with user From 73d0396b1a89c8e21a9f2b970561fc49d5dcf9d5 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Sat, 3 May 2025 10:23:32 -0700 Subject: [PATCH 4/8] Explicitly load WARP dll --- tools/clang/test/CMakeLists.txt | 21 +------ tools/clang/test/taef_exec/DownloadWarp.cmake | 60 ++++++++++++++----- tools/clang/test/taef_exec/lit.cfg | 6 ++ .../unittests/HLSLExec/ExecutionTest.cpp | 28 ++++++++- 4 files changed, 79 insertions(+), 36 deletions(-) diff --git a/tools/clang/test/CMakeLists.txt b/tools/clang/test/CMakeLists.txt index f34d8cfff4..3035d344b0 100644 --- a/tools/clang/test/CMakeLists.txt +++ b/tools/clang/test/CMakeLists.txt @@ -129,26 +129,11 @@ add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR} ) -# Use a custom target so we can depend on it and re-run the cmake logic which downloads warp -# from nuget if requested. -# add_custom_target(WarpFromNuget -# COMMAND "${CMAKE_COMMAND}" -# -DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} -# -DBUILD_TYPE=${CMAKE_BUILD_TYPE} -# -DBINARY_DIR=${CMAKE_BINARY_DIR} -# -P "${CMAKE_CURRENT_SOURCE_DIR}/taef_exec/DownloadWarp.cmake") - -# if(NOT CMAKE_CONFIGURATION_TYPES) -# add_dependencies(check-clang-taef_exec WarpFromNuget) -# endif() - -# add_custom_target(TestWarp COMMAND echo "$ENV{ALLUSERSPROFILE} $ENV{MY_TEST}" DEPENDS WarpFromNuget) - # add_lit_testsuites doesn't generate targets for Visual Studio or Xcode builds # (since these IDEs cannot handle the huge number of targets it generates). # -# We must manually generate targets that we want to expose in visual studio -# builds. +# We must manually generate targets that we want to expose when using these +# generators. if(CMAKE_CONFIGURATION_TYPES) # Add the unit test suite @@ -173,7 +158,7 @@ if(CMAKE_CONFIGURATION_TYPES) ${CMAKE_CURRENT_SOURCE_DIR}/taef_exec PARAMS ${CLANG_TEST_PARAMS} adapter=${TAEF_EXEC_ADAPTER} - DEPENDS WarpFromNuget ExecHLSLTests dxexp + DEPENDS ExecHLSLTests dxexp ARGS ${CLANG_TEST_EXTRA_ARGS} ) endif() diff --git a/tools/clang/test/taef_exec/DownloadWarp.cmake b/tools/clang/test/taef_exec/DownloadWarp.cmake index 646d6509fc..8db4c903c6 100644 --- a/tools/clang/test/taef_exec/DownloadWarp.cmake +++ b/tools/clang/test/taef_exec/DownloadWarp.cmake @@ -1,34 +1,59 @@ +include_guard(GLOBAL) + # This script is run at configure time to install the latest WARP. + +if(NOT WIN32) + # WARP is only a thing on Win32 + return() +endif() + + # -# NOTE: !! describe the environment variable that can be used to override which -# WARP is used during testing. !! +# At runtime, the Execution Tests looks at the WARP_DLL runtime parameter to +# decide which DLL to use. When USE_NUGET_WARP is set to true, this will +# configure the tests by default to use the DLL from the installed nuget +# package. -include_guard(GLOBAL) +set(USE_NUGET_WARP TRUE CACHE BOOL + "Whether or not to use WARP from the Microsoft.Direct3D.WARP nuget package") + +# The NUGET_WARP_EXTRA_ARGS cmake variable can be use to specify additional +# arguments to the nuget.exe command line. For example, to install a specific +# version of WARP, set NUGET_WARP_EXTRA_ARGS to "-Version 1.0.13". +set(NUGET_WARP_EXTRA_ARGS "" CACHE STRING + "Extra arguments to pass to nuget.exe when installing Microsoft.Direct3D.WARP.") + +if(NOT USE_NUGET_WARP) + message(STATUS "Using OS version of WARP") + return() +endif() + +function(InstallWarpFailure) + message(FATAL_ERROR "Unable to install WARP nuget package. Set USE_NUGET_WARP to FALSE to use OS version of WARP.") +endfunction() find_program(NUGET_EXE nuget.exe HINTS ${CMAKE_BINARY_DIR}/nuget) if(NOT NUGET_EXE) message(STATUS "nuget.exe not found in, download nuget.exe to ${CMAKE_BINARY_DIR}/nuget/nuget.exe...") - file(DOWNLOAD + file(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${CMAKE_BINARY_DIR}/nuget/nuget.exe ) find_program(NUGET_EXE nuget.exe HINTS ${CMAKE_BINARY_DIR}/nuget) if(NOT NUGET_EXE) - message(FATAL_ERROR "nuget.exe not found in ${CMAKE_BINARY_DIR}/nuget/nuget.exe") + message(SEND_ERROR "nuget.exe not found in ${CMAKE_BINARY_DIR}/nuget/nuget.exe") + InstallWarpFailure() endif() endif() -# Install the WARP nuget package. The NUGET_WARP_EXTRA_ARGS cmake variable can -# be use to specify additional arguments to the nuget.exe command line. For -# example, to install a specific version of WARP, set NUGET_WARP_EXTRA_ARGS to -# "-Version 1.0.13". -set(NUGET_WARP_EXTRA_ARGS "" CACHE STRING - "Extra arguments to pass to nuget.exe when installing Microsoft.Direct3D.WARP.") +# Install the WARP nuget package. # NUGET_WARP_EXTRA_ARGS gets passed as a single command-line argument. In cmake, # lists are items separated by semicolons, so these will become separate # arguments. -string(REPLACE " " ";" NUGET_WARP_EXTRA_ARGS_LIST ${NUGET_WARP_EXTRA_ARGS}) +if(NUGET_WARP_EXTRA_ARGS) + string(REPLACE " " ";" NUGET_WARP_EXTRA_ARGS_LIST ${NUGET_WARP_EXTRA_ARGS}) +endif() execute_process( COMMAND ${NUGET_EXE} install -ForceEnglishOutput Microsoft.Direct3D.WARP -OutputDirectory ${CMAKE_BINARY_DIR}/nuget ${NUGET_WARP_EXTRA_ARGS_LIST} @@ -37,8 +62,8 @@ execute_process( ERROR_VARIABLE nuget_output) if(NOT result EQUAL 0) - message(FATAL_ERROR "nuget install Microsoft.Direct3D.WARP failed with exit code ${result}.\n${nuget_output}") - + message(SEND_ERROR "nuget install Microsoft.Direct3D.WARP failed with exit code ${result}.\n${nuget_output}") + InstallWarpFailure() endif() string(REGEX MATCH "Package \"(Microsoft.Direct3D.WARP..+)\" is already installed" IGNORED_OUTPUT ${nuget_output}) @@ -46,10 +71,11 @@ if(CMAKE_MATCH_1) set(WARP_PACKAGE ${CMAKE_MATCH_1}) else() string(REGEX MATCH "Added package '(Microsoft.Direct3D.WARP..+)' to folder" IGNORED_OUTPUT ${nuget_output}) - if (CMAKE_MATCH_1) + if(CMAKE_MATCH_1) set(WARP_PACKAGE ${CMAKE_MATCH_1}) else() - message(FATAL_ERROR "Failed to find package install named in nuget output:\n ${nuget_output}") + message(SEND_ERROR "Failed to find package install named in nuget output:\n ${nuget_output}") + InstallWarpFailure() endif() endif() @@ -65,5 +91,7 @@ if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ARM64") set(WARP_ARCH "arm64") endif() +# WARP_DLL is picked up by lit.site.cfg.in so it can be passed as a TAEF runtime +# parameter by lit.cfg set(WARP_DLL ${WARP_DIR}/build/native/bin/${WARP_ARCH}/d3d10warp.dll) diff --git a/tools/clang/test/taef_exec/lit.cfg b/tools/clang/test/taef_exec/lit.cfg index 98d50824c5..9685da6711 100644 --- a/tools/clang/test/taef_exec/lit.cfg +++ b/tools/clang/test/taef_exec/lit.cfg @@ -70,6 +70,12 @@ if config.unsupported == False: extra_params.append('/p:') extra_params.append('D3D12SDKVersion=1') + warp_dll = getattr(config, 'warp_dll', None) + if warp_dll: + extra_params.append('/p:') + extra_params.append(f'WARP_DLL={warp_dll}') + print(f"Using WARP from {warp_dll}\n") + # use ';' to split multiple params. taef_extra_params = lit_config.params.get('taef_exec_extra_params', None) if taef_extra_params: diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 6db27d7a41..4fa667b2f9 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -806,6 +806,20 @@ class ExecutionTest { VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))); if (GetTestParamUseWARP(UseWarpByDefault())) { + + // The WARP_DLL runtime parameter can be used to specify a specific DLL to + // load. To force this to be used, we make sure that this DLL is loaded + // before attempting to create the device. + HMODULE ExplicitlyLoadedWarpDll = NULL; + WEX::Common::String WarpDllPath; + if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(L"WARP_DLL", WarpDllPath))) { + WEX::Logging::Log::Comment(WEX::Common::String().Format( + L"WARP_DLL requested: %ls", (const wchar_t*)WarpDllPath)); + ExplicitlyLoadedWarpDll = LoadLibraryExW(WarpDllPath, NULL, 0); + VERIFY_WIN32_BOOL_SUCCEEDED(!!ExplicitlyLoadedWarpDll); + } + + // Create the WARP device CComPtr warpAdapter; VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter))); HRESULT createHR = D3D12CreateDevice(warpAdapter, D3D_FEATURE_LEVEL_11_0, @@ -820,14 +834,24 @@ class ExecutionTest { return false; } + // Now that the WARP device is created we can release our reference to the + // warp dll. + if (ExplicitlyLoadedWarpDll) { + FreeLibrary(ExplicitlyLoadedWarpDll); + ExplicitlyLoadedWarpDll = NULL; + } + + // Log the actual version of WARP that's loaded so we can be sure that + // we're using the version we think. if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { WCHAR szFullModuleFilePath[MAX_PATH] = L""; GetModuleFileNameW(GetModuleHandleW(L"d3d10warp.dll"), - szFullModuleFilePath, sizeof(szFullModuleFilePath)); + szFullModuleFilePath, sizeof(szFullModuleFilePath)); WEX::Logging::Log::Comment(WEX::Common::String().Format( - L"WARP driver loaded from: %S", szFullModuleFilePath)); + L"WARP driver loaded from: %ls", szFullModuleFilePath)); } + } else { CComPtr hardwareAdapter; WEX::Common::String AdapterValue; From 69fd6d0c4f35c16da030f1c5c6aea7f9380c83c0 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Sat, 3 May 2025 10:34:28 -0700 Subject: [PATCH 5/8] Fix formatting --- tools/clang/unittests/HLSLExec/ExecutionTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 4fa667b2f9..3ca41e237b 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -812,9 +812,10 @@ class ExecutionTest { // before attempting to create the device. HMODULE ExplicitlyLoadedWarpDll = NULL; WEX::Common::String WarpDllPath; - if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(L"WARP_DLL", WarpDllPath))) { + if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( + L"WARP_DLL", WarpDllPath))) { WEX::Logging::Log::Comment(WEX::Common::String().Format( - L"WARP_DLL requested: %ls", (const wchar_t*)WarpDllPath)); + L"WARP_DLL requested: %ls", (const wchar_t *)WarpDllPath)); ExplicitlyLoadedWarpDll = LoadLibraryExW(WarpDllPath, NULL, 0); VERIFY_WIN32_BOOL_SUCCEEDED(!!ExplicitlyLoadedWarpDll); } @@ -846,12 +847,11 @@ class ExecutionTest { if (GetModuleHandleW(L"d3d10warp.dll") != NULL) { WCHAR szFullModuleFilePath[MAX_PATH] = L""; GetModuleFileNameW(GetModuleHandleW(L"d3d10warp.dll"), - szFullModuleFilePath, sizeof(szFullModuleFilePath)); + szFullModuleFilePath, sizeof(szFullModuleFilePath)); WEX::Logging::Log::Comment(WEX::Common::String().Format( L"WARP driver loaded from: %ls", szFullModuleFilePath)); } - } else { CComPtr hardwareAdapter; WEX::Common::String AdapterValue; From 8ce9a1ff54b462807e62ad1beec1b3e22b2ba033 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 9 May 2025 14:55:46 -0700 Subject: [PATCH 6/8] Add RAII helper for ensuring FreeLibrary is called --- .../unittests/HLSLExec/ExecutionTest.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 3ca41e237b..5abbee0afb 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -810,14 +810,30 @@ class ExecutionTest { // The WARP_DLL runtime parameter can be used to specify a specific DLL to // load. To force this to be used, we make sure that this DLL is loaded // before attempting to create the device. - HMODULE ExplicitlyLoadedWarpDll = NULL; + + struct WarpDll { + HMODULE Module = NULL; + + ~WarpDll() { + Close(); + } + + void Close() { + if (Module) { + FreeLibrary(Module); + Module = NULL; + } + } + }; + + WarpDll ExplicitlyLoadedWarpDll; WEX::Common::String WarpDllPath; if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue( L"WARP_DLL", WarpDllPath))) { WEX::Logging::Log::Comment(WEX::Common::String().Format( L"WARP_DLL requested: %ls", (const wchar_t *)WarpDllPath)); - ExplicitlyLoadedWarpDll = LoadLibraryExW(WarpDllPath, NULL, 0); - VERIFY_WIN32_BOOL_SUCCEEDED(!!ExplicitlyLoadedWarpDll); + ExplicitlyLoadedWarpDll.Module = LoadLibraryExW(WarpDllPath, NULL, 0); + VERIFY_WIN32_BOOL_SUCCEEDED(!!ExplicitlyLoadedWarpDll.Module); } // Create the WARP device @@ -837,10 +853,7 @@ class ExecutionTest { // Now that the WARP device is created we can release our reference to the // warp dll. - if (ExplicitlyLoadedWarpDll) { - FreeLibrary(ExplicitlyLoadedWarpDll); - ExplicitlyLoadedWarpDll = NULL; - } + ExplicitlyLoadedWarpDll.Close(); // Log the actual version of WARP that's loaded so we can be sure that // we're using the version we think. From 742120f3f8d0ed84cf9d860101c698827920abd1 Mon Sep 17 00:00:00 2001 From: "Damyan Pepper (from Dev Box)" Date: Fri, 9 May 2025 14:55:54 -0700 Subject: [PATCH 7/8] Grammar fix --- tools/clang/test/taef_exec/DownloadWarp.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/clang/test/taef_exec/DownloadWarp.cmake b/tools/clang/test/taef_exec/DownloadWarp.cmake index 8db4c903c6..c89f66ae88 100644 --- a/tools/clang/test/taef_exec/DownloadWarp.cmake +++ b/tools/clang/test/taef_exec/DownloadWarp.cmake @@ -9,7 +9,7 @@ endif() # -# At runtime, the Execution Tests looks at the WARP_DLL runtime parameter to +# At runtime, the Execution Tests look at the WARP_DLL runtime parameter to # decide which DLL to use. When USE_NUGET_WARP is set to true, this will # configure the tests by default to use the DLL from the installed nuget # package. From 1560f10b7bb44d2d577027463ccf37031e352f05 Mon Sep 17 00:00:00 2001 From: Damyan Pepper Date: Mon, 12 May 2025 16:00:17 -0700 Subject: [PATCH 8/8] Formatting --- tools/clang/unittests/HLSLExec/ExecutionTest.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp index 5abbee0afb..22753f5609 100644 --- a/tools/clang/unittests/HLSLExec/ExecutionTest.cpp +++ b/tools/clang/unittests/HLSLExec/ExecutionTest.cpp @@ -814,9 +814,7 @@ class ExecutionTest { struct WarpDll { HMODULE Module = NULL; - ~WarpDll() { - Close(); - } + ~WarpDll() { Close(); } void Close() { if (Module) {