SlideShare ist ein Scribd-Unternehmen logo
1 von 10
第7回テックヒルズ
PLAYGROUND内の描画仕組み
ロマン ピコア
現代のモバイル用描画パイプライン

固定機能
プログラム可能
状態の変更のコスト
実行回数や負担を減らすための一般方法
まったく描画しないために処理
カメラの空間に無い物を描画しない。(カリング)

ピクセル毎の負担を減らす又ステート変更を減
らす
透明ではないオブジェクトを「近く遠く」にソート

透明であるオブジェクトを「遠く近く」にソート

高級なゲームはモデルOcclusionを計算

シェーダーの種類・パラメターでソート

テクスチャーでソート

A

A

A

B

B

B
モバイル、2Dの場合


Shader数が少ない、変わらないゲームも多い。




透明ではない物はほとんどありません:背景のみ。






画像とαブレンド・足し算ブレンドはほとんど。

Z Bufferのトリックは無意味。

3Dに比べてベクターデータ/頂点が少ない。

塗る面積が3Dとやや同じ・もっと大きいかも。
(Overdraw)
次のボトルネック:切り替えより回数減らそう
描画回数を減らすため、ステートが同じなら、バッチを実現。
4回実行(頂点情報だけが違う)
一回で描画

複数の描画命令を同じステートなら、同じ頂点リストにまとめて、実行数を減らす。
変わりにCPUがVertex Shaderの計算の一部を自前で計算し、バッファー作成する。
Playgroundでは?
XY

UV

モデル : XY バッファ / UV バッファ

インスタンス化 + 2D Matrixをかける(状態キャッシュ)
CO X U X U X U
インスタンス : Color + XYUV Buffer
L
YV YV YV

描画時にバッチバッファにまとめる
XUXUXUXUXUXUXUXUXU
… YV YV YV YV YV YV YV YV YV …
CO CO CO CO CO CO
…
…
L
L
L
L
L
L
同じステートで実行
速度を保つためにはキャッシュ&フラグ
①変わった時にフラグのみを変更
②変更された所だけのMatrixを再計算(フラグがあるため、
最適化ができて、無駄な計算せずにすむ)

Index
XY UV

2Dモデル
2Dインスタンス
シーングラフのノード

XUXUXUXU
YVYVYVYV

③変更された時だけにMatrixをかけて、画面空間で
XYを計算。そしてXYUVをインターレス化:キャッ
シュ

CO
L

④フラグによって、コピーの最適化: XYUV, COLOR,
INDEX XYU

V

Index
COL
気になる、Cocos 2Dはどうしている?

見た限り、バッチは可能ですが、純粋にプログラマーの責任
気になる、Unityはどうしている?
普段の場合、Unityの仕様を見ると、
 Batching of static model done by Unity Pro.
 Batching of dynamic model done by Unity. (=Playgroundと同じ動
作)
 Culling done by Unity
普通に3Dモデルで2Dを描画する作業なら、バッチ機能がやってくれ
るはず。
しかし2Dライブラリの場合、ライブラリ次第です。
例えば、ex2DライブラリはC#で自前でバッチする。

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Kürzlich hochgeladen (12)

知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Playground内の描画仕組み

Hinweis der Redaktion

  1. 今晩は、クラブのピコアと主します。今日のため何かを話そうかを悩んでたのですが、全体的にモバイルの描画の仕組みと、Playgroundの仕組みの話をしようと思います。よろしくお願いします。描画は奥が深い専門なので、10分程度ですから、コンパクトに正確な情報を説明したいと思います。(30 - 40秒)
  2. まず、現代のモバイル用のGraphic Pipelineを説明する必要があります。これがそのパイプラインの図です。それぞれの機能を連続に実行して、入力されたベクターデータが画像を作る事になります。頂点のそれぞれのバッファーの構造が設定できるため、まずデータを集まる・変換する仕組みが存在します。(Vertex Gather)そして、頂点の計算を行う。(Vertex Shader)そのあと、三角の場合のみの話ですが、頂点を3個ずつにまとめ、描画できるように三角を設定します。(Primitive Assembly)そして、ピクセル毎にRasterizerが働いて、ピクセル毎の計算を行う(Pixel Shader)そのあと、Depth TestやStencilを行う。この図はKhronos Groupからの図ですが、実はHWではEarly Z と言いまして、先にZ機能の一部を使う事でPixel Shaderを実行しない事もできる。そうすると、節約につながっています。モジュール毎にプログラム可能と固定機能を設定するだけの2種類に分かれており、それぞれの機能にパラメターを設定して、描画を実行する。(1分30秒程度): 2 mn
  3. 状態を変更し、描画を実行するの繰り返しで1画面分の画像を作る。もちろん、この図は理論的な話であって、わかりやすくするため、わざとたくさんな変更を見せかけた。実際に内部のステートがそんなに激しく(はげしく)変わっていない。でも、よく変わるのは同じ物を描画するではなくて、毎回違う物を描画するため、Vertex情報のバッファーが基本的に変わる。ShaderのパラメターShader自身利用されるTextureその他はZ Testがよく変更されます。(1分) - 3 mn total
  4. 細かい説明をしませんが、基本的に3Dエンジンなら、こんな作業をする。まずCPU側で- カメラの空間にモデルが入るかどうか確認する、例えばBounding box/ellipseを使って確認コストを出来るだけ安くする。さらにOcclusion Libraryを使う高級エンジンもある。描画するシーンのいろんな順でソートする。GPUが無駄をしないため。そして、CPUの先処理によって、GPUの時間・負担が少なくします。Textureの切り替え数を減らす:まとめて描画する。 Z Bufferで近くにあったオブジェクトを先に描画させる事によって、裏にあるピクセルを出来るだけZ バッファでrejectされる。その他のわざもたくさんあるので言うだけ : LOD モデルやシェダー, Imposter, mipmapなど)じゃ、2Dゲームの場合ではどうなりますか?(1分30秒) - 4mn30 total
  5. 2Dの場合、まず不透明なオブジェクトがほとんどない。背景のみ。そのあと、画像をかさねて描画するだけです。すべての画像が透明のため、Pixel Shaderの実行回数を減らすのは難しい。また、3Dに比べたら頂点の数は1/10になってもおかしくないので、Vertex shaderのコストやCPUでBatchするコストが問題にならないです。そして、ステートがほぼ変更がないため、ステート変更が基本的にTextureの切り替えと頂点データ。(1分) - 5mn30 total
  6. ですので、出来るだけ、同じTextureに素材あつまれば(Atlasと言います)さらにステートの変更を少なくが出来る、そうすると、実行回数自身を減らす事が可能になります。同じステートであれば、まとめて一気に描画する。しかし、このため、CPU側で以前にあったVertex Shaderの一部の仕事をCPU側に持っていく事が必要です。OpenGLESの仕様では、頂点のバッファーの順で描画する事になっていますので、CPUで作ったリストの順でそのままGPUが描画します。1分 – 6mn30 total
  7. 3Dエンジンと同じくモデルを持つ。(座標、UV, Color)しかし、色の情報はモデルに必要ない、インスタンスのみ。Cullingが基本的にしない。ポリゴンがそんなに多くないため、OpenGLESにスキップさせた方が早い。(ただし、場所によって更新しないコードが存在。)インスタンスが座標情報を画面空間でCPUで計算し、インスタンスで保存。描画時にコピーし、まとめて描画。もちろん、インスタンス内の更新やバッチ用のバッファの更新が最適化にされており。出来るだけ無駄なコピーや更新処理を実行しないように設計されています。メリット:ユーザがtextureの順と描画順をあわせる事を気をつけたら、自動的に最適なGPUコールになります。Demerit : はじめからCPUに負担をかける事。2分 : total 8 mn
  8. そして、全体的にMatrixの計算更新を実際実行するのはフラグによってされるので、必要な部分のみを再計算します。そのあと、変わったMatrixにつながっている2Dインスタンス(つまり描画命令の一部)、Matrixをかけたあとの状態を再計算します。ですので、Cache的な役割を持ち、変わった時にだけ再計算されます。そして描画ループで描画リストをみながら、さらに、フラグ情報でバッチ自身が変わったかどうか、ずれがあったどうか、色やUVや座標だけが変わったのかをうまく確認し、バッチ自身のコストも最適化可能。9.5mn
  9. 9.75mn
  10. Unityの場合、モデル毎にmesh / materialになってて、Mesh が 3Dモデルの頂点の事です。Materialがどんなshaderで、どんなtextureを利用しているのかを意味する。そうしますと、同じMaterialでまとめる処理を行う。つまりバッチする。さらに、動かないオブジェクトであれば、同じmeshにまとめるUnity Proの機能があります。(Dynamic バッチのコストを下がる)Materialを気をつければ、うまくバッチできるはず。しかし、2Dの場合、例えば、ex2Dのライブラリではバッチを自前で実装している。純粋に3Dモデルを使って、2Dをやる分にはとくに問題ないですが、2Dライブラリによって、処理が違うかもしれないので、気をつける点です。1分30 – total 10mn30 sec.