glCompileShader上的Mesa访问冲突

时间:2015-12-08 17:52:43

标签: opengl glsl mesa

我一直试图为Windows编译mesa。我一直在关注大约this教程,但使用MSYS2而不是完整的Linux操作系统。除了一个方面,我已经成功编译了一个功能正常的opengl32.dll。

当它包含任意数量的标准内置函数之一时,我在编译着色器时遇到访问冲突。其中包括以下内容:

getType max(genType, getType);
getType min(genType, getType);
float dot(genType x, genType y);
genType normalize(genType v);

这并非详尽无遗。大多数(可能是所有)内置函数都失败了。没有任何这些函数,着色器编译并运行正常。我无法获得编译日志或类似的东西,因为访问冲突意味着glCompileShader执行后没有代码。这是我的顶点着色器:

#version 130
in vec2 position;
void main()
{
    gl_Position = vec4(position, 0.0, 1.0);

    // Meaningless tests ...
    float a = 3.0, b = 4.0, c;
    c = max(a, b); // <-- COMPILES AND RUNS OK WITHOUT THIS LINE
}

C ++代码是一个简单的本机Windows应用程序,它遵循this tutorial。如果人们认为它是相关的,我可以发布完整的代码,但大多数只是窗口设置和类似。实际的着色器编译位如下所示:

// Load the shader source code from a file
std::string filePath("Shaders/vertex");
std::ifstream stream(filePath, std::ios::in);
std::string code = "", line = "";
while(getline(stream, line)) code += "\n" + line;
stream.close();
const char* code_c_str = code.c_str();
GLint code_length = code.size();

// Create a shader and compile the loaded source code
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShaderID, 1, &code_c_str, &code_length);
glCompileShader(vertexShaderID);

当链接到硬件库(在我的例子中是NVIDIA)时,程序运行正常。该程序在链接到由我公司的前雇员完成的Mesa构建时也起作用。不幸的是,个人没有留下关于如何构建Mesa二进制文件的文档。我尝试使用和不使用LLVM构建Mesa,每次都有相同的结果。

有谁知道为什么我的Mesa构建可能无法如此惊人地编译简单的内置glsl函数?

更新

我按照建议进行了调试构建,问题就消失了。这似乎是一个优化问题。我已经确定发布版本使用-O0或-O1优化,并且在-O2或-O3上失败。仍然有点痛苦,因为性能对于这个应用程序很重要,但至少我现在有一个可用的DLL并且想知道去哪里。

作为参考,我在msys2上使用默认的gcc / g ++交叉编译器,它似乎是4.9.2。我无法从调试器中获得太多,因为DLL是使用mingw构建的,但测试解决方案是在Visual Studio中。但是,我从gdb获得了这个:

#0  0x00000008 in ?? ()
#1  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#2  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#3  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#4  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#5  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#6  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#7  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#8  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#9  0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#10 0x630e51a0 in (anonymous namespace)::builtin_builder::new_sig(glsl_type const*, bool (*)(_mesa_glsl_parse_state const*), int, ...) [clone .constprop.166]
    () at src/glsl/list.h:440
#11 0x644395c0 in glsl_type::_struct_gl_DepthRangeParameters_type ()
   from C:\Users\will\Documents\Visual Studio 2012\Projects\OpenGLMinimalTest\Debug\opengl32.dll
#12 0x048c0964 in ?? ()
#13 0x00000002 in ?? ()
#14 0x01040000 in ?? ()
#15 0x00000000 in ?? ()

在Mesa代码之前或之后没有任何信息,因为这些位分别是Windows DLL和Visual Studio编译。错误在内置函数构建器中,这是有意义的,因为它的内置函数生成它。 (至少对我来说)这个错误的原因并不是很明显。

1 个答案:

答案 0 :(得分:0)

这不是一个完整的答案,但我认为这已经足够......

只有在更高级别的优化时,MinGW构建才会发生访问冲突问题。 O2及以上不起作用。问题在于着色器内置函数,但我们从未确切地知道它是什么或如何修复它。

最终,为了在Windows上生成高效的Mesa构建,我放弃了MinGW并使用visual studio构建。我使用以下python脚本作为起点。

https://github.com/florianlink/MesaOnWindows

希望这对于遇到同样问题的人来说是足够的信息。