google / shaderc

A collection of tools, libraries, and tests for Vulkan shader compilation.
Other
1.79k stars 344 forks source link

Entry point renaming functionality missing? #860

Open QuantumDeveloper opened 4 years ago

QuantumDeveloper commented 4 years ago

Using glslangValidator user can do entry point renaming (useful for GLSL) glslangValidator -e myEntry --source-entrypoint main Seems shaderc is missing this functionality? Would be useful when several GLSL shaders is present inside one file to implement something like effects framework

dneto0 commented 4 years ago

I believe that functionality exists in Glslang for HLSL, not for GLSL? I can't make it work with GLSL.

I tried a trivial fragment shader in GLSL with this command line:

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

But I got:

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

If I use -H instead of -o a.spv then it does emit expected 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

That may be a problem with Glslang. I don't even know if --source-entrypoint is supposed to work for anything other than HLSL.

dneto0 commented 4 years ago

I acknowledge this would be a useful feature for GLSL.

johnkslang commented 4 years ago

Note the example given in the OP is taken from https://github.com/KhronosGroup/glslang/issues/605 which showed how to do this for GLSL.

johnkslang commented 4 years ago

More detail is now in https://github.com/KhronosGroup/glslang/issues/1970#issuecomment-552056323.

Note this is all showing how to create SPIR-V with different entry-point names, not changing the rules of GLSL that require the GLSL source to have an entry-point of "void main()".

QuantumDeveloper commented 4 years ago

@johnkslang Sorry, I didnt really get how to rename entrypoint to main during SPIR-V compilation using shaderc. I am not using it from command line, but directly from code. Could you please give an example how to do described manipulation using shaderc?

johnkslang commented 4 years ago

Is this glslang functionality exposed through shaderc? I'm not a shaderc expert.

QuantumDeveloper commented 4 years ago

I didint find this in shaderc headers (at least in C interop interface)

johnkslang commented 4 years ago

My best guess is to classify this as an enhancement request for shaderc, @dneto0.