Changes between Initial Version and Version 1 of Vulkan


Ignore:
Timestamp:
Jun 5, 2023, 7:55:00 PM (12 months ago)
Author:
Vladislav Belov
Comment:

Initial version.

Legend:

Unmodified
Added
Removed
Modified
  • Vulkan

    v1 v1  
     1[[TOC]]
     2
     3= Vulkan =
     4
     5Vulkan is a modern cross-platform API for graphics and computing (similar to D3D12 and Metal). It was added as backend to Pyrogenesis in r27412. Vulkan drivers from different vendors are usually much lighter than GL ones. Vulkan supports multithreading, it means in the future we might try to utilize it after separating graphics and simulation.
     6
     7== Building shaders ==
     8
     9Vulkan can't run pure GLSL shaders (which we use for GL), it uses a special binary format for shaders: SPIR-V. A shader program requires '''rules''' to be built. It's a JSON file which describes all combinations of shader programs with defines for each combination. Each rules file might contain combinations for a single or multiple shaders.
     10
     11=== Recompiling existing shaders ===
     12
     13* Read [https://trac.wildfiregames.com/browser/ps/trunk/source/tools/spirv/README.md source/tools/spirv/README.md] and perform required installations
     14* Download rules for SVN or release from https://releases.wildfiregames.com/spir-v/rules.latest.json or https://releases.wildfiregames.com/spir-v/rules.0.0.27.json respectively
     15* Run the script (usually it's necessary to provide modmod dependency as it provides important headers):
     16{{{#!bash
     17python source/tools/spirv/compile.py \
     18  path-to-folder-with-input-mod rules-path mod-output-path [-d dependency-mod]
     19}}}
     20* Example to rebuild shaders inside a repository (it'll create the `binaries/data/mods/public/spirv` folder):
     21{{{#!bash
     22python source/tools/spirv/compile.py \
     23  binaries/data/mods/public rules.json binaries/data/mods/public -d binaries/data/mods/mod
     24}}}
     25
     26=== Compiling new shader
     27
     28* Read [https://trac.wildfiregames.com/browser/ps/trunk/source/tools/spirv/README.md source/tools/spirv/README.md] and perform required installations
     29* Create a rules file for the new shader, format:
     30{{{#!json
     31{
     32  "shader-program-name":
     33  {
     34    "combinations":
     35    [
     36      [{"name": "DEFINE1", "value": "VALUE1"}, ...],
     37      ...,
     38    ],
     39    "name": "shader-program-name"
     40  },
     41  ...
     42}
     43}}}
     44* Example `rules.json` with a single combination for `model_water`:
     45{{{#!json
     46{
     47  "model_water":
     48  {
     49    "combinations":
     50    [
     51      [{"name": "IGNORE_LOS", "value": "1"}, {"name": "USE_TRANSPARENT", "value": "1"}]
     52    ],
     53    "name": "model_water"
     54  }
     55}
     56}}}
     57* Run the script (usually it's necessary to provide modmod dependency as it provides important headers):
     58{{{#!bash
     59python source/tools/spirv/compile.py \
     60  path-to-folder-with-input-mod rules-path mod-output-path -p shader-program-name
     61 [-d dependency-mod]
     62}}}
     63* Example to build shader inside a repository:
     64{{{#!bash
     65python source/tools/spirv/compile.py \
     66  binaries/data/mods/public rules.json binaries/data/mods/public -p model_waterfall -d binaries/data/mods/mod
     67}}}
     68
     69== Debugging ==
     70
     71First of all we need to enable lightweight debug helpers:
     72{{{
     73renderer.backend.debuglabels = "true"
     74renderer.backend.debugmessages = "true"
     75renderer.backend.debugscopedlabels = "true"
     76}}}
     77
     78They're making logs and captures more readable but don't cost performance noticeably.
     79
     80The next step is to enable basic validation layers (usually it requires to have Vulkan SDK installed). They're making the game much slower but at the same time evaluating much more checks.
     81{{{
     82renderer.backend.debugcontext = "true"
     83}}}
     84
     85If it's not enough then it needs to run the game via Vulkan configurator to setup validation layers more precisely (it also allows to enable GPU assist). '''Note:''' Currently validation layers might report false-positive hazards with enabled descriptor indexing because it can't properly check descriptor accesses yet: https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/3450. It's possible to hide them by disabling descriptor indexing:
     86{{{
     87renderer.backend.vulkan.disabledescriptorindexing = "true"
     88}}}
     89Usually it shouldn't change the game behavior noticeably because descriptor indexing only affects textures binding and not barriers.
     90
     91=== Artifacts ===
     92Sometimes visual artifacts might caused by a synchronization issue or by missing or incorrect barriers. There're few options which might help to debug such cases.
     93
     94Adds a strong execution and memory barrier after each framebuffer pass (during EndFramebufferPass):
     95{{{
     96renderer.backend.vulkan.debugbarrierafterframebufferpass = "true"
     97}}}
     98
     99Waits GPU to be idle for a particular CPU step (uses `vkDeviceWaitIdle` under the hood):
     100{{{
     101renderer.backend.vulkan.debugwaitidlebeforeacquire = "true"
     102renderer.backend.vulkan.debugwaitidlebeforepresent = "true"
     103renderer.backend.vulkan.debugwaitidleafterpresent = "true"
     104}}}
     105
     106See [#Tools Tools].
     107
     108== Profiling ==
     109
     110Currently we don't support in-game profiling of Vulkan. Only external tools are applicable for now.
     111
     112See [#Tools Tools].
     113
     114== Tools ==
     115
     116A list of tested tools that work or not for Pyrogenesis. It's recommended to enable labels and scoped labels to make it easier to navigate through captures.
     117
     118* '''RenderDoc''' - a free MIT licensed stand-alone graphics debugger (https://renderdoc.org/). It allows to capture frames and do a very simple profiling.
     119* '''NVIDIA® NSight™''' - a free proprietary standalone developer tool that enables you to debug, and do extensive profiling (https://developer.nvidia.com/nsight-graphics, https://developer.nvidia.com/nsight-visual-studio-edition). Currently it doesn't work with Vulkan on Windows because we still build 32-bits application. #2611 should fix that.