diff --git a/shaders/README.md b/shaders/README.md new file mode 100644 index 00000000..3787f3d8 --- /dev/null +++ b/shaders/README.md @@ -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). \ No newline at end of file diff --git a/shaders/glsl/compileshaders.py b/shaders/glsl/compileshaders.py index e0a4e1f5..c53acfa1 100644 --- a/shaders/glsl/compileshaders.py +++ b/shaders/glsl/compileshaders.py @@ -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() \ No newline at end of file + sys.exit(res) \ No newline at end of file diff --git a/shaders/hlsl/compile.py b/shaders/hlsl/compileshaders.py similarity index 90% rename from shaders/hlsl/compile.py rename to shaders/hlsl/compileshaders.py index 3923c618..24033bf2 100644 --- a/shaders/hlsl/compile.py +++ b/shaders/hlsl/compileshaders.py @@ -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])