Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is --source-entrypoint intended to work with GLSL? #1970

Closed
dneto0 opened this issue Nov 8, 2019 · 1 comment
Closed

Is --source-entrypoint intended to work with GLSL? #1970

dneto0 opened this issue Nov 8, 2019 · 1 comment

Comments

@dneto0
Copy link
Contributor

dneto0 commented Nov 8, 2019

This is prompted by google/shaderc#860

With this GLSL shader:

#version 450
layout(location = 0) out vec4 o;
void a() { o = vec4(1.0); }
void b() { o = vec4(2.0); }

I tried:

  glslangValidator -V a.frag --sep a -e main -o a.spv

and got this error:

     a.frag
     ERROR: Source entry point must be "main"

If I use -H instead of -o a.spv then it does emit sensible output:

                          Capability Shader
           1:             ExtInstImport  "GLSL.std.450"
                          MemoryModel Logical GLSL450
                          EntryPoint Fragment 4  "main" 9
                          ExecutionMode 4 OriginUpperLeft
                          Source GLSL 450
                          Name 4  "main"
                          Name 9  "o"
                          Decorate 9(o) Location 0
           2:             TypeVoid
           3:             TypeFunction 2
           6:             TypeFloat 32
           7:             TypeVector 6(float) 4
           8:             TypePointer Output 7(fvec4)
        9(o):      8(ptr) Variable Output
          10:    6(float) Constant 1065353216
          11:    7(fvec4) ConstantComposite 10 10 10 10
     4(main):           2 Function None 3
           5:             Label
                          Store 9(o) 11
                          Return
                          FunctionEnd

So there's a discrepancy between -H and -o.

But also the person in the Shaderc issue was suggesting --sep would be useful for GLSL compilation.

@johnkslang
Copy link
Member

There are multiple subjects. (See #605 as a related issue.)

Legal GLSL

It is illegal GLSL to not have the source code have "void main()" as the entry point. SPIR-V for Vulkan/OpenGL did not change that rule.

Renaming the SPIR-V entry point

You should be able to use the following to rename the GLSL entry point to a different SPIR-V entry point:

glslangValidator -e myEntry --source-entrypoint main ...

Compile-time versus link-time with multiple compilation units

Lacking main as an entry point is a link-time error, not a compile-time error, and your shader uses a desktop version, which allows multiple compilation units (as in, the entry point could still be in another compilation).

Both the -H and -V options implicitly request the link for you, but you need to provide all the compilation units together, as SPIR-V for graphics has only one compilation unit per stage, so multiple GLSL compilation units are turned into a single SPIR-V compilation unit in one go.

-o

It looks like when -o was added, it did not also implicitly link. I can see that going either way, depending on whether you want it to act like other tools making just one of many compilation units, or do what SPIR-V for graphics actually needs today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants