Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dengan AGI Frame Profiler, Anda dapat menyelidiki shader dengan
memilih panggilan gambar dari salah satu penerusan render kami, dan melalui
bagian Vertex Shader atau bagian Fragment Shader pada panel
Pipeline.
Di sini Anda akan menemukan statistik berguna yang berasal dari analisis statis kode
shader, serta assembly Standard Portable Intermediate Representation
(SPIR-V) yang menjadi tujuan kompilasi GLSL kami. Ada juga tab
untuk melihat representasi GLSL asli (dengan nama yang dihasilkan compiler untuk variabel, fungsi, dan lainnya) yang didekompilasi dengan SPIR-V Cross, untuk memberikan konteks tambahan bagi SPIR-V.
Analisis statis
Gambar 1. Teks??
Gunakan penghitung analisis statis untuk melihat operasi tingkat rendah di shader.
Petunjuk ALU: Jumlah ini menunjukkan jumlah operasi ALU
(penambahan, perkalian, pembagian, dan sebagainya) yang dijalankan dalam
shader, dan merupakan proxy yang baik untuk tingkat kerumitan shader. Cobalah untuk meminimalkan
nilai ini.
Memfaktorkan ulang komputasi umum atau menyederhanakan komputasi yang dilakukan di
shader dapat membantu mengurangi jumlah petunjuk yang diperlukan.
Petunjuk Tekstur: Jumlah ini menunjukkan frekuensi terjadinya pengambilan sampel
tekstur di shader.
Pengambilan sampel tekstur bisa mahal bergantung pada jenis tekstur
yang diambil sampelnya. Jadi, melakukan referensi silang kode shader dengan tekstur
terikat yang ditemukan di bagian Kumpulan Deskripsi dapat memberikan informasi
selengkapnya tentang jenis tekstur yang digunakan.
Hindari akses acak saat mengambil sampel tekstur karena perilaku ini tidak
ideal untuk penyimpanan tekstur ke cache.
Petunjuk Cabang: Jumlah ini menunjukkan jumlah operasi cabang
di shader. Meminimalkan pencabangan sangat ideal pada prosesor paralel seperti
GPU, dan bahkan dapat membantu compiler menemukan pengoptimalan tambahan:
Gunakan fungsi seperti min, max, dan clamp agar tidak perlu mencabangkan nilai numerik.
Menguji biaya komputasi melalui percabangan. Karena kedua jalur
cabang dieksekusi di banyak arsitektur, ada banyak skenario
di mana selalu melakukan komputasi lebih cepat daripada melewatkan
komputasi dengan cabang.
Register Sementara: Register ini adalah register on-core yang cepat yang digunakan untuk
menyimpan hasil operasi perantara yang diperlukan oleh komputasi pada
GPU. Ada batasan jumlah register yang tersedia untuk komputasi
sebelum GPU harus menggunakan memori luar inti lainnya untuk menyimpan
nilai menengah, sehingga mengurangi performa keseluruhan. (Batas ini bervariasi
bergantung pada model GPU.)
Jumlah register sementara yang digunakan mungkin lebih tinggi daripada yang diharapkan jika
compiler shader menjalankan operasi seperti unrolling loop, jadi sebaiknya
referensikan silang nilai ini dengan SPIR-V atau GLSL yang didekompilasi untuk melihat fungsi
kode.
Analisis kode shader
Selidiki kode shader yang didekompilasi untuk menentukan apakah ada
potensi peningkatan yang dapat dilakukan.
Gambar 2. Teks??
Presisi: Presisi variabel shader dapat memengaruhi performa
GPU aplikasi Anda.
Coba gunakan pengubah presisi mediump pada variabel jika
memungkinkan, karena variabel 16-bit presisi sedang (mediump) biasanya
lebih cepat dan lebih hemat daya daripada variabel presisi penuh (highp)
32-bit.
Jika Anda tidak melihat penentu presisi di shader pada deklarasi
variabel, atau di bagian atas shader dengan
precision precision-qualifier type, default-nya adalah presisi penuh
(highp). Pastikan Anda juga melihat deklarasi variabel.
Penggunaan mediump untuk output shader vertex juga lebih disarankan untuk alasan
yang sama seperti dijelaskan di atas, dan juga bermanfaat untuk mengurangi bandwidth
memori serta penggunaan register sementara yang mungkin diperlukan untuk melakukan
interpolasi.
Uniform Buffers: Cobalah untuk mempertahankan ukuran Uniform Buffers sekecil
mungkin (sambil mempertahankan aturan penyelarasan). Hal ini membantu membuat komputasi
lebih kompatibel dengan caching dan berpotensi memungkinkan data seragam
dipromosikan ke register on-core yang lebih cepat.
Menghapus Output Vertex Shader yang tidak digunakan: Jika Anda mendapati output shader vertex
tidak digunakan dalam shader fragmen, hapus output tersebut dari shader untuk mengosongkan
bandwidth memori dan register sementara.
Memindahkan komputasi dari Fragment Shader ke Vertex Shader: Jika kode shader
fragmen melakukan komputasi yang tidak bergantung pada status khusus
fragmen yang diarsir (atau dapat diinterpolasi dengan benar), sebaiknya pindahkan ke
shader vertex. Alasannya karena di sebagian besar aplikasi, shader vertex dijalankan jauh lebih jarang dibandingkan dengan shader fragmen.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# Analyze shader performance\n\nAGI Frame Profiler allows you to investigate your shaders by\nselecting a draw call from one of our render passes, and going through either\nthe **Vertex Shader** section or **Fragment Shader** section of the **Pipeline**\npane.\n\nHere you'll find useful statistics coming from static analysis of the shader\ncode, as well as the [Standard Portable Intermediate Representation](https://en.wikipedia.org/wiki/Standard_Portable_Intermediate_Representation)\n(SPIR-V) assembly that our GLSL has been compiled down to. There's also a tab\nfor viewing a representation of the original GLSL (with compiler generated names for variables, functions, and more) that was decompiled with SPIR-V Cross, to provide additional context for the SPIR-V.\n\nStatic analysis\n---------------\n\n**Figure 1.**Caption??\n\nUse static analysis counters to view low-level operations in the shader.\n\n- **ALU Instructions**: This count shows the number of ALU operations\n (adds, multiplies, divisions, and more) are being executed within the\n shader, and is a good proxy for how complex the shader is. Try to minimize\n this value.\n\n Refactoring common computations or simplify computations done in the\n shader can help reduce the number of instructions needed.\n- **Texture Instructions**: This count shows the number of times texture\n sampling occurs in the shader.\n\n - Texture sampling can be expensive depending on the type of textures being sampled from, so cross-referencing the shader code with the bound textures found in the **Descriptor Sets** section can provide more information on the types of textures being used.\n - Avoid random access when sampling textures, because this behavior is not ideal for texture-caching.\n- **Branch Instructions**: This count shows the number of branch operations\n in the shader. Minimizing branching is ideal on parallelized processors such\n as the GPU, and can even help the compiler find additional optimizations:\n\n - Use functions such as `min`, `max`, and `clamp` to avoid needing to branch on numeric values.\n - Test the cost of computation over branching. Because both paths of a branch are executed in many architectures, there are many scenarios where always doing the computation is faster than skipping over the computation with a branch.\n- **Temporary Registers**: These are fast, on-core registers that are used to\n hold the results of intermediate operations required by computations on the\n GPU. There is a limit to the number of registers available for computations\n before the GPU has to spill over into using other off-core memory to store\n intermediate values, reducing overall performance. (This limit varies\n depending on the GPU model.)\n\n The number of temporary registers used may be higher than expected if the\n shader compiler performs operations such as unrolling loops, so it's good\n to cross-reference this value with the SPIR-V or decompiled GLSL to see what\n the code is doing.\n\n### Shader code analysis\n\nInvestigate the decompiled shader code itself to determine if there any\npotential improvements are possible.\n**Figure 2.**Caption??\n\n- **Precision** : The precision of shader variables can impact the GPU performance of your application.\n - Try using the `mediump` precision modifier on variables wherever possible, since medium precision (`mediump`) 16-bit variables are usually faster and more power efficient than full precision (`highp`) 32-bit variables.\n - If you don't see any precision qualifiers in the shader on variable declarations, or at the top of the shader with a `precision precision-qualifier type`, it defaults to full precision (`highp`). Make sure to look at variable declarations as well.\n - Using `mediump` for vertex shader output is also preferred for the same reasons described above, and also has the benefit of reducing memory bandwidth and potentially temporary register usage needed to do interpolation.\n- **Uniform Buffers** : Try to keep the size of **Uniform Buffers** as small as possible (while maintaining alignment rules). This helps make computations more compatible with caching and potentially allow for uniform data to be promoted to faster on-core registers.\n- **Remove unused Vertex Shader Outputs**: If you find vertex shader outputs\n being unused in the fragment shader, remove them from the shader to free up\n memory bandwidth and temporary registers.\n\n- **Move computation from Fragment Shader to Vertex Shader**: If the fragment\n shader code performs computations that are independent of state specific to\n the fragment being shaded (or can be interpolated properly), moving it to\n the vertex shader is ideal. The reason for this is that in most apps, the\n vertex shader is run much less frequently compared to the fragment shader."]]