ShaderConfig.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using Ryujinx.Graphics.Shader.StructuredIr;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Numerics;
  7. namespace Ryujinx.Graphics.Shader.Translation
  8. {
  9. class ShaderConfig
  10. {
  11. // TODO: Non-hardcoded array size.
  12. public const int SamplerArraySize = 4;
  13. private const int ThreadsPerWarp = 32;
  14. public ShaderStage Stage { get; }
  15. public bool GpPassthrough { get; }
  16. public bool LastInPipeline { get; private set; }
  17. public bool LastInVertexPipeline { get; private set; }
  18. public int ThreadsPerInputPrimitive { get; }
  19. public OutputTopology OutputTopology { get; }
  20. public int MaxOutputVertices { get; }
  21. public int LocalMemorySize { get; }
  22. public ImapPixelType[] ImapTypes { get; }
  23. public int OmapTargets { get; }
  24. public bool OmapSampleMask { get; }
  25. public bool OmapDepth { get; }
  26. public IGpuAccessor GpuAccessor { get; }
  27. public TranslationOptions Options { get; }
  28. public bool TransformFeedbackEnabled { get; }
  29. public int Size { get; private set; }
  30. public byte ClipDistancesWritten { get; private set; }
  31. public FeatureFlags UsedFeatures { get; private set; }
  32. public int Cb1DataSize { get; private set; }
  33. public bool NextUsesFixedFuncAttributes { get; private set; }
  34. public int UsedInputAttributes { get; private set; }
  35. public int UsedOutputAttributes { get; private set; }
  36. public HashSet<int> UsedInputAttributesPerPatch { get; }
  37. public HashSet<int> UsedOutputAttributesPerPatch { get; }
  38. public HashSet<int> NextUsedInputAttributesPerPatch { get; private set; }
  39. public int PassthroughAttributes { get; private set; }
  40. private int _nextUsedInputAttributes;
  41. private int _thisUsedInputAttributes;
  42. private Dictionary<int, int> _perPatchAttributeLocations;
  43. public UInt128 NextInputAttributesComponents { get; private set; }
  44. public UInt128 ThisInputAttributesComponents { get; private set; }
  45. private int _usedConstantBuffers;
  46. private int _usedStorageBuffers;
  47. private int _usedStorageBuffersWrite;
  48. private struct TextureInfo : IEquatable<TextureInfo>
  49. {
  50. public int CbufSlot { get; }
  51. public int Handle { get; }
  52. public bool Indexed { get; }
  53. public TextureFormat Format { get; }
  54. public TextureInfo(int cbufSlot, int handle, bool indexed, TextureFormat format)
  55. {
  56. CbufSlot = cbufSlot;
  57. Handle = handle;
  58. Indexed = indexed;
  59. Format = format;
  60. }
  61. public override bool Equals(object obj)
  62. {
  63. return obj is TextureInfo other && Equals(other);
  64. }
  65. public bool Equals(TextureInfo other)
  66. {
  67. return CbufSlot == other.CbufSlot && Handle == other.Handle && Indexed == other.Indexed && Format == other.Format;
  68. }
  69. public override int GetHashCode()
  70. {
  71. return HashCode.Combine(CbufSlot, Handle, Indexed, Format);
  72. }
  73. }
  74. private struct TextureMeta
  75. {
  76. public bool AccurateType;
  77. public SamplerType Type;
  78. public TextureUsageFlags UsageFlags;
  79. }
  80. private readonly Dictionary<TextureInfo, TextureMeta> _usedTextures;
  81. private readonly Dictionary<TextureInfo, TextureMeta> _usedImages;
  82. private BufferDescriptor[] _cachedConstantBufferDescriptors;
  83. private BufferDescriptor[] _cachedStorageBufferDescriptors;
  84. private TextureDescriptor[] _cachedTextureDescriptors;
  85. private TextureDescriptor[] _cachedImageDescriptors;
  86. private int _firstConstantBufferBinding;
  87. private int _firstStorageBufferBinding;
  88. public int FirstConstantBufferBinding => _firstConstantBufferBinding;
  89. public int FirstStorageBufferBinding => _firstStorageBufferBinding;
  90. public ShaderConfig(IGpuAccessor gpuAccessor, TranslationOptions options)
  91. {
  92. Stage = ShaderStage.Compute;
  93. GpuAccessor = gpuAccessor;
  94. Options = options;
  95. UsedInputAttributesPerPatch = new HashSet<int>();
  96. UsedOutputAttributesPerPatch = new HashSet<int>();
  97. _usedTextures = new Dictionary<TextureInfo, TextureMeta>();
  98. _usedImages = new Dictionary<TextureInfo, TextureMeta>();
  99. }
  100. public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationOptions options) : this(gpuAccessor, options)
  101. {
  102. Stage = header.Stage;
  103. GpPassthrough = header.Stage == ShaderStage.Geometry && header.GpPassthrough;
  104. ThreadsPerInputPrimitive = header.ThreadsPerInputPrimitive;
  105. OutputTopology = header.OutputTopology;
  106. MaxOutputVertices = header.MaxOutputVertexCount;
  107. LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize + (header.ShaderLocalMemoryCrsSize / ThreadsPerWarp);
  108. ImapTypes = header.ImapTypes;
  109. OmapTargets = header.OmapTargets;
  110. OmapSampleMask = header.OmapSampleMask;
  111. OmapDepth = header.OmapDepth;
  112. TransformFeedbackEnabled = gpuAccessor.QueryTransformFeedbackEnabled();
  113. LastInPipeline = true;
  114. LastInVertexPipeline = header.Stage < ShaderStage.Fragment;
  115. }
  116. public int GetDepthRegister()
  117. {
  118. // The depth register is always two registers after the last color output.
  119. return BitOperations.PopCount((uint)OmapTargets) + 1;
  120. }
  121. public uint ConstantBuffer1Read(int offset)
  122. {
  123. if (Cb1DataSize < offset + 4)
  124. {
  125. Cb1DataSize = offset + 4;
  126. }
  127. return GpuAccessor.ConstantBuffer1Read(offset);
  128. }
  129. public TextureFormat GetTextureFormat(int handle, int cbufSlot = -1)
  130. {
  131. // When the formatted load extension is supported, we don't need to
  132. // specify a format, we can just declare it without a format and the GPU will handle it.
  133. if (GpuAccessor.QueryHostSupportsImageLoadFormatted())
  134. {
  135. return TextureFormat.Unknown;
  136. }
  137. var format = GpuAccessor.QueryTextureFormat(handle, cbufSlot);
  138. if (format == TextureFormat.Unknown)
  139. {
  140. GpuAccessor.Log($"Unknown format for texture {handle}.");
  141. format = TextureFormat.R8G8B8A8Unorm;
  142. }
  143. return format;
  144. }
  145. private bool FormatSupportsAtomic(TextureFormat format)
  146. {
  147. return format == TextureFormat.R32Sint || format == TextureFormat.R32Uint;
  148. }
  149. public TextureFormat GetTextureFormatAtomic(int handle, int cbufSlot = -1)
  150. {
  151. // Atomic image instructions do not support GL_EXT_shader_image_load_formatted,
  152. // and must have a type specified. Default to R32Sint if not available.
  153. var format = GpuAccessor.QueryTextureFormat(handle, cbufSlot);
  154. if (!FormatSupportsAtomic(format))
  155. {
  156. GpuAccessor.Log($"Unsupported format for texture {handle}: {format}.");
  157. format = TextureFormat.R32Sint;
  158. }
  159. return format;
  160. }
  161. public void SizeAdd(int size)
  162. {
  163. Size += size;
  164. }
  165. public void InheritFrom(ShaderConfig other)
  166. {
  167. ClipDistancesWritten |= other.ClipDistancesWritten;
  168. UsedFeatures |= other.UsedFeatures;
  169. UsedInputAttributes |= other.UsedInputAttributes;
  170. UsedOutputAttributes |= other.UsedOutputAttributes;
  171. _usedConstantBuffers |= other._usedConstantBuffers;
  172. _usedStorageBuffers |= other._usedStorageBuffers;
  173. _usedStorageBuffersWrite |= other._usedStorageBuffersWrite;
  174. foreach (var kv in other._usedTextures)
  175. {
  176. if (!_usedTextures.TryAdd(kv.Key, kv.Value))
  177. {
  178. _usedTextures[kv.Key] = MergeTextureMeta(kv.Value, _usedTextures[kv.Key]);
  179. }
  180. }
  181. foreach (var kv in other._usedImages)
  182. {
  183. if (!_usedImages.TryAdd(kv.Key, kv.Value))
  184. {
  185. _usedImages[kv.Key] = MergeTextureMeta(kv.Value, _usedImages[kv.Key]);
  186. }
  187. }
  188. }
  189. public void SetInputUserAttributeFixedFunc(int index)
  190. {
  191. UsedInputAttributes |= 1 << index;
  192. }
  193. public void SetOutputUserAttributeFixedFunc(int index)
  194. {
  195. UsedOutputAttributes |= 1 << index;
  196. }
  197. public void SetInputUserAttribute(int index, int component)
  198. {
  199. int mask = 1 << index;
  200. UsedInputAttributes |= mask;
  201. _thisUsedInputAttributes |= mask;
  202. ThisInputAttributesComponents |= UInt128.One << (index * 4 + component);
  203. }
  204. public void SetInputUserAttributePerPatch(int index)
  205. {
  206. UsedInputAttributesPerPatch.Add(index);
  207. }
  208. public void SetOutputUserAttribute(int index)
  209. {
  210. UsedOutputAttributes |= 1 << index;
  211. }
  212. public void SetOutputUserAttributePerPatch(int index)
  213. {
  214. UsedOutputAttributesPerPatch.Add(index);
  215. }
  216. public void MergeFromtNextStage(ShaderConfig config)
  217. {
  218. NextInputAttributesComponents = config.ThisInputAttributesComponents;
  219. NextUsedInputAttributesPerPatch = config.UsedInputAttributesPerPatch;
  220. NextUsesFixedFuncAttributes = config.UsedFeatures.HasFlag(FeatureFlags.FixedFuncAttr);
  221. MergeOutputUserAttributes(config.UsedInputAttributes, config.UsedInputAttributesPerPatch);
  222. if (UsedOutputAttributesPerPatch.Count != 0)
  223. {
  224. // Regular and per-patch input/output locations can't overlap,
  225. // so we must assign on our location using unused regular input/output locations.
  226. Dictionary<int, int> locationsMap = new Dictionary<int, int>();
  227. int freeMask = ~UsedOutputAttributes;
  228. foreach (int attr in UsedOutputAttributesPerPatch)
  229. {
  230. int location = BitOperations.TrailingZeroCount(freeMask);
  231. if (location == 32)
  232. {
  233. config.GpuAccessor.Log($"No enough free locations for patch input/output 0x{attr:X}.");
  234. break;
  235. }
  236. locationsMap.Add(attr, location);
  237. freeMask &= ~(1 << location);
  238. }
  239. // Both stages must agree on the locations, so use the same "map" for both.
  240. _perPatchAttributeLocations = locationsMap;
  241. config._perPatchAttributeLocations = locationsMap;
  242. }
  243. LastInPipeline = false;
  244. // We don't consider geometry shaders using the geometry shader passthrough feature
  245. // as being the last because when this feature is used, it can't actually modify any of the outputs,
  246. // so the stage that comes before it is the last one that can do modifications.
  247. if (config.Stage != ShaderStage.Fragment && (config.Stage != ShaderStage.Geometry || !config.GpPassthrough))
  248. {
  249. LastInVertexPipeline = false;
  250. }
  251. }
  252. public void MergeOutputUserAttributes(int mask, IEnumerable<int> perPatch)
  253. {
  254. _nextUsedInputAttributes = mask;
  255. if (GpPassthrough)
  256. {
  257. PassthroughAttributes = mask & ~UsedOutputAttributes;
  258. }
  259. else
  260. {
  261. UsedOutputAttributes |= mask;
  262. UsedOutputAttributesPerPatch.UnionWith(perPatch);
  263. }
  264. }
  265. public int GetPerPatchAttributeLocation(int index)
  266. {
  267. if (_perPatchAttributeLocations == null || !_perPatchAttributeLocations.TryGetValue(index, out int location))
  268. {
  269. return index;
  270. }
  271. return location;
  272. }
  273. public bool IsUsedOutputAttribute(int attr)
  274. {
  275. // The check for fixed function attributes on the next stage is conservative,
  276. // returning false if the output is just not used by the next stage is also valid.
  277. if (NextUsesFixedFuncAttributes &&
  278. attr >= AttributeConsts.UserAttributeBase &&
  279. attr < AttributeConsts.UserAttributeEnd)
  280. {
  281. int index = (attr - AttributeConsts.UserAttributeBase) >> 4;
  282. return (_nextUsedInputAttributes & (1 << index)) != 0;
  283. }
  284. return true;
  285. }
  286. public int GetFreeUserAttribute(bool isOutput, int index)
  287. {
  288. int useMask = isOutput ? _nextUsedInputAttributes : _thisUsedInputAttributes;
  289. int bit = -1;
  290. while (useMask != -1)
  291. {
  292. bit = BitOperations.TrailingZeroCount(~useMask);
  293. if (bit == 32)
  294. {
  295. bit = -1;
  296. break;
  297. }
  298. else if (index < 1)
  299. {
  300. break;
  301. }
  302. useMask |= 1 << bit;
  303. index--;
  304. }
  305. return bit;
  306. }
  307. public void SetAllInputUserAttributes()
  308. {
  309. UsedInputAttributes |= Constants.AllAttributesMask;
  310. ThisInputAttributesComponents |= ~UInt128.Zero >> (128 - Constants.MaxAttributes * 4);
  311. }
  312. public void SetAllOutputUserAttributes()
  313. {
  314. UsedOutputAttributes |= Constants.AllAttributesMask;
  315. }
  316. public void SetClipDistanceWritten(int index)
  317. {
  318. ClipDistancesWritten |= (byte)(1 << index);
  319. }
  320. public void SetUsedFeature(FeatureFlags flags)
  321. {
  322. UsedFeatures |= flags;
  323. }
  324. public void SetUsedConstantBuffer(int slot)
  325. {
  326. _usedConstantBuffers |= 1 << slot;
  327. }
  328. public void SetUsedStorageBuffer(int slot, bool write)
  329. {
  330. int mask = 1 << slot;
  331. _usedStorageBuffers |= mask;
  332. if (write)
  333. {
  334. _usedStorageBuffersWrite |= mask;
  335. }
  336. }
  337. public void SetUsedTexture(
  338. Instruction inst,
  339. SamplerType type,
  340. TextureFormat format,
  341. TextureFlags flags,
  342. int cbufSlot,
  343. int handle)
  344. {
  345. inst &= Instruction.Mask;
  346. bool isImage = inst == Instruction.ImageLoad || inst == Instruction.ImageStore || inst == Instruction.ImageAtomic;
  347. bool isWrite = inst == Instruction.ImageStore || inst == Instruction.ImageAtomic;
  348. bool accurateType = inst != Instruction.Lod && inst != Instruction.TextureSize;
  349. bool coherent = flags.HasFlag(TextureFlags.Coherent);
  350. if (isImage)
  351. {
  352. SetUsedTextureOrImage(_usedImages, cbufSlot, handle, type, format, true, isWrite, false, coherent);
  353. }
  354. else
  355. {
  356. bool intCoords = flags.HasFlag(TextureFlags.IntCoords) || inst == Instruction.TextureSize;
  357. SetUsedTextureOrImage(_usedTextures, cbufSlot, handle, type, TextureFormat.Unknown, intCoords, false, accurateType, coherent);
  358. }
  359. GpuAccessor.RegisterTexture(handle, cbufSlot);
  360. }
  361. private void SetUsedTextureOrImage(
  362. Dictionary<TextureInfo, TextureMeta> dict,
  363. int cbufSlot,
  364. int handle,
  365. SamplerType type,
  366. TextureFormat format,
  367. bool intCoords,
  368. bool write,
  369. bool accurateType,
  370. bool coherent)
  371. {
  372. var dimensions = type.GetDimensions();
  373. var isIndexed = type.HasFlag(SamplerType.Indexed);
  374. var usageFlags = TextureUsageFlags.None;
  375. if (intCoords)
  376. {
  377. usageFlags |= TextureUsageFlags.NeedsScaleValue;
  378. var canScale = Stage.SupportsRenderScale() && !isIndexed && !write && dimensions == 2;
  379. if (!canScale)
  380. {
  381. // Resolution scaling cannot be applied to this texture right now.
  382. // Flag so that we know to blacklist scaling on related textures when binding them.
  383. usageFlags |= TextureUsageFlags.ResScaleUnsupported;
  384. }
  385. }
  386. if (write)
  387. {
  388. usageFlags |= TextureUsageFlags.ImageStore;
  389. }
  390. if (coherent)
  391. {
  392. usageFlags |= TextureUsageFlags.ImageCoherent;
  393. }
  394. int arraySize = isIndexed ? SamplerArraySize : 1;
  395. for (int layer = 0; layer < arraySize; layer++)
  396. {
  397. var info = new TextureInfo(cbufSlot, handle + layer * 2, isIndexed, format);
  398. var meta = new TextureMeta()
  399. {
  400. AccurateType = accurateType,
  401. Type = type,
  402. UsageFlags = usageFlags
  403. };
  404. if (dict.TryGetValue(info, out var existingMeta))
  405. {
  406. dict[info] = MergeTextureMeta(meta, existingMeta);
  407. }
  408. else
  409. {
  410. dict.Add(info, meta);
  411. }
  412. }
  413. }
  414. private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta)
  415. {
  416. meta.UsageFlags |= existingMeta.UsageFlags;
  417. // If the texture we have has inaccurate type information, then
  418. // we prefer the most accurate one.
  419. if (existingMeta.AccurateType)
  420. {
  421. meta.AccurateType = true;
  422. meta.Type = existingMeta.Type;
  423. }
  424. return meta;
  425. }
  426. public BufferDescriptor[] GetConstantBufferDescriptors()
  427. {
  428. if (_cachedConstantBufferDescriptors != null)
  429. {
  430. return _cachedConstantBufferDescriptors;
  431. }
  432. int usedMask = _usedConstantBuffers;
  433. if (UsedFeatures.HasFlag(FeatureFlags.CbIndexing))
  434. {
  435. usedMask |= (int)GpuAccessor.QueryConstantBufferUse();
  436. }
  437. return _cachedConstantBufferDescriptors = GetBufferDescriptors(
  438. usedMask,
  439. 0,
  440. UsedFeatures.HasFlag(FeatureFlags.CbIndexing),
  441. out _firstConstantBufferBinding,
  442. GpuAccessor.QueryBindingConstantBuffer);
  443. }
  444. public BufferDescriptor[] GetStorageBufferDescriptors()
  445. {
  446. if (_cachedStorageBufferDescriptors != null)
  447. {
  448. return _cachedStorageBufferDescriptors;
  449. }
  450. return _cachedStorageBufferDescriptors = GetBufferDescriptors(
  451. _usedStorageBuffers,
  452. _usedStorageBuffersWrite,
  453. true,
  454. out _firstStorageBufferBinding,
  455. GpuAccessor.QueryBindingStorageBuffer);
  456. }
  457. private static BufferDescriptor[] GetBufferDescriptors(
  458. int usedMask,
  459. int writtenMask,
  460. bool isArray,
  461. out int firstBinding,
  462. Func<int, int> getBindingCallback)
  463. {
  464. firstBinding = 0;
  465. bool hasFirstBinding = false;
  466. var descriptors = new BufferDescriptor[BitOperations.PopCount((uint)usedMask)];
  467. int lastSlot = -1;
  468. for (int i = 0; i < descriptors.Length; i++)
  469. {
  470. int slot = BitOperations.TrailingZeroCount(usedMask);
  471. if (isArray)
  472. {
  473. // The next array entries also consumes bindings, even if they are unused.
  474. for (int j = lastSlot + 1; j < slot; j++)
  475. {
  476. int binding = getBindingCallback(j);
  477. if (!hasFirstBinding)
  478. {
  479. firstBinding = binding;
  480. hasFirstBinding = true;
  481. }
  482. }
  483. }
  484. lastSlot = slot;
  485. descriptors[i] = new BufferDescriptor(getBindingCallback(slot), slot);
  486. if (!hasFirstBinding)
  487. {
  488. firstBinding = descriptors[i].Binding;
  489. hasFirstBinding = true;
  490. }
  491. if ((writtenMask & (1 << slot)) != 0)
  492. {
  493. descriptors[i].SetFlag(BufferUsageFlags.Write);
  494. }
  495. usedMask &= ~(1 << slot);
  496. }
  497. return descriptors;
  498. }
  499. public TextureDescriptor[] GetTextureDescriptors()
  500. {
  501. return _cachedTextureDescriptors ??= GetTextureOrImageDescriptors(_usedTextures, GpuAccessor.QueryBindingTexture);
  502. }
  503. public TextureDescriptor[] GetImageDescriptors()
  504. {
  505. return _cachedImageDescriptors ??= GetTextureOrImageDescriptors(_usedImages, GpuAccessor.QueryBindingImage);
  506. }
  507. private static TextureDescriptor[] GetTextureOrImageDescriptors(Dictionary<TextureInfo, TextureMeta> dict, Func<int, bool, int> getBindingCallback)
  508. {
  509. var descriptors = new TextureDescriptor[dict.Count];
  510. int i = 0;
  511. foreach (var kv in dict.OrderBy(x => x.Key.Indexed).OrderBy(x => x.Key.Handle))
  512. {
  513. var info = kv.Key;
  514. var meta = kv.Value;
  515. bool isBuffer = (meta.Type & SamplerType.Mask) == SamplerType.TextureBuffer;
  516. int binding = getBindingCallback(i, isBuffer);
  517. descriptors[i] = new TextureDescriptor(binding, meta.Type, info.Format, info.CbufSlot, info.Handle);
  518. descriptors[i].SetFlag(meta.UsageFlags);
  519. i++;
  520. }
  521. return descriptors;
  522. }
  523. public (TextureDescriptor, int) FindTextureDescriptor(AstTextureOperation texOp)
  524. {
  525. TextureDescriptor[] descriptors = GetTextureDescriptors();
  526. for (int i = 0; i < descriptors.Length; i++)
  527. {
  528. var descriptor = descriptors[i];
  529. if (descriptor.CbufSlot == texOp.CbufSlot &&
  530. descriptor.HandleIndex == texOp.Handle &&
  531. descriptor.Format == texOp.Format)
  532. {
  533. return (descriptor, i);
  534. }
  535. }
  536. return (default, -1);
  537. }
  538. private static int FindDescriptorIndex(TextureDescriptor[] array, AstTextureOperation texOp)
  539. {
  540. for (int i = 0; i < array.Length; i++)
  541. {
  542. var descriptor = array[i];
  543. if (descriptor.Type == texOp.Type &&
  544. descriptor.CbufSlot == texOp.CbufSlot &&
  545. descriptor.HandleIndex == texOp.Handle &&
  546. descriptor.Format == texOp.Format)
  547. {
  548. return i;
  549. }
  550. }
  551. return -1;
  552. }
  553. public int FindTextureDescriptorIndex(AstTextureOperation texOp)
  554. {
  555. return FindDescriptorIndex(GetTextureDescriptors(), texOp);
  556. }
  557. public int FindImageDescriptorIndex(AstTextureOperation texOp)
  558. {
  559. return FindDescriptorIndex(GetImageDescriptors(), texOp);
  560. }
  561. }
  562. }