Add support for loading compiled Slang shaders

This commit is contained in:
Sascha Willems 2025-02-06 21:25:43 +01:00
parent 3ecc0d2e1f
commit a87dfde9cc
5 changed files with 16 additions and 13 deletions

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example base class * Vulkan Example base class
* *
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -790,7 +790,7 @@ VulkanExampleBase::VulkanExampleBase()
commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode"); commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode");
commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width"); commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width");
commandLineParser.add("height", { "-h", "--height" }, 1, "Set window height"); commandLineParser.add("height", { "-h", "--height" }, 1, "Set window height");
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl or hlsl)"); commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (gls, hlsl or slang)");
commandLineParser.add("gpuselection", { "-g", "--gpu" }, 1, "Select GPU to run on"); commandLineParser.add("gpuselection", { "-g", "--gpu" }, 1, "Select GPU to run on");
commandLineParser.add("gpulist", { "-gl", "--listgpus" }, 0, "Display a list of available Vulkan devices"); commandLineParser.add("gpulist", { "-gl", "--listgpus" }, 0, "Display a list of available Vulkan devices");
commandLineParser.add("benchmark", { "-b", "--benchmark" }, 0, "Run example in benchmark mode"); commandLineParser.add("benchmark", { "-b", "--benchmark" }, 0, "Run example in benchmark mode");
@ -828,8 +828,8 @@ VulkanExampleBase::VulkanExampleBase()
} }
if (commandLineParser.isSet("shaders")) { if (commandLineParser.isSet("shaders")) {
std::string value = commandLineParser.getValueAsString("shaders", "glsl"); std::string value = commandLineParser.getValueAsString("shaders", "glsl");
if ((value != "glsl") && (value != "hlsl")) { if ((value != "glsl") && (value != "hlsl") && (value != "slang")) {
std::cerr << "Shader type must be one of 'glsl' or 'hlsl'\n"; std::cerr << "Shader type must be one of 'glsl', 'hlsl' or 'slang'\n";
} }
else { else {
shaderDir = value; shaderDir = value;

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example base class * Vulkan Example base class
* *
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -92,7 +92,7 @@ private:
void destroyCommandBuffers(); void destroyCommandBuffers();
std::string shaderDir = "glsl"; std::string shaderDir = "glsl";
protected: protected:
// Returns the path to the root of the glsl or hlsl shader directory. // Returns the path to the root of the glsl, hlsl or slang shader directory.
std::string getShadersPath() const; std::string getShadersPath() const;
// Frame counter to display fps // Frame counter to display fps

View file

@ -1,4 +1,4 @@
# Copyright (c) 2016-2024, Sascha Willems # Copyright (c) 2016-2025, Sascha Willems
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# Function for building single example # Function for building single example
@ -28,15 +28,18 @@ function(buildExample EXAMPLE_NAME)
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") 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")
set(SHADER_DIR_HLSL "../shaders/hlsl/${EXAMPLE_NAME}") set(SHADER_DIR_HLSL "../shaders/hlsl/${EXAMPLE_NAME}")
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") 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")
set(SHADER_DIR_SLANG "../shaders/slang/${EXAMPLE_NAME}")
file(GLOB SHADERS_SLANG "${SHADER_DIR_SLANG}/*.slang")
source_group("Shaders\\GLSL" FILES ${SHADERS_GLSL}) source_group("Shaders\\GLSL" FILES ${SHADERS_GLSL})
source_group("Shaders\\HLSL" FILES ${SHADERS_HLSL}) source_group("Shaders\\HLSL" FILES ${SHADERS_HLSL})
source_group("Shaders\\SLANG" FILES ${SHADERS_SLANG})
# Add optional readme / tutorial # Add optional readme / tutorial
file(GLOB README_FILES "${EXAMPLE_FOLDER}/*.md") file(GLOB README_FILES "${EXAMPLE_FOLDER}/*.md")
if(WIN32) if(WIN32)
add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES}) add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${SHADERS_SLANG} ${README_FILES})
target_link_libraries(${EXAMPLE_NAME} base ${Vulkan_LIBRARY} ${WINLIBS}) target_link_libraries(${EXAMPLE_NAME} base ${Vulkan_LIBRARY} ${WINLIBS})
else(WIN32) else(WIN32)
add_executable(${EXAMPLE_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES}) add_executable(${EXAMPLE_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${SHADERS_SLANG} ${README_FILES})
target_link_libraries(${EXAMPLE_NAME} base ) target_link_libraries(${EXAMPLE_NAME} base )
endif(WIN32) endif(WIN32)

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example - Minimal headless compute example * Vulkan Example - Minimal headless compute example
* *
* Copyright (C) 2017-2022 by Sascha Willems - www.saschawillems.de * Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -607,7 +607,7 @@ void android_main(android_app* state) {
#else #else
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
commandLineParser.add("help", { "--help" }, 0, "Show help"); commandLineParser.add("help", { "--help" }, 0, "Show help");
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl or hlsl)"); commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl, hlsl or slang)");
commandLineParser.parse(argc, argv); commandLineParser.parse(argc, argv);
if (commandLineParser.isSet("help")) { if (commandLineParser.isSet("help")) {
commandLineParser.printHelp(); commandLineParser.printHelp();

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example - Minimal headless rendering example * Vulkan Example - Minimal headless rendering example
* *
* Copyright (C) 2017-2022 by Sascha Willems - www.saschawillems.de * Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -942,7 +942,7 @@ void android_main(android_app* state) {
#else #else
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
commandLineParser.add("help", { "--help" }, 0, "Show help"); commandLineParser.add("help", { "--help" }, 0, "Show help");
commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl or hlsl)"); commandLineParser.add("shaders", { "-s", "--shaders" }, 1, "Select shader type to use (glsl, hlsl or slang)");
commandLineParser.parse(argc, argv); commandLineParser.parse(argc, argv);
if (commandLineParser.isSet("help")) { if (commandLineParser.isSet("help")) {
commandLineParser.printHelp(); commandLineParser.printHelp();