@@ -50,12 +50,29 @@ struct SVertexInputAttribParams
50
50
uint32_t binding : 4 ;
51
51
uint32_t format : 8 ;// asset::E_FORMAT
52
52
uint32_t relativeOffset : 13 ;// assuming max=2048
53
+
54
+ constexpr static size_t serializedSize () { return sizeof (uint32_t ); }
55
+
56
+ void serialize (void * mem) const
57
+ {
58
+ auto * dst = reinterpret_cast <uint32_t *>(mem);
59
+ *dst = core::bitfieldInsert (*dst, binding, 0 , 4 );
60
+ *dst = core::bitfieldInsert (*dst, format, 4 , 8 );
61
+ *dst = core::bitfieldInsert (*dst, relativeOffset, 12 , 13 );
62
+ }
53
63
} PACK_STRUCT;
54
64
static_assert (sizeof (SVertexInputAttribParams)==(4u ), " Unexpected size!" );
55
65
struct SVertexInputBindingParams
56
66
{
57
67
uint32_t stride = 0u ;
58
68
E_VERTEX_INPUT_RATE inputRate = EVIR_PER_VERTEX;
69
+
70
+ constexpr static size_t serializedSize () { return sizeof (SVertexInputBindingParams); }
71
+
72
+ void serialize (void * mem) const
73
+ {
74
+ memcpy (mem, this , serializedSize ());
75
+ }
59
76
} PACK_STRUCT;
60
77
static_assert (sizeof (SVertexInputBindingParams)==5u , " Unexpected size!" );
61
78
struct SVertexInputParams
@@ -72,6 +89,21 @@ struct SVertexInputParams
72
89
73
90
static_assert (sizeof (enabledAttribFlags)*8 >= MAX_VERTEX_ATTRIB_COUNT, " Insufficient flag bits for number of supported attributes" );
74
91
static_assert (sizeof (enabledBindingFlags)*8 >= MAX_ATTR_BUF_BINDING_COUNT, " Insufficient flag bits for number of supported bindings" );
92
+
93
+ constexpr static size_t serializedSize () { return 2u *sizeof (uint16_t ) + MAX_VERTEX_ATTRIB_COUNT*SVertexInputAttribParams::serializedSize () + MAX_ATTR_BUF_BINDING_COUNT*SVertexInputBindingParams::serializedSize (); }
94
+
95
+ void serialize (void * mem) const
96
+ {
97
+ auto * flags = reinterpret_cast <uint16_t *>(mem);
98
+ flags[0 ] = enabledAttribFlags;
99
+ flags[1 ] = enabledBindingFlags;
100
+ auto * dst = reinterpret_cast <uint8_t *>(flags + 2 );
101
+ for (uint32_t i = 0u ; i < MAX_VERTEX_ATTRIB_COUNT; ++i)
102
+ attributes[i].serialize (dst + i*attributes[i].serializedSize ());
103
+ dst += MAX_VERTEX_ATTRIB_COUNT * SVertexInputAttribParams::serializedSize ();
104
+ for (uint32_t i = 0u ; i < MAX_VERTEX_ATTRIB_COUNT; ++i)
105
+ bindings[i].serialize (dst + i*bindings[i].serializedSize ());
106
+ }
75
107
} PACK_STRUCT;
76
108
static_assert (sizeof (SVertexInputParams) == (2u * 2u + SVertexInputParams::MAX_VERTEX_ATTRIB_COUNT * sizeof (SVertexInputAttribParams) + SVertexInputParams::MAX_ATTR_BUF_BINDING_COUNT * sizeof (SVertexInputBindingParams)), " Unexpected size!" );
77
109
@@ -80,6 +112,13 @@ struct SPrimitiveAssemblyParams
80
112
E_PRIMITIVE_TOPOLOGY primitiveType = EPT_TRIANGLE_LIST;
81
113
uint8_t primitiveRestartEnable = false ;
82
114
uint16_t tessPatchVertCount = 3u ;
115
+
116
+ constexpr static size_t serializedSize () { return sizeof (SPrimitiveAssemblyParams); }
117
+
118
+ void serialize (void * mem) const
119
+ {
120
+ memcpy (mem, this , sizeof (*this ));
121
+ }
83
122
} PACK_STRUCT;
84
123
static_assert (sizeof (SPrimitiveAssemblyParams)==4u , " Unexpected size!" );
85
124
@@ -174,6 +213,29 @@ struct SRasterizationParams
174
213
uint16_t depthBoundsTestEnable : 1 ;
175
214
uint16_t stencilTestEnable : 1 ;
176
215
} PACK_STRUCT;
216
+
217
+ constexpr static size_t serializedSize () { return offsetof (SRasterizationParams, backStencilOps) + sizeof (SStencilOpParams) + sizeof (uint16_t ); }
218
+
219
+ void serialize (void * _mem) const
220
+ {
221
+ memcpy (_mem, this , sizeof (*this ));
222
+ auto * bf_dst = reinterpret_cast <uint8_t *>(_mem);
223
+ bf_dst += offsetof (SRasterizationParams, backStencilOps) + sizeof (SStencilOpParams);
224
+ uint16_t bf = 0 ;
225
+ bf = core::bitfieldInsert (bf, depthClampEnable, 0 , 1 );
226
+ bf = core::bitfieldInsert (bf, rasterizerDiscard, 1 , 1 );
227
+ bf = core::bitfieldInsert (bf, frontFaceIsCCW, 2 , 1 );
228
+ bf = core::bitfieldInsert (bf, depthBiasEnable, 3 , 1 );
229
+ bf = core::bitfieldInsert (bf, sampleShadingEnable, 4 , 1 );
230
+ bf = core::bitfieldInsert (bf, alphaToCoverageEnable, 5 , 1 );
231
+ bf = core::bitfieldInsert (bf, alphaToOneEnable, 6 , 1 );
232
+ bf = core::bitfieldInsert (bf, depthTestEnable, 7 , 1 );
233
+ bf = core::bitfieldInsert (bf, depthWriteEnable, 8 , 1 );
234
+ bf = core::bitfieldInsert (bf, depthBoundsTestEnable, 9 , 1 );
235
+ bf = core::bitfieldInsert (bf, stencilTestEnable, 10 , 1 );
236
+
237
+ reinterpret_cast <uint16_t *>(bf_dst)[0 ] = bf;
238
+ }
177
239
} PACK_STRUCT;
178
240
static_assert (sizeof (SRasterizationParams)==4u *sizeof (uint8_t ) + 3u *sizeof (uint32_t ) + 3u *sizeof (float ) + 2u *sizeof (SStencilOpParams) + sizeof (uint16_t ), " Unexpected size!" );
179
241
@@ -275,7 +337,6 @@ enum E_BLEND_OP : uint8_t
275
337
EBO_BLUE_EXT
276
338
};
277
339
278
- #include " irr/irrunpack.h"
279
340
280
341
struct SColorAttachmentBlendParams
281
342
{
@@ -306,7 +367,26 @@ struct SColorAttachmentBlendParams
306
367
uint8_t alphaBlendOp : 2 ;
307
368
// RGBA, LSB is R, MSB is A
308
369
uint8_t colorWriteMask : 4 ;
309
- };
370
+
371
+ constexpr static size_t serializedSize () { return 5ull ; }
372
+
373
+ void serialize (void * _mem) const
374
+ {
375
+ auto * bf_dst = reinterpret_cast <uint8_t *>(_mem);
376
+ uint64_t bf = 0 ;
377
+ bf = core::bitfieldInsert<uint64_t >(bf, attachmentEnabled, 0 , 1 );
378
+ bf = core::bitfieldInsert<uint64_t >(bf, blendEnable, 1 , 1 );
379
+ bf = core::bitfieldInsert<uint64_t >(bf, srcColorFactor, 2 , 5 );
380
+ bf = core::bitfieldInsert<uint64_t >(bf, dstColorFactor, 7 , 5 );
381
+ bf = core::bitfieldInsert<uint64_t >(bf, colorBlendOp, 12 , 6 );
382
+ bf = core::bitfieldInsert<uint64_t >(bf, srcAlphaFactor, 18 , 5 );
383
+ bf = core::bitfieldInsert<uint64_t >(bf, dstAlphaFactor, 23 , 5 );
384
+ bf = core::bitfieldInsert<uint64_t >(bf, alphaBlendOp, 28 , 2 );
385
+ bf = core::bitfieldInsert<uint64_t >(bf, colorWriteMask, 30 , 4 );
386
+
387
+ memcpy (bf_dst, &bf, serializedSize ());
388
+ }
389
+ } PACK_STRUCT;
310
390
static_assert (sizeof (SColorAttachmentBlendParams)==6u , " Unexpected size of SColorAttachmentBlendParams (should be 6)" );
311
391
312
392
struct SBlendParams
@@ -317,9 +397,22 @@ struct SBlendParams
317
397
uint8_t logicOpEnable : 1 ;
318
398
uint8_t logicOp : 4 ;
319
399
SColorAttachmentBlendParams blendParams[MAX_COLOR_ATTACHMENT_COUNT];
320
- };
400
+
401
+ constexpr static size_t serializedSize () { return 1u + MAX_COLOR_ATTACHMENT_COUNT * SColorAttachmentBlendParams::serializedSize (); }
402
+
403
+ void serialize (void * _mem) const
404
+ {
405
+ auto * bf_dst = reinterpret_cast <uint8_t *>(_mem);
406
+ *bf_dst = core::bitfieldInsert (*bf_dst, logicOpEnable, 0 , 1 );
407
+ *bf_dst = core::bitfieldInsert (*bf_dst, logicOp, 1 , 4 );
408
+ ++bf_dst;
409
+ for (uint32_t i = 0u ; i < MAX_COLOR_ATTACHMENT_COUNT; ++i)
410
+ blendParams[i].serialize (bf_dst + i*SColorAttachmentBlendParams::serializedSize ());
411
+ }
412
+ } PACK_STRUCT;
321
413
static_assert (sizeof (SBlendParams)==(1u + sizeof (SColorAttachmentBlendParams)*SBlendParams::MAX_COLOR_ATTACHMENT_COUNT), " Unexpected size!" );
322
414
415
+ #include " irr/irrunpack.h"
323
416
324
417
// TODO put into legacy namespace later
325
418
/*
0 commit comments