I am failing to properly use a separate sampler and texture in my glsl code. glslangValidator refuses to compile my code with this error: ERROR: shader/simple_push_const.frag:21: 'sampler/image' : cannot construct this type
The only source I know of which demonstrates proper usage is GL_KHR_vulkan_glsl, and here is my interpretation:
#version 450
#extension GL_KHR_vulkan_glsl : enable // tried this, not sure if required, get no error from this line
layout( set = 0, binding = 3 ) uniform texture2D my_tex; // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
layout( set = 0, binding = 4 ) uniform sampler my_sampler; // VK_DESCRIPTOR_TYPE_SAMPLER
layout( location = 0 ) in vec3 vsNormal;
layout( location = 1 ) in vec2 vsTexCoord;
layout( location = 0 ) out vec4 fsColor;
void main() {
// ...
vec4 rgba = texture( texture2D( sampler2D( my_tex, my_sampler )), vsTexCoord ); // line 21
// ...
}
Why are you constructing a texture2D from a sampler2D? You simply need to combine your existing texture2D with your sampler, which you did with sampler2D(my_tex, my_sampler). That’s the parameter you pass to texture.
#extension GL_KHR_vulkan_glsl : enable // tried this, not sure if required, get no error from this line
KHR_vulkan_glsl spec:
This extension is not enabled with a #extension as other extensions are.
[…]
Instead, use of this extension is an effect of using a GLSL front-end in a
mode that has it generate SPIR-V for Vulkan.
works, thanks.
Btw, I wonder why such an example is not in the spec. Without "accidentally" reading GL_KHR_vulkan_glsl extension I would not know how to use it at all. I'll create an issue.