Skip to content

Commit 03c83ce

Browse files
committed
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.
1 parent 0e3a5ed commit 03c83ce

15 files changed

+127
-73
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ IndentCaseLabels: true
124124
# IndentRequiresClause: true
125125
IndentWidth: 4
126126
# IndentWrappedFunctionNames: false
127-
# InsertBraces: false
127+
InsertBraces: true
128128
# InsertNewlineAtEOF: false
129129
# InsertTrailingCommas: None
130130
# IntegerLiteralSeparator:

drivers/gles3/shaders/canvas.glsl

+7-6
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,19 @@ void main() {
208208
// no crash or freeze on all Adreno 3xx with 'if / else if' and slightly faster!
209209
int vertex_id = gl_VertexID % 6;
210210
vec2 vertex_base;
211-
if (vertex_id == 0)
211+
if (vertex_id == 0) {
212212
vertex_base = vec2(0.0, 0.0);
213-
else if (vertex_id == 1)
213+
} else if (vertex_id == 1) {
214214
vertex_base = vec2(0.0, 1.0);
215-
else if (vertex_id == 2)
215+
} else if (vertex_id == 2) {
216216
vertex_base = vec2(1.0, 1.0);
217-
else if (vertex_id == 3)
217+
} else if (vertex_id == 3) {
218218
vertex_base = vec2(1.0, 0.0);
219-
else if (vertex_id == 4)
219+
} else if (vertex_id == 4) {
220220
vertex_base = vec2(0.0, 0.0);
221-
else if (vertex_id == 5)
221+
} else if (vertex_id == 5) {
222222
vertex_base = vec2(1.0, 1.0);
223+
}
223224

224225
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);
225226
vec4 color = read_draw_data_modulation;

drivers/metal/metal_objects.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,9 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDRenderPipeline final : public MDPi
850850
uint32_t front_reference = 0;
851851
uint32_t back_reference = 0;
852852
_FORCE_INLINE_ void apply(id<MTLRenderCommandEncoder> __unsafe_unretained p_enc) const {
853-
if (!enabled)
853+
if (!enabled) {
854854
return;
855+
}
855856
[p_enc setStencilFrontReferenceValue:front_reference backReferenceValue:back_reference];
856857
}
857858
} stencil;

drivers/metal/rendering_device_driver_metal.mm

+4-2
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,9 @@ void write_buffer(uint8_t const *p_buffer, uint32_t p_length) {
11981198
uint64_t pos = 0;
11991199

12001200
bool check_length(size_t p_size) {
1201-
if (status != Status::OK)
1201+
if (status != Status::OK) {
12021202
return false;
1203+
}
12031204

12041205
if (pos + p_size > length) {
12051206
status = Status::SHORT_BUFFER;
@@ -2518,8 +2519,9 @@ void deserialize(BufReader &p_reader) {
25182519

25192520
for (UniformInfo const &uniform : set.uniforms) {
25202521
BindingInfo const *binding_info = uniform.bindings.getptr(stage);
2521-
if (binding_info == nullptr)
2522+
if (binding_info == nullptr) {
25222523
continue;
2524+
}
25232525

25242526
[descriptors addObject:binding_info->new_argument_descriptor()];
25252527
BindingInfo const *secondary_binding_info = uniform.bindings_secondary.getptr(stage);

misc/utility/clang_format_glsl.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ IncludeCategories:
2323
Priority: 3
2424
IndentCaseLabels: true
2525
IndentWidth: 4
26+
InsertBraces: true
2627
JavaImportGroups:
2728
- org.godotengine
2829
- android

modules/betsy/bc1.glsl

+23-14
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ void OptimizeColorsBlock(const uint srcPixelsBlock[16], out float outMinEndp16,
108108

109109
// determine covariance matrix
110110
float cov[6];
111-
for (int i = 0; i < 6; ++i)
111+
for (int i = 0; i < 6; ++i) {
112112
cov[i] = 0;
113+
}
113114

114115
for (int i = 0; i < 16; ++i) {
115116
const float3 currColor = unpackUnorm4x8(srcPixelsBlock[i]).xyz * 255.0f;
@@ -124,8 +125,9 @@ void OptimizeColorsBlock(const uint srcPixelsBlock[16], out float outMinEndp16,
124125
}
125126

126127
// convert covariance matrix to float, find principal axis via power iter
127-
for (int i = 0; i < 6; ++i)
128+
for (int i = 0; i < 6; ++i) {
128129
cov[i] /= 255.0f;
130+
}
129131

130132
float3 vF = maxColor - minColor;
131133

@@ -180,8 +182,9 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
180182
float3 dir = color[0] - color[1];
181183
float stops[4];
182184

183-
for (int i = 0; i < 4; ++i)
185+
for (int i = 0; i < 4; ++i) {
184186
stops[i] = dot(color[i], dir);
187+
}
185188

186189
// think of the colors as arranged on a line; project point onto that line, then choose
187190
// 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]) {
203206
const float dotValue = dot(currColor, dir);
204207
mask <<= 2u;
205208

206-
if (dotValue < halfPoint)
209+
if (dotValue < halfPoint) {
207210
mask |= ((dotValue < c0Point) ? 1u : 3u);
208-
else
211+
} else {
209212
mask |= ((dotValue < c3Point) ? 2u : 0u);
213+
}
210214
}
211215
#else
212216
// with floyd-steinberg dithering
@@ -228,43 +232,47 @@ uint MatchColorsBlock(const uint srcPixelsBlock[16], float3 color[4]) {
228232
dotValue = dot(currColor, dir);
229233

230234
ditherDot = (dotValue * 16.0f) + (3 * ep2[1] + 5 * ep2[0]);
231-
if (ditherDot < halfPoint)
235+
if (ditherDot < halfPoint) {
232236
step = (ditherDot < c0Point) ? 1u : 3u;
233-
else
237+
} else {
234238
step = (ditherDot < c3Point) ? 2u : 0u;
239+
}
235240
ep1[0] = dotValue - stops[step];
236241
lmask = step;
237242

238243
currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 1]).xyz * 255.0f;
239244
dotValue = dot(currColor, dir);
240245

241246
ditherDot = (dotValue * 16.0f) + (7 * ep1[0] + 3 * ep2[2] + 5 * ep2[1] + ep2[0]);
242-
if (ditherDot < halfPoint)
247+
if (ditherDot < halfPoint) {
243248
step = (ditherDot < c0Point) ? 1u : 3u;
244-
else
249+
} else {
245250
step = (ditherDot < c3Point) ? 2u : 0u;
251+
}
246252
ep1[1] = dotValue - stops[step];
247253
lmask |= step << 2u;
248254

249255
currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 2]).xyz * 255.0f;
250256
dotValue = dot(currColor, dir);
251257

252258
ditherDot = (dotValue * 16.0f) + (7 * ep1[1] + 3 * ep2[3] + 5 * ep2[2] + ep2[1]);
253-
if (ditherDot < halfPoint)
259+
if (ditherDot < halfPoint) {
254260
step = (ditherDot < c0Point) ? 1u : 3u;
255-
else
261+
} else {
256262
step = (ditherDot < c3Point) ? 2u : 0u;
263+
}
257264
ep1[2] = dotValue - stops[step];
258265
lmask |= step << 4u;
259266

260267
currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 2]).xyz * 255.0f;
261268
dotValue = dot(currColor, dir);
262269

263270
ditherDot = (dotValue * 16.0f) + (7 * ep1[2] + 5 * ep2[3] + ep2[2]);
264-
if (ditherDot < halfPoint)
271+
if (ditherDot < halfPoint) {
265272
step = (ditherDot < c0Point) ? 1u : 3u;
266-
else
273+
} else {
267274
step = (ditherDot < c3Point) ? 2u : 0u;
275+
}
268276
ep1[3] = dotValue - stops[step];
269277
lmask |= step << 6u;
270278

@@ -294,8 +302,9 @@ bool RefineBlock(const uint srcPixelsBlock[16], uint mask, inout float inOutMinE
294302
// yes, linear system would be singular; solve using optimal
295303
// single-color match on average color
296304
float3 rgbVal = float3(8.0f / 255.0f, 8.0f / 255.0f, 8.0f / 255.0f);
297-
for (int i = 0; i < 16; ++i)
305+
for (int i = 0; i < 16; ++i) {
298306
rgbVal += unpackUnorm4x8(srcPixelsBlock[i]).xyz;
307+
}
299308

300309
rgbVal = floor(rgbVal * (255.0f / 16.0f));
301310

modules/betsy/bc4.glsl

+6-3
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ void main() {
102102
a -= dist2;
103103
}
104104

105-
if (a >= dist)
105+
if (a >= dist) {
106106
ind += 1;
107+
}
107108

108109
// turn linear scale into DXT index (0/1 are extremal pts)
109110
ind = -ind & 7;
@@ -121,10 +122,12 @@ void main() {
121122
}
122123
}
123124

124-
if (mask0 != 0u)
125+
if (mask0 != 0u) {
125126
atomicOr(g_mask[maskIdxBase].x, mask0);
126-
if (mask1 != 0u)
127+
}
128+
if (mask1 != 0u) {
127129
atomicOr(g_mask[maskIdxBase].y, mask1);
130+
}
128131

129132
memoryBarrierShared();
130133
barrier();

servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl

+10-7
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,27 @@ void main() {
177177

178178
float theta;
179179
if (Ny < Nx) {
180-
if (Ny <= -0.999)
180+
if (Ny <= -0.999) {
181181
theta = Nx;
182-
else
182+
} else {
183183
theta = Ny;
184+
}
184185
} else {
185-
if (Ny >= 0.999)
186+
if (Ny >= 0.999) {
186187
theta = -Nx;
187-
else
188+
} else {
188189
theta = -Ny;
190+
}
189191
}
190192

191193
float phi;
192-
if (Nz <= -0.999)
194+
if (Nz <= -0.999) {
193195
phi = -NmaxXY;
194-
else if (Nz >= 0.999)
196+
} else if (Nz >= 0.999) {
195197
phi = NmaxXY;
196-
else
198+
} else {
197199
phi = Nz;
200+
}
198201

199202
float theta2 = theta * theta;
200203
float phi2 = phi * phi;

servers/rendering/renderer_rd/shaders/effects/cubemap_filter_raster.glsl

+10-7
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,27 @@ void main() {
170170

171171
float theta;
172172
if (Ny < Nx) {
173-
if (Ny <= -0.999)
173+
if (Ny <= -0.999) {
174174
theta = Nx;
175-
else
175+
} else {
176176
theta = Ny;
177+
}
177178
} else {
178-
if (Ny >= 0.999)
179+
if (Ny >= 0.999) {
179180
theta = -Nx;
180-
else
181+
} else {
181182
theta = -Ny;
183+
}
182184
}
183185

184186
float phi;
185-
if (Nz <= -0.999)
187+
if (Nz <= -0.999) {
186188
phi = -NmaxXY;
187-
else if (Nz >= 0.999)
189+
} else if (Nz >= 0.999) {
188190
phi = NmaxXY;
189-
else
191+
} else {
190192
phi = Nz;
193+
}
191194

192195
float theta2 = theta * theta;
193196
float phi2 = phi * phi;

servers/rendering/renderer_rd/shaders/effects/sort.glsl

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ void main() {
7070

7171
int i;
7272
for (i = 0; i < 2 * ITERATIONS; ++i) {
73-
if (GI + i * NUM_THREADS < numElementsInThreadGroup)
73+
if (GI + i * NUM_THREADS < numElementsInThreadGroup) {
7474
g_LDS[LocalBaseIndex + i * NUM_THREADS] = sort_buffer.data[GlobalBaseIndex + i * NUM_THREADS];
75+
}
7576
}
7677

7778
groupMemoryBarrier();
@@ -163,8 +164,9 @@ void main() {
163164

164165
// Load shared data
165166
for (i = 0; i < 2; ++i) {
166-
if (GI + i * NUM_THREADS < tgp.w)
167+
if (GI + i * NUM_THREADS < tgp.w) {
167168
g_LDS[LocalBaseIndex + i * NUM_THREADS] = sort_buffer.data[GlobalBaseIndex + i * NUM_THREADS];
169+
}
168170
}
169171

170172
groupMemoryBarrier();

servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl

+12-6
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,25 @@ vec3 clip_aabb(vec3 aabb_min, vec3 aabb_max, vec3 p, vec3 q) {
250250
vec3 rmax = (aabb_max - p.xyz);
251251
vec3 rmin = (aabb_min - p.xyz);
252252

253-
if (r.x > rmax.x + FLT_MIN)
253+
if (r.x > rmax.x + FLT_MIN) {
254254
r *= (rmax.x / r.x);
255-
if (r.y > rmax.y + FLT_MIN)
255+
}
256+
if (r.y > rmax.y + FLT_MIN) {
256257
r *= (rmax.y / r.y);
257-
if (r.z > rmax.z + FLT_MIN)
258+
}
259+
if (r.z > rmax.z + FLT_MIN) {
258260
r *= (rmax.z / r.z);
261+
}
259262

260-
if (r.x < rmin.x - FLT_MIN)
263+
if (r.x < rmin.x - FLT_MIN) {
261264
r *= (rmin.x / r.x);
262-
if (r.y < rmin.y - FLT_MIN)
265+
}
266+
if (r.y < rmin.y - FLT_MIN) {
263267
r *= (rmin.y / r.y);
264-
if (r.z < rmin.z - FLT_MIN)
268+
}
269+
if (r.z < rmin.z - FLT_MIN) {
265270
r *= (rmin.z / r.z);
271+
}
266272

267273
return p + r;
268274
}

0 commit comments

Comments
 (0)