Edit

kc3-lang/angle/src/libGLESv2/Fence.cpp

Branch :

  • Show log

    Commit

  • Author : apatrick@chromium.org
    Date : 2012-01-11 20:03:29
    Hash : f289ee8d
    Message : Allocate D3D queries from a pool for the Display. This is a workaround for an Intel bug. The crash looks like this: 0x5f816c53 [d3d9.dll + 0x00036c53] CQuery::~CQuery() 0x5f816bec [d3d9.dll + 0x00036bec] CQuery::`vector deleting destructor'(unsigned int) 0x5f7e8129 [d3d9.dll + 0x00008129] CBaseObject::~CBaseObject() 0x5f9e19c7 [libglesv2.dll + 0x000319c7] gl::Fence::`vector deleting destructor'(unsigned int) 0x5f9de78e [libglesv2.dll - context.cpp:975] gl::Context::deleteFence(unsigned int) 0x5f9e1491 [libglesv2.dll - context.cpp:198] gl::Context::~Context() 0x5f9e182f [libglesv2.dll - context.cpp:3936] glDestroyContext 0x717654ec [libegl.dll - display.cpp:749] egl::Display::destroyContext(gl::Context *) 0x7176a3da [libegl.dll - libegl.cpp:907] eglDestroyContext 0x64fbaf33 [chrome.dll - gl_context_egl.cc:75] gfx::GLContextEGL::Destroy() The vendor ID is always 8086 (Intel). Not an XP issue - it's happening on Win 7. With this change, D3D queries are only released when the display is destroyed or reset or if a very high number of D3D queries have been allocated. Tested by stepping exercising the NV_fence entry points in a debugger. Review URL: http://codereview.appspot.com/5534065 git-svn-id: https://angleproject.googlecode.com/svn/trunk@941 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/libGLESv2/Fence.cpp
  • //
    // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    // Fence.cpp: Implements the gl::Fence class, which supports the GL_NV_fence extension.
    
    #include "libGLESv2/Fence.h"
    
    #include "libGLESv2/main.h"
    
    namespace gl
    {
    
    Fence::Fence()
    { 
        mQuery = NULL;
        mCondition = GL_NONE;
        mStatus = GL_FALSE;
    }
    
    Fence::~Fence()
    {
        if (mQuery != NULL)
        {
            getDisplay()->freeEventQuery(mQuery);
        }
    }
    
    GLboolean Fence::isFence()
    {
        // GL_NV_fence spec:
        // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence.
        return mQuery != NULL;
    }
    
    void Fence::setFence(GLenum condition)
    {
        if (!mQuery)
        {
            mQuery = getDisplay()->allocateEventQuery();
            if (!mQuery)
            {
                return error(GL_OUT_OF_MEMORY);
            }
        }
    
        HRESULT result = mQuery->Issue(D3DISSUE_END);
        ASSERT(SUCCEEDED(result));
    
        mCondition = condition;
        mStatus = GL_FALSE;
    }
    
    GLboolean Fence::testFence()
    {
        if (mQuery == NULL)
        {
            return error(GL_INVALID_OPERATION, GL_TRUE);
        }
    
        HRESULT result = mQuery->GetData(NULL, 0, D3DGETDATA_FLUSH);
    
        if (checkDeviceLost(result))
        {
           return error(GL_OUT_OF_MEMORY, GL_TRUE);
        }
    
        ASSERT(result == S_OK || result == S_FALSE);
        mStatus = result == S_OK;
        return mStatus;
    }
    
    void Fence::finishFence()
    {
        if (mQuery == NULL)
        {
            return error(GL_INVALID_OPERATION);
        }
    
        while (!testFence())
        {
            Sleep(0);
        }
    }
    
    void Fence::getFenceiv(GLenum pname, GLint *params)
    {
        if (mQuery == NULL)
        {
            return error(GL_INVALID_OPERATION);
        }
    
        switch (pname)
        {
            case GL_FENCE_STATUS_NV:
            {
                // GL_NV_fence spec:
                // Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV
                // or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
                if (mStatus)
                {
                    params[0] = GL_TRUE;
                    return;
                }
                
                HRESULT result = mQuery->GetData(NULL, 0, 0);
                
                if (checkDeviceLost(result))
                {
                    params[0] = GL_TRUE;
                    return error(GL_OUT_OF_MEMORY);
                }
    
                ASSERT(result == S_OK || result == S_FALSE);
                mStatus = result == S_OK;
                params[0] = mStatus;
                
                break;
            }
            case GL_FENCE_CONDITION_NV:
                params[0] = mCondition;
                break;
            default:
                return error(GL_INVALID_ENUM);
                break;
        }
    }
    
    }