2015-10-18 142 views
4

我能夠在桌面上使用GLSL 330核心實例渲染,但我無法在Android上運行相同的C++代碼(使用SDL2和NDK構建系統和Android Studio)。OpenGL ES 3實例渲染失敗,但在桌面上工作

的logcat的誤差如下所示:

-18 15:49:57.264 20996-21026/package I/SDL/APP: shaders/mobile/sceneShader.frag.glsl compiled successfully 
10-18 15:49:57.274 20996-21026/package I/SDL/APP: Program link failed: --From Vertex Shader: 
10-18 15:49:57.274 20996-21026/packageI/SDL/APP: linker error: multiple attribute attempt to bind at same location 
10-18 15:49:57.274 20996-21026/packageI/SDL/APP: --From Fragment Shader: 
10-18 15:49:57.274 20996-21026/package I/SDL/APP: linker error: multiple attribute attempt to bind at same location 

我的桌面和移動着色器代碼是除了在文件的頂部,其中的#Version線(分別指定ES或桌面版本)相同。

我的移動着色器代碼如下所示:

#version 300 es 

precision mediump float; 

// attribute data 
layout (location = 0) in vec3 VertexPosition; 
layout (location = 1) in vec2 VertexTexCoord; 
layout (location = 2) in vec3 VertexNormal; 
layout (location = 3) in mat4 InstanceTransform; // used for translating the positions of instance renders 

// varying data 
layout (location = 0) out vec3 vPosition; 
layout (location = 1) out vec2 vTexCoord0; 
layout (location = 2) out vec2 vTexCoord1; 
layout (location = 3) out vec3 vTexSkyboxCoord; 
layout (location = 4) out vec3 vNormal; 
layout (location = 5) out vec3 vClampColor; 

// uniform data 
layout (location = 0) uniform bool uInstanceRendering; 

layout (location = 1) uniform mat4 uModelViewMatrix; 
layout (location = 2) uniform mat4 uProjectionMatrix; 
layout (location = 3) uniform mat3 uNormalMatrix; 

layout (location = 4) uniform vec2 uTexOffset0; 
layout (location = 5) uniform vec2 uTexOffset1; 

void main(void) 
{ 
    vec4 mvPosition; 

    if (uInstanceRendering) 
    { 
     mvPosition = uModelViewMatrix * InstanceTransform * vec4(VertexPosition, 1.0); 
    } 
    else 
    { 
     mvPosition = uModelViewMatrix * vec4(VertexPosition, 1.0); 
    } 

    vTexSkyboxCoord = VertexPosition; // for skybox rendering 

    const float atlasRows = 6.0f; 
    vTexCoord0 = (VertexTexCoord/atlasRows) + uTexOffset0; 
    vTexCoord1 = (VertexTexCoord/atlasRows) + uTexOffset1; 

    vPosition = mvPosition.xyz; 

    vNormal = normalize(uNormalMatrix * VertexNormal); 

    vClampColor = clamp(VertexPosition, 0.0, 1.0); 

    gl_Position = uProjectionMatrix * mvPosition; 

#ifdef GL_ES 
    gl_PointSize = 10.0f; 
#endif 
} 

繁瑣使用在C++側和GLSL側二者的評論我已銷指向的錯誤這行代碼後:

mvPosition = uModelViewMatrix * InstanceTransform * vec4(VertexPosition, 1.0); 

如果我將它註釋掉,程序將會編譯,但不會執行glDraw * Instaced調用,而沒有大量與gpu相關的錯誤(如logcat所示)。

10-18 15:58:42.504 29196-29238/package W/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/package W/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-ES20: <finish_current_fbo_rendering:315>: GL_OUT_OF_MEMORY 

我做了一個小例子來簡單測試實例渲染和同樣的問題與OpenGL ES的3(也使用SDL仍然)彈出。

#version 300 es 
precision mediump float; 

// attribute data 
layout (location = 0) in vec3 aVertexPosition; 
layout (location = 1) in vec2 aVertexTexCoord; 
layout (location = 2) in vec3 aVertexNormal; 
layout (location = 3) in mat4 aInstanceTransform; 

// varying data 
out vec3 vPosition; 
out vec2 vTexCoord; 
out vec3 vNormal; 

// uniform data 
uniform mat4 uModelViewMatrix; 
uniform mat4 uProjectionMatrix; 
uniform mat3 uNormalMatrix; 

void main(void) 
{ 
    vec4 mvTransform = uModelViewMatrix * aInstanceTransform * vec4(aVertexPosition, 1.0); 

    vTexCoord = aVertexTexCoord; 

    vPosition = mvTransform.xyz; 

    vNormal = normalize(uNormalMatrix * aVertexNormal); 

    gl_Position = uProjectionMatrix * mvTransform; 
} 

這裏是我設置的頂點數據:

glBindBuffer(GL_ARRAY_BUFFER, mVBO_InstanceData); 
glBufferData(GL_ARRAY_BUFFER, instanceData.size() * sizeof(glm::mat4), instanceData.data(), GL_STATIC_DRAW); 

glEnableVertexAttribArray(3); 
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(0)); 
glVertexAttribDivisor(3, 1); // increment instance data by 1 each iteration 

glEnableVertexAttribArray(4); 
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(sizeof(glm::vec4))); 
glVertexAttribDivisor(4, 1); 

glEnableVertexAttribArray(5); 
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(2 * sizeof(glm::vec4))); 
glVertexAttribDivisor(5, 1); 

glEnableVertexAttribArray(6); 
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(3 * sizeof(glm::vec4))); 
glVertexAttribDivisor(6, 1); 

回答

0

我發現在頂點着色器中只使用'glBindAttribLocation'而不是佈局限定符修復了問題。我甚至使用了與佈局限定符相同的編號方案。我想知道我是否可以用4個vec4設置實例數據?我想mat4會在我的移動設備上拋出編號方案?

4

你的一些location預選賽是不符合300 es着色器版本。你的頂點着色器包含以下定義:

layout (location = 0) out vec3 vPosition; 
... 

的GLSL ES 3.00規範說:

頂點着色不能有輸出佈局預選賽。

頂點和片段着色器允許在輸出變量聲明位置佈局限定符:

此限制僅在3.10版本,其中相應的措詞已經改變到解除。

幾乎同樣的道理也適用於制服,在您使用:

layout (location = 0) uniform bool uInstanceRendering; 
... 

而且這裏,着色器版本3.00不允許在制服layout預選賽:

佈局預選賽可用於統一塊,但不用於非塊統一聲明。

此外,該選項在版本3.10中添加。

+0

啊,感謝您查看我的代碼並通知我這件事。在我移植到移動設備之前,我在桌面上進行了大部分測試,因此我必須對其進行調整。但是,這並沒有解決我的GPU實例問題。我認爲這可能是我的硬件(我的電話),但我還不確定。 – BlazePascal

+0

如果您刪除佈局指令,您仍然收到鏈接錯誤嗎?對於制服,你當然必須使用'glGetUniformLocation()'來代替。 –

+0

是的,在將佈局限定符添加到輸出和統一變量之前,出現了錯誤。我只是添加了它們,因爲我認爲它可以解決移動端的綁定問題。 – BlazePascal