gsdx ogl: use a set to store the supported extension

Split mandatory/optional extensions

Note: set is nice but likely much slower than reading a boolean
So both are kept
This commit is contained in:
Gregory Hainaut 2019-02-04 12:36:02 +01:00
parent e6b0a7828e
commit aed7ccaadf
3 changed files with 80 additions and 70 deletions

View File

@ -29,6 +29,23 @@ PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate = NUL
#include "PFN_GLLOADER_CPP.h" #include "PFN_GLLOADER_CPP.h"
namespace GLExtension {
static std::unordered_set<std::string> s_extensions;
bool Has(const std::string& ext)
{
return !!s_extensions.count(ext);
}
void Set(const std::string& ext, bool v)
{
if (v)
s_extensions.insert(ext);
else
s_extensions.erase(ext);
}
}
namespace ReplaceGL { namespace ReplaceGL {
void APIENTRY ScissorIndexed(GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height) void APIENTRY ScissorIndexed(GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height)
@ -141,24 +158,21 @@ namespace GLLoader {
bool found_GL_NVX_gpu_memory_info = false; bool found_GL_NVX_gpu_memory_info = false;
// Mandatory // Mandatory
bool found_GL_ARB_buffer_storage = false;
bool found_GL_ARB_clip_control = false;
bool found_GL_ARB_copy_image = false;
bool found_GL_ARB_direct_state_access = false; bool found_GL_ARB_direct_state_access = false;
bool found_GL_ARB_separate_shader_objects = false;
bool found_GL_ARB_shading_language_420pack = false;
bool found_GL_ARB_texture_barrier = false; bool found_GL_ARB_texture_barrier = false;
bool found_GL_ARB_texture_storage = false;
bool found_GL_KHR_debug = false;
static bool status_and_override(bool& found, const std::string& name, bool mandatory = false) static bool mandatory(const std::string& ext)
{ {
if (mandatory) { bool found = GLExtension::Has(ext);
if (!found) { if (!found)
fprintf(stderr, "ERROR: %s is NOT SUPPORTED\n", name.c_str()); fprintf(stderr, "ERROR: %s is NOT SUPPORTED\n", ext.c_str());
}
return found; return found;
} }
static bool optional(bool& found, const std::string& name)
{
found = GLExtension::Has(name);
if (s_first_load) { if (s_first_load) {
if (!found) { if (!found) {
@ -174,13 +188,14 @@ namespace GLLoader {
if (theApp.GetConfigI(opt.c_str()) != -1) { if (theApp.GetConfigI(opt.c_str()) != -1) {
found = theApp.GetConfigB(opt.c_str()); found = theApp.GetConfigB(opt.c_str());
fprintf(stderr, "Override %s detection (%s)\n", name.c_str(), found ? "Enabled" : "Disabled"); fprintf(stderr, "Override %s detection (%s)\n", name.c_str(), found ? "Enabled" : "Disabled");
GLExtension::Set(name);
} }
return true; return true;
} }
bool check_gl_version(int major, int minor) { bool check_gl_version(int major, int minor)
{
const GLubyte* s = glGetString(GL_VERSION); const GLubyte* s = glGetString(GL_VERSION);
if (s == NULL) { if (s == NULL) {
fprintf(stderr, "Error: GLLoader failed to get GL version\n"); fprintf(stderr, "Error: GLLoader failed to get GL version\n");
@ -223,6 +238,7 @@ namespace GLLoader {
if (theApp.GetConfigI("override_geometry_shader") != -1) { if (theApp.GetConfigI("override_geometry_shader") != -1) {
found_geometry_shader = theApp.GetConfigB("override_geometry_shader"); found_geometry_shader = theApp.GetConfigB("override_geometry_shader");
GLExtension::Set("GL_ARB_geometry_shader4", found_geometry_shader);
fprintf(stderr, "Overriding geometry shaders detection\n"); fprintf(stderr, "Overriding geometry shaders detection\n");
} }
@ -238,68 +254,60 @@ namespace GLLoader {
return true; return true;
} }
bool check_gl_supported_extension() { bool check_gl_supported_extension()
{
int max_ext = 0; int max_ext = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext); glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext);
if (glGetStringi && max_ext) { if (glGetStringi && max_ext) {
for (GLint i = 0; i < max_ext; i++) { for (GLint i = 0; i < max_ext; i++) {
std::string ext{(const char*)glGetStringi(GL_EXTENSIONS, i)}; std::string ext{(const char*)glGetStringi(GL_EXTENSIONS, i)};
// Bonus GLExtension::Set(ext);
if (ext.compare("GL_EXT_texture_filter_anisotropic") == 0) found_GL_EXT_texture_filter_anisotropic = true;
if (ext.compare("GL_NVX_gpu_memory_info") == 0) found_GL_NVX_gpu_memory_info = true;
// GL4.0
if (ext.compare("GL_ARB_gpu_shader5") == 0) found_GL_ARB_gpu_shader5 = true;
// GL4.1
if (ext.compare("GL_ARB_viewport_array") == 0) found_GL_ARB_viewport_array = true;
if (ext.compare("GL_ARB_separate_shader_objects") == 0) found_GL_ARB_separate_shader_objects = true;
// GL4.2
if (ext.compare("GL_ARB_shading_language_420pack") == 0) found_GL_ARB_shading_language_420pack = true;
if (ext.compare("GL_ARB_texture_storage") == 0) found_GL_ARB_texture_storage = true;
if (ext.compare("GL_ARB_shader_image_load_store") == 0) found_GL_ARB_shader_image_load_store = true;
// GL4.3
if (ext.compare("GL_ARB_copy_image") == 0) found_GL_ARB_copy_image = true;
if (ext.compare("GL_KHR_debug") == 0) found_GL_KHR_debug = true;
// GL4.4
if (ext.compare("GL_ARB_buffer_storage") == 0) found_GL_ARB_buffer_storage = true;
if (ext.compare("GL_ARB_clear_texture") == 0) found_GL_ARB_clear_texture = true;
// GL4.5
if (ext.compare("GL_ARB_direct_state_access") == 0) found_GL_ARB_direct_state_access = true;
if (ext.compare("GL_ARB_clip_control") == 0) found_GL_ARB_clip_control = true;
if (ext.compare("GL_ARB_texture_barrier") == 0) found_GL_ARB_texture_barrier = true;
if (ext.compare("GL_ARB_get_texture_sub_image") == 0) found_GL_ARB_get_texture_sub_image = true;
//fprintf(stderr, "DEBUG ext: %s\n", ext.c_str()); //fprintf(stderr, "DEBUG ext: %s\n", ext.c_str());
} }
} }
bool status = true; bool status = true;
bool required_for_hw = (theApp.GetCurrentRendererType() == GSRendererType::OGL_HW);
// Bonus // Mandatory for both renderer
status &= status_and_override(found_GL_EXT_texture_filter_anisotropic, "GL_EXT_texture_filter_anisotropic"); {
// GL4.0 // GL4.1
status &= status_and_override(found_GL_ARB_gpu_shader5, "GL_ARB_gpu_shader5"); status &= mandatory("GL_ARB_separate_shader_objects");
// GL4.1 // GL4.2
status &= status_and_override(found_GL_ARB_viewport_array, "GL_ARB_viewport_array"); status &= mandatory("GL_ARB_shading_language_420pack");
status &= status_and_override(found_GL_ARB_separate_shader_objects, "GL_ARB_separate_shader_objects", true); status &= mandatory("GL_ARB_texture_storage");
// GL4.2 // GL4.3
status &= status_and_override(found_GL_ARB_shader_image_load_store, "GL_ARB_shader_image_load_store"); status &= mandatory("GL_KHR_debug");
status &= status_and_override(found_GL_ARB_shading_language_420pack, "GL_ARB_shading_language_420pack", true); // GL4.4
status &= status_and_override(found_GL_ARB_texture_storage, "GL_ARB_texture_storage", true); status &= mandatory("GL_ARB_buffer_storage");
// GL4.3 }
status &= status_and_override(found_GL_ARB_copy_image, "GL_ARB_copy_image", required_for_hw);
status &= status_and_override(found_GL_KHR_debug, "GL_KHR_debug", true); // Only for HW renderer
// GL4.4 if (theApp.GetCurrentRendererType() == GSRendererType::OGL_HW) {
status &= status_and_override(found_GL_ARB_buffer_storage,"GL_ARB_buffer_storage", true); status &= mandatory("GL_ARB_copy_image");
status &= status_and_override(found_GL_ARB_clear_texture,"GL_ARB_clear_texture"); status &= mandatory("GL_ARB_clip_control");
// GL4.5 }
status &= status_and_override(found_GL_ARB_clip_control, "GL_ARB_clip_control", required_for_hw);
status &= status_and_override(found_GL_ARB_direct_state_access, "GL_ARB_direct_state_access"); // Extra
// Mandatory for the advance HW renderer effect. Unfortunately Mesa LLVMPIPE/SWR renderers doesn't support this extension. {
// Rendering might be corrupted but it could be good enough for test/virtual machine. // Bonus
status &= status_and_override(found_GL_ARB_texture_barrier, "GL_ARB_texture_barrier"); status &= optional(found_GL_EXT_texture_filter_anisotropic, "GL_EXT_texture_filter_anisotropic"); // ARB extension in 4.6
status &= status_and_override(found_GL_ARB_get_texture_sub_image, "GL_ARB_get_texture_sub_image"); // GL4.0
status &= optional(found_GL_ARB_gpu_shader5, "GL_ARB_gpu_shader5");
// GL4.1
status &= optional(found_GL_ARB_viewport_array, "GL_ARB_viewport_array");
// GL4.2
status &= optional(found_GL_ARB_shader_image_load_store, "GL_ARB_shader_image_load_store");
// GL4.3
// GL4.4
status &= optional(found_GL_ARB_clear_texture,"GL_ARB_clear_texture");
// GL4.5
status &= optional(found_GL_ARB_direct_state_access, "GL_ARB_direct_state_access");
// Mandatory for the advance HW renderer effect. Unfortunately Mesa LLVMPIPE/SWR renderers doesn't support this extension.
// Rendering might be corrupted but it could be good enough for test/virtual machine.
status &= optional(found_GL_ARB_texture_barrier, "GL_ARB_texture_barrier");
status &= optional(found_GL_ARB_get_texture_sub_image, "GL_ARB_get_texture_sub_image");
}
if (s_first_load) { if (s_first_load) {
if (vendor_id_amd) { if (vendor_id_amd) {

View File

@ -115,6 +115,10 @@ extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE #define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif #endif
namespace GLExtension {
extern bool Has(const std::string& ext);
extern void Set(const std::string& ext, bool v = true);
}
namespace GLLoader { namespace GLLoader {
void check_gl_requirements(); void check_gl_requirements();
@ -129,8 +133,6 @@ namespace GLLoader {
// GL // GL
extern bool found_geometry_shader; extern bool found_geometry_shader;
extern bool found_GL_ARB_copy_image;
extern bool found_GL_ARB_clip_control;
extern bool found_GL_ARB_gpu_shader5; extern bool found_GL_ARB_gpu_shader5;
extern bool found_GL_ARB_shader_image_load_store; extern bool found_GL_ARB_shader_image_load_store;
extern bool found_GL_ARB_clear_texture; extern bool found_GL_ARB_clear_texture;

View File

@ -498,7 +498,7 @@ bool GSDeviceOGL::Create(const std::shared_ptr<GSWnd> &wnd)
// This extension allow FS depth to range from -1 to 1. So // This extension allow FS depth to range from -1 to 1. So
// gl_position.z could range from [0, 1] // gl_position.z could range from [0, 1]
// Change depth convention // Change depth convention
if (GLLoader::found_GL_ARB_clip_control && glClipControl) if (GLExtension::Has("GL_ARB_clip_control"))
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
// **************************************************************** // ****************************************************************
@ -1234,7 +1234,7 @@ void GSDeviceOGL::CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r
PSSetShaderResource(6, sTex); PSSetShaderResource(6, sTex);
#endif #endif
ASSERT(GLLoader::found_GL_ARB_copy_image && glCopyImageSubData); ASSERT(GLExtension::Has("GL_ARB_copy_image") && glCopyImageSubData);
glCopyImageSubData( sid, GL_TEXTURE_2D, glCopyImageSubData( sid, GL_TEXTURE_2D,
0, r.x, r.y, 0, 0, r.x, r.y, 0,
did, GL_TEXTURE_2D, did, GL_TEXTURE_2D,