Skip to content

Commit 78c60ac

Browse files
darksylincSplizard
authored andcommitted
Fix union order to simplify empty initializers
This is a followup to PR godotengine#101344 (commit 0e06eb8). Some of them were not an issue because Godot was initializing all members, but they were "fixed" just in case since it could become a problem in the future. Valgrind was specifically complaining about HashMapData & GlobalPipelineData.
1 parent 01259df commit 78c60ac

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

core/templates/a_hash_map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636
struct HashMapData {
3737
union {
38+
uint64_t data;
3839
struct
3940
{
4041
uint32_t hash;
4142
uint32_t hash_to_key;
4243
};
43-
uint64_t data;
4444
};
4545
};
4646

drivers/gles3/rasterizer_scene_gles3.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
250250
};
251251

252252
union {
253+
struct {
254+
uint64_t sort_key1;
255+
uint64_t sort_key2;
256+
};
253257
struct {
254258
uint64_t lod_index : 8;
255259
uint64_t surface_index : 8;
@@ -265,10 +269,6 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
265269
uint64_t depth_layer : 4;
266270
uint64_t priority : 8;
267271
};
268-
struct {
269-
uint64_t sort_key1;
270-
uint64_t sort_key2;
271-
};
272272
} sort;
273273

274274
RS::PrimitiveType primitive = RS::PRIMITIVE_MAX;

scene/3d/voxelizer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class Voxelizer {
7272

7373
struct CellSort {
7474
union {
75+
uint64_t key = 0;
7576
struct {
7677
uint64_t z : 16;
7778
uint64_t y : 16;
7879
uint64_t x : 16;
7980
uint64_t level : 16;
8081
};
81-
uint64_t key = 0;
8282
};
8383

8484
int32_t index = 0;

scene/gui/graph_edit.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class GraphEdit : public Control {
150150
private:
151151
struct ConnectionType {
152152
union {
153+
uint64_t key = 0;
153154
struct {
154155
uint32_t type_a;
155156
uint32_t type_b;
156157
};
157-
uint64_t key = 0;
158158
};
159159

160160
static uint32_t hash(const ConnectionType &p_conn) {

servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ class RenderForwardClustered : public RendererSceneRenderRD {
428428
};
429429

430430
union {
431+
struct {
432+
uint64_t sort_key1;
433+
uint64_t sort_key2;
434+
};
431435
struct {
432436
uint64_t lod_index : 8;
433437
uint64_t surface_index : 8;
@@ -443,10 +447,6 @@ class RenderForwardClustered : public RendererSceneRenderRD {
443447
uint64_t depth_layer : 4;
444448
uint64_t priority : 8;
445449
};
446-
struct {
447-
uint64_t sort_key1;
448-
uint64_t sort_key2;
449-
};
450450
} sort;
451451

452452
RS::PrimitiveType primitive = RS::PRIMITIVE_MAX;
@@ -541,6 +541,8 @@ class RenderForwardClustered : public RendererSceneRenderRD {
541541

542542
struct GlobalPipelineData {
543543
union {
544+
uint32_t key;
545+
544546
struct {
545547
uint32_t texture_samples : 3;
546548
uint32_t use_reflection_probes : 1;
@@ -556,8 +558,6 @@ class RenderForwardClustered : public RendererSceneRenderRD {
556558
uint32_t use_shadow_cubemaps : 1;
557559
uint32_t use_shadow_dual_paraboloid : 1;
558560
};
559-
560-
uint32_t key;
561561
};
562562
};
563563

servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ class RenderForwardMobile : public RendererSceneRenderRD {
397397
};
398398

399399
union {
400+
struct {
401+
uint64_t sort_key1;
402+
uint64_t sort_key2;
403+
};
400404
struct {
401405
// !BAS! CHECK BITS!!!
402406

@@ -413,10 +417,6 @@ class RenderForwardMobile : public RendererSceneRenderRD {
413417
// uint64_t lod_index : 8; // no need to sort on LOD
414418
// uint64_t uses_forward_gi : 1; // no GI here, remove
415419
};
416-
struct {
417-
uint64_t sort_key1;
418-
uint64_t sort_key2;
419-
};
420420
} sort;
421421

422422
RS::PrimitiveType primitive = RS::PRIMITIVE_MAX;
@@ -575,6 +575,8 @@ class RenderForwardMobile : public RendererSceneRenderRD {
575575

576576
struct GlobalPipelineData {
577577
union {
578+
uint32_t key;
579+
578580
struct {
579581
uint32_t texture_samples : 3;
580582
uint32_t target_samples : 3;
@@ -586,8 +588,6 @@ class RenderForwardMobile : public RendererSceneRenderRD {
586588
uint32_t use_shadow_cubemaps : 1;
587589
uint32_t use_shadow_dual_paraboloid : 1;
588590
};
589-
590-
uint32_t key;
591591
};
592592
};
593593

0 commit comments

Comments
 (0)