Using the [[clip_distance]] attribute in a Metal shader?

In a Metal shader, I am trying to make use of the [[clip_distance]] attribute in the output structure of a vertex shader function as follows:


struct vtx_out {

    float4 gl_Position [[position]];

    float gl_ClipDistance[1] [[clip_distance]];

};


However, this results in the following shader compilation error:


<program source>:86:32: error: 'clip_distance' attribute cannot be applied to types

    float gl_ClipDistance[1] [[clip_distance]];

                               ^


I am trying to compile this for running on a Mac running OS X El Capitan.


Why am I getting this error, and how can I make use of the [[clip_distance]] attribute?

Answered by Bill Hollings in 230226022

It turns out the

[[clip_distance]]
attribute qualifier (or any attribute qualifier) must be applied to the array, not the array element. So...the correct declaration is...


float gl_ClipDistance [[clip_distance]] [1];


See this SO answer.

This sounds like it could be a compiler bug. Could you file a Radar with a sample project that reproduces the issue and let us know the number here? Thanks.

Accepted Answer

It turns out the

[[clip_distance]]
attribute qualifier (or any attribute qualifier) must be applied to the array, not the array element. So...the correct declaration is...


float gl_ClipDistance [[clip_distance]] [1];


See this SO answer.

Using the [[clip_distance]] attribute in a Metal shader?
 
 
Q