Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Getting validation raised because SPIRV prodces a decoration of clipdistance that isn't used #858

Closed
dankbaker opened this issue Aug 18, 2016 · 11 comments
Assignees

Comments

@dankbaker
Copy link

#version 450

layout(set=0,binding=0) buffer Dynamics
{    
     layout(offset=0)  vec4 s_Color;
     layout(offset=16) vec4 s_Color2;
     layout(offset=32) vec2 Scale;
     layout(offset=40) vec2 Offset;
     layout(offset=48) float ZDepth;
} DynamicsI;

layout(set=1,binding=0) uniform samplerBuffer V_Position;
layout(set=1,binding=1) uniform samplerBuffer V_TexCoord;

out vec2 Tex;

void main() 
{
    vec4 Pos = texelFetch (V_Position, gl_VertexIndex );
    Pos.xy = Pos.xy * DynamicsI.Scale + DynamicsI.Offset;

    Tex = texelFetch (V_TexCoord, gl_VertexIndex ).xy;
    gl_Position = Pos;
}

This vertex shader, after compilation in glsllang, will cause a validation message (error) because it declares the clipdistance as a decoration but doesn't use it but the device doesn't support it. All shaders generated from glslang will have this problem because it always adds this decoration.

@lentinem
Copy link

This has come up before and I believe glslang was going to address this. Assigning to Chris to make sure that was the resolution.

@dankbaker
Copy link
Author

Funny, I posted it to the GLSLang folks and they thought it was a validation issue.

@lentinem
Copy link

Can you post the bug link for their side here?

@chrisforbes
Copy link
Collaborator

The immediate solution is to explicitly redeclare the gl_PerVertex block to have the subset of members that you want.

@dankbaker
Copy link
Author

KhronosGroup/glslang#472

SPIRV folks say it's fine, GLSL compiler is outputting them. In order for the messages to go away I had to hack up GLSLang.

@chrisforbes
Copy link
Collaborator

@dankbaker in the interim, include a redeclaration like so:

out gl_PerVertex {
    vec4 gl_Position;
};

As for the issue, it looks like we shouldn't be producing this error unless you actually touch the clipdistance member. Unfortunately, that message isn't produced by the layer, it comes out of the validator within SPIRV-Tools.

@chrisforbes
Copy link
Collaborator

Raised a bug in the validator project where this needs to be fixed.

@dneto0
Copy link

dneto0 commented Aug 23, 2016

The rule was relaxed in the validator as of July 7, but only for the Vulkan 1.0 context, and remains strict in the "universal SPIR-V" target environments. (See the SPIRV-Tools bug for details commit hashes).

If using the validator API, you must use it with a context created with SPV_ENV_VULKAN_1_0.
If using spirv-val command line tool, you must specify --target-env, as follows:

$ glslc -c x.vert
$ ls x.*
x.vert  x.vert.spv
$ spirv-val x.vert.spv
error: 43: Operand 4 of MemberDecorate requires one of these capabilities: ClipDistance 
$ echo $?
243
$ spirv-val --target-env vulkan1.0  x.vert.spv
$ echo $?
0

@dneto0
Copy link

dneto0 commented Aug 23, 2016

After further discussion on KhronosGroup/SPIRV-Tools#365 we'll change the validator to allow these cases to pass with any environment.

@chrisforbes
Copy link
Collaborator

@dankbaker I've confirmed that this works using master, and it looks like everything required made it into the 1.0.21.1 SDK. Are you still seeing spurious errors?

@dankbaker
Copy link
Author

Latests SDK doesn't seem to generate the error, so looks good!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants