From 89b5c1d9bf2245d26c9ba2ea73fdfcd61819c059 Mon Sep 17 00:00:00 2001 From: "Lytovchenko, Danylo" Date: Thu, 5 Jun 2025 14:28:12 +0200 Subject: [PATCH] SWDEV-123456 auto clang-format (#482) * SWDEV-123456 - add clang-format script and pre-commit hook [ROCm/clr commit: 580a8759dd6cf065b2c2e9f685c517ac6e9ab2e8] --- .../clr/.github/hooks/clang-format-check.sh | 39 +++++++++++++++++++ projects/clr/.github/hooks/pre-commit | 2 + .../clr/.github/workflows/clang-format.yml | 22 +++++++++++ projects/clr/opencl/amdocl/cl_d3d9.cpp | 14 +++---- 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 projects/clr/.github/hooks/clang-format-check.sh create mode 100644 projects/clr/.github/hooks/pre-commit create mode 100644 projects/clr/.github/workflows/clang-format.yml diff --git a/projects/clr/.github/hooks/clang-format-check.sh b/projects/clr/.github/hooks/clang-format-check.sh new file mode 100644 index 0000000000..a9f4f25f79 --- /dev/null +++ b/projects/clr/.github/hooks/clang-format-check.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -euo pipefail + +RANGE="" + +while [[ $# -gt 0 ]]; do + echo $1 + echo $2 + case "$1" in + --range) + RANGE="$2" + shift 2 + ;; + *) + echo "Unknown arg $1" >&2 + exit 64 + ;; + esac +done + +regex='\.(c|cc|cpp|cxx|h|hh|hpp|hxx)$' + +if [[ -n $RANGE ]]; then + files=$(git diff --name-only "$RANGE" | grep -E "$regex" || true) +else + files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E "$regex" || true) +fi +echo "Checking $files" +[[ -z $files ]] && exit 0 + +clang_bin="${CLANG_FORMAT:-clang-format}" +if ! command -v "$clang_bin" >/dev/null 2>&1; then + if [[ -x "/c/Program Files/LLVM/bin/clang-format.exe" ]]; then + clang_bin="/c/Program Files/LLVM/bin/clang-format.exe" + fi +fi + +"$clang_bin" -style=file --dry-run -fallback-style=none -n -Werror $files diff --git a/projects/clr/.github/hooks/pre-commit b/projects/clr/.github/hooks/pre-commit new file mode 100644 index 0000000000..f42d5a3174 --- /dev/null +++ b/projects/clr/.github/hooks/pre-commit @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exec "$(git rev-parse --show-toplevel)/.github/hooks/clang-format-check.sh" diff --git a/projects/clr/.github/workflows/clang-format.yml b/projects/clr/.github/workflows/clang-format.yml new file mode 100644 index 0000000000..b17babaa2f --- /dev/null +++ b/projects/clr/.github/workflows/clang-format.yml @@ -0,0 +1,22 @@ +name: Clang format check + +on: + push: + +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install clang-format + run: | + sudo apt update && sudo apt install -y clang-format + + - name: Run clang-format-check + id: clang-format + run: | + chmod +x .github/hooks/clang-format-check.sh + ./.github/hooks/clang-format-check.sh --range "${{ github.event.before }}..${{ github.sha }}" diff --git a/projects/clr/opencl/amdocl/cl_d3d9.cpp b/projects/clr/opencl/amdocl/cl_d3d9.cpp index 90e3241892..a0e9349c3b 100644 --- a/projects/clr/opencl/amdocl/cl_d3d9.cpp +++ b/projects/clr/opencl/amdocl/cl_d3d9.cpp @@ -28,6 +28,7 @@ #include #include + RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR, (cl_platform_id platform, cl_uint num_media_adapters, cl_dx9_media_adapter_type_khr* media_adapters_type, void* media_adapters, @@ -182,8 +183,7 @@ RUNTIME_ENTRY_RET(cl_mem, clCreateFromDX9MediaSurfaceKHR, D3DSURFACE_DESC Desc; pD3D9Resource->GetDesc(&Desc); - if ((Desc.Format != D3DFMT_NV_12) && - (Desc.Format != D3DFMT_P010) && + if ((Desc.Format != D3DFMT_NV_12) && (Desc.Format != D3DFMT_P010) && (Desc.Format != D3DFMT_YV_12) && (plane != 0)) { *not_null(errcode_ret) = CL_INVALID_VALUE; LogWarning("The plane has to be Zero if the surface format is non-planar !"); @@ -232,15 +232,16 @@ RUNTIME_EXIT // clCreateImage2DFromD3D9ResourceAMD // cl_mem amd::clCreateImage2DFromD3D9ResourceAMD(amd::Context& amdContext, cl_mem_flags flags, - cl_dx9_media_adapter_type_khr adapter_type, - cl_dx9_surface_info_khr* surface_info, cl_uint plane, - int* errcode_ret) { + cl_dx9_media_adapter_type_khr adapter_type, + cl_dx9_surface_info_khr* surface_info, cl_uint plane, + int* errcode_ret) { cl_dx9_surface_info_khr* cl_surf_info = reinterpret_cast(surface_info); IDirect3DSurface9* pD3D9Resource = cl_surf_info->resource; HANDLE shared_handle = cl_surf_info->shared_handle; amd::D3D9Object obj; - cl_int errcode = amd::D3D9Object::initD3D9Object(amdContext, adapter_type, surface_info, plane, obj); + cl_int errcode = + amd::D3D9Object::initD3D9Object(amdContext, adapter_type, surface_info, plane, obj); if (CL_SUCCESS != errcode) { *not_null(errcode_ret) = errcode; return (cl_mem)0; @@ -293,5 +294,4 @@ void amd::SyncD3D9Objects(std::vector& memObjects) { } - #endif //_WIN32