I’m currently encountering an issue similar to the one described in this thread, but the difference is that I’m actually using a usampler2D and not sampling directly from a texture.
Take this (quickly hacked together) shader for a debug display of a deferred renderer:
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 1) uniform sampler2D samplerPosition;
layout (binding = 2) uniform sampler2D samplerNormal;
layout (binding = 3) uniform usampler2D samplerAlbedo;
layout (location = 0) in vec3 inUV;
layout (location = 0) out vec4 outFragColor;
void main()
{
vec3 components[3];
components[0] = texture(samplerPosition, inUV.st).rgb;
components[1] = texture(samplerNormal, inUV.st).rgb;
ivec2 texDim = textureSize(samplerAlbedo, 0);
uvec4 albedo = texelFetch(samplerAlbedo, ivec2(inUV.st * texDim ), 0);
vec4 color;
color.rg = unpackHalf2x16(albedo.r);
color.ba = unpackHalf2x16(albedo.g);
vec4 spec;
spec.rg = unpackHalf2x16(albedo.b);
components[2] = vec3(spec.r);
// Select component depending on z coordinate of quad
highp int index = int(inUV.z);
outFragColor.rgb = components[index];
}
This compiles perfectly to SPIR-V using the latest glslangvalidator, but throws a driver validation error when loading that shader:
ERROR: [Driver] Code 2 : Fragment info
-------------
(0) : fatal error C9999: Can't convert to expr: texelFetch
Which is caused by line 20:
uvec4 albedo = texelFetch(samplerAlbedo, ivec2(inUV.st * texDim ), 0);
Observations
After digging around it seems that this may be caused by newer versions of the glslangvalidator generating wrong/different SPIR-V output.
As with the validation layers, I’m always building the glslangvalidator from current sources instead of using the one from the SDK.
Now if I switch back to the glslangvalidator from the SDK for generating the SPIR-V for that shader, everything works fine. No validation layer error, and I get to see what I expect (unpacked color components).
So this may be an issue related to the SPIR-V output of the glsl reference compiler.
I have uploaded the SPIR-V outputs generated by the different versions of the validator:
- Working SPIR-V generated by glslangvalidator from SDK 1.0.17.0
- Crashing SPIR-V generated by glslangvalidator built from current sources
So if this is actually a bug caused by newer versions of the glslangvalidator generating wrong SPIR-V output I’d go on and report it at their repo.
Driver version is 368.51 on windows 10 (64-bit) with a GTX 980.