如何在OpenGL中显示ATI卡的gpu内存使用情况?

时间:2017-02-03 13:00:35

标签: c++ opengl memory-management gpu

我正在编写一个gpu mem信息使用应用程序,向您显示视频卡的全部视频内存(全局)。 这是基于OpenGL / Glut的,它可以在NVIDIA卡上使​​用NVIDIA,并且不适用于ATI卡中的ATI(每个GPU显示4个值但从未更改过)。我总是检查相同的OpenGL游戏(minetest)。

我用这个链接写: Determining available video memory

这个代码(渲染方法):

void display(void)
{
    int line = 1;
    std::string vendor;
    glClear(GL_COLOR_BUFFER_BIT);
    output(0, fontHeight * line++, "GPU Mem info");

    vendor.append("vendor : ");
    vendor.append(glGetString(GL_VENDOR) ? (char*)glGetString(GL_VENDOR) : "null");
    output(0, fontHeight * line++, vendor.c_str());

    if (vendor.find("NVIDIA") != std::string::npos)
    {

        static struct { GLenum glcode; const char * name; } GPU_MEMORY_INFO_SYMBOLE_ARRAY_NVIDIA[]=
        {
            {GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, "free" },
            {GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, "total"},
            {GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX,"dedicated"},
            {GPU_MEMORY_INFO_EVICTION_COUNT_NVX,"eviction count"},
            {GPU_MEMORY_INFO_EVICTED_MEMORY_NVX,"evicted mem"},
            {0,0}
        };

        for (int i = 0; GPU_MEMORY_INFO_SYMBOLE_ARRAY_NVIDIA[i].glcode; i++)
        {
            std::string text;
            GLint value = 0;
            std::ostringstream oss;


            text.append(GPU_MEMORY_INFO_SYMBOLE_ARRAY_NVIDIA[i].name);
            text.append(" : ");

            glGetIntegerv(GPU_MEMORY_INFO_SYMBOLE_ARRAY_NVIDIA[i].glcode, &value);
            oss << value;
            text.append(oss.str());

            text.append("Kbytes");

            output(0, fontHeight * line++, text.c_str());
        }
    }
    else if (vendor.find("ATI") != std::string::npos)
    {


        static struct { GLenum glcode; const char * name; } GPU_MEMORY_INFO_SYMBOLE_ARRAY_ATI[] =
        {
            { TEXTURE_FREE_MEMORY_ATI, "texture" },
            { VBO_FREE_MEMORY_ATI, "vbo" },
            { RENDERBUFFER_FREE_MEMORY_ATI,"renderbuffer" },
            { 0,0 }
        };

        static const char * index2name[] = { "total", "free", "total free auxiliary",  "largest auxiliary free", 0 };

        for (int i = 0; GPU_MEMORY_INFO_SYMBOLE_ARRAY_ATI[i].glcode; i++)
        {
            std::string title;
            GLint values[4] = { 0,0,0,0 };

            title.append(GPU_MEMORY_INFO_SYMBOLE_ARRAY_ATI[i].name);
            title.append(" :");
            output(0, fontHeight * line++, title.c_str());

            glGetIntegerv(GPU_MEMORY_INFO_SYMBOLE_ARRAY_ATI[i].glcode, values);
            for (int j = 0; index2name[j]; j++)
            {
                std::string text;
                text.append("+ ");
                text.append(index2name[j]);
                text.append(" : ");
                std::ostringstream oss;
                oss << values[j];               
                text.append(oss.str());
                text.append("Kbytes");
                output(0, fontHeight * line++, text.c_str());
            }           
        }
    }
    else 
    {
        output(0, fontHeight * line++, "unkown vendor");
    }

    glutSwapBuffers();
}

有人可以帮助我吗?

0 个答案:

没有答案