Skip to content

Bad GLSL from shared term in conditional #36

Description

@floybix

Hi, I found this failure case. If a term appears multiple times within one branch of an if, the shared term gets emitted without an assignment to a variable.

(require '[gamma.api :as g])
(require '[gamma.program :as p])

(def ans2
  (let [g-elem (g/* 5 5)
        sh {(g/gl-position) (g/vec4 (g/if (g/== 0 0)
                                          (g/+ g-elem g-elem)
                                          0.0))}]
    (:glsl (p/shader sh {:float :highp}))))

(println ans2)
precision highp float;

void main(void){
float v387;
float v394;
if((0.0 == 0.0)){
  (5.0 * 5.0);                       <----- note missing assignment
  (v387 = (v394 + v394));}
  else {
    (v387 = 0.0);}
(gl_Position = vec4(v387));
}

I tried to track it down in the code but got lost in the compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions