mesa编译器nir信息储存问题

2024-06-18 20:20

本文主要是介绍mesa编译器nir信息储存问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

概述

本来想将一个完整的可以从hlsl-dxil-spirv-nir-code的项目划分为两个动态库a.dll与b.dll。应用程序调用a.dll与b.dll执行相同的过程。
a.dll:执行dxil-spirv-nir前端相关的转换。
b.dll:执行nir-code的转换。
应用程序调用dxc实现hlsl-dxil的过程,调用a.dll实现dxil-spirv-nir过程,调用b.dll实现nir-code过程。
想法是好的,可以使代码结构清晰。
不过出现了问题,在b.dll实现nir-code过程出现崩溃

分析

在spirv-nir过程是可以的,在nir-code过程中执行pass出现错误

nir_shader* nir = spirv_to_nir((uint32_t*)spirv.data, word_count, NULL, 0,entry_point.stage, entry_point.name,&spirv_opts, &nir_opts);

原因是nir_opts参数控制了很多lower的行为。在进入b.dll执行nir-code过程,nir_opts所有的数据都为0了。
后来想一想,每个动态库都是一个独立的程序,全局变量不能跨程序保留值。
查阅nir结构,看看有没有保留的地方,结果发现了,如下

typedef struct nir_shader {gc_ctx *gctx;/** list of uniforms (nir_variable) */struct exec_list variables;/** Set of driver-specific options for the shader.** The memory for the options is expected to be kept in a single static* copy by the driver.*/const struct nir_shader_compiler_options *options;/** Various bits of compile-time information about a given shader */struct shader_info info;/** list of nir_function */struct exec_list functions;/*** The size of the variable space for load_input_*, load_uniform_*, etc.* intrinsics.  This is in back-end specific units which is likely one of* bytes, dwords, or vec4s depending on context and back-end.*/unsigned num_inputs, num_uniforms, num_outputs;/** Size in bytes of required implicitly bound global memory */unsigned global_mem_size;/** Size in bytes of required scratch space */unsigned scratch_size;/** Constant data associated with this shader.** Constant data is loaded through load_constant intrinsics (as compared to* the NIR load_const instructions which have the constant value inlined* into them).  This is usually generated by nir_opt_large_constants (so* shaders don't have to load_const into a temporary array when they want* to indirect on a const array).*/void *constant_data;/** Size of the constant data associated with the shader, in bytes */unsigned constant_data_size;struct nir_xfb_info *xfb_info;unsigned printf_info_count;u_printf_info *printf_info;
} nir_shader;

const struct nir_shader_compiler_options *options;就是保存option的地方。
在调用完a.dll之后,通过手动给他们复制,发现暂时可以解决问题。

不过运行到后面又出现问题

NIR_PASS_V(nir, nir_split_var_copies);

在上面pass宏定义中,执行nir_shader_serialize_deserialize函数崩溃,在该函数中执行glsl_array_type函数崩溃。

const glsl_type *
glsl_array_type(const glsl_type *element,unsigned array_size,unsigned explicit_stride)
{/* Ensure there's no internal padding, to avoid multiple hashes for same key. */STATIC_ASSERT(sizeof(struct array_key) == (3 * sizeof(uintptr_t)));struct array_key key = { 0 };key.element = (uintptr_t)element;key.array_size = array_size;key.explicit_stride = explicit_stride;const uint32_t key_hash = array_key_hash(&key);simple_mtx_lock(&glsl_type_cache_mutex);assert(glsl_type_cache.users > 0);   //崩溃在这里,glsl_type_cache全局变量都是0void *mem_ctx = glsl_type_cache.mem_ctx;if (glsl_type_cache.array_types == NULL) {glsl_type_cache.array_types = array_key_table_create(mem_ctx);}struct hash_table *array_types = glsl_type_cache.array_types;const struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(array_types, key_hash, &key);if (entry == NULL) {linear_ctx *lin_ctx = glsl_type_cache.lin_ctx;const glsl_type *t = make_array_type(lin_ctx, element, array_size, explicit_stride);struct array_key *stored_key = linear_zalloc(lin_ctx, struct array_key);memcpy(stored_key, &key, sizeof(key));entry = _mesa_hash_table_insert_pre_hashed(array_types, key_hash,stored_key,(void *) t);}const glsl_type *t = (const glsl_type *) entry->data;simple_mtx_unlock(&glsl_type_cache_mutex);assert(t->base_type == GLSL_TYPE_ARRAY);assert(t->length == array_size);assert(t->fields.array == element);return t;
}

发现glsl_type_cache全局结构体成员变量都是0。
至此,可以得出结论,在spirv-nir转换的过程中,对很多全局变量赋值了,如果不在同一个动态库中调用,那么就会出现全局变量统统为0的情况。

解决

将dxil-spirv-nir-code写到同一个动态库a.dll中,应用程序调用dxc实现hlsl-dxil的过程,调用a.dll实现dxil-spirv-nir-code过程,发现问题全部解决。

这篇关于mesa编译器nir信息储存问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1072992

相关文章

IDEA和GIT关于文件中LF和CRLF问题及解决

《IDEA和GIT关于文件中LF和CRLF问题及解决》文章总结:因IDEA默认使用CRLF换行符导致Shell脚本在Linux运行报错,需在编辑器和Git中统一为LF,通过调整Git的core.aut... 目录问题描述问题思考解决过程总结问题描述项目软件安装shell脚本上git仓库管理,但拉取后,上l

idea npm install很慢问题及解决(nodejs)

《ideanpminstall很慢问题及解决(nodejs)》npm安装速度慢可通过配置国内镜像源(如淘宝)、清理缓存及切换工具解决,建议设置全局镜像(npmconfigsetregistryht... 目录idea npm install很慢(nodejs)配置国内镜像源清理缓存总结idea npm in

pycharm跑python项目易出错的问题总结

《pycharm跑python项目易出错的问题总结》:本文主要介绍pycharm跑python项目易出错问题的相关资料,当你在PyCharm中运行Python程序时遇到报错,可以按照以下步骤进行排... 1. 一定不要在pycharm终端里面创建环境安装别人的项目子模块等,有可能出现的问题就是你不报错都安装

idea突然报错Malformed \uxxxx encoding问题及解决

《idea突然报错Malformeduxxxxencoding问题及解决》Maven项目在切换Git分支时报错,提示project元素为描述符根元素,解决方法:删除Maven仓库中的resolv... 目www.chinasem.cn录问题解决方式总结问题idea 上的 maven China编程项目突然报错,是

Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题

《Python爬虫HTTPS使用requests,httpx,aiohttp实战中的证书异步等问题》在爬虫工程里,“HTTPS”是绕不开的话题,HTTPS为传输加密提供保护,同时也给爬虫带来证书校验、... 目录一、核心问题与优先级检查(先问三件事)二、基础示例:requests 与证书处理三、高并发选型:

前端导出Excel文件出现乱码或文件损坏问题的解决办法

《前端导出Excel文件出现乱码或文件损坏问题的解决办法》在现代网页应用程序中,前端有时需要与后端进行数据交互,包括下载文件,:本文主要介绍前端导出Excel文件出现乱码或文件损坏问题的解决办法,... 目录1. 检查后端返回的数据格式2. 前端正确处理二进制数据方案 1:直接下载(推荐)方案 2:手动构造

Python绘制TSP、VRP问题求解结果图全过程

《Python绘制TSP、VRP问题求解结果图全过程》本文介绍用Python绘制TSP和VRP问题的静态与动态结果图,静态图展示路径,动态图通过matplotlib.animation模块实现动画效果... 目录一、静态图二、动态图总结【代码】python绘制TSP、VRP问题求解结果图(包含静态图与动态图

MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决

《MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决》MyBatis默认开启一级缓存,同一事务中循环调用查询方法时会重复使用缓存数据,导致获取的序列主键值均为1,... 目录问题原因解决办法如果是存储过程总结问题myBATis有如下代码获取序列作为主键IdMappe

linux查找java项目日志查找报错信息方式

《linux查找java项目日志查找报错信息方式》日志查找定位步骤:进入项目,用tail-f实时跟踪日志,tail-n1000查看末尾1000行,grep搜索关键词或时间,vim内精准查找并高亮定位,... 目录日志查找定位在当前文件里找到报错消息总结日志查找定位1.cd 进入项目2.正常日志 和错误日

k8s容器放开锁内存限制问题

《k8s容器放开锁内存限制问题》nccl-test容器运行mpirun时因NCCL_BUFFSIZE过大导致OOM,需通过修改docker服务配置文件,将LimitMEMLOCK设为infinity并... 目录问题问题确认放开容器max locked memory限制总结参考:https://Access