@@ -10,25 +10,33 @@ with some additional workarounds and emulation. We emulate OpenGL's different de
10
10
y flipping, default uniforms, and OpenGL
11
11
[ line segment rasterization] ( OpenGLLineSegmentRasterization.md ) . For more info see
12
12
[ 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.
28
35
29
36
See the below diagram for a high-level view of the shader translation flow:
30
37
31
38
<!-- Generated from https://bramp.github.io/js-sequence-diagrams/
39
+ Note: remove whitespace in - -> arrows.
32
40
participant App
33
41
participant "ANGLE Front-end"
34
42
participant "Vulkan Back-end"
@@ -41,7 +49,7 @@ App->"ANGLE Front-end": glCompileShader (VS)
41
49
"Vulkan Back-end"->"ANGLE Translator": sh::Compile
42
50
"ANGLE Translator"- ->"ANGLE Front-end": return Vulkan-compatible GLSL
43
51
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.
45
53
46
54
Note right of App: Same for FS, GS, etc...
47
55
@@ -52,22 +60,20 @@ App->"ANGLE Front-end": glLinkProgram
52
60
53
61
Note right of "Vulkan Back-end": ProgramVk inits uniforms,\nlayouts, and descriptors.
54
62
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
57
66
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
59
68
69
+ GlslangWrapperVk- ->"Vulkan Back-end": return transformed SPIR-V
60
70
"Vulkan Back-end"- ->"ANGLE Front-end": return success
61
71
62
72
Note right of App: App execution continues...
63
73
64
74
App->"ANGLE Front-end": glDrawArrays (any draw)
65
75
"ANGLE Front-end"->"Vulkan Back-end": ContextVk::drawArrays
66
76
67
- "Vulkan Back-end"->GlslangWrapperVk: GlslangWrapperVk::GetShaderCode (with defines)
68
- GlslangWrapperVk->Glslang: GlslangToSpv
69
- Glslang- ->"Vulkan Back-end": Return SPIR-V
70
-
71
77
Note right of "Vulkan Back-end": We init VkShaderModules\nand VkPipeline then\nrecord the draw.
72
78
73
79
"Vulkan Back-end"- ->"ANGLE Front-end": return success
0 commit comments