Skip to content

Commit a87dfde

Browse files
committed
Add support for loading compiled Slang shaders
1 parent 3ecc0d2 commit a87dfde

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

base/vulkanexamplebase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan Example base class
33
*
4-
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -790,7 +790,7 @@ VulkanExampleBase::VulkanExampleBase()
790790
commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode");
791791
commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width");
792792
commandLineParser.add("height", { "-h", "--height" }, 1, "Set window height");
793-
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl or hlsl)");
793+
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (gls, hlsl or slang)");
794794
commandLineParser.add("gpuselection", { "-g", "--gpu" }, 1, "Select GPU to run on");
795795
commandLineParser.add("gpulist", { "-gl", "--listgpus" }, 0, "Display a list of available Vulkan devices");
796796
commandLineParser.add("benchmark", { "-b", "--benchmark" }, 0, "Run example in benchmark mode");
@@ -828,8 +828,8 @@ VulkanExampleBase::VulkanExampleBase()
828828
}
829829
if (commandLineParser.isSet("shaders")) {
830830
std::string value = commandLineParser.getValueAsString("shaders", "glsl");
831-
if ((value != "glsl") && (value != "hlsl")) {
832-
std::cerr << "Shader type must be one of 'glsl' or 'hlsl'\n";
831+
if ((value != "glsl") && (value != "hlsl") && (value != "slang")) {
832+
std::cerr << "Shader type must be one of 'glsl', 'hlsl' or 'slang'\n";
833833
}
834834
else {
835835
shaderDir = value;

base/vulkanexamplebase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan Example base class
33
*
4-
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -92,7 +92,7 @@ class VulkanExampleBase
9292
void destroyCommandBuffers();
9393
std::string shaderDir = "glsl";
9494
protected:
95-
// Returns the path to the root of the glsl or hlsl shader directory.
95+
// Returns the path to the root of the glsl, hlsl or slang shader directory.
9696
std::string getShadersPath() const;
9797

9898
// Frame counter to display fps

examples/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016-2024, Sascha Willems
1+
# Copyright (c) 2016-2025, Sascha Willems
22
# SPDX-License-Identifier: MIT
33

44
# Function for building single example
@@ -28,15 +28,18 @@ function(buildExample EXAMPLE_NAME)
2828
file(GLOB SHADERS_GLSL "${SHADER_DIR_GLSL}/*.vert" "${SHADER_DIR_GLSL}/*.frag" "${SHADER_DIR_GLSL}/*.comp" "${SHADER_DIR_GLSL}/*.geom" "${SHADER_DIR_GLSL}/*.tesc" "${SHADER_DIR_GLSL}/*.tese" "${SHADER_DIR_GLSL}/*.mesh" "${SHADER_DIR_GLSL}/*.task" "${SHADER_DIR_GLSL}/*.rgen" "${SHADER_DIR_GLSL}/*.rchit" "${SHADER_DIR_GLSL}/*.rmiss" "${SHADER_DIR_GLSL}/*.rcall" "${SHADER_DIR_GLSL}/*.rahit" "${SHADER_DIR_GLSL}/*.rint" "${SHADER_DIR_GLSL}/*.glsl")
2929
set(SHADER_DIR_HLSL "../shaders/hlsl/${EXAMPLE_NAME}")
3030
file(GLOB SHADERS_HLSL "${SHADER_DIR_HLSL}/*.vert" "${SHADER_DIR_HLSL}/*.frag" "${SHADER_DIR_HLSL}/*.comp" "${SHADER_DIR_HLSL}/*.geom" "${SHADER_DIR_HLSL}/*.tesc" "${SHADER_DIR_HLSL}/*.tese" "${SHADER_DIR_HLSL}/*.mesh" "${SHADER_DIR_HLSL}/*.task" "${SHADER_DIR_HLSL}/*.rgen" "${SHADER_DIR_HLSL}/*.rchit" "${SHADER_DIR_HLSL}/*.rmiss" "${SHADER_DIR_HLSL}/*.rcall" "${SHADER_DIR_HLSL}/*.rahit" "${SHADER_DIR_HLSL}/*.rint")
31+
set(SHADER_DIR_SLANG "../shaders/slang/${EXAMPLE_NAME}")
32+
file(GLOB SHADERS_SLANG "${SHADER_DIR_SLANG}/*.slang")
3133
source_group("Shaders\\GLSL" FILES ${SHADERS_GLSL})
3234
source_group("Shaders\\HLSL" FILES ${SHADERS_HLSL})
35+
source_group("Shaders\\SLANG" FILES ${SHADERS_SLANG})
3336
# Add optional readme / tutorial
3437
file(GLOB README_FILES "${EXAMPLE_FOLDER}/*.md")
3538
if(WIN32)
36-
add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES})
39+
add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${SHADERS_SLANG} ${README_FILES})
3740
target_link_libraries(${EXAMPLE_NAME} base ${Vulkan_LIBRARY} ${WINLIBS})
3841
else(WIN32)
39-
add_executable(${EXAMPLE_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES})
42+
add_executable(${EXAMPLE_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${SHADERS_SLANG} ${README_FILES})
4043
target_link_libraries(${EXAMPLE_NAME} base )
4144
endif(WIN32)
4245

examples/computeheadless/computeheadless.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan Example - Minimal headless compute example
33
*
4-
* Copyright (C) 2017-2022 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -607,7 +607,7 @@ void android_main(android_app* state) {
607607
#else
608608
int main(int argc, char* argv[]) {
609609
commandLineParser.add("help", { "--help" }, 0, "Show help");
610-
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl or hlsl)");
610+
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl, hlsl or slang)");
611611
commandLineParser.parse(argc, argv);
612612
if (commandLineParser.isSet("help")) {
613613
commandLineParser.printHelp();

examples/renderheadless/renderheadless.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan Example - Minimal headless rendering example
33
*
4-
* Copyright (C) 2017-2022 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -942,7 +942,7 @@ void android_main(android_app* state) {
942942
#else
943943
int main(int argc, char* argv[]) {
944944
commandLineParser.add("help", { "--help" }, 0, "Show help");
945-
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl or hlsl)");
945+
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl, hlsl or slang)");
946946
commandLineParser.parse(argc, argv);
947947
if (commandLineParser.isSet("help")) {
948948
commandLineParser.printHelp();

0 commit comments

Comments
 (0)