aconstlink / motor

Software Framework for Audio/Visual/Interactive Real-Time Applications
MIT License
1 stars 0 forks source link

msl return value deduction #61

Open aconstlink opened 3 months ago

aconstlink commented 3 months ago

If an overloaded function is used the generator picks all functions of the symbol regardless of the signature and puts them into the shader. Depending on the functions' size this could lead to miss-compilation.

There is no AST(or similar structure) for determining all the value types passed to a function so selecting the correct function is not possible.

Example:

There are two functions with the same name but different signature:

vec2_t xyz( in vec2_t vin ) {
    return vin ;
}

vec3_t xyz( in vec3_t vin ) {
    return vin ;
}

Selecting the right function can be done by name which is the current state. Selecting by signature is the problem here:

vec2_t some_other_function( in vec2_t vin ) {
    return vin ;
}

vec3_t some_other_function( in vec3_t vin ) {
    return vin ;
}
vec2_t some_vector ;
msl.xyz( some_vector ) ;
msl.xyz( some_other_function( some_vector ) ) ;

The first call could be resolved because variable types are present in the current state. The second call is more of a problem.

Here is another example:

vec2_t some_vector1 ;
vec2_t some_vector2 ;
msl.xyz( some_vecto1 + some_vector2 ) ;

So any expression leads to a resulting type which need to be determined in order to be able to select the correct overloaded function.

In the above case the shader generator needs to select the vec2_t version of the xyz function. At the moment, in order to make this happen, the generators use all occurrences of the function called and put them in the resulting shader.