shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
2.58k stars 200 forks source link

D3D12 libraries not installed to bin folder when building only slang-test #5462

Open cheneym2 opened 3 weeks ago

cheneym2 commented 3 weeks ago

This issue was discovered in the VS2022 workflow.

1) IMPORTANT: Clean out any existing build/Release/bin and build/Debug/bin contents, as you won't notice the issue if there are files there from a previous build attempt.

2) Initialize the VS solution file:

cmake --preset vs2022

3) Open build/slang.sln file in visual studio

4) Build by clicking the "Local Windows Debugger" icon (IMPORTANT, Do Not Use Build Solution)

The former method will only build the current project and its dependencies. It will not install D3D12 binaries and slang-tests using D3D12 will not work.

Observe: NVIDIA.COM+acheney@acheney-lt3 /cygdrive/c/Users/acheney/Documents/git/slang5

$ ls C:/Users/acheney/Documents/git/slang5/build/Release/bin
dawn.dll                gfx.dll    platform.dll          slang-core-module.bin  slang-reflection-test-tool.dll  slang-test.exe  slang-unit-test-tool.dll  slang.slang  test-process.exe  webgpu_dawn.dll
gfx-unit-test-tool.dll  gfx.slang  render-test-tool.dll  slang-glslang.dll      slang-rt.dll                    slang-tint.dll  slang.dll                 slangd.exe   test-server.exe

D3D12 libraries are installed by a vcproj named "copy-prebuilt-binaries" and that is a dependency of the whole solution, so using the "Build Solution" command does not see this issue.

Observe the contents of the build folder AFTER using the Build Solution command. It has the D3D12 folder (and many other files). slang-test d3d12 tests will work after doing that.

NVIDIA.COM+acheney@acheney-lt3 /cygdrive/c/Users/acheney/Documents/git/slang5
$ ls C:/Users/acheney/Documents/git/slang5/build/Release/bin
D3D12                 d3dcompiler_47.dll  gfx-unit-test-tool.dll  hello-world.exe    ray-tracing-pipeline.exe  shader-toy.exe         slang-reflection-test-tool.dll  slang-tint.dll            slangc.exe        triangle.exe
autodiff-texture.exe  dawn.dll            gfx.dll                 model-viewer.exe   ray-tracing.exe           slang-core-module.bin  slang-replay.exe                slang-unit-test-tool.dll  slangd.exe        webgpu_dawn.dll
cpu-com-example.exe   dxcompiler.dll      gfx.slang               platform-test.exe  render-test-tool.dll      slang-glslang.dll      slang-rt.dll                    slang.dll                 test-process.exe
cpu-hello-world.exe   dxil.dll            gpu-printing.exe        platform.dll       shader-object.exe         slang-profile.exe      slang-test.exe                  slang.slang               test-server.exe

There should be a dependency placed between slang-test and any other apps we run in the slang solution that depend on D3D12 libraries.

Inserting this at the end of CMakeLists.txt works, but it seems like a hack.

    if(SLANG_ENABLE_PREBUILT_BINARIES)
      add_dependencies(slang-test, copy-prebuilt-binaries)
    endif()
expipiplus1 commented 3 weeks ago

that's pretty much the correct solution, but it might be slightly nicer to do with adding a REQUIRED_BY argument to the copy-prebuilt-binaries target, or adding a REQUIRES to slang-test (and friends). whatever's neater. cmake generator expressions can be used to make the conditional tidy and not