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

相关文章

springboot3.4和mybatis plus的版本问题的解决

《springboot3.4和mybatisplus的版本问题的解决》本文主要介绍了springboot3.4和mybatisplus的版本问题的解决,主要由于SpringBoot3.4与MyBat... 报错1:spring-boot-starter/3.4.0/spring-boot-starter-

在 Spring Boot 中使用异步线程时的 HttpServletRequest 复用问题记录

《在SpringBoot中使用异步线程时的HttpServletRequest复用问题记录》文章讨论了在SpringBoot中使用异步线程时,由于HttpServletRequest复用导致... 目录一、问题描述:异步线程操作导致请求复用时 Cookie 解析失败1. 场景背景2. 问题根源二、问题详细分

解读为什么@Autowired在属性上被警告,在setter方法上不被警告问题

《解读为什么@Autowired在属性上被警告,在setter方法上不被警告问题》在Spring开发中,@Autowired注解常用于实现依赖注入,它可以应用于类的属性、构造器或setter方法上,然... 目录1. 为什么 @Autowired 在属性上被警告?1.1 隐式依赖注入1.2 IDE 的警告:

解决java.lang.NullPointerException问题(空指针异常)

《解决java.lang.NullPointerException问题(空指针异常)》本文详细介绍了Java中的NullPointerException异常及其常见原因,包括对象引用为null、数组元... 目录Java.lang.NullPointerException(空指针异常)NullPointer

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

关于Nginx跨域问题及解决方案(CORS)

《关于Nginx跨域问题及解决方案(CORS)》文章主要介绍了跨域资源共享(CORS)机制及其在现代Web开发中的重要性,通过Nginx,可以简单地解决跨域问题,适合新手学习和应用,文章详细讲解了CO... 目录一、概述二、什么是 CORS?三、常见的跨域场景四、Nginx 如何解决 CORS 问题?五、基

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

Nginx启动失败:端口80被占用问题的解决方案

《Nginx启动失败:端口80被占用问题的解决方案》在Linux服务器上部署Nginx时,可能会遇到Nginx启动失败的情况,尤其是错误提示bind()to0.0.0.0:80failed,这种问题通... 目录引言问题描述问题分析解决方案1. 检查占用端口 80 的进程使用 netstat 命令使用 ss

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多