Skip to content

Instantly share code, notes, and snippets.

@danginsburg
Last active January 9, 2024 20:04
Show Gist options
  • Save danginsburg/a39412c5591f0559dd5bc12f8aec9da2 to your computer and use it in GitHub Desktop.
Save danginsburg/a39412c5591f0559dd5bc12f8aec9da2 to your computer and use it in GitHub Desktop.
Building lavapipe for Windows with Visual Studio 2022

Steps I followed to build lavapipe on Windows (1/9/24). Documenting the steps so that I remember, and putting them on gist in case it's useful to anyone else. Much of this info is courtesy of Mike Blumenkrantz.

  1. From cmd.exe as Administrator:
choco install winflexbison pkgconfiglite /Y
  1. Clone mesa:
git clone https://gitlab.freedesktop.org/mesa/mesa.git
  • I have a hacky local patch to find the DX headers, there is surely a way to specify the windows SDK include with meson, but I'm too lazy to figure it out:
diff --git a/src/vulkan/wsi/wsi_common_win32.cpp b/src/vulkan/wsi/wsi_common_win32.cpp
index e614dae9782..3759a9cd381 100644
--- a/src/vulkan/wsi/wsi_common_win32.cpp
+++ b/src/vulkan/wsi/wsi_common_win32.cpp
@@ -34,9 +34,10 @@
 #include "wsi_common_private.h"

 #define D3D12_IGNORE_SDK_LAYERS
-#include <dxgi1_4.h>
-#include <directx/d3d12.h>
-#include <dxguids/dxguids.h>
+#include <C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/shared/dxgi1_4.h>
+#include <C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/um/d3d12.h>
+
+//#include <dxguids/dxguids.h>

 #include <dcomp.h>
  1. Make folder for LLVM:
mkdir -p mesa/subprojects/llvm
  1. Drop the following file as meson.build in mesa/subprojects/llvm:
project('llvm', ['cpp'])

cpp = meson.get_compiler('cpp')

_deps = []
_search = join_paths(meson.current_source_dir(), 'lib')
foreach d : ['LLVMCodeGen', 'LLVMScalarOpts', 'LLVMAnalysis',
             'LLVMTransformUtils', 'LLVMCore', 'LLVMX86CodeGen',
             'LLVMSelectionDAG', 'LLVMipo', 'LLVMAsmPrinter',
             'LLVMInstCombine', 'LLVMInstrumentation', 'LLVMMC',
             'LLVMGlobalISel', 'LLVMObjectYAML', 'LLVMDebugInfoPDB',
             'LLVMVectorize', 'LLVMPasses', 'LLVMSupport',
             'LLVMLTO', 'LLVMObject', 'LLVMDebugInfoCodeView',
             'LLVMDebugInfoDWARF', 'LLVMOrcJIT', 'LLVMProfileData',
             'LLVMObjCARCOpts', 'LLVMBitReader', 'LLVMCoroutines',
             'LLVMBitWriter', 'LLVMRuntimeDyld', 'LLVMMIRParser',
             'LLVMX86Desc', 'LLVMAsmParser', 'LLVMTableGen',
             'LLVMFuzzMutate', 'LLVMLinker', 'LLVMMCParser',
             'LLVMExecutionEngine', 'LLVMCoverage', 'LLVMInterpreter',
             'LLVMTarget', 'LLVMX86AsmParser', 'LLVMSymbolize',
             'LLVMDebugInfoMSF', 'LLVMMCJIT', 'LLVMXRay',
             'LLVMX86AsmParser', 'LLVMX86Disassembler',
             'LLVMMCDisassembler', 'LLVMOption', 'LLVMIRReader',
             'LLVMLibDriver', 'LLVMDlltoolDriver', 'LLVMDemangle',
             'LLVMBinaryFormat', 'LLVMLineEditor',
             'LLVMWindowsManifest', 'LLVMX86Info', 'LLVMX86Info',
             'LLVMTargetParser', 'LLVMTargetParser', 'LLVMRemarks', 
             'LLVMBitstreamReader', 'LLVMFrontendOpenMP', 'LLVMFrontendOffloading', 
             'LLVMCFGuard', 'LLVMCodeGenTypes',
             'LLVMAggressiveInstCombine', 'LLVMIRPrinter', 'LLVMHipStdPar', 
             'LLVMTextAPI', 'LLVMOrcTargetProcess' ]
  _deps += cpp.find_library(d, dirs : _search)
endforeach


inc_llvm = include_directories('./include')

dep_llvm = declare_dependency(
  include_directories : [inc_llvm],
  dependencies : _deps,
  version : '17.0.6',
)

has_rtti = false
irbuilder_h = files('include/llvm/IR/IRBuilder.h')

  1. Clone LLVM
git clone https://github.com/llvm/llvm-project.git
  1. Build LLVM following instructions here: https://llvm.org/docs/GettingStartedVS.html. Specifically I did (don't need clang as in the instructions there):
cmake -S llvm\llvm -B build -DLLVM_TARGETS_TO_BUILD=X86 -Thost=x64 --prefix /path/to/mesa/subprojects/llvm
  • Build LLVM project, then build INSTALL project inside LLVM solution in VS 2022. Having set --prefix, it should install to mesa/subprojects/llvm
  1. Now we can build mesa, first run meson to generate sln/vcxproj:
meson release --wipe --reconfigure --backend=vs -Dprefix=d:/mesa/release --buildtype=debugoptimized -Dgallium-drivers=swrast -Dvulkan-drivers=swrast
  1. Open mesa.sln in VS 2022 and Build All.
  2. Make a copy of /path/to/mesa/release/src/gallium/targets/lavapipe/lvp_devenv_icd.x86_64.json and rename it (the build copy has the wrong name for the DLL, it has the soname)
  3. Put this in your json (note renaming libvulkan_lvp.so -> vulkan_lvp.dll):
{
    "ICD": {
        "api_version": "1.1.274",
        "library_path": "D:/Users/Dan/src/mesa/release/src/gallium/targets/lavapipe/vulkan_lvp.dll"
    },
    "file_format_version": "1.0.0"
}
  1. Now can run with:
VK_ICD_FILENAMES=D:/Users/Dan/src/mesa/release/src/gallium/targets/lavapipe/lvp_devenv_icd_mine.x86_64.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment