alixinne / glsl-lang

LALR parser for GLSL
https://alixinne.github.io/glsl-lang/glsl_lang/
BSD 3-Clause "New" or "Revised" License
23 stars 4 forks source link

Add GL_KHR_vulkan_glsl types to parser #8

Closed ennis closed 2 years ago

ennis commented 2 years ago

This PR adds parser and AST support for the types defined in GL_KHR_vulkan_glsl.

alixinne commented 2 years ago

Thanks for the contribution! However, in order to add support for more Vulkan tokens (aside from the ones from the GLSL 4.60 spec, which are a subset of GL_KHR_vulkan_glsl), you need to add the new tokens to some other locations as well:

ennis commented 2 years ago

It looks like the 41 tokens were already there in lexer and pp. If I'm not mistaken, only AST code needed to be updated.

alixinne commented 2 years ago

It looks like the 41 tokens were already there in lexer and pp. If I'm not mistaken, only AST code needed to be updated.

Yes, my bad, I thought there were extra tokens compared to what is mentioned in the GLSL 4.60 spec. It's all good on the lexing/parsing side. However you'll need to update glsl-lang-quote to support the changes in the AST (see lang-quote/src/tokenize.rs).

Since this brings Vulkan types as part of the AST, it would be nice to cover these with at least some tests. Maybe by adding lang/data/vulkan_types.glsl as follows:

uniform texture1D         u1;
uniform texture2D         u2;
uniform texture3D         u3;
uniform textureCube       u4;
uniform texture2DRect     u5;
uniform texture1DArray    u6;
uniform texture2DArray    u7;
uniform textureBuffer     u8;
uniform texture2DMS       u9;
uniform texture2DMSArray  u10;
uniform textureCubeArray  u11;
uniform itexture1D        u12;
uniform itexture2D        u13;
uniform itexture3D        u14;
uniform itextureCube      u15;
uniform itexture2DRect    u16;
uniform itexture1DArray   u17;
uniform itexture2DArray   u18;
uniform itextureBuffer    u19;
uniform itexture2DMS      u20;
uniform itexture2DMSArray u21;
uniform itextureCubeArray u22;
uniform sampler           u23;
uniform samplerShadow     u24;
uniform subpassInput      u25;
uniform isubpassInput     u26;
uniform usubpassInput     u27;
uniform subpassInputMS    u28;
uniform isubpassInputMS   u29;
uniform usubpassInputMS   u30;

And then parsing it and comparing it with an AST structure in lang/src/parse_tests.rs? parse_buffer_block_0 is an example of such a test.

ennis commented 2 years ago

Added parser tests as suggested, and updated lang-quote