You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向片段着色器传递额外变量导致着色器程序完全失效

AMD核显GLSL着色器输出赋值导致渲染空白问题

着色器代码

顶点着色器

in vec3 a_Position;
in vec4 a_Color;
in float a_Width;
in vec4 a_JointProduct;
in int a_EntityID;

layout(location=0) out vec3 pos;
layout(location=1) out vec4 color;
layout(location=2) out float v_stroke_width;
layout(location=3) out flat int v_EntityID;
layout(location=4) out vec4 v_joint_product;

layout(std140, binding = 0) uniform Camera
{
  mat4 u_ViewProjection;
};


void main(){
    gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
    pos = vec3(1.0, 1.0, 1.0);
    color = vec4(1.0);
    v_stroke_width = a_Width;
    //v_joint_product = a_JointProduct;
    //v_EntityID = a_EntityID;
}

片段着色器

layout(location = 0) out vec4 frag_color;

layout(location=0) in vec3 pos;
layout(location=1) in vec4 v_color;
layout(location=2) in float v_stroke_width;
layout(location=3) in flat int v_EntityID;
layout(location=4) in vec4 v_joint_product;


void main() {
    frag_color = vec4(1.0);
}

问题现象

  • 注释掉v_joint_product = a_JointProduct;和v_EntityID = a_EntityID;时,搭配测试数据可正常渲染预期结果。
  • 取消其中任意一行的注释后,渲染结果完全空白,无任何三角形显示。
  • 着色器编译、链接均无错误,但程序停止正常渲染。

环境信息

Vendor: ATI Technologies Inc.
Renderer: AMD Radeon(TM) Graphics
Version: 4.5.14802 Core Profile/Debug Context 21.40.18.15 30.0.14018.15002

已知情况

问题仅出现在上述AMD核显环境,在独显及Linux系统的集成/独显环境下均正常,推测为驱动兼容性问题。

解决建议

  • 调整输出变量的location布局:尝试交换v_EntityID和v_joint_product的location编号,或将flat int类型变量放在更靠前的位置,避免与vec4类型变量的位置冲突。
  • 显式初始化所有输出变量:在顶点着色器开头对所有输出变量做默认初始化,比如v_EntityID = 0;、v_joint_product = vec4(0.0);,避免驱动处理未初始化的变量状态异常。
  • 修改变量类型的存储限定:将flat int改为flat ivec1,或对a_EntityID尝试ivec1类型兼容处理,规避驱动对单个int类型flat输出的处理bug。
  • 更新显卡驱动:升级到AMD官方最新核显驱动版本,修复已知的GLSL兼容性问题。
  • 绕过flat限定符测试:暂时移除v_EntityID的flat限定符,若能正常渲染,再通过其他方式实现flat插值需求(比如将ID编码到vec4通道传递)。

内容的提问来源于stack exchange,提问作者Batres

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 01:10:18