Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Extended A Study in Bitmap: Is NDK the fast Pro...
Search
bigbackboom
October 15, 2024
34
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Extended A Study in Bitmap: Is NDK the fast Processing method by CPU?
bigbackboom
October 15, 2024
More Decks by bigbackboom
See All by bigbackboom
Learn as a Pair
bigbackboom
0
74
Not 2 L8 JKでもわかるMaterial 3
bigbackboom
0
62
JKでもわかるSFace Recognition
bigbackboom
0
81
Androidタブレットアプリ作成_棚から牡丹餅を得るにはまず棚から
bigbackboom
0
70
Proto Datastoreを使う前の心構え
bigbackboom
0
320
Have A Dog in CircleCI
bigbackboom
0
93
Androidエンジニアのお仕事でのショボーン
bigbackboom
0
95
解明!楽しいプレゼンする話すスキル
bigbackboom
0
130
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
88
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
800
Become a Pro
speakerdeck
PRO
31
6k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
A Modern Web Designer's Workflow
chriscoyier
698
190k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The World Runs on Bad Software
bkeepers
PRO
72
12k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
320
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
Transcript
EXTENDED A Study in Bitmap: Is NDK the Fastest Processing
Method by CPU? キクチコウダイ
自己紹介 菊池 広大(キクチコウダイ) 2023年6月 株式会社マネーフォワードに入社 埼玉出身、Iターンで東京から福岡に引越し Androidエンジニア、たまにバックエンド Github: https://github.com/BigBackBoom
WE ARE HIRING!!!!
概要 以前、モバチキで発表したものに 内容を肉付けしたものとなっています。
おさらい
概要 C++で実行されるAndroidのNDKは 本当に実行速度最速なのか? Bitmapファイルを処理して その速度を検証してみよう
NDKとは?
NDKとは? • Kotlin/JavaからC/C++などのNativeコードでの開発 が可能にするツールセット • C/C++でしか提供されていないパワフルなライブラリ が利用可能になる • Nativeコードのロジックを再利用できる。
検証内容
検証内容 4KのBMPファイルを アルファブレンディングして 処理時間を測る
パフォーマンス
パフォーマンス
パフォーマンス NDK: • Average: 50ms • Max: 75ms • Min:
33ms • Median: 45.5ms JVM: • Average: 63.3ms • Max: 90ms • Min: 59ms • Median: 60ms まとめ
結論 • NDKだから早いとは限らない • ただ、ハードウェアアクセラレーションを利用すれば最強! • とはいえ、【パフォーマンスチューニング】は大事だが、ゲームアプリ のフレームレート改善でもない限り、msレベルのチューニングは無駄
EXTENDED!
Extended なんでJVMとネイティブコードで そんなに処理速度に差が出てないの?
Extended JavaはJust in Time(JIT)コンパイラーを 内部的に利用しているため 実行直前にネイティブコードを生成している。
Extended ハードウェアアクセラレーションでの処理は 果たして高速なのだろうか? OpenGL© ESで試してみた
Extended • クロスプラットフォームで動作するグラフィックライ ブラリ。 • 実装難易度は高いが、最高レベルのパフォーマンスで 描画可能 • Androidの描画ライブラリSkiaも裏はこいつ
Extended OpenGLのテクスチャに画像を貼り付けて シェーダーで高速 ブレンディング処理を実施する
Extended • テクスチャの色データを取 り出す GLSLの実装 #version 300 es precision mediump
float; in vec2 v_texCoord; layout(location = 0) out vec4 outColor; uniform sampler2D s_texture; uniform vec3 rgb; uniform float alpha; void main() { // change color order since bitmap is BGR float filtering = 1.0 - alpha; vec4 texture = texture(s_texture , v_texCoord); float r = (texture.b * alpha) + (rgb.r * filtering) ; float g = (texture.g * alpha) + (rgb.g * filtering) ; float b = (texture.r * alpha) + (rgb.b * filtering) ; // change color order since bitmap is BGR outColor = vec4(r, g, b, 1.0f); }
Extended • テクスチャの色データを取 り出す • 取り出したデータでブレン ディング処理をする GLSLの実装 #version 300
es precision mediump float; in vec2 v_texCoord; layout(location = 0) out vec4 outColor; uniform sampler2D s_texture; uniform vec3 rgb; uniform float alpha; void main() { // change color order since bitmap is BGR float filtering = 1.0 - alpha; vec4 texture = texture(s_texture , v_texCoord); float r = (texture.b * alpha) + (rgb.r * filtering) ; float g = (texture.g * alpha) + (rgb.g * filtering) ; float b = (texture.r * alpha) + (rgb.b * filtering) ; // change color order since bitmap is BGR outColor = vec4(r, g, b, 1.0f); }
Extended • テクスチャの色データを取 り出す • 取り出したデータでブレン ディング処理をする • 普通のプログラミング言語 に近いが、if文を使うと劇
的に遅くなる😂 GLSLの実装 #version 300 es precision mediump float; in vec2 v_texCoord; layout(location = 0) out vec4 outColor; uniform sampler2D s_texture; uniform vec3 rgb; uniform float alpha; void main() { // change color order since bitmap is BGR float filtering = 1.0 - alpha; vec4 texture = texture(s_texture , v_texCoord); float r = (texture.b * alpha) + (rgb.r * filtering) ; float g = (texture.g * alpha) + (rgb.g * filtering) ; float b = (texture.r * alpha) + (rgb.b * filtering) ; // change color order since bitmap is BGR outColor = vec4(r, g, b, 1.0f); }
Extended
結論
結論 俺たちのGPUは最強なんだ!
結論 • Javaも実は実処理はネイティブコード • GPUを使った処理はやっぱり早い。
以上、ありがとうございました!
Sample Repository: ❖ Kotlin 2.0 ❖ Multi-Module with NDK ❖
Jetpack Compose https://github.com/BigBackBoom/hades