Browse Source

Style: Enable clang-format's `InsertBraces` config

This was part of our style guide since we started using clang-format
but the feature was only added in clang-format 15, and we hadn't
noticed it yet.
Rémi Verschelde 6 months ago
parent
commit
03c83cea1e

+ 1 - 1
.clang-format

@@ -124,7 +124,7 @@ IndentCaseLabels: true
 # IndentRequiresClause: true
 IndentWidth: 4
 # IndentWrappedFunctionNames: false
-# InsertBraces: false
+InsertBraces: true
 # InsertNewlineAtEOF: false
 # InsertTrailingCommas: None
 # IntegerLiteralSeparator:

+ 7 - 6
drivers/gles3/shaders/canvas.glsl

@@ -208,18 +208,19 @@ void main() {
 	// no crash or freeze on all Adreno 3xx	with 'if / else if' and slightly faster!
 	int vertex_id = gl_VertexID % 6;
 	vec2 vertex_base;
-	if (vertex_id == 0)
+	if (vertex_id == 0) {
 		vertex_base = vec2(0.0, 0.0);
-	else if (vertex_id == 1)
+	} else if (vertex_id == 1) {
 		vertex_base = vec2(0.0, 1.0);
-	else if (vertex_id == 2)
+	} else if (vertex_id == 2) {
 		vertex_base = vec2(1.0, 1.0);
-	else if (vertex_id == 3)
+	} else if (vertex_id == 3) {
 		vertex_base = vec2(1.0, 0.0);
-	else if (vertex_id == 4)
+	} else if (vertex_id == 4) {
 		vertex_base = vec2(0.0, 0.0);
-	else if (vertex_id == 5)
+	} else if (vertex_id == 5) {
 		vertex_base = vec2(1.0, 1.0);
+	}
 
 	vec2 uv = read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) * ((read_draw_data_flags & INSTANCE_FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy);
 	vec4 color = read_draw_data_modulation;

+ 2 - 1
drivers/metal/metal_objects.h

@@ -850,8 +850,9 @@ public:
 			uint32_t front_reference = 0;
 			uint32_t back_reference = 0;
 			_FORCE_INLINE_ void apply(id<MTLRenderCommandEncoder> __unsafe_unretained p_enc) const {
-				if (!enabled)
+				if (!enabled) {
 					return;
+				}
 				[p_enc setStencilFrontReferenceValue:front_reference backReferenceValue:back_reference];
 			}
 		} stencil;

+ 4 - 2
drivers/metal/rendering_device_driver_metal.mm

@@ -1198,8 +1198,9 @@ class BufReader {
 	uint64_t pos = 0;
 
 	bool check_length(size_t p_size) {
-		if (status != Status::OK)
+		if (status != Status::OK) {
 			return false;
+		}
 
 		if (pos + p_size > length) {
 			status = Status::SHORT_BUFFER;
@@ -2518,8 +2519,9 @@ RDD::ShaderID RenderingDeviceDriverMetal::shader_create_from_bytecode(const Vect
 
 			for (UniformInfo const &uniform : set.uniforms) {
 				BindingInfo const *binding_info = uniform.bindings.getptr(stage);
-				if (binding_info == nullptr)
+				if (binding_info == nullptr) {
 					continue;
+				}
 
 				[descriptors addObject:binding_info->new_argument_descriptor()];
 				BindingInfo const *secondary_binding_info = uniform.bindings_secondary.getptr(stage);

+ 1 - 0
misc/utility/clang_format_glsl.yml

@@ -23,6 +23,7 @@ IncludeCategories:
     Priority: 3
 IndentCaseLabels: true
 IndentWidth: 4
+InsertBraces: true
 JavaImportGroups:
   - org.godotengine
   - android

+ 23 - 14
modules/betsy/bc1.glsl

@@ -108,8 +108,9 @@ void OptimizeColorsBlock(const uint srcPixelsBlock[16], out float outMinEndp16,
 
 	// determine covariance matrix
 	float cov[6];
-	for (int i = 0; i < 6; ++i)
+	for (int i = 0; i < 6; ++i) {
 		cov[i] = 0;
+	}
 
 	for (int i = 0; i < 16; ++i) {
 		const float3 currColor = unpackUnorm4x8(srcPixelsBlock[i]).xyz * 255.0f;
@@ -124,8 +125,9 @@ void OptimizeColorsBlock(const uint srcPixelsBlock[16], out float outMinEndp16,
 	}
 
 	// convert covariance matrix to float, find principal axis via power iter
-	for (int i = 0; i < 6; ++i)
+	for (int i = 0; i < 6; ++i) {
 		cov[i] /= 255.0f;
+	}
 
 	float3 vF = maxColor - minColor;
 
@@ -180,8 +182,9 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
 	float3 dir = color[0] - color[1];
 	float stops[4];
 
-	for (int i = 0; i < 4; ++i)
+	for (int i = 0; i < 4; ++i) {
 		stops[i] = dot(color[i], dir);
+	}
 
 	// think of the colors as arranged on a line; project point onto that line, then choose
 	// next color out of available ones. we compute the crossover points for "best color in top
@@ -203,10 +206,11 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
 		const float dotValue = dot(currColor, dir);
 		mask <<= 2u;
 
-		if (dotValue < halfPoint)
+		if (dotValue < halfPoint) {
 			mask |= ((dotValue < c0Point) ? 1u : 3u);
-		else
+		} else {
 			mask |= ((dotValue < c3Point) ? 2u : 0u);
+		}
 	}
 #else
 	// with floyd-steinberg dithering
@@ -228,10 +232,11 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
 		dotValue = dot(currColor, dir);
 
 		ditherDot = (dotValue * 16.0f) + (3 * ep2[1] + 5 * ep2[0]);
-		if (ditherDot < halfPoint)
+		if (ditherDot < halfPoint) {
 			step = (ditherDot < c0Point) ? 1u : 3u;
-		else
+		} else {
 			step = (ditherDot < c3Point) ? 2u : 0u;
+		}
 		ep1[0] = dotValue - stops[step];
 		lmask = step;
 
@@ -239,10 +244,11 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
 		dotValue = dot(currColor, dir);
 
 		ditherDot = (dotValue * 16.0f) + (7 * ep1[0] + 3 * ep2[2] + 5 * ep2[1] + ep2[0]);
-		if (ditherDot < halfPoint)
+		if (ditherDot < halfPoint) {
 			step = (ditherDot < c0Point) ? 1u : 3u;
-		else
+		} else {
 			step = (ditherDot < c3Point) ? 2u : 0u;
+		}
 		ep1[1] = dotValue - stops[step];
 		lmask |= step << 2u;
 
@@ -250,10 +256,11 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
 		dotValue = dot(currColor, dir);
 
 		ditherDot = (dotValue * 16.0f) + (7 * ep1[1] + 3 * ep2[3] + 5 * ep2[2] + ep2[1]);
-		if (ditherDot < halfPoint)
+		if (ditherDot < halfPoint) {
 			step = (ditherDot < c0Point) ? 1u : 3u;
-		else
+		} else {
 			step = (ditherDot < c3Point) ? 2u : 0u;
+		}
 		ep1[2] = dotValue - stops[step];
 		lmask |= step << 4u;
 
@@ -261,10 +268,11 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
 		dotValue = dot(currColor, dir);
 
 		ditherDot = (dotValue * 16.0f) + (7 * ep1[2] + 5 * ep2[3] + ep2[2]);
-		if (ditherDot < halfPoint)
+		if (ditherDot < halfPoint) {
 			step = (ditherDot < c0Point) ? 1u : 3u;
-		else
+		} else {
 			step = (ditherDot < c3Point) ? 2u : 0u;
+		}
 		ep1[3] = dotValue - stops[step];
 		lmask |= step << 6u;
 
@@ -294,8 +302,9 @@ bool RefineBlock(const uint srcPixelsBlock[16], uint mask, inout float inOutMinE
 		// yes, linear system would be singular; solve using optimal
 		// single-color match on average color
 		float3 rgbVal = float3(8.0f / 255.0f, 8.0f / 255.0f, 8.0f / 255.0f);
-		for (int i = 0; i < 16; ++i)
+		for (int i = 0; i < 16; ++i) {
 			rgbVal += unpackUnorm4x8(srcPixelsBlock[i]).xyz;
+		}
 
 		rgbVal = floor(rgbVal * (255.0f / 16.0f));
 

+ 6 - 3
modules/betsy/bc4.glsl

@@ -102,8 +102,9 @@ void main() {
 			a -= dist2;
 		}
 
-		if (a >= dist)
+		if (a >= dist) {
 			ind += 1;
+		}
 
 		// turn linear scale into DXT index (0/1 are extremal pts)
 		ind = -ind & 7;
@@ -121,10 +122,12 @@ void main() {
 		}
 	}
 
-	if (mask0 != 0u)
+	if (mask0 != 0u) {
 		atomicOr(g_mask[maskIdxBase].x, mask0);
-	if (mask1 != 0u)
+	}
+	if (mask1 != 0u) {
 		atomicOr(g_mask[maskIdxBase].y, mask1);
+	}
 
 	memoryBarrierShared();
 	barrier();

+ 10 - 7
servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl

@@ -177,24 +177,27 @@ void main() {
 
 			float theta;
 			if (Ny < Nx) {
-				if (Ny <= -0.999)
+				if (Ny <= -0.999) {
 					theta = Nx;
-				else
+				} else {
 					theta = Ny;
+				}
 			} else {
-				if (Ny >= 0.999)
+				if (Ny >= 0.999) {
 					theta = -Nx;
-				else
+				} else {
 					theta = -Ny;
+				}
 			}
 
 			float phi;
-			if (Nz <= -0.999)
+			if (Nz <= -0.999) {
 				phi = -NmaxXY;
-			else if (Nz >= 0.999)
+			} else if (Nz >= 0.999) {
 				phi = NmaxXY;
-			else
+			} else {
 				phi = Nz;
+			}
 
 			float theta2 = theta * theta;
 			float phi2 = phi * phi;

+ 10 - 7
servers/rendering/renderer_rd/shaders/effects/cubemap_filter_raster.glsl

@@ -170,24 +170,27 @@ void main() {
 
 			float theta;
 			if (Ny < Nx) {
-				if (Ny <= -0.999)
+				if (Ny <= -0.999) {
 					theta = Nx;
-				else
+				} else {
 					theta = Ny;
+				}
 			} else {
-				if (Ny >= 0.999)
+				if (Ny >= 0.999) {
 					theta = -Nx;
-				else
+				} else {
 					theta = -Ny;
+				}
 			}
 
 			float phi;
-			if (Nz <= -0.999)
+			if (Nz <= -0.999) {
 				phi = -NmaxXY;
-			else if (Nz >= 0.999)
+			} else if (Nz >= 0.999) {
 				phi = NmaxXY;
-			else
+			} else {
 				phi = Nz;
+			}
 
 			float theta2 = theta * theta;
 			float phi2 = phi * phi;

+ 4 - 2
servers/rendering/renderer_rd/shaders/effects/sort.glsl

@@ -70,8 +70,9 @@ void main() {
 
 	int i;
 	for (i = 0; i < 2 * ITERATIONS; ++i) {
-		if (GI + i * NUM_THREADS < numElementsInThreadGroup)
+		if (GI + i * NUM_THREADS < numElementsInThreadGroup) {
 			g_LDS[LocalBaseIndex + i * NUM_THREADS] = sort_buffer.data[GlobalBaseIndex + i * NUM_THREADS];
+		}
 	}
 
 	groupMemoryBarrier();
@@ -163,8 +164,9 @@ void main() {
 
 	// Load shared data
 	for (i = 0; i < 2; ++i) {
-		if (GI + i * NUM_THREADS < tgp.w)
+		if (GI + i * NUM_THREADS < tgp.w) {
 			g_LDS[LocalBaseIndex + i * NUM_THREADS] = sort_buffer.data[GlobalBaseIndex + i * NUM_THREADS];
+		}
 	}
 
 	groupMemoryBarrier();

+ 12 - 6
servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl

@@ -250,19 +250,25 @@ vec3 clip_aabb(vec3 aabb_min, vec3 aabb_max, vec3 p, vec3 q) {
 	vec3 rmax = (aabb_max - p.xyz);
 	vec3 rmin = (aabb_min - p.xyz);
 
-	if (r.x > rmax.x + FLT_MIN)
+	if (r.x > rmax.x + FLT_MIN) {
 		r *= (rmax.x / r.x);
-	if (r.y > rmax.y + FLT_MIN)
+	}
+	if (r.y > rmax.y + FLT_MIN) {
 		r *= (rmax.y / r.y);
-	if (r.z > rmax.z + FLT_MIN)
+	}
+	if (r.z > rmax.z + FLT_MIN) {
 		r *= (rmax.z / r.z);
+	}
 
-	if (r.x < rmin.x - FLT_MIN)
+	if (r.x < rmin.x - FLT_MIN) {
 		r *= (rmin.x / r.x);
-	if (r.y < rmin.y - FLT_MIN)
+	}
+	if (r.y < rmin.y - FLT_MIN) {
 		r *= (rmin.y / r.y);
-	if (r.z < rmin.z - FLT_MIN)
+	}
+	if (r.z < rmin.z - FLT_MIN) {
 		r *= (rmin.z / r.z);
+	}
 
 	return p + r;
 }

+ 32 - 16
servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl

@@ -128,38 +128,54 @@ void main() {
 	int index = x + y * 4;
 	float limit = 0.0;
 	if (x < 8) {
-		if (index == 0)
+		if (index == 0) {
 			limit = 0.0625;
-		if (index == 1)
+		}
+		if (index == 1) {
 			limit = 0.5625;
-		if (index == 2)
+		}
+		if (index == 2) {
 			limit = 0.1875;
-		if (index == 3)
+		}
+		if (index == 3) {
 			limit = 0.6875;
-		if (index == 4)
+		}
+		if (index == 4) {
 			limit = 0.8125;
-		if (index == 5)
+		}
+		if (index == 5) {
 			limit = 0.3125;
-		if (index == 6)
+		}
+		if (index == 6) {
 			limit = 0.9375;
-		if (index == 7)
+		}
+		if (index == 7) {
 			limit = 0.4375;
-		if (index == 8)
+		}
+		if (index == 8) {
 			limit = 0.25;
-		if (index == 9)
+		}
+		if (index == 9) {
 			limit = 0.75;
-		if (index == 10)
+		}
+		if (index == 10) {
 			limit = 0.125;
-		if (index == 11)
+		}
+		if (index == 11) {
 			limit = 0.625;
-		if (index == 12)
+		}
+		if (index == 12) {
 			limit = 1.0;
-		if (index == 13)
+		}
+		if (index == 13) {
 			limit = 0.5;
-		if (index == 14)
+		}
+		if (index == 14) {
 			limit = 0.875;
-		if (index == 15)
+		}
+		if (index == 15) {
 			limit = 0.375;
+		}
 	}
 	if (frag_color.a < limit) {
 		discard;

+ 2 - 1
servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl

@@ -2805,8 +2805,9 @@ void main() {
 #endif
 #ifdef MODE_DUAL_PARABOLOID
 
-	if (dp_clip > 0.0)
+	if (dp_clip > 0.0) {
 		discard;
+	}
 #endif
 
 	fragment_shader(scene_data_block.data);

+ 2 - 1
servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl

@@ -837,8 +837,9 @@ void main() {
 #endif
 #ifdef MODE_DUAL_PARABOLOID
 
-	if (dp_clip > 0.0)
+	if (dp_clip > 0.0) {
 		discard;
+	}
 #endif
 
 	//lay out everything, whatever is unused is optimized away anyway

+ 11 - 6
servers/rendering/rendering_light_culler.cpp

@@ -696,10 +696,11 @@ void RenderingLightCuller::debug_print_LUT_as_table() {
 		int s = entry.size();
 
 		for (int p = 0; p < 8; p++) {
-			if (p < s)
+			if (p < s) {
 				sz += itos(entry[p]);
-			else
+			} else {
 				sz += "0"; // just a spacer
+			}
 
 			sz += ", ";
 		}
@@ -765,12 +766,14 @@ void RenderingLightCuller::add_LUT(int p_plane_0, int p_plane_1, PointOrder p_pt
 	// All entries of the LUT that have plane 0 set and plane 1 not set.
 	for (uint32_t n = 0; n < 64; n++) {
 		// If bit0 not set...
-		if (!(n & bit0))
+		if (!(n & bit0)) {
 			continue;
+		}
 
 		// If bit1 set...
-		if (n & bit1)
+		if (n & bit1) {
 			continue;
+		}
 
 		// Meets criteria.
 		add_LUT_entry(n, p_pts);
@@ -791,8 +794,9 @@ void RenderingLightCuller::compact_LUT_entry(uint32_t p_entry_id) {
 
 	int num_pairs = entry.size() / 2;
 
-	if (num_pairs == 0)
+	if (num_pairs == 0) {
 		return;
+	}
 
 	LocalVector<uint8_t> temp;
 
@@ -816,8 +820,9 @@ void RenderingLightCuller::compact_LUT_entry(uint32_t p_entry_id) {
 		for (int p = 1; p < num_pairs; p++) {
 			unsigned int bit = 1 << p;
 			// Is it done already?
-			if (BFpairs & bit)
+			if (BFpairs & bit) {
 				continue;
+			}
 
 			// There must be at least 1 free pair.
 			// Attempt to add.