OpenGL: Handle Spir-V

This commit is contained in:
Lynix
2020-04-19 15:31:48 +02:00
parent f63d045676
commit bd6924d66d
11 changed files with 3454 additions and 53 deletions

View File

@@ -53,11 +53,7 @@ namespace Nz
std::shared_ptr<ShaderStageImpl> OpenGLDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
{
auto shaderStage = std::make_shared<OpenGLShaderStage>();
if (!shaderStage->Create(*this, type, lang, source, sourceSize))
return {};
return shaderStage;
return std::make_shared<OpenGLShaderStage>(*this, type, lang, source, sourceSize);
}
std::unique_ptr<Texture> OpenGLDevice::InstantiateTexture(const TextureInfo& params)

View File

@@ -5,47 +5,39 @@
#include <Nazara/OpenGLRenderer/OpenGLShaderStage.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/OpenGLRenderer/Utils.hpp>
#include <stdexcept>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
bool OpenGLShaderStage::Create(OpenGLDevice& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
OpenGLShaderStage::OpenGLShaderStage(OpenGLDevice& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
{
if (!m_shader.Create(device, ToOpenGL(type)))
return false; //< TODO: Handle error message
throw std::runtime_error("failed to create shader"); //< TODO: Handle error message
switch (lang)
{
case ShaderLanguage::GLSL:
m_shader.SetSource(reinterpret_cast<const char*>(source), GLint(sourceSize));
m_shader.Compile();
break;
case ShaderLanguage::SpirV:
{
if (!device.GetReferenceContext().IsExtensionSupported("GL_ARB_gl_spirv"))
{
NazaraError("Spir-V is not supported");
return false;
}
if (!device.GetReferenceContext().IsExtensionSupported(GL::Extension::SpirV))
throw std::runtime_error("SpirV is not supported by this OpenGL implementation");
constexpr GLenum SHADER_BINARY_FORMAT_SPIR_V = 0x9551;
m_shader.SetBinarySource(SHADER_BINARY_FORMAT_SPIR_V, source, GLsizei(sourceSize));
m_shader.SetBinarySource(GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, source, GLsizei(sourceSize));
m_shader.SpecializeShader("main", 0U, nullptr, nullptr);
break;
}
default:
NazaraError("Unsupported shader language");
return false;
throw std::runtime_error("Unsupported shader language");
}
std::string errorLog;
if (!m_shader.Compile(&errorLog))
{
NazaraError("Failed to compile shader: " + errorLog);
return false;
}
return true;
if (!m_shader.GetCompilationStatus(&errorLog))
throw std::runtime_error("Failed to compile shader: " + errorLog);
}
}

View File

@@ -11,7 +11,8 @@
namespace Nz::GL
{
Context::~Context() = default;
thread_local const Context* s_currentContext = nullptr;
bool Context::Initialize(const ContextParams& params)
{
@@ -70,6 +71,10 @@ namespace Nz::GL
return true;
});
m_extensionStatus.fill(ExtensionStatus::NotSupported);
if (m_supportedExtensions.count("GL_ARB_gl_spirv"))
m_extensionStatus[UnderlyingCast(Extension::SpirV)] = ExtensionStatus::ARB;
#define NAZARA_OPENGLRENDERER_FUNC(name, sig)
#define NAZARA_OPENGLRENDERER_EXT_FUNC(name, sig) LoadSymbol(name, #name, false);
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_EXT_FUNC)