Compiling GLSL in SPIR-V using Premake 5 and Visual Studio 2015

Instead of manually compiling my GLSL shaders on SPIR-V, I want Visual Studio to automatically detect changes in the shader files and run glslangValidator as a build step. I am using Premake to create a Visual Studio solution / project.

One of the partially worked out solutions was announced in premake5.lua:

    --prebuildcommands [[for %%i in (..\data\shaders\*) do (..\libs\vulkan\glslangValidator.exe -V -o "%%~dpibin\%%~nxi.spv" %%i)]]

and then right-click shader in solution explorer -> properties -> General -> Item Type -> Custom Build Tool.

There are some disadvantages to this approach:

  • All shaders are recompiled when only one changes
  • I had to manually change the settings of the VS project

The closest thing I could find in the documentation was the following: Custom build commands . I think the idea is to use a filter for shader files and generate build commands, but I just couldn't get anything to work. Maybe someone has an idea?

+4
source share
2 answers

It looks like I misunderstood some things from the start documentation (thanks Nicole). I earned:

filter "files:../data/shaders/*"
    buildcommands '"../libs/vulkan/glslangValidator.exe" -V -o "%{file.directory}/bin/%{file.name}.spv" "%{file.relpath}"'
    buildoutputs "%{file.directory}/bin/%{file.name}.spv"

Visual Studio krOoze. - ( ). , Visual Studio ( (.frag,.vert,.comp ..)).

+2

Premake, Visual Studio:

  • Item Type Custom Build Tool
  • Custom Build Tool, :
    • Command Line $(VULKAN_SDK)\Bin32\glslangValidator -V -o $(OutDir)\%(Identity).spv %(Identity) ( x32, Bin x64)
    • Description - , . Compiling vertex shader
    • Outputs, . $(OutDir)\%(Identity).spv
    • Link Objects No

, .

( ) -:

for %%f in (*.vert *.tesc *.tese *.geom *.frag *.comp) \
   do %VK_SDK_PATH%\Bin\glslangValidator.exe -V -o $(OutDir)\%%f.spv %%f

, .

+3

Source: https://habr.com/ru/post/1652001/


All Articles