3

I'm using Jonno Robson's Vulkan code base from github found here: Vulkan-Terrain-Generator as a guide and or learning reference to better understand Vulkan. I don't have any issues with the source code itself, but my question or concern pertains to compiling GLSL shader codes into Spir V code. I am new to SpirV its compilers and tool kits. I've tried using both: glslangValidator.exe and glslc.exe to convert the shader files into Spir V files.

In Jonno's code base, he converted each GLSL shader file into a corresponding spirv file. I tried using the flag options that he used in his batch file the only difference is I replaced the directory that points to his glslangValidator.exe with my own directory.

I'm trying to achieve the same effect where it will take all of the shader files that are in the directory of the batch file to be compiled from GLSL to Spir V where it will append .spv to the end of each of the new SpirV files that it will generate in that directory after converting it from GLSL to the respected Spir V byte code.

Here is what my batch file looks like:

compile.bat

C:\VulkanSDK\Bin\glslangValidator.exe -V %1 -o %1.spv
pause

However it is not working for me after I double click on the batch file. It opens and runs, but it is not generating the expected shader_filename.vert.spv ... shader_filename.frag.spv files.

I don't know what platform they did theirs on, but I'm running Windows 7 and I don't know if that makes a difference with the command arguments or flags to be fed within the batch commands. I don't know if they used any other tool kit within the Vulkan SDK or some outside library or tool or what not.

What I would like to be able to do with this batch file is to convert all of the shader files into the appropriate Spir V files with the simplest batch command there is. I don't want to have to write the same command over and over again for each shader file as there are over 20 shaders in this directory.

How can I achieve this or what are the proper command arguments for either glslangValidator or glslc to generate the needed SpirV files?

I have read the documents found here: SPIR-V Toolchain but I'm still not sure how to properly generate the needed batch file.

4

1 回答 1

3

You need to ensure you provide an input name for each file, the example purely used %1 which was then issued as a paramter from command line, something like:

mybatch.bat inputfile.frag

We need to change it if you are planning to just double click it. It will allow you to loop though each of the files you want to do this for:

@echo off
for %%i in (*.vert *.frag) do "C:\VulkanSDK\Bin\glslangValidator.exe" -V "%%~i" -o "%%~i.spv"

What it does is to take each .vert and .frag and assigns it to metavariable %%i we then just issue the command for each until we have looped though each file.

You can read more about meta variables and how to expand on them when doing for /? from cmd.exe

Here is an extract.

You can now use the following optional syntax:

%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file
%~$PATH:I   - searches the directories listed in the PATH
               environment variable and expands %I to the
               fully qualified name of the first one found.
               If the environment variable name is not
               defined or the file is not found by the
               search, then this modifier expands to the
               empty string

The modifiers can be combined to get compound results:

%~dpI       - expands %I to a drive letter and path only
%~nxI       - expands %I to a file name and extension only
%~fsI       - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
               environment variable for %I and expands to the
               drive letter and path of the first one found.
%~ftzaI     - expands %I to a DIR like output line
于 2019-09-19T07:23:17.960 回答