mesa编译器input识别问题2

news/2024/11/14 22:00:51/

概述

hlsl源码如下:

struct PSInput
{float4 position : SV_POSITION;float4 color : COLOR;float4 color2 : COLOR2;
};PSInput VS(float4 pos : POSITION, float4 color : COLOR)
{PSInput result;result.position = pos;result.color = color;return result;
}float4 PS(PSInput input) : SV_Target
{return input.color + input.color2;
}

在ps生成nir的时候出现了input的base都是0的情况,具体如下:

nir_lower_io
shader: MESA_SHADER_FRAGMENT
source_sha1: {0x66390dc6, 0x70183d7d, 0x85314169, 0x1ea4ea16, 0x26fa6adc}
internal: false
stage: 4
next_stage: 0
inputs_read: 33-34
outputs_written: 4
subgroup_size: 0
bit_sizes_float: 0x20
bit_sizes_int: 0x20
origin_upper_left: true
inputs: 0
outputs: 0
uniforms: 0
decl_var system INTERP_MODE_NONE none vec4 SV_Position (SYSTEM_VALUE_FRAG_COORD)
decl_var shader_in INTERP_MODE_NONE none vec4 COLOR (VARYING_SLOT_VAR1.xyzw, 0, 0)
decl_var shader_in INTERP_MODE_NONE none vec4 COLOR_2 (VARYING_SLOT_VAR2.xyzw, 0, 0)
decl_var shader_out INTERP_MODE_NONE none vec4 SV_Target (FRAG_RESULT_DATA0.xyzw, 0, 0)
decl_function main (0 params)impl main {con block b0:   // preds:32     %0 = deref_var &COLOR_2 (shader_in vec4)32    %10 = load_const (0x00000000 = 0.000000)32x4  %11 = @load_input (%10) (base=0, range=1, component=0, dest_type=float32, io location=VARYING_SLOT_VAR2 slots=1)  // COLOR_232     %2 = deref_var &COLOR (shader_in vec4)32    %12 = load_const (0x00000000 = 0.000000)32x4  %13 = @load_input (%12) (base=0, range=1, component=0, dest_type=float32, io location=VARYING_SLOT_VAR1 slots=1)  // COLOR32     %4 = fadd %13.x, %11.x32     %5 = fadd %13.y, %11.y32     %6 = fadd %13.z, %11.z32     %7 = fadd %13.w, %11.w32     %8 = deref_var &SV_Target (shader_out vec4)32x4   %9 = vec4 %4, %5, %6, %7@store_deref (%8, %9) (wrmask=xyzw, access=none)return (pass_flags: 0xcd)// succs: b1block b1:
}

其中%11和%13的load_input的base都是0,出现错误。

分析

用mesa源代码编译好,使用mesa编译出现的驱动去绘制三角形。fs源代码如下

#version 430layout(location = 1) in vec4 COLOR;
layout(location = 2) in vec4 COLOR2;
out vec4 FragColor;void main()
{FragColor = COLOR + COLOR2;
}

nir如下:

shader: MESA_SHADER_VERTEX
source_blake3: {0x7338de06, 0x8f93c5b1, 0xe49d7e79, 0xe70d38eb, 0xcfc0ab1f, 0x0f3bb3fd, 0xfc42e485, 0xb2e36f24}
name: GLSL3
internal: false
stage: 0
next_stage: 4
inputs_read: 15,18
outputs_written: 0,33-34
subgroup_size: 1
bit_sizes_float: 0x20
bit_sizes_int: 0x20
flrp_lowered: true
inputs: 2
outputs: 3
uniforms: 0
decl_var shader_in INTERP_MODE_NONE none vec3 aPos (VERT_ATTRIB_GENERIC0.xyz, 0, 0)
decl_var shader_in INTERP_MODE_NONE none vec4 aPos2 (VERT_ATTRIB_GENERIC3.xyzw, 1, 0)
decl_var shader_out INTERP_MODE_NONE none vec4 gl_Position (VARYING_SLOT_POS.xyzw, 0, 0)
decl_var shader_out INTERP_MODE_NONE none vec4 COLOR (VARYING_SLOT_VAR1.xyzw, 1, 0)
decl_var shader_out INTERP_MODE_NONE none vec4 COLOR2 (VARYING_SLOT_VAR2.xyzw, 2, 0)
decl_function main (0 params)impl main {con block b0:   // preds: 32     %0(driver_location=0) = deref_var &aPos (shader_in vec3)32x3   %1 = @load_deref (%0) (access=none)32     %2(driver_location=1) = deref_var &aPos2 (shader_in vec4)32x4   %3 = @load_deref (%2) (access=none)32     %4 = load_const (0x3f800000 = 1.000000 = 1065353216)32x4   %5 = vec4 %1.x, %1.y, %1.z, %432x4   %6 = fadd %5, %332     %7(driver_location=0) = deref_var &gl_Position (shader_out vec4)@store_deref (%7, %6) (wrmask=xyzw, access=none)32     %8(driver_location=1) = deref_var &COLOR (shader_out vec4)@store_deref (%8, %3) (wrmask=xyzw, access=none)32     %9(driver_location=2) = deref_var &COLOR2 (shader_out vec4)@store_deref (%9, %3) (wrmask=xyzw, access=none)// succs: b1 block b1:
}

其中driver_location是自己添加上的,其实就是base。
由上面可以知道,mesa做了处理,说明我们漏掉了一些步骤。

解决

通过调试源码可以知道,添加以下代码可以解决问题。

/* Depending on PIPE_CAP_TGSI_TEXCOORD (st->needs_texcoord_semantic) we* may need to fix up varying slots so the glsl->nir path is aligned* with the anything->tgsi->nir path.*/
static void
st_nir_fixup_varying_slots(/*struct st_context* st, */nir_shader* shader, nir_variable_mode mode)
{//if (st->needs_texcoord_semantic)//    return;/* This is called from finalize, but we don't want to do this adjustment twice. *///assert(!st->allow_st_finalize_nir_twice);nir_foreach_variable_with_modes(var, shader, mode) {if (var->data.location >= VARYING_SLOT_VAR0 && var->data.location < VARYING_SLOT_PATCH0) {var->data.location += 9;}else if (var->data.location == VARYING_SLOT_PNTC) {var->data.location = VARYING_SLOT_VAR8;}else if ((var->data.location >= VARYING_SLOT_TEX0) &&(var->data.location <= VARYING_SLOT_TEX7)) {var->data.location += VARYING_SLOT_VAR0 - VARYING_SLOT_TEX0;}}
}void
st_nir_assign_varying_locations(/*struct st_context* st, */nir_shader* nir)
{/* Lowered IO don't have variables, so exit. */if (nir->info.io_lowered)return;if (nir->info.stage == MESA_SHADER_VERTEX) {nir_assign_io_var_locations(nir, nir_var_shader_out,&nir->num_outputs,nir->info.stage);st_nir_fixup_varying_slots(/*st, */nir, nir_var_shader_out);}else if (nir->info.stage == MESA_SHADER_GEOMETRY ||nir->info.stage == MESA_SHADER_TESS_CTRL ||nir->info.stage == MESA_SHADER_TESS_EVAL) {nir_assign_io_var_locations(nir, nir_var_shader_in,&nir->num_inputs,nir->info.stage);st_nir_fixup_varying_slots(/*st, */nir, nir_var_shader_in);nir_assign_io_var_locations(nir, nir_var_shader_out,&nir->num_outputs,nir->info.stage);st_nir_fixup_varying_slots(/*st, */nir, nir_var_shader_out);}else if (nir->info.stage == MESA_SHADER_FRAGMENT) {nir_assign_io_var_locations(nir, nir_var_shader_in,&nir->num_inputs,nir->info.stage);st_nir_fixup_varying_slots(/*st, */nir, nir_var_shader_in);nir_assign_io_var_locations(nir, nir_var_shader_out,&nir->num_outputs,nir->info.stage);}else if (nir->info.stage == MESA_SHADER_COMPUTE) {/* TODO? */}else {unreachable("invalid shader type");}
}

上面的与st相关的注释是自己加的,后续需要考虑上下文。


http://www.ppmy.cn/news/1468693.html

相关文章

鸿蒙开发接口安全:【@ohos.abilityAccessCtrl (访问控制管理)】

访问控制管理 说明&#xff1a; 本模块首批接口从API version 8开始支持。后续版本的新增接口&#xff0c;采用上角标单独标记接口的起始版本。 导入模块 import abilityAccessCtrl from ohos.abilityAccessCtrlabilityAccessCtrl.createAtManager createAtManager(): AtMan…

Einstein Summation 爱因斯坦求和 torch.einsum

Einstein Summation 爱因斯坦求和 torch.einsum flyfish 理解爱因斯坦求和的基本概念和语法&#xff0c;这对初学者来说可能有一定难度。对于不熟悉该表示法的用户来说&#xff0c;可能不如直接的矩阵乘法表达式易于理解。 整个思路是 向量的点积 -》矩阵乘法-》einsum 向…

Visual Studio的快捷按键

Visual Studio的快捷按键对于提高编程效率至关重要。以下是一些常用的Visual Studio快捷按键&#xff0c;并按照功能进行分类和归纳&#xff1a; 1. 文件操作 Ctrl O&#xff1a;打开文件Ctrl S&#xff1a;保存文件Ctrl Shift S&#xff1a;全部保存Ctrl N&#xff1a;…

【LeetCode】42.接雨水

接雨水 题目描述&#xff1a; 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图&#xff0c;计算按此排列的柱子&#xff0c;下雨之后能接多少雨水。 示例 1&#xff1a; 输入&#xff1a;height [0,1,0,2,1,0,1,3,2,1,2,1] 输出&#xff1a;6 解释&#xff1a;上面是由数…

PostgreSQL中有没有类似Oracle的dba_objects系统视图

PostgreSQL中有没有类似Oracle的dba_objects系统视图 在PostgreSQL中&#xff0c;没有一个完全集成了所有对象信息的视图&#xff08;类似于Oracle中的DBA_OBJECTS&#xff09;。但是&#xff0c;PostgreSQL提供了一些系统目录表和视图&#xff0c;可以用来获取数据库对象的信…

机器学习笔记 - stable diffusion web-ui安装教程

一、Stable Diffusion WEB UI 屌丝劲发作了,所以本地调试了Stable Diffusion之后,就去看了一下Stable Diffusion WEB UI,网络上各种打包套件什么的好像很火。国内的也就这个层次了,老外搞创新,国内跟着屁股后面搞搞应用层,就叫大神了。 不扯闲篇了,我们这里从git源码直接…

mac配置Personal Access Tokens

背景 在macbook环境中&#xff0c;使用idea、android studio、xcode时&#xff0c;使用gitlab需要登录&#xff0c;而直接使用文明密码是不允许登录的&#xff0c;这时就需要换种方式&#xff0c;这里有两种&#xff1a;ssh、Access Tokens&#xff0c;在公用电脑上推荐使用Ac…

[译文] LLM安全:3.网络LLM攻击及提示注入知识普及(PortSwigger)

这是作者新开的一个专栏&#xff0c;主要翻译国外知名安全厂商的技术报告和安全技术&#xff0c;了解它们的前沿技术&#xff0c;学习它们威胁溯源和恶意代码分析的方法&#xff0c;希望对您有所帮助。当然&#xff0c;由于作者英语有限&#xff0c;会借助LLM进行校验和润色&am…