Rendering Architecture

Cohtml draws the UI (a View) in a user-provided texture.

The Unity integration takes care of that by calling UnitySetRenderTexture method followed by a SetRenderTarget render event.

Cohtml performs incremental rendering by updating only the parts of the UI texture that have changed. It will not redraw everything in the UI, which improves performance significantly. The user should not draw anything on the UI texture, except the output of Cohtml. Internally Cohtml uses the Coherent Labs Renoir graphics library.

Cohtml asynchronously records rendering commands that are later executed on the render thread when the DrawView render event is issued.

This is the reason every View object has a corresponding ViewRenderer. The View lives on the UI thread and “controls” the page, while the ViewRenderer is only in charge of drawing it and lives on the render thread.

Backends

On different platforms, Cohtml can draw with different rendering APIs. The API-specific code is encapsulated in a Renoir backend.

The Prysm Unity plugin uses different backends depending on the selected graphics rendering API in the project settings.

Prysm supports the following rendering APIs:

  • DirectX 11
  • OpenGL 3.3+
  • OpenGL ES 3
  • DirectX 12
  • Vulkan
  • Metal

Rendering Platform Specifics

The Vulkan SDK includes validation layers, which hook into API entry points and provide debugging functionality. In our samples we enable Vulkan validation layers by default on Windows, but not on Android. The motivation for this is, that on Android the layers should be explicitly packaged in the apk. Generally, the following guide should be followed. Alternatively, if you want to package the validation layers in an already built apk, you can use ApkTool and SignApk to do so. This can be achieved by extracting all the tools in the apk output directory and executing a script similar to the following one:

@ECHO OFF

SETLOCAL

SET FileName=ActivityCohtml
SET Platform=armeabi-v7a
SET AndroidNDKPath=C:\Microsoft\AndroidNDK64\android-ndk-r16b
SET ValidationLayerFolder=%AndroidNDKPath%\sources\third_party\vulkan\src\build-android\jniLibs\%Platform%
SET ApkTool=apktool_2.3.3.jar

ECHO %FileName%

java -jar %ApkTool% d %FileName%.apk`

copy /Y %ValidationLayerFolder%\libVkLayer_core_validation.so %FileName%\lib\%Platform%\
copy /Y %ValidationLayerFolder%\libVkLayer_image.so %FileName%\lib\%Platform%\
copy /Y %ValidationLayerFolder%\libVkLayer_object_tracker.so %FileName%\lib\%Platform%\
copy /Y %ValidationLayerFolder%\libVkLayer_parameter_validation.so %FileName%\lib\%Platform%\
copy /Y %ValidationLayerFolder%\libVkLayer_swapchain.so %FileName%\lib\%Platform%\
copy /Y %ValidationLayerFolder%\libVkLayer_threading.so %FileName%\lib\%Platform%\
copy /Y %ValidationLayerFolder%\libVkLayer_unique_objects.so %FileName%\lib\%Platform%\

java -jar %ApkTool% b %FileName%

move %FileName%\dist\%FileName%.apk %FileName%_UNALIGNED.apk

java -jar signapk.jar certificate.pem key.pk8 %FileName%_UNALIGNED.apk %FileName%.apk

del %FileName%_UNALIGNED.apk
rmdir /s /q %FileName%

ENDLOCAL

Advanced Rendering Debugging

Developers can gain further insight into the rendering commands generated during runtime by calling the View::EmitRenderingMetadata method. Metadata markers will be inserted in the rendering command stream that can be hooked to third-party tools like PIX, RenderDoc, Razor etc., or internal engine profilers. The markers will show which elements generate every rendering command in the stream. The backend should also implement the marker-related commands, for the DirectX 11 backend you should enable the DX11_ANNOTATE_EVENTS define, which by default is enabled only in Debug configurations.

Font generation on the GPU

SDF on GPU - Font generation on the GPU.

Combating gradient banding

Dithering the gradient rendering - Gradients dithering.