Permalink
Browse files

Merge pull request #11182 from unknownbrackets/postshader

GLES: Use accurate GLSL ver in postshader convert
  • Loading branch information...
hrydgard committed Jun 15, 2018
2 parents e03aeba + 0d2de36 commit 53f0f136ac2ca66fa62d8ebf45015fb6ef6b97e2
Showing with 20 additions and 14 deletions.
  1. +1 −5 GPU/Common/ShaderTranslation.cpp
  2. +18 −9 ext/native/gfx_es2/gpu_features.cpp
  3. +1 −0 ext/native/gfx_es2/gpu_features.h
@@ -310,11 +310,7 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade
spirv_cross::ShaderResources resources = glsl.get_shader_resources();
// Set some options.
spirv_cross::CompilerGLSL::Options options;
if (gl_extensions.ver[0] >= 4) {
options.version = 400;
} else {
options.version = 300;
}
options.version = gl_extensions.GLSLVersion();
glsl.set_options(options);
// Compile to GLSL, ready to give to GL driver.
*dest = glsl.compile();
@@ -54,6 +54,23 @@ bool GLExtensions::VersionGEThan(int major, int minor, int sub) {
return gl_extensions.ver[2] >= sub;
}
int GLExtensions::GLSLVersion() {
// Used for shader translation and core contexts (Apple drives fail without an exact match.)
if (gl_extensions.VersionGEThan(3, 3)) {
return gl_extensions.ver[0] * 100 + gl_extensions.ver[1] * 10;
} else if (gl_extensions.VersionGEThan(3, 2)) {
return 150;
} else if (gl_extensions.VersionGEThan(3, 1)) {
return 140;
} else if (gl_extensions.VersionGEThan(3, 0)) {
return 130;
} else if (gl_extensions.VersionGEThan(2, 1)) {
return 120;
} else {
return 110;
}
}
void ProcessGPUFeatures() {
gl_extensions.bugs = 0;
@@ -505,15 +522,7 @@ std::string ApplyGLSLPrelude(const std::string &source, uint32_t stage) {
std::string version = "";
if (!gl_extensions.IsGLES && gl_extensions.IsCoreContext) {
// We need to add a corresponding #version. Apple drives fail without an exact match.
if (gl_extensions.VersionGEThan(3, 3)) {
version = StringFromFormat("#version %d%d0\n", gl_extensions.ver[0], gl_extensions.ver[1]);
} else if (gl_extensions.VersionGEThan(3, 2)) {
version = "#version 150\n";
} else if (gl_extensions.VersionGEThan(3, 1)) {
version = "#version 140\n";
} else {
version = "#version 130\n";
}
version = StringFromFormat("#version %d\n", gl_extensions.GLSLVersion());
}
if (stage == GL_FRAGMENT_SHADER) {
temp = version + glsl_fragment_prelude + source;
@@ -103,6 +103,7 @@ struct GLExtensions {
// greater-or-equal than
bool VersionGEThan(int major, int minor, int sub = 0);
int GLSLVersion();
};
extern GLExtensions gl_extensions;

0 comments on commit 53f0f13

Please sign in to comment.