PostProcessing: Use ShaderGen GLSL version string

This commit is contained in:
Stenzek 2024-04-28 14:40:35 +10:00
parent 295081fe62
commit 5d20f4514d
No known key found for this signature in database
3 changed files with 21 additions and 17 deletions

View File

@ -1175,8 +1175,13 @@ bool PostProcessing::ReShadeFXShader::CompilePipeline(GPUTexture::Format format,
const char* precision = (api == RenderAPI::OpenGLES) ?
"precision highp float;\nprecision highp int;\nprecision highp sampler2D;\n" :
"";
real_code = fmt::format("#version {}\n#define ENTRY_POINT_{}\n{}\n{}\n{}",
(api == RenderAPI::OpenGLES) ? "320 es" : "460 core", name, defns, precision, code);
TinyString version_string = "#version 460 core\n";
#ifdef ENABLE_OPENGL
if (api == RenderAPI::OpenGL || api == RenderAPI::OpenGLES)
version_string = ShaderGen::GetGLSLVersionString(api);
#endif
real_code = fmt::format("{}\n#define ENTRY_POINT_{}\n{}\n{}\n{}", version_string, name, defns, precision, code);
for (const Sampler& sampler : samplers)
{

View File

@ -28,7 +28,7 @@ ShaderGen::ShaderGen(RenderAPI render_api, bool supports_dual_source_blend, bool
{
#ifdef ENABLE_OPENGL
if (m_render_api == RenderAPI::OpenGL || m_render_api == RenderAPI::OpenGLES)
SetGLSLVersionString();
m_glsl_version_string = GetGLSLVersionString(m_render_api);
m_use_glsl_interface_blocks = (IsVulkan() || IsMetal() || GLAD_GL_ES_VERSION_3_2 || GLAD_GL_VERSION_3_2);
m_use_glsl_binding_layout = (IsVulkan() || IsMetal() || UseGLSLBindingLayout());
@ -72,10 +72,10 @@ void ShaderGen::DefineMacro(std::stringstream& ss, const char* name, s32 value)
}
#ifdef ENABLE_OPENGL
void ShaderGen::SetGLSLVersionString()
TinyString ShaderGen::GetGLSLVersionString(RenderAPI render_api)
{
const char* glsl_version = reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION));
const bool glsl_es = (m_render_api == RenderAPI::OpenGLES);
const bool glsl_es = (render_api == RenderAPI::OpenGLES);
Assert(glsl_version != nullptr);
// Skip any strings in front of the version code.
@ -100,19 +100,16 @@ void ShaderGen::SetGLSLVersionString()
}
else
{
Log_ErrorPrintf("Invalid GLSL version string: '%s' ('%s')", glsl_version, glsl_version_start);
Log_ErrorFmt("Invalid GLSL version string: '{}' ('{}')", glsl_version, glsl_version_start);
if (glsl_es)
{
major_version = 3;
minor_version = 0;
}
m_glsl_version_string = glsl_es ? "300" : "130";
}
char buf[128];
std::snprintf(buf, sizeof(buf), "#version %d%02d%s", major_version, minor_version,
(glsl_es && major_version >= 3) ? " es" : "");
m_glsl_version_string = buf;
return TinyString::from_format("#version {}{:02d}{}", major_version, minor_version,
(glsl_es && major_version >= 3) ? " es" : "");
}
#endif

View File

@ -1,10 +1,12 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#pragma once
#include "gpu_device.h"
#include "common/small_string.h"
#include <sstream>
#include <string>
@ -16,6 +18,10 @@ public:
static bool UseGLSLBindingLayout();
#ifdef ENABLE_OPENGL
static TinyString GetGLSLVersionString(RenderAPI render_api);
#endif
std::string GenerateScreenQuadVertexShader(float z = 0.0f);
std::string GenerateUVQuadVertexShader();
std::string GenerateFillFragmentShader();
@ -31,10 +37,6 @@ protected:
const char* GetInterpolationQualifier(bool interface_block, bool centroid_interpolation, bool sample_interpolation,
bool is_out) const;
#ifdef ENABLE_OPENGL
void SetGLSLVersionString();
#endif
void DefineMacro(std::stringstream& ss, const char* name, bool enabled);
void DefineMacro(std::stringstream& ss, const char* name, s32 value);
void WriteHeader(std::stringstream& ss);
@ -64,5 +66,5 @@ protected:
bool m_use_glsl_binding_layout;
bool m_has_uniform_buffer = false;
std::string m_glsl_version_string;
TinyString m_glsl_version_string;
};