Update and document shader compilation scripts

Will no longer fail with certain shaderStages
Refs #1126
This commit is contained in:
Sascha Willems 2024-06-04 21:31:24 +02:00
parent 9c25dad12c
commit 196e6a4c6b
3 changed files with 20 additions and 4 deletions

3
shaders/README.md Normal file
View file

@ -0,0 +1,3 @@
# Shaders
This folder contains the shaders used by the samples. Source files are available as GLSL and HLSL and also come with precompiled SPIR-V files that are consumed by the samples. To recompile shaders you can use the `compileshaders.py` scripts in the respective folders or any other means that can generate Vulkan SPIR-V from GLSL or HLSL. One such option is [this extension for Visual Studio](https://github.com/SaschaWillems/SPIRV-VSExtension).

View file

@ -1,3 +1,6 @@
# Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
# This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
import argparse
import fileinput
import os
@ -25,7 +28,7 @@ def findGlslang():
if isExe(full_path):
return full_path
sys.exit("Could not find DXC executable on PATH, and was not specified with --dxc")
sys.exit("Could not find glslangvalidator executable on PATH, and was not specified with --glslang")
glslang_path = findGlslang()
dir_path = os.path.dirname(os.path.realpath(__file__))
@ -40,10 +43,14 @@ for root, dirs, files in os.walk(dir_path):
if args.g:
add_params = "-g"
# Ray tracing shaders require a different target environment
if file.endswith(".rgen") or file.endswith(".rchit") or file.endswith(".rmiss"):
add_params = add_params + " --target-env vulkan1.2"
# Same goes for samples that use ray queries
if root.endswith("rayquery") and file.endswith(".frag"):
add_params = add_params + " --target-env vulkan1.2"
res = subprocess.call("%s -V %s -o %s %s" % (glslang_path, input_file, output_file, add_params), shell=True)
# res = subprocess.call([glslang_path, '-V', input_file, '-o', output_file, add_params], shell=True)
if res != 0:
sys.exit()
sys.exit(res)

View file

@ -1,5 +1,5 @@
# Copyright 2020 Google LLC
# Copyright 2023 Sascha Willems
# Copyright 2023-2024 Sascha Willems
import argparse
import fileinput
@ -40,6 +40,7 @@ for root, dirs, files in os.walk(dir_path):
target = ''
profile = ''
additional_exts = ''
if(hlsl_file.find('.vert') != -1):
profile = 'vs_6_1'
elif(hlsl_file.find('.frag') != -1):
@ -59,8 +60,12 @@ for root, dirs, files in os.walk(dir_path):
profile = 'lib_6_3'
elif(hlsl_file.find('.mesh') != -1):
target='-fspv-target-env=vulkan1.2'
additional_exts = '-fspv-extension=SPV_EXT_mesh_shader'
profile = 'ms_6_6'
if root.endswith("debugprintf"):
additional_exts = '-fspv-extension=SPV_KHR_non_semantic_info'
print('Compiling %s' % (hlsl_file))
subprocess.check_output([
dxc_path,
@ -73,6 +78,7 @@ for root, dirs, files in os.walk(dir_path):
'-fspv-extension=SPV_EXT_descriptor_indexing',
'-fspv-extension=SPV_KHR_ray_query',
'-fspv-extension=SPV_KHR_fragment_shading_rate',
additional_exts,
target,
hlsl_file,
'-Fo', spv_out])