shader-slang / slang

Making it easier to work with shaders
MIT License
2.07k stars 178 forks source link

Make sure examples and slang-glslang are compiled correctly with CMake #3827

Open starlightany opened 6 months ago

starlightany commented 6 months ago

Hi, On Windows 11, x64, using Ninja, and MSVC

Recently, I've been trying to run examples from slang, but encountered numerous issues.

Firstly, there's a compilation issue. If you want to compile the examples, you need to manually add --target all-examples to the compilation command. Additionally, after compilation, I realized the actual execution path for the code is under ./slang, so it's unable to find the corresponding .slang files. I had no choice but to move all the shaders that needed to be executed to the outermost ./slang directory. At this point, the target example was able to run, but there were still some problems.

Also, when running the "hello world" example, I encountered the following error:

(0): error 100: failed to load downstream compiler 'spirv-opt'
(0): note 99999: failed to load dynamic library 'slang-glslang'

Moreover, for projects that utilize gfx, it seems like nothing is actually being rendered. I checked the source code and found that something seems to fail during creation without returning an error. After debugging, I believe the error code encountered is as shown in the following image: image

I'm not entirely sure if the issue lies with my method of compilation or the way I'm running it.

csyonghe commented 6 months ago

We have not completed our cmake support yet. You can try configure cmake with presets, e.g.

cmake --preset default

Or please refer to our build instructions to use premake to generate the project files.

All examples need to be run with work directory set to where the same path as their main.cpp file.

csyonghe commented 6 months ago

On windows, the build process is:

  1. Clone repo
  2. git submodule update --init
  3. .\premake.bat vs2019 --deps=true
  4. Build slang.sln

To run an example, e.g. set the current work directory to the main.cpp file of that example, and run the project from visual studio.

starlightany commented 6 months ago

ok, thank you. I have already tried compiling with cmake --preset default, but it seems that due to some incomplete compilation configurations, it cannot correctly compile the executable file for the example. That's why I went to check the CMakeLists.txt to see if it can be compiled correctly. Since that's the case, I will try again using premake.