Vulkan Debugging & Validation Layers

🔍 Vulkan Validation Layers, Debugging & Profiling

Vulkan core drivers perform almost zero error checking in release builds to maximize execution speed. Passing an invalid pointer or incorrect image layout will silently crash the GPU.

During development, Validation Layers intercept every API call to verify specification compliance and catch synchronization hazards.


🛡️ 1. Enabling Validation in Odin

package main

import vk "vendor:vulkan"

VALIDATION_LAYERS := [?]cstring{
    "VK_LAYER_KHRONOS_validation",
}

create_instance :: proc() -> vk.Instance {
    create_info: vk.InstanceCreateInfo
    create_info.sType = .INSTANCE_CREATE_INFO
    
    when ODIN_DEBUG {
        create_info.enabledLayerCount = len(VALIDATION_LAYERS)
        create_info.ppEnabledLayerNames = &VALIDATION_LAYERS[0]
    }

    instance: vk.Instance
    vk.CreateInstance(&create_info, nil, &instance)
    return instance
}

🛠️ 2. Essential Profiling Tools

  1. RenderDoc: Frame debugger for inspecting draw calls, pipeline state, descriptor sets, and buffer memory.
  2. NVIDIA Nsight Graphics / AMD Radeon Developer Tool Suite (RGIT): Hardware-level profiling of GPU wave occupancy, memory bandwidth saturation, and shader instruction stalls.