Skip to content

Commit

Permalink
Style: Enable clang-format's InsertBraces config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akien-mga committed Jan 9, 2025
1 parent 0e3a5ed commit 03c83ce
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ IndentCaseLabels: true
# IndentRequiresClause: true
IndentWidth: 4
# IndentWrappedFunctionNames: false
# InsertBraces: false
InsertBraces: true
# InsertNewlineAtEOF: false
# InsertTrailingCommas: None
# IntegerLiteralSeparator:
Expand Down
13 changes: 7 additions & 6 deletions drivers/gles3/shaders/canvas.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion drivers/metal/metal_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,9 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDRenderPipeline final : public MDPi
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;
Expand Down
6 changes: 4 additions & 2 deletions drivers/metal/rendering_device_driver_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,9 @@ void write_buffer(uint8_t const *p_buffer, uint32_t p_length) {
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;
Expand Down Expand Up @@ -2518,8 +2519,9 @@ void deserialize(BufReader &p_reader) {

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);
Expand Down
1 change: 1 addition & 0 deletions misc/utility/clang_format_glsl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ IncludeCategories:
Priority: 3
IndentCaseLabels: true
IndentWidth: 4
InsertBraces: true
JavaImportGroups:
- org.godotengine
- android
Expand Down
37 changes: 23 additions & 14 deletions modules/betsy/bc1.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -228,43 +232,47 @@ 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;

currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 1]).xyz * 255.0f;
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;

currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 2]).xyz * 255.0f;
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;

currColor = unpackUnorm4x8(srcPixelsBlock[y * 4 + 2]).xyz * 255.0f;
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;

Expand Down Expand Up @@ -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));

Expand Down
9 changes: 6 additions & 3 deletions modules/betsy/bc4.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
17 changes: 10 additions & 7 deletions servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions servers/rendering/renderer_rd/shaders/effects/sort.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 12 additions & 6 deletions servers/rendering/renderer_rd/shaders/effects/taa_resolve.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 03c83ce

Please sign in to comment.