OperandManager.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using Ryujinx.Graphics.Shader.StructuredIr;
  3. using Ryujinx.Graphics.Shader.Translation;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Numerics;
  8. using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo;
  9. namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
  10. {
  11. class OperandManager
  12. {
  13. private static readonly string[] StagePrefixes = new string[] { "cp", "vp", "tcp", "tep", "gp", "fp" };
  14. private readonly struct BuiltInAttribute
  15. {
  16. public string Name { get; }
  17. public AggregateType Type { get; }
  18. public BuiltInAttribute(string name, AggregateType type)
  19. {
  20. Name = name;
  21. Type = type;
  22. }
  23. }
  24. private static Dictionary<int, BuiltInAttribute> _builtInAttributes = new Dictionary<int, BuiltInAttribute>()
  25. {
  26. { AttributeConsts.Layer, new BuiltInAttribute("gl_Layer", AggregateType.S32) },
  27. { AttributeConsts.PointSize, new BuiltInAttribute("gl_PointSize", AggregateType.FP32) },
  28. { AttributeConsts.PositionX, new BuiltInAttribute("gl_Position.x", AggregateType.FP32) },
  29. { AttributeConsts.PositionY, new BuiltInAttribute("gl_Position.y", AggregateType.FP32) },
  30. { AttributeConsts.PositionZ, new BuiltInAttribute("gl_Position.z", AggregateType.FP32) },
  31. { AttributeConsts.PositionW, new BuiltInAttribute("gl_Position.w", AggregateType.FP32) },
  32. { AttributeConsts.ClipDistance0, new BuiltInAttribute("gl_ClipDistance[0]", AggregateType.FP32) },
  33. { AttributeConsts.ClipDistance1, new BuiltInAttribute("gl_ClipDistance[1]", AggregateType.FP32) },
  34. { AttributeConsts.ClipDistance2, new BuiltInAttribute("gl_ClipDistance[2]", AggregateType.FP32) },
  35. { AttributeConsts.ClipDistance3, new BuiltInAttribute("gl_ClipDistance[3]", AggregateType.FP32) },
  36. { AttributeConsts.ClipDistance4, new BuiltInAttribute("gl_ClipDistance[4]", AggregateType.FP32) },
  37. { AttributeConsts.ClipDistance5, new BuiltInAttribute("gl_ClipDistance[5]", AggregateType.FP32) },
  38. { AttributeConsts.ClipDistance6, new BuiltInAttribute("gl_ClipDistance[6]", AggregateType.FP32) },
  39. { AttributeConsts.ClipDistance7, new BuiltInAttribute("gl_ClipDistance[7]", AggregateType.FP32) },
  40. { AttributeConsts.PointCoordX, new BuiltInAttribute("gl_PointCoord.x", AggregateType.FP32) },
  41. { AttributeConsts.PointCoordY, new BuiltInAttribute("gl_PointCoord.y", AggregateType.FP32) },
  42. { AttributeConsts.TessCoordX, new BuiltInAttribute("gl_TessCoord.x", AggregateType.FP32) },
  43. { AttributeConsts.TessCoordY, new BuiltInAttribute("gl_TessCoord.y", AggregateType.FP32) },
  44. { AttributeConsts.InstanceId, new BuiltInAttribute("gl_InstanceID", AggregateType.S32) },
  45. { AttributeConsts.VertexId, new BuiltInAttribute("gl_VertexID", AggregateType.S32) },
  46. { AttributeConsts.BaseInstance, new BuiltInAttribute("gl_BaseInstanceARB", AggregateType.S32) },
  47. { AttributeConsts.BaseVertex, new BuiltInAttribute("gl_BaseVertexARB", AggregateType.S32) },
  48. { AttributeConsts.InstanceIndex, new BuiltInAttribute("gl_InstanceIndex", AggregateType.S32) },
  49. { AttributeConsts.VertexIndex, new BuiltInAttribute("gl_VertexIndex", AggregateType.S32) },
  50. { AttributeConsts.DrawIndex, new BuiltInAttribute("gl_DrawIDARB", AggregateType.S32) },
  51. { AttributeConsts.FrontFacing, new BuiltInAttribute("gl_FrontFacing", AggregateType.Bool) },
  52. // Special.
  53. { AttributeConsts.FragmentOutputDepth, new BuiltInAttribute("gl_FragDepth", AggregateType.FP32) },
  54. { AttributeConsts.ThreadKill, new BuiltInAttribute("gl_HelperInvocation", AggregateType.Bool) },
  55. { AttributeConsts.ThreadIdX, new BuiltInAttribute("gl_LocalInvocationID.x", AggregateType.U32) },
  56. { AttributeConsts.ThreadIdY, new BuiltInAttribute("gl_LocalInvocationID.y", AggregateType.U32) },
  57. { AttributeConsts.ThreadIdZ, new BuiltInAttribute("gl_LocalInvocationID.z", AggregateType.U32) },
  58. { AttributeConsts.CtaIdX, new BuiltInAttribute("gl_WorkGroupID.x", AggregateType.U32) },
  59. { AttributeConsts.CtaIdY, new BuiltInAttribute("gl_WorkGroupID.y", AggregateType.U32) },
  60. { AttributeConsts.CtaIdZ, new BuiltInAttribute("gl_WorkGroupID.z", AggregateType.U32) },
  61. { AttributeConsts.LaneId, new BuiltInAttribute(null, AggregateType.U32) },
  62. { AttributeConsts.InvocationId, new BuiltInAttribute("gl_InvocationID", AggregateType.S32) },
  63. { AttributeConsts.PrimitiveId, new BuiltInAttribute("gl_PrimitiveID", AggregateType.S32) },
  64. { AttributeConsts.PatchVerticesIn, new BuiltInAttribute("gl_PatchVerticesIn", AggregateType.S32) },
  65. { AttributeConsts.EqMask, new BuiltInAttribute(null, AggregateType.U32) },
  66. { AttributeConsts.GeMask, new BuiltInAttribute(null, AggregateType.U32) },
  67. { AttributeConsts.GtMask, new BuiltInAttribute(null, AggregateType.U32) },
  68. { AttributeConsts.LeMask, new BuiltInAttribute(null, AggregateType.U32) },
  69. { AttributeConsts.LtMask, new BuiltInAttribute(null, AggregateType.U32) },
  70. // Support uniforms.
  71. { AttributeConsts.FragmentOutputIsBgraBase + 0, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[0]", AggregateType.Bool) },
  72. { AttributeConsts.FragmentOutputIsBgraBase + 4, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[1]", AggregateType.Bool) },
  73. { AttributeConsts.FragmentOutputIsBgraBase + 8, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[2]", AggregateType.Bool) },
  74. { AttributeConsts.FragmentOutputIsBgraBase + 12, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[3]", AggregateType.Bool) },
  75. { AttributeConsts.FragmentOutputIsBgraBase + 16, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[4]", AggregateType.Bool) },
  76. { AttributeConsts.FragmentOutputIsBgraBase + 20, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[5]", AggregateType.Bool) },
  77. { AttributeConsts.FragmentOutputIsBgraBase + 24, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[6]", AggregateType.Bool) },
  78. { AttributeConsts.FragmentOutputIsBgraBase + 28, new BuiltInAttribute($"{DefaultNames.SupportBlockIsBgraName}[7]", AggregateType.Bool) },
  79. { AttributeConsts.SupportBlockViewInverseX, new BuiltInAttribute($"{DefaultNames.SupportBlockViewportInverse}.x", AggregateType.FP32) },
  80. { AttributeConsts.SupportBlockViewInverseY, new BuiltInAttribute($"{DefaultNames.SupportBlockViewportInverse}.y", AggregateType.FP32) }
  81. };
  82. private Dictionary<AstOperand, string> _locals;
  83. public OperandManager()
  84. {
  85. _locals = new Dictionary<AstOperand, string>();
  86. }
  87. public string DeclareLocal(AstOperand operand)
  88. {
  89. string name = $"{DefaultNames.LocalNamePrefix}_{_locals.Count}";
  90. _locals.Add(operand, name);
  91. return name;
  92. }
  93. public string GetExpression(CodeGenContext context, AstOperand operand)
  94. {
  95. return operand.Type switch
  96. {
  97. OperandType.Argument => GetArgumentName(operand.Value),
  98. OperandType.Attribute => GetAttributeName(context, operand.Value, perPatch: false),
  99. OperandType.AttributePerPatch => GetAttributeName(context, operand.Value, perPatch: true),
  100. OperandType.Constant => NumberFormatter.FormatInt(operand.Value),
  101. OperandType.ConstantBuffer => GetConstantBufferName(operand, context.Config),
  102. OperandType.LocalVariable => _locals[operand],
  103. OperandType.Undefined => DefaultNames.UndefinedName,
  104. _ => throw new ArgumentException($"Invalid operand type \"{operand.Type}\".")
  105. };
  106. }
  107. private static string GetConstantBufferName(AstOperand operand, ShaderConfig config)
  108. {
  109. return GetConstantBufferName(operand.CbufSlot, operand.CbufOffset, config.Stage, config.UsedFeatures.HasFlag(FeatureFlags.CbIndexing));
  110. }
  111. public static string GetConstantBufferName(int slot, int offset, ShaderStage stage, bool cbIndexable)
  112. {
  113. return $"{GetUbName(stage, slot, cbIndexable)}[{offset >> 2}].{GetSwizzleMask(offset & 3)}";
  114. }
  115. private static string GetVec4Indexed(string vectorName, string indexExpr, bool indexElement)
  116. {
  117. if (indexElement)
  118. {
  119. return $"{vectorName}[{indexExpr}]";
  120. }
  121. string result = $"{vectorName}.x";
  122. for (int i = 1; i < 4; i++)
  123. {
  124. result = $"(({indexExpr}) == {i}) ? ({vectorName}.{GetSwizzleMask(i)}) : ({result})";
  125. }
  126. return $"({result})";
  127. }
  128. public static string GetConstantBufferName(int slot, string offsetExpr, ShaderStage stage, bool cbIndexable, bool indexElement)
  129. {
  130. return GetVec4Indexed(GetUbName(stage, slot, cbIndexable) + $"[{offsetExpr} >> 2]", offsetExpr + " & 3", indexElement);
  131. }
  132. public static string GetConstantBufferName(string slotExpr, string offsetExpr, ShaderStage stage, bool indexElement)
  133. {
  134. return GetVec4Indexed(GetUbName(stage, slotExpr) + $"[{offsetExpr} >> 2]", offsetExpr + " & 3", indexElement);
  135. }
  136. public static string GetOutAttributeName(CodeGenContext context, int value, bool perPatch)
  137. {
  138. return GetAttributeName(context, value, perPatch, isOutAttr: true);
  139. }
  140. public static string GetAttributeName(CodeGenContext context, int value, bool perPatch, bool isOutAttr = false, string indexExpr = "0")
  141. {
  142. ShaderConfig config = context.Config;
  143. if ((value & AttributeConsts.LoadOutputMask) != 0)
  144. {
  145. isOutAttr = true;
  146. }
  147. value &= AttributeConsts.Mask & ~3;
  148. char swzMask = GetSwizzleMask((value >> 2) & 3);
  149. if (perPatch)
  150. {
  151. if (value >= AttributeConsts.UserAttributePerPatchBase && value < AttributeConsts.UserAttributePerPatchEnd)
  152. {
  153. value -= AttributeConsts.UserAttributePerPatchBase;
  154. return $"{DefaultNames.PerPatchAttributePrefix}{(value >> 4)}.{swzMask}";
  155. }
  156. else if (value < AttributeConsts.UserAttributePerPatchBase)
  157. {
  158. return value switch
  159. {
  160. AttributeConsts.TessLevelOuter0 => "gl_TessLevelOuter[0]",
  161. AttributeConsts.TessLevelOuter1 => "gl_TessLevelOuter[1]",
  162. AttributeConsts.TessLevelOuter2 => "gl_TessLevelOuter[2]",
  163. AttributeConsts.TessLevelOuter3 => "gl_TessLevelOuter[3]",
  164. AttributeConsts.TessLevelInner0 => "gl_TessLevelInner[0]",
  165. AttributeConsts.TessLevelInner1 => "gl_TessLevelInner[1]",
  166. _ => null
  167. };
  168. }
  169. }
  170. else if (value >= AttributeConsts.UserAttributeBase && value < AttributeConsts.UserAttributeEnd)
  171. {
  172. int attrOffset = value;
  173. value -= AttributeConsts.UserAttributeBase;
  174. string prefix = isOutAttr
  175. ? DefaultNames.OAttributePrefix
  176. : DefaultNames.IAttributePrefix;
  177. bool indexable = config.UsedFeatures.HasFlag(isOutAttr ? FeatureFlags.OaIndexing : FeatureFlags.IaIndexing);
  178. if (indexable)
  179. {
  180. string name = prefix;
  181. if (config.Stage == ShaderStage.Geometry && !isOutAttr)
  182. {
  183. name += $"[{indexExpr}]";
  184. }
  185. return name + $"[{(value >> 4)}]." + swzMask;
  186. }
  187. else if (config.TransformFeedbackEnabled &&
  188. ((config.LastInVertexPipeline && isOutAttr) ||
  189. (config.Stage == ShaderStage.Fragment && !isOutAttr)))
  190. {
  191. int components = config.LastInPipeline ? context.Info.GetTransformFeedbackOutputComponents(attrOffset) : 1;
  192. string name = components > 1 ? $"{prefix}{(value >> 4)}" : $"{prefix}{(value >> 4)}_{swzMask}";
  193. if (AttributeInfo.IsArrayAttributeGlsl(config.Stage, isOutAttr))
  194. {
  195. name += isOutAttr ? "[gl_InvocationID]" : $"[{indexExpr}]";
  196. }
  197. return components > 1 ? name + '.' + swzMask : name;
  198. }
  199. else
  200. {
  201. string name = $"{prefix}{(value >> 4)}";
  202. if (AttributeInfo.IsArrayAttributeGlsl(config.Stage, isOutAttr))
  203. {
  204. name += isOutAttr ? "[gl_InvocationID]" : $"[{indexExpr}]";
  205. }
  206. return name + '.' + swzMask;
  207. }
  208. }
  209. else
  210. {
  211. if (value >= AttributeConsts.FragmentOutputColorBase && value < AttributeConsts.FragmentOutputColorEnd)
  212. {
  213. value -= AttributeConsts.FragmentOutputColorBase;
  214. return $"{DefaultNames.OAttributePrefix}{(value >> 4)}.{swzMask}";
  215. }
  216. else if (_builtInAttributes.TryGetValue(value, out BuiltInAttribute builtInAttr))
  217. {
  218. string subgroupMask = value switch
  219. {
  220. AttributeConsts.EqMask => "Eq",
  221. AttributeConsts.GeMask => "Ge",
  222. AttributeConsts.GtMask => "Gt",
  223. AttributeConsts.LeMask => "Le",
  224. AttributeConsts.LtMask => "Lt",
  225. _ => null
  226. };
  227. if (subgroupMask != null)
  228. {
  229. return config.GpuAccessor.QueryHostSupportsShaderBallot()
  230. ? $"unpackUint2x32(gl_SubGroup{subgroupMask}MaskARB).x"
  231. : $"gl_Subgroup{subgroupMask}Mask.x";
  232. }
  233. else if (value == AttributeConsts.LaneId)
  234. {
  235. return config.GpuAccessor.QueryHostSupportsShaderBallot()
  236. ? "gl_SubGroupInvocationARB"
  237. : "gl_SubgroupInvocationID";
  238. }
  239. if (config.Stage == ShaderStage.Fragment)
  240. {
  241. // TODO: There must be a better way to handle this...
  242. switch (value)
  243. {
  244. case AttributeConsts.PositionX: return $"(gl_FragCoord.x / {DefaultNames.SupportBlockRenderScaleName}[0])";
  245. case AttributeConsts.PositionY: return $"(gl_FragCoord.y / {DefaultNames.SupportBlockRenderScaleName}[0])";
  246. case AttributeConsts.PositionZ: return "gl_FragCoord.z";
  247. case AttributeConsts.PositionW: return "gl_FragCoord.w";
  248. case AttributeConsts.FrontFacing:
  249. if (config.GpuAccessor.QueryHostHasFrontFacingBug())
  250. {
  251. // This is required for Intel on Windows, gl_FrontFacing sometimes returns incorrect
  252. // (flipped) values. Doing this seems to fix it.
  253. return "(-floatBitsToInt(float(gl_FrontFacing)) < 0)";
  254. }
  255. break;
  256. }
  257. }
  258. string name = builtInAttr.Name;
  259. if (AttributeInfo.IsArrayAttributeGlsl(config.Stage, isOutAttr) && AttributeInfo.IsArrayBuiltIn(value))
  260. {
  261. name = isOutAttr ? $"gl_out[gl_InvocationID].{name}" : $"gl_in[{indexExpr}].{name}";
  262. }
  263. return name;
  264. }
  265. }
  266. // TODO: Warn about unknown built-in attribute.
  267. return isOutAttr ? "// bad_attr0x" + value.ToString("X") : "0.0";
  268. }
  269. public static string GetAttributeName(string attrExpr, ShaderConfig config, bool isOutAttr = false, string indexExpr = "0")
  270. {
  271. string name = isOutAttr
  272. ? DefaultNames.OAttributePrefix
  273. : DefaultNames.IAttributePrefix;
  274. if (config.Stage == ShaderStage.Geometry && !isOutAttr)
  275. {
  276. name += $"[{indexExpr}]";
  277. }
  278. return $"{name}[{attrExpr} >> 2][{attrExpr} & 3]";
  279. }
  280. public static string GetUbName(ShaderStage stage, int slot, bool cbIndexable)
  281. {
  282. if (cbIndexable)
  283. {
  284. return GetUbName(stage, NumberFormatter.FormatInt(slot, AggregateType.S32));
  285. }
  286. return $"{GetShaderStagePrefix(stage)}_{DefaultNames.UniformNamePrefix}{slot}_{DefaultNames.UniformNameSuffix}";
  287. }
  288. private static string GetUbName(ShaderStage stage, string slotExpr)
  289. {
  290. return $"{GetShaderStagePrefix(stage)}_{DefaultNames.UniformNamePrefix}[{slotExpr}].{DefaultNames.DataName}";
  291. }
  292. public static string GetSamplerName(ShaderStage stage, AstTextureOperation texOp, string indexExpr)
  293. {
  294. return GetSamplerName(stage, texOp.CbufSlot, texOp.Handle, texOp.Type.HasFlag(SamplerType.Indexed), indexExpr);
  295. }
  296. public static string GetSamplerName(ShaderStage stage, int cbufSlot, int handle, bool indexed, string indexExpr)
  297. {
  298. string suffix = cbufSlot < 0 ? $"_tcb_{handle:X}" : $"_cb{cbufSlot}_{handle:X}";
  299. if (indexed)
  300. {
  301. suffix += $"a[{indexExpr}]";
  302. }
  303. return GetShaderStagePrefix(stage) + "_" + DefaultNames.SamplerNamePrefix + suffix;
  304. }
  305. public static string GetImageName(ShaderStage stage, AstTextureOperation texOp, string indexExpr)
  306. {
  307. return GetImageName(stage, texOp.CbufSlot, texOp.Handle, texOp.Format, texOp.Type.HasFlag(SamplerType.Indexed), indexExpr);
  308. }
  309. public static string GetImageName(
  310. ShaderStage stage,
  311. int cbufSlot,
  312. int handle,
  313. TextureFormat format,
  314. bool indexed,
  315. string indexExpr)
  316. {
  317. string suffix = cbufSlot < 0
  318. ? $"_tcb_{handle:X}_{format.ToGlslFormat()}"
  319. : $"_cb{cbufSlot}_{handle:X}_{format.ToGlslFormat()}";
  320. if (indexed)
  321. {
  322. suffix += $"a[{indexExpr}]";
  323. }
  324. return GetShaderStagePrefix(stage) + "_" + DefaultNames.ImageNamePrefix + suffix;
  325. }
  326. public static string GetShaderStagePrefix(ShaderStage stage)
  327. {
  328. int index = (int)stage;
  329. if ((uint)index >= StagePrefixes.Length)
  330. {
  331. return "invalid";
  332. }
  333. return StagePrefixes[index];
  334. }
  335. private static char GetSwizzleMask(int value)
  336. {
  337. return "xyzw"[value];
  338. }
  339. public static string GetArgumentName(int argIndex)
  340. {
  341. return $"{DefaultNames.ArgumentNamePrefix}{argIndex}";
  342. }
  343. public static AggregateType GetNodeDestType(CodeGenContext context, IAstNode node, bool isAsgDest = false)
  344. {
  345. if (node is AstOperation operation)
  346. {
  347. if (operation.Inst == Instruction.LoadAttribute)
  348. {
  349. // Load attribute basically just returns the attribute value.
  350. // Some built-in attributes may have different types, so we need
  351. // to return the type based on the attribute that is being read.
  352. if (operation.GetSource(0) is AstOperand operand && operand.Type == OperandType.Constant)
  353. {
  354. if (_builtInAttributes.TryGetValue(operand.Value & ~3, out BuiltInAttribute builtInAttr))
  355. {
  356. return builtInAttr.Type;
  357. }
  358. }
  359. return OperandInfo.GetVarType(OperandType.Attribute);
  360. }
  361. else if (operation.Inst == Instruction.Call)
  362. {
  363. AstOperand funcId = (AstOperand)operation.GetSource(0);
  364. Debug.Assert(funcId.Type == OperandType.Constant);
  365. return context.GetFunction(funcId.Value).ReturnType;
  366. }
  367. else if (operation.Inst == Instruction.VectorExtract)
  368. {
  369. return GetNodeDestType(context, operation.GetSource(0)) & ~AggregateType.ElementCountMask;
  370. }
  371. else if (operation is AstTextureOperation texOp)
  372. {
  373. if (texOp.Inst == Instruction.ImageLoad ||
  374. texOp.Inst == Instruction.ImageStore ||
  375. texOp.Inst == Instruction.ImageAtomic)
  376. {
  377. return texOp.GetVectorType(texOp.Format.GetComponentType());
  378. }
  379. else if (texOp.Inst == Instruction.TextureSample)
  380. {
  381. return texOp.GetVectorType(GetDestVarType(operation.Inst));
  382. }
  383. }
  384. return GetDestVarType(operation.Inst);
  385. }
  386. else if (node is AstOperand operand)
  387. {
  388. if (operand.Type == OperandType.Argument)
  389. {
  390. int argIndex = operand.Value;
  391. return context.CurrentFunction.GetArgumentType(argIndex);
  392. }
  393. return GetOperandVarType(context, operand, isAsgDest);
  394. }
  395. else
  396. {
  397. throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\".");
  398. }
  399. }
  400. private static AggregateType GetOperandVarType(CodeGenContext context, AstOperand operand, bool isAsgDest = false)
  401. {
  402. if (operand.Type == OperandType.Attribute)
  403. {
  404. if (_builtInAttributes.TryGetValue(operand.Value & ~3, out BuiltInAttribute builtInAttr))
  405. {
  406. return builtInAttr.Type;
  407. }
  408. else if (context.Config.Stage == ShaderStage.Vertex && !isAsgDest &&
  409. operand.Value >= AttributeConsts.UserAttributeBase &&
  410. operand.Value < AttributeConsts.UserAttributeEnd)
  411. {
  412. int location = (operand.Value - AttributeConsts.UserAttributeBase) / 16;
  413. AttributeType type = context.Config.GpuAccessor.QueryAttributeType(location);
  414. return type.ToAggregateType();
  415. }
  416. }
  417. return OperandInfo.GetVarType(operand);
  418. }
  419. }
  420. }