texture2D and texelFetch incompatible ?

I’d like to fetch texel from a texture without a sampler. HLSL provides a Texture.Load() function that does this.
In GLSL there’s texelFetch function which takes a gsampler and a uint2 (for sampler2D) and returns the texel value. In OpenGL it simply bypasses the sampler configuration.
I tried to pass a texture2D instead of a sampler2D to texelFetch ; glslang doesn’t complain at all and build a shader. However when creating the pipeline the Nvidia driver emits an error :

"[Driver] Code 1: Fragment info

(0): fatal error C9999: Can’t convert to expr: texelFetch"

using driver 365.10.
Is this a driver bug or is texelFetch not intended to be used on texture and in the later case, what is the glsl equivalent of texture.Load function ? I would like to avoid creating and tracking a sampler if possible.


For reference here is the dump with -H :

linearize_depth.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.

Linked fragment stage:

// Module Version 10000
// Generated by (magic number): 80001
// Id’s are bound by 69

                          Capability Shader
           1:             ExtInstImport  "GLSL.std.450"
                          MemoryModel Logical GLSL450
                          EntryPoint Fragment 4  "main" 12 57
                          ExecutionMode 4 OriginUpperLeft
                          Source GLSL 450
                          SourceExtension  "GL_ARB_separate_shader_objects"
                          SourceExtension  "GL_ARB_shading_language_420pack"
                          Name 4  "main"
                          Name 9  "uv"
                          Name 12  "gl_FragCoord"
                          Name 19  "d"
                          Name 22  "tex"
                          Name 34  "c0"
                          Name 36  "SSAOBuffer"
                          MemberName 36(SSAOBuffer) 0  "ModelMatrix"
                          MemberName 36(SSAOBuffer) 1  "ViewProjectionMatrix"
                          MemberName 36(SSAOBuffer) 2  "ProjectionMatrix"
                          MemberName 36(SSAOBuffer) 3  "zn"
                          MemberName 36(SSAOBuffer) 4  "zf"
                          Name 38  ""
                          Name 47  "c1"
                          Name 53  "c2"
                          Name 57  "FragColor"
                          Name 68  "Depth"
                          Decorate 12(gl_FragCoord) BuiltIn FragCoord
                          Decorate 22(tex) DescriptorSet 0
                          Decorate 22(tex) Binding 0
                          MemberDecorate 36(SSAOBuffer) 0 ColMajor
                          MemberDecorate 36(SSAOBuffer) 0 Offset 0
                          MemberDecorate 36(SSAOBuffer) 0 MatrixStride 16
                          MemberDecorate 36(SSAOBuffer) 1 ColMajor
                          MemberDecorate 36(SSAOBuffer) 1 Offset 64
                          MemberDecorate 36(SSAOBuffer) 1 MatrixStride 16
                          MemberDecorate 36(SSAOBuffer) 2 ColMajor
                          MemberDecorate 36(SSAOBuffer) 2 Offset 128
                          MemberDecorate 36(SSAOBuffer) 2 MatrixStride 16
                          MemberDecorate 36(SSAOBuffer) 3 Offset 192
                          MemberDecorate 36(SSAOBuffer) 4 Offset 196
                          Decorate 36(SSAOBuffer) Block
                          Decorate 38 DescriptorSet 0
                          Decorate 38 Binding 1
                          Decorate 57(FragColor) Location 0
                          Decorate 68(Depth) DescriptorSet 0
                          Decorate 68(Depth) Binding 1
                          Decorate 68(Depth) NonReadable
           2:             TypeVoid
           3:             TypeFunction 2
           6:             TypeFloat 32
           7:             TypeVector 6(float) 2
           8:             TypePointer Function 7(fvec2)
          10:             TypeVector 6(float) 4
          11:             TypePointer Input 10(fvec4)

12(gl_FragCoord): 11(ptr) Variable Input
15: 6(float) Constant 1149239296
16: 7(fvec2) ConstantComposite 15 15
18: TypePointer Function 6(float)
20: TypeImage 6(float) 2D sampled format:Unknown
21: TypePointer UniformConstant 20
22(tex): 21(ptr) Variable UniformConstant
26: TypeInt 32 1
27: TypeVector 26(int) 2
29: 26(int) Constant 0
31: TypeInt 32 0
32: 31(int) Constant 0
35: TypeMatrix 10(fvec4) 4
36(SSAOBuffer): TypeStruct 35 35 35 6(float) 6(float)
37: TypePointer Uniform 36(SSAOBuffer)
38: 37(ptr) Variable Uniform
39: 26(int) Constant 3
40: TypePointer Uniform 6(float)
43: 26(int) Constant 4
56: TypePointer Output 10(fvec4)
57(FragColor): 56(ptr) Variable Output
66: TypeImage 6(float) 2D nonsampled format:R32f
67: TypePointer UniformConstant 66
68(Depth): 67(ptr) Variable UniformConstant
4(main): 2 Function None 3
5: Label
9(uv): 8(ptr) Variable Function
19(d): 18(ptr) Variable Function
34(c0): 18(ptr) Variable Function
47(c1): 18(ptr) Variable Function
53(c2): 18(ptr) Variable Function
13: 10(fvec4) Load 12(gl_FragCoord)
14: 7(fvec2) VectorShuffle 13 13 0 1
17: 7(fvec2) FDiv 14 16
Store 9(uv) 17
23: 20 Load 22(tex)
24: 10(fvec4) Load 12(gl_FragCoord)
25: 7(fvec2) VectorShuffle 24 24 0 1
28: 27(ivec2) ConvertFToS 25
30: 10(fvec4) ImageFetch 23 28 Lod 29
33: 6(float) CompositeExtract 30 0
Store 19(d) 33
41: 40(ptr) AccessChain 38 39
42: 6(float) Load 41
44: 40(ptr) AccessChain 38 43
45: 6(float) Load 44
46: 6(float) FMul 42 45
Store 34(c0) 46
48: 40(ptr) AccessChain 38 39
49: 6(float) Load 48
50: 40(ptr) AccessChain 38 43
51: 6(float) Load 50
52: 6(float) FSub 49 51
Store 47(c1) 52
54: 40(ptr) AccessChain 38 43
55: 6(float) Load 54
Store 53(c2) 55
58: 6(float) Load 34(c0)
59: 6(float) Load 19(d)
60: 6(float) Load 47(c1)
61: 6(float) FMul 59 60
62: 6(float) Load 53(c2)
63: 6(float) FAdd 61 62
64: 6(float) FDiv 58 63
65: 10(fvec4) CompositeConstruct 64 64 64 64
Store 57(FragColor) 65
Return
FunctionEnd

Thanks for reporting this; we are investigating.

In the meantime could you try the 365.19 driver we released last week?

Regards,

Mathias Schott

For the record, glslang now returns an error if you try to use texelFetch with a texture2D.
Link to the issue: https://github.com/KhronosGroup/glslang/issues/252

The interesting part:

Also, some functions (such as texelFetch) feel like they might work with a gtextureXX object. But this doesn’t seem to be guaranteed by GL_KHR_vulkan_glsl. It might be clearer if it just generated a compile error.

Thanks. Since it’s out of spec the issue is invalid.