annotate semicongine/rendering/shaders.nim @ 1284:feb52b1c18e0

fixing stuff
author sam <sam@basx.dev>
date Mon, 29 Jul 2024 20:09:04 +0700
parents 0369fa1ffbd9
children 6e8f02e58606
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
1 func glslType[T: SupportedGPUType|Image](value: T): string =
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
2 when T is float32: "float"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
3 elif T is float64: "double"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
4 elif T is int8 or T is int16 or T is int32 or T is int64: "int"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
5 elif T is uint8 or T is uint16 or T is uint32 or T is uint64: "uint"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
6 elif T is TVec2[int32]: "ivec2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
7 elif T is TVec2[int64]: "ivec2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
8 elif T is TVec3[int32]: "ivec3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
9 elif T is TVec3[int64]: "ivec3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
10 elif T is TVec4[int32]: "ivec4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
11 elif T is TVec4[int64]: "ivec4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
12 elif T is TVec2[uint32]: "uvec2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
13 elif T is TVec2[uint64]: "uvec2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
14 elif T is TVec3[uint32]: "uvec3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
15 elif T is TVec3[uint64]: "uvec3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
16 elif T is TVec4[uint32]: "uvec4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
17 elif T is TVec4[uint64]: "uvec4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
18 elif T is TVec2[float32]: "vec2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
19 elif T is TVec2[float64]: "dvec2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
20 elif T is TVec3[float32]: "vec3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
21 elif T is TVec3[float64]: "dvec3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
22 elif T is TVec4[float32]: "vec4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
23 elif T is TVec4[float64]: "dvec4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
24 elif T is TMat2[float32]: "mat2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
25 elif T is TMat2[float64]: "dmat2"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
26 elif T is TMat23[float32]: "mat23"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
27 elif T is TMat23[float64]: "dmat23"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
28 elif T is TMat32[float32]: "mat32"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
29 elif T is TMat32[float64]: "dmat32"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
30 elif T is TMat3[float32]: "mat3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
31 elif T is TMat3[float64]: "dmat3"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
32 elif T is TMat34[float32]: "mat34"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
33 elif T is TMat34[float64]: "dmat34"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
34 elif T is TMat43[float32]: "mat43"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
35 elif T is TMat43[float64]: "dmat43"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
36 elif T is TMat4[float32]: "mat4"
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
37 elif T is TMat4[float64]: "dmat4"
1228
4e465583ea32 did: rename texture to image
sam <sam@basx.dev>
parents: 1218
diff changeset
38 elif T is Image: "sampler2D"
1247
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents: 1240
diff changeset
39 else:
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents: 1240
diff changeset
40 const n = typetraits.name(T)
c15770761865 add: gltf loading test, gltf loading for materials
sam <sam@basx.dev>
parents: 1240
diff changeset
41 {.error: "Unsupported data type on GPU: " & n.}
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
42
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
43 func vkType[T: SupportedGPUType](value: T): VkFormat =
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
44 when T is float32: VK_FORMAT_R32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
45 elif T is float64: VK_FORMAT_R64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
46 elif T is int8: VK_FORMAT_R8_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
47 elif T is int16: VK_FORMAT_R16_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
48 elif T is int32: VK_FORMAT_R32_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
49 elif T is int64: VK_FORMAT_R64_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
50 elif T is uint8: VK_FORMAT_R8_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
51 elif T is uint16: VK_FORMAT_R16_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
52 elif T is uint32: VK_FORMAT_R32_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
53 elif T is uint64: VK_FORMAT_R64_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
54 elif T is TVec2[int32]: VK_FORMAT_R32G32_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
55 elif T is TVec2[int64]: VK_FORMAT_R64G64_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
56 elif T is TVec3[int32]: VK_FORMAT_R32G32B32_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
57 elif T is TVec3[int64]: VK_FORMAT_R64G64B64_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
58 elif T is TVec4[int32]: VK_FORMAT_R32G32B32A32_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
59 elif T is TVec4[int64]: VK_FORMAT_R64G64B64A64_SINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
60 elif T is TVec2[uint32]: VK_FORMAT_R32G32_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
61 elif T is TVec2[uint64]: VK_FORMAT_R64G64_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
62 elif T is TVec3[uint32]: VK_FORMAT_R32G32B32_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
63 elif T is TVec3[uint64]: VK_FORMAT_R64G64B64_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
64 elif T is TVec4[uint32]: VK_FORMAT_R32G32B32A32_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
65 elif T is TVec4[uint64]: VK_FORMAT_R64G64B64A64_UINT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
66 elif T is TVec2[float32]: VK_FORMAT_R32G32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
67 elif T is TVec2[float64]: VK_FORMAT_R64G64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
68 elif T is TVec3[float32]: VK_FORMAT_R32G32B32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
69 elif T is TVec3[float64]: VK_FORMAT_R64G64B64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
70 elif T is TVec4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
71 elif T is TVec4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
72 elif T is TMat2[float32]: VK_FORMAT_R32G32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
73 elif T is TMat2[float64]: VK_FORMAT_R64G64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
74 elif T is TMat23[float32]: VK_FORMAT_R32G32B32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
75 elif T is TMat23[float64]: VK_FORMAT_R64G64B64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
76 elif T is TMat32[float32]: VK_FORMAT_R32G32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
77 elif T is TMat32[float64]: VK_FORMAT_R64G64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
78 elif T is TMat3[float32]: VK_FORMAT_R32G32B32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
79 elif T is TMat3[float64]: VK_FORMAT_R64G64B64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
80 elif T is TMat34[float32]: VK_FORMAT_R32G32B32A32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
81 elif T is TMat34[float64]: VK_FORMAT_R64G64B64A64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
82 elif T is TMat43[float32]: VK_FORMAT_R32G32B32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
83 elif T is TMat43[float64]: VK_FORMAT_R64G64B64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
84 elif T is TMat4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
85 elif T is TMat4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
86 else: {.error: "Unsupported data type on GPU".}
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
87
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
88
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
89 func numberOfVertexInputAttributeDescriptors[T: SupportedGPUType|Image](value: T): uint32 =
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
90 when T is TMat2[float32] or T is TMat2[float64] or T is TMat23[float32] or T is TMat23[float64]:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
91 2
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
92 elif T is TMat32[float32] or T is TMat32[float64] or T is TMat3[float32] or T is TMat3[float64] or T is TMat34[float32] or T is TMat34[float64]:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
93 3
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
94 elif T is TMat43[float32] or T is TMat43[float64] or T is TMat4[float32] or T is TMat4[float64]:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
95 4
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
96 else:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
97 1
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
98
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
99 func nLocationSlots[T: SupportedGPUType|Image](value: T): uint32 =
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
100 #[
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
101 single location:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
102 - any scalar
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
103 - any 16-bit vector
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
104 - any 32-bit vector
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
105 - any 64-bit vector that has max. 2 components
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
106 16-bit scalar and vector types, and
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
107 32-bit scalar and vector types, and
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
108 64-bit scalar and 2-component vector types.
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
109 two locations
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
110 64-bit three- and four-component vectors
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
111 ]#
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
112 when T is TVec3[int64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
113 T is TVec4[int64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
114 T is TVec3[uint64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
115 T is TVec4[uint64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
116 T is TVec3[float64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
117 T is TVec4[float64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
118 T is TMat23[float64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
119 T is TMat3[float64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
120 T is TMat34[float64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
121 T is TMat43[float64] or
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
122 T is TMat4[float64]:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
123 return 2
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
124 else:
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
125 return 1
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
126
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
127 proc generateShaderSource[TShader](shader: TShader): (string, string) {.compileTime.} =
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
128 const GLSL_VERSION = "450"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
129 var vsInput: seq[string]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
130 var vsOutput: seq[string]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
131 var fsInput: seq[string]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
132 var fsOutput: seq[string]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
133 var uniforms: seq[string]
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
134 var pushConstants: seq[string]
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
135 var samplers: seq[string]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
136 var vsInputLocation = 0'u32
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
137 var passLocation = 0
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
138 var fsOutputLocation = 0
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
139
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
140 var sawDescriptorSets = false
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
141 for fieldname, value in fieldPairs(shader):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
142 # vertex shader inputs
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
143 when hasCustomPragma(value, VertexAttribute) or hasCustomPragma(value, InstanceAttribute):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
144 assert typeof(value) is SupportedGPUType
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
145 vsInput.add "layout(location = " & $vsInputLocation & ") in " & glslType(value) & " " & fieldname & ";"
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
146 for j in 0 ..< numberOfVertexInputAttributeDescriptors(value):
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
147 vsInputLocation += nLocationSlots(value)
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
148
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
149 # intermediate values, passed between shaders
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
150 elif hasCustomPragma(value, Pass) or hasCustomPragma(value, PassFlat):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
151 let flat = if hasCustomPragma(value, PassFlat): "flat " else: ""
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
152 vsOutput.add "layout(location = " & $passLocation & ") " & flat & "out " & glslType(value) & " " & fieldname & ";"
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
153 fsInput.add "layout(location = " & $passLocation & ") " & flat & "in " & glslType(value) & " " & fieldname & ";"
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
154 passLocation.inc
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
155
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
156 # fragment shader output
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
157 elif hasCustomPragma(value, ShaderOutput):
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
158 fsOutput.add &"layout(location = " & $fsOutputLocation & ") out " & glslType(value) & " " & fieldname & ";"
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
159 fsOutputLocation.inc
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
160
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
161 # descriptor sets
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
162 # need to consider 4 cases: uniform block, texture, uniform block array, texture array
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
163 elif hasCustomPragma(value, DescriptorSets):
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
164 assert not sawDescriptorSets, "Only one field with pragma DescriptorSets allowed per shader"
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
165 assert typeof(value) is tuple, "Descriptor field '" & fieldname & "' must be of type tuple"
1284
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
166 assert tupleLen(value) <= MAX_DESCRIPTORSETS, typetraits.name(TShader) & ": maximum " & $MAX_DESCRIPTORSETS & " allowed"
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
167 sawDescriptorSets = true
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
168 var descriptorSetIndex = 0
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
169 for descriptor in value.fields:
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
170
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
171 var descriptorBinding = 0
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
172
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
173 for descriptorName, descriptorValue in fieldPairs(descriptor):
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
174
1228
4e465583ea32 did: rename texture to image
sam <sam@basx.dev>
parents: 1218
diff changeset
175 when typeof(descriptorValue) is Image:
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
176 samplers.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform " & glslType(descriptorValue) & " " & descriptorName & ";"
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
177 descriptorBinding.inc
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
178
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
179 elif typeof(descriptorValue) is GPUValue:
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
180
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
181 uniforms.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform T" & descriptorName & " {"
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
182 when typeof(descriptorValue.data) is object:
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
183
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
184 for blockFieldName, blockFieldValue in descriptorValue.data.fieldPairs():
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
185 assert typeof(blockFieldValue) is SupportedGPUType, "uniform block field '" & blockFieldName & "' is not a SupportedGPUType"
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
186 uniforms.add " " & glslType(blockFieldValue) & " " & blockFieldName & ";"
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
187 uniforms.add "} " & descriptorName & ";"
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
188
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
189 else:
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
190 {.error: "Unsupported shader descriptor field " & descriptorName & " (must be object)".}
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
191 descriptorBinding.inc
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
192
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
193 elif typeof(descriptorValue) is array:
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
194
1228
4e465583ea32 did: rename texture to image
sam <sam@basx.dev>
parents: 1218
diff changeset
195 when elementType(descriptorValue) is Image:
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
196
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
197 let arrayDecl = "[" & $typeof(descriptorValue).len & "]"
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
198 samplers.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform " & glslType(default(elementType(descriptorValue))) & " " & descriptorName & "" & arrayDecl & ";"
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
199 descriptorBinding.inc
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
200
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
201 elif elementType(descriptorValue) is GPUValue:
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
202
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
203 uniforms.add "layout(set=" & $descriptorSetIndex & ", binding = " & $descriptorBinding & ") uniform T" & descriptorName & " {"
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
204
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
205 for blockFieldName, blockFieldValue in default(elementType(descriptorValue)).data.fieldPairs():
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
206 assert typeof(blockFieldValue) is SupportedGPUType, "uniform block field '" & blockFieldName & "' is not a SupportedGPUType"
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
207 uniforms.add " " & glslType(blockFieldValue) & " " & blockFieldName & ";"
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
208 uniforms.add "} " & descriptorName & "[" & $descriptorValue.len & "];"
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
209 descriptorBinding.inc
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
210
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
211 else:
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
212 {.error: "Unsupported shader descriptor field " & descriptorName.}
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
213
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
214 descriptorSetIndex.inc
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
215 elif fieldname in ["vertexCode", "fragmentCode"]:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
216 discard
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
217 elif hasCustomPragma(value, PushConstantAttribute):
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
218 assert pushConstants.len == 0, "Only one push constant value allowed"
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
219 assert value is object, "push constants need to be objects"
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
220 pushConstants.add "layout( push_constant ) uniform constants"
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
221 pushConstants.add "{"
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
222 for constFieldName, constFieldValue in value.fieldPairs():
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
223 assert typeof(constFieldValue) is SupportedGPUType, "push constant field '" & constFieldName & "' is not a SupportedGPUType"
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
224 pushConstants.add " " & glslType(constFieldValue) & " " & constFieldName & ";"
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
225 pushConstants.add "} " & fieldname & ";"
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
226 else:
1284
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
227 static:
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
228 echo "Unsupported shader field '" & typetraits.name(TShader) & "." & fieldname & "' of type " & typetraits.name(typeof(value))
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
229 {.error: "Unsupported shader field".}
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
230
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
231 result[0] = (@[&"#version {GLSL_VERSION}", "#extension GL_EXT_scalar_block_layout : require", ""] &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
232 vsInput &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
233 uniforms &
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
234 pushConstants &
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
235 samplers &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
236 vsOutput &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
237 @[shader.vertexCode]).join("\n")
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
238
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
239 result[1] = (@[&"#version {GLSL_VERSION}", "#extension GL_EXT_scalar_block_layout : require", ""] &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
240 fsInput &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
241 uniforms &
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
242 pushConstants &
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
243 samplers &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
244 fsOutput &
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
245 @[shader.fragmentCode]).join("\n")
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
246
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
247 proc compileGlslToSPIRV(stage: VkShaderStageFlagBits, shaderSource: string): seq[uint32] {.compileTime.} =
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
248 func stage2string(stage: VkShaderStageFlagBits): string {.compileTime.} =
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
249 case stage
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
250 of VK_SHADER_STAGE_VERTEX_BIT: "vert"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
251 of VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: "tesc"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
252 of VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: "tese"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
253 of VK_SHADER_STAGE_GEOMETRY_BIT: "geom"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
254 of VK_SHADER_STAGE_FRAGMENT_BIT: "frag"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
255 of VK_SHADER_STAGE_COMPUTE_BIT: "comp"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
256 else: ""
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
257
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
258 when defined(nimcheck): # will not run if nimcheck is running
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
259 return result
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
260
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
261 let
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
262 stagename = stage2string(stage)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
263 shaderHash = hash(shaderSource)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
264 shaderfile = getTempDir() / &"shader_{shaderHash}.{stagename}"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
265
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
266 if not shaderfile.fileExists:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
267 echo "shader of type ", stage
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
268 for i, line in enumerate(shaderSource.splitlines()):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
269 echo " ", i + 1, " ", line
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
270 var glslExe = currentSourcePath.parentDir.parentDir.parentDir / "tools" / "glslangValidator"
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
271 when defined(windows):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
272 glslExe = glslExe & "." & ExeExt
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
273 let command = &"{glslExe} --entry-point main -V --stdin -S {stagename} -o {shaderfile}"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
274 echo "run: ", command
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
275 discard StaticExecChecked(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
276 command = command,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
277 input = shaderSource
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
278 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
279 else:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
280 echo &"shaderfile {shaderfile} is up-to-date"
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
281
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
282 when defined(mingw) and defined(linux): # required for crosscompilation, path separators get messed up
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
283 let shaderbinary = staticRead shaderfile.replace("\\", "/")
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
284 else:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
285 let shaderbinary = staticRead shaderfile
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
286
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
287 var i = 0
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
288 while i < shaderbinary.len:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
289 result.add(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
290 (uint32(shaderbinary[i + 0]) shl 0) or
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
291 (uint32(shaderbinary[i + 1]) shl 8) or
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
292 (uint32(shaderbinary[i + 2]) shl 16) or
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
293 (uint32(shaderbinary[i + 3]) shl 24)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
294 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
295 i += 4
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
296
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
297
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
298 proc compileShader[TShader](shader: static TShader): (VkShaderModule, VkShaderModule) =
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
299 const (vertexShaderSource, fragmentShaderSource) = generateShaderSource(shader)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
300
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
301 let vertexBinary = compileGlslToSPIRV(VK_SHADER_STAGE_VERTEX_BIT, vertexShaderSource)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
302 let fragmentBinary = compileGlslToSPIRV(VK_SHADER_STAGE_FRAGMENT_BIT, fragmentShaderSource)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
303
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
304 var createInfoVertex = VkShaderModuleCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
305 sType: VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
306 codeSize: csize_t(vertexBinary.len * sizeof(uint32)),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
307 pCode: vertexBinary.ToCPointer,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
308 )
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1192
diff changeset
309 checkVkResult vulkan.device.vkCreateShaderModule(addr(createInfoVertex), nil, addr(result[0]))
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
310 var createInfoFragment = VkShaderModuleCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
311 sType: VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
312 codeSize: csize_t(fragmentBinary.len * sizeof(uint32)),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
313 pCode: fragmentBinary.ToCPointer,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
314 )
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1192
diff changeset
315 checkVkResult vulkan.device.vkCreateShaderModule(addr(createInfoFragment), nil, addr(result[1]))
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
316
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
317 template ForVertexDataFields(shader: typed, fieldname, valuename, isinstancename, body: untyped): untyped =
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
318 for theFieldname, value in fieldPairs(shader):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
319 when hasCustomPragma(value, VertexAttribute) or hasCustomPragma(value, InstanceAttribute):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
320 when not typeof(value) is seq:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
321 {.error: "field '" & theFieldname & "' needs to be a seq".}
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
322 when not typeof(value) is SupportedGPUType:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
323 {.error: "field '" & theFieldname & "' is not a supported GPU type".}
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
324 block:
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
325 const `fieldname` {.inject.} = theFieldname
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
326 let `valuename` {.inject.} = value
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
327 const `isinstancename` {.inject.} = hasCustomPragma(value, InstanceAttribute)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
328 body
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
329
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
330 proc getDescriptorSetCount[TShader](): uint32 =
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
331 for _, value in fieldPairs(default(TShader)):
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
332 when hasCustomPragma(value, DescriptorSets):
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
333 return tupleLen(typeof(value)).uint32
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
334
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
335 proc createDescriptorSetLayouts[TShader](): array[MAX_DESCRIPTORSETS, VkDescriptorSetLayout] =
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
336 var setNumber: int
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
337 for _, value in fieldPairs(default(TShader)):
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
338 when hasCustomPragma(value, DescriptorSets):
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1205
diff changeset
339 for descriptorSet in value.fields:
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
340 var layoutbindings: seq[VkDescriptorSetLayoutBinding]
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
341 forDescriptorFields(descriptorSet, fieldName, fieldValue, descriptorType, descriptorCount, descriptorBindingNumber):
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
342 layoutbindings.add VkDescriptorSetLayoutBinding(
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
343 binding: descriptorBindingNumber,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
344 descriptorType: descriptorType,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
345 descriptorCount: descriptorCount,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
346 stageFlags: VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS),
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
347 pImmutableSamplers: nil,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
348 )
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
349 var layoutCreateInfo = VkDescriptorSetLayoutCreateInfo(
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
350 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
351 bindingCount: layoutbindings.len.uint32,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
352 pBindings: layoutbindings.ToCPointer
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
353 )
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
354 checkVkResult vkCreateDescriptorSetLayout(
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
355 vulkan.device,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
356 addr(layoutCreateInfo),
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
357 nil,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
358 addr(result[setNumber])
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
359 )
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
360 inc setNumber
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
361
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
362 proc createPipeline*[TShader](
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
363 renderPass: RenderPass,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
364 topology: VkPrimitiveTopology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
365 polygonMode: VkPolygonMode = VK_POLYGON_MODE_FILL,
1231
70f6c1cfe005 add: incomplete cube demo
sam <sam@basx.dev>
parents: 1229
diff changeset
366 cullMode: openArray[VkCullModeFlagBits] = [VK_CULL_MODE_BACK_BIT],
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
367 frontFace: VkFrontFace = VK_FRONT_FACE_CLOCKWISE,
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1231
diff changeset
368 lineWidth = 1'f32,
1257
e9b8d87b9883 fix: super stupid bug in perspective matrix X(
sam <sam@basx.dev>
parents: 1253
diff changeset
369 depthClampEnable = false,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
370 ): Pipeline[TShader] =
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
371 # create pipeline
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
372
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
373 const shader = default(TShader)
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
374 (result.vertexShaderModule, result.fragmentShaderModule) = compileShader(shader)
1192
90bf0cab1d02 did: so many, many things
sam <sam@basx.dev>
parents: 1190
diff changeset
375
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
376 var nSets = getDescriptorSetCount[TShader]()
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
377 result.descriptorSetLayouts = createDescriptorSetLayouts[TShader]()
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
378
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
379 let pushConstant = VkPushConstantRange(
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
380 stageFlags: VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS),
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
381 offset: 0,
1253
c4f98eb4bb05 fix: a few things
sam <sam@basx.dev>
parents: 1252
diff changeset
382 size: PUSH_CONSTANT_SIZE, # currently supported everywhere, places for two mat4
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
383 )
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
384
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
385 let pipelineLayoutInfo = VkPipelineLayoutCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
386 sType: VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
387 setLayoutCount: nSets,
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
388 pSetLayouts: if nSets == 0: nil else: result.descriptorSetLayouts.ToCPointer,
1252
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
389 pushConstantRangeCount: 1,
01e9f41d35b1 add:support for push constants
sam <sam@basx.dev>
parents: 1247
diff changeset
390 pPushConstantRanges: addr(pushConstant),
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
391 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
392 checkVkResult vkCreatePipelineLayout(vulkan.device, addr(pipelineLayoutInfo), nil, addr(result.layout))
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
393
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
394 let stages = [
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
395 VkPipelineShaderStageCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
396 sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
397 stage: VK_SHADER_STAGE_VERTEX_BIT,
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1192
diff changeset
398 module: result.vertexShaderModule,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
399 pName: "main",
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
400 ),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
401 VkPipelineShaderStageCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
402 sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
403 stage: VK_SHADER_STAGE_FRAGMENT_BIT,
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1192
diff changeset
404 module: result.fragmentShaderModule,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
405 pName: "main",
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
406 ),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
407 ]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
408 var
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
409 bindings: seq[VkVertexInputBindingDescription]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
410 attributes: seq[VkVertexInputAttributeDescription]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
411 var inputBindingNumber = 0'u32
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
412 var location = 0'u32
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
413 ForVertexDataFields(default(TShader), fieldname, value, isInstanceAttr):
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
414 bindings.add VkVertexInputBindingDescription(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
415 binding: inputBindingNumber,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
416 stride: sizeof(value).uint32,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
417 inputRate: if isInstanceAttr: VK_VERTEX_INPUT_RATE_INSTANCE else: VK_VERTEX_INPUT_RATE_VERTEX,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
418 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
419 # allows to submit larger data structures like Mat44, for most other types will be 1
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
420 let perDescriptorSize = sizeof(value).uint32 div numberOfVertexInputAttributeDescriptors(value)
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
421 for i in 0'u32 ..< numberOfVertexInputAttributeDescriptors(value):
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
422 attributes.add VkVertexInputAttributeDescription(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
423 binding: inputBindingNumber,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
424 location: location,
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
425 format: vkType(value),
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
426 offset: i * perDescriptorSize,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
427 )
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
428 location += nLocationSlots(value)
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
429 inc inputBindingNumber
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
430
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
431 let
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
432 vertexInputInfo = VkPipelineVertexInputStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
433 sType: VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
434 vertexBindingDescriptionCount: uint32(bindings.len),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
435 pVertexBindingDescriptions: bindings.ToCPointer,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
436 vertexAttributeDescriptionCount: uint32(attributes.len),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
437 pVertexAttributeDescriptions: attributes.ToCPointer,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
438 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
439 inputAssembly = VkPipelineInputAssemblyStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
440 sType: VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
441 topology: topology,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
442 primitiveRestartEnable: false,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
443 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
444 viewportState = VkPipelineViewportStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
445 sType: VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
446 viewportCount: 1,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
447 scissorCount: 1,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
448 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
449 rasterizer = VkPipelineRasterizationStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
450 sType: VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
1257
e9b8d87b9883 fix: super stupid bug in perspective matrix X(
sam <sam@basx.dev>
parents: 1253
diff changeset
451 depthClampEnable: depthClampEnable,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
452 rasterizerDiscardEnable: VK_FALSE,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
453 polygonMode: polygonMode,
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1231
diff changeset
454 lineWidth: lineWidth,
1231
70f6c1cfe005 add: incomplete cube demo
sam <sam@basx.dev>
parents: 1229
diff changeset
455 cullMode: toBits cullMode,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
456 frontFace: frontFace,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
457 depthBiasEnable: VK_FALSE,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
458 depthBiasConstantFactor: 0.0,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
459 depthBiasClamp: 0.0,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
460 depthBiasSlopeFactor: 0.0,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
461 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
462 multisampling = VkPipelineMultisampleStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
463 sType: VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
464 sampleShadingEnable: VK_FALSE,
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
465 rasterizationSamples: renderPass.samples,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
466 minSampleShading: 1.0,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
467 pSampleMask: nil,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
468 alphaToCoverageEnable: VK_FALSE,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
469 alphaToOneEnable: VK_FALSE,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
470 )
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
471 # will only be enabled it the renderpass actually uses a depth buffer
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
472 depthStencil = VkPipelineDepthStencilStateCreateInfo(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
473 sType: VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
474 depthTestEnable: true,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
475 depthWriteEnable: true,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
476 depthCompareOp: VK_COMPARE_OP_LESS,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
477 depthBoundsTestEnable: false,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
478 stencilTestEnable: false,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
479 minDepthBounds: 0'f32,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
480 maxDepthBounds: 0'f32,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
481 )
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
482 colorBlendAttachment = VkPipelineColorBlendAttachmentState(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
483 colorWriteMask: toBits [VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT, VK_COLOR_COMPONENT_A_BIT],
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1231
diff changeset
484 blendEnable: true,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
485 srcColorBlendFactor: VK_BLEND_FACTOR_SRC_ALPHA,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
486 dstColorBlendFactor: VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
487 colorBlendOp: VK_BLEND_OP_ADD,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
488 srcAlphaBlendFactor: VK_BLEND_FACTOR_ONE,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
489 dstAlphaBlendFactor: VK_BLEND_FACTOR_ZERO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
490 alphaBlendOp: VK_BLEND_OP_ADD,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
491 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
492 colorBlending = VkPipelineColorBlendStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
493 sType: VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
494 logicOpEnable: false,
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1231
diff changeset
495 logicOp: VK_LOGIC_OP_COPY,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
496 attachmentCount: 1,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
497 pAttachments: addr(colorBlendAttachment),
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1231
diff changeset
498 blendConstants: [0'f32, 0'f32, 0'f32, 0'f32]
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
499 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
500 dynamicStates = [VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR]
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
501 dynamicState = VkPipelineDynamicStateCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
502 sType: VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
503 dynamicStateCount: dynamicStates.len.uint32,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
504 pDynamicStates: dynamicStates.ToCPointer,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
505 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
506 let createInfo = VkGraphicsPipelineCreateInfo(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
507 sType: VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
508 stageCount: 2,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
509 pStages: stages.ToCPointer,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
510 pVertexInputState: addr(vertexInputInfo),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
511 pInputAssemblyState: addr(inputAssembly),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
512 pViewportState: addr(viewportState),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
513 pRasterizationState: addr(rasterizer),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
514 pMultisampleState: addr(multisampling),
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
515 pDepthStencilState: if renderPass.depthBuffer: addr(depthStencil) else: nil,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
516 pColorBlendState: addr(colorBlending),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
517 pDynamicState: addr(dynamicState),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
518 layout: result.layout,
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1228
diff changeset
519 renderPass: renderPass.vk,
1190
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
520 subpass: 0,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
521 basePipelineHandle: VkPipeline(0),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
522 basePipelineIndex: -1,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
523 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
524 checkVkResult vkCreateGraphicsPipelines(
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
525 vulkan.device,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
526 VkPipelineCache(0),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
527 1,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
528 addr(createInfo),
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
529 nil,
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
530 addr(result.vk)
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
531 )
a3eb305bcac2 start of complete and total refactoring: the ULTIMATE
sam <sam@basx.dev>
parents:
diff changeset
532
1284
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
533 func layout*(pipeline: Pipeline, level: int): VkDescriptorSetLayout =
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
534 pipeline.descriptorSetLayouts[level]
feb52b1c18e0 fixing stuff
sam <sam@basx.dev>
parents: 1283
diff changeset
535
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
536 template withPipeline*(commandbuffer: VkCommandBuffer, pipeline: Pipeline, body: untyped): untyped =
1202
a8864fe6fe6e add: descriptor sets binding n stuff
sam <sam@basx.dev>
parents: 1201
diff changeset
537 block:
a8864fe6fe6e add: descriptor sets binding n stuff
sam <sam@basx.dev>
parents: 1201
diff changeset
538 vkCmdBindPipeline(commandbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.vk)
a8864fe6fe6e add: descriptor sets binding n stuff
sam <sam@basx.dev>
parents: 1201
diff changeset
539 body
a8864fe6fe6e add: descriptor sets binding n stuff
sam <sam@basx.dev>
parents: 1201
diff changeset
540
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1267
diff changeset
541 proc destroyPipeline*(pipeline: Pipeline) =
1201
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
542
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
543 for descriptorSetLayout in pipeline.descriptorSetLayouts:
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
544 vkDestroyDescriptorSetLayout(vulkan.device, descriptorSetLayout, nil)
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
545
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1192
diff changeset
546 vkDestroyShaderModule(vulkan.device, pipeline.vertexShaderModule, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1192
diff changeset
547 vkDestroyShaderModule(vulkan.device, pipeline.fragmentShaderModule, nil)
1201
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
548 vkDestroyPipelineLayout(vulkan.device, pipeline.layout, nil)
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
549 vkDestroyPipeline(vulkan.device, pipeline.vk, nil)