From 02837a5b829390aca03bb0e493ced639aa074b81 Mon Sep 17 00:00:00 2001 From: Wentao Liu Date: Thu, 24 Oct 2024 10:21:04 +0800 Subject: [PATCH] CI: add clang-format-check.yml --- .github/workflows/clang-format-check.yml | 20 ++++++++++++++++++++ README.md | 1 + src/pbrt/accelerator/hlbvh.cu | 2 +- src/pbrt/base/megakernel_integrator.cu | 4 ++-- src/pbrt/bxdfs/layered_bxdf.h | 2 +- src/pbrt/euclidean_space/bounds2.h | 2 +- src/pbrt/euclidean_space/point2.h | 4 ++-- src/pbrt/euclidean_space/point3.h | 4 ++-- src/pbrt/euclidean_space/vector3.h | 2 +- src/pbrt/films/rgb_film.cu | 2 +- src/pbrt/filters/mitchell.cu | 3 ++- src/pbrt/lights/spot_light.h | 2 +- src/pbrt/util/float.h | 2 +- src/pbrt/util/piecewise_constant_1d.h | 2 +- 14 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/clang-format-check.yml diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml new file mode 100644 index 0000000..8a59092 --- /dev/null +++ b/.github/workflows/clang-format-check.yml @@ -0,0 +1,20 @@ +name: formatting check (clang-format-16) + +on: + push: + branches: [ "*" ] + pull_request: + branches: [ "*" ] + workflow_dispatch: + +jobs: + formatting-check: + name: formatting check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run clang-format style check for C/C++/Protobuf programs. + uses: jidicula/clang-format-action@v4.13.0 + with: + clang-format-version: '16' + check-path: 'src/pbrt' diff --git a/README.md b/README.md index fadbc5e..ad260f5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # pbrt-minus [![cuda-build](https://github.com/w3ntao/pbrt-minus/actions/workflows/cuda-build.yml/badge.svg)](https://github.com/w3ntao/pbrt-minus/actions/workflows/cuda-build.yml) +[![formatted with clang-format-16](https://github.com/w3ntao/pbrt-minus/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/w3ntao/pbrt-minus/actions/workflows/clang-format-check.yml) A simpler, less performant, physically based, GPU ray tracer rewritten from PBRT-v4. diff --git a/src/pbrt/accelerator/hlbvh.cu b/src/pbrt/accelerator/hlbvh.cu index f166340..0c12f40 100644 --- a/src/pbrt/accelerator/hlbvh.cu +++ b/src/pbrt/accelerator/hlbvh.cu @@ -537,7 +537,7 @@ void HLBVH::build_bvh(const std::vector &gpu_primitives, if (verify_counter != num_total_primitives) { REPORT_FATAL_ERROR(); } - + printf("HLBVH: %zu/%d (%.2f%) treelets filled (max primitives in a treelet: %d)\n", dense_treelet_indices.size(), MAX_TREELET_NUM, double(dense_treelet_indices.size()) / MAX_TREELET_NUM * 100, diff --git a/src/pbrt/base/megakernel_integrator.cu b/src/pbrt/base/megakernel_integrator.cu index eb68332..e4e946e 100644 --- a/src/pbrt/base/megakernel_integrator.cu +++ b/src/pbrt/base/megakernel_integrator.cu @@ -165,8 +165,8 @@ void Integrator::render(Film *film, const std::string &sampler_type, uint sample uint thread_width = 8; uint thread_height = 8; - std::cout << " (samples per pixel: " << samples_per_pixel << ") " << "in " << thread_width - << "x" << thread_height << " blocks.\n" + std::cout << " (samples per pixel: " << samples_per_pixel << ") " + << "in " << thread_width << "x" << thread_height << " blocks.\n" << std::flush; dim3 blocks(divide_and_ceil(uint(film_resolution.x), thread_width), diff --git a/src/pbrt/bxdfs/layered_bxdf.h b/src/pbrt/bxdfs/layered_bxdf.h index 21dbab8..441d00f 100644 --- a/src/pbrt/bxdfs/layered_bxdf.h +++ b/src/pbrt/bxdfs/layered_bxdf.h @@ -11,7 +11,7 @@ template class LayeredBxDF { public: PBRT_GPU - LayeredBxDF() {}; + LayeredBxDF(){}; PBRT_GPU LayeredBxDF(TopBxDF top, BottomBxDF bottom, FloatType thickness, const SampledSpectrum &albedo, diff --git a/src/pbrt/euclidean_space/bounds2.h b/src/pbrt/euclidean_space/bounds2.h index bbe5244..ea598f2 100644 --- a/src/pbrt/euclidean_space/bounds2.h +++ b/src/pbrt/euclidean_space/bounds2.h @@ -23,7 +23,7 @@ class Bounds2 { PBRT_CPU_GPU Bounds2(Point2 p1, Point2 p2) : p_min(p1.min(p2)), p_max(p1.max(p2)) {} - + PBRT_CPU_GPU Vector2 Diagonal() const { return p_max - p_min; diff --git a/src/pbrt/euclidean_space/point2.h b/src/pbrt/euclidean_space/point2.h index 029fb31..1f9ace6 100644 --- a/src/pbrt/euclidean_space/point2.h +++ b/src/pbrt/euclidean_space/point2.h @@ -9,9 +9,9 @@ class Point2 { public: T x, y; - PBRT_CPU_GPU Point2() {}; + PBRT_CPU_GPU Point2(){}; - PBRT_CPU_GPU Point2(T _x, T _y) : x(_x), y(_y) {}; + PBRT_CPU_GPU Point2(T _x, T _y) : x(_x), y(_y){}; PBRT_CPU_GPU explicit Point2(const Vector2 v) : x(v.x), y(v.y) {} diff --git a/src/pbrt/euclidean_space/point3.h b/src/pbrt/euclidean_space/point3.h index c798b8e..b341e91 100644 --- a/src/pbrt/euclidean_space/point3.h +++ b/src/pbrt/euclidean_space/point3.h @@ -8,9 +8,9 @@ class Point3 { public: T x, y, z; - PBRT_CPU_GPU Point3() : x(NAN), y(NAN), z(NAN) {}; + PBRT_CPU_GPU Point3() : x(NAN), y(NAN), z(NAN){}; - PBRT_CPU_GPU Point3(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}; + PBRT_CPU_GPU Point3(T _x, T _y, T _z) : x(_x), y(_y), z(_z){}; PBRT_CPU_GPU T &operator[](uint8_t index) { switch (index) { diff --git a/src/pbrt/euclidean_space/vector3.h b/src/pbrt/euclidean_space/vector3.h index 31cbfcc..a2e6419 100644 --- a/src/pbrt/euclidean_space/vector3.h +++ b/src/pbrt/euclidean_space/vector3.h @@ -9,7 +9,7 @@ class Vector3 { public: T x, y, z; - PBRT_CPU_GPU Vector3() : x(NAN), y(NAN), z(NAN) {}; + PBRT_CPU_GPU Vector3() : x(NAN), y(NAN), z(NAN){}; PBRT_CPU_GPU Vector3(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {} diff --git a/src/pbrt/films/rgb_film.cu b/src/pbrt/films/rgb_film.cu index 1deb7f2..d6443c7 100644 --- a/src/pbrt/films/rgb_film.cu +++ b/src/pbrt/films/rgb_film.cu @@ -78,7 +78,7 @@ void RGBFilm::add_sample(uint pixel_index, const SampledSpectrum &radiance_l, if (weight == 0) { return; } - + auto rgb = sensor->to_sensor_rgb(radiance_l, lambda); if (DEBUG_MODE && rgb.has_nan()) { diff --git a/src/pbrt/filters/mitchell.cu b/src/pbrt/filters/mitchell.cu index 465ff7d..1352080 100644 --- a/src/pbrt/filters/mitchell.cu +++ b/src/pbrt/filters/mitchell.cu @@ -12,7 +12,8 @@ FloatType MitchellFilter::Mitchell1D(FloatType x) const { if (x <= 1) { return ((12 - 9 * b - 6 * c) * x * x * x + (-18 + 12 * b + 6 * c) * x * x + (6 - 2 * b)) * (1.f / 6.f); - } else if (x <= 2) { + } + if (x <= 2) { return ((-b - 6 * c) * x * x * x + (6 * b + 30 * c) * x * x + (-12 * b - 48 * c) * x + (8 * b + 24 * c)) * (1.f / 6.f); diff --git a/src/pbrt/lights/spot_light.h b/src/pbrt/lights/spot_light.h index 7a5a530..8d81c7e 100644 --- a/src/pbrt/lights/spot_light.h +++ b/src/pbrt/lights/spot_light.h @@ -22,7 +22,7 @@ class SpotLight : public LightBase { PBRT_GPU SampledSpectrum l(Point3f p, Normal3f n, Point2f uv, Vector3f w, const SampledWavelengths &lambda) const; - + PBRT_GPU cuda::std::optional sample_li(const LightSampleContext &ctx, const Point2f &u, SampledWavelengths &lambda) const; diff --git a/src/pbrt/util/float.h b/src/pbrt/util/float.h index c00b74c..cc7ed4e 100644 --- a/src/pbrt/util/float.h +++ b/src/pbrt/util/float.h @@ -65,7 +65,7 @@ class Half { if (f.u >= f16max.u) { // result is Inf or NaN (all exponent bits set) o.u = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; - } // NaN->qNaN and Inf->Inf + } // NaN->qNaN and Inf->Inf else { // (De)normalized number or zero if (f.u < (113 << 23)) { // resulting FP16 is subnormal or zero // use a magic value to align our 10 mantissa bits at the bottom diff --git a/src/pbrt/util/piecewise_constant_1d.h b/src/pbrt/util/piecewise_constant_1d.h index 96ee9cf..643e13c 100644 --- a/src/pbrt/util/piecewise_constant_1d.h +++ b/src/pbrt/util/piecewise_constant_1d.h @@ -75,7 +75,7 @@ class PiecewiseConstant1D { // Compute offset along CDF segment FloatType du = u - cdf[o]; - + if (cdf[o + 1] - cdf[o] > 0) { du /= cdf[o + 1] - cdf[o]; }