inout Equivalent

Are parameters to functions in Metal “inout” (GLSL) by default?

If not, how can I achieve “inout” in Metal?



L. Spiro

Accepted Reply

The equivalent of inout in Metal shading language is using non-const references (or pointers), just like C++. However, you need to put the appropriate address space, and it depends on what you pass as argument (see section 4.2 of Metal shading language reference). If you are passing local variables, then the address space should be thread.


--

Francois

Replies

take a look at the [[ stage_in ]] attribute (page 61).

Isn’t [[ stage_in ]] just for vertex/pixel/etc. entry points?

I am talking about regular functions.


As in:

void SetLightArgsDir( inout DEF_LIGHT_ARGS _dlaArgs, in vec3 _vLightDir, in vec4 _vLightColor, in vec3 _vNormal ) {
  _dlaArgs.vLightDir = _vLightDir;
  _dlaArgs.vLightDiffuse = _vLightColor;

  _dlaArgs.fLdotN = saturate( dot( _dlaArgs.vLightDir, _vNormal ) );
  _dlaArgs.fLdotV = saturate( dot( _dlaArgs.vLightDir, _dlaArgs.vView ) );
  _dlaArgs.vLightHalfVector = normalize( _dlaArgs.vLightDir + _dlaArgs.vView );
  _dlaArgs.fLdotH = _dlaArgs.fVdotH = saturate( dot( _dlaArgs.vLightDir, _dlaArgs.vLightHalfVector ) );
  _dlaArgs.fNdotH = saturate( dot( _vNormal, _dlaArgs.vLightHalfVector ) );
  //_dlaArgs.fVdotH = saturate( dot( _dlaArgs.vView, _dlaArgs.vLightHalfVector ) );
}



L. Spiro

The equivalent of inout in Metal shading language is using non-const references (or pointers), just like C++. However, you need to put the appropriate address space, and it depends on what you pass as argument (see section 4.2 of Metal shading language reference). If you are passing local variables, then the address space should be thread.


--

Francois