varjo icon indicating copy to clipboard operation
varjo copied to clipboard

Add unsized array support & ensure it works properly in combination with interface blocks

Open cbaggers opened this issue 7 years ago • 7 comments

I think this is going to be a fairly large task. We havent made any real effort to make this work and so I expect there is some code that is assuming this won't be happening. Tread carefully and write tests :)

cbaggers avatar Jan 16 '18 13:01 cbaggers

added test to ensure array params are all sized

cbaggers avatar Apr 05 '18 19:04 cbaggers

Hey, could this be bumped up in priority if possible? I'm in need of stuff like this in vari:

layout(std430) buffer MyBuffer
{
  int rows, cols;
  int board[];
};

psilord avatar Apr 14 '18 10:04 psilord

This is the next thing to fix

cbaggers avatar Nov 21 '18 22:11 cbaggers

hmm, some part of it seems to work already

(v-defstruct unsized-tail ()
  (pos :vec3)
  (all-the-ints (:int *)))

(glsl-code
        (compile-vert ((vert pos-col)
                       &uniform (the-data unsized-tail :ssbo :std-140))
            :450 nil
          (with-slots (all-the-ints) the-data
            (setf (aref all-the-ints 1) 10)
            (v! 1 2 3 4))))

results in

"// vertex-stage
#version 450

layout(location = 0)  in vec3 fk_vert_position;
layout(location = 1)  in vec4 fk_vert_color;

layout(std140) buffer _SSBO_THE_DATA
{
    vec3 POS;
    int[] ALL_THE_INTS;
} THE_DATA;

void main()
{
    THE_DATA.ALL_THE_INTS[1] = 10;
    vec4 g_GEXPR0_933 = vec4(float(1),float(2),float(3),float(4));
    gl_Position = g_GEXPR0_933;
    return;
}
"

which kinda looks ok

cbaggers avatar Nov 21 '18 22:11 cbaggers

Just to clarify, I made no changes to varjo for the above to work

cbaggers avatar Nov 21 '18 22:11 cbaggers

more seems to work than expected. One issue we can see here is that the unsigned array is allowed in the non tail position of the values passed to the fragment stage. That's an easy thing to fix though.

TESTS> (glsl-code
        (compile-vert ((vert pos-col)
                       &uniform (the-data unsized-tail :ssbo :std-140))
            :450 nil
          (with-slots (all-the-ints) the-data
            (let ((x all-the-ints))
              (labels ((zoop ()
                         (aref x 10))
                       (zorp ()
                         (aref all-the-ints 10)))
                (zoop)
                (zorp)
                (values
                 (v! 1 2 3 4)
                 (v! 1 2)
                 all-the-ints
                 (v! 3 4)))))))
"// vertex-stage
#version 450

layout(location = 0)  in vec3 fk_vert_position;
layout(location = 1)  in vec4 fk_vert_color;

out _FROM_VERTEX_STAGE_
{
     out vec2 _VERTEX_STAGE_OUT_1;
     out int[] _VERTEX_STAGE_OUT_2;
     out vec2 _VERTEX_STAGE_OUT_3;
} v_out;

layout(std140) buffer _SSBO_THE_DATA
{
    vec3 POS;
    int[] ALL_THE_INTS;
} THE_DATA;

int ZOOP(int[] X);
int ZORP();

int ZORP()
{
    return THE_DATA.ALL_THE_INTS[10];
}

int ZOOP(int[] X)
{
    return X[10];
}

void main()
{
    int[] X = THE_DATA.ALL_THE_INTS;
    ZOOP(X);
    ZORP();
    vec4 g_PROG1_TMP962 = vec4(float(1),float(2),float(3),float(4));
    v_out._VERTEX_STAGE_OUT_1 = vec2(float(1),float(2));
    v_out._VERTEX_STAGE_OUT_2 = THE_DATA.ALL_THE_INTS;
    v_out._VERTEX_STAGE_OUT_3 = vec2(float(3),float(4));
    vec4 g_GEXPR0_963 = g_PROG1_TMP962;
    gl_Position = g_GEXPR0_963;
    return;
}

"

cbaggers avatar Nov 21 '18 23:11 cbaggers

gotta find out how this plays with geom and tess shaders

cbaggers avatar Nov 21 '18 23:11 cbaggers