summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorEgor <egor.yusov@gmail.com>2019-02-16 20:12:20 +0000
committerEgor <egor.yusov@gmail.com>2019-02-16 20:12:20 +0000
commita93c8f764724651c9fdfe059e20c7c714b355e9d (patch)
treed02fb7c46c10da1d38bfcd0c26616ac0ceca848a /Graphics
parentAdded Sam_ComparsionLinearClamp to common states (diff)
downloadDiligentCore-a93c8f764724651c9fdfe059e20c7c714b355e9d.tar.gz
DiligentCore-a93c8f764724651c9fdfe059e20c7c714b355e9d.zip
Fixed GLES3.0 context on Android
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GLSLTools/include/GLSLSourceBuilder.h8
-rw-r--r--Graphics/GLSLTools/src/GLSLSourceBuilder.cpp133
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp95
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm26
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp7
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp6
6 files changed, 135 insertions, 140 deletions
diff --git a/Graphics/GLSLTools/include/GLSLSourceBuilder.h b/Graphics/GLSLTools/include/GLSLSourceBuilder.h
index ed23535b..bfd6e55c 100644
--- a/Graphics/GLSLTools/include/GLSLSourceBuilder.h
+++ b/Graphics/GLSLTools/include/GLSLSourceBuilder.h
@@ -24,17 +24,21 @@
#pragma once
#include "BasicTypes.h"
+#include "DeviceCaps.h"
#include "Shader.h"
namespace Diligent
{
-
+
enum TargetGLSLCompiler
{
glslang,
driver
};
-String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs, TargetGLSLCompiler TargetCompiler, const char* ExtraDefinitions = nullptr);
+String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs,
+ const DeviceCaps& deviceCaps,
+ TargetGLSLCompiler TargetCompiler,
+ const char* ExtraDefinitions = nullptr);
} \ No newline at end of file
diff --git a/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp b/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp
index 1c0b2c30..3ac24f83 100644
--- a/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp
+++ b/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp
@@ -22,6 +22,7 @@
*/
#include <cstring>
+#include <sstream>
#include "GLSLSourceBuilder.h"
#include "DebugUtilities.h"
@@ -32,7 +33,10 @@
namespace Diligent
{
-String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs, TargetGLSLCompiler TargetCompiler, const char* ExtraDefinitions)
+String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs,
+ const DeviceCaps& deviceCaps,
+ TargetGLSLCompiler TargetCompiler,
+ const char* ExtraDefinitions)
{
String GLSLSource;
@@ -62,48 +66,17 @@ String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs, Targe
"#define DESKTOP_GL 1\n"
"#define PLATFORM_MACOS 1\n"
);
-#elif PLATFORM_IOS
- GLSLSource.append(
- "#version 300 es\n"
- "#extension GL_EXT_separate_shader_objects : enable\n"
- "#ifndef GL_ES\n"
- "# define GL_ES 1\n"
- "#endif\n"
-
- "#define PLATFORM_IOS 1\n"
- "precision highp float;\n"
- "precision highp int;\n"
- //"precision highp uint;\n"
-
- "precision highp sampler2D;\n"
- "precision highp sampler3D;\n"
- "precision highp samplerCube;\n"
- "precision highp samplerCubeShadow;\n"
- "precision highp sampler2DShadow;\n"
- "precision highp sampler2DArray;\n"
- "precision highp sampler2DArrayShadow;\n"
-
- "precision highp isampler2D;\n"
- "precision highp isampler3D;\n"
- "precision highp isamplerCube;\n"
- "precision highp isampler2DArray;\n"
-
- "precision highp usampler2D;\n"
- "precision highp usampler3D;\n"
- "precision highp usamplerCube;\n"
- "precision highp usampler2DArray;\n"
- );
+#elif PLATFORM_ANDROID || PLATFORM_IOS
+ std::stringstream versionss;
+ versionss << "#version " << deviceCaps.MajorVersion << deviceCaps.MinorVersion << "0 es\n";
+ GLSLSource.append(versionss.str());
- // Built-in variable 'gl_Position' must be redeclared before use, with separate shader objects.
- if (ShaderType == SHADER_TYPE_VERTEX)
- GLSLSource.append("out vec4 gl_Position;\n");
+ if (deviceCaps.bSeparableProgramSupported)
+ GLSLSource.append("#extension GL_EXT_separate_shader_objects : enable\n");
-#elif PLATFORM_ANDROID
- GLSLSource.append(
- "#version 310 es\n"
- "#extension GL_EXT_texture_cube_map_array : enable\n"
- );
+ if (deviceCaps.TexCaps.bCubemapArraysSupported)
+ GLSLSource.append("#extension GL_EXT_texture_cube_map_array : enable\n");
if (ShaderType == SHADER_TYPE_GEOMETRY)
GLSLSource.append("#extension GL_EXT_geometry_shader : enable\n");
@@ -115,9 +88,17 @@ String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs, Targe
"#ifndef GL_ES\n"
"# define GL_ES 1\n"
"#endif\n"
+ );
- "#define PLATFORM_ANDROID 1\n"
+#if PLATFORM_ANDROID
+ GLSLSource.append("#define PLATFORM_ANDROID 1\n");
+#elif PLATFORM_IOS
+ GLSLSource.append("#define PLATFORM_IOS 1\n");
+#else
+# error "Unexpected platform"
+#endif
+ GLSLSource.append(
"precision highp float;\n"
"precision highp int;\n"
//"precision highp uint;\n" // This line causes shader compilation error on NVidia!
@@ -125,46 +106,70 @@ String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs, Targe
"precision highp sampler2D;\n"
"precision highp sampler3D;\n"
"precision highp samplerCube;\n"
- "precision highp samplerCubeArray;\n"
"precision highp samplerCubeShadow;\n"
- "precision highp samplerCubeArrayShadow;\n"
+
"precision highp sampler2DShadow;\n"
"precision highp sampler2DArray;\n"
"precision highp sampler2DArrayShadow;\n"
- "precision highp sampler2DMS;\n" // ES3.1
"precision highp isampler2D;\n"
"precision highp isampler3D;\n"
"precision highp isamplerCube;\n"
- "precision highp isamplerCubeArray;\n"
"precision highp isampler2DArray;\n"
- "precision highp isampler2DMS;\n" // ES3.1
"precision highp usampler2D;\n"
"precision highp usampler3D;\n"
"precision highp usamplerCube;\n"
- "precision highp usamplerCubeArray;\n"
"precision highp usampler2DArray;\n"
- "precision highp usampler2DMS;\n" // ES3.1
-
- "precision highp image2D;\n"
- "precision highp image3D;\n"
- "precision highp imageCube;\n"
- "precision highp image2DArray;\n"
-
- "precision highp iimage2D;\n"
- "precision highp iimage3D;\n"
- "precision highp iimageCube;\n"
- "precision highp iimage2DArray;\n"
-
- "precision highp uimage2D;\n"
- "precision highp uimage3D;\n"
- "precision highp uimageCube;\n"
- "precision highp uimage2DArray;\n"
);
+
+ if (deviceCaps.TexCaps.bCubemapArraysSupported)
+ {
+ GLSLSource.append(
+ "precision highp samplerCubeArray;\n"
+ "precision highp samplerCubeArrayShadow;\n"
+ "precision highp isamplerCubeArray;\n"
+ "precision highp usamplerCubeArray;\n"
+ );
+ }
+
+ if (deviceCaps.TexCaps.bTexture2DMSSupported)
+ {
+ GLSLSource.append(
+ "precision highp sampler2DMS;\n"
+ "precision highp isampler2DMS;\n"
+ "precision highp usampler2DMS;\n"
+ );
+ }
+
+ if (deviceCaps.bComputeShadersSupported)
+ {
+ GLSLSource.append(
+ "precision highp image2D;\n"
+ "precision highp image3D;\n"
+ "precision highp imageCube;\n"
+ "precision highp image2DArray;\n"
+
+ "precision highp iimage2D;\n"
+ "precision highp iimage3D;\n"
+ "precision highp iimageCube;\n"
+ "precision highp iimage2DArray;\n"
+
+ "precision highp uimage2D;\n"
+ "precision highp uimage3D;\n"
+ "precision highp uimageCube;\n"
+ "precision highp uimage2DArray;\n"
+ );
+ }
+
+ // Built-in variable 'gl_Position' must be redeclared before use, with separate shader objects.
+ if (deviceCaps.bSeparableProgramSupported && ShaderType == SHADER_TYPE_VERTEX)
+ GLSLSource.append("out vec4 gl_Position;\n");
+
#elif
# error "Undefined platform"
#endif
+
// It would be much more convenient to use row_major matrices.
// But unfortunatelly on NVIDIA, the following directive
// layout(std140, row_major) uniform;
@@ -175,7 +180,7 @@ String BuildGLSLSourceString(const ShaderCreationAttribs& CreationAttribs, Targe
"layout(std140) uniform;\n"
);
- if(ShaderType == SHADER_TYPE_VERTEX && TargetCompiler == TargetGLSLCompiler::glslang)
+ if (ShaderType == SHADER_TYPE_VERTEX && TargetCompiler == TargetGLSLCompiler::glslang)
{
// https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_vulkan_glsl.txt
GLSLSource.append("#define gl_VertexID gl_VertexIndex\n"
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp
index a8f788ee..0e0f877e 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp
@@ -22,6 +22,7 @@
*/
#include "pch.h"
+#include <utility>
#include "GLContextAndroid.h"
#include "EngineGLAttribs.h"
@@ -131,23 +132,26 @@ namespace Diligent
bool GLContext::InitEGLContext()
{
- major_version_ = 3;
- minor_version_ = 1;
+ std::pair<int,int> es_versions[] = {{3,2}, {3,1}, {3,0}};
+ for(size_t i=0; i < _countof(es_versions) && context_ == EGL_NO_CONTEXT; ++i)
+ {
+ const auto& version = es_versions[i];
+ major_version_ = version.first;
+ minor_version_ = version.second;
- const EGLint context_attribs[] =
- {
- EGL_CONTEXT_CLIENT_VERSION, major_version_,
- EGL_CONTEXT_MINOR_VERSION_KHR, minor_version_,
- EGL_NONE
- };
+ const EGLint context_attribs[] =
+ {
+ EGL_CONTEXT_CLIENT_VERSION, major_version_,
+ EGL_CONTEXT_MINOR_VERSION_KHR, minor_version_,
+ EGL_NONE
+ };
- LOG_INFO_MESSAGE( "contextAttribs: ", context_attribs[0], ' ', context_attribs[1], '\n' );
- LOG_INFO_MESSAGE( "contextAttribs: ", context_attribs[2], ' ', context_attribs[3], '\n' );
+ context_ = eglCreateContext( display_, config_, NULL, context_attribs );
+ }
- context_ = eglCreateContext( display_, config_, NULL, context_attribs );
- if( context_ == EGL_NO_CONTEXT )
+ if (context_ == EGL_NO_CONTEXT)
{
- LOG_ERROR_AND_THROW( "Failed to create EGLContext" );
+ LOG_ERROR_AND_THROW("Failed to create EGLContext");
}
if( eglMakeCurrent( display_, surface_, surface_, context_ ) == EGL_FALSE )
@@ -155,6 +159,7 @@ namespace Diligent
LOG_ERROR_AND_THROW( "Unable to eglMakeCurrent" );
}
+ LOG_INFO_MESSAGE("Created OpenGLES Context ", major_version_, '.', minor_version_);
context_valid_ = true;
return true;
}
@@ -237,41 +242,6 @@ namespace Diligent
Init( NativeWindow );
FillDeviceCaps(DeviceCaps);
-#if 0
- // Creates table of supported extensions strings
- extensions.clear();
- string tmp;
- sint32 begin, end;
- tmp = string( (char*)glGetString( GL_EXTENSIONS ) );
-
- begin = 0;
- end = tmp.find( ' ', 0 );
-
- DEBUG_PRINT( _L( "Checking Extensions" ) );
-
- while( end != string::npos )
- {
- DEBUG_PRINT( (_L( "extension %s" )), tmp.substr( begin, end - begin ).c_str() );
- extensions.insert( extensions.end(), tmp.substr( begin, end - begin ) );
- begin = end + 1;
- end = tmp.find( ' ', begin );
- }
-
- if( supportExtension( "GL_INTEL_tessellation" ) )
- {
- glPatchParameteri = (PFNGLPATCHPARAMETERIPROC)eglGetProcAddress( "glPatchParameteri" );
- DEBUG_PRINT( _L( "%s = %p" ), "glPatchParameteri", (void*)glPatchParameteri );
- glPatchParameterfv = (PFNGLPATCHPARAMETERFVPROC)eglGetProcAddress( "glPatchParameterfv" );
- DEBUG_PRINT( _L( "%s = %p" ), "glPatchParameterfv", (void*)glPatchParameterfv );
- }
- //if(supportExtension("GL_INTEL_compute_shader"))
- {
- glDispatchCompute = (PFNGLDISPATCHCOMPUTEPROC)eglGetProcAddress( "glDispatchCompute" );
- DEBUG_PRINT( _L( "%s = %p" ), "glDispatchCompute", (void*)glDispatchCompute );
- glBindImageTexture = (PFNGLBINDIMAGETEXTUREPROC)eglGetProcAddress( "glBindImageTexture" );
- DEBUG_PRINT( _L( "%s = %p" ), "glBindImageTexture", (void*)glBindImageTexture );
- }
-#endif
}
GLContext::~GLContext()
@@ -417,25 +387,34 @@ namespace Diligent
void GLContext::FillDeviceCaps( DeviceCaps &DeviceCaps )
{
+ const auto* Extensions = (char*)glGetString(GL_EXTENSIONS);
+ LOG_INFO_MESSAGE( "Supported extensions: \n", Extensions);
+
DeviceCaps.DevType = DeviceType::OpenGLES;
DeviceCaps.MajorVersion = major_version_;
DeviceCaps.MinorVersion = minor_version_;
bool IsGLES31OrAbove = (major_version_ >= 4 || (major_version_ == 3 && minor_version_ >= 1) );
- DeviceCaps.bSeparableProgramSupported = IsGLES31OrAbove;
- DeviceCaps.bIndirectRenderingSupported = IsGLES31OrAbove;
+ bool IsGLES32OrAbove = (major_version_ >= 4 || (major_version_ == 3 && minor_version_ >= 2) );
+ DeviceCaps.bSeparableProgramSupported = IsGLES31OrAbove || strstr(Extensions, "separate_shader_objects");
+ DeviceCaps.bIndirectRenderingSupported = IsGLES31OrAbove || strstr(Extensions, "draw_indirect");
+
+ DeviceCaps.bComputeShadersSupported = IsGLES31OrAbove || strstr(Extensions, "compute_shader");
+ DeviceCaps.bGeometryShadersSupported = IsGLES32OrAbove || strstr(Extensions, "geometry_shader");
+ DeviceCaps.bTessellationSupported = IsGLES32OrAbove || strstr(Extensions, "tessellation_shader");
auto &SamCaps = DeviceCaps.SamCaps;
- SamCaps.bBorderSamplingModeSupported = GL_TEXTURE_BORDER_COLOR && IsGLES31OrAbove;
- SamCaps.bAnisotropicFilteringSupported = GL_TEXTURE_MAX_ANISOTROPY_EXT && IsGLES31OrAbove;
+ SamCaps.bBorderSamplingModeSupported = GL_TEXTURE_BORDER_COLOR && (IsGLES32OrAbove || strstr(Extensions, "texture_border_clamp"));
+ SamCaps.bAnisotropicFilteringSupported = GL_TEXTURE_MAX_ANISOTROPY_EXT && (IsGLES31OrAbove || strstr(Extensions, "texture_filter_anisotropic"));
SamCaps.bLODBiasSupported = GL_TEXTURE_LOD_BIAS && IsGLES31OrAbove;
auto &TexCaps = DeviceCaps.TexCaps;
- TexCaps.bTexture1DSupported = False; // Not supported in GLES 3.1
- TexCaps.bTexture1DArraySupported = False; // Not supported in GLES 3.1
- TexCaps.bTexture2DMSSupported = IsGLES31OrAbove;
- TexCaps.bTexture2DMSArraySupported = False; // Not supported in GLES 3.1
- TexCaps.bTextureViewSupported = False; // Not supported in GLES 3.1
- TexCaps.bCubemapArraysSupported = False; // Not supported in GLES 3.1
+ TexCaps.bTexture1DSupported = False; // Not supported in GLES 3.2
+ TexCaps.bTexture1DArraySupported = False; // Not supported in GLES 3.2
+ TexCaps.bTexture2DMSSupported = IsGLES31OrAbove || strstr(Extensions, "texture_storage_multisample");
+ TexCaps.bTexture2DMSArraySupported = IsGLES32OrAbove || strstr(Extensions, "texture_storage_multisample_2d_array");
+ TexCaps.bTextureViewSupported = IsGLES31OrAbove || strstr(Extensions, "texture_view");
+ TexCaps.bCubemapArraysSupported = IsGLES32OrAbove || strstr(Extensions, "texture_cube_map_array");
+
DeviceCaps.bMultithreadedResourceCreationSupported = False;
}
}
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm b/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm
index 1992d19b..5567eb0e 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextIOS.mm
@@ -70,19 +70,21 @@ namespace Diligent
DeviceCaps.MajorVersion = MajorVersion;
DeviceCaps.MinorVersion = MinorVersion;
DeviceCaps.bMultithreadedResourceCreationSupported = False;
- DeviceCaps.bIndirectRenderingSupported = False;
- DeviceCaps.bGeometryShadersSupported = False;
- DeviceCaps.bTessellationSupported = False;
- DeviceCaps.bWireframeFillSupported = False;
- DeviceCaps.bComputeShadersSupported = False;
- DeviceCaps.SamCaps.bLODBiasSupported = False;
+ DeviceCaps.bIndirectRenderingSupported = False;
+ DeviceCaps.bGeometryShadersSupported = False;
+ DeviceCaps.bTessellationSupported = False;
+ DeviceCaps.bWireframeFillSupported = False;
+ DeviceCaps.bComputeShadersSupported = False;
+
+ DeviceCaps.SamCaps.bLODBiasSupported = False;
DeviceCaps.SamCaps.bBorderSamplingModeSupported = False;
- DeviceCaps.TexCaps.bTexture1DSupported = False;
- DeviceCaps.TexCaps.bCubemapArraysSupported = False;
- DeviceCaps.TexCaps.bTexture1DSupported = False;
- DeviceCaps.TexCaps.bTexture1DArraySupported = False;
- DeviceCaps.TexCaps.bTextureViewSupported = False;
- DeviceCaps.TexCaps.bTexture2DMSSupported = False;
+
+ DeviceCaps.TexCaps.bTexture1DSupported = False;
+ DeviceCaps.TexCaps.bCubemapArraysSupported = False;
+ DeviceCaps.TexCaps.bTexture1DSupported = False;
+ DeviceCaps.TexCaps.bTexture1DArraySupported = False;
+ DeviceCaps.TexCaps.bTextureViewSupported = False;
+ DeviceCaps.TexCaps.bTexture2DMSSupported = False;
DeviceCaps.TexCaps.bTexture2DMSArraySupported = False;
}
diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp
index a7a24800..a1c1cd20 100644
--- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp
@@ -33,12 +33,15 @@ using namespace Diligent;
namespace Diligent
{
-ShaderGLImpl::ShaderGLImpl(IReferenceCounters *pRefCounters, RenderDeviceGLImpl *pDeviceGL, const ShaderCreationAttribs &CreationAttribs, bool bIsDeviceInternal) :
+ShaderGLImpl::ShaderGLImpl(IReferenceCounters* pRefCounters,
+ RenderDeviceGLImpl* pDeviceGL,
+ const ShaderCreationAttribs& CreationAttribs,
+ bool bIsDeviceInternal) :
TShaderBase( pRefCounters, pDeviceGL, CreationAttribs.Desc, bIsDeviceInternal ),
m_GlProgObj(false),
m_GLShaderObj( false, GLObjectWrappers::GLShaderObjCreateReleaseHelper( GetGLShaderType( m_Desc.ShaderType ) ) )
{
- auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::driver);
+ auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pDeviceGL->GetDeviceCaps(), TargetGLSLCompiler::driver);
// Note: there is a simpler way to create the program:
//m_uiShaderSeparateProg = glCreateShaderProgramv(GL_VERTEX_SHADER, _countof(ShaderStrings), ShaderStrings);
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index b0058a8f..fef2d052 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -37,7 +37,9 @@
namespace Diligent
{
-ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pRenderDeviceVk, const ShaderCreationAttribs& CreationAttribs) :
+ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters,
+ RenderDeviceVkImpl* pRenderDeviceVk,
+ const ShaderCreationAttribs& CreationAttribs) :
TShaderBase (pRefCounters, pRenderDeviceVk, CreationAttribs.Desc),
m_StaticResLayout (*this, pRenderDeviceVk->GetLogicalDevice()),
m_StaticResCache (ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources),
@@ -57,7 +59,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl*
}
else
{
- auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n");
+ auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pRenderDeviceVk->GetDeviceCaps(), TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n");
m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), static_cast<int>(GLSLSource.length()), CreationAttribs.ppCompilerOutput);
}