49

有趣的阅读 - 如何量化分析Unity着色器的性能开销

 3 years ago
source link: https://zhuanlan.zhihu.com/p/161761815
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

有趣的阅读 - 如何量化分析Unity着色器的性能开销

计算机图形学话题下的优秀回答者

本文是一篇很有趣的文章,通过对Shader性能进行量化来分析Unity Shader的复杂度。

为此,作者将使用mali offline shader compiler这个比较冷门的工具来查看Unity中不同Shader的GPU cycles开销。

通常来查看一个Shader的开销有两种套路:

第一种就不赘述了,属于玄学。第二种还可以细分为对Shader进行静态分析或是在运行时profile各种性能指标。而本文作者使用的Mali Offline Compiler听上去就是用于前者的,即对shader代码进行静态分析。而Mali Offline Compiler的分析报告就会包含所消耗的GPU cycles,并且指出性能的bound是哪类操作。下面是一个示例。

`C:\Users\rtorresb\Desktop\Tmp>malioc shader.vert
Mali Offline Compiler v7.1.0 (Build 7a3538)
Copyright 2007-2020 Arm Limited, all rights reserved
Configuration
=============
Hardware: Mali-G76 r0p0
Driver: Bifrost r19p0-00rel0
Shader type: OpenGL ES Vertex (inferred)
Main shader
===========
Work registers: 32
Uniform registers: 82
Stack spilling: False
A LS V T Bound
Total instruction cycles: 2.9 16.0 0.0 0.0 LS
Shortest path cycles: 2.9 16.0 0.0 0.0 LS
Longest path cycles: 2.9 16.0 0.0 0.0 LS
A = Arithmetic, LS = Load/Store, V = Varying, T = Texture

比如这个Shader的LS = Load/Store是一个可以考虑优化的着手点。

全文分为以下几个部分:

  • Is It Important to Count GPU Cycles Nowadays?
  • Setting Up Your Mali Offline Compiler
  • Compiling Your Unity Shaders
  • Getting Your Unity Shader Performance Metrics
  • What Does This Teach Us?

原文标题:

How to Analyze the Performance Cost of Your Unity Shaders?

文章链接:

How to Analyze the Performance Cost of Your Unity Shaders - The Gamedev Guru​thegamedev.guru图标
编辑于 07-20

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK