这是我能想到的(最简单的)实例化着色器,它基本上只是转换了一堆 2D 基元:
#version 400
#extension GL_ARB_draw_instanced : enable
#extension GL_ARB_shading_language_420pack : enable
layout(std140, binding = 0) uniform VConstants {
vec4 vfuniforms[48];
};
in vec4 pos;
void main() {
gl_Position = vec4(0.0,0,0.0,1);
gl_Position.x = dot(pos, vfuniforms[int(float(gl_InstanceID) * 2.0)]);
gl_Position.y = dot(pos, vfuniforms[int(float(gl_InstanceID) * 2.0 + 1.0)]);
}
如果我尝试使用 Vulkan SDK 附带的 glslangValidator 将其编译为 SPIR-V,我会得到:
WARNING: 0:2: '#extension' : extension not supported: GL_ARB_draw_instanced
ERROR: 0:14: 'gl_InstanceID' : undeclared identifier
ERROR: 1 compilation errors. No code generated.
如果我删除该#extension GL_ARB_draw_instanced
行,我仍然会收到gl_InstanceID
错误消息。是否可以编写实例化 GLSL 并将它们编译为 SPIR-V?如果是这样,我做错了什么?