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

news/2025/10/5 13:50:14/文章来源:https://www.cnblogs.com/wzzkaifa/p/19126522

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;

    }

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/928311.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

百度自己网站排名公司网站 域名 cn com

转载于:https://www.cnblogs.com/studybrother/p/10109433.html

北京易思腾网站建设博兴县建设局官方网站

目录 1. 系统级编程 2. 游戏开发 3. 嵌入式系统 4. 大数据处理 5. 金融和量化分析 6. 人工智能和机器学习 7. 网络和通信 结语 C是一种多范式编程语言,具有高性能、中级抽象能力和面向对象的特性。由Bjarne Stroustrup于1979年首次设计并实现,C在…

【LUT技术专题】图像自适应3DLUT - 指南

【LUT技术专题】图像自适应3DLUT - 指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Mo…

深入解析:基于51单片机的音乐盒键盘演奏proteus仿真

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

网站搭建大型公司企业电话查询黄页

目录 set 1基本用法 2Set 实例的属性和方法 3遍历操作 3.1 keys() , values() , entries() 3.2 forEach() 3.3遍历的应用 weakset 含义 语法 总结 set 1基本用法 ES6 提供了新的数据结构 Set。它类似于数组,但是成员的值都是唯一…

完整教程:AugmentFree:解除 AugmentCode 限制的终极方案 如何快速清理vscode和AugmentCode缓存—windows端

完整教程:AugmentFree:解除 AugmentCode 限制的终极方案 如何快速清理vscode和AugmentCode缓存—windows端pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; displa…

文件的物理结构II

索引分配 允许文件离散地分配在各磁盘块中,系统会为每一个文件建一张索引表 表中记录了文件的哥哥逻辑块对应的物理快 索引表中存放的磁盘块叫索引块 文件数据存放的磁盘块叫数据块 类似于页表 索引分配方式可以支持随…

白城网站建设哪家好金华百度推广公司

http状态码 后端调试 f8:逐行执行 f7:进入语句内部 f9:执行到下一个断点 前端调试 f10:逐行调试 f11:进入语句内部 f8:执行到下一个断点 日志 按照级别开启日志 日志的测试类 比如把application里…

03-delphi10.3下PDFium5.8的PdfView1显示相关

03-delphi10.3下PDFium5.8的PdfView1显示相关procedure TForm2.Button3Click(Sender: TObject); //正常显示 beginPdfView1.Width:= 420;PdfView1.Height:=594; end;procedure TForm2.Button4Click(Sender: TOb…

【开源程序】 黑客帝国系列系统监控软件:基于PyQt5的全方位资源监控系统

【开源程序】 黑客帝国系列系统监控软件:基于PyQt5的全方位资源监控系统2025-10-05 13:26 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: a…

ABC426

ABC426C. Upgrade Required 开一个桶来维护每种版本的电脑数量,一开始每个桶中的电脑数都是 \(1\) 用变量 \(r\) 来维护“第一个可能非空的版本号”,并且 \(r\) 只会单调递增。每次操作把 \(r\) 指向的连续若干个桶(…

muse cc 做网站wordpress 中文社区

商家转账到零钱是什么? 通过商家转账到零钱这个功能,如果我们系统需要对用户支付费用,比如发放佣金、提成、退款之类的,可以直接转账到用户的微信零钱。 【商家转账到零钱】是【企业付款到零钱】的升级版,2022年5月1…

完整教程:OS9.【Linux】基本权限(下)

完整教程:OS9.【Linux】基本权限(下)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Mona…

wordpress一个主站多个子站百度百科优化排名

腾讯云4核8G服务器支持多少人在线访问?支持25人同时访问。实际上程序效率不同支持人数在线人数不同,公网带宽也是影响4核8G服务器并发数的一大因素,假设公网带宽太小,流量直接卡在入口,4核8G配置的CPU内存也会造成计算…

怎么样在服务器上建设网站济南建设网济南市建培中心

摘要:近几年,Android系统占据着智能移动设备操作系统领域中极大的市场份额。随着Android市场中软件数量的不断攀升,移动用户对Android应用的质量要求也越来越高。如何保证Android软件的质量,成为移动应用领域中亟待解决的问题。重视移动应用的测试工作,是提高Androi…

楚雄建设局网站成都平面设计公司

从叶到花,或从花到叶,于科研是一个过程,而于生命自身则永远只在此刻。花和叶都是一种记忆方式,果子同时也是种子。生命是闪耀的此刻,不是过程,就像芳香不需要道路一样。 ——顾城《一个人应该活得是他自己并且干净》 二叉搜索树:右子树节点值都比node大,…

专业的外贸网站建设安徽合肥网站制作

1⃣️环境准备 准备 Java 环境:终端输入 java -version 命令来确认版本是否符合 Elasticsearch 要求下载并解压 Elasticsearch:前往(https://www.elastic.co/downloads/elasticsearch)选择适合你的 Mac 系统的 Elasticsearch 版本…

完整教程:JVM——云原生时代JVM的演进之路

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

价值原语博弈:AI元人文的伦理架构探索

价值原语博弈:AI元人文的伦理架构探索 在人工智能伦理研究的当前阶段,我们面临着将抽象道德原则转化为可实践框架的挑战。本文提出“价值原语博弈”作为实现AI元人文理念的一种工程化路径,通过构建动态的价值计算模…