尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

vulkan游戏引擎的vulkan_utils实现 - 教程

vulkan游戏引擎的vulkan_utils实现 - 教程
📅 发布时间:2026/6/20 2:14:07

1.vulkan_utils.h

#pragma once

#include "vulkan_types.inl"


 

const char* vulkan_result_string(VkResult result,b8 get_extended);

b8 vulkan_result_is_success(VkResult result);



2.vulkan_utils.c

#include "vulkan_utils.h"

const char* vulkan_result_string(VkResult result, b8 get_extended) {

   

    // Success Codes

    switch (result) {

        default:

        case VK_SUCCESS:

            return !get_extended ? "VK_SUCCESS" : "VK_SUCCESS Command successfully completed";

        case VK_NOT_READY:

            return !get_extended ? "VK_NOT_READY" : "VK_NOT_READY A fence or query has not yet completed";

        case VK_TIMEOUT:

            return !get_extended ? "VK_TIMEOUT" : "VK_TIMEOUT A wait operation has not completed in the specifiedtime";

        case VK_EVENT_SET:

            return !get_extended ? "VK_EVENT_SET" : "VK_EVENT_SET An event is signaled";

        case VK_EVENT_RESET:

            return !get_extended ? "VK_EVENT_RESET" : "VK_EVENT_RESET An event is unsignaled";

        case VK_INCOMPLETE:

            return !get_extended ? "VK_INCOMPLETE" : "VK_INCOMPLETE A returnarraywas too small for the result";

        case VK_SUBOPTIMAL_KHR:

            return !get_extended ? "VK_SUBOPTIMAL_KHR" : "VK_SUBOPTIMAL_KHR A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully.";

        case VK_THREAD_IDLE_KHR:

            return !get_extended ? "VK_THREAD_IDLE_KHR" : "VK_THREAD_IDLE_KHR A deferred operation is not complete but there is currently no work for this thread to do at the time of this call.";

        case VK_THREAD_DONE_KHR:

            return !get_extended ? "VK_THREAD_DONE_KHR" : "VK_THREAD_DONE_KHR A deferred operation is not complete but there is no work remaining to assign to additional threads.";

        case VK_OPERATION_DEFERRED_KHR:

            return !get_extended ? "VK_OPERATION_DEFERRED_KHR" : "VK_OPERATION_DEFERRED_KHR A deferred operation was requested and at least some of the work was deferred.";

        case VK_OPERATION_NOT_DEFERRED_KHR:

            return !get_extended ? "VK_OPERATION_NOT_DEFERRED_KHR" : "VK_OPERATION_NOT_DEFERRED_KHR A deferred operation was requested and no operations were deferred.";

        case VK_PIPELINE_COMPILE_REQUIRED_EXT:

            return !get_extended ? "VK_PIPELINE_COMPILE_REQUIRED_EXT" : "VK_PIPELINE_COMPILE_REQUIRED_EXT A requested pipeline creation would have required compilation, but the application requested compilation to not be performed.";

        // Error codes

        case VK_ERROR_OUT_OF_HOST_MEMORY:

            return !get_extended ? "VK_ERROR_OUT_OF_HOST_MEMORY" : "VK_ERROR_OUT_OF_HOST_MEMORY A host memory allocation has failed.";

        case VK_ERROR_OUT_OF_DEVICE_MEMORY:

            return !get_extended ? "VK_ERROR_OUT_OF_DEVICE_MEMORY" : "VK_ERROR_OUT_OF_DEVICE_MEMORY A device memory allocation has failed.";

        case VK_ERROR_INITIALIZATION_FAILED:

            return !get_extended ? "VK_ERROR_INITIALIZATION_FAILED" : "VK_ERROR_INITIALIZATION_FAILED Initialization of an object could not be completed for implementation-specific reasons.";

        case VK_ERROR_DEVICE_LOST:

            return !get_extended ? "VK_ERROR_DEVICE_LOST" : "VK_ERROR_DEVICE_LOST The logical or physical device has been lost. See Lost Device";

        case VK_ERROR_MEMORY_MAP_FAILED:

            return !get_extended ? "VK_ERROR_MEMORY_MAP_FAILED" : "VK_ERROR_MEMORY_MAP_FAILED Mapping of a memory object has failed.";

        case VK_ERROR_LAYER_NOT_PRESENT:

            return !get_extended ? "VK_ERROR_LAYER_NOT_PRESENT" : "VK_ERROR_LAYER_NOT_PRESENT A requested layer is not present or could not be loaded.";

        case VK_ERROR_EXTENSION_NOT_PRESENT:

            return !get_extended ? "VK_ERROR_EXTENSION_NOT_PRESENT" : "VK_ERROR_EXTENSION_NOT_PRESENT A requested extension is not supported.";

        case VK_ERROR_FEATURE_NOT_PRESENT:

            return !get_extended ? "VK_ERROR_FEATURE_NOT_PRESENT" : "VK_ERROR_FEATURE_NOT_PRESENT A requested feature is not supported.";

        case VK_ERROR_INCOMPATIBLE_DRIVER:

            return !get_extended ? "VK_ERROR_INCOMPATIBLE_DRIVER" : "VK_ERROR_INCOMPATIBLE_DRIVER The requested version of Vulkan is not supported by the driver or is otherwise incompatible for implementation-specific reasons.";

        case VK_ERROR_TOO_MANY_OBJECTS:

            return !get_extended ? "VK_ERROR_TOO_MANY_OBJECTS" : "VK_ERROR_TOO_MANY_OBJECTS Too many objects of the type have already been created.";

        case VK_ERROR_FORMAT_NOT_SUPPORTED:

            return !get_extended ? "VK_ERROR_FORMAT_NOT_SUPPORTED" : "VK_ERROR_FORMAT_NOT_SUPPORTED A requested format is not supported on this device.";

        case VK_ERROR_FRAGMENTED_POOL:

            return !get_extended ? "VK_ERROR_FRAGMENTED_POOL" : "VK_ERROR_FRAGMENTED_POOL A pool allocation has failed due to fragmentation of the pool’s memory. This must only be returned if no attempt to allocate host or device memory was made to accommodate the new allocation. This should be returned in preference to VK_ERROR_OUT_OF_POOL_MEMORY, but only if the implementation is certain that the pool allocation failure was due to fragmentation.";

        case VK_ERROR_SURFACE_LOST_KHR:

            return !get_extended ? "VK_ERROR_SURFACE_LOST_KHR" : "VK_ERROR_SURFACE_LOST_KHR A surface is no longer available.";

        case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:

            return !get_extended ? "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR" : "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR The requested window is already in use by Vulkan or another API in a manner which prevents it from being used again.";

        case VK_ERROR_OUT_OF_DATE_KHR:

            return !get_extended ? "VK_ERROR_OUT_OF_DATE_KHR" : "VK_ERROR_OUT_OF_DATE_KHR A surface has changed in such a way that it is no longer compatible with the swapchain, and further presentation requests using the swapchain will fail. Applications must query the new surface properties and recreate their swapchain if they wish to continue presenting to the surface.";

        case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:

            return !get_extended ? "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR" : "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR The display used by a swapchain does not use the same presentable image layout, or is incompatible in a way that prevents sharing an image.";

        case VK_ERROR_INVALID_SHADER_NV:

            return !get_extended ? "VK_ERROR_INVALID_SHADER_NV" : "VK_ERROR_INVALID_SHADER_NV One or more shaders failed to compile or link. More details are reported back to the application via VK_EXT_debug_report if enabled.";

        case VK_ERROR_OUT_OF_POOL_MEMORY:

            return !get_extended ? "VK_ERROR_OUT_OF_POOL_MEMORY" : "VK_ERROR_OUT_OF_POOL_MEMORY A pool memory allocation has failed. This must only be returned if no attempt to allocate host or device memory was made to accommodate the new allocation. If the failure was definitely due to fragmentation of the pool, VK_ERROR_FRAGMENTED_POOL should be returned instead.";

        case VK_ERROR_INVALID_EXTERNAL_HANDLE:

            return !get_extended ? "VK_ERROR_INVALID_EXTERNAL_HANDLE" : "VK_ERROR_INVALID_EXTERNAL_HANDLE An external handle is not a valid handle of the specified type.";

        case VK_ERROR_FRAGMENTATION:

            return !get_extended ? "VK_ERROR_FRAGMENTATION" : "VK_ERROR_FRAGMENTATION A descriptor pool creation has failed due to fragmentation.";

        case VK_ERROR_INVALID_DEVICE_ADDRESS_EXT:

            return !get_extended ? "VK_ERROR_INVALID_DEVICE_ADDRESS_EXT" : "VK_ERROR_INVALID_DEVICE_ADDRESS_EXT A buffer creation failed because the requested address is not available.";

        // NOTE: Same as above

        // case VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS:

        //    return !get_extended ? "VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS" :"VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS A buffer creation or memory allocation failed because the requested address is not available. A shader group handle assignment failed because the requested shader group handle information is no longer valid.";

        case VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:

            return !get_extended ? "VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT" : "VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT An operation on a swapchain created with VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT failed as it did not have exlusive full-screen access. This may occur due to implementation-dependent reasons, outside of the application’s control.";

        case VK_ERROR_UNKNOWN:

            return !get_extended ? "VK_ERROR_UNKNOWN" : "VK_ERROR_UNKNOWN An unknown error has occurred; either the application has provided invalid input, or an implementation failure has occurred.";

        case VK_ERROR_VALIDATION_FAILED_EXT:

            return !get_extended ? "VK_ERROR_VALIDATION_FAILED_EXT" : "A command failed because invalid usage was detected by the implementation or a validation-layer.";

    }

}


 

b8 vulkan_result_is_success(VkResult result) {

    // From: https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkResult.html

    switch (result) {

        default:

            // Success Codes

        case VK_SUCCESS:

        case VK_NOT_READY:

        case VK_TIMEOUT:

        case VK_EVENT_SET:

        case VK_EVENT_RESET:

        case VK_INCOMPLETE:

        case VK_SUBOPTIMAL_KHR:

        case VK_THREAD_IDLE_KHR:

        case VK_THREAD_DONE_KHR:

        case VK_OPERATION_DEFERRED_KHR:

        case VK_OPERATION_NOT_DEFERRED_KHR:

        case VK_PIPELINE_COMPILE_REQUIRED_EXT:

            return true;

        // Error codes

        case VK_ERROR_OUT_OF_HOST_MEMORY:

        case VK_ERROR_OUT_OF_DEVICE_MEMORY:

        case VK_ERROR_INITIALIZATION_FAILED:

        case VK_ERROR_DEVICE_LOST:

        case VK_ERROR_MEMORY_MAP_FAILED:

        case VK_ERROR_LAYER_NOT_PRESENT:

        case VK_ERROR_EXTENSION_NOT_PRESENT:

        case VK_ERROR_FEATURE_NOT_PRESENT:

        case VK_ERROR_INCOMPATIBLE_DRIVER:

        case VK_ERROR_TOO_MANY_OBJECTS:

        case VK_ERROR_FORMAT_NOT_SUPPORTED:

        case VK_ERROR_FRAGMENTED_POOL:

        case VK_ERROR_SURFACE_LOST_KHR:

        case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:

        case VK_ERROR_OUT_OF_DATE_KHR:

        case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:

        case VK_ERROR_INVALID_SHADER_NV:

        case VK_ERROR_OUT_OF_POOL_MEMORY:

        case VK_ERROR_INVALID_EXTERNAL_HANDLE:

        case VK_ERROR_FRAGMENTATION:

        case VK_ERROR_INVALID_DEVICE_ADDRESS_EXT:

        // NOTE: Same as above

        // case VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS:

        case VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:

        case VK_ERROR_UNKNOWN:

   

            return false;

    }

}

相关新闻

  • 深入解析:基于51单片机的音乐盒键盘演奏proteus仿真
  • 03-delphi10.3下PDFium5.8的PdfView1显示相关
  • arEPRP and arEHS

最新新闻

  • 杭州GEO优化公司2026年6月Top5:选型疑问与避坑全解 - GEO优化
  • 2026年最新武汉光谷科技职业技术学校联系方式及招生办电话号码 - 武汉中职最新信息发布
  • 揭秘Mac鼠标滚轮终极优化:让外接鼠标拥有触控板般的丝滑体验
  • MC9RS08KA2内部时钟与定时器深度解析:从原理到低功耗设计实战
  • 2026玉林本地人必选防水补漏检测维修公司靠谱服务商TOP5推荐:房屋渗漏水检测维修/卫生间/厨房/天花板/阳台/外墙渗漏水检测补漏维修-暗管漏水检测专业仪器精准定位漏水点 - 即刻修防水
  • PingFangSC字体实战:现代Web开发中的跨平台中文字体终极配置指南

日新闻

  • 信任的进化:技术实现详解——如何用JavaScript构建博弈论模拟器
  • Terrakube自定义工作流:如何集成OPA、Infracost等工具扩展IaC能力
  • grunt-concurrent快速入门:5分钟学会并行运行Grunt任务

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号