blob: da3c859b3f59c9288e9daaa2c03664b561a75860 [file] [log] [blame]
/*-------------------------------------------------------------------------
* drawElements Quality Program EGL Module
* ---------------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief EGL gles2 sharing threaded tests
*//*--------------------------------------------------------------------*/
#include "teglGLES2SharingThreadedTests.hpp"
#include "tcuTestLog.hpp"
#include "tcuThreadUtil.hpp"
#include "deRandom.hpp"
#include "deThread.hpp"
#include "deSharedPtr.hpp"
#include "deMutex.hpp"
#include "deSemaphore.hpp"
#include "deStringUtil.hpp"
#include "deClock.h"
#include "deString.h"
#include "deMemory.h"
#include "deMath.h"
#include "gluDefs.hpp"
#include "glwEnums.hpp"
#include "glwFunctions.hpp"
#include "egluUtil.hpp"
#include "eglwLibrary.hpp"
#include "eglwEnums.hpp"
#include <vector>
#include <string>
#include <memory>
#include <sstream>
using std::vector;
using std::string;
using de::SharedPtr;
using namespace glw;
using namespace eglw;
namespace deqp
{
namespace egl
{
namespace GLES2ThreadTest
{
class Texture;
class Buffer;
class Shader;
class Program;
class GLES2ResourceManager
{
public:
SharedPtr<Texture> popTexture (int index);
const SharedPtr<Texture> getTexture (int index) const { return m_textures[index]; }
void addTexture (SharedPtr<Texture> texture) { m_textures.push_back(texture); }
int getTextureCount (void) const { return (int)m_textures.size(); }
SharedPtr<Buffer> popBuffer (int index);
const SharedPtr<Buffer> getBuffer (int index) const { return m_buffers[index]; }
void addBuffer (SharedPtr<Buffer> buffer) { m_buffers.push_back(buffer); }
int getBufferCount (void) const { return (int)m_buffers.size(); }
SharedPtr<Shader> popShader (int index);
const SharedPtr<Shader> getShader (int index) const { return m_shaders[index]; }
void addShader (SharedPtr<Shader> shader) { m_shaders.push_back(shader); }
int getShaderCount (void) const { return (int)m_shaders.size(); }
SharedPtr<Program> popProgram (int index);
const SharedPtr<Program> getProgram (int index) const { return m_programs[index]; }
void addProgram (SharedPtr<Program> program) { m_programs.push_back(program); }
int getProgramCount (void) const { return (int)m_programs.size(); }
private:
std::vector<SharedPtr<Texture> > m_textures;
std::vector<SharedPtr<Buffer> > m_buffers;
std::vector<SharedPtr<Shader> > m_shaders;
std::vector<SharedPtr<Program> > m_programs;
};
SharedPtr<Texture> GLES2ResourceManager::popTexture (int index)
{
SharedPtr<Texture> texture = m_textures[index];
m_textures.erase(m_textures.begin() + index);
return texture;
}
SharedPtr<Buffer> GLES2ResourceManager::popBuffer (int index)
{
SharedPtr<Buffer> buffer = m_buffers[index];
m_buffers.erase(m_buffers.begin() + index);
return buffer;
}
SharedPtr<Shader> GLES2ResourceManager::popShader (int index)
{
SharedPtr<Shader> shader = m_shaders[index];
m_shaders.erase(m_shaders.begin() + index);
return shader;
}
SharedPtr<Program> GLES2ResourceManager::popProgram (int index)
{
SharedPtr<Program> program = m_programs[index];
m_programs.erase(m_programs.begin() + index);
return program;
}
class GLES2Context : public tcu::ThreadUtil::Object
{
public:
GLES2Context (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<GLES2ResourceManager> resourceManager);
~GLES2Context (void);
// Call generation time attributes
SharedPtr<GLES2ResourceManager> resourceManager;
// Run time attributes
EGLDisplay display;
EGLContext context;
struct
{
glEGLImageTargetTexture2DOESFunc imageTargetTexture2D;
} glExtensions;
private:
GLES2Context (const GLES2Context&);
GLES2Context& operator= (const GLES2Context&);
};
GLES2Context::GLES2Context (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<GLES2ResourceManager> resourceManager_)
: tcu::ThreadUtil::Object ("Context", event)
, resourceManager (resourceManager_)
, display (EGL_NO_DISPLAY)
, context (EGL_NO_CONTEXT)
{
glExtensions.imageTargetTexture2D = DE_NULL;
}
GLES2Context::~GLES2Context (void)
{
}
class Surface : public tcu::ThreadUtil::Object
{
public:
Surface (SharedPtr<tcu::ThreadUtil::Event> event);
~Surface (void);
// Run time attributes
EGLSurface surface;
private:
Surface (const Surface&);
Surface& operator= (const Surface&);
};
Surface::Surface (SharedPtr<tcu::ThreadUtil::Event> event)
: tcu::ThreadUtil::Object ("Surface", event)
, surface (EGL_NO_SURFACE)
{
}
Surface::~Surface (void)
{
}
// EGL thread with thread specifig state
class EGLThread : public tcu::ThreadUtil::Thread
{
public:
EGLThread (const Library& egl_, const glw::Functions& gl_, int seed);
~EGLThread (void);
virtual void deinit (void);
const Library& egl;
const glw::Functions& gl;
// Generation time attributes
SharedPtr<GLES2Context> context;
SharedPtr<Surface> surface;
// Runtime attributes
SharedPtr<GLES2Context> runtimeContext;
EGLSurface eglSurface;
private:
};
EGLThread::EGLThread (const Library& egl_, const glw::Functions& gl_, int seed)
: tcu::ThreadUtil::Thread (seed)
, egl (egl_)
, gl (gl_)
, eglSurface (EGL_NO_SURFACE)
{
}
void EGLThread::deinit (void)
{
if (runtimeContext)
{
if (runtimeContext->context != EGL_NO_CONTEXT)
egl.makeCurrent(runtimeContext->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
egl.destroyContext(runtimeContext->display, runtimeContext->context);
runtimeContext->context = EGL_NO_CONTEXT;
egl.destroySurface(runtimeContext->display, eglSurface);
eglSurface = EGL_NO_SURFACE;
}
egl.releaseThread();
}
EGLThread::~EGLThread (void)
{
EGLThread::deinit();
}
class FenceSync
{
public:
FenceSync (void);
~FenceSync (void);
void init (EGLThread& thread, bool serverSync);
bool waitReady (EGLThread& thread);
void addWaiter (void);
private:
EGLDisplay m_display;
EGLSyncKHR m_sync;
de::Mutex m_lock;
int m_waiterCount;
bool m_serverSync;
};
FenceSync::FenceSync (void)
: m_display (EGL_NO_DISPLAY)
, m_sync (NULL)
, m_waiterCount (0)
, m_serverSync (false)
{
}
FenceSync::~FenceSync (void)
{
}
void FenceSync::addWaiter (void)
{
m_lock.lock();
m_waiterCount++;
m_lock.unlock();
}
void FenceSync::init (EGLThread& thread, bool serverSync)
{
m_display = thread.runtimeContext->display;
m_serverSync = serverSync;
// Use sync only if somebody will actualy depend on it
m_lock.lock();
if (m_waiterCount > 0)
{
thread.newMessage() << "Begin -- eglCreateSyncKHR(" << ((size_t)m_display) << ", EGL_SYNC_FENCE_KHR, DE_NULL)" << tcu::ThreadUtil::Message::End;
m_sync = thread.egl.createSyncKHR(m_display, EGL_SYNC_FENCE_KHR, DE_NULL);
thread.newMessage() << "End -- " << ((size_t)m_sync) << " = eglCreateSyncKHR()" << tcu::ThreadUtil::Message::End;
TCU_CHECK(m_sync);
}
m_lock.unlock();
}
bool FenceSync::waitReady (EGLThread& thread)
{
bool ok = true;
if (m_serverSync)
{
thread.newMessage() << "Begin -- eglWaitSyncKHR(" << ((size_t)m_display) << ", " << ((size_t)m_sync) << ", 0)" << tcu::ThreadUtil::Message::End;
EGLint result = thread.egl.waitSyncKHR(m_display, m_sync, 0);
thread.newMessage() << "End -- " << result << " = eglWaitSyncKHR()" << tcu::ThreadUtil::Message::End;
ok = result == EGL_TRUE;
}
else
{
thread.newMessage() << "Begin -- eglClientWaitSyncKHR(" << ((size_t)m_display) << ", " << ((size_t)m_sync) << ", EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, 1000 000 000)" << tcu::ThreadUtil::Message::End;
EGLint result = thread.egl.clientWaitSyncKHR(m_display, m_sync, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, 1000000000);
thread.newMessage() << "End -- " << result << " = eglClientWaitSyncKHR()" << tcu::ThreadUtil::Message::End;
ok = result == EGL_CONDITION_SATISFIED_KHR;
}
m_lock.lock();
m_waiterCount--;
DE_ASSERT(m_waiterCount >= 0);
if (m_waiterCount == 0)
{
// \note [mika] This is no longer deterministic and eglDestroySyncKHR might happen in different places and in different threads
thread.newMessage() << "Begin -- eglDestroySyncKHR(" << ((size_t)m_display) << ", " << ((size_t)m_sync) << ")" << tcu::ThreadUtil::Message::End;
EGLint destroyResult = thread.egl.destroySyncKHR(m_display, m_sync);
thread.newMessage() << "End -- " << destroyResult << " = eglDestroySyncKHR()" << tcu::ThreadUtil::Message::End;
m_sync = DE_NULL;
}
m_lock.unlock();
return ok;
}
class Object : public tcu::ThreadUtil::Object
{
public:
Object (const char* type, SharedPtr<tcu::ThreadUtil::Event> e, SharedPtr<FenceSync> sync);
~Object (void);
void readGL (SharedPtr<FenceSync> sync, std::vector<SharedPtr<FenceSync> >& deps);
void modifyGL (SharedPtr<FenceSync> sync, std::vector<SharedPtr<FenceSync> >& deps);
private:
SharedPtr<FenceSync> m_modifySync;
vector<SharedPtr<FenceSync> > m_readSyncs;
};
Object::Object (const char* type, SharedPtr<tcu::ThreadUtil::Event> e, SharedPtr<FenceSync> sync)
: tcu::ThreadUtil::Object (type, e)
, m_modifySync (sync)
{
}
Object::~Object (void)
{
}
void Object::readGL (SharedPtr<FenceSync> sync, std::vector<SharedPtr<FenceSync> >& deps)
{
if (m_modifySync)
m_modifySync->addWaiter();
// Make call depend on last modifying call
deps.push_back(m_modifySync);
// Add read dependency
m_readSyncs.push_back(sync);
}
void Object::modifyGL (SharedPtr<FenceSync> sync, std::vector<SharedPtr<FenceSync> >& deps)
{
// Make call depend on all reads
for (int readNdx = 0; readNdx < (int)m_readSyncs.size(); readNdx++)
{
if (m_readSyncs[readNdx])
m_readSyncs[readNdx]->addWaiter();
deps.push_back(m_readSyncs[readNdx]);
}
if (m_modifySync)
m_modifySync->addWaiter();
deps.push_back(m_modifySync);
// Update last modifying call
m_modifySync = sync;
// Clear read dependencies of last "version" of this object
m_readSyncs.clear();
}
class Operation : public tcu::ThreadUtil::Operation
{
public:
Operation (const char* name, bool useSync, bool serverSync);
virtual ~Operation (void);
SharedPtr<FenceSync> getSync (void) { return m_sync; }
void readGLObject (SharedPtr<Object> object);
void modifyGLObject (SharedPtr<Object> object);
virtual void execute (tcu::ThreadUtil::Thread& thread);
private:
bool m_useSync;
bool m_serverSync;
std::vector<SharedPtr<FenceSync> > m_syncDeps;
SharedPtr<FenceSync> m_sync;
};
Operation::Operation (const char* name, bool useSync, bool serverSync)
: tcu::ThreadUtil::Operation (name)
, m_useSync (useSync)
, m_serverSync (serverSync)
, m_sync (useSync ? SharedPtr<FenceSync>(new FenceSync()) : SharedPtr<FenceSync>())
{
}
Operation::~Operation (void)
{
}
void Operation::readGLObject (SharedPtr<Object> object)
{
object->read(m_event, m_deps);
object->readGL(m_sync, m_syncDeps);
}
void Operation::modifyGLObject (SharedPtr<Object> object)
{
object->modify(m_event, m_deps);
object->modifyGL(m_sync, m_syncDeps);
}
void Operation::execute (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
bool success = true;
// Wait for dependencies and check that they succeeded
for (int depNdx = 0; depNdx < (int)m_deps.size(); depNdx++)
{
if (!m_deps[depNdx]->waitReady())
success = false;
}
// Try execute operation
if (success)
{
try
{
if (m_useSync)
{
for (int depNdx = 0; depNdx < (int)m_syncDeps.size(); depNdx++)
{
EGLThread* eglThread = dynamic_cast<EGLThread*>(&thread);
DE_ASSERT(eglThread);
if (m_syncDeps[depNdx]->waitReady(*eglThread) != tcu::ThreadUtil::Event::RESULT_OK)
{
success = false;
break;
}
}
}
if (success)
{
exec(thread);
if (m_useSync)
{
EGLThread* eglThread = dynamic_cast<EGLThread*>(&thread);
DE_ASSERT(eglThread);
m_sync->init(*eglThread, m_serverSync);
thread.newMessage() << "Begin -- glFlush()" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, flush());
thread.newMessage() << "End -- glFlush()" << tcu::ThreadUtil::Message::End;
}
else
{
thread.newMessage() << "Begin -- glFinish()" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, finish());
thread.newMessage() << "End -- glFinish()" << tcu::ThreadUtil::Message::End;
}
}
}
catch (...)
{
// Got exception event failed
m_event->setResult(tcu::ThreadUtil::Event::RESULT_FAILED);
throw;
}
}
if (success)
m_event->setResult(tcu::ThreadUtil::Event::RESULT_OK);
else
m_event->setResult(tcu::ThreadUtil::Event::RESULT_FAILED);
m_deps.clear();
m_event = SharedPtr<tcu::ThreadUtil::Event>();
m_syncDeps.clear();
m_sync = SharedPtr<FenceSync>();
}
class EGLImage : public Object
{
public:
EGLImage (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync);
virtual ~EGLImage (void) {}
EGLImageKHR image;
};
// EGLResource manager
class EGLResourceManager
{
public:
void addContext (SharedPtr<GLES2Context> context) { m_contexts.push_back(context); }
void addSurface (SharedPtr<Surface> surface) { m_surfaces.push_back(surface); }
void addImage (SharedPtr<EGLImage> image) { m_images.push_back(image); }
SharedPtr<Surface> popSurface (int index);
SharedPtr<GLES2Context> popContext (int index);
SharedPtr<EGLImage> popImage (int index);
int getContextCount (void) const { return (int)m_contexts.size(); }
int getSurfaceCount (void) const { return (int)m_surfaces.size(); }
int getImageCount (void) const { return (int)m_images.size(); }
private:
std::vector<SharedPtr<GLES2Context> > m_contexts;
std::vector<SharedPtr<Surface> > m_surfaces;
std::vector<SharedPtr<EGLImage> > m_images;
};
SharedPtr<Surface> EGLResourceManager::popSurface (int index)
{
SharedPtr<Surface> surface = m_surfaces[index];
m_surfaces.erase(m_surfaces.begin() + index);
return surface;
}
SharedPtr<GLES2Context> EGLResourceManager::popContext (int index)
{
SharedPtr<GLES2Context> context = m_contexts[index];
m_contexts.erase(m_contexts.begin() + index);
return context;
}
SharedPtr<EGLImage> EGLResourceManager::popImage (int index)
{
SharedPtr<EGLImage> image = m_images[index];
m_images.erase(m_images.begin() + index);
return image;
}
class CreateContext : public tcu::ThreadUtil::Operation
{
public:
CreateContext (EGLDisplay display, EGLConfig config, SharedPtr<GLES2Context> shared, SharedPtr<GLES2Context>& context);
void exec (tcu::ThreadUtil::Thread& thread);
private:
EGLDisplay m_display;
EGLConfig m_config;
SharedPtr<GLES2Context> m_shared;
SharedPtr<GLES2Context> m_context;
};
CreateContext::CreateContext (EGLDisplay display, EGLConfig config, SharedPtr<GLES2Context> shared, SharedPtr<GLES2Context>& context)
: tcu::ThreadUtil::Operation ("CreateContext")
, m_display (display)
, m_config (config)
, m_shared (shared)
{
if (shared)
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(shared));
context = SharedPtr<GLES2Context>(new GLES2Context(getEvent(), (shared ? shared->resourceManager : SharedPtr<GLES2ResourceManager>(new GLES2ResourceManager))));
m_context = context;
}
void CreateContext::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
m_context->display = m_display;
const EGLint attriblist[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
thread.newMessage() << "Begin -- eglBindAPI(EGL_OPENGL_ES_API)" << tcu::ThreadUtil::Message::End;
EGLU_CHECK_CALL(thread.egl, bindAPI(EGL_OPENGL_ES_API));
thread.newMessage() << "End -- eglBindAPI()" << tcu::ThreadUtil::Message::End;
if (m_shared)
{
DE_ASSERT(m_shared->context != EGL_NO_CONTEXT);
DE_ASSERT(m_shared->display != EGL_NO_DISPLAY);
DE_ASSERT(m_shared->display == m_display);
thread.newMessage() << "Begin -- eglCreateContext(" << m_display << ", " << m_config << ", " << m_shared->context << ", { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE })" << tcu::ThreadUtil::Message::End;
m_context->context = thread.egl.createContext(m_display, m_config, m_shared->context, attriblist);
thread.newMessage() << "End -- " << m_context->context << " = eglCreateContext()" << tcu::ThreadUtil::Message::End;
}
else
{
thread.newMessage() << "Begin -- eglCreateContext(" << m_display << ", " << m_config << ", EGL_NO_CONTEXT, { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE })" << tcu::ThreadUtil::Message::End;
m_context->context = thread.egl.createContext(m_display, m_config, EGL_NO_CONTEXT, attriblist);
thread.newMessage() << "End -- " << m_context->context << " = eglCreateContext()" << tcu::ThreadUtil::Message::End;
}
EGLU_CHECK_MSG(thread.egl, "Failed to create GLES2 context");
TCU_CHECK(m_context->context != EGL_NO_CONTEXT);
}
class DestroyContext : public tcu::ThreadUtil::Operation
{
public:
DestroyContext (SharedPtr<GLES2Context> contex);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<GLES2Context> m_context;
};
DestroyContext::DestroyContext (SharedPtr<GLES2Context> contex)
: tcu::ThreadUtil::Operation ("DestroyContext")
, m_context (contex)
{
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(m_context));
}
void DestroyContext::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- eglDestroyContext(" << m_context->display << ", " << m_context->context << ")" << tcu::ThreadUtil::Message::End;
EGLU_CHECK_CALL(thread.egl, destroyContext(m_context->display, m_context->context));
thread.newMessage() << "End -- eglDestroyContext()" << tcu::ThreadUtil::Message::End;
m_context->display = EGL_NO_DISPLAY;
m_context->context = EGL_NO_CONTEXT;
}
class MakeCurrent : public tcu::ThreadUtil::Operation
{
public:
MakeCurrent (EGLThread& thread, EGLDisplay display, SharedPtr<Surface> surface, SharedPtr<GLES2Context> context);
void exec (tcu::ThreadUtil::Thread& thread);
private:
EGLDisplay m_display;
SharedPtr<Surface> m_surface;
SharedPtr<GLES2Context> m_context;
};
MakeCurrent::MakeCurrent (EGLThread& thread, EGLDisplay display, SharedPtr<Surface> surface, SharedPtr<GLES2Context> context)
: tcu::ThreadUtil::Operation ("MakeCurrent")
, m_display (display)
, m_surface (surface)
, m_context (context)
{
if (m_context)
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(m_context));
if (m_surface)
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(m_surface));
// Release old contexts
if (thread.context)
{
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(thread.context));
}
// Release old surface
if (thread.surface)
{
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(thread.surface));
}
thread.context = m_context;
thread.surface = m_surface;
}
void MakeCurrent::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
if (m_context)
{
thread.eglSurface = m_surface->surface;
thread.runtimeContext = m_context;
DE_ASSERT(m_surface);
thread.newMessage() << "Begin -- eglMakeCurrent(" << m_display << ", " << m_surface->surface << ", " << m_surface->surface << ", " << m_context->context << ")" << tcu::ThreadUtil::Message::End;
EGLU_CHECK_CALL(thread.egl, makeCurrent(m_display, m_surface->surface, m_surface->surface, m_context->context));
thread.newMessage() << "End -- eglMakeCurrent()" << tcu::ThreadUtil::Message::End;
}
else
{
thread.runtimeContext = m_context;
thread.newMessage() << "Begin -- eglMakeCurrent(" << m_display << ", EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)" << tcu::ThreadUtil::Message::End;
EGLU_CHECK_CALL(thread.egl, makeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
thread.newMessage() << "End -- eglMakeCurrent()" << tcu::ThreadUtil::Message::End;
}
}
class InitGLExtension : public tcu::ThreadUtil::Operation
{
public:
InitGLExtension (const char* extension);
void exec (tcu::ThreadUtil::Thread& thread);
private:
std::string m_extension;
};
InitGLExtension::InitGLExtension (const char* extension)
: tcu::ThreadUtil::Operation ("InitGLExtension")
, m_extension (extension)
{
}
void InitGLExtension::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
// Check extensions
bool found = false;
thread.newMessage() << "Begin -- glGetString(GL_EXTENSIONS)" << tcu::ThreadUtil::Message::End;
std::string extensions = (const char*)thread.gl.getString(GL_EXTENSIONS);
thread.newMessage() << "End -- glGetString()" << tcu::ThreadUtil::Message::End;
std::string::size_type pos = extensions.find(" ");
do
{
std::string extension;
if (pos != std::string::npos)
{
extension = extensions.substr(0, pos);
extensions = extensions.substr(pos+1);
}
else
{
extension = extensions;
extensions = "";
}
if (extension == m_extension)
{
found = true;
break;
}
pos = extensions.find(" ");
} while (pos != std::string::npos);
if (!found)
throw tcu::NotSupportedError((m_extension + " not supported").c_str(), "", __FILE__, __LINE__);
// Query function pointers
if (m_extension == "GL_OES_EGL_image")
{
thread.newMessage() << "Begin -- eglGetProcAddress(\"glEGLImageTargetTexture2DOES\")" << tcu::ThreadUtil::Message::End;
thread.runtimeContext->glExtensions.imageTargetTexture2D = (glEGLImageTargetTexture2DOESFunc)thread.egl.getProcAddress("glEGLImageTargetTexture2DOES");
thread.newMessage() << "End -- " << ((void*)thread.runtimeContext->glExtensions.imageTargetTexture2D) << " = eglGetProcAddress()"<< tcu::ThreadUtil::Message::End;
}
}
class CreatePBufferSurface : public tcu::ThreadUtil::Operation
{
public:
CreatePBufferSurface (EGLDisplay display, EGLConfig config, EGLint width, EGLint height, SharedPtr<Surface>& surface);
void exec (tcu::ThreadUtil::Thread& thread);
private:
EGLDisplay m_display;
EGLConfig m_config;
EGLint m_width;
EGLint m_height;
SharedPtr<Surface> m_surface;
};
CreatePBufferSurface::CreatePBufferSurface (EGLDisplay display, EGLConfig config, EGLint width, EGLint height, SharedPtr<Surface>& surface)
: tcu::ThreadUtil::Operation ("CreatePBufferSurface")
, m_display (display)
, m_config (config)
, m_width (width)
, m_height (height)
{
surface = SharedPtr<Surface>(new Surface(getEvent()));
m_surface = surface;
}
void CreatePBufferSurface::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
const EGLint attriblist[] = {
EGL_WIDTH, m_width,
EGL_HEIGHT, m_height,
EGL_NONE
};
thread.newMessage() << "Begin -- eglCreatePbufferSurface(" << m_display << ", " << m_config << ", { EGL_WIDTH, " << m_width << ", EGL_HEIGHT, " << m_height << ", EGL_NONE })" << tcu::ThreadUtil::Message::End;
m_surface->surface = thread.egl.createPbufferSurface(m_display, m_config, attriblist);
thread.newMessage() << "End -- " << m_surface->surface << "= eglCreatePbufferSurface()" << tcu::ThreadUtil::Message::End;
EGLU_CHECK_MSG(thread.egl, "eglCreatePbufferSurface()");
}
class DestroySurface : public tcu::ThreadUtil::Operation
{
public:
DestroySurface (EGLDisplay display, SharedPtr<Surface> surface);
void exec (tcu::ThreadUtil::Thread& thread);
private:
EGLDisplay m_display;
SharedPtr<Surface> m_surface;
};
DestroySurface::DestroySurface (EGLDisplay display, SharedPtr<Surface> surface)
: tcu::ThreadUtil::Operation ("DestroySurface")
, m_display (display)
, m_surface (surface)
{
modifyObject(SharedPtr<tcu::ThreadUtil::Object>(m_surface));
}
void DestroySurface::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- eglDestroySurface(" << m_display << ", " << m_surface->surface << ")" << tcu::ThreadUtil::Message::End;
EGLU_CHECK_CALL(thread.egl, destroySurface(m_display, m_surface->surface));
thread.newMessage() << "End -- eglDestroySurface()" << tcu::ThreadUtil::Message::End;
}
EGLImage::EGLImage (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync)
: Object ("EGLImage", event, sync)
, image (EGL_NO_IMAGE_KHR)
{
}
class Texture : public Object
{
public:
Texture (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync);
// Runtime parameters
GLuint texture;
// Call generation time parameters
bool isDefined;
SharedPtr<EGLImage> sourceImage;
};
Texture::Texture (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync)
: Object ("Texture", event, sync)
, texture (0)
, isDefined (false)
{
}
class CreateTexture : public Operation
{
public:
CreateTexture (SharedPtr<Texture>& texture, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
};
CreateTexture::CreateTexture (SharedPtr<Texture>& texture, bool useSync, bool serverSync)
: Operation ("CreateTexture", useSync, serverSync)
{
texture = SharedPtr<Texture>(new Texture(getEvent(), getSync()));
m_texture = texture;
}
void CreateTexture::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint tex = 0;
thread.newMessage() << "Begin -- glGenTextures(1, { 0 })" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, genTextures(1, &tex));
thread.newMessage() << "End -- glGenTextures(1, { " << tex << " })" << tcu::ThreadUtil::Message::End;
m_texture->texture = tex;
}
class DeleteTexture : public Operation
{
public:
DeleteTexture (SharedPtr<Texture> texture, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
};
DeleteTexture::DeleteTexture (SharedPtr<Texture> texture, bool useSync, bool serverSync)
: Operation ("DeleteTexture", useSync, serverSync)
, m_texture (texture)
{
modifyGLObject(SharedPtr<Object>(m_texture));
}
void DeleteTexture::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint tex = m_texture->texture;
thread.newMessage() << "Begin -- glDeleteTextures(1, { " << tex << " })" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, deleteTextures(1, &tex));
thread.newMessage() << "End -- glDeleteTextures()" << tcu::ThreadUtil::Message::End;
m_texture->texture = 0;
}
class TexImage2D : public Operation
{
public:
TexImage2D (SharedPtr<Texture> texture, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
GLint m_level;
GLint m_internalFormat;
GLsizei m_width;
GLsizei m_height;
GLenum m_format;
GLenum m_type;
};
TexImage2D::TexImage2D (SharedPtr<Texture> texture, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, bool useSync, bool serverSync)
: Operation ("TexImage2D", useSync, serverSync)
, m_texture (texture)
, m_level (level)
, m_internalFormat (internalFormat)
, m_width (width)
, m_height (height)
, m_format (format)
, m_type (type)
{
modifyGLObject(SharedPtr<Object>(m_texture));
m_texture->isDefined = true;
// Orphang texture
texture->sourceImage = SharedPtr<EGLImage>();
}
void TexImage2D::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
void* dummyData = thread.getDummyData(m_width*m_height*4);
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glTexImage2D(GL_TEXTURE_2D, " << m_level << ", " << m_internalFormat << ", " << m_width << ", " << m_height << ", 0, " << m_format << ", " << m_type << ", data)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, texImage2D(GL_TEXTURE_2D, m_level, m_internalFormat, m_width, m_height, 0, m_format, m_type, dummyData));
thread.newMessage() << "End -- glTexImage2D()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
}
class TexSubImage2D : public Operation
{
public:
TexSubImage2D (SharedPtr<Texture> texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
GLint m_level;
GLint m_xoffset;
GLint m_yoffset;
GLsizei m_width;
GLsizei m_height;
GLenum m_format;
GLenum m_type;
};
TexSubImage2D::TexSubImage2D (SharedPtr<Texture> texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, bool useSync, bool serverSync)
: Operation ("TexSubImage2D", useSync, serverSync)
, m_texture (texture)
, m_level (level)
, m_xoffset (xoffset)
, m_yoffset (yoffset)
, m_width (width)
, m_height (height)
, m_format (format)
, m_type (type)
{
modifyGLObject(SharedPtr<Object>(m_texture));
if (m_texture->sourceImage)
modifyGLObject(SharedPtr<Object>(m_texture->sourceImage));
}
void TexSubImage2D::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
void* dummyData = thread.getDummyData(m_width*m_height*4);
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glTexSubImage2D(GL_TEXTURE_2D, " << m_level << ", " << m_xoffset << ", " << m_yoffset << ", " << m_width << ", " << m_height << ", 0, " << m_format << ", " << m_type << ", <data>)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, texSubImage2D(GL_TEXTURE_2D, m_level, m_xoffset, m_yoffset, m_width, m_height, m_format, m_type, dummyData));
thread.newMessage() << "End -- glSubTexImage2D()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
}
class CopyTexImage2D : public Operation
{
public:
CopyTexImage2D (SharedPtr<Texture> texture, GLint level, GLint internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
GLint m_level;
GLint m_internalFormat;
GLint m_x;
GLint m_y;
GLsizei m_width;
GLsizei m_height;
GLint m_border;
};
CopyTexImage2D::CopyTexImage2D (SharedPtr<Texture> texture, GLint level, GLint internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border, bool useSync, bool serverSync)
: Operation ("CopyTexImage2D", useSync, serverSync)
, m_texture (texture)
, m_level (level)
, m_internalFormat (internalFormat)
, m_x (x)
, m_y (y)
, m_width (width)
, m_height (height)
, m_border (border)
{
modifyGLObject(SharedPtr<Object>(m_texture));
texture->isDefined = true;
// Orphang texture
texture->sourceImage = SharedPtr<EGLImage>();
}
void CopyTexImage2D::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glCopyTexImage2D(GL_TEXTURE_2D, " << m_level << ", " << m_internalFormat << ", " << m_x << ", " << m_y << ", " << m_width << ", " << m_height << ", " << m_border << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, copyTexImage2D(GL_TEXTURE_2D, m_level, m_internalFormat, m_x, m_y, m_width, m_height, m_border));
thread.newMessage() << "End -- glCopyTexImage2D()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
}
class CopyTexSubImage2D : public Operation
{
public:
CopyTexSubImage2D (SharedPtr<Texture> texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
GLint m_level;
GLint m_xoffset;
GLint m_yoffset;
GLint m_x;
GLint m_y;
GLsizei m_width;
GLsizei m_height;
};
CopyTexSubImage2D::CopyTexSubImage2D (SharedPtr<Texture> texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, bool useSync, bool serverSync)
: Operation ("CopyTexSubImage2D", useSync, serverSync)
, m_texture (texture)
, m_level (level)
, m_xoffset (xoffset)
, m_yoffset (yoffset)
, m_x (x)
, m_y (y)
, m_width (width)
, m_height (height)
{
modifyGLObject(SharedPtr<Object>(m_texture));
if (m_texture->sourceImage)
modifyGLObject(SharedPtr<Object>(m_texture->sourceImage));
}
void CopyTexSubImage2D::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glCopyTexSubImage2D(GL_TEXTURE_2D, " << m_level << ", " << m_xoffset << ", " << m_yoffset << ", " << m_x << ", " << m_y << ", " << m_width << ", " << m_height << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, copyTexSubImage2D(GL_TEXTURE_2D, m_level, m_xoffset, m_yoffset, m_x, m_y, m_width, m_height));
thread.newMessage() << "End -- glCopyTexSubImage2D()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
}
class Buffer : public Object
{
public:
Buffer (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync);
// Runtime attributes
GLuint buffer;
GLsizeiptr size;
// Call generation time parameters
bool isDefined;
};
Buffer::Buffer (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync)
: Object ("Buffer", event, sync)
, buffer (0)
, size (0)
, isDefined (false)
{
}
class CreateBuffer : public Operation
{
public:
CreateBuffer (SharedPtr<Buffer>& buffer, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Buffer> m_buffer;
};
CreateBuffer::CreateBuffer (SharedPtr<Buffer>& buffer, bool useSync, bool serverSync)
: Operation ("CreateBuffer", useSync, serverSync)
{
buffer = SharedPtr<Buffer>(new Buffer(getEvent(), getSync()));
m_buffer = buffer;
}
void CreateBuffer::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint buffer = 0;
thread.newMessage() << "Begin -- glGenBuffers(1, { 0 })" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, genBuffers(1, &buffer));
thread.newMessage() << "End -- glGenBuffers(1, { " << buffer << " })" << tcu::ThreadUtil::Message::End;
m_buffer->buffer = buffer;
}
class DeleteBuffer : public Operation
{
public:
DeleteBuffer (SharedPtr<Buffer> buffer, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Buffer> m_buffer;
};
DeleteBuffer::DeleteBuffer (SharedPtr<Buffer> buffer, bool useSync, bool serverSync)
: Operation ("DeleteBuffer", useSync, serverSync)
, m_buffer (buffer)
{
modifyGLObject(SharedPtr<Object>(m_buffer));
}
void DeleteBuffer::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint buffer = m_buffer->buffer;
thread.newMessage() << "Begin -- glDeleteBuffers(1, { " << buffer << " })" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, deleteBuffers(1, &buffer));
thread.newMessage() << "End -- glDeleteBuffers()" << tcu::ThreadUtil::Message::End;
m_buffer->buffer = 0;
}
class BufferData : public Operation
{
public:
BufferData (SharedPtr<Buffer> buffer, GLenum target, GLsizeiptr size, GLenum usage, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Buffer> m_buffer;
GLenum m_target;
GLsizeiptr m_size;
GLenum m_usage;
};
BufferData::BufferData (SharedPtr<Buffer> buffer, GLenum target, GLsizeiptr size, GLenum usage, bool useSync, bool serverSync)
: Operation ("BufferData", useSync, serverSync)
, m_buffer (buffer)
, m_target (target)
, m_size (size)
, m_usage (usage)
{
modifyGLObject(SharedPtr<Object>(m_buffer));
buffer->isDefined = true;
buffer->size = size;
}
void BufferData::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
void* dummyData = thread.getDummyData(m_size);
thread.newMessage() << "Begin -- glBindBuffer(" << m_target << ", " << m_buffer->buffer << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(m_target, m_buffer->buffer));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBufferData(" << m_target << ", " << m_size << ", <DATA>, " << m_usage << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bufferData(m_target, m_size, dummyData, m_usage));
thread.newMessage() << "End -- glBufferData()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindBuffer(" << m_target << ", 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(m_target, 0));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
}
class BufferSubData : public Operation
{
public:
BufferSubData (SharedPtr<Buffer> buffer, GLenum target, GLintptr offset, GLsizeiptr size, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Buffer> m_buffer;
GLenum m_target;
GLintptr m_offset;
GLsizeiptr m_size;
};
BufferSubData::BufferSubData (SharedPtr<Buffer> buffer, GLenum target, GLintptr offset, GLsizeiptr size, bool useSync, bool serverSync)
: Operation ("BufferSubData", useSync, serverSync)
, m_buffer (buffer)
, m_target (target)
, m_offset (offset)
, m_size (size)
{
modifyGLObject(SharedPtr<Object>(m_buffer));
}
void BufferSubData::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
void* dummyData = thread.getDummyData(m_size);
thread.newMessage() << "Begin -- glBindBuffer(" << m_target << ", " << m_buffer->buffer << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(m_target, m_buffer->buffer));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBufferSubData(" << m_target << ", " << m_offset << ", " << m_size << ", <DATA>)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bufferSubData(m_target, m_offset, m_size, dummyData));
thread.newMessage() << "End -- glBufferSubData()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindBuffer(" << m_target << ", 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(m_target, 0));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
}
class Shader : public Object
{
public:
Shader (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync);
GLuint shader;
GLenum type;
bool isDefined;
bool compiled;
};
Shader::Shader (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync)
: Object ("Shader", event, sync)
, shader (0)
, type (GL_NONE)
, isDefined (false)
, compiled (false)
{
}
class CreateShader : public Operation
{
public:
CreateShader (GLenum type, SharedPtr<Shader>& shader, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Shader> m_shader;
GLenum m_type;
};
CreateShader::CreateShader (GLenum type, SharedPtr<Shader>& shader, bool useSync, bool serverSync)
: Operation ("CreateShader", useSync, serverSync)
, m_type (type)
{
shader = SharedPtr<Shader>(new Shader(getEvent(), getSync()));
shader->type = type;
m_shader = shader;
}
void CreateShader::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint shader = 0;
thread.newMessage() << "Begin -- glCreateShader(" << m_type << ")" << tcu::ThreadUtil::Message::End;
shader = thread.gl.createShader(m_type);
GLU_CHECK_GLW_MSG(thread.gl, "glCreateShader()");
thread.newMessage() << "End -- " << shader << " = glCreateShader(" << m_type << ")" << tcu::ThreadUtil::Message::End;
m_shader->shader = shader;
}
class DeleteShader : public Operation
{
public:
DeleteShader (SharedPtr<Shader> shader, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Shader> m_shader;
};
DeleteShader::DeleteShader (SharedPtr<Shader> shader, bool useSync, bool serverSync)
: Operation ("DeleteShader", useSync, serverSync)
, m_shader (shader)
{
modifyGLObject(SharedPtr<Object>(m_shader));
}
void DeleteShader::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint shader = m_shader->shader;
thread.newMessage() << "Begin -- glDeleteShader(" << shader << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, deleteShader(shader));
thread.newMessage() << "End -- glDeleteShader()" << tcu::ThreadUtil::Message::End;
m_shader->shader = 0;
}
class ShaderSource : public Operation
{
public:
ShaderSource (SharedPtr<Shader> sharder, const char* source, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Shader> m_shader;
string m_source;
};
ShaderSource::ShaderSource (SharedPtr<Shader> shader, const char* source, bool useSync, bool serverSync)
: Operation ("ShaderSource", useSync, serverSync)
, m_shader (shader)
, m_source (source)
{
modifyGLObject(SharedPtr<Object>(m_shader));
m_shader->isDefined = true;
}
void ShaderSource::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
const char* shaderSource = m_source.c_str();
thread.newMessage() << "Begin -- glShaderSource(" << m_shader->shader << ", 1, \"" << shaderSource << "\", DE_NULL)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, shaderSource(m_shader->shader, 1, &shaderSource, DE_NULL));
thread.newMessage() << "End -- glShaderSource()" << tcu::ThreadUtil::Message::End;
}
class ShaderCompile : public Operation
{
public:
ShaderCompile (SharedPtr<Shader> sharder, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Shader> m_shader;
};
ShaderCompile::ShaderCompile (SharedPtr<Shader> shader, bool useSync, bool serverSync)
: Operation ("ShaderCompile", useSync, serverSync)
, m_shader (shader)
{
m_shader->compiled = true;
modifyGLObject(SharedPtr<Object>(m_shader));
}
void ShaderCompile::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glCompileShader(" << m_shader->shader << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, compileShader(m_shader->shader));
thread.newMessage() << "End -- glCompileShader()" << tcu::ThreadUtil::Message::End;
}
class Program : public Object
{
public:
Program (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync);
// Generation time attributes
SharedPtr<Shader> vertexShader;
SharedPtr<Shader> fragmentShader;
bool linked;
// Runtime attributes
GLuint program;
GLuint runtimeVertexShader;
GLuint runtimeFragmentShader;
};
Program::Program (SharedPtr<tcu::ThreadUtil::Event> event, SharedPtr<FenceSync> sync)
: Object ("Program", event, sync)
, linked (false)
, program (0)
, runtimeVertexShader (0)
, runtimeFragmentShader (0)
{
}
class CreateProgram : public Operation
{
public:
CreateProgram (SharedPtr<Program>& program, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
};
CreateProgram::CreateProgram (SharedPtr<Program>& program, bool useSync, bool serverSync)
: Operation ("CreateProgram", useSync, serverSync)
{
program = SharedPtr<Program>(new Program(getEvent(), getSync()));
m_program = program;
}
void CreateProgram::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint program = 0;
thread.newMessage() << "Begin -- glCreateProgram()" << tcu::ThreadUtil::Message::End;
program = thread.gl.createProgram();
GLU_CHECK_GLW_MSG(thread.gl, "glCreateProgram()");
thread.newMessage() << "End -- " << program << " = glCreateProgram()" << tcu::ThreadUtil::Message::End;
m_program->program = program;
}
class DeleteProgram : public Operation
{
public:
DeleteProgram (SharedPtr<Program> program, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
};
DeleteProgram::DeleteProgram (SharedPtr<Program> program, bool useSync, bool serverSync)
: Operation ("DeleteProgram", useSync, serverSync)
, m_program (program)
{
modifyGLObject(SharedPtr<Object>(m_program));
}
void DeleteProgram::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint program = m_program->program;
thread.newMessage() << "Begin -- glDeleteProgram(" << program << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, deleteProgram(program));
thread.newMessage() << "End -- glDeleteProgram()" << tcu::ThreadUtil::Message::End;
m_program->program = 0;
}
class AttachShader : public Operation
{
public:
AttachShader (SharedPtr<Program> sharder, SharedPtr<Shader> shader, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
SharedPtr<Shader> m_shader;
};
AttachShader::AttachShader (SharedPtr<Program> program, SharedPtr<Shader> shader, bool useSync, bool serverSync)
: Operation ("AttachShader", useSync, serverSync)
, m_program (program)
, m_shader (shader)
{
modifyGLObject(SharedPtr<Object>(m_program));
readGLObject(SharedPtr<Object>(m_shader));
if (m_shader->type == GL_VERTEX_SHADER)
m_program->vertexShader = shader;
else if (m_shader->type == GL_FRAGMENT_SHADER)
m_program->fragmentShader = shader;
else
DE_ASSERT(false);
}
void AttachShader::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glAttachShader(" << m_program->program << ", " << m_shader->shader << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, attachShader(m_program->program, m_shader->shader));
thread.newMessage() << "End -- glAttachShader()" << tcu::ThreadUtil::Message::End;
if (m_shader->type == GL_VERTEX_SHADER)
m_program->runtimeVertexShader = m_shader->shader;
else if (m_shader->type == GL_FRAGMENT_SHADER)
m_program->runtimeFragmentShader = m_shader->shader;
else
DE_ASSERT(false);
}
class DetachShader : public Operation
{
public:
DetachShader (SharedPtr<Program> sharder, GLenum type, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
GLenum m_type;
};
DetachShader::DetachShader (SharedPtr<Program> program, GLenum type, bool useSync, bool serverSync)
: Operation ("DetachShader", useSync, serverSync)
, m_program (program)
, m_type (type)
{
modifyGLObject(SharedPtr<Object>(m_program));
if (m_type == GL_VERTEX_SHADER)
{
DE_ASSERT(m_program->vertexShader);
m_program->vertexShader = SharedPtr<Shader>();
}
else if (m_type == GL_FRAGMENT_SHADER)
{
DE_ASSERT(m_program->fragmentShader);
m_program->fragmentShader = SharedPtr<Shader>();
}
else
DE_ASSERT(false);
}
void DetachShader::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
if (m_type == GL_VERTEX_SHADER)
{
thread.newMessage() << "Begin -- glDetachShader(" << m_program->program << ", " << m_program->runtimeVertexShader << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, detachShader(m_program->program, m_program->runtimeVertexShader));
thread.newMessage() << "End -- glDetachShader()" << tcu::ThreadUtil::Message::End;
m_program->runtimeVertexShader = 0;
}
else if (m_type == GL_FRAGMENT_SHADER)
{
thread.newMessage() << "Begin -- glDetachShader(" << m_program->program << ", " << m_program->runtimeFragmentShader << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, detachShader(m_program->program, m_program->runtimeFragmentShader));
thread.newMessage() << "End -- glDetachShader()" << tcu::ThreadUtil::Message::End;
m_program->runtimeFragmentShader = 0;
}
else
DE_ASSERT(false);
}
class LinkProgram : public Operation
{
public:
LinkProgram (SharedPtr<Program> program, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
};
LinkProgram::LinkProgram (SharedPtr<Program> program, bool useSync, bool serverSync)
: Operation ("LinkProgram", useSync, serverSync)
, m_program (program)
{
modifyGLObject(SharedPtr<Object>(m_program));
program->linked = true;
}
void LinkProgram::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
GLuint program = m_program->program;
thread.newMessage() << "Begin -- glLinkProgram(" << program << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, linkProgram(program));
thread.newMessage() << "End -- glLinkProgram()" << tcu::ThreadUtil::Message::End;
}
class RenderBuffer : public Operation
{
public:
RenderBuffer (SharedPtr<Program> program, SharedPtr<Buffer> buffer, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
SharedPtr<Buffer> m_buffer;
};
RenderBuffer::RenderBuffer (SharedPtr<Program> program, SharedPtr<Buffer> buffer, bool useSync, bool serverSync)
: Operation ("RenderBuffer", useSync, serverSync)
, m_program (program)
, m_buffer (buffer)
{
readGLObject(SharedPtr<Object>(program));
readGLObject(SharedPtr<Object>(buffer));
}
void RenderBuffer::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glClearColor(0.5f, 0.5f, 0.5f, 1.0f)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, clearColor(0.5f, 0.5f, 0.5f, 1.0f));
thread.newMessage() << "End -- glClearColor()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glClear(GL_COLOR_BUFFER_BIT)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, clear(GL_COLOR_BUFFER_BIT));
thread.newMessage() << "End -- glClear()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glUseProgram(" << m_program->program << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, useProgram(m_program->program));
thread.newMessage() << "End -- glUseProgram()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glGetAttribLocation(" << m_program->program << ", \"a_pos\")" << tcu::ThreadUtil::Message::End;
GLint posLoc = thread.gl.getAttribLocation(m_program->program, "a_pos");
GLU_CHECK_GLW_MSG(thread.gl, "glGetAttribLocation()");
thread.newMessage() << "End -- " << posLoc << " = glGetAttribLocation()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glEnableVertexAttribArray(" << posLoc << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, enableVertexAttribArray(posLoc));
thread.newMessage() << "End -- glEnableVertexAttribArray()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindBuffer(GL_ARRAY_BUFFER, " << m_buffer->buffer << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(GL_ARRAY_BUFFER, m_buffer->buffer));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glVertexAttribPointer(" << posLoc << ", GL_BYTE, GL_TRUE, 0, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, vertexAttribPointer(posLoc, 2, GL_BYTE, GL_TRUE, 0, 0));
thread.newMessage() << "End -- glVertexAttribPointer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glDrawArrays(GL_TRIANGLES, 0, " << (m_buffer->size / 2) << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, drawArrays(GL_TRIANGLES, 0, (GLsizei)m_buffer->size / 2));
thread.newMessage() << "End -- glDrawArrays()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindBuffer(GL_ARRAY_BUFFER, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(GL_ARRAY_BUFFER, 0));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glDisableVertexAttribArray(" << posLoc << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, disableVertexAttribArray(posLoc));
thread.newMessage() << "End -- glDisableVertexAttribArray()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glUseProgram(0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, useProgram(0));
thread.newMessage() << "End -- glUseProgram()" << tcu::ThreadUtil::Message::End;
}
class RenderTexture : public Operation
{
public:
RenderTexture (SharedPtr<Program> program, SharedPtr<Texture> texture, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Program> m_program;
SharedPtr<Texture> m_texture;
};
RenderTexture::RenderTexture (SharedPtr<Program> program, SharedPtr<Texture> texture, bool useSync, bool serverSync)
: Operation ("RenderTexture", useSync, serverSync)
, m_program (program)
, m_texture (texture)
{
readGLObject(SharedPtr<Object>(program));
readGLObject(SharedPtr<Object>(texture));
}
void RenderTexture::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glClearColor(0.5f, 0.5f, 0.5f, 1.0f)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, clearColor(0.5f, 0.5f, 0.5f, 1.0f));
thread.newMessage() << "End -- glClearColor()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glClear(GL_COLOR_BUFFER_BIT)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, clear(GL_COLOR_BUFFER_BIT));
thread.newMessage() << "End -- glClear()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glUseProgram(" << m_program->program << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, useProgram(m_program->program));
thread.newMessage() << "End -- glUseProgram()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glGetUniformLocation(" << m_program->program << ", \"u_sampler\")" << tcu::ThreadUtil::Message::End;
GLint samplerPos = thread.gl.getUniformLocation(m_program->program, "u_sampler");
GLU_CHECK_GLW_MSG(thread.gl, "glGetUniformLocation()");
thread.newMessage() << "End -- glGetUniformLocation()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glUniform1i(" << samplerPos << ", 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, uniform1i(samplerPos, 0));
thread.newMessage() << "End -- glUniform1i()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glGetAttribLocation(" << m_program->program << ", \"a_pos\")" << tcu::ThreadUtil::Message::End;
GLint posLoc = thread.gl.getAttribLocation(m_program->program, "a_pos");
GLU_CHECK_GLW_MSG(thread.gl, "glGetAttribLocation()");
thread.newMessage() << "End -- " << posLoc << " = glGetAttribLocation()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glEnableVertexAttribArray(" << posLoc << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, enableVertexAttribArray(posLoc));
thread.newMessage() << "End -- glEnableVertexAttribArray()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindBuffer(GL_ARRAY_BUFFER, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(GL_ARRAY_BUFFER, 0));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
float coords[] = {
-1.0, -1.0,
1.0, -1.0,
1.0, 1.0,
1.0, 1.0,
-1.0, 1.0,
-1.0, -1.0
};
thread.newMessage() << "Begin -- glVertexAttribPointer(" << posLoc << ", GL_FLOAT, GL_FALSE, 0, <data>)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, vertexAttribPointer(posLoc, 2, GL_FLOAT, GL_FALSE, 0, coords));
thread.newMessage() << "End -- glVertexAttribPointer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glDrawArrays(GL_TRIANGLES, 0, 6)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, drawArrays(GL_TRIANGLES, 0, 6));
thread.newMessage() << "End -- glDrawArrays()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindBuffer(GL_ARRAY_BUFFER, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindBuffer(GL_ARRAY_BUFFER, 0));
thread.newMessage() << "End -- glBindBuffer()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glDisableVertexAttribArray(" << posLoc << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, disableVertexAttribArray(posLoc));
thread.newMessage() << "End -- glDisableVertexAttribArray()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glUseProgram(0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, useProgram(0));
thread.newMessage() << "End -- glUseProgram()" << tcu::ThreadUtil::Message::End;
}
class ReadPixels : public Operation
{
public:
ReadPixels (int x, int y, int width, int height, GLenum format, GLenum type, SharedPtr<tcu::ThreadUtil::DataBlock>& data, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
int m_x;
int m_y;
int m_width;
int m_height;
GLenum m_format;
GLenum m_type;
SharedPtr<tcu::ThreadUtil::DataBlock> m_data;
};
ReadPixels::ReadPixels (int x, int y, int width, int height, GLenum format, GLenum type, SharedPtr<tcu::ThreadUtil::DataBlock>& data, bool useSync, bool serverSync)
: Operation ("ReadPixels", useSync, serverSync)
, m_x (x)
, m_y (y)
, m_width (width)
, m_height (height)
, m_format (format)
, m_type (type)
{
data = SharedPtr<tcu::ThreadUtil::DataBlock>(new tcu::ThreadUtil::DataBlock(getEvent()));
m_data = data;
}
void ReadPixels::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
DE_ASSERT(m_type == GL_UNSIGNED_BYTE);
DE_ASSERT(m_format == GL_RGBA);
std::vector<deUint8> data((m_width-m_x)*(m_height-m_y)*4);
thread.newMessage() << "Begin -- glReadPixels(" << m_x << ", " << m_y << ", " << m_width << ", " << m_height << ", " << m_format << ", " << m_type << ", <data>)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, readPixels(m_x, m_y, m_width, m_height, m_format, m_type, &(data[0])));
thread.newMessage() << "End -- glReadPixels()" << tcu::ThreadUtil::Message::End;
m_data->setData(data.size(), &(data[0]));
}
class CreateImageFromTexture : public Operation
{
public:
// \note [mika] Unlike eglCreateImageKHR this operation requires current context and uses it for creating EGLImage
// Current context is required to support EGL sync objects in current tests system
CreateImageFromTexture (SharedPtr<EGLImage>& image, SharedPtr<Texture> texture, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
SharedPtr<EGLImage> m_image;
};
CreateImageFromTexture::CreateImageFromTexture (SharedPtr<EGLImage>& image, SharedPtr<Texture> texture, bool useSync, bool serverSync)
: Operation ("CreateImageFromTexture", useSync, serverSync)
{
modifyGLObject(SharedPtr<Object>(texture));
image = SharedPtr<EGLImage>(new EGLImage(getEvent(), getSync()));
m_image = image;
m_texture = texture;
m_texture->sourceImage = m_image;
}
void CreateImageFromTexture::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
EGLint attribList[] = {
EGL_GL_TEXTURE_LEVEL_KHR, 0,
EGL_NONE
};
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
// Make texture image complete...
thread.newMessage() << "Begin -- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
thread.newMessage() << "End -- glTexParameteri()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
thread.newMessage() << "End -- glTexParameteri()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
thread.newMessage() << "End -- glTexParameteri()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
thread.newMessage() << "End -- glTexParameteri()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- eglCreateImageKHR(" << thread.runtimeContext->display << ", " << thread.runtimeContext->context << ", EGL_GL_TEXTURE_2D_KHR, " << m_texture->texture << ", { EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_NONE })" << tcu::ThreadUtil::Message::End;
m_image->image = thread.egl.createImageKHR(thread.runtimeContext->display, thread.runtimeContext->context, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)(deUintptr)m_texture->texture, attribList);
EGLU_CHECK_MSG(thread.egl, "eglCreateImageKHR()");
thread.newMessage() << "End -- " << m_image->image << " = eglCreateImageKHR()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
}
class DestroyImage : public Operation
{
public:
// \note [mika] Unlike eglDestroyImageKHR this operation requires current context and uses it for creating EGLImage
// Current context is required to support EGL sync objects in current tests system
DestroyImage (SharedPtr<EGLImage> image, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<EGLImage> m_image;
};
DestroyImage::DestroyImage (SharedPtr<EGLImage> image, bool useSync, bool serverSync)
: Operation ("CreateImageFromTexture", useSync, serverSync)
, m_image (image)
{
modifyGLObject(SharedPtr<Object>(image));
}
void DestroyImage::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- eglDestroyImageKHR(" << thread.runtimeContext->display << ", " << m_image->image << ")" << tcu::ThreadUtil::Message::End;
thread.egl.destroyImageKHR(thread.runtimeContext->display, m_image->image);
m_image->image = EGL_NO_IMAGE_KHR;
EGLU_CHECK_MSG(thread.egl, "eglDestroyImageKHR()");
thread.newMessage() << "End -- eglDestroyImageKHR()" << tcu::ThreadUtil::Message::End;
}
class DefineTextureFromImage : public Operation
{
public:
DefineTextureFromImage (SharedPtr<Texture> texture, SharedPtr<EGLImage> image, bool useSync, bool serverSync);
void exec (tcu::ThreadUtil::Thread& thread);
private:
SharedPtr<Texture> m_texture;
SharedPtr<EGLImage> m_image;
};
DefineTextureFromImage::DefineTextureFromImage (SharedPtr<Texture> texture, SharedPtr<EGLImage> image, bool useSync, bool serverSync)
: Operation ("DefineTextureFromImage", useSync, serverSync)
{
readGLObject(SharedPtr<Object>(image));
modifyGLObject(SharedPtr<Object>(texture));
texture->isDefined = true;
texture->sourceImage = image;
m_image = image;
m_texture = texture;
}
void DefineTextureFromImage::exec (tcu::ThreadUtil::Thread& t)
{
EGLThread& thread = dynamic_cast<EGLThread&>(t);
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, " << m_texture->texture << ")" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, m_texture->texture));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, " << m_image->image << ")" << tcu::ThreadUtil::Message::End;
thread.runtimeContext->glExtensions.imageTargetTexture2D(GL_TEXTURE_2D, m_image->image);
GLU_CHECK_GLW_MSG(thread.gl, "glEGLImageTargetTexture2DOES()");
thread.newMessage() << "End -- glEGLImageTargetTexture2DOES()" << tcu::ThreadUtil::Message::End;
thread.newMessage() << "Begin -- glBindTexture(GL_TEXTURE_2D, 0)" << tcu::ThreadUtil::Message::End;
GLU_CHECK_GLW_CALL(thread.gl, bindTexture(GL_TEXTURE_2D, 0));
thread.newMessage() << "End -- glBindTexture()" << tcu::ThreadUtil::Message::End;
}
} // GLES2ThreadTest
static void requireEGLExtension (const Library& egl, EGLDisplay eglDisplay, const char* requiredExtension)
{
if (!eglu::hasExtension(egl, eglDisplay, requiredExtension))
TCU_THROW(NotSupportedError, (string(requiredExtension) + " not supported").c_str());
}
enum OperationId
{
THREADOPERATIONID_NONE = 0,
THREADOPERATIONID_CREATE_BUFFER,
THREADOPERATIONID_DESTROY_BUFFER,
THREADOPERATIONID_BUFFER_DATA,
THREADOPERATIONID_BUFFER_SUBDATA,
THREADOPERATIONID_CREATE_TEXTURE,
THREADOPERATIONID_DESTROY_TEXTURE,
THREADOPERATIONID_TEXIMAGE2D,
THREADOPERATIONID_TEXSUBIMAGE2D,
THREADOPERATIONID_COPYTEXIMAGE2D,
THREADOPERATIONID_COPYTEXSUBIMAGE2D,
THREADOPERATIONID_CREATE_VERTEX_SHADER,
THREADOPERATIONID_CREATE_FRAGMENT_SHADER,
THREADOPERATIONID_DESTROY_SHADER,
THREADOPERATIONID_SHADER_SOURCE,
THREADOPERATIONID_SHADER_COMPILE,
THREADOPERATIONID_ATTACH_SHADER,
THREADOPERATIONID_DETACH_SHADER,
THREADOPERATIONID_CREATE_PROGRAM,
THREADOPERATIONID_DESTROY_PROGRAM,
THREADOPERATIONID_LINK_PROGRAM,
THREADOPERATIONID_CREATE_IMAGE_FROM_TEXTURE,
THREADOPERATIONID_DESTROY_IMAGE,
THREADOPERATIONID_TEXTURE_FROM_IMAGE,
THREADOPERATIONID_LAST
};
class GLES2SharingRandomTest : public TestCase
{
public:
struct TestConfig
{
TestConfig (void);
int threadCount;
int operationCount;
bool serverSync;
bool useFenceSync;
bool useImages;
float probabilities[THREADOPERATIONID_LAST][THREADOPERATIONID_LAST];
};
GLES2SharingRandomTest (EglTestContext& context, const TestConfig& config, const char* name, const char* description);
~GLES2SharingRandomTest (void);
void init (void);
void deinit (void);
IterateResult iterate (void);
void addRandomOperation (GLES2ThreadTest::EGLResourceManager& resourceManager);
private:
TestConfig m_config;
int m_seed;
de::Random m_random;
tcu::TestLog& m_log;
bool m_threadsStarted;
bool m_threadsRunning;
bool m_executionReady;
bool m_requiresRestart;
deUint64 m_beginTimeUs;
deUint64 m_timeOutUs;
deUint32 m_sleepTimeMs;
deUint64 m_timeOutTimeUs;
std::vector<GLES2ThreadTest::EGLThread*> m_threads;
EGLDisplay m_eglDisplay;
EGLConfig m_eglConfig;
OperationId m_lastOperation;
glw::Functions m_gl;
};
GLES2SharingRandomTest::TestConfig::TestConfig (void)
: threadCount (0)
, operationCount (0)
, serverSync (false)
, useFenceSync (false)
, useImages (false)
{
deMemset(probabilities, 0, sizeof(probabilities));
}
GLES2SharingRandomTest::GLES2SharingRandomTest (EglTestContext& context, const TestConfig& config, const char* name, const char* description)
: TestCase (context, name, description)
, m_config (config)
, m_seed (deStringHash(name))
, m_random (deStringHash(name))
, m_log (m_testCtx.getLog())
, m_threadsStarted (false)
, m_threadsRunning (false)
, m_executionReady (false)
, m_requiresRestart (false)
, m_beginTimeUs (0)
, m_timeOutUs (10000000) // 10 seconds
, m_sleepTimeMs (1) // 1 milliseconds
, m_timeOutTimeUs (0)
, m_eglDisplay (EGL_NO_DISPLAY)
, m_eglConfig (0)
, m_lastOperation (THREADOPERATIONID_NONE)
{
}
GLES2SharingRandomTest::~GLES2SharingRandomTest (void)
{
GLES2SharingRandomTest::deinit();
}
void GLES2SharingRandomTest::init (void)
{
const Library& egl = m_eglTestCtx.getLibrary();
const EGLint attribList[] =
{
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_ALPHA_SIZE, 1,
EGL_NONE
};
m_eglDisplay = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
m_eglConfig = eglu::chooseSingleConfig(egl, m_eglDisplay, attribList);
m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2,0));
// Check extensions
if (m_config.useFenceSync)
requireEGLExtension(egl, m_eglDisplay, "EGL_KHR_fence_sync");
if (m_config.serverSync)
requireEGLExtension(egl, m_eglDisplay, "EGL_KHR_wait_sync");
if (m_config.useImages)
{
requireEGLExtension(egl, m_eglDisplay, "EGL_KHR_image_base");
requireEGLExtension(egl, m_eglDisplay, "EGL_KHR_gl_texture_2D_image");
}
GLES2ThreadTest::EGLResourceManager resourceManager;
// Create contexts
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
{
m_threads.push_back(new GLES2ThreadTest::EGLThread(egl, m_gl, deInt32Hash(m_seed+threadNdx)));
SharedPtr<GLES2ThreadTest::GLES2Context> context;
SharedPtr<GLES2ThreadTest::GLES2Context> shared = (threadNdx > 0 ? resourceManager.popContext(0) : SharedPtr<GLES2ThreadTest::GLES2Context>());
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::CreateContext(m_eglDisplay, m_eglConfig, shared, context));
resourceManager.addContext(context);
if (shared)
resourceManager.addContext(shared);
}
// Create surfaces
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
{
SharedPtr<GLES2ThreadTest::Surface> surface;
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::CreatePBufferSurface(m_eglDisplay, m_eglConfig, 400, 400, surface));
resourceManager.addSurface(surface);
}
// Make contexts current
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
{
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::MakeCurrent(*m_threads[threadNdx], m_eglDisplay, resourceManager.popSurface(0), resourceManager.popContext(0)));
}
// Operations to check fence sync support
if (m_config.useFenceSync)
{
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
{
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::InitGLExtension("GL_OES_EGL_sync"));
}
}
// Init EGLimage support
if (m_config.useImages)
{
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
{
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::InitGLExtension("GL_OES_EGL_image"));
}
}
// Add random operations
for (int operationNdx = 0; operationNdx < m_config.operationCount; operationNdx++)
addRandomOperation(resourceManager);
{
int threadNdx = 0;
// Destroy images
// \note Android reference counts EGLDisplays so we can't trust the eglTerminate() to clean up resources
while (resourceManager.getImageCount() > 0)
{
const SharedPtr<GLES2ThreadTest::EGLImage> image = resourceManager.popImage(0);
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::DestroyImage(image, m_config.useFenceSync, m_config.serverSync));
threadNdx = (threadNdx + 1) % m_config.threadCount;
}
}
// Release contexts
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
{
SharedPtr<GLES2ThreadTest::GLES2Context> context = m_threads[threadNdx]->context;
SharedPtr<GLES2ThreadTest::Surface> surface = m_threads[threadNdx]->surface;
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::MakeCurrent(*m_threads[threadNdx], m_eglDisplay, SharedPtr<GLES2ThreadTest::Surface>(), SharedPtr<GLES2ThreadTest::GLES2Context>()));
resourceManager.addSurface(surface);
resourceManager.addContext(context);
}
// Destroy contexts
for (int threadNdx = 0; threadNdx < (int)m_threads.size(); threadNdx++)
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::DestroyContext(resourceManager.popContext(0)));
// Destroy surfaces
for (int threadNdx = 0; threadNdx < m_config.threadCount; threadNdx++)
m_threads[threadNdx]->addOperation(new GLES2ThreadTest::DestroySurface(m_eglDisplay, resourceManager.popSurface(0)));
}
void GLES2SharingRandomTest::deinit (void)
{
for (int threadNdx = 0; threadNdx < (int)m_threads.size(); threadNdx++)
{
delete m_threads[threadNdx];
m_threads[threadNdx] = DE_NULL;
}
m_threads.clear();
if (m_eglDisplay != EGL_NO_DISPLAY)
{
m_eglTestCtx.getLibrary().terminate(m_eglDisplay);
m_eglDisplay = EGL_NO_DISPLAY;
}
TCU_CHECK(!m_requiresRestart);
}
void GLES2SharingRandomTest::addRandomOperation (GLES2ThreadTest::EGLResourceManager& resourceManager)
{
int threadNdx = m_random.getUint32() % (deUint32)m_threads.size();
std::vector<OperationId> operations;
std::vector<float> weights;
operations.push_back(THREADOPERATIONID_CREATE_BUFFER);
weights.push_back(m_config.probabilities[m_lastOperation][THREADOPERATIONID_CREATE_BUFFER]);
operations.push_back(THREADOPERATIONID_CREATE_TEXTURE);
weights.push_back(m_config.probabilities[m_lastOperation][THREADOPERATIONID_CREATE_TEXTURE]);
operations.push_back(THREADOPERATIONID_CREATE_VERTEX_SHADER);
weights.push_back(m_config.probabilities[m_lastOperation][THREADOPERATIONID_CREATE_VERTEX_SHADER]);
operations.push_back(THREADOPERATIONID_CREATE_FRAGMENT_SHADER);
weights.push_back(m_config.probabilities[m_lastOperation][THREADOPERATIONID_CREATE_FRAGMENT_SHADER]);
operations.push_back(THREADOPERATIONID_CREATE_PROGRAM);
weights.push_back(m_config.probabilities[m_lastOperation][THREADOPERATIONID_CREATE_PROGRAM]);
int destroyableBufferNdx = -1;
int destroyableTextureNdx = -1;
int destroyableShaderNdx = -1;
int destroyableProgramNdx = -1;
int vertexShaderNdx = -1;
int fragmentShaderNdx = -1;
int definedTextureNdx = -1;
int definedBufferNdx = -1;
int definedShaderNdx = -1;
int detachableProgramNdx = -1;
GLenum detachShaderType = GL_VERTEX_SHADER;
int unusedVertexAttachmentProgramNdx = -1;
int unusedFragmentAttachmentProgramNdx = -1;
int linkableProgramNdx = -1;
int attachProgramNdx = -1;
int attachShaderNdx = -1;
int nonSiblingTextureNdx = -1;
if (m_threads[threadNdx]->context->resourceManager->getBufferCount() > 0)
destroyableBufferNdx = m_random.getUint32() % m_threads[threadNdx]->context->resourceManager->getBufferCount();
if (m_threads[threadNdx]->context->resourceManager->getTextureCount() > 0)
destroyableTextureNdx = m_random.getUint32() % m_threads[threadNdx]->context->resourceManager->getTextureCount();
if (m_threads[threadNdx]->context->resourceManager->getShaderCount() > 0)
destroyableShaderNdx = m_random.getUint32() % m_threads[threadNdx]->context->resourceManager->getShaderCount();
if (m_threads[threadNdx]->context->resourceManager->getProgramCount() > 0)
destroyableProgramNdx = m_random.getUint32() % m_threads[threadNdx]->context->resourceManager->getProgramCount();
// Check what kind of buffers we have
for (int bufferNdx = 0; bufferNdx < m_threads[threadNdx]->context->resourceManager->getBufferCount(); bufferNdx++)
{
SharedPtr<GLES2ThreadTest::Buffer> buffer = m_threads[threadNdx]->context->resourceManager->getBuffer(bufferNdx);
if (buffer->isDefined)
{
if (definedBufferNdx == -1)
definedBufferNdx = bufferNdx;
else if (m_random.getBool())
definedBufferNdx = bufferNdx;
}
}
// Check what kind of textures we have
for (int textureNdx = 0; textureNdx < m_threads[threadNdx]->context->resourceManager->getTextureCount(); textureNdx++)
{
SharedPtr<GLES2ThreadTest::Texture> texture = m_threads[threadNdx]->context->resourceManager->getTexture(textureNdx);
if (texture->isDefined)
{
if (definedTextureNdx == -1)
definedTextureNdx = textureNdx;
else if (m_random.getBool())
definedTextureNdx = textureNdx;
if (!texture->sourceImage)
{
if (nonSiblingTextureNdx == -1)
nonSiblingTextureNdx = textureNdx;
else if (m_random.getBool())
nonSiblingTextureNdx = textureNdx;
}
}
}
// Check what kind of shaders we have
for (int shaderNdx = 0; shaderNdx < m_threads[threadNdx]->context->resourceManager->getShaderCount(); shaderNdx++)
{
SharedPtr<GLES2ThreadTest::Shader> shader = m_threads[threadNdx]->context->resourceManager->getShader(shaderNdx);