From f1ae55c378087c77f937c52cd036c4391f73f68b Mon Sep 17 00:00:00 2001 From: Zane <1638944816@qq.com> Date: Tue, 30 Sep 2025 10:01:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1Project/图文合批/动态图集.md | 2 ++ 1Project/图文合批/图文合批.md | 0 3Resources/游戏开发/性能优化/卡片/Batch.md | 6 ++++++ 3Resources/游戏开发/性能优化/卡片/DrawCall.md | 6 ++++++ .../游戏开发/性能优化/卡片/SetPassCall.md | 6 ++++++ .../性能优化/卡片/内存碎片如何优化.md | 8 ++++++++ .../游戏开发/性能优化/压缩/ASTC图片压缩.md | 3 +++ .../性能优化/并行计算/CPU/SIMD(单指令多数据).md | 5 +++++ .../性能优化/并行计算/GPU/Compute Shader.md | 6 ++++++ .../游戏开发/性能优化/并行计算/GPU/SIMT.md | 5 +++++ 3Resources/游戏开发/性能优化/性能优化-目录.md | 4 +++- 卡片数据库.base | 19 +++++++++++++++++++ 12 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 1Project/图文合批/动态图集.md create mode 100644 1Project/图文合批/图文合批.md create mode 100644 卡片数据库.base diff --git a/1Project/图文合批/动态图集.md b/1Project/图文合批/动态图集.md new file mode 100644 index 0000000..4a00a59 --- /dev/null +++ b/1Project/图文合批/动态图集.md @@ -0,0 +1,2 @@ +# 算法 +# 做法 diff --git a/1Project/图文合批/图文合批.md b/1Project/图文合批/图文合批.md new file mode 100644 index 0000000..e69de29 diff --git a/3Resources/游戏开发/性能优化/卡片/Batch.md b/3Resources/游戏开发/性能优化/卡片/Batch.md index 84bd239..5d03284 100644 --- a/3Resources/游戏开发/性能优化/卡片/Batch.md +++ b/3Resources/游戏开发/性能优化/卡片/Batch.md @@ -1 +1,7 @@ +--- +tags: + - Batch +--- + + 把数据加载到显存,设置渲染状态,CPU调用GPU渲染的过程称之为一个Batch。这其实就是渲染流程的运用阶段,最终输出一个渲染图元(点、线、面等),再传递给GPU进行几何阶段和光栅化阶段的渲染显示。一个Batch必然会触发一次或多次DrawCal,目包含了该对象的所有的网格和顶点数据以及材质信息。把数据加载到显存是指把清染所蛋的数据从硬盘加载到内存(RAM),再将网格和纹理等加载到显卡 VRAM),这一步比较释时。设置清染状态就是设置场景中的网格的顶点 Verex)片元(Fragment)着色器,光源属性,材质等。Unitv提供的动态合批(Dvnamic Batching)合并的就是这一过程,将清染状态相同的对象合并成-个Batch,减少DrawCall。 \ No newline at end of file diff --git a/3Resources/游戏开发/性能优化/卡片/DrawCall.md b/3Resources/游戏开发/性能优化/卡片/DrawCall.md index 6f2afe5..56e85b4 100644 --- a/3Resources/游戏开发/性能优化/卡片/DrawCall.md +++ b/3Resources/游戏开发/性能优化/卡片/DrawCall.md @@ -1 +1,7 @@ +--- +tags: + - DrawCall +--- + + CPU每次调用图像编程接口 glDrawElements(0penGl日中的图元清染函数)或者 DrawIndexedPrimitive(Direct中的顶点绘制方法)命令GPU渲染的操作称为一次Draw Cal,Draw Cal就是一次渲染命令的调用,它指向一个需要被渲染的图元(primitive)列表,不包含任何材质信息,glDrawElements 或者 DrawIndexedPrimitive 函数的作用是将CPU准备好的顶点数据渲染出来. \ No newline at end of file diff --git a/3Resources/游戏开发/性能优化/卡片/SetPassCall.md b/3Resources/游戏开发/性能优化/卡片/SetPassCall.md index 66c0b64..bcdab88 100644 --- a/3Resources/游戏开发/性能优化/卡片/SetPassCall.md +++ b/3Resources/游戏开发/性能优化/卡片/SetPassCall.md @@ -1 +1,7 @@ +--- +tags: + - DrawCall +--- + + Shader脚本中一个Pass语义块就是一个完整的渲染流程,一个着色器可以包含多个Pass语义块,每当GPU运行-个Pass之前,就会产生一个SetPassCall,所以可以理解为一次完整的染流程次数。 \ No newline at end of file diff --git a/3Resources/游戏开发/性能优化/卡片/内存碎片如何优化.md b/3Resources/游戏开发/性能优化/卡片/内存碎片如何优化.md index ba94c8c..e47cdd0 100644 --- a/3Resources/游戏开发/性能优化/卡片/内存碎片如何优化.md +++ b/3Resources/游戏开发/性能优化/卡片/内存碎片如何优化.md @@ -1,2 +1,10 @@ +--- +tags: + - 性能优化 + - 内存优化 + - 内存碎片 +--- + + - 大对象尽量复用,比如数组,可以在开头就分配好空间 - new int\[1000] diff --git a/3Resources/游戏开发/性能优化/压缩/ASTC图片压缩.md b/3Resources/游戏开发/性能优化/压缩/ASTC图片压缩.md index 144c993..1a5f658 100644 --- a/3Resources/游戏开发/性能优化/压缩/ASTC图片压缩.md +++ b/3Resources/游戏开发/性能优化/压缩/ASTC图片压缩.md @@ -1,6 +1,9 @@ --- 参考链接: "[ASTC图片压缩技术浅析 - 知乎](https://zhuanlan.zhihu.com/p/1898042738022285491)" 参考链接2: "[深入理解ASTC](https://zhuanlan.zhihu.com/p/707250800)" +tags: + - ASTC + - 压缩 --- # 浅析 diff --git a/3Resources/游戏开发/性能优化/并行计算/CPU/SIMD(单指令多数据).md b/3Resources/游戏开发/性能优化/并行计算/CPU/SIMD(单指令多数据).md index 86dd7c7..e32245a 100644 --- a/3Resources/游戏开发/性能优化/并行计算/CPU/SIMD(单指令多数据).md +++ b/3Resources/游戏开发/性能优化/并行计算/CPU/SIMD(单指令多数据).md @@ -1,3 +1,8 @@ +--- +tags: + - 多线程 + - SIMD +--- - 一个普通加法指令,一次只能对两个数执行一个加法操作。 diff --git a/3Resources/游戏开发/性能优化/并行计算/GPU/Compute Shader.md b/3Resources/游戏开发/性能优化/并行计算/GPU/Compute Shader.md index e69de29..36b9c3e 100644 --- a/3Resources/游戏开发/性能优化/并行计算/GPU/Compute Shader.md +++ b/3Resources/游戏开发/性能优化/并行计算/GPU/Compute Shader.md @@ -0,0 +1,6 @@ +--- +tags: + - 多线程 + - GPU + - ComputeShader +--- diff --git a/3Resources/游戏开发/性能优化/并行计算/GPU/SIMT.md b/3Resources/游戏开发/性能优化/并行计算/GPU/SIMT.md index ce5e621..7856271 100644 --- a/3Resources/游戏开发/性能优化/并行计算/GPU/SIMT.md +++ b/3Resources/游戏开发/性能优化/并行计算/GPU/SIMT.md @@ -1,3 +1,8 @@ +--- +tags: + - SIMT + - 多线程 +--- 单指令多线程 diff --git a/3Resources/游戏开发/性能优化/性能优化-目录.md b/3Resources/游戏开发/性能优化/性能优化-目录.md index 5695846..72920b0 100644 --- a/3Resources/游戏开发/性能优化/性能优化-目录.md +++ b/3Resources/游戏开发/性能优化/性能优化-目录.md @@ -12,4 +12,6 @@ tags: - 代码优化 - 池化 - 复用 - - GC \ No newline at end of file + - GC + - UWA蓝皮书 + - https://blog.uwa4d.com/archives/BlueBook_2025.html \ No newline at end of file diff --git a/卡片数据库.base b/卡片数据库.base new file mode 100644 index 0000000..5c6d85c --- /dev/null +++ b/卡片数据库.base @@ -0,0 +1,19 @@ +views: + - type: table + name: 表格 + filters: + and: + - file.hasTag("性能优化") + order: + - file.name + sort: + - property: file.name + direction: DESC + - type: cards + name: 视图 + filters: + and: + - file.hasTag("性能优化") + cardSize: 150 + image: note.tags + imageAspectRatio: 1.25 From 89282b017472ff9b79e2215f6a8b45a321f80139 Mon Sep 17 00:00:00 2001 From: Zane <1638944816@qq.com> Date: Thu, 9 Oct 2025 20:47:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=85=AC=E5=8F=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .obsidian/core-plugins.json | 6 +- 1Project/图文合批/动态图集.md | 2 - 1Project/图文合批/图文合批.md | 0 .../Texture、Texture2D与RenderTexture.md | 11 +++ .../卡片/Texture、Texture2D与RenderTexture.md | 68 +++++++++++++++++++ 5 files changed, 83 insertions(+), 4 deletions(-) delete mode 100644 1Project/图文合批/动态图集.md delete mode 100644 1Project/图文合批/图文合批.md create mode 100644 2Areas/游戏开发/Texture、Texture2D与RenderTexture.md create mode 100644 3Resources/游戏开发/性能优化/卡片/Texture、Texture2D与RenderTexture.md diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json index cf7c8a1..a59bef1 100644 --- a/.obsidian/core-plugins.json +++ b/.obsidian/core-plugins.json @@ -8,7 +8,7 @@ "outgoing-link": true, "tag-pane": true, "page-preview": true, - "daily-notes": true, + "daily-notes": false, "templates": true, "note-composer": true, "command-palette": true, @@ -28,5 +28,7 @@ "sync": false, "properties": false, "bookmarks": true, - "webviewer": false + "webviewer": false, + "footnotes": false, + "bases": true } \ No newline at end of file diff --git a/1Project/图文合批/动态图集.md b/1Project/图文合批/动态图集.md deleted file mode 100644 index 4a00a59..0000000 --- a/1Project/图文合批/动态图集.md +++ /dev/null @@ -1,2 +0,0 @@ -# 算法 -# 做法 diff --git a/1Project/图文合批/图文合批.md b/1Project/图文合批/图文合批.md deleted file mode 100644 index e69de29..0000000 diff --git a/2Areas/游戏开发/Texture、Texture2D与RenderTexture.md b/2Areas/游戏开发/Texture、Texture2D与RenderTexture.md new file mode 100644 index 0000000..44e3813 --- /dev/null +++ b/2Areas/游戏开发/Texture、Texture2D与RenderTexture.md @@ -0,0 +1,11 @@ +--- +tags: + - Texture + - Texture2D + - RenderTexture +资源链接: "[[3Resources/游戏开发/性能优化/卡片/Texture、Texture2D与RenderTexture|Texture、Texture2D与RenderTexture]]" +--- +简言: +`Texture` 是抽象基类; +`Texture2D` 是可读写的普通贴图; +`RenderTexture` 是可被渲染的动态纹理。 \ No newline at end of file diff --git a/3Resources/游戏开发/性能优化/卡片/Texture、Texture2D与RenderTexture.md b/3Resources/游戏开发/性能优化/卡片/Texture、Texture2D与RenderTexture.md new file mode 100644 index 0000000..46795ad --- /dev/null +++ b/3Resources/游戏开发/性能优化/卡片/Texture、Texture2D与RenderTexture.md @@ -0,0 +1,68 @@ +--- +tags: + - Texture + - Texture2D + - RenderTexture +--- + + +### Texture Texture2D RenderTexture +三者关系与差别如下: + +--- + +### 一、继承与本质关系 + +|类型|基类|存储位置|用途| +|---|---|---|---| +|**Texture**|基类|GPU|所有纹理的抽象基类| +|**Texture2D**|派生自 Texture|GPU|常规 2D 纹理,可读写像素| +|**RenderTexture**|派生自 Texture|GPU|可作为渲染目标的纹理| + +--- + +### 二、功能差异 + +| 特性 | Texture2D | RenderTexture | +| -------------------- | --------------------------------------- | -------------------------------------------- | +| 是否可被采样(用于材质) | ✔ | ✔ | +| 是否可写入(CPU端) | ✔(`SetPixels`/`LoadRawTextureData`) | ✖(仅GPU写) | +| 是否可作为渲染目标 | ✖ | ✔(Camera/Graphics.Blit可直接输出) | +| 是否支持MipMap | ✔ | ✔(可选) | +| 是否可用于ComputeShader读写 | 读可用(`Texture2D`)
写需`RWTexture2D`绑定 | 读写都可(`RenderTexture.enableRandomWrite=true`) | +| 是否可保存为文件 | ✔(`EncodeToPNG`/`ReadPixels`) | 需先复制到`Texture2D`再保存 | + +--- + +### 三、常见交互流程 + +1. **GPU渲染到RenderTexture → 读取像素到Texture2D:** + + ```CSharp + RenderTexture rt = new RenderTexture(512, 512, 0); Camera.main.targetTexture = rt; Camera.main.Render(); Texture2D tex = new Texture2D(512, 512, TextureFormat.RGBA32, false); RenderTexture.active = rt; tex.ReadPixels(new Rect(0, 0, 512, 512), 0, 0); tex.Apply(); RenderTexture.active = null; + ``` + + 此流程用于截图或生成贴图资产。 + +2. **Texture2D 复制内容到 RenderTexture:** + + `Graphics.Blit(texture2D, renderTexture);` + + 仅在shader中使用时保留GPU端数据,不经CPU拷贝。 + +3. **RenderTexture 作为材质输入:** + + `material.SetTexture("_MainTex", renderTexture);` + + +--- + +### 四、性能与使用建议 + +- `Texture2D` 适合静态资源(贴图、UI图标、字体图集)。 + +- `RenderTexture` 适合动态生成(后期处理、离屏渲染、动态阴影、SDF生成)。 + +- CPU访问`RenderTexture`代价高,应尽量避免频繁`ReadPixels`。 + +- 若仅GPU间数据流转,用`RenderTexture`或`ComputeBuffer`,不要回读。 \ No newline at end of file