How to run the code examples

This Learning Path assumes you are already familiar with the Vulkan API and have an application that uses it to create and render images on Android. If that is the case, you may skip this step.

Otherwise, you may use a test application like those provided by the Khronos Vulkan Samples repository .

Note

You do not need to create a new Vulkan Sample to complete this Learning Path but you can familiarize yourself with the code examples and save them as a reference. The Vulkan Sample provided in the previous step allows you to experiment with AFRC without any coding required.

Build Khronos’ Vulkan Samples

Download the repository:

    

        
        
            git clone --recurse-submodules https://github.com/KhronosGroup/Vulkan-Samples.git
cd vulkan-samples
python ./scripts/generate.py android
        
    

And follow the build instructions to run the example applications on an Android device.

Tip

You can use Android Studio to build and run the samples (the build instructions explain how to do this).

Create a test sample

If you are coding an example, rather than following along with the existing Image Compression Control sample, we need to first create a test sample. We can use the default API sample template to write and run the code snippets presented in this Learning Path.

To create a new sample:

    

        
        
            python ./scripts/generate.py sample_api --name afrc --category extensions
        
    

The necessary files will have been created in samples/extensions/afrc/.

View the sample logs

The screen output will not be relevant for the code we will write in this Learning Path. Instead, we will be focusing on the output of Android’s logcat, which can be printed using the Android Debug bridge (adb) included in the Android SDK Platform tools :

    

        
        
            # Clear the log and stop the sample if it is already running
adb logcat -c
adb shell am force-stop com.khronos.vulkan_samples

# Start the sample
adb shell am start --esa cmd "sample,afrc" com.khronos.vulkan_samples/com.khronos.vulkan_samples.SampleLauncherActivity

# Filter logcat to show sample messages only
adb logcat -s VulkanSamples
        
    

The output should start with:

    

        
        I VulkanSamples: [info] Logger initialized
I VulkanSamples: [info] Waiting on window surface to be ready
I VulkanSamples: [info] ContentRectChanged: 0xb4000079e82e6cd0
I VulkanSamples:
I VulkanSamples: [info] Initializing Vulkan sample

        
    

Modify the sample

The code snippets shown so far can be added anywhere within the afrc::prepare_pipelines() function in the afrc.cpp file.

To add a log, use the LOGI, LOGW and LOGE functions, for example:

    

        
        
            void afrc::prepare_pipelines()
{
	LOGI("Hello world!");

    ...
}
        
    

This will result in the following line being added to logcat:

    

        
        I VulkanSamples: [info] Hello world!

        
    
Back
Next