mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-26 13:47:46 +00:00
Make glslang dependency optional
This is only needed for additional GLSL debug information, and is definitely not required.
This commit is contained in:
parent
6b1ec81cfd
commit
19cfedee5c
4 changed files with 44 additions and 28 deletions
|
@ -4,7 +4,7 @@
|
||||||
find_package(spirv_cross_core REQUIRED)
|
find_package(spirv_cross_core REQUIRED)
|
||||||
find_package(spirv_cross_glsl REQUIRED)
|
find_package(spirv_cross_glsl REQUIRED)
|
||||||
find_package(SPIRV-Headers REQUIRED)
|
find_package(SPIRV-Headers REQUIRED)
|
||||||
find_package(glslang REQUIRED)
|
find_package(glslang) # for additional debug information in the GLSL
|
||||||
|
|
||||||
add_library(renderer STATIC)
|
add_library(renderer STATIC)
|
||||||
target_sources(renderer
|
target_sources(renderer
|
||||||
|
@ -53,10 +53,16 @@ target_link_libraries(renderer
|
||||||
imgui
|
imgui
|
||||||
dxbc
|
dxbc
|
||||||
spirv-cross-core
|
spirv-cross-core
|
||||||
spirv-cross-glsl
|
spirv-cross-glsl)
|
||||||
glslang::SPIRV
|
|
||||||
glslang::glslang-default-resource-limits)
|
|
||||||
target_compile_definitions(renderer PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_ENABLE_EXPERIMENTAL)
|
target_compile_definitions(renderer PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_ENABLE_EXPERIMENTAL)
|
||||||
target_compile_options(renderer PUBLIC -fexceptions) # needed for spirv-cross and dxbc
|
target_compile_options(renderer PUBLIC -fexceptions) # needed for spirv-cross and dxbc
|
||||||
|
|
||||||
|
if (glslang_FOUND)
|
||||||
|
target_link_libraries(renderer
|
||||||
|
PUBLIC
|
||||||
|
glslang::SPIRV
|
||||||
|
glslang::glslang-default-resource-limits)
|
||||||
|
target_compile_definitions(renderer PRIVATE HAVE_GLSLANG)
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_library(Novus::Renderer ALIAS renderer)
|
add_library(Novus::Renderer ALIAS renderer)
|
|
@ -6,12 +6,11 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <glslang/Public/ShaderLang.h>
|
#include <physis.hpp>
|
||||||
#include <spirv.hpp>
|
#include <spirv.hpp>
|
||||||
#include <spirv_glsl.hpp>
|
#include <spirv_glsl.hpp>
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
struct physis_Shader;
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
class ShaderManager
|
class ShaderManager
|
||||||
|
@ -23,7 +22,7 @@ public:
|
||||||
VkShaderModule convertShaderModule(const physis_Shader &shader, spv::ExecutionModel executionModel);
|
VkShaderModule convertShaderModule(const physis_Shader &shader, spv::ExecutionModel executionModel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<uint32_t> compileGLSL(const std::string_view sourceString, const EShLanguage sourceLanguage);
|
std::vector<uint32_t> compileGLSL(std::string_view sourceString, ShaderStage stage);
|
||||||
|
|
||||||
Device &m_device;
|
Device &m_device;
|
||||||
};
|
};
|
|
@ -5,17 +5,11 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include <glm/ext/matrix_clip_space.hpp>
|
#include <glm/ext/matrix_clip_space.hpp>
|
||||||
#include <glslang/Public/ResourceLimits.h>
|
|
||||||
#include <glslang/Public/ShaderLang.h>
|
|
||||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
#include <spirv_glsl.hpp>
|
#include <spirv_glsl.hpp>
|
||||||
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "dxbc_module.h"
|
|
||||||
#include "dxbc_reader.h"
|
#include "dxbc_reader.h"
|
||||||
#include "rendermanager.h"
|
#include "rendermanager.h"
|
||||||
#include "swapchain.h"
|
#include "swapchain.h"
|
||||||
|
|
|
@ -5,12 +5,16 @@
|
||||||
|
|
||||||
#include <dxbc_module.h>
|
#include <dxbc_module.h>
|
||||||
#include <dxbc_reader.h>
|
#include <dxbc_reader.h>
|
||||||
#include <glslang/Public/ResourceLimits.h>
|
|
||||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
|
||||||
#include <glslang/SPIRV/Logger.h>
|
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
#include <spirv_glsl.hpp>
|
#include <spirv_glsl.hpp>
|
||||||
|
|
||||||
|
#ifdef HAVE_GLSLANG
|
||||||
|
#include <glslang/Public/ResourceLimits.h>
|
||||||
|
#include <glslang/Public/ShaderLang.h>
|
||||||
|
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||||
|
#include <glslang/SPIRV/Logger.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
ShaderManager::ShaderManager(Device &device)
|
ShaderManager::ShaderManager(Device &device)
|
||||||
|
@ -27,9 +31,7 @@ spirv_cross::CompilerGLSL ShaderManager::getShaderModuleResources(const physis_S
|
||||||
dxvk::DxbcModuleInfo info;
|
dxvk::DxbcModuleInfo info;
|
||||||
auto result = module.compile(info, "test");
|
auto result = module.compile(info, "test");
|
||||||
|
|
||||||
// glsl.build_combined_image_samplers();
|
return {result.code.data(), result.code.dwords()};
|
||||||
|
|
||||||
return spirv_cross::CompilerGLSL(result.code.data(), result.code.dwords());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkShaderModule ShaderManager::convertShaderModule(const physis_Shader &shader, spv::ExecutionModel executionModel)
|
VkShaderModule ShaderManager::convertShaderModule(const physis_Shader &shader, spv::ExecutionModel executionModel)
|
||||||
|
@ -41,6 +43,10 @@ VkShaderModule ShaderManager::convertShaderModule(const physis_Shader &shader, s
|
||||||
dxvk::DxbcModuleInfo info;
|
dxvk::DxbcModuleInfo info;
|
||||||
auto result = module.compile(info, "test");
|
auto result = module.compile(info, "test");
|
||||||
|
|
||||||
|
VkShaderModuleCreateInfo createInfo = {};
|
||||||
|
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||||
|
|
||||||
|
#ifdef HAVE_GLSLANG
|
||||||
// TODO: for debug only
|
// TODO: for debug only
|
||||||
spirv_cross::CompilerGLSL glsl(result.code.data(), result.code.dwords());
|
spirv_cross::CompilerGLSL glsl(result.code.data(), result.code.dwords());
|
||||||
|
|
||||||
|
@ -65,11 +71,7 @@ VkShaderModule ShaderManager::convertShaderModule(const physis_Shader &shader, s
|
||||||
} else if (texture.name == "v7") {
|
} else if (texture.name == "v7") {
|
||||||
glsl.set_name(texture.id, "BoneId");
|
glsl.set_name(texture.id, "BoneId");
|
||||||
}
|
}
|
||||||
// glsl.set_name(texture.id, shader.)
|
|
||||||
// qInfo() << shader.resource_parameters[i].name << texture.id;
|
|
||||||
// qInfo() << "stage input" << i << texture.name << glsl.get_type(texture.type_id).width;
|
|
||||||
i++;
|
i++;
|
||||||
// glsl.set_name(remap.combined_id, "SPIRV_Cross_Combined");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here you can also set up decorations if you want (binding = #N).
|
// Here you can also set up decorations if you want (binding = #N).
|
||||||
|
@ -93,12 +95,13 @@ VkShaderModule ShaderManager::convertShaderModule(const physis_Shader &shader, s
|
||||||
glsl.set_common_options(options);
|
glsl.set_common_options(options);
|
||||||
glsl.set_entry_point("main", executionModel);
|
glsl.set_entry_point("main", executionModel);
|
||||||
|
|
||||||
auto newModule = compileGLSL(glsl.compile(), executionModel == spv::ExecutionModelVertex ? EShLanguage::EShLangVertex : EShLanguage::EShLangFragment);
|
auto newModule = compileGLSL(glsl.compile(), executionModel == spv::ExecutionModelVertex ? ShaderStage::Vertex : ShaderStage::Pixel);
|
||||||
|
|
||||||
VkShaderModuleCreateInfo createInfo = {};
|
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
|
||||||
createInfo.codeSize = newModule.size() * sizeof(uint32_t);
|
createInfo.codeSize = newModule.size() * sizeof(uint32_t);
|
||||||
createInfo.pCode = reinterpret_cast<const uint32_t *>(newModule.data());
|
createInfo.pCode = reinterpret_cast<const uint32_t *>(newModule.data());
|
||||||
|
#else
|
||||||
|
createInfo.codeSize = result.code.size();
|
||||||
|
createInfo.pCode = reinterpret_cast<const uint32_t *>(result.code.data());
|
||||||
|
#endif
|
||||||
|
|
||||||
VkShaderModule shaderModule;
|
VkShaderModule shaderModule;
|
||||||
vkCreateShaderModule(m_device.device, &createInfo, nullptr, &shaderModule);
|
vkCreateShaderModule(m_device.device, &createInfo, nullptr, &shaderModule);
|
||||||
|
@ -106,8 +109,9 @@ VkShaderModule ShaderManager::convertShaderModule(const physis_Shader &shader, s
|
||||||
return shaderModule;
|
return shaderModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint32_t> ShaderManager::compileGLSL(const std::string_view sourceString, const EShLanguage sourceLanguage)
|
std::vector<uint32_t> ShaderManager::compileGLSL(const std::string_view sourceString, const ShaderStage stage)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_GLSLANG
|
||||||
static bool ProcessInitialized = false;
|
static bool ProcessInitialized = false;
|
||||||
|
|
||||||
if (!ProcessInitialized) {
|
if (!ProcessInitialized) {
|
||||||
|
@ -117,6 +121,16 @@ std::vector<uint32_t> ShaderManager::compileGLSL(const std::string_view sourceSt
|
||||||
|
|
||||||
const char *InputCString = sourceString.data();
|
const char *InputCString = sourceString.data();
|
||||||
|
|
||||||
|
EShLanguage sourceLanguage = EShLanguage::EShLangVertex;
|
||||||
|
switch (stage) {
|
||||||
|
case ShaderStage::Vertex:
|
||||||
|
sourceLanguage = EShLanguage::EShLangVertex;
|
||||||
|
break;
|
||||||
|
case ShaderStage::Pixel:
|
||||||
|
sourceLanguage = EShLanguage::EShLangFragment;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
glslang::TShader shader(sourceLanguage);
|
glslang::TShader shader(sourceLanguage);
|
||||||
shader.setStrings(&InputCString, 1);
|
shader.setStrings(&InputCString, 1);
|
||||||
|
|
||||||
|
@ -151,4 +165,7 @@ std::vector<uint32_t> ShaderManager::compileGLSL(const std::string_view sourceSt
|
||||||
glslang::GlslangToSpv(*Program.getIntermediate(sourceLanguage), SpirV, &logger, &spvOptions);
|
glslang::GlslangToSpv(*Program.getIntermediate(sourceLanguage), SpirV, &logger, &spvOptions);
|
||||||
|
|
||||||
return SpirV;
|
return SpirV;
|
||||||
|
#else
|
||||||
|
return {};
|
||||||
|
#endif
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue