Announcement

Collapse
No announcement yet.

A Deep Dive Into Vulkan's Validation Layers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A Deep Dive Into Vulkan's Validation Layers

    Phoronix: A Deep Dive Into Vulkan's Validation Layers

    The plugable validation layers concept is one of many great improvements with Vulkan over OpenGL. If you are new to Vulkan development or just haven't explored the validation layers yet, The Khronos Group and LunarG hosted a webinar this week concerning this area of the new high-performance graphics API...

    http://www.phoronix.com/scan.php?pag...n-Layers-HowTo

  • #2
    So then you can have two builds when you compile, "Release" and "Debug" that produce two different binaries.
    One for high-performance fast rendering for release to customers.
    Then one for developers when developing and debugging to perform checks to ensure integrity and correctness.

    Comment


    • #3
      Originally posted by uid313 View Post
      So then you can have two builds when you compile, "Release" and "Debug" that produce two different binaries.
      One for high-performance fast rendering for release to customers.
      Then one for developers when developing and debugging to perform checks to ensure integrity and correctness.
      Not really. It is current practice to have two builds already, for debugging and for release, but if I got it correctly, those validation layers can be activated on any build (since it is more or less at the driver level). I guess you could for instance enable it for the talos principle if you wanted.

      Does someone know if there is some integration with APITrace or similar?

      Comment


      • #4
        Originally posted by [email protected] View Post

        Not really. It is current practice to have two builds already, for debugging and for release, but if I got it correctly, those validation layers can be activated on any build (since it is more or less at the driver level). I guess you could for instance enable it for the talos principle if you wanted.

        Does someone know if there is some integration with APITrace or similar?
        Oh, so it can be activated on an already built binary instead of when compiling?

        Kind of like passing an environment variable before running the executable.

        Comment


        • #5
          Originally posted by uid313 View Post

          Oh, so it can be activated on an already built binary instead of when compiling?

          Kind of like passing an environment variable before running the executable.
          nop

          You have to enable the extension in your code, you also have to add code to handle the validation log.

          you use ifdef's

          const std::vector<const char*> validationLayers = {
          "VK_LAYER_LUNARG_standard_validation"
          };

          #ifdef NDEBUG
          const bool enableValidationLayers = false;
          #else
          const bool enableValidationLayers = true;
          #endif


          bool checkValidationLayerSupport() {
          uint32_t layerCount;
          vkEnumerateInstanceLayerProperties(&layerCount, nullptr);

          std::vector<VkLayerProperties> availableLayers(layerCount);
          vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());

          for (const char* layerName : validationLayers) {
          bool layerFound = false;

          for (const auto& layerProperties : availableLayers){
          if (strcmp(layerName, layerProperties.layerName) == 0){
          layerFound = true;
          break;
          }
          }

          if (!layerFound) return false;
          }

          return true;
          }


          .....
          if (enableValidationLayers){
          extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION _NAME);
          }
          ......


          void setupDebugCallback(){
          if (!enableValidationLayers) return;
          VkDebugReportCallbackCreateInfoEXT createInfo = {};
          createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INF O_EXT;
          createInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
          createInfo.pfnCallback = debugCallback;

          if(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, callback.replace()) != VK_SUCCESS){
          throw std::runtime_error("failed to set up debug callback!");
          }
          }

          static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
          VkDebugReportFlagsEXT flags,
          VkDebugReportObjectTypeEXT objType,
          uint64_t obj,
          size_t location,
          int32_t code,
          const char* layerPrefix,
          const char* msg,
          void* userData)
          {
          std::cerr << "Validation layer: " << msg << std::endl;
          return VK_FALSE;
          }

          Comment


          • #6
            Originally posted by RavFX View Post

            nop

            You have to enable the extension in your code, you also have to add code to handle the validation log.

            you use ifdef's

            Code:
            const std::vector<const char*> validationLayers = {
            "VK_LAYER_LUNARG_standard_validation"
            };
            
            #ifdef NDEBUG
            const bool enableValidationLayers = false;
            #else
            const bool enableValidationLayers = true;
            #endif
            
            bool checkValidationLayerSupport() {
            uint32_t layerCount;
            vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
            
            std::vector<VkLayerProperties> availableLayers(layerCount);
            vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
            
            for (const char* layerName : validationLayers) {
            bool layerFound = false;
            
            for (const auto& layerProperties : availableLayers){
            if (strcmp(layerName, layerProperties.layerName) == 0){
            layerFound = true;
            break;
            }
            }
            
            if (!layerFound) return false;
            }
            
            return true;
            }
            
            
            .....
            if (enableValidationLayers){
            extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
            }
            ......
            
            
            void setupDebugCallback(){
            if (!enableValidationLayers) return;
            VkDebugReportCallbackCreateInfoEXT createInfo = {};
            createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
            createInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
            createInfo.pfnCallback = debugCallback;
            
            if(CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, callback.replace()) != VK_SUCCESS){
            throw std::runtime_error("failed to set up debug callback!");
            }
            }
            
            static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
            VkDebugReportFlagsEXT flags,
            VkDebugReportObjectTypeEXT objType,
            uint64_t obj,
            size_t location,
            int32_t code,
            const char* layerPrefix,
            const char* msg,
            void* userData)
            {
            std::cerr << "Validation layer: " << msg << std::endl;
            return VK_FALSE;
            }
            Thank you, I stand corrected. I though it was just a matter of passing an environment variable with
            Code:
            VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_standard_validation
            Can you enable them with LD_PRELOAD, though ? I would be surprised if there isn't a mean to inject those layers somewhere in one way or another.

            Comment


            • #7
              Originally posted by [email protected] View Post

              Thank you, I stand corrected. I though it was just a matter of passing an environment variable with
              Code:
              VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_standard_validation
              Can you enable them with LD_PRELOAD, though ? I would be surprised if there isn't a mean to inject those layers somewhere in one way or another.
              You might be enable to enable it but still the application might still need manage these validation log and if it's a ifdef DEBUG that turn these parts on and your running a release build, these loggings part will be off in most apps. I tried to try with my useless triangle app I made, I broke the shaders and tried to run it that way and my system crashed. I don't know if it's the mesa I just updated (SI is not quite ready) or what.

              Comment


              • #8
                Originally posted by [email protected] View Post

                Thank you, I stand corrected. I though it was just a matter of passing an environment variable with
                Code:
                VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_standard_validation
                Can you enable them with LD_PRELOAD, though ? I would be surprised if there isn't a mean to inject those layers somewhere in one way or another.
                There is vktrace: github.com/LunarG/VulkanTools/tree/master/vktrace

                Haven't used it myself (yet), no idea how well it works.

                Comment


                • #9
                  Rust eliminates the need for a validation layer for OpenGL and Vulkan both. Those using Glium or Vulkano get their validation at compile-time with the Rust compiler. Debug/Release builds thus have no use for the optional validation checks, and are hence never used.

                  Comment


                  • #10
                    Surprised nobody has mentioned that the Steam overlay for Vulkan is implemented via a Vulkan layer.

                    Rust eliminates the need for a validation layer for OpenGL and Vulkan both. Those using Glium or Vulkano get their validation at compile-time with the Rust compiler. Debug/Release builds thus have no use for the optional validation checks, and are hence never used.
                    While it would help, the validation layer also gives hints as to improper uses that may actually be technically correct ways to use the API. This is something Rust can't really moderate on.

                    In addition, the debug validation layers help with tracking various resources and can be used as a runtime tracing tool to help rendering artifacts and engine bugs.

                    Don't be so quick to try to invalidate useful tools.

                    Comment

                    Working...
                    X