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

相关文章

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

解决RocketMQ的幂等性问题

《解决RocketMQ的幂等性问题》重复消费因调用链路长、消息发送超时或消费者故障导致,通过生产者消息查询、Redis缓存及消费者唯一主键可以确保幂等性,避免重复处理,本文主要介绍了解决RocketM... 目录造成重复消费的原因解决方法生产者端消费者端代码实现造成重复消费的原因当系统的调用链路比较长的时

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

kkFileView启动报错:报错2003端口占用的问题及解决

《kkFileView启动报错:报错2003端口占用的问题及解决》kkFileView启动报错因office组件2003端口未关闭,解决:查杀占用端口的进程,终止Java进程,使用shutdown.s... 目录原因解决总结kkFileViewjavascript启动报错启动office组件失败,请检查of

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原