Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glslang support #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ jobs:
- name: Install Doxygen
run: sudo apt install doxygen graphviz
- name: Install Vulkan
uses: humbletim/install-vulkan-sdk@v1.1.1
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
version: latest
vulkan-query-version: 1.3.224.1
vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang
vulkan-use-cache: true
- name: Configure VulkanSceneGraph
run: cmake -S . -B . -DCMAKE_BUILD_TYPE=Release
- name: Build Documentation
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
env:
BuildDocEnabled: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
CMakeVersion: 3.10.x
CMakeVersion: 3.24.x
jobs:
build:
runs-on: ${{ matrix.os }}
Expand All @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.12
uses: jwlawson/actions-setup-cmake@v1.14.1
with:
cmake-version: ${{ env.CMakeVersion }}
- name: Setup NDK
Expand All @@ -28,5 +28,5 @@ jobs:
- name: Build and Install VSG
shell: bash
run: |
cmake . -DCMAKE_TOOLCHAIN_FILE=$(dirname $(which ndk-build))/build/cmake/android.toolchain.cmake -DANDROID_ABI=${{matrix.android-abi}} -DANDROID_PLATFORM=${{matrix.android-platform}} -DBUILD_SHARED_LIBS=${{matrix.build-shared}} -DCMAKE_INSTALL_PREFIX=./install
cmake . -DCMAKE_TOOLCHAIN_FILE=$(dirname $(which ndk-build))/build/cmake/android.toolchain.cmake -DANDROID_ABI=${{matrix.android-abi}} -DANDROID_PLATFORM=${{matrix.android-platform}} -DBUILD_SHARED_LIBS=${{matrix.build-shared}} -DCMAKE_INSTALL_PREFIX=./install -DVSG_USE_SYSTEM_GLSLANG=0
cmake --build . --target install --config Release
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
env:
BuildDocEnabled: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
CMakeVersion: 3.10.x
CMakeVersion: 3.24.x
jobs:
build:
runs-on: ${{ matrix.os }}
Expand All @@ -22,14 +22,15 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.12
uses: jwlawson/actions-setup-cmake@v1.14.1
with:
cmake-version: ${{ env.CMakeVersion }}
- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@v1.1.1
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
version: ${{ matrix.vulkan-version }}
cache: true
vulkan-query-version: ${{ matrix.vulkan-version }}
vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang
vulkan-use-cache: true
- name: Add MSBuild to PATH
uses: microsoft/[email protected]
if: startsWith(matrix.os, 'windows')
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/win-cygwin-mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@v1.1.1
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
version: latest
cache: true
vulkan-query-version: latest
vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang
vulkan-use-cache: true

- uses: msys2/setup-msys2@v2
with:
Expand All @@ -34,10 +35,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@v1.1.1
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
version: latest
cache: true
vulkan-query-version: latest
vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang
vulkan-use-cache: true

- uses: msys2/setup-msys2@v2
with:
Expand Down
53 changes: 30 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.24)

project(vsg
VERSION 1.1.0
Expand Down Expand Up @@ -37,29 +37,36 @@ find_package(Vulkan ${Vulkan_MIN_VERSION} REQUIRED)

find_package(Threads REQUIRED)

# Enable/disable shader compilation support that pulls in glslang
set(VSG_SUPPORTS_ShaderCompiler 1 CACHE STRING "Optional shader compiler support, 0 for off, 1 for enabled." )
if (VSG_SUPPORTS_ShaderCompiler)
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/glslang/build_vars.cmake)

if (Git_FOUND)

set(glslang_URL "https://github.com/vsg-dev/glslang.git" CACHE STRING "URL of the glslang git repository")
set(glslang_branch "VSG-1.0.x" CACHE STRING "branch/tag of the glslang git repository")

execute_process(COMMAND ${GIT_EXECUTABLE} clone --depth 1 --branch ${glslang_branch} ${glslang_URL}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
RESULT_VARIABLE GIT_SUBMOD_RESULT)

if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(WARNING "git clone of glslang failed. ShaderCompile support disabled.")
set(VSG_SUPPORTS_ShaderCompiler 0)
set(VSG_USE_SYSTEM_GLSLANG 1 CACHE STRING "Use system installed glslang, 0 for off, 1 for enabled." )
set(GLSLANG_VERSION 13.1.1)
if (VSG_USE_SYSTEM_GLSLANG)
add_definitions(-DVSG_USE_SYSTEM_GLSLANG)
find_package(glslang REQUIRED ${GLSLANG_VERSION})
else ()
cmake_policy(SET CMP0135 NEW) # use DOWNLOAD_EXTRACT_TIMESTAMP
set(ENABLE_OPT OFF CACHE BOOL "")
include(FetchContent)
FetchContent_Declare(glslang
URL https://github.com/KhronosGroup/glslang/archive/refs/tags/${GLSLANG_VERSION}.zip
URL_HASH SHA3_256=4b01f8b92754eb6ea2aee3747fba25a9439a37d69c24058222ec920b132a172a
SOURCE_DIR fetched/glslang
)
# Like `FetchContent_MakeAvailable` but passes EXCLUDE_FROM_ALL to `add_subdirectory`.
macro(FetchContent_MakeAvailableExcludeFromAll)
foreach(contentName IN ITEMS ${ARGV})
string(TOLOWER ${contentName} contentNameLower)
FetchContent_GetProperties(${contentName})
if(NOT ${contentNameLower}_POPULATED)
FetchContent_Populate(${contentName})
if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt)
add_subdirectory(${${contentNameLower}_SOURCE_DIR}
${${contentNameLower}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
else()
message(WARNING "git clone of glslang failed. ShaderCompile support disabled.")
set(VSG_SUPPORTS_ShaderCompiler 0)
endif()
endif()
endforeach()
endmacro()
FetchContent_MakeAvailableExcludeFromAll(glslang)

endif()

set(VSG_SUPPORTS_Windowing 1 CACHE STRING "Optional native windowing support providing a default implementation of vsg::Window::create(), 0 for off, 1 for enabled." )
Expand Down
1 change: 1 addition & 0 deletions src/vsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ endif()
set(LIBRARIES PUBLIC
Vulkan::Vulkan
Threads::Threads
glslang
)

# Check for std::atomic
Expand Down
28 changes: 6 additions & 22 deletions src/vsg/utils/ShaderCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/state/GraphicsPipeline.h>
#include <vsg/utils/ShaderCompiler.h>

#if VSG_SUPPORTS_ShaderCompiler
# include <SPIRV/GlslangToSpv.h>
# include <glslang/Public/ResourceLimits.h>
# include <glslang/Public/ShaderLang.h>
#if VSG_USE_SYSTEM_GLSLANG
# include <glslang/SPIRV/GlslangToSpv.h>
#else
# include <SPIRV/GlslangToSpv.h>
#endif
#include <glslang/Public/ResourceLimits.h>
#include <glslang/Public/ShaderLang.h>

#include <algorithm>
#include <iomanip>
Expand All @@ -35,7 +37,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

using namespace vsg;

#if VSG_SUPPORTS_ShaderCompiler
static std::atomic_uint s_initialized = 0;

static void s_initializeProcess()
Expand All @@ -54,8 +55,6 @@ static void s_finalizeProcess()
}
}

#endif

std::string debugFormatShaderSource(const std::string& source)
{
std::istringstream iss(source);
Expand All @@ -79,17 +78,9 @@ ShaderCompiler::ShaderCompiler() :

ShaderCompiler::~ShaderCompiler()
{
#if VSG_SUPPORTS_ShaderCompiler
s_finalizeProcess();
#endif
}

bool ShaderCompiler::supported() const
{
return VSG_SUPPORTS_ShaderCompiler == 1;
}

#if VSG_SUPPORTS_ShaderCompiler
bool ShaderCompiler::compile(ShaderStages& shaders, const std::vector<std::string>& defines, ref_ptr<const Options> options)
{
// need to balance the inits.
Expand Down Expand Up @@ -290,13 +281,6 @@ bool ShaderCompiler::compile(ShaderStages& shaders, const std::vector<std::strin

return true;
}
#else
bool ShaderCompiler::compile(ShaderStages&, const std::vector<std::string>&, ref_ptr<const Options> /*options*/)
{
warn("ShaderCompile::compile(..) not supported,");
return false;
}
#endif

bool ShaderCompiler::compile(ref_ptr<ShaderStage> shaderStage, const std::vector<std::string>& defines, ref_ptr<const Options> options)
{
Expand Down
3 changes: 0 additions & 3 deletions src/vsg/vk/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,13 @@ ShaderCompiler* Context::getOrCreateShaderCompiler()
{
if (shaderCompiler) return shaderCompiler;

#if VSG_SUPPORTS_ShaderCompiler
shaderCompiler = ShaderCompiler::create();

if (device && device->getInstance())
{
shaderCompiler->defaults->vulkanVersion = device->getInstance()->apiVersion;
}

#endif

return shaderCompiler;
}

Expand Down
Loading