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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
73
Not 2 L8 JKでもわかるMaterial 3
bigbackboom
0
62
JKでもわかるSFace Recognition
bigbackboom
0
80
Androidタブレットアプリ作成_棚から牡丹餅を得るにはまず棚から
bigbackboom
0
70
Proto Datastoreを使う前の心構え
bigbackboom
0
320
Have A Dog in CircleCI
bigbackboom
0
90
Androidエンジニアのお仕事でのショボーン
bigbackboom
0
94
解明!楽しいプレゼンする話すスキル
bigbackboom
0
130
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
88
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
First, design no harm
axbom
PRO
2
1.2k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
260
Ethics towards AI in product and experience design
skipperchong
2
310
Mobile First: as difficult as doing things right
swwweet
225
10k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Design in an AI World
tapps
1
250
The Invisible Side of Design
smashingmag
302
52k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
240
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
230
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
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