You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -990,20 +990,20 @@ These shader stages share several functions and built-ins
990
990
| imageAtomicExchange | InterlockedExchange |
991
991
| nonuniformEXT | NonUniformResourceIndex |
992
992
| gl_BaryCoordEXT | SV_Barycentrics |
993
-
| gl_BaryCoordNoPerspEXT | SV_Barycentrics with noperspective |
993
+
| gl_BaryCoordNoPerspEXT | SV_Barycentrics with noperspective |
994
994
|====
995
995
996
996
== Functions
997
997
998
998
[NOTE]
999
999
====
1000
1000
Most GLSL functions are also available in HLSL and vice-versa. This chapter lists functions with divergent names. Functions that have a 1:1 counterpart (e.g. `isNan`) aren't listed.
Copy file name to clipboardExpand all lines: chapters/hlsl.adoc
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,7 @@ Similar to regular programming languages, HLSL and GLSL differ in their syntax.
42
42
Here is the same shader written in both languages to give quick comparison on how they basically differ, including the aforementioned namespace that e.g. adds explicit locations:
Copy file name to clipboardExpand all lines: chapters/mapping_data_to_shaders.adoc
+43-26Lines changed: 43 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ The only shader stage in core Vulkan that has an input attribute controlled by V
39
39
40
40
Before calling `vkCreateGraphicsPipelines` a `VkPipelineVertexInputStateCreateInfo` struct will need to be filled out with a list of `VkVertexInputAttributeDescription` mappings to the shader.
41
41
42
-
An example GLSL vertex shader:
42
+
An example GLSL vertex shader (link:https://godbolt.org/z/x3b3ceTa6[Try Online]):
43
43
44
44
[source,glsl]
45
45
----
@@ -55,12 +55,11 @@ There is only a single input attribute at location 0. This can also be seen in t
55
55
56
56
[source,swift]
57
57
----
58
-
Name 18 "inPosition"
59
-
Decorate 18(inPosition) Location 0
58
+
OpDecorate %inPosition Location 0
60
59
61
-
17: TypePointer Input 16(fvec3)
62
-
18(inPosition): 17(ptr) Variable Input
63
-
19: 16(fvec3) Load 18(inPosition)
60
+
%ptr = OpTypePointer Input %v3float
61
+
%inPosition = OpVariable %ptr Input
62
+
%20 = OpLoad %v3float %inPosition
64
63
----
65
64
66
65
In this example, the following could be used for the `VkVertexInputAttributeDescription`:
@@ -115,7 +114,7 @@ In this example, there are the following 3 descriptor sets:
The GLSL of the shader (link:https://godbolt.org/z/oMz58a78T[Try Online]):
119
118
120
119
[source,glsl]
121
120
----
@@ -140,23 +139,23 @@ The corresponding SPIR-V assembly:
140
139
141
140
[source,swift]
142
141
----
143
-
Decorate 19(myTextureSampler) DescriptorSet 0
144
-
Decorate 19(myTextureSampler) Binding 0
142
+
OpDecorate %myTextureSampler DescriptorSet 0
143
+
OpDecorate %myTextureSampler Binding 0
145
144
146
-
MemberDecorate 29(uniformBuffer0) 0 Offset 0
147
-
Decorate 29(uniformBuffer0) Block
148
-
Decorate 31(ubo_0) DescriptorSet 0
149
-
Decorate 31(ubo_0) Binding 2
145
+
OpMemberDecorate %uniformBuffer0 0 Offset 0
146
+
OpDecorate %uniformBuffer0 Block
147
+
OpDecorate %ubo_0 DescriptorSet 0
148
+
OpDecorate %ubo_0 Binding 2
150
149
151
-
MemberDecorate 38(uniformBuffer1) 0 Offset 0
152
-
Decorate 38(uniformBuffer1) Block
153
-
Decorate 40(ubo_1) DescriptorSet 0
154
-
Decorate 40(ubo_1) Binding 3
150
+
OpMemberDecorate %uniformBuffer1 0 Offset 0
151
+
OpDecorate %uniformBuffer1 Block
152
+
OpDecorate %ubo_1 DescriptorSet 0
153
+
OpDecorate %ubo_1 Binding 3
155
154
156
-
MemberDecorate 44(storageBuffer) 0 Offset 0
157
-
Decorate 44(storageBuffer) BufferBlock
158
-
Decorate 46(ssbo) DescriptorSet 2
159
-
Decorate 46(ssbo) Binding 0
155
+
OpMemberDecorate %storageBuffer 0 Offset 0
156
+
OpDecorate %storageBuffer BufferBlock
157
+
OpDecorate %ssbo DescriptorSet 2
158
+
OpDecorate %ssbo Binding 0
160
159
----
161
160
162
161
The binding of descriptors is done while recording the command buffer. The descriptors must be bound at the time of a draw/dispatch call. The following is some pseudo code to better represent this:
@@ -194,6 +193,8 @@ For GLSL, more information can be found in the link:https://registry.khronos.org
On some implementations, it **may** be more efficient to sample from an image using a combination of sampler and sampled image that are stored together in the descriptor set in a combined descriptor.
Using specialization constants, the decision can instead be made when calling `vkCreateGraphicsPipelines` to compile the shader. This means there only needs to be a single shader.
478
493
494
+
link:https://godbolt.org/z/xnncjdf3z[Try Online]
495
+
479
496
[source,glsl]
480
497
----
481
498
#version 450
@@ -489,13 +506,13 @@ void main() {
489
506
490
507
Resulting SPIR-V assembly:
491
508
492
-
[source,spswiftirv]
509
+
[source,swift]
493
510
----
494
-
Decorate 9(outColor) Location 0
495
-
Decorate 10(myColor) SpecId 0
511
+
OpDecorate %outColor Location 0
512
+
OpDecorate %myColor SpecId 0
496
513
497
-
// 0x3f800000 as decimal which is 1.0 for a 32 bit float
498
-
10(myColor): 6(float) SpecConstant 1065353216
514
+
// 0x3f800000 as decimal which is 1.0 for a 32 bit float
515
+
%myColor = OpSpecConstant %float 1065353216
499
516
----
500
517
501
518
With specialization constants, the value is still a constant inside the shader, but for example, if another `VkPipeline` uses the same shader, but wants to set the `myColor` value to `0.5f`, it is possible to do so at runtime.
Copy file name to clipboardExpand all lines: chapters/push_constants.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ A small bank of values writable via the API and accessible in shaders. Push cons
35
35
36
36
From a shader perspective, push constant are similar to a uniform buffer. The spec provides details for the link:https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#interfaces-resources-pushconst[push constant interface] between Vulkan and SPIR-V.
37
37
38
-
A simple GLSL fragment shader example:
38
+
A simple GLSL fragment shader example (link:https://godbolt.org/z/93WaYd8dE[Try Online]):
Copy file name to clipboardExpand all lines: chapters/shader_memory_layout.adoc
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,8 @@ This extension allows the use of `std430` memory layout in UBOs. link:https://re
39
39
40
40
One example of when the `uniformBufferStandardLayout` feature is needed is when an application doesn't want the array stride for a UBO to be restricted to `extended alignment`
0 commit comments