Error when sampling with seperate sampler and texture

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
    // ...
}

What am I missing?

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.

Because of the example in the extension description:

    Constructors can then be used to combine a sampler and a texture at the
    point of making a texture lookup call:

        texture2D(sampler2D(t, s), ...);

Note: ```

texture2D
The following features are removed:
    * ...
    * the already deprecated texturing functions (e.g., texture2D())

However, you are right, 

vec4 rgba = texture( sampler2D( my_tex, my_sampler ), vsTexCoord );

 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.

Ah, it’s an error in the specification then.

One you post this issue on Github, would you be able to post back here with the issue #id. Thanks.

Issue #466.

Thanks, missed that one.