cbaggers / varjo

Lisp to GLSL Language Translator
BSD 2-Clause "Simplified" License
223 stars 23 forks source link

Bug in implicit discarding of extra return values #199

Closed djeis97 closed 6 years ago

djeis97 commented 6 years ago

When an external function returns multiple values but the call site doesn't explicitly use multiple-value-bind to capture them varjo appears to be storing these extra values in generated out-variables for the stage as a whole, however it's not actually generating the declarations for these variables so the shader fails to compile.

Test case:

(varjo:add-external-function 'foo '() '() '((values 1 2)))
(varjo:translate (varjo:make-stage :fragment '() '() '() '((let ((x (foo))) (vari:vec4 x)))))

(varjo:glsl-code *) ;; =>

"// fragment-stage
#version 460

layout(location = 0)  out vec4 _FRAGMENT_STAGE_OUT_0;

int FOO(out int return_1);

int FOO(out int return_1)
{
    int g_PROG1_TMP889 = 1;
    return_1 = 2;
    return g_PROG1_TMP889;
}

void main()
{
    int X = FOO(_FRAGMENT_STAGE_OUT_1);
    vec4 g_GEXPR0_898 = vec4(float(X));
    _FRAGMENT_STAGE_OUT_0 = g_GEXPR0_898;
    return;
}

"

Note _FRAGMENT_STAGE_OUT_1.

djeis97 commented 6 years ago

As a side note, this breaks with the vertex stage as well (haven't tested any others).

cbaggers commented 6 years ago

ooh nasty. thanks for the bug report!

cbaggers commented 6 years ago

Patreons have just funded the fixing of this big as I'be fixed it down the coffee shop :p

I'll push these fix when I'm home as I don't trust public wifi