1

目前,我正在尝试实现一个计算着色器。为此,我使用了一个模板,它使用 Qt 来处理 OpenGL 的东西。要创建计算着色器,使用此函数,它适用于其他一些计算着色器:

std::shared_ptr<QOpenGLShaderProgram> createComputeShaderProgram(const QString &computeShaderPath)
{
  auto shaderProgram = std::make_shared<QOpenGLShaderProgram>();
  bool result;
  //! Load and compile the compute shader
  if (!computeShaderPath.isEmpty()) {
    result = shaderProgram->addShaderFromSourceFile(QOpenGLShader::Compute, computeShaderPath);
    if (!result) {
        qWarning() << computeShaderPath;
        qWarning() << shaderProgram->log();
    }
  }
  //! ...and finally link it to resolve any references.
  result = shaderProgram->link();
  if (!result)
    qWarning() << "Could not link shader program:" << shaderProgram->log();
  return shaderProgram;
}

正如我所说,这适用于所有其他计算着色器。呼叫线路时出现问题

result = shaderProgram->link();

我没有在着色器中更改导致错误的大东西。我刚刚添加了一个基本的 naiv 邻居搜索。为了弄清楚,当错误发生时,我尝试注释掉一些行,看看它现在是否正在编译。从中,我得到了由于//relevant line以下着色器函数中标有的两行而发生错误的信息:

#define NUM_NEIGHBORS 4

float distNN[NUM_NEIGHBORS];
int idxNN[NUM_NEIGHBORS];

void neighborSearch()
{
  vec3 currentPosition = /* ... calc the current position with the compute shader invocation ID */;
  vec3 currentPoint = vec3(0.0);
  float curDist = 0.0;

  currentPoint = pointCloud[0].vertex.xyz;
  curDist = distance(currentPosition, currentPoint);
  float maxDist = curDist;
  int idxMaxDist = 0;
  for(int i = 1; i < NUM_NEIGHBORS; i++)
  {
    currentPoint = pointCloud[i].vertex.xyz;
    curDist = distance(currentPosition, currentPoint);
    if(curDist >= maxDist)
    {
        maxDist = curDist;   //relevant line
        idxMaxDist = i;      //relevant line
    }
  }
  for(int i = 0; i < NUM_NEIGHBORS; i++)
  {
    distNN[i] = maxDist;
    idxNN[i] = idxMaxDist;
  }
  for(int i = 0; i < nmbPoints; i++)
  {
    currentPoint = pointCloud[i].vertex.xyz;
    curDist = distance(currentPoint,currentPosition);
    if(curDist < distNN[NUM_NEIGHBORS-1])
    {
        bool inserted = false;
        int j = NUM_NEIGHBORS - 2;
        while(!inserted)
        {
            if(curDist < distNN[j] && j >= 0)
            {
                j--;
            }
            else
            {
                for(int k = NUM_NEIGHBORS-1; k > j+1; k--)
                {
                    distNN[k] = distNN[k-1];
                    idxNN[k] = idxNN[k-1];
                }
                distNN[j+1] = curDist;
                idxNN[j+1] = i;
                inserted = true;
            }
        }
    }//curDist < NUM_NEIGHBORS-1
  }//iterate over all neighbors
}//neighborSearch()

我希望在简化此着色器的同时,我没有删除对此至关重要的东西。我用地址清理器编译它,它的输出是:

==5365== ERROR: AddressSanitizer: SEGV on unknown address 0x00000000002c (pc 0x7fde1d61b630 sp 0x7fffb34c61b8 bp 0x7fffb34c77a0 T0)
AddressSanitizer can not provide additional info.
#0 0x7fde1d61b62f (/usr/lib64/libnvidia-glcore.so.331.49+0xb5062f)
#1 0x7fde1d4eacc5 (/usr/lib64/libnvidia-glcore.so.331.49+0xa1fcc5)
#2 0x7fde1d4eb25e (/usr/lib64/libnvidia-glcore.so.331.49+0xa2025e)
#3 0x7fde1d4eb34f (/usr/lib64/libnvidia-glcore.so.331.49+0xa2034f)
#4 0x7fde1d4f051f (/usr/lib64/libnvidia-glcore.so.331.49+0xa2551f)
#5 0x7fde1d4f1b43 (/usr/lib64/libnvidia-glcore.so.331.49+0xa26b43)
#6 0x7fde1d4f04f7 (/usr/lib64/libnvidia-glcore.so.331.49+0xa254f7)
#7 0x7fde1d4f0d83 (/usr/lib64/libnvidia-glcore.so.331.49+0xa25d83)
#8 0x7fde1d4f10f6 (/usr/lib64/libnvidia-glcore.so.331.49+0xa260f6)
#9 0x7fde1d4cce43 (/usr/lib64/libnvidia-glcore.so.331.49+0xa01e43)
#10 0x7fde1d4d2bd4 (/usr/lib64/libnvidia-glcore.so.331.49+0xa07bd4)
#11 0x7fde1d4d325a (/usr/lib64/libnvidia-glcore.so.331.49+0xa0825a)
#12 0x7fde1dc616ad (/usr/lib64/libnvidia-glcore.so.331.49+0x11966ad)
#13 0x7fde1dc6741b (/usr/lib64/libnvidia-glcore.so.331.49+0x119c41b)
#14 0x7fde1dc44a7a (/usr/lib64/libnvidia-glcore.so.331.49+0x1179a7a)
#15 0x7fde22c7eca0 (/QT_DIRECTORY/5.2.1/gcc_64/lib/libQt5Gui.so.5.2.1+0x34dca0)
#16-24 some project relevant stuff
==5365== ABORTING

有谁知道为什么会出现这个问题以及如何解决它?我真的不知道现在该怎么办。

系统信息:

  • 64 位 OpenSuse 13.1
  • 英伟达 GT 555M
  • 直接运行程序optirun qtcreator

Valgrind 输出:

$ optirun valgrind --leak-check=yes ./projectname
==4038== Memcheck, a memory error detector
==4038== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==4038== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==4038== Command: ./projectname
==4038== 
==4038== Shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING.
==4038== Process memory map follows:
    0x000000400000-0x00000055f000   PROJECT_DIRECTORY/projectname
    0x00000075e000-0x000000766000   PROJECT_DIRECTORY/projectname
    0x000000766000-0x00000076d000   PROJECT_DIRECTORY/projectname
    0x00000076d000-0x00000076e000
    0x000004000000-0x000004020000   /lib64/ld-2.18.so
    0x000004020000-0x00000402d000
    0x000004035000-0x00000403d000
    0x000004052000-0x000004062000
    0x00000421f000-0x000004220000   /lib64/ld-2.18.so
    0x000004220000-0x000004221000   /lib64/ld-2.18.so
    0x000004221000-0x000004222000
    0x000004222000-0x000004223000
    0x000004a22000-0x000004a23000   /usr/local/lib64/valgrind/vgpreload_core-amd64-linux.so
    0x000004a23000-0x000004c22000   /usr/local/lib64/valgrind/vgpreload_core-amd64-linux.so
    0x000004c22000-0x000004c23000   /usr/local/lib64/valgrind/vgpreload_core-amd64-linux.so
    0x000004c23000-0x000004c24000   /usr/local/lib64/valgrind/vgpreload_core-amd64-linux.so
    0x000004c24000-0x000004c32000   /usr/local/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
    0x000004c32000-0x000004e32000   /usr/local/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
    0x000004e32000-0x000004e33000   /usr/local/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
    0x000004e33000-0x000004e34000   /usr/local/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
    0x000004e34000-0x000004e35000   /usr/lib64/libdlfaker.so
    0x000004e35000-0x000005035000   /usr/lib64/libdlfaker.so
    0x000005035000-0x000005036000   /usr/lib64/libdlfaker.so
    0x000005036000-0x000005037000   /usr/lib64/libdlfaker.so
    0x000005037000-0x000005104000   /usr/lib64/librrfaker.so
    0x000005104000-0x000005304000   /usr/lib64/librrfaker.so
    0x000005304000-0x000005307000   /usr/lib64/librrfaker.so
    0x000005307000-0x000005309000   /usr/lib64/librrfaker.so
    0x000005309000-0x00000534c000
    0x00000534c000-0x000005375000   /usr/lib64/libasan.so.0.0.0
    0x000005375000-0x000005574000   /usr/lib64/libasan.so.0.0.0
    0x000005574000-0x000005575000   /usr/lib64/libasan.so.0.0.0
    0x000005575000-0x000005576000   /usr/lib64/libasan.so.0.0.0
    0x000005576000-0x0000082db000
    0x0000082db000-0x000008358000   /usr/lib64/libGLU.so.1.3.1
    0x000008358000-0x000008557000   /usr/lib64/libGLU.so.1.3.1
    0x000008557000-0x000008559000   /usr/lib64/libGLU.so.1.3.1
    0x000008559000-0x00000855a000   /usr/lib64/libGLU.so.1.3.1
    0x00000855a000-0x0000085bb000   QT_DIRECTORY/gcc_64/lib/libQt5OpenGL.so.5.2.1
    0x0000085bb000-0x0000087ba000   QT_DIRECTORY/gcc_64/lib/libQt5OpenGL.so.5.2.1
    0x0000087ba000-0x0000087bc000   QT_DIRECTORY/gcc_64/lib/libQt5OpenGL.so.5.2.1
    0x0000087bc000-0x0000087be000   QT_DIRECTORY/gcc_64/lib/libQt5OpenGL.so.5.2.1
    0x0000087be000-0x000008db9000   QT_DIRECTORY/gcc_64/lib/libQt5Widgets.so.5.2.1
    0x000008db9000-0x000008fb9000   QT_DIRECTORY/gcc_64/lib/libQt5Widgets.so.5.2.1
    0x000008fb9000-0x000008fe3000   QT_DIRECTORY/gcc_64/lib/libQt5Widgets.so.5.2.1
    0x000008fe3000-0x000009004000   QT_DIRECTORY/gcc_64/lib/libQt5Widgets.so.5.2.1
    0x000009004000-0x000009464000   QT_DIRECTORY/gcc_64/lib/libQt5Gui.so.5.2.1
    0x000009464000-0x000009663000   QT_DIRECTORY/gcc_64/lib/libQt5Gui.so.5.2.1
    0x000009663000-0x000009677000   QT_DIRECTORY/gcc_64/lib/libQt5Gui.so.5.2.1
    0x000009677000-0x000009689000   QT_DIRECTORY/gcc_64/lib/libQt5Gui.so.5.2.1
    0x000009689000-0x00000968a000
    0x00000968a000-0x000009b33000   QT_DIRECTORY/gcc_64/lib/libQt5Core.so.5.2.1
    0x000009b33000-0x000009d33000   QT_DIRECTORY/gcc_64/lib/libQt5Core.so.5.2.1
    0x000009d33000-0x000009d3d000   QT_DIRECTORY/gcc_64/lib/libQt5Core.so.5.2.1
    0x000009d3d000-0x000009d56000   QT_DIRECTORY/gcc_64/lib/libQt5Core.so.5.2.1
    0x000009d56000-0x000009d58000
    0x000009d58000-0x000009e35000   /usr/lib64/nvidia/libGL.so.331.49
    0x000009e35000-0x00000a034000   /usr/lib64/nvidia/libGL.so.331.49
    0x00000a034000-0x00000a074000   /usr/lib64/nvidia/libGL.so.331.49
    0x00000a074000-0x00000a08b000
    0x00000a08b000-0x00000a0a3000   /lib64/libpthread-2.18.so
    0x00000a0a3000-0x00000a2a3000   /lib64/libpthread-2.18.so
    0x00000a2a3000-0x00000a2a4000   /lib64/libpthread-2.18.so
    0x00000a2a4000-0x00000a2a5000   /lib64/libpthread-2.18.so
    0x00000a2a5000-0x00000a2a9000
    0x00000a2a9000-0x00000a393000   /usr/lib64/libstdc++.so.6.0.18
    0x00000a393000-0x00000a592000   /usr/lib64/libstdc++.so.6.0.18
    0x00000a592000-0x00000a59a000   /usr/lib64/libstdc++.so.6.0.18
    0x00000a59a000-0x00000a59c000   /usr/lib64/libstdc++.so.6.0.18
    0x00000a59c000-0x00000a5b1000
    0x00000a5b1000-0x00000a6b3000   /lib64/libm-2.18.so
    0x00000a6b3000-0x00000a8b2000   /lib64/libm-2.18.so
    0x00000a8b2000-0x00000a8b3000   /lib64/libm-2.18.so
    0x00000a8b3000-0x00000a8b4000   /lib64/libm-2.18.so
    0x00000a8b4000-0x00000a8c2000   /usr/lib64/libgomp.so.1.0.0
    0x00000a8c2000-0x00000aac1000   /usr/lib64/libgomp.so.1.0.0
    0x00000aac1000-0x00000aac2000   /usr/lib64/libgomp.so.1.0.0
    0x00000aac2000-0x00000aac3000   /usr/lib64/libgomp.so.1.0.0
    0x00000aac3000-0x00000aad9000   /lib64/libgcc_s.so.1
    0x00000aad9000-0x00000acd8000   /lib64/libgcc_s.so.1
    0x00000acd8000-0x00000acd9000   /lib64/libgcc_s.so.1
    0x00000acd9000-0x00000acda000   /lib64/libgcc_s.so.1
    0x00000acda000-0x00000ae7e000   /lib64/libc-2.18.so
    0x00000ae7e000-0x00000b07e000   /lib64/libc-2.18.so
    0x00000b07e000-0x00000b082000   /lib64/libc-2.18.so
    0x00000b082000-0x00000b084000   /lib64/libc-2.18.so
    0x00000b084000-0x00000b088000
    0x00000b088000-0x00000b08b000   /lib64/libdl-2.18.so
    0x00000b08b000-0x00000b28a000   /lib64/libdl-2.18.so
    0x00000b28a000-0x00000b28b000   /lib64/libdl-2.18.so
    0x00000b28b000-0x00000b28c000   /lib64/libdl-2.18.so
    0x00000b28c000-0x00000b290000   /usr/lib64/libXv.so.1.0.0
    0x00000b290000-0x00000b48f000   /usr/lib64/libXv.so.1.0.0
    0x00000b48f000-0x00000b490000   /usr/lib64/libXv.so.1.0.0
    0x00000b490000-0x00000b491000   /usr/lib64/libXv.so.1.0.0
    0x00000b491000-0x00000b5c9000   /usr/lib64/libX11.so.6.3.0
    0x00000b5c9000-0x00000b7c9000   /usr/lib64/libX11.so.6.3.0
    0x00000b7c9000-0x00000b7ca000   /usr/lib64/libX11.so.6.3.0
    0x00000b7ca000-0x00000b7cf000   /usr/lib64/libX11.so.6.3.0
    0x00000b7cf000-0x00000b7e0000   /usr/lib64/libXext.so.6.4.0
    0x00000b7e0000-0x00000b9df000   /usr/lib64/libXext.so.6.4.0
    0x00000b9df000-0x00000b9e0000   /usr/lib64/libXext.so.6.4.0
    0x00000b9e0000-0x00000b9e1000   /usr/lib64/libXext.so.6.4.0
    0x00000b9e1000-0x00000ba30000   /usr/lib64/libgobject-2.0.so.0.3800.2
    0x00000ba30000-0x00000bc30000   /usr/lib64/libgobject-2.0.so.0.3800.2
    0x00000bc30000-0x00000bc31000   /usr/lib64/libgobject-2.0.so.0.3800.2
    0x00000bc31000-0x00000bc32000   /usr/lib64/libgobject-2.0.so.0.3800.2
    0x00000bc32000-0x00000bd33000   /usr/lib64/libglib-2.0.so.0.3800.2
    0x00000bd33000-0x00000bf32000   /usr/lib64/libglib-2.0.so.0.3800.2
    0x00000bf32000-0x00000bf33000   /usr/lib64/libglib-2.0.so.0.3800.2
    0x00000bf33000-0x00000bf34000   /usr/lib64/libglib-2.0.so.0.3800.2
    0x00000bf34000-0x00000bf35000
    0x00000bf35000-0x00000c13e000   QT_DIRECTORY/gcc_64/lib/libicui18n.so.51.1
    0x00000c13e000-0x00000c33e000   QT_DIRECTORY/gcc_64/lib/libicui18n.so.51.1
    0x00000c33e000-0x00000c34b000   QT_DIRECTORY/gcc_64/lib/libicui18n.so.51.1
    0x00000c34b000-0x00000c34d000   QT_DIRECTORY/gcc_64/lib/libicui18n.so.51.1
    0x00000c34d000-0x00000c34e000
    0x00000c34e000-0x00000c4be000   QT_DIRECTORY/gcc_64/lib/libicuuc.so.51.1
    0x00000c4be000-0x00000c6bd000   QT_DIRECTORY/gcc_64/lib/libicuuc.so.51.1
    0x00000c6bd000-0x00000c6ce000   QT_DIRECTORY/gcc_64/lib/libicuuc.so.51.1
    0x00000c6ce000-0x00000c6cf000   QT_DIRECTORY/gcc_64/lib/libicuuc.so.51.1
    0x00000c6cf000-0x00000c6d4000
    0x00000c6d4000-0x00000c6d5000   /usr/lib64/libgthread-2.0.so.0.3800.2
    0x00000c6d5000-0x00000c8d4000   /usr/lib64/libgthread-2.0.so.0.3800.2
    0x00000c8d4000-0x00000c8d5000   /usr/lib64/libgthread-2.0.so.0.3800.2
    0x00000c8d5000-0x00000c8d6000   /usr/lib64/libgthread-2.0.so.0.3800.2
    0x00000c8d6000-0x00000c8dd000   /lib64/librt-2.18.so
    0x00000c8dd000-0x00000cadc000   /lib64/librt-2.18.so
    0x00000cadc000-0x00000cadd000   /lib64/librt-2.18.so
    0x00000cadd000-0x00000cade000   /lib64/librt-2.18.so
    0x00000cade000-0x00000cae1000   /usr/lib64/libnvidia-tls.so.331.49
    0x00000cae1000-0x00000cce0000   /usr/lib64/libnvidia-tls.so.331.49
    0x00000cce0000-0x00000cce1000   /usr/lib64/libnvidia-tls.so.331.49
    0x00000cce1000-0x00000e849000   /usr/lib64/libnvidia-glcore.so.331.49
    0x00000e849000-0x00000ea48000   /usr/lib64/libnvidia-glcore.so.331.49
    0x00000ea48000-0x00000f4d3000   /usr/lib64/libnvidia-glcore.so.331.49
    0x00000f4d3000-0x00000f4f0000
    0x00000f4f0000-0x00000f50e000   /usr/lib64/libxcb.so.1.1.0
    0x00000f50e000-0x00000f70d000   /usr/lib64/libxcb.so.1.1.0
    0x00000f70d000-0x00000f70e000   /usr/lib64/libxcb.so.1.1.0
    0x00000f70e000-0x00000f70f000   /usr/lib64/libxcb.so.1.1.0
    0x00000f70f000-0x00000f716000   /usr/lib64/libffi.so.4.0.1
    0x00000f716000-0x00000f915000   /usr/lib64/libffi.so.4.0.1
    0x00000f915000-0x00000f916000   /usr/lib64/libffi.so.4.0.1
    0x00000f916000-0x00000f917000   /usr/lib64/libffi.so.4.0.1
    0x00000f917000-0x00000f982000   /usr/lib64/libpcre.so.1.2.5
    0x00000f982000-0x00000fb82000   /usr/lib64/libpcre.so.1.2.5
    0x00000fb82000-0x00000fb83000   /usr/lib64/libpcre.so.1.2.5
    0x00000fb83000-0x00000fb84000   /usr/lib64/libpcre.so.1.2.5
    0x00000fb84000-0x0000110cc000   QT_DIRECTORY/gcc_64/lib/libicudata.so.51.1
    0x0000110cc000-0x0000112cc000   QT_DIRECTORYgcc_64/lib/libicudata.so.51.1
    0x0000112cc000-0x0000112cd000   QT_DIRECTORY/gcc_64/lib/libicudata.so.51.1
    0x0000112cd000-0x0000112d0000   /usr/lib64/libXau.so.6.0.0
    0x0000112d0000-0x0000114cf000   /usr/lib64/libXau.so.6.0.0
    0x0000114cf000-0x0000114d0000   /usr/lib64/libXau.so.6.0.0
    0x0000114d0000-0x0000114d1000   /usr/lib64/libXau.so.6.0.0
    0x000038000000-0x0000383d6000   /usr/local/lib64/valgrind/memcheck-amd64-linux
    0x0000385d5000-0x0000385d9000   /usr/local/lib64/valgrind/memcheck-amd64-linux
    0x0000385d9000-0x00003a048000
    0x000802001000-0x000802b9c000
    0x000802b9c000-0x000802b9e000
    0x000802b9e000-0x000802c9e000   [stack:4038]
    0x000802c9e000-0x000802ca0000
    0x000802ca0000-0x000802ca1000   /tmp/vgdb-pipe-shared-mem-vgdb-4038-by-USERNAME-on-linux-92w9.site
    0x000802ca1000-0x000802cbd000
    0x000802cbd000-0x000803359000
    0x00080339b000-0x000803a94000
    0x000803b6c000-0x000806434000
    0x000ffeffe000-0x000fff001000
    0x7ffd84e0f000-0x7ffd84e31000
    0xffffffffff600000-0xffffffffff601000   [vsyscall]
==4038== End of process memory map.
==4038== 
==4038== HEAP SUMMARY:
==4038==     in use at exit: 0 bytes in 0 blocks
==4038==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==4038== 
==4038== All heap blocks were freed -- no leaks are possible
==4038== 
==4038== For counts of detected and suppressed errors, rerun with: -v
==4038== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

的输出在这里optirun valgrind -v ./projectname在线

glslangValidator 输出:

Warning, version 430 is not yet complete; most version-specific features are present, but some are missing.

快速解决:

i = i+1-1;在相关行之前添加该行可以解决错误。

4

0 回答 0