最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

glsl - Push Constant not a constant integer expression for setting uniform buffer array size - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a fragment shader for a Vulcan application that takes an array of texture2Ds. I have this working however i need to set the size of the array at application run time rather than compile time.

I'm trying to do this using a push constant to push the number of textures into the shader to set the array size. But my GLSL compiler is complaining that the push constant is not a constant integer expression.

Here is my current shader, it works however produces an error message if provided less than 8 textures at runtime.

#version 450

layout(set = 0, binding = 1) uniform sampler samp;
layout(set = 0, binding = 2) uniform texture2D textures[8];

layout(location = 0) in flat uint fragTexID;

layout(location = 1) in vec2 fragTexCoord;

layout(location = 0) out vec4 outColor;

void main() {
    outColor = texture(sampler2D(textures[ fragTexID ], samp), fragTexCoord);
}

And now adding in push constants to set the size of the textures array

#version 450

layout(push_constant) uniform PushConstants {
    uint myUint;
} pc;

layout(set = 0, binding = 1) uniform sampler samp;
layout(set = 0, binding = 2) uniform texture2D textures[ pc.myUint ];

layout(location = 0) in flat uint fragTexID;

layout(location = 1) in vec2 fragTexCoord;

layout(location = 0) out vec4 outColor;

void main() {
    outColor = texture(sampler2D(textures[ fragTexID ], samp), fragTexCoord);
}

But when compiled this complains that "array size must be a constant integer expression", I assumed push constants would be constant, especially since it is defined as uniform.

I have also tried explicity stating my uint myUint as uniform uint myUint but get the same error.

Any idea what i'm doing wrong here, or if this approach won't work, is it possible to set the array size at runtime?

Thank-you :)

发布评论

评论列表(0)

  1. 暂无评论