From 49fa7fcc447f8b259ab279b91085f432ae5a192c Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Thu, 8 Dec 2022 02:07:19 +0900 Subject: [PATCH 01/21] upload contains "windows" in GH Actions --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 47914a3f2..c6e30aaf3 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -128,7 +128,7 @@ jobs: shell: bash - uses: actions/upload-artifact@v3 - if: matrix.name == 'windows-msvc' + if: contains(matrix.name, 'windows') with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin From e8393116d4f15af1f65f5ffa6b43cda21a88185f Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Thu, 8 Dec 2022 02:09:09 +0900 Subject: [PATCH 02/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index c6e30aaf3..aff93488b 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -2,9 +2,7 @@ name: C/C++ CI on: push: - branches: [ master ] pull_request: - branches: [ master ] permissions: contents: read # to fetch code (actions/checkout) From b0515a0dd06b9cd5d72762f66e00b558628f3a35 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:50:48 +0900 Subject: [PATCH 03/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index aff93488b..7653f6e17 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -130,3 +130,12 @@ jobs: with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin + + - uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest" + prerelease: true + title: "AutoRelease" + files: | + build/bin/* From 8b73b8562844d51a7cfedb10bbb0ba18a42a6625 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Fri, 9 Dec 2022 01:34:19 +0900 Subject: [PATCH 04/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 7653f6e17..a5f4fb6bd 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -134,7 +134,7 @@ jobs: - uses: marvinpinto/action-automatic-releases@latest with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest" + automatic_release_tag: "master" prerelease: true title: "AutoRelease" files: | From a09a4d05187297e1782d3508adb1d3fa2d0d0322 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Fri, 9 Dec 2022 01:49:22 +0900 Subject: [PATCH 05/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index a5f4fb6bd..d5a5c147a 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -5,7 +5,7 @@ on: pull_request: permissions: - contents: read # to fetch code (actions/checkout) + contents: write-all # to fetch code (actions/checkout),and release jobs: job: From 09375a386a2abfae4e990308daeadd6c0c0e48ba Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Fri, 9 Dec 2022 10:28:32 +0900 Subject: [PATCH 06/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index d5a5c147a..c4825d803 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -5,7 +5,7 @@ on: pull_request: permissions: - contents: write-all # to fetch code (actions/checkout),and release + contents: write # to fetch code (actions/checkout),and release jobs: job: From b9cf35ea3adff3bf55565ac07a006025b11a8da2 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Fri, 9 Dec 2022 16:20:49 +0900 Subject: [PATCH 07/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index c4825d803..9c2146063 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -132,6 +132,7 @@ jobs: path: build/bin - uses: marvinpinto/action-automatic-releases@latest + if: contains(matrix.name, 'windows') with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "master" From cf3be00fd384ea9597e833ae7a49cf3d49dbdec3 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Fri, 9 Dec 2022 17:42:45 +0900 Subject: [PATCH 08/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9c2146063..8f2ba442d 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -132,7 +132,7 @@ jobs: path: build/bin - uses: marvinpinto/action-automatic-releases@latest - if: contains(matrix.name, 'windows') + if: contains(matrix.name, 'windows-latest-cl') with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "master" From fde8bf1071ff0cb81c2aec23403dba9746b05046 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Sat, 10 Dec 2022 17:37:49 +0900 Subject: [PATCH 09/21] =?UTF-8?q?build=E3=81=99=E3=82=8B=E6=96=B9=E3=81=AB?= =?UTF-8?q?=E3=81=A4=E3=81=84=E3=81=A6windows-msvc=E3=81=AE=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6=E3=81=84=E3=82=8B=E6=96=B9=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit この二つ、何の違いがあるかいまいち理解してない… clでビルドするかhunterでビルドするかの違い? --- .github/workflows/ccpp.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 8f2ba442d..79b52b544 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -2,7 +2,9 @@ name: C/C++ CI on: push: + branches: [master] pull_request: + branches: [master] permissions: contents: write # to fetch code (actions/checkout),and release @@ -97,12 +99,12 @@ jobs: - name: Set Windows specific CMake arguments if: contains(matrix.name, 'windows') id: windows_extra_cmake_args - run: echo "::set-output name=args::-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1" + run: echo "args=-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1" >> $GITHUB_OUTPUT - name: Set Hunter specific CMake arguments if: contains(matrix.name, 'hunter') id: hunter_extra_cmake_args - run: echo "::set-output name=args::-DBUILD_SHARED_LIBS=OFF -DASSIMP_HUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/polly/${{ matrix.toolchain }}.cmake" + run: echo "args=-DBUILD_SHARED_LIBS=OFF -DASSIMP_HUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/polly/${{ matrix.toolchain }}.cmake" >> $GITHUB_OUTPUT - name: configure and build uses: lukka/run-cmake@v3 @@ -119,20 +121,20 @@ jobs: - name: Exclude certain tests in Hunter specific builds if: contains(matrix.name, 'hunter') id: hunter_extra_test_args - run: echo "::set-output name=args::--gtest_filter=-utOpenGEXImportExport.Importissue1340_EmptyCameraObject:utColladaZaeImportExport.importBlenFromFileTest" + run: echo "args=--gtest_filter=-utOpenGEXImportExport.Importissue1340_EmptyCameraObject:utColladaZaeImportExport.importBlenFromFileTest" >> $GITHUB_OUTPUT - name: test run: cd build/bin && ./unit ${{ steps.hunter_extra_test_args.outputs.args }} shell: bash - uses: actions/upload-artifact@v3 - if: contains(matrix.name, 'windows') + if: contains(matrix.name, 'windows-msvc') with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin - uses: marvinpinto/action-automatic-releases@latest - if: contains(matrix.name, 'windows-latest-cl') + if: contains(matrix.name, 'windows-msvc') with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "master" From bbfc9f4658f3703783d398bc3325502f7e97532b Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Mon, 12 Dec 2022 10:34:45 +0900 Subject: [PATCH 10/21] =?UTF-8?q?upload/release=E5=AF=BE=E8=B1=A1=E3=81=AE?= =?UTF-8?q?artifact=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 追加当時のIssueを参考に修正(当時はHunterなかったっぽい) https://github.com/assimp/assimp/commit/a9a0c3093226a23eb7558539bc6ebe5bcb98442b --- .github/workflows/ccpp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 79b52b544..a9e569b46 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -128,13 +128,13 @@ jobs: shell: bash - uses: actions/upload-artifact@v3 - if: contains(matrix.name, 'windows-msvc') + if: contains(matrix.name, 'latest') with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin - uses: marvinpinto/action-automatic-releases@latest - if: contains(matrix.name, 'windows-msvc') + if: contains(matrix.name, 'windows-latest') with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "master" From 53f0d5dcbd880b7025f204e2e12ef30e7526cbda Mon Sep 17 00:00:00 2001 From: kazu0617 Date: Mon, 12 Dec 2022 10:55:13 +0900 Subject: [PATCH 11/21] fix ccpp.yml -- fix matrix.name check for artifact --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 47914a3f2..3ba39f617 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -128,7 +128,7 @@ jobs: shell: bash - uses: actions/upload-artifact@v3 - if: matrix.name == 'windows-msvc' + if: contains(matrix.name,'windows-latest-cl') with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin From 4b523e99c4258d62fc55d65601eb10044273251f Mon Sep 17 00:00:00 2001 From: kazu0617 Date: Mon, 12 Dec 2022 12:10:32 +0900 Subject: [PATCH 12/21] fix ccpp.yml - build both hunter or not --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 3ba39f617..b7ac3b97e 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -128,7 +128,7 @@ jobs: shell: bash - uses: actions/upload-artifact@v3 - if: contains(matrix.name,'windows-latest-cl') + if: contains(matrix.name,'windows') with: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin From f77db867b568ef64c12791eb01fe1ce5b16c5f5c Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Mon, 12 Dec 2022 12:43:34 +0900 Subject: [PATCH 13/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 88 ++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index a9e569b46..13725e1ef 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -2,15 +2,15 @@ name: C/C++ CI on: push: - branches: [master] + branches: [ master ] pull_request: - branches: [master] + branches: [ master ] permissions: contents: write # to fetch code (actions/checkout),and release jobs: - job: + build: name: ${{ matrix.name }}-build-and-test runs-on: ${{ matrix.os }} strategy: @@ -133,12 +133,76 @@ jobs: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin - - uses: marvinpinto/action-automatic-releases@latest - if: contains(matrix.name, 'windows-latest') - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "master" - prerelease: true - title: "AutoRelease" - files: | - build/bin/* + create-release: + needs: [build] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}' + with: + tag_name: '${{github.ref}}' + release_name: 'Release ${{github.ref}}' + draft: false + prerelease: true + - run: | + echo '${{steps.create-release.outputs.upload_url}}' > release_upload_url.txt + - uses: actions/upload-artifact@v1 + with: + name: create-release + path: release_upload_url.txt + + upload-release: + strategy: + matrix: + name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter, windows-msvc-hunter] + # For Windows msvc, for Linux and macOS let's use the clang compiler, use gcc for Linux. + include: + - name: windows-latest-cl.exe + os: windows-latest + cxx: cl.exe + cc: cl.exe + - name: ubuntu-latest-clang++ + os: ubuntu-latest + cxx: clang++ + cc: clang + - name: macos-latest-clang++ + os: macos-latest + cxx: clang++ + cc: clang + - name: ubuntu-latest-g++ + os: ubuntu-latest + cxx: g++ + cc: gcc + - name: ubuntu-gcc-hunter + os: ubuntu-latest + toolchain: ninja-gcc-cxx17-fpic + - name: macos-clang-hunter + os: macos-latest + toolchain: ninja-clang-cxx17-fpic + - name: windows-msvc-hunter + os: windows-latest + toolchain: ninja-vs-win64-cxx17 + + needs: [create-release] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: softprops/action-gh-release@v1 + with: + name: create-release + - id: upload-url + run: | + echo "url=$(cat create-release/release_upload_url.txt)" >> $GITHUB_OUTPUT + - uses: actions/download-artifact@v1 + with: + name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' + - uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}' + with: + files: | + *.zip + From 5925dcd0e251d08cc4ce3f195b06241e55268ef3 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Sat, 17 Dec 2022 15:08:25 +0900 Subject: [PATCH 14/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 13725e1ef..6b7e57c54 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -133,6 +133,16 @@ jobs: name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' path: build/bin + - uses: marvinpinto/action-automatic-releases@latest + if: contains(matrix.name, 'windows-latest') + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "master" + prerelease: true + title: "AutoRelease" + files: | + build/bin/* + create-release: needs: [build] runs-on: ubuntu-latest From dd313da24f49d371f4b3a275839c423a3055e380 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Sat, 17 Dec 2022 21:04:11 +0900 Subject: [PATCH 15/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 6b7e57c54..72f010c96 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -41,9 +41,9 @@ jobs: - name: macos-clang-hunter os: macos-latest toolchain: ninja-clang-cxx17-fpic - - name: windows-msvc-hunter - os: windows-latest - toolchain: ninja-vs-win64-cxx17 + #- name: windows-msvc-hunter + # os: windows-latest + # toolchain: ninja-vs-win64-cxx17 steps: - uses: actions/checkout@v3 @@ -134,7 +134,7 @@ jobs: path: build/bin - uses: marvinpinto/action-automatic-releases@latest - if: contains(matrix.name, 'windows-latest') + if: contains(matrix.name, 'windows-latest-cl.exe') with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "master" From 2ec097b862012fcb80097544fc6f8fd7a4c9f155 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Sat, 17 Dec 2022 21:06:36 +0900 Subject: [PATCH 16/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 72f010c96..ea7f05d9f 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter, windows-msvc-hunter] + name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter] # For Windows msvc, for Linux and macOS let's use the clang compiler, use gcc for Linux. include: - name: windows-latest-cl.exe From 2c87088079c3d7ad50eef8c8d03f0d7fc662c744 Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Sat, 17 Dec 2022 21:49:28 +0900 Subject: [PATCH 17/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index ea7f05d9f..2fb20def4 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter] + name: [ubuntu-latest-g++, macos-latest-clang++, windows-latest-cl.exe, ubuntu-latest-clang++, ubuntu-gcc-hunter, macos-clang-hunter, windows-msvc-hunter] # For Windows msvc, for Linux and macOS let's use the clang compiler, use gcc for Linux. include: - name: windows-latest-cl.exe @@ -41,9 +41,9 @@ jobs: - name: macos-clang-hunter os: macos-latest toolchain: ninja-clang-cxx17-fpic - #- name: windows-msvc-hunter - # os: windows-latest - # toolchain: ninja-vs-win64-cxx17 + - name: windows-msvc-hunter + os: windows-latest + toolchain: ninja-vs-win64-cxx17 steps: - uses: actions/checkout@v3 @@ -130,11 +130,11 @@ jobs: - uses: actions/upload-artifact@v3 if: contains(matrix.name, 'latest') with: - name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' + name: 'assimp-bins-${{ matrix.name }}' path: build/bin - uses: marvinpinto/action-automatic-releases@latest - if: contains(matrix.name, 'windows-latest-cl.exe') + if: contains(matrix.name, 'windows-msvc-hunter') with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "master" From a84bf34cbb235e5880c46422f8db2290f345fbbb Mon Sep 17 00:00:00 2001 From: Kazuki Y <6259214+kazu0617@users.noreply.github.com> Date: Thu, 29 Dec 2022 23:43:07 +0900 Subject: [PATCH 18/21] Update ccpp.yml --- .github/workflows/ccpp.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index b7ac3b97e..e8023a8f9 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -99,12 +99,12 @@ jobs: - name: Set Windows specific CMake arguments if: contains(matrix.name, 'windows') id: windows_extra_cmake_args - run: echo "::set-output name=args::-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1" + run: echo "args=-DASSIMP_BUILD_ASSIMP_TOOLS=1 -DASSIMP_BUILD_ASSIMP_VIEW=1" >> $GITHUB_OUTPUT - name: Set Hunter specific CMake arguments if: contains(matrix.name, 'hunter') id: hunter_extra_cmake_args - run: echo "::set-output name=args::-DBUILD_SHARED_LIBS=OFF -DASSIMP_HUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/polly/${{ matrix.toolchain }}.cmake" + run: echo "args=-DBUILD_SHARED_LIBS=OFF -DASSIMP_HUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/polly/${{ matrix.toolchain }}.cmake" >> $GITHUB_OUTPUT - name: configure and build uses: lukka/run-cmake@v3 @@ -121,7 +121,7 @@ jobs: - name: Exclude certain tests in Hunter specific builds if: contains(matrix.name, 'hunter') id: hunter_extra_test_args - run: echo "::set-output name=args::--gtest_filter=-utOpenGEXImportExport.Importissue1340_EmptyCameraObject:utColladaZaeImportExport.importBlenFromFileTest" + run: echo "args=--gtest_filter=-utOpenGEXImportExport.Importissue1340_EmptyCameraObject:utColladaZaeImportExport.importBlenFromFileTest" >> $GITHUB_OUTPUT - name: test run: cd build/bin && ./unit ${{ steps.hunter_extra_test_args.outputs.args }} @@ -130,5 +130,5 @@ jobs: - uses: actions/upload-artifact@v3 if: contains(matrix.name,'windows') with: - name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' - path: build/bin + name: 'assimp-bins-${{ matrix.name }}' + path: build/bin/assimp*.exe From 824db16a689d191bf20cafb94e29d9e8feeee66b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 7 Oct 2023 14:17:39 +0200 Subject: [PATCH 19/21] Fix verbose string + refactorings --- code/PostProcessing/ImproveCacheLocality.cpp | 215 ++++++++++--------- code/PostProcessing/ImproveCacheLocality.h | 3 +- include/assimp/aabb.h | 9 +- include/assimp/anim.h | 1 - 4 files changed, 121 insertions(+), 107 deletions(-) diff --git a/code/PostProcessing/ImproveCacheLocality.cpp b/code/PostProcessing/ImproveCacheLocality.cpp index 9336d6b17..7f28d2332 100644 --- a/code/PostProcessing/ImproveCacheLocality.cpp +++ b/code/PostProcessing/ImproveCacheLocality.cpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2023, assimp team All rights reserved. @@ -59,31 +57,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() -: mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) { +ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() : + mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) { // empty } // ------------------------------------------------------------------------------------------------ // Returns whether the processing step is present in the given flag field. -bool ImproveCacheLocalityProcess::IsActive( unsigned int pFlags) const { +bool ImproveCacheLocalityProcess::IsActive(unsigned int pFlags) const { return (pFlags & aiProcess_ImproveCacheLocality) != 0; } // ------------------------------------------------------------------------------------------------ // Setup configuration -void ImproveCacheLocalityProcess::SetupProperties(const Importer* pImp) { +void ImproveCacheLocalityProcess::SetupProperties(const Importer *pImp) { // AI_CONFIG_PP_ICL_PTCACHE_SIZE controls the target cache size for the optimizer - mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE,PP_ICL_PTCACHE_SIZE); + mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE, PP_ICL_PTCACHE_SIZE); } // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. -void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { +void ImproveCacheLocalityProcess::Execute(aiScene *pScene) { if (!pScene->mNumMeshes) { ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess skipped; there are no meshes"); return; @@ -93,11 +91,11 @@ void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { float out = 0.f; unsigned int numf = 0, numm = 0; - for( unsigned int a = 0; a < pScene->mNumMeshes; ++a ){ - const float res = ProcessMesh( pScene->mMeshes[a],a); + for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { + const float res = ProcessMesh(pScene->mMeshes[a], a); if (res) { numf += pScene->mMeshes[a]->mNumFaces; - out += res; + out += res; ++numm; } } @@ -109,9 +107,54 @@ void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { } } +// ------------------------------------------------------------------------------------------------ +static ai_real calculateInputACMR(aiMesh *pMesh, const aiFace *const pcEnd, + unsigned int configCacheDepth, unsigned int meshNum) { + ai_real fACMR = 0.0f; + unsigned int *piFIFOStack = new unsigned int[configCacheDepth]; + memset(piFIFOStack, 0xff, configCacheDepth * sizeof(unsigned int)); + unsigned int *piCur = piFIFOStack; + const unsigned int *const piCurEnd = piFIFOStack + configCacheDepth; + + // count the number of cache misses + unsigned int iCacheMisses = 0; + for (const aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) { + for (unsigned int qq = 0; qq < 3; ++qq) { + bool bInCache = false; + for (unsigned int *pp = piFIFOStack; pp < piCurEnd; ++pp) { + if (*pp == pcFace->mIndices[qq]) { + // the vertex is in cache + bInCache = true; + break; + } + } + if (!bInCache) { + ++iCacheMisses; + if (piCurEnd == piCur) { + piCur = piFIFOStack; + } + *piCur++ = pcFace->mIndices[qq]; + } + } + } + delete[] piFIFOStack; + fACMR = (ai_real)iCacheMisses / pMesh->mNumFaces; + if (3.0 == fACMR) { + char szBuff[128]; // should be sufficiently large in every case + + // the JoinIdenticalVertices process has not been executed on this + // mesh, otherwise this value would normally be at least minimally + // smaller than 3.0 ... + ai_snprintf(szBuff, 128, "Mesh %u: Not suitable for vcache optimization", meshNum); + ASSIMP_LOG_WARN(szBuff); + return static_cast(0.f); + } + return fACMR; +} + // ------------------------------------------------------------------------------------------------ // Improves the cache coherency of a specific mesh -ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshNum) { +ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshNum) { // TODO: rewrite this to use std::vector or boost::shared_array ai_assert(nullptr != pMesh); @@ -126,91 +169,57 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me return static_cast(0.f); } - if(pMesh->mNumVertices <= mConfigCacheDepth) { + if (pMesh->mNumVertices <= mConfigCacheDepth) { return static_cast(0.f); } ai_real fACMR = 3.f; - const aiFace* const pcEnd = pMesh->mFaces+pMesh->mNumFaces; + const aiFace *const pcEnd = pMesh->mFaces + pMesh->mNumFaces; // Input ACMR is for logging purposes only - if (!DefaultLogger::isNullLogger()) { - - unsigned int* piFIFOStack = new unsigned int[mConfigCacheDepth]; - memset(piFIFOStack,0xff,mConfigCacheDepth*sizeof(unsigned int)); - unsigned int* piCur = piFIFOStack; - const unsigned int* const piCurEnd = piFIFOStack + mConfigCacheDepth; - - // count the number of cache misses - unsigned int iCacheMisses = 0; - for (const aiFace* pcFace = pMesh->mFaces;pcFace != pcEnd;++pcFace) { - for (unsigned int qq = 0; qq < 3;++qq) { - bool bInCache = false; - for (unsigned int* pp = piFIFOStack;pp < piCurEnd;++pp) { - if (*pp == pcFace->mIndices[qq]) { - // the vertex is in cache - bInCache = true; - break; - } - } - if (!bInCache) { - ++iCacheMisses; - if (piCurEnd == piCur) { - piCur = piFIFOStack; - } - *piCur++ = pcFace->mIndices[qq]; - } - } - } - delete[] piFIFOStack; - fACMR = (ai_real) iCacheMisses / pMesh->mNumFaces; - if (3.0 == fACMR) { - char szBuff[128]; // should be sufficiently large in every case - - // the JoinIdenticalVertices process has not been executed on this - // mesh, otherwise this value would normally be at least minimally - // smaller than 3.0 ... - ai_snprintf(szBuff,128,"Mesh %u: Not suitable for vcache optimization",meshNum); - ASSIMP_LOG_WARN(szBuff); - return static_cast(0.f); - } + if (!DefaultLogger::isNullLogger()) { + fACMR = calculateInputACMR(pMesh, pcEnd, mConfigCacheDepth, meshNum); } // first we need to build a vertex-triangle adjacency list - VertexTriangleAdjacency adj(pMesh->mFaces,pMesh->mNumFaces, pMesh->mNumVertices,true); + VertexTriangleAdjacency adj(pMesh->mFaces, pMesh->mNumFaces, pMesh->mNumVertices, true); // build a list to store per-vertex caching time stamps - unsigned int* const piCachingStamps = new unsigned int[pMesh->mNumVertices]; - memset(piCachingStamps,0x0,pMesh->mNumVertices*sizeof(unsigned int)); + std::vector piCachingStamps; + piCachingStamps.resize(pMesh->mNumVertices); + memset(&piCachingStamps[0], 0x0, pMesh->mNumVertices * sizeof(unsigned int)); // allocate an empty output index buffer. We store the output indices in one large array. // Since the number of triangles won't change the input faces can be reused. This is how // we save thousands of redundant mini allocations for aiFace::mIndices - const unsigned int iIdxCnt = pMesh->mNumFaces*3; - unsigned int* const piIBOutput = new unsigned int[iIdxCnt]; - unsigned int* piCSIter = piIBOutput; + const unsigned int iIdxCnt = pMesh->mNumFaces * 3; + std::vector piIBOutput; + piIBOutput.resize(iIdxCnt); + std::vector::iterator piCSIter = piIBOutput.begin(); // allocate the flag array to hold the information // whether a face has already been emitted or not - std::vector abEmitted(pMesh->mNumFaces,false); + std::vector abEmitted(pMesh->mNumFaces, false); // dead-end vertex index stack - std::stack > sDeadEndVStack; + std::stack> sDeadEndVStack; // create a copy of the piNumTriPtr buffer - unsigned int* const piNumTriPtr = adj.mLiveTriangles; + unsigned int *const piNumTriPtr = adj.mLiveTriangles; const std::vector piNumTriPtrNoModify(piNumTriPtr, piNumTriPtr + pMesh->mNumVertices); // get the largest number of referenced triangles and allocate the "candidate buffer" - unsigned int iMaxRefTris = 0; { - const unsigned int* piCur = adj.mLiveTriangles; - const unsigned int* const piCurEnd = adj.mLiveTriangles+pMesh->mNumVertices; - for (;piCur != piCurEnd;++piCur) { - iMaxRefTris = std::max(iMaxRefTris,*piCur); + unsigned int iMaxRefTris = 0; + { + const unsigned int *piCur = adj.mLiveTriangles; + const unsigned int *const piCurEnd = adj.mLiveTriangles + pMesh->mNumVertices; + for (; piCur != piCurEnd; ++piCur) { + iMaxRefTris = std::max(iMaxRefTris, *piCur); } } ai_assert(iMaxRefTris > 0); - unsigned int* piCandidates = new unsigned int[iMaxRefTris*3]; + std::vector piCandidates; + piCandidates.resize(iMaxRefTris * 3); unsigned int iCacheMisses = 0; // ................................................................................... @@ -245,22 +254,22 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me int ivdx = 0; int ics = 1; - int iStampCnt = mConfigCacheDepth+1; - while (ivdx >= 0) { + int iStampCnt = mConfigCacheDepth + 1; + while (ivdx >= 0) { unsigned int icnt = piNumTriPtrNoModify[ivdx]; - unsigned int* piList = adj.GetAdjacentTriangles(ivdx); - unsigned int* piCurCandidate = piCandidates; + unsigned int *piList = adj.GetAdjacentTriangles(ivdx); + std::vector::iterator piCurCandidate = piCandidates.begin(); // get all triangles in the neighborhood - for (unsigned int tri = 0; tri < icnt;++tri) { + for (unsigned int tri = 0; tri < icnt; ++tri) { // if they have not yet been emitted, add them to the output IB const unsigned int fidx = *piList++; - if (!abEmitted[fidx]) { + if (!abEmitted[fidx]) { // so iterate through all vertices of the current triangle - const aiFace* pcFace = &pMesh->mFaces[ fidx ]; + const aiFace *pcFace = &pMesh->mFaces[fidx]; unsigned nind = pcFace->mNumIndices; for (unsigned ind = 0; ind < nind; ind++) { unsigned dp = pcFace->mIndices[ind]; @@ -281,7 +290,7 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me *piCSIter++ = dp; // if the vertex is not yet in cache, set its cache count - if (iStampCnt-piCachingStamps[dp] > mConfigCacheDepth) { + if (iStampCnt - piCachingStamps[dp] > mConfigCacheDepth) { piCachingStamps[dp] = iStampCnt++; ++iCacheMisses; } @@ -297,16 +306,16 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me // get next fanning vertex ivdx = -1; int max_priority = -1; - for (unsigned int* piCur = piCandidates;piCur != piCurCandidate;++piCur) { + for (std::vector::iterator piCur = piCandidates.begin(); piCur != piCurCandidate; ++piCur) { const unsigned int dp = *piCur; // must have live triangles - if (piNumTriPtr[dp] > 0) { + if (piNumTriPtr[dp] > 0) { int priority = 0; // will the vertex be in cache, even after fanning occurs? unsigned int tmp; - if ((tmp = iStampCnt-piCachingStamps[dp]) + 2*piNumTriPtr[dp] <= mConfigCacheDepth) { + if ((tmp = iStampCnt - piCachingStamps[dp]) + 2 * piNumTriPtr[dp] <= mConfigCacheDepth) { priority = tmp; } @@ -324,7 +333,7 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me while (!sDeadEndVStack.empty()) { unsigned int iCachedIdx = sDeadEndVStack.top(); sDeadEndVStack.pop(); - if (piNumTriPtr[ iCachedIdx ] > 0) { + if (piNumTriPtr[iCachedIdx] > 0) { ivdx = iCachedIdx; break; } @@ -333,9 +342,9 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me if (-1 == ivdx) { // well, there isn't such a vertex. Simply get the next vertex in input order and // hope it is not too bad ... - while (ics < (int)pMesh->mNumVertices) { + while (ics < (int)pMesh->mNumVertices) { ++ics; - if (piNumTriPtr[ics] > 0) { + if (piNumTriPtr[ics] > 0) { ivdx = ics; break; } @@ -345,29 +354,29 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me } ai_real fACMR2 = 0.0f; if (!DefaultLogger::isNullLogger()) { - fACMR2 = (float)iCacheMisses / pMesh->mNumFaces; - + fACMR2 = static_cast(iCacheMisses / pMesh->mNumFaces); + const ai_real averageACMR = ((fACMR - fACMR2) / fACMR) * 100.f; // very intense verbose logging ... prepare for much text if there are many meshes - if ( DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) { - ASSIMP_LOG_VERBOSE_DEBUG("Mesh %u | ACMR in: ", meshNum, " out: ", fACMR, " | ~", fACMR2, ((fACMR - fACMR2) / fACMR) * 100.f); + if (DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) { + ASSIMP_LOG_VERBOSE_DEBUG("Mesh ", meshNum, "| ACMR in: ", fACMR, " out: ", fACMR2, " | average ACMR ", averageACMR); } - fACMR2 *= pMesh->mNumFaces; } - // sort the output index buffer back to the input array - piCSIter = piIBOutput; - for (aiFace* pcFace = pMesh->mFaces; pcFace != pcEnd;++pcFace) { - unsigned nind = pcFace->mNumIndices; - unsigned * ind = pcFace->mIndices; - if (nind > 0) ind[0] = *piCSIter++; - if (nind > 1) ind[1] = *piCSIter++; - if (nind > 2) ind[2] = *piCSIter++; - } - // delete temporary storage - delete[] piCachingStamps; - delete[] piIBOutput; - delete[] piCandidates; + // sort the output index buffer back to the input array + piCSIter = piIBOutput.begin(); + for (aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) { + unsigned nind = pcFace->mNumIndices; + unsigned *ind = pcFace->mIndices; + if (nind > 0) + ind[0] = *piCSIter++; + if (nind > 1) + ind[1] = *piCSIter++; + if (nind > 2) + ind[2] = *piCSIter++; + } return fACMR2; } + +} // namespace Assimp diff --git a/code/PostProcessing/ImproveCacheLocality.h b/code/PostProcessing/ImproveCacheLocality.h index 6f4d55719..f8f8263d2 100644 --- a/code/PostProcessing/ImproveCacheLocality.h +++ b/code/PostProcessing/ImproveCacheLocality.h @@ -2,8 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - +Copyright (c) 2006-2023, assimp team All rights reserved. diff --git a/include/assimp/aabb.h b/include/assimp/aabb.h index b38aa1697..52953b773 100644 --- a/include/assimp/aabb.h +++ b/include/assimp/aabb.h @@ -51,10 +51,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --------------------------------------------------------------------------- /** - * An axis-aligned bounding box. + * @brief An axis-aligned bounding box. */ struct aiAABB { + /** + * @brief The minimum edge position of the axis-aligned bounding-box. + */ C_STRUCT aiVector3D mMin; + + /** + * @brief The maximum edge position of the axis-aligned bounding-box. + */ C_STRUCT aiVector3D mMax; #ifdef __cplusplus diff --git a/include/assimp/anim.h b/include/assimp/anim.h index 49f0d5014..6c4159c47 100644 --- a/include/assimp/anim.h +++ b/include/assimp/anim.h @@ -78,7 +78,6 @@ struct aiVectorKey { } /// @brief Construction from a given time and key value. - aiVectorKey(double time, const aiVector3D &value) : mTime(time), mValue(value) { // empty From 3ce8af18e21372c6101da06160eccc6a6a6b1288 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 7 Oct 2023 14:20:55 +0200 Subject: [PATCH 20/21] Revert "Fix verbose string + refactorings" This reverts commit 824db16a689d191bf20cafb94e29d9e8feeee66b. --- code/PostProcessing/ImproveCacheLocality.cpp | 211 +++++++++---------- code/PostProcessing/ImproveCacheLocality.h | 3 +- include/assimp/aabb.h | 9 +- include/assimp/anim.h | 1 + 4 files changed, 105 insertions(+), 119 deletions(-) diff --git a/code/PostProcessing/ImproveCacheLocality.cpp b/code/PostProcessing/ImproveCacheLocality.cpp index 7f28d2332..9336d6b17 100644 --- a/code/PostProcessing/ImproveCacheLocality.cpp +++ b/code/PostProcessing/ImproveCacheLocality.cpp @@ -3,7 +3,9 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2022, assimp team + + All rights reserved. @@ -57,31 +59,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -namespace Assimp { +using namespace Assimp; // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() : - mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) { +ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() +: mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) { // empty } // ------------------------------------------------------------------------------------------------ // Returns whether the processing step is present in the given flag field. -bool ImproveCacheLocalityProcess::IsActive(unsigned int pFlags) const { +bool ImproveCacheLocalityProcess::IsActive( unsigned int pFlags) const { return (pFlags & aiProcess_ImproveCacheLocality) != 0; } // ------------------------------------------------------------------------------------------------ // Setup configuration -void ImproveCacheLocalityProcess::SetupProperties(const Importer *pImp) { +void ImproveCacheLocalityProcess::SetupProperties(const Importer* pImp) { // AI_CONFIG_PP_ICL_PTCACHE_SIZE controls the target cache size for the optimizer - mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE, PP_ICL_PTCACHE_SIZE); + mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE,PP_ICL_PTCACHE_SIZE); } // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. -void ImproveCacheLocalityProcess::Execute(aiScene *pScene) { +void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { if (!pScene->mNumMeshes) { ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess skipped; there are no meshes"); return; @@ -91,11 +93,11 @@ void ImproveCacheLocalityProcess::Execute(aiScene *pScene) { float out = 0.f; unsigned int numf = 0, numm = 0; - for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { - const float res = ProcessMesh(pScene->mMeshes[a], a); + for( unsigned int a = 0; a < pScene->mNumMeshes; ++a ){ + const float res = ProcessMesh( pScene->mMeshes[a],a); if (res) { numf += pScene->mMeshes[a]->mNumFaces; - out += res; + out += res; ++numm; } } @@ -107,54 +109,9 @@ void ImproveCacheLocalityProcess::Execute(aiScene *pScene) { } } -// ------------------------------------------------------------------------------------------------ -static ai_real calculateInputACMR(aiMesh *pMesh, const aiFace *const pcEnd, - unsigned int configCacheDepth, unsigned int meshNum) { - ai_real fACMR = 0.0f; - unsigned int *piFIFOStack = new unsigned int[configCacheDepth]; - memset(piFIFOStack, 0xff, configCacheDepth * sizeof(unsigned int)); - unsigned int *piCur = piFIFOStack; - const unsigned int *const piCurEnd = piFIFOStack + configCacheDepth; - - // count the number of cache misses - unsigned int iCacheMisses = 0; - for (const aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) { - for (unsigned int qq = 0; qq < 3; ++qq) { - bool bInCache = false; - for (unsigned int *pp = piFIFOStack; pp < piCurEnd; ++pp) { - if (*pp == pcFace->mIndices[qq]) { - // the vertex is in cache - bInCache = true; - break; - } - } - if (!bInCache) { - ++iCacheMisses; - if (piCurEnd == piCur) { - piCur = piFIFOStack; - } - *piCur++ = pcFace->mIndices[qq]; - } - } - } - delete[] piFIFOStack; - fACMR = (ai_real)iCacheMisses / pMesh->mNumFaces; - if (3.0 == fACMR) { - char szBuff[128]; // should be sufficiently large in every case - - // the JoinIdenticalVertices process has not been executed on this - // mesh, otherwise this value would normally be at least minimally - // smaller than 3.0 ... - ai_snprintf(szBuff, 128, "Mesh %u: Not suitable for vcache optimization", meshNum); - ASSIMP_LOG_WARN(szBuff); - return static_cast(0.f); - } - return fACMR; -} - // ------------------------------------------------------------------------------------------------ // Improves the cache coherency of a specific mesh -ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshNum) { +ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshNum) { // TODO: rewrite this to use std::vector or boost::shared_array ai_assert(nullptr != pMesh); @@ -169,57 +126,91 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes return static_cast(0.f); } - if (pMesh->mNumVertices <= mConfigCacheDepth) { + if(pMesh->mNumVertices <= mConfigCacheDepth) { return static_cast(0.f); } ai_real fACMR = 3.f; - const aiFace *const pcEnd = pMesh->mFaces + pMesh->mNumFaces; + const aiFace* const pcEnd = pMesh->mFaces+pMesh->mNumFaces; // Input ACMR is for logging purposes only - if (!DefaultLogger::isNullLogger()) { - fACMR = calculateInputACMR(pMesh, pcEnd, mConfigCacheDepth, meshNum); + if (!DefaultLogger::isNullLogger()) { + + unsigned int* piFIFOStack = new unsigned int[mConfigCacheDepth]; + memset(piFIFOStack,0xff,mConfigCacheDepth*sizeof(unsigned int)); + unsigned int* piCur = piFIFOStack; + const unsigned int* const piCurEnd = piFIFOStack + mConfigCacheDepth; + + // count the number of cache misses + unsigned int iCacheMisses = 0; + for (const aiFace* pcFace = pMesh->mFaces;pcFace != pcEnd;++pcFace) { + for (unsigned int qq = 0; qq < 3;++qq) { + bool bInCache = false; + for (unsigned int* pp = piFIFOStack;pp < piCurEnd;++pp) { + if (*pp == pcFace->mIndices[qq]) { + // the vertex is in cache + bInCache = true; + break; + } + } + if (!bInCache) { + ++iCacheMisses; + if (piCurEnd == piCur) { + piCur = piFIFOStack; + } + *piCur++ = pcFace->mIndices[qq]; + } + } + } + delete[] piFIFOStack; + fACMR = (ai_real) iCacheMisses / pMesh->mNumFaces; + if (3.0 == fACMR) { + char szBuff[128]; // should be sufficiently large in every case + + // the JoinIdenticalVertices process has not been executed on this + // mesh, otherwise this value would normally be at least minimally + // smaller than 3.0 ... + ai_snprintf(szBuff,128,"Mesh %u: Not suitable for vcache optimization",meshNum); + ASSIMP_LOG_WARN(szBuff); + return static_cast(0.f); + } } // first we need to build a vertex-triangle adjacency list - VertexTriangleAdjacency adj(pMesh->mFaces, pMesh->mNumFaces, pMesh->mNumVertices, true); + VertexTriangleAdjacency adj(pMesh->mFaces,pMesh->mNumFaces, pMesh->mNumVertices,true); // build a list to store per-vertex caching time stamps - std::vector piCachingStamps; - piCachingStamps.resize(pMesh->mNumVertices); - memset(&piCachingStamps[0], 0x0, pMesh->mNumVertices * sizeof(unsigned int)); + unsigned int* const piCachingStamps = new unsigned int[pMesh->mNumVertices]; + memset(piCachingStamps,0x0,pMesh->mNumVertices*sizeof(unsigned int)); // allocate an empty output index buffer. We store the output indices in one large array. // Since the number of triangles won't change the input faces can be reused. This is how // we save thousands of redundant mini allocations for aiFace::mIndices - const unsigned int iIdxCnt = pMesh->mNumFaces * 3; - std::vector piIBOutput; - piIBOutput.resize(iIdxCnt); - std::vector::iterator piCSIter = piIBOutput.begin(); + const unsigned int iIdxCnt = pMesh->mNumFaces*3; + unsigned int* const piIBOutput = new unsigned int[iIdxCnt]; + unsigned int* piCSIter = piIBOutput; // allocate the flag array to hold the information // whether a face has already been emitted or not - std::vector abEmitted(pMesh->mNumFaces, false); + std::vector abEmitted(pMesh->mNumFaces,false); // dead-end vertex index stack - std::stack> sDeadEndVStack; + std::stack > sDeadEndVStack; // create a copy of the piNumTriPtr buffer - unsigned int *const piNumTriPtr = adj.mLiveTriangles; + unsigned int* const piNumTriPtr = adj.mLiveTriangles; const std::vector piNumTriPtrNoModify(piNumTriPtr, piNumTriPtr + pMesh->mNumVertices); // get the largest number of referenced triangles and allocate the "candidate buffer" - unsigned int iMaxRefTris = 0; - { - const unsigned int *piCur = adj.mLiveTriangles; - const unsigned int *const piCurEnd = adj.mLiveTriangles + pMesh->mNumVertices; - for (; piCur != piCurEnd; ++piCur) { - iMaxRefTris = std::max(iMaxRefTris, *piCur); + unsigned int iMaxRefTris = 0; { + const unsigned int* piCur = adj.mLiveTriangles; + const unsigned int* const piCurEnd = adj.mLiveTriangles+pMesh->mNumVertices; + for (;piCur != piCurEnd;++piCur) { + iMaxRefTris = std::max(iMaxRefTris,*piCur); } } ai_assert(iMaxRefTris > 0); - std::vector piCandidates; - piCandidates.resize(iMaxRefTris * 3); + unsigned int* piCandidates = new unsigned int[iMaxRefTris*3]; unsigned int iCacheMisses = 0; // ................................................................................... @@ -254,22 +245,22 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes int ivdx = 0; int ics = 1; - int iStampCnt = mConfigCacheDepth + 1; - while (ivdx >= 0) { + int iStampCnt = mConfigCacheDepth+1; + while (ivdx >= 0) { unsigned int icnt = piNumTriPtrNoModify[ivdx]; - unsigned int *piList = adj.GetAdjacentTriangles(ivdx); - std::vector::iterator piCurCandidate = piCandidates.begin(); + unsigned int* piList = adj.GetAdjacentTriangles(ivdx); + unsigned int* piCurCandidate = piCandidates; // get all triangles in the neighborhood - for (unsigned int tri = 0; tri < icnt; ++tri) { + for (unsigned int tri = 0; tri < icnt;++tri) { // if they have not yet been emitted, add them to the output IB const unsigned int fidx = *piList++; - if (!abEmitted[fidx]) { + if (!abEmitted[fidx]) { // so iterate through all vertices of the current triangle - const aiFace *pcFace = &pMesh->mFaces[fidx]; + const aiFace* pcFace = &pMesh->mFaces[ fidx ]; unsigned nind = pcFace->mNumIndices; for (unsigned ind = 0; ind < nind; ind++) { unsigned dp = pcFace->mIndices[ind]; @@ -290,7 +281,7 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes *piCSIter++ = dp; // if the vertex is not yet in cache, set its cache count - if (iStampCnt - piCachingStamps[dp] > mConfigCacheDepth) { + if (iStampCnt-piCachingStamps[dp] > mConfigCacheDepth) { piCachingStamps[dp] = iStampCnt++; ++iCacheMisses; } @@ -306,16 +297,16 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes // get next fanning vertex ivdx = -1; int max_priority = -1; - for (std::vector::iterator piCur = piCandidates.begin(); piCur != piCurCandidate; ++piCur) { + for (unsigned int* piCur = piCandidates;piCur != piCurCandidate;++piCur) { const unsigned int dp = *piCur; // must have live triangles - if (piNumTriPtr[dp] > 0) { + if (piNumTriPtr[dp] > 0) { int priority = 0; // will the vertex be in cache, even after fanning occurs? unsigned int tmp; - if ((tmp = iStampCnt - piCachingStamps[dp]) + 2 * piNumTriPtr[dp] <= mConfigCacheDepth) { + if ((tmp = iStampCnt-piCachingStamps[dp]) + 2*piNumTriPtr[dp] <= mConfigCacheDepth) { priority = tmp; } @@ -333,7 +324,7 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes while (!sDeadEndVStack.empty()) { unsigned int iCachedIdx = sDeadEndVStack.top(); sDeadEndVStack.pop(); - if (piNumTriPtr[iCachedIdx] > 0) { + if (piNumTriPtr[ iCachedIdx ] > 0) { ivdx = iCachedIdx; break; } @@ -342,9 +333,9 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes if (-1 == ivdx) { // well, there isn't such a vertex. Simply get the next vertex in input order and // hope it is not too bad ... - while (ics < (int)pMesh->mNumVertices) { + while (ics < (int)pMesh->mNumVertices) { ++ics; - if (piNumTriPtr[ics] > 0) { + if (piNumTriPtr[ics] > 0) { ivdx = ics; break; } @@ -354,29 +345,29 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int mes } ai_real fACMR2 = 0.0f; if (!DefaultLogger::isNullLogger()) { - fACMR2 = static_cast(iCacheMisses / pMesh->mNumFaces); - const ai_real averageACMR = ((fACMR - fACMR2) / fACMR) * 100.f; + fACMR2 = (float)iCacheMisses / pMesh->mNumFaces; + // very intense verbose logging ... prepare for much text if there are many meshes - if (DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) { - ASSIMP_LOG_VERBOSE_DEBUG("Mesh ", meshNum, "| ACMR in: ", fACMR, " out: ", fACMR2, " | average ACMR ", averageACMR); + if ( DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) { + ASSIMP_LOG_VERBOSE_DEBUG("Mesh %u | ACMR in: ", meshNum, " out: ", fACMR, " | ~", fACMR2, ((fACMR - fACMR2) / fACMR) * 100.f); } + fACMR2 *= pMesh->mNumFaces; } - // sort the output index buffer back to the input array - piCSIter = piIBOutput.begin(); - for (aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) { + piCSIter = piIBOutput; + for (aiFace* pcFace = pMesh->mFaces; pcFace != pcEnd;++pcFace) { unsigned nind = pcFace->mNumIndices; - unsigned *ind = pcFace->mIndices; - if (nind > 0) - ind[0] = *piCSIter++; - if (nind > 1) - ind[1] = *piCSIter++; - if (nind > 2) - ind[2] = *piCSIter++; + unsigned * ind = pcFace->mIndices; + if (nind > 0) ind[0] = *piCSIter++; + if (nind > 1) ind[1] = *piCSIter++; + if (nind > 2) ind[2] = *piCSIter++; } + // delete temporary storage + delete[] piCachingStamps; + delete[] piIBOutput; + delete[] piCandidates; + return fACMR2; } - -} // namespace Assimp diff --git a/code/PostProcessing/ImproveCacheLocality.h b/code/PostProcessing/ImproveCacheLocality.h index f8f8263d2..6f4d55719 100644 --- a/code/PostProcessing/ImproveCacheLocality.h +++ b/code/PostProcessing/ImproveCacheLocality.h @@ -2,7 +2,8 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2023, assimp team +Copyright (c) 2006-2022, assimp team + All rights reserved. diff --git a/include/assimp/aabb.h b/include/assimp/aabb.h index 52953b773..b38aa1697 100644 --- a/include/assimp/aabb.h +++ b/include/assimp/aabb.h @@ -51,17 +51,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // --------------------------------------------------------------------------- /** - * @brief An axis-aligned bounding box. + * An axis-aligned bounding box. */ struct aiAABB { - /** - * @brief The minimum edge position of the axis-aligned bounding-box. - */ C_STRUCT aiVector3D mMin; - - /** - * @brief The maximum edge position of the axis-aligned bounding-box. - */ C_STRUCT aiVector3D mMax; #ifdef __cplusplus diff --git a/include/assimp/anim.h b/include/assimp/anim.h index 6c4159c47..49f0d5014 100644 --- a/include/assimp/anim.h +++ b/include/assimp/anim.h @@ -78,6 +78,7 @@ struct aiVectorKey { } /// @brief Construction from a given time and key value. + aiVectorKey(double time, const aiVector3D &value) : mTime(time), mValue(value) { // empty From 2998ad82a19f1a83137eb43f2dc0d88f302b00b7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 7 Oct 2023 14:21:59 +0200 Subject: [PATCH 21/21] Fix verbose string + refactorings --- code/PostProcessing/ImproveCacheLocality.cpp | 217 ++++++++++--------- 1 file changed, 113 insertions(+), 104 deletions(-) diff --git a/code/PostProcessing/ImproveCacheLocality.cpp b/code/PostProcessing/ImproveCacheLocality.cpp index 9336d6b17..d7bb95698 100644 --- a/code/PostProcessing/ImproveCacheLocality.cpp +++ b/code/PostProcessing/ImproveCacheLocality.cpp @@ -3,9 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2022, assimp team - - +Copyright (c) 2006-2023, assimp team All rights reserved. @@ -59,31 +57,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -using namespace Assimp; +namespace Assimp { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() -: mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) { +ImproveCacheLocalityProcess::ImproveCacheLocalityProcess() : + mConfigCacheDepth(PP_ICL_PTCACHE_SIZE) { // empty } // ------------------------------------------------------------------------------------------------ // Returns whether the processing step is present in the given flag field. -bool ImproveCacheLocalityProcess::IsActive( unsigned int pFlags) const { +bool ImproveCacheLocalityProcess::IsActive(unsigned int pFlags) const { return (pFlags & aiProcess_ImproveCacheLocality) != 0; } // ------------------------------------------------------------------------------------------------ // Setup configuration -void ImproveCacheLocalityProcess::SetupProperties(const Importer* pImp) { +void ImproveCacheLocalityProcess::SetupProperties(const Importer *pImp) { // AI_CONFIG_PP_ICL_PTCACHE_SIZE controls the target cache size for the optimizer - mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE,PP_ICL_PTCACHE_SIZE); + mConfigCacheDepth = pImp->GetPropertyInteger(AI_CONFIG_PP_ICL_PTCACHE_SIZE, PP_ICL_PTCACHE_SIZE); } // ------------------------------------------------------------------------------------------------ // Executes the post processing step on the given imported data. -void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { +void ImproveCacheLocalityProcess::Execute(aiScene *pScene) { if (!pScene->mNumMeshes) { ASSIMP_LOG_DEBUG("ImproveCacheLocalityProcess skipped; there are no meshes"); return; @@ -93,11 +91,11 @@ void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { float out = 0.f; unsigned int numf = 0, numm = 0; - for( unsigned int a = 0; a < pScene->mNumMeshes; ++a ){ - const float res = ProcessMesh( pScene->mMeshes[a],a); + for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { + const float res = ProcessMesh(pScene->mMeshes[a], a); if (res) { numf += pScene->mMeshes[a]->mNumFaces; - out += res; + out += res; ++numm; } } @@ -109,9 +107,54 @@ void ImproveCacheLocalityProcess::Execute( aiScene* pScene) { } } +// ------------------------------------------------------------------------------------------------ +static ai_real calculateInputACMR(aiMesh *pMesh, const aiFace *const pcEnd, + unsigned int configCacheDepth, unsigned int meshNum) { + ai_real fACMR = 0.0f; + unsigned int *piFIFOStack = new unsigned int[configCacheDepth]; + memset(piFIFOStack, 0xff, configCacheDepth * sizeof(unsigned int)); + unsigned int *piCur = piFIFOStack; + const unsigned int *const piCurEnd = piFIFOStack + configCacheDepth; + + // count the number of cache misses + unsigned int iCacheMisses = 0; + for (const aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) { + for (unsigned int qq = 0; qq < 3; ++qq) { + bool bInCache = false; + for (unsigned int *pp = piFIFOStack; pp < piCurEnd; ++pp) { + if (*pp == pcFace->mIndices[qq]) { + // the vertex is in cache + bInCache = true; + break; + } + } + if (!bInCache) { + ++iCacheMisses; + if (piCurEnd == piCur) { + piCur = piFIFOStack; + } + *piCur++ = pcFace->mIndices[qq]; + } + } + } + delete[] piFIFOStack; + fACMR = (ai_real)iCacheMisses / pMesh->mNumFaces; + if (3.0 == fACMR) { + char szBuff[128]; // should be sufficiently large in every case + + // the JoinIdenticalVertices process has not been executed on this + // mesh, otherwise this value would normally be at least minimally + // smaller than 3.0 ... + ai_snprintf(szBuff, 128, "Mesh %u: Not suitable for vcache optimization", meshNum); + ASSIMP_LOG_WARN(szBuff); + return static_cast(0.f); + } + return fACMR; +} + // ------------------------------------------------------------------------------------------------ // Improves the cache coherency of a specific mesh -ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshNum) { +ai_real ImproveCacheLocalityProcess::ProcessMesh(aiMesh *pMesh, unsigned int meshNum) { // TODO: rewrite this to use std::vector or boost::shared_array ai_assert(nullptr != pMesh); @@ -126,91 +169,57 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me return static_cast(0.f); } - if(pMesh->mNumVertices <= mConfigCacheDepth) { + if (pMesh->mNumVertices <= mConfigCacheDepth) { return static_cast(0.f); } ai_real fACMR = 3.f; - const aiFace* const pcEnd = pMesh->mFaces+pMesh->mNumFaces; + const aiFace *const pcEnd = pMesh->mFaces + pMesh->mNumFaces; // Input ACMR is for logging purposes only - if (!DefaultLogger::isNullLogger()) { - - unsigned int* piFIFOStack = new unsigned int[mConfigCacheDepth]; - memset(piFIFOStack,0xff,mConfigCacheDepth*sizeof(unsigned int)); - unsigned int* piCur = piFIFOStack; - const unsigned int* const piCurEnd = piFIFOStack + mConfigCacheDepth; - - // count the number of cache misses - unsigned int iCacheMisses = 0; - for (const aiFace* pcFace = pMesh->mFaces;pcFace != pcEnd;++pcFace) { - for (unsigned int qq = 0; qq < 3;++qq) { - bool bInCache = false; - for (unsigned int* pp = piFIFOStack;pp < piCurEnd;++pp) { - if (*pp == pcFace->mIndices[qq]) { - // the vertex is in cache - bInCache = true; - break; - } - } - if (!bInCache) { - ++iCacheMisses; - if (piCurEnd == piCur) { - piCur = piFIFOStack; - } - *piCur++ = pcFace->mIndices[qq]; - } - } - } - delete[] piFIFOStack; - fACMR = (ai_real) iCacheMisses / pMesh->mNumFaces; - if (3.0 == fACMR) { - char szBuff[128]; // should be sufficiently large in every case - - // the JoinIdenticalVertices process has not been executed on this - // mesh, otherwise this value would normally be at least minimally - // smaller than 3.0 ... - ai_snprintf(szBuff,128,"Mesh %u: Not suitable for vcache optimization",meshNum); - ASSIMP_LOG_WARN(szBuff); - return static_cast(0.f); - } + if (!DefaultLogger::isNullLogger()) { + fACMR = calculateInputACMR(pMesh, pcEnd, mConfigCacheDepth, meshNum); } // first we need to build a vertex-triangle adjacency list - VertexTriangleAdjacency adj(pMesh->mFaces,pMesh->mNumFaces, pMesh->mNumVertices,true); + VertexTriangleAdjacency adj(pMesh->mFaces, pMesh->mNumFaces, pMesh->mNumVertices, true); // build a list to store per-vertex caching time stamps - unsigned int* const piCachingStamps = new unsigned int[pMesh->mNumVertices]; - memset(piCachingStamps,0x0,pMesh->mNumVertices*sizeof(unsigned int)); + std::vector piCachingStamps; + piCachingStamps.resize(pMesh->mNumVertices); + memset(&piCachingStamps[0], 0x0, pMesh->mNumVertices * sizeof(unsigned int)); // allocate an empty output index buffer. We store the output indices in one large array. // Since the number of triangles won't change the input faces can be reused. This is how // we save thousands of redundant mini allocations for aiFace::mIndices - const unsigned int iIdxCnt = pMesh->mNumFaces*3; - unsigned int* const piIBOutput = new unsigned int[iIdxCnt]; - unsigned int* piCSIter = piIBOutput; + const unsigned int iIdxCnt = pMesh->mNumFaces * 3; + std::vector piIBOutput; + piIBOutput.resize(iIdxCnt); + std::vector::iterator piCSIter = piIBOutput.begin(); // allocate the flag array to hold the information // whether a face has already been emitted or not - std::vector abEmitted(pMesh->mNumFaces,false); + std::vector abEmitted(pMesh->mNumFaces, false); // dead-end vertex index stack - std::stack > sDeadEndVStack; + std::stack> sDeadEndVStack; // create a copy of the piNumTriPtr buffer - unsigned int* const piNumTriPtr = adj.mLiveTriangles; + unsigned int *const piNumTriPtr = adj.mLiveTriangles; const std::vector piNumTriPtrNoModify(piNumTriPtr, piNumTriPtr + pMesh->mNumVertices); // get the largest number of referenced triangles and allocate the "candidate buffer" - unsigned int iMaxRefTris = 0; { - const unsigned int* piCur = adj.mLiveTriangles; - const unsigned int* const piCurEnd = adj.mLiveTriangles+pMesh->mNumVertices; - for (;piCur != piCurEnd;++piCur) { - iMaxRefTris = std::max(iMaxRefTris,*piCur); + unsigned int iMaxRefTris = 0; + { + const unsigned int *piCur = adj.mLiveTriangles; + const unsigned int *const piCurEnd = adj.mLiveTriangles + pMesh->mNumVertices; + for (; piCur != piCurEnd; ++piCur) { + iMaxRefTris = std::max(iMaxRefTris, *piCur); } } ai_assert(iMaxRefTris > 0); - unsigned int* piCandidates = new unsigned int[iMaxRefTris*3]; + std::vector piCandidates; + piCandidates.resize(iMaxRefTris * 3); unsigned int iCacheMisses = 0; // ................................................................................... @@ -245,23 +254,23 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me int ivdx = 0; int ics = 1; - int iStampCnt = mConfigCacheDepth+1; - while (ivdx >= 0) { + int iStampCnt = mConfigCacheDepth + 1; + while (ivdx >= 0) { unsigned int icnt = piNumTriPtrNoModify[ivdx]; - unsigned int* piList = adj.GetAdjacentTriangles(ivdx); - unsigned int* piCurCandidate = piCandidates; + unsigned int *piList = adj.GetAdjacentTriangles(ivdx); + std::vector::iterator piCurCandidate = piCandidates.begin(); // get all triangles in the neighborhood - for (unsigned int tri = 0; tri < icnt;++tri) { + for (unsigned int tri = 0; tri < icnt; ++tri) { // if they have not yet been emitted, add them to the output IB const unsigned int fidx = *piList++; - if (!abEmitted[fidx]) { + if (!abEmitted[fidx]) { // so iterate through all vertices of the current triangle - const aiFace* pcFace = &pMesh->mFaces[ fidx ]; - unsigned nind = pcFace->mNumIndices; + const aiFace *pcFace = &pMesh->mFaces[fidx]; + const unsigned nind = pcFace->mNumIndices; for (unsigned ind = 0; ind < nind; ind++) { unsigned dp = pcFace->mIndices[ind]; @@ -281,7 +290,7 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me *piCSIter++ = dp; // if the vertex is not yet in cache, set its cache count - if (iStampCnt-piCachingStamps[dp] > mConfigCacheDepth) { + if (iStampCnt - piCachingStamps[dp] > mConfigCacheDepth) { piCachingStamps[dp] = iStampCnt++; ++iCacheMisses; } @@ -297,16 +306,16 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me // get next fanning vertex ivdx = -1; int max_priority = -1; - for (unsigned int* piCur = piCandidates;piCur != piCurCandidate;++piCur) { + for (std::vector::iterator piCur = piCandidates.begin(); piCur != piCurCandidate; ++piCur) { const unsigned int dp = *piCur; // must have live triangles - if (piNumTriPtr[dp] > 0) { + if (piNumTriPtr[dp] > 0) { int priority = 0; // will the vertex be in cache, even after fanning occurs? unsigned int tmp; - if ((tmp = iStampCnt-piCachingStamps[dp]) + 2*piNumTriPtr[dp] <= mConfigCacheDepth) { + if ((tmp = iStampCnt - piCachingStamps[dp]) + 2 * piNumTriPtr[dp] <= mConfigCacheDepth) { priority = tmp; } @@ -324,7 +333,7 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me while (!sDeadEndVStack.empty()) { unsigned int iCachedIdx = sDeadEndVStack.top(); sDeadEndVStack.pop(); - if (piNumTriPtr[ iCachedIdx ] > 0) { + if (piNumTriPtr[iCachedIdx] > 0) { ivdx = iCachedIdx; break; } @@ -333,9 +342,9 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me if (-1 == ivdx) { // well, there isn't such a vertex. Simply get the next vertex in input order and // hope it is not too bad ... - while (ics < (int)pMesh->mNumVertices) { + while (ics < (int)pMesh->mNumVertices) { ++ics; - if (piNumTriPtr[ics] > 0) { + if (piNumTriPtr[ics] > 0) { ivdx = ics; break; } @@ -345,29 +354,29 @@ ai_real ImproveCacheLocalityProcess::ProcessMesh( aiMesh* pMesh, unsigned int me } ai_real fACMR2 = 0.0f; if (!DefaultLogger::isNullLogger()) { - fACMR2 = (float)iCacheMisses / pMesh->mNumFaces; - + fACMR2 = static_cast(iCacheMisses / pMesh->mNumFaces); + const ai_real averageACMR = ((fACMR - fACMR2) / fACMR) * 100.f; // very intense verbose logging ... prepare for much text if there are many meshes - if ( DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) { - ASSIMP_LOG_VERBOSE_DEBUG("Mesh %u | ACMR in: ", meshNum, " out: ", fACMR, " | ~", fACMR2, ((fACMR - fACMR2) / fACMR) * 100.f); + if (DefaultLogger::get()->getLogSeverity() == Logger::VERBOSE) { + ASSIMP_LOG_VERBOSE_DEBUG("Mesh ", meshNum, "| ACMR in: ", fACMR, " out: ", fACMR2, " | average ACMR ", averageACMR); } - fACMR2 *= pMesh->mNumFaces; } - // sort the output index buffer back to the input array - piCSIter = piIBOutput; - for (aiFace* pcFace = pMesh->mFaces; pcFace != pcEnd;++pcFace) { - unsigned nind = pcFace->mNumIndices; - unsigned * ind = pcFace->mIndices; - if (nind > 0) ind[0] = *piCSIter++; - if (nind > 1) ind[1] = *piCSIter++; - if (nind > 2) ind[2] = *piCSIter++; - } - // delete temporary storage - delete[] piCachingStamps; - delete[] piIBOutput; - delete[] piCandidates; + // sort the output index buffer back to the input array + piCSIter = piIBOutput.begin(); + for (aiFace *pcFace = pMesh->mFaces; pcFace != pcEnd; ++pcFace) { + unsigned nind = pcFace->mNumIndices; + unsigned *ind = pcFace->mIndices; + if (nind > 0) + ind[0] = *piCSIter++; + if (nind > 1) + ind[1] = *piCSIter++; + if (nind > 2) + ind[2] = *piCSIter++; + } return fACMR2; } + +} // namespace Assimp