Skip to content

Commit

Permalink
Update and document shader compilation scripts
Browse files Browse the repository at this point in the history
Will no longer fail with certain shaderStages
Refs #1126
  • Loading branch information
SaschaWillems committed Jun 4, 2024
1 parent 9c25dad commit 196e6a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions shaders/README.md
Original file line number Diff line number Diff line change
@@ -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).
13 changes: 10 additions & 3 deletions shaders/glsl/compileshaders.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -25,7 +28,7 @@ def isExe(path):
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__))
Expand All @@ -40,10 +43,14 @@ def isExe(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)
8 changes: 7 additions & 1 deletion shaders/hlsl/compile.py → shaders/hlsl/compileshaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2020 Google LLC
# Copyright 2023 Sascha Willems
# Copyright 2023-2024 Sascha Willems

import argparse
import fileinput
Expand Down Expand Up @@ -40,6 +40,7 @@ def isExe(path):

target = ''
profile = ''
additional_exts = ''
if(hlsl_file.find('.vert') != -1):
profile = 'vs_6_1'
elif(hlsl_file.find('.frag') != -1):
Expand All @@ -59,8 +60,12 @@ def isExe(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,
Expand All @@ -73,6 +78,7 @@ def isExe(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])

0 comments on commit 196e6a4

Please sign in to comment.