OpenGL: Handle Spir-V
This commit is contained in:
@@ -19,13 +19,11 @@ namespace Nz
|
||||
class NAZARA_OPENGLRENDERER_API OpenGLShaderStage : public ShaderStageImpl
|
||||
{
|
||||
public:
|
||||
OpenGLShaderStage() = default;
|
||||
OpenGLShaderStage(OpenGLDevice& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize);
|
||||
OpenGLShaderStage(const OpenGLShaderStage&) = delete;
|
||||
OpenGLShaderStage(OpenGLShaderStage&&) noexcept = default;
|
||||
~OpenGLShaderStage() = default;
|
||||
|
||||
bool Create(OpenGLDevice& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize);
|
||||
|
||||
OpenGLShaderStage& operator=(const OpenGLShaderStage&) = delete;
|
||||
OpenGLShaderStage& operator=(OpenGLShaderStage&&) noexcept = default;
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
#define NAZARA_OPENGLRENDERER_CONTEXTIMPL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -20,6 +22,22 @@ namespace Nz::GL
|
||||
OpenGL_ES
|
||||
};
|
||||
|
||||
enum class Extension
|
||||
{
|
||||
SpirV,
|
||||
|
||||
Max = SpirV
|
||||
};
|
||||
|
||||
enum class ExtensionStatus
|
||||
{
|
||||
NotSupported,
|
||||
|
||||
ARB,
|
||||
EXT,
|
||||
KHR
|
||||
};
|
||||
|
||||
struct ContextParams
|
||||
{
|
||||
ContextType type = ContextType::OpenGL_ES;
|
||||
@@ -44,8 +62,10 @@ namespace Nz::GL
|
||||
|
||||
virtual void EnableVerticalSync(bool enabled) = 0;
|
||||
|
||||
inline ExtensionStatus GetExtensionStatus(Extension extension) const;
|
||||
inline const ContextParams& GetParams() const;
|
||||
|
||||
inline bool IsExtensionSupported(Extension extension) const;
|
||||
inline bool IsExtensionSupported(const std::string& extension) const;
|
||||
|
||||
bool Initialize(const ContextParams& params);
|
||||
@@ -53,7 +73,7 @@ namespace Nz::GL
|
||||
virtual void SwapBuffers() = 0;
|
||||
|
||||
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) sig name = nullptr;
|
||||
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC)
|
||||
NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_FUNC)
|
||||
#undef NAZARA_OPENGLRENDERER_FUNC
|
||||
|
||||
static const Context* GetCurrentContext();
|
||||
@@ -73,6 +93,7 @@ namespace Nz::GL
|
||||
private:
|
||||
void GL_APIENTRY HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message) const;
|
||||
|
||||
std::array<ExtensionStatus, UnderlyingCast(Extension::Max) + 1> m_extensionStatus;
|
||||
std::unordered_set<std::string> m_supportedExtensions;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,11 +7,22 @@
|
||||
|
||||
namespace Nz::GL
|
||||
{
|
||||
|
||||
inline ExtensionStatus Context::GetExtensionStatus(Extension extension) const
|
||||
{
|
||||
return m_extensionStatus[UnderlyingCast(extension)];
|
||||
}
|
||||
|
||||
inline const ContextParams& Context::GetParams() const
|
||||
{
|
||||
return m_params;
|
||||
}
|
||||
|
||||
inline bool Context::IsExtensionSupported(Extension extension) const
|
||||
{
|
||||
return GetExtensionStatus(extension) != ExtensionStatus::NotSupported;
|
||||
}
|
||||
|
||||
inline bool Context::IsExtensionSupported(const std::string& extension) const
|
||||
{
|
||||
return m_supportedExtensions.find(extension) != m_supportedExtensions.end();
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#include <GLES3/gl32.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
// Define some OpenGL (not ES) extensions
|
||||
#define GL_SHADER_BINARY_FORMAT_SPIR_V_ARB 0x9551
|
||||
#define GL_SPIR_V_BINARY_ARB 0x9552
|
||||
typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERARBPROC) (GLuint shader, const GLchar* pEntryPoint, GLuint numSpecializationConstants, const GLuint* pConstantIndex, const GLuint* pConstantValue);
|
||||
|
||||
// OpenGL core
|
||||
#define NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(cb, extCb) \
|
||||
@@ -143,5 +147,7 @@
|
||||
cb(glViewport, PFNGLVIEWPORTPROC) \
|
||||
\
|
||||
extCb(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \
|
||||
\
|
||||
extCb(glSpecializeShaderARB, PFNGLSPECIALIZESHADERARBPROC) \
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,14 +21,19 @@ namespace Nz::GL
|
||||
Shader(Shader&&) noexcept = default;
|
||||
inline ~Shader();
|
||||
|
||||
inline bool Compile(std::string* error = nullptr);
|
||||
inline void Compile();
|
||||
|
||||
inline bool Create(OpenGLDevice& device, GLenum type);
|
||||
inline void Destroy();
|
||||
|
||||
inline bool GetCompilationStatus(std::string* error = nullptr);
|
||||
|
||||
inline void SetBinarySource(GLenum binaryFormat, const void* binary, GLsizei length);
|
||||
inline void SetSource(const char* source, GLint length);
|
||||
|
||||
// GL_ARB_gl_spirv
|
||||
inline void SpecializeShader(const GLchar* pEntryPoint, GLuint numSpecializationConstants, const GLuint* pConstantIndex, const GLuint* pConstantValue);
|
||||
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
Shader& operator=(Shader&&) noexcept = default;
|
||||
|
||||
|
||||
@@ -13,11 +13,37 @@ namespace Nz::GL
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline bool Shader::Compile(std::string* error)
|
||||
inline void Shader::Compile()
|
||||
{
|
||||
assert(m_shader);
|
||||
m_device->GetReferenceContext().glCompileShader(m_shader);
|
||||
}
|
||||
|
||||
inline bool Shader::Create(OpenGLDevice& device, GLenum type)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_device = &device;
|
||||
m_shader = device.GetReferenceContext().glCreateShader(type);
|
||||
if (!m_shader)
|
||||
return false; //< TODO: Handle error messages
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void Shader::Destroy()
|
||||
{
|
||||
if (m_shader)
|
||||
{
|
||||
m_device->GetReferenceContext().glDeleteShader(m_shader);
|
||||
m_shader = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool Shader::GetCompilationStatus(std::string* error)
|
||||
{
|
||||
assert(m_shader);
|
||||
const GL::Context& context = m_device->GetReferenceContext();
|
||||
context.glCompileShader(m_shader);
|
||||
|
||||
GLint success;
|
||||
context.glGetShaderiv(m_shader, GL_COMPILE_STATUS, &success);
|
||||
@@ -43,27 +69,6 @@ namespace Nz::GL
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Shader::Create(OpenGLDevice& device, GLenum type)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_device = &device;
|
||||
m_shader = device.GetReferenceContext().glCreateShader(type);
|
||||
if (!m_shader)
|
||||
return false; //< TODO: Handle error messages
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void Shader::Destroy()
|
||||
{
|
||||
if (m_shader)
|
||||
{
|
||||
m_device->GetReferenceContext().glDeleteShader(m_shader);
|
||||
m_shader = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Shader::SetBinarySource(GLenum binaryFormat, const void* binary, GLsizei length)
|
||||
{
|
||||
assert(m_shader);
|
||||
@@ -77,6 +82,15 @@ namespace Nz::GL
|
||||
|
||||
m_device->GetReferenceContext().glShaderSource(m_shader, 1U, &source, &length);
|
||||
}
|
||||
|
||||
inline void Shader::SpecializeShader(const GLchar* pEntryPoint, GLuint numSpecializationConstants, const GLuint* pConstantIndex, const GLuint* pConstantValue)
|
||||
{
|
||||
assert(m_shader);
|
||||
const GL::Context& context = m_device->GetReferenceContext();
|
||||
assert(context.glSpecializeShaderARB);
|
||||
|
||||
context.glSpecializeShaderARB(m_shader, pEntryPoint, numSpecializationConstants, pConstantIndex, pConstantValue);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user