@@ -10,25 +10,33 @@ with some additional workarounds and emulation. We emulate OpenGL's different de
1010y flipping, default uniforms, and OpenGL
1111[ line segment rasterization] ( OpenGLLineSegmentRasterization.md ) . For more info see
1212[ TranslatorVulkan.cpp] [ TranslatorVulkan.cpp ] . After initial compilation the shaders are not
13- complete. They are templated with markers that are filled in later at link time.
14-
15- 1 . ** Link-Time Translation** : During a call to ` glLinkProgram ` the Vulkan back-end can know the
16- necessary locations and properties to write to connect the shader stage interfaces. We get the
17- completed shader source using ANGLE's [ GlslangWrapperVk] [ GlslangWrapperVk.cpp ] helper class. We still
18- cannot generate ` VkShaderModules ` since some ANGLE features like
19- [ OpenGL line rasterization] ( OpenGLLineSegmentRasterization.md ) emulation depend on draw-time
20- information.
21-
22- 1 . ** Draw-time SPIR-V Generation** : Once the application records a draw call we use Khronos'
23- [ glslang] [ glslang ] to convert the Vulkan-compatible GLSL into SPIR-V. The SPIR-V is then compiled
24- into ` VkShaderModules ` . For details please see [ GlslangWrapperVk.cpp] [ GlslangWrapperVk.cpp ] . The
25- ` VkShaderModules ` are then used by ` VkPipelines ` with the appropriate specialization constant
26- values. Note that we currently don't use [ SPIRV-Tools] [ SPIRV-Tools ] to perform any SPIR-V
27- optimization. This could be something to improve on in the future.
13+ complete. The translator initially assigns resources and in/out variables arbitrary descriptor set,
14+ binding and location indices. The correct values are determined at link time. For the sake of
15+ transform feedback, some markers are left in the shader for link-time substitution.
16+
17+ The translator outputs some feature code conditional to Vulkan specialization constants, which are
18+ resolved at draw-time. For example,
19+ [ Bresenham line rasterization] ( OpenGLLineSegmentRasterization.md ) emulation.
20+
21+ 1 . ** Link-Time Compilation and Transformation** : During a call to ` glLinkProgram ` the Vulkan
22+ back-end can know the necessary locations and properties to write to connect the shader stage
23+ interfaces. We get the completed shader source using ANGLE's
24+ [ GlslangWrapperVk] [ GlslangWrapperVk.cpp ] helper class. At this time, we use Khronos'
25+ [ glslang] [ glslang ] to convert the Vulkan-compatible GLSL into SPIR-V. A transformation pass is done
26+ on the generated SPIR-V to update the arbitrary descriptor set, binding and location indices set in
27+ step 1. Additionally, component and various transform feedback decorations are added and inactive
28+ varyings are removed from the shader interface. We currently don't generate ` VkShaderModules ` at
29+ this time, but that could be a future optimization.
30+
31+ 1 . ** Draw-time Pipeline Creation** : Once the application records a draw call, the SPIR-V is compiled
32+ into ` VkShaderModule ` s. The appropriate specialization constants are then resolved and the
33+ ` VkPipeline ` object is created. Note that we currently don't use [ SPIRV-Tools] [ SPIRV-Tools ] to
34+ perform any SPIR-V optimization. This could be something to improve on in the future.
2835
2936See the below diagram for a high-level view of the shader translation flow:
3037
3138<!-- Generated from https://bramp.github.io/js-sequence-diagrams/
39+ Note: remove whitespace in - -> arrows.
3240participant App
3341participant "ANGLE Front-end"
3442participant "Vulkan Back-end"
@@ -41,7 +49,7 @@ App->"ANGLE Front-end": glCompileShader (VS)
4149"Vulkan Back-end"->"ANGLE Translator": sh::Compile
4250"ANGLE Translator"- ->"ANGLE Front-end": return Vulkan-compatible GLSL
4351
44- Note right of "ANGLE Front-end": Source is templated\nwith markers to be\nfilled at link time.
52+ Note right of "ANGLE Front-end": Source is using bogus\nVulkan qualifiers to be\ncorrected at link time.
4553
4654Note right of App: Same for FS, GS, etc...
4755
@@ -52,22 +60,20 @@ App->"ANGLE Front-end": glLinkProgram
5260
5361Note right of "Vulkan Back-end": ProgramVk inits uniforms,\nlayouts, and descriptors.
5462
55- "Vulkan Back-end"->GlslangWrapperVk: GlslangWrapperVk::GetShaderSource
56- GlslangWrapperVk- ->"Vulkan Back-end": return filled-in sources
63+ "Vulkan Back-end"->GlslangWrapperVk: GlslangWrapperVk::GetShaderSpirvCode
64+ GlslangWrapperVk->Glslang: GlslangToSpv
65+ Glslang- ->GlslangWrapperVk: Return SPIR-V
5766
58- Note right of "Vulkan Back-end": Source is templated with\ndefines to be resolved at\ndraw time.
67+ Note right of GlslangWrapperVk: Transform SPIR-V
5968
69+ GlslangWrapperVk- ->"Vulkan Back-end": return transformed SPIR-V
6070"Vulkan Back-end"- ->"ANGLE Front-end": return success
6171
6272Note right of App: App execution continues...
6373
6474App->"ANGLE Front-end": glDrawArrays (any draw)
6575"ANGLE Front-end"->"Vulkan Back-end": ContextVk::drawArrays
6676
67- "Vulkan Back-end"->GlslangWrapperVk: GlslangWrapperVk::GetShaderCode (with defines)
68- GlslangWrapperVk->Glslang: GlslangToSpv
69- Glslang- ->"Vulkan Back-end": Return SPIR-V
70-
7177Note right of "Vulkan Back-end": We init VkShaderModules\nand VkPipeline then\nrecord the draw.
7278
7379"Vulkan Back-end"- ->"ANGLE Front-end": return success
0 commit comments