ae2f_docs
Loading...
Searching...
No Matches
constant.h
Go to the documentation of this file.
1/** @file constant.h */
2
3#ifndef lib_build_constant_h
4#define lib_build_constant_h
5
6#include <string.h>
7
8#include <ae2f/Keys.h>
9#include <ae2f/c90/StdInt.h>
10
11#include <aclspv/spvty.h>
12
13#include "./id.h"
14#include "./ctx.h"
15#include "./emitx.h"
16
17#include "./constant/ptr.auto.h"
18
19/** TODO: make this modular. this is risky */
20ae2f_inline static aclspv_id_t util_get_default_id(
21 const e_id_default c_id_default,
22 h_util_ctx_t h_ctx
23 );
24
25typedef struct {
27 aclspv_id_t m_const_val_id;
28 aclspv_id_t m_const_spec_id;
29 aclspv_id_t m_const_spec_type_id;
30
31 /** array type id */
32 aclspv_id_t m_arr8_id;
33 aclspv_id_t m_arr16_id;
34 aclspv_id_t m_arr32_id;
35 aclspv_id_t m_arrspec32_id;
36
37 aclspv_id_t m_vec32_id;
38
39 /** u32_vec4_id */
40 aclspv_id_t m_arr128_id;
41
42 /** struct type id (for storage) */
43 aclspv_id_t m_struct_id;
44 aclspv_id_t m_struct128_id;
45
46 /** struct type id (for private, workgroup) */
47 aclspv_id_t m_structpriv_id;
48 aclspv_id_t m_structprivspec_id;
49 aclspv_id_t m_structpriv128_id;
50
51 /** push constant pointer id */
52 aclspv_id_t m_ptr_psh;
53
54 /** storage buffer pointer id */
55 aclspv_id_t m_ptr_storage;
56 aclspv_id_t m_ptr_func;
57
58 /** uniform pointer id */
59 aclspv_id_t m_ptr_uniform;
60 aclspv_id_t m_ptr_uniformconst;
61
62 /** workgroup pointer id */
63 aclspv_id_t m_ptr_work;
64 aclspv_id_t m_ptr_workspec;
65
66 /** normal pointer id */
67 aclspv_id_t m_ptr;
68} util_constant;
69
70typedef util_constant* ae2f_restrict p_util_constant_t;
71
72ae2f_inline ae2f_ccpure static util_constant* util_get_constant_node(
73 const aclspv_wrdcount_t c_key,
74 h_util_ctx_t h_ctx
75 )
76{
77 const aclspv_wrdcount_t COUNT = (aclspv_wrdcount_t)(h_ctx->m_constant_cache.m_sz / (size_t)sizeof(util_constant));
78 aclspv_wrdcount_t LEFT = 0;
79 aclspv_wrdcount_t RIGHT = COUNT;
80
81 ae2f_expected_if(COUNT) {
82 while(LEFT < RIGHT) {
83 const aclspv_wrdcount_t MIDDLE = LEFT + ((RIGHT - LEFT) >> 1);
84
85
86 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key == c_key)
87 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE];
88
89 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key < c_key) {
90 LEFT = MIDDLE + 1;
91 } else {
92 RIGHT = MIDDLE;
93 }
94 }
95
96
97 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT].m_key == c_key)
98 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT];
99 }
100
101 return ae2f_NIL;
102}
103
104ae2f_inline static util_constant* util_mk_constant_node(
105 const aclspv_wrdcount_t c_key,
106 h_util_ctx_t h_ctx
107 )
108{
109 const aclspv_wrdcount_t COUNT = (aclspv_wrdcount_t)(h_ctx->m_constant_cache.m_sz / (size_t)sizeof(util_constant));
110 aclspv_wrdcount_t LEFT = 0;
111 aclspv_wrdcount_t RIGHT = COUNT;
112 size_t NSIZE;
113
114 if(COUNT) {
115 while(LEFT < RIGHT) {
116 const aclspv_wrdcount_t MIDDLE = LEFT + ((RIGHT - LEFT) >> 1);
117
118 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key == c_key)
119 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE];
120
121 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key < c_key) {
122 LEFT = MIDDLE + 1;
123 } else {
124 RIGHT = MIDDLE;
125 }
126 }
127
128 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT].m_key == c_key)
129 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT];
130
131 }
132
133
134 NSIZE = (size_t)(h_ctx->m_constant_cache.m_sz + (size_t)sizeof(util_constant));
135
136 _aclspv_grow_vec_with_copy(
137 _aclspv_malloc, _aclspv_free
138 , _aclspv_memcpy
139 , L_new, h_ctx->m_constant_cache
140 , NSIZE
141 );
142 ae2f_expected_but_else(h_ctx->m_constant_cache.m_p) return ae2f_NIL;
143
144 memmove(
145 &((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT + 1]
146 , &((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT]
147 , (size_t)((COUNT - LEFT) * (sizeof(util_constant)))
148 );
149
150 /** sanity check for future possibility of having more elements */
151 memset(&((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT], 0, sizeof(util_constant));
152 ((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT].m_key = c_key;
153
154 return &((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT];
155}
156
157#include <spirv/unified1/spirv.h>
158#include "./wrdemit.h"
159
160ae2f_inline static aclspv_id_t util_mk_constant_val_id(const aclspv_wrd_t c_val, h_util_ctx_t h_ctx)
161{
162 util_constant* ae2f_restrict const C = util_mk_constant_node(c_val, h_ctx);
163 ae2f_expected_but_else(C) return 0;
164 ae2f_expected_but_else(C->m_key == c_val) {
165 assert(0 && "key does not match");
166 return 0;
167 }
168
169 if(C->m_const_val_id) return C->m_const_val_id;
170
171
172 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U32, h_ctx))
173 return 0;
174
175 /** OpConstant */
176 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpConstant, 3))) return 0;
177 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32))) return 0;
178 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
179 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, c_val))) return 0;
180
181 C->m_const_val_id = h_ctx->m_id++;
182
183 return C->m_const_val_id;
184}
185
186ae2f_inline static aclspv_id_t util_mk_constant_spec_id(const aclspv_wrd_t c_key, const aclspv_wrd_t c_val, h_util_ctx_t h_ctx)
187{
188 util_constant* ae2f_restrict const C = util_mk_constant_node(c_key, h_ctx);
190 ae2f_expected_but_else(ae2f_expected(C->m_key == c_key)) {
191 assert(0 && "key does not match");
192 return 0;
193 }
194
195
196 if(C->m_const_spec_id) return C->m_const_spec_id;
197
198
199 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U32, h_ctx))
200 return 0;
201
202 /** OpSpecConstant */
203 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(
204 &h_ctx->m_section.m_types
205 , h_ctx->m_count.m_types
206 , SpvOpSpecConstant
207 , 3))
208 ) return 0;
209 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32))) return 0;
210 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
211 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, c_val))) return 0;
212
213 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(
214 &h_ctx->m_section.m_decorate
215 , h_ctx->m_count.m_decorate
216 , SpvOpDecorate
217 , 3
218 ))) return 0;
219
220 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(
221 &h_ctx->m_section.m_decorate
222 , h_ctx->m_count.m_decorate
223 , h_ctx->m_id
224 ))) return 0;
225
226 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(
227 &h_ctx->m_section.m_decorate
228 , h_ctx->m_count.m_decorate
229 , SpvDecorationSpecId
230 ))) return 0;
231
232 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(
233 &h_ctx->m_section.m_decorate
234 , h_ctx->m_count.m_decorate
235 , c_key
236 ))) return 0;
237
238
239 C->m_const_spec_id = h_ctx->m_id++;
240
241 return C->m_const_spec_id;
242}
243
244ae2f_inline static aclspv_id_t util_mk_constant_vec32_id(const aclspv_wrd_t c_val, h_util_ctx_t h_ctx)
245{
246 util_constant* ae2f_restrict const C = util_mk_constant_node(c_val, h_ctx);
247 ae2f_expected_but_else(C) return 0;
248 ae2f_expected_but_else(C->m_key == c_val) return 0;
249
250
251 if(C->m_vec32_id) return C->m_vec32_id;
252
253
254 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U32, h_ctx))
255 return 0;
256
257 if(c_val == 1) return ID_DEFAULT_U32;
258
259 /** OpTypeVector */
260 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypeVector, 3))) return 0;
261 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
262 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32))) return 0;
263 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, c_val))) return 0;
264
265 C->m_vec32_id = h_ctx->m_id++;
266
267 return C->m_vec32_id;
268}
269
270ae2f_inline static aclspv_id_t util_mk_constant_arr8_id(const aclspv_wrd_t c_arrcount, h_util_ctx_t h_ctx)
271{
272 util_constant* ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
273 ae2f_expected_but_else(C) return 0;
274 ae2f_expected_but_else(C->m_key == c_arrcount) return 0;
275 ae2f_expected_but_else(C->m_const_val_id)
276 C->m_const_val_id = util_mk_constant_val_id(c_arrcount, h_ctx);
277
278 if(C->m_arr8_id) return C->m_arr8_id;
279 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U8, h_ctx))
280 return 0;
281 if(C->m_key == 1) return ID_DEFAULT_U8;
282
283
284 /** OpArray */
285 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypeArray, 3))) return 0;
286 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
287 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U8))) return 0;
288 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_val_id))) return 0;
289
290 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(&h_ctx->m_section.m_decorate
291 , h_ctx->m_count.m_decorate
292 , SpvOpDecorate, 3)))
293 return 0;
294 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
295 , h_ctx->m_count.m_decorate
296 , h_ctx->m_id)))
297 return 0;
298 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
299 , h_ctx->m_count.m_decorate
300 , SpvDecorationArrayStride)))
301 return 0;
302 /** TODO: research this */
303 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
304 , h_ctx->m_count.m_decorate, 4)))
305 return 0;
306
307
308 C->m_arr8_id = h_ctx->m_id++;
309
310 return C->m_arr8_id;
311}
312
313ae2f_inline static aclspv_id_t util_mk_constant_arr16_id(const aclspv_wrd_t c_arrcount, h_util_ctx_t h_ctx)
314{
315 util_constant* ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
316 ae2f_expected_but_else(C) return 0;
317 ae2f_expected_but_else(C->m_key == c_arrcount) return 0;
318 ae2f_expected_but_else(C->m_const_val_id)
319 C->m_const_val_id = util_mk_constant_val_id(c_arrcount, h_ctx);
320
321 if(C->m_arr16_id) return C->m_arr16_id;
322 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U16, h_ctx))
323 return 0;
324 if(C->m_key == 1) return ID_DEFAULT_U16;
325
326 /** OpArray */
327 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypeArray, 3))) return 0;
328 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
329 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U16))) return 0;
330 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_val_id))) return 0;
331
332 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(&h_ctx->m_section.m_decorate
333 , h_ctx->m_count.m_decorate
334 , SpvOpDecorate, 3)))
335 return 0;
336 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
337 , h_ctx->m_count.m_decorate
338 , h_ctx->m_id)))
339 return 0;
340 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
341 , h_ctx->m_count.m_decorate
342 , SpvDecorationArrayStride)))
343 return 0;
344 /** TODO: research this */
345 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
346 , h_ctx->m_count.m_decorate, 4)))
347 return 0;
348
349
350 C->m_arr16_id = h_ctx->m_id++;
351
352 return C->m_arr16_id;
353}
354
355ae2f_inline static aclspv_id_t util_mk_constant_arr32_id(const aclspv_wrd_t c_arrcount, h_util_ctx_t h_ctx)
356{
357 util_constant* ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
358 ae2f_expected_but_else(C) return 0;
359 ae2f_expected_but_else(C->m_key == c_arrcount) return 0;
360 ae2f_expected_but_else(C->m_const_val_id)
361 C->m_const_val_id = util_mk_constant_val_id(c_arrcount, h_ctx);
362
363 if(C->m_arr32_id) return C->m_arr32_id;
364 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U32, h_ctx))
365 return 0;
366 if(C->m_key == 1) return ID_DEFAULT_U32;
367
368 /** OpArray */
369 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypeArray, 3))) return 0;
370 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
371 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32))) return 0;
372 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_val_id))) return 0;
373
374 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(&h_ctx->m_section.m_decorate
375 , h_ctx->m_count.m_decorate
376 , SpvOpDecorate, 3)))
377 return 0;
378 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
379 , h_ctx->m_count.m_decorate
380 , h_ctx->m_id)))
381 return 0;
382 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
383 , h_ctx->m_count.m_decorate
384 , SpvDecorationArrayStride)))
385 return 0;
386 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
387 , h_ctx->m_count.m_decorate, 4)))
388 return 0;
389
390
391 C->m_arr32_id = h_ctx->m_id++;
392
393 return C->m_arr32_id;
394}
395
396ae2f_inline static aclspv_id_t util_mk_constant_arrspec32_id(const aclspv_wrd_t c_key, const aclspv_wrd_t c_arrcount, h_util_ctx_t h_ctx)
397{
398 util_constant* ae2f_restrict const C = util_mk_constant_node(c_key, h_ctx);
399 ae2f_expected_but_else(C) return 0;
400 ae2f_expected_but_else(C->m_key == c_key) return 0;
401 ae2f_expected_but_else(C->m_const_spec_id)
402 util_mk_constant_spec_id(c_key, c_arrcount, h_ctx);
403
404 if(C->m_arrspec32_id) return C->m_arrspec32_id;
405 ae2f_expected_but_else(util_get_default_id(ID_DEFAULT_U32, h_ctx))
406 return 0;
407
408 /** OpArray */
409 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypeArray, 3))) return 0;
410 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
411 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32))) return 0;
412 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_spec_id))) return 0;
413
414 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(&h_ctx->m_section.m_decorate
415 , h_ctx->m_count.m_decorate
416 , SpvOpDecorate, 3)))
417 return 0;
418 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
419 , h_ctx->m_count.m_decorate
420 , h_ctx->m_id)))
421 return 0;
422 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
423 , h_ctx->m_count.m_decorate
424 , SpvDecorationArrayStride)))
425 return 0;
426 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
427 , h_ctx->m_count.m_decorate, 4)))
428 return 0;
429
430
431 C->m_arrspec32_id = h_ctx->m_id++;
432
433 return C->m_arrspec32_id;
434}
435
436ae2f_inline static aclspv_id_t util_mk_constant_arr128_id(const aclspv_wrd_t c_arrcount, h_util_ctx_t h_ctx)
437{
438 util_constant* ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
439 const aclspv_id_t ID_U32V4 = util_mk_constant_vec32_id(4, h_ctx);
440
441 ae2f_expected_but_else(C) return 0;
442 ae2f_expected_but_else(C->m_key == c_arrcount) return 0;
443 ae2f_expected_but_else(util_mk_constant_val_id(c_arrcount, h_ctx)) return 0;
444 assert(ID_U32V4);
445
446
447 if(C->m_arr128_id) return C->m_arr128_id;
448
449 if(C->m_key == 1) return ID_U32V4;
450
451
452
453 assert(C->m_const_val_id);
454
455 /** OpArray */
456 ae2f_expected_but_else(h_ctx->m_count.m_types = (aclspv_wrd_t)util_emitx_4(
457 &h_ctx->m_section.m_types
458 , h_ctx->m_count.m_types
459 , SpvOpTypeArray
460 , h_ctx->m_id
461 , ID_U32V4
462 , C->m_const_val_id
463 )) return 0;
464
465 ae2f_expected_but_else(util_emitx_4(
466 &h_ctx->m_section.m_decorate
467 , h_ctx->m_count.m_decorate
468 , SpvOpDecorate, h_ctx->m_id
469 , SpvDecorationArrayStride, 16))
470 return 0;
471
472 assert(h_ctx->m_id);
473 assert(C->m_arr128_id);
474 C->m_arr128_id = h_ctx->m_id++;
475
476 return C->m_arr128_id;
477}
478
479ae2f_inline static aclspv_id_t util_mk_constant_struct_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
480 util_constant* ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
481 ae2f_expected_but_else(C) return 0;
482 ae2f_expected_but_else(C->m_key == c_wrdcount) return 0;
483 ae2f_expected_but_else(C->m_arr32_id && C->m_key > 1)
484 C->m_arr32_id = util_mk_constant_arr32_id(c_wrdcount, h_ctx);
485
486 if(C->m_struct_id) return C->m_struct_id;
487
488 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types
489 , h_ctx->m_count.m_types, SpvOpTypeStruct, 2))) return 0;
490 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types
491 , h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
492 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types
493 , h_ctx->m_count.m_types, C->m_arr32_id))) return 0;
494
495
496
497 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(&h_ctx->m_section.m_decorate
498 , h_ctx->m_count.m_decorate, SpvOpDecorate, 2)))
499 return 0;
500 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
501 , h_ctx->m_count.m_decorate, h_ctx->m_id)))
502 return 0;
503 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
504 , h_ctx->m_count.m_decorate, SpvDecorationBlock)))
505 return 0;
506
507 /* Member Offset */
508 ae2f_expected_but_else(h_ctx->m_count.m_decorate = util_emitx_5(
509 &h_ctx->m_section.m_decorate
510 , h_ctx->m_count.m_decorate
511 , SpvOpMemberDecorate
512 , h_ctx->m_id
513 , 0
514 , SpvDecorationOffset
515 , 0
516 )) return 0;
517
518 C->m_struct_id = h_ctx->m_id++;
519 return C->m_struct_id;
520}
521
522ae2f_inline static aclspv_id_t util_mk_constant_struct128_id(const aclspv_wrd_t c_veccount, h_util_ctx_t h_ctx) {
523#if 1
524 util_constant* ae2f_restrict const C = util_mk_constant_node(c_veccount, h_ctx);
525
527 assert(0 && "C is null");
528 return 0;
529 }
530 ae2f_expected_but_else(C->m_arr128_id = util_mk_constant_arr128_id(c_veccount, h_ctx)) {
531 assert(0 && "arr128 is null");
532 return 0;
533 }
534 if(C->m_struct128_id) return C->m_struct128_id;
535 assert(!C->m_struct128_id);
536
537 ae2f_expected_but_else(h_ctx->m_count.m_types = util_emitx_3(
538 &h_ctx->m_section.m_types
539 , h_ctx->m_count.m_types
540 , SpvOpTypeStruct
541 , h_ctx->m_id
542 , C->m_arr128_id)) {
543 assert(0 && "alloc failed");
544 return 0;
545 }
546
547 ae2f_expected_but_else((h_ctx->m_count.m_decorate = emit_opcode(&h_ctx->m_section.m_decorate
548 , h_ctx->m_count.m_decorate, SpvOpDecorate, 2)))
549 return 0;
550 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
551 , h_ctx->m_count.m_decorate, h_ctx->m_id)))
552 return 0;
553 ae2f_expected_but_else((h_ctx->m_count.m_decorate = util_emit_wrd(&h_ctx->m_section.m_decorate
554 , h_ctx->m_count.m_decorate, SpvDecorationBlock)))
555 return 0;
556
557 /* Member Offset */
558 ae2f_expected_but_else(h_ctx->m_count.m_decorate = util_emitx_5(
559 &h_ctx->m_section.m_decorate
560 , h_ctx->m_count.m_decorate
561 , SpvOpMemberDecorate
562 , h_ctx->m_id
563 , 0
564 , SpvDecorationOffset
565 , 0
566 )) return 0;
567
568
569 C->m_struct128_id = h_ctx->m_id++;
570
571 return C->m_struct128_id;
572#else
573 const aclspv_id_t RET = util_mk_constant_struct_id(c_veccount << 2, h_ctx);
574 return RET;
575#endif
576}
577
578ae2f_inline static aclspv_id_t util_mk_constant_structprivspec_id(const aclspv_wrd_t c_key, const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
579 util_constant* ae2f_restrict const C = util_mk_constant_node(c_key, h_ctx);
580 ae2f_expected_but_else(C) return 0;
581 ae2f_expected_but_else(C->m_key == c_key) return 0;
582 ae2f_expected_but_else(C->m_arrspec32_id)
583 util_mk_constant_arrspec32_id(c_key, c_wrdcount, h_ctx);
584
585 if(C->m_structprivspec_id) return C->m_structprivspec_id;
586
587 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types
588 , h_ctx->m_count.m_types, SpvOpTypeStruct, 2))) return 0;
589 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types
590 , h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
591 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types
592 , h_ctx->m_count.m_types, C->m_arrspec32_id))) return 0;
593
594 C->m_structprivspec_id = h_ctx->m_id++;
595 return C->m_structprivspec_id;
596}
597
598ae2f_inline static aclspv_id_t util_mk_constant_structpriv_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
599 util_constant* ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
600 ae2f_expected_but_else(C) return 0;
601 ae2f_expected_but_else(C->m_key == c_wrdcount) return 0;
602 ae2f_expected_but_else(C->m_arr32_id)
603 ae2f_expected_but_else(C->m_arr32_id = util_mk_constant_arr32_id(c_wrdcount, h_ctx))
604 return 0;
605
606 if(C->m_structpriv_id) return C->m_structpriv_id;
607
608 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types
609 , h_ctx->m_count.m_types, SpvOpTypeStruct, 2))) return 0;
610 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types
611 , h_ctx->m_count.m_types, h_ctx->m_id))) return 0;
612 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types
613 , h_ctx->m_count.m_types, C->m_arr32_id))) return 0;
614
615 C->m_structpriv_id = h_ctx->m_id++;
616 return C->m_structpriv_id;
617}
618
619
620ae2f_inline static aclspv_id_t util_mk_constant_ptr_psh_id(const aclspv_wrd_t c_wrdcount, const h_util_ctx_t h_ctx) {
621
622 aclspv_id_t ID;
623 _util_mk_constant_ptr_tmpl(
624 L_new, m_ptr_psh
625 , m_struct_id
626 , ID, c_wrdcount
627 , h_ctx
628 , util_mk_constant_struct_id
629 , SpvStorageClassPushConstant);
630 return ID;
631}
632
633ae2f_inline static aclspv_id_t util_mk_constant_ptr_storage_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
634 aclspv_id_t ID;
635 _util_mk_constant_ptr_tmpl(
636 L_new, m_ptr_storage
637 , m_struct_id
638 , ID, c_wrdcount
639 , h_ctx
640 , util_mk_constant_struct_id
641 , SpvStorageClassStorageBuffer);
642 return ID;
643}
644
645ae2f_inline static aclspv_id_t util_mk_constant_ptr_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
646 aclspv_id_t ID;
647 _util_mk_constant_ptr_tmpl(
648 L_new, m_ptr
649 , m_structpriv_id
650 , ID, c_wrdcount
651 , h_ctx
652 , util_mk_constant_structpriv_id
653 , SpvStorageClassPrivate);
654 return ID;
655}
656
657ae2f_inline static aclspv_id_t util_mk_constant_ptr_func(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
658 aclspv_id_t ID;
659 _util_mk_constant_ptr_tmpl(
660 L_new, m_ptr_func
661 , m_structpriv_id
662 , ID, c_wrdcount
663 , h_ctx
664 , util_mk_constant_structpriv_id
665 , SpvStorageClassFunction);
666 return ID;
667}
668
669ae2f_inline static aclspv_id_t util_mk_constant_ptr_uniform_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
670 util_constant* ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
671 ae2f_expected_but_else(C) return 0;
672 ae2f_expected_but_else(C->m_key == c_wrdcount) return 0;
673 ae2f_expected_but_else(C->m_struct128_id)
674 C->m_struct128_id = util_mk_constant_struct128_id(sz_to_count(c_wrdcount), h_ctx);
675
676 if(C->m_ptr_uniform) return C->m_ptr_uniform;
677
678 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypePointer, 3)))
679 return 0;
680 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id)))
681 return 0;
682 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvStorageClassUniform)))
683 return 0;
684 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_struct128_id)))
685 return 0;
686
687 C->m_ptr_uniform = h_ctx->m_id++;
688
689 return C->m_ptr_uniform;
690}
691
692ae2f_inline static aclspv_id_t util_mk_constant_ptr_uniformconstant_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
693 util_constant* ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
694 ae2f_expected_but_else(C) return 0;
695 ae2f_expected_but_else(C->m_key == c_wrdcount) return 0;
696 ae2f_expected_but_else(C->m_struct128_id)
697 C->m_struct128_id = util_mk_constant_struct128_id(sz_to_count(c_wrdcount), h_ctx);
698
699 if(C->m_ptr_uniformconst) return C->m_ptr_uniformconst;
700
701 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypePointer, 3)))
702 return 0;
703 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id)))
704 return 0;
705 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvStorageClassUniformConstant)))
706 return 0;
707 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_struct128_id)))
708 return 0;
709
710 C->m_ptr_uniformconst = h_ctx->m_id++;
711
712 return C->m_ptr_uniformconst;
713}
714
715ae2f_inline static aclspv_id_t util_mk_constant_ptr_workspec_id(const aclspv_wrd_t c_key, const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
716 util_constant* ae2f_restrict C = util_mk_constant_node(c_key, h_ctx);
717 ae2f_expected_but_else(C) return 0;
718 ae2f_expected_but_else(C->m_key == c_key) return 0;
719 ae2f_expected_but_else(C->m_structprivspec_id)
720 (void)util_mk_constant_structprivspec_id(c_key, c_wrdcount, h_ctx);
721
722 if(C->m_ptr_workspec) return C->m_ptr_workspec;
723
724
725 ae2f_expected_but_else((h_ctx->m_count.m_types = emit_opcode(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvOpTypePointer, 3)))
726 return 0;
727 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx->m_id)))
728 return 0;
729 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvStorageClassWorkgroup)))
730 return 0;
731 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_structpriv_id)))
732 return 0;
733
734 C->m_ptr_workspec = h_ctx->m_id++;
735
736 return C->m_ptr_workspec;
737}
738
739ae2f_inline static aclspv_id_t util_mk_constant_ptr_work_id(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
740 aclspv_id_t ID;
741 _util_mk_constant_ptr_tmpl(
742 L_new, m_ptr_work
743 , m_structpriv_id
744 , ID, c_wrdcount
745 , h_ctx
746 , util_mk_constant_structpriv_id
747 , SpvStorageClassWorkgroup);
748 return ID;
749}
750
751ae2f_inline static aclspv_id_t util_mk_constant_ptr_by_enum(const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx, enum SpvStorageClass_ c_class) {
752 switch((aclspv_wrd_t)c_class) {
753 case SpvStorageClassWorkgroup:
754 return util_mk_constant_ptr_work_id(c_wrdcount, h_ctx);
755 case SpvStorageClassPrivate:
756 return util_mk_constant_ptr_id(c_wrdcount, h_ctx);
757 case SpvStorageClassUniform:
758 return util_mk_constant_ptr_uniform_id(c_wrdcount, h_ctx);
759 case SpvStorageClassStorageBuffer:
760 return util_mk_constant_ptr_storage_id(c_wrdcount, h_ctx);
761 case SpvStorageClassPushConstant:
762 return util_mk_constant_ptr_psh_id(c_wrdcount, h_ctx);
763
764 default:
766 return 0;
767 }
768
769}
770
771#endif
#define ae2f_IS_SHARED
Definition Call.auto.h:12
#define ae2f_OFF
Definition Call.auto.h:3
#define ae2f_WhenCXX(a)
Appears when the current language is C.
Definition Cxx.h:44
#define ae2f_WhenC(a)
Appears when the current language is C++.
Definition Cxx.h:38
#define unless(a)
Invokes when condition is false.
Definition Keys.h:34
#define ae2f_extern
Suggests the existence of external variable or function, in naming of C. [non-mangling].
Definition Keys.h:25
#define ae2f_NIL
Definition Nil.h:13
#define ACLSPV_ABI_DECL
Declaration as ABI.
Definition abi.h:23
#define STATE_VAL
#define FNINFO
#define cpysz
#define cpypad
#define ae2f_assume(a)
tells the compiler that value if a is false, below this keyword is not expected to be reached.
Definition cc.h:228
#define ae2f_unexpected_but_if(a)
Definition cc.h:192
#define ae2f_ccpure
Keyword as [[pure]] on C23.
Definition cc.h:52
#define ae2f_expected_but_else(a)
Definition cc.h:201
#define ae2f_expected_if(a)
Definition cc.h:195
#define ae2f_ccconst
Keyword as [[const]] on C23..
Definition cc.h:66
#define ae2f_noexcept
marker that this function does not throw something.
Definition cc.h:133
#define ae2f_restrict
Keyword as restrict on C99.
Definition cc.h:81
#define ae2f_expected_not(a)
expectes a as false.
Definition cc.h:185
#define ae2f_unreachable()
tells the compiler that below this keyword is not expected to be reached.
Definition cc.h:213
#define ae2f_inline
inline
Definition cc.h:149
#define ae2f_expected(a)
expectes a as true.
Definition cc.h:184
#define CTX
#define EMIT_POS
#define util_emitx_type_pointer(h_wrds, c_wrdcount, c_retid, c_storage_class, c_elm_type_id)
Definition emitx.h:134
#define ret_count
#define get_buf_from_scale(h_alloc, c_scale)
Definition scale.h:34
#define aclspv_opcode_t
integer as operation code
Definition spvty.h:27
aclspv_wrd_t aclspv_wrdcount_t
the integer type represents the number of word.
Definition spvty.h:61
#define ACLSPV_MASK_OPCODE
mask for opcode
Definition spvty.h:37
#define aclspv_wrd_t
integer as word
Definition spvty.h:16
#define ACLSPV_MASK_NOPRNDS
mask for number of operands
Definition spvty.h:42
x_aclspv_vec m_scale_vars
Definition ctx.h:62
aclspv_wrdcount_t m_num_type_uniques
Definition ctx.h:44
x_aclspv_vec m_cursors
cache for cursors for parsing one function for its use see util/cursor.h
Definition ctx.h:77
x_aclspv_vec m_constant_cache
Definition ctx.h:65
aclspv_id_t m_id
id
Definition ctx.h:50
x_aclspv_vec m_ret
word count for m_ret
Definition ctx.h:56
aclspv_wrd_t m_is_logical
when on, ignores m_is_buffer_64.
Definition ctx.h:23
aclspv_wrdcount_t m_num_cursor
number of m_cursors. for its use see util/cursor.h
Definition ctx.h:41
x_aclspv_vec m_type_uniques
cache for complex types which needs to be stored somewhere for its use see util/type_unique....
Definition ctx.h:86
util_bind_unified m_unified
Definition bind.h:20
#define mk_noprnds(c_num_opprm)
Definition wrdemit.h:66
#define emit_opcode(h_wrds, c_wrdcount, c_opcode, c_num_opprm_opt)
try emit opcode with num_opprm
Definition wrdemit.h:75
#define sz_to_count(c_sz)
byte size to word count
Definition wrdemit.h:24
#define get_wrd_of_vec(vec)
get word buffer from vector
Definition wrdemit.h:38
aclspv_wrdcount_t spvsz_t
Definition wrdemit.h:18
#define count_to_sz(c_count)
word count to byte size
Definition wrdemit.h:32
#define set_oprnd_count_for_opcode(cr_wrd, c_num_opprm)
Definition wrdemit.h:78
#define opcode_to_wrd(c_opcode, c_num_opprm)
Definition wrdemit.h:69