2021-05-19 14:15:26 -07:00
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
|
|
using System;
|
2020-11-12 15:15:34 -08:00
|
|
|
using System.Collections.Generic;
|
2021-05-19 14:15:26 -07:00
|
|
|
using System.Linq;
|
|
|
|
using System.Numerics;
|
2020-11-12 15:15:34 -08:00
|
|
|
|
2019-12-29 09:41:50 -08:00
|
|
|
namespace Ryujinx.Graphics.Shader.Translation
|
2019-10-12 23:02:07 -07:00
|
|
|
{
|
2020-07-29 22:53:23 -07:00
|
|
|
class ShaderConfig
|
2019-10-12 23:02:07 -07:00
|
|
|
{
|
2021-05-19 14:15:26 -07:00
|
|
|
// TODO: Non-hardcoded array size.
|
|
|
|
public const int SamplerArraySize = 4;
|
|
|
|
|
2019-10-12 23:02:07 -07:00
|
|
|
public ShaderStage Stage { get; }
|
|
|
|
|
2021-01-28 19:38:51 -08:00
|
|
|
public bool GpPassthrough { get; }
|
|
|
|
|
2019-12-15 20:59:46 -08:00
|
|
|
public OutputTopology OutputTopology { get; }
|
|
|
|
|
|
|
|
public int MaxOutputVertices { get; }
|
|
|
|
|
2020-02-01 19:25:52 -08:00
|
|
|
public int LocalMemorySize { get; }
|
|
|
|
|
2020-04-02 17:20:47 -07:00
|
|
|
public ImapPixelType[] ImapTypes { get; }
|
|
|
|
|
|
|
|
public OmapTarget[] OmapTargets { get; }
|
|
|
|
public bool OmapSampleMask { get; }
|
|
|
|
public bool OmapDepth { get; }
|
2019-11-30 18:53:09 -08:00
|
|
|
|
2020-05-05 18:02:28 -07:00
|
|
|
public IGpuAccessor GpuAccessor { get; }
|
2019-10-12 23:02:07 -07:00
|
|
|
|
2021-07-06 12:20:06 -07:00
|
|
|
public TranslationOptions Options { get; }
|
2019-10-12 23:02:07 -07:00
|
|
|
|
2020-07-29 22:53:23 -07:00
|
|
|
public int Size { get; private set; }
|
|
|
|
|
2021-04-20 03:33:54 -07:00
|
|
|
public byte ClipDistancesWritten { get; private set; }
|
|
|
|
|
2020-07-29 22:53:23 -07:00
|
|
|
public FeatureFlags UsedFeatures { get; private set; }
|
2020-07-06 19:41:07 -07:00
|
|
|
|
2020-11-12 15:15:34 -08:00
|
|
|
public HashSet<int> TextureHandlesForCache { get; }
|
|
|
|
|
2021-05-19 14:15:26 -07:00
|
|
|
private readonly TranslationCounts _counts;
|
|
|
|
|
2021-08-11 13:27:00 -07:00
|
|
|
public int UsedInputAttributes { get; private set; }
|
|
|
|
public int UsedOutputAttributes { get; private set; }
|
|
|
|
public int PassthroughAttributes { get; private set; }
|
|
|
|
|
2021-05-19 14:15:26 -07:00
|
|
|
private int _usedConstantBuffers;
|
|
|
|
private int _usedStorageBuffers;
|
|
|
|
private int _usedStorageBuffersWrite;
|
|
|
|
|
|
|
|
private struct TextureInfo : IEquatable<TextureInfo>
|
|
|
|
{
|
|
|
|
public int CbufSlot { get; }
|
|
|
|
public int Handle { get; }
|
|
|
|
public bool Indexed { get; }
|
|
|
|
public TextureFormat Format { get; }
|
|
|
|
|
|
|
|
public TextureInfo(int cbufSlot, int handle, bool indexed, TextureFormat format)
|
|
|
|
{
|
|
|
|
CbufSlot = cbufSlot;
|
|
|
|
Handle = handle;
|
|
|
|
Indexed = indexed;
|
|
|
|
Format = format;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
|
|
|
return obj is TextureInfo other && Equals(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Equals(TextureInfo other)
|
|
|
|
{
|
|
|
|
return CbufSlot == other.CbufSlot && Handle == other.Handle && Indexed == other.Indexed && Format == other.Format;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return HashCode.Combine(CbufSlot, Handle, Indexed, Format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct TextureMeta
|
|
|
|
{
|
|
|
|
public bool AccurateType;
|
|
|
|
public SamplerType Type;
|
|
|
|
public TextureUsageFlags UsageFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly Dictionary<TextureInfo, TextureMeta> _usedTextures;
|
|
|
|
private readonly Dictionary<TextureInfo, TextureMeta> _usedImages;
|
|
|
|
|
|
|
|
private BufferDescriptor[] _cachedConstantBufferDescriptors;
|
|
|
|
private BufferDescriptor[] _cachedStorageBufferDescriptors;
|
|
|
|
private TextureDescriptor[] _cachedTextureDescriptors;
|
|
|
|
private TextureDescriptor[] _cachedImageDescriptors;
|
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
public int FirstConstantBufferBinding { get; private set; }
|
|
|
|
public int FirstStorageBufferBinding { get; private set; }
|
|
|
|
|
2021-07-06 12:20:06 -07:00
|
|
|
public ShaderConfig(IGpuAccessor gpuAccessor, TranslationOptions options, TranslationCounts counts)
|
2019-12-15 20:59:46 -08:00
|
|
|
{
|
2020-11-12 15:15:34 -08:00
|
|
|
Stage = ShaderStage.Compute;
|
|
|
|
GpuAccessor = gpuAccessor;
|
2021-07-06 12:20:06 -07:00
|
|
|
Options = options;
|
2021-05-19 14:15:26 -07:00
|
|
|
_counts = counts;
|
2020-11-12 15:15:34 -08:00
|
|
|
TextureHandlesForCache = new HashSet<int>();
|
2021-05-19 14:15:26 -07:00
|
|
|
_usedTextures = new Dictionary<TextureInfo, TextureMeta>();
|
|
|
|
_usedImages = new Dictionary<TextureInfo, TextureMeta>();
|
2019-12-15 20:59:46 -08:00
|
|
|
}
|
|
|
|
|
2021-07-06 12:20:06 -07:00
|
|
|
public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationOptions options, TranslationCounts counts) : this(gpuAccessor, options, counts)
|
2019-12-15 20:59:46 -08:00
|
|
|
{
|
2021-05-19 14:15:26 -07:00
|
|
|
Stage = header.Stage;
|
|
|
|
GpPassthrough = header.Stage == ShaderStage.Geometry && header.GpPassthrough;
|
|
|
|
OutputTopology = header.OutputTopology;
|
|
|
|
MaxOutputVertices = header.MaxOutputVertexCount;
|
|
|
|
LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize;
|
|
|
|
ImapTypes = header.ImapTypes;
|
|
|
|
OmapTargets = header.OmapTargets;
|
|
|
|
OmapSampleMask = header.OmapSampleMask;
|
|
|
|
OmapDepth = header.OmapDepth;
|
2019-12-15 20:59:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public int GetDepthRegister()
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (int index = 0; index < OmapTargets.Length; index++)
|
|
|
|
{
|
|
|
|
for (int component = 0; component < 4; component++)
|
|
|
|
{
|
|
|
|
if (OmapTargets[index].ComponentEnabled(component))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The depth register is always two registers after the last color output.
|
|
|
|
return count + 1;
|
|
|
|
}
|
2020-07-03 16:48:44 -07:00
|
|
|
|
2021-05-19 11:05:43 -07:00
|
|
|
public TextureFormat GetTextureFormat(int handle, int cbufSlot = -1)
|
2020-07-03 16:48:44 -07:00
|
|
|
{
|
|
|
|
// When the formatted load extension is supported, we don't need to
|
|
|
|
// specify a format, we can just declare it without a format and the GPU will handle it.
|
2021-08-11 14:01:06 -07:00
|
|
|
if (GpuAccessor.QueryHostSupportsImageLoadFormatted())
|
2020-07-03 16:48:44 -07:00
|
|
|
{
|
|
|
|
return TextureFormat.Unknown;
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:05:43 -07:00
|
|
|
var format = GpuAccessor.QueryTextureFormat(handle, cbufSlot);
|
2020-07-03 16:48:44 -07:00
|
|
|
|
|
|
|
if (format == TextureFormat.Unknown)
|
|
|
|
{
|
|
|
|
GpuAccessor.Log($"Unknown format for texture {handle}.");
|
|
|
|
|
|
|
|
format = TextureFormat.R8G8B8A8Unorm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
2020-07-29 22:53:23 -07:00
|
|
|
|
2021-08-30 22:51:57 -07:00
|
|
|
private bool FormatSupportsAtomic(TextureFormat format)
|
|
|
|
{
|
|
|
|
return format == TextureFormat.R32Sint || format == TextureFormat.R32Uint;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TextureFormat GetTextureFormatAtomic(int handle, int cbufSlot = -1)
|
|
|
|
{
|
|
|
|
// Atomic image instructions do not support GL_EXT_shader_image_load_formatted,
|
|
|
|
// and must have a type specified. Default to R32Sint if not available.
|
|
|
|
|
|
|
|
var format = GpuAccessor.QueryTextureFormat(handle, cbufSlot);
|
|
|
|
|
|
|
|
if (!FormatSupportsAtomic(format))
|
|
|
|
{
|
|
|
|
GpuAccessor.Log($"Unsupported format for texture {handle}: {format}.");
|
|
|
|
|
|
|
|
format = TextureFormat.R32Sint;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2020-07-29 22:53:23 -07:00
|
|
|
public void SizeAdd(int size)
|
|
|
|
{
|
|
|
|
Size += size;
|
|
|
|
}
|
|
|
|
|
2021-05-20 12:43:23 -07:00
|
|
|
public void InheritFrom(ShaderConfig other)
|
|
|
|
{
|
|
|
|
ClipDistancesWritten |= other.ClipDistancesWritten;
|
|
|
|
UsedFeatures |= other.UsedFeatures;
|
|
|
|
|
|
|
|
TextureHandlesForCache.UnionWith(other.TextureHandlesForCache);
|
|
|
|
|
2021-08-11 13:27:00 -07:00
|
|
|
UsedInputAttributes |= other.UsedInputAttributes;
|
|
|
|
UsedOutputAttributes |= other.UsedOutputAttributes;
|
2021-05-20 12:43:23 -07:00
|
|
|
_usedConstantBuffers |= other._usedConstantBuffers;
|
|
|
|
_usedStorageBuffers |= other._usedStorageBuffers;
|
|
|
|
_usedStorageBuffersWrite |= other._usedStorageBuffersWrite;
|
|
|
|
|
|
|
|
foreach (var kv in other._usedTextures)
|
|
|
|
{
|
|
|
|
if (!_usedTextures.TryAdd(kv.Key, kv.Value))
|
|
|
|
{
|
|
|
|
_usedTextures[kv.Key] = MergeTextureMeta(kv.Value, _usedTextures[kv.Key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var kv in other._usedImages)
|
|
|
|
{
|
|
|
|
if (!_usedImages.TryAdd(kv.Key, kv.Value))
|
|
|
|
{
|
|
|
|
_usedImages[kv.Key] = MergeTextureMeta(kv.Value, _usedImages[kv.Key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 13:27:00 -07:00
|
|
|
public void SetInputUserAttribute(int index)
|
|
|
|
{
|
|
|
|
UsedInputAttributes |= 1 << index;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetOutputUserAttribute(int index)
|
|
|
|
{
|
|
|
|
UsedOutputAttributes |= 1 << index;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void MergeOutputUserAttributes(int mask)
|
|
|
|
{
|
|
|
|
if (GpPassthrough)
|
|
|
|
{
|
|
|
|
PassthroughAttributes = mask & ~UsedOutputAttributes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UsedOutputAttributes |= mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-26 16:44:47 -07:00
|
|
|
public void SetAllInputUserAttributes()
|
|
|
|
{
|
|
|
|
UsedInputAttributes |= Constants.AllAttributesMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAllOutputUserAttributes()
|
|
|
|
{
|
|
|
|
UsedOutputAttributes |= Constants.AllAttributesMask;
|
|
|
|
}
|
|
|
|
|
2021-04-20 03:33:54 -07:00
|
|
|
public void SetClipDistanceWritten(int index)
|
|
|
|
{
|
|
|
|
ClipDistancesWritten |= (byte)(1 << index);
|
|
|
|
}
|
|
|
|
|
2020-07-29 22:53:23 -07:00
|
|
|
public void SetUsedFeature(FeatureFlags flags)
|
|
|
|
{
|
|
|
|
UsedFeatures |= flags;
|
|
|
|
}
|
2021-05-19 14:15:26 -07:00
|
|
|
|
|
|
|
public Operand CreateCbuf(int slot, int offset)
|
|
|
|
{
|
|
|
|
SetUsedConstantBuffer(slot);
|
|
|
|
return OperandHelper.Cbuf(slot, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUsedConstantBuffer(int slot)
|
|
|
|
{
|
|
|
|
_usedConstantBuffers |= 1 << slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUsedStorageBuffer(int slot, bool write)
|
|
|
|
{
|
|
|
|
int mask = 1 << slot;
|
|
|
|
_usedStorageBuffers |= mask;
|
|
|
|
|
|
|
|
if (write)
|
|
|
|
{
|
|
|
|
_usedStorageBuffersWrite |= mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUsedTexture(
|
|
|
|
Instruction inst,
|
|
|
|
SamplerType type,
|
|
|
|
TextureFormat format,
|
|
|
|
TextureFlags flags,
|
|
|
|
int cbufSlot,
|
|
|
|
int handle)
|
|
|
|
{
|
|
|
|
inst &= Instruction.Mask;
|
2021-08-30 22:51:57 -07:00
|
|
|
bool isImage = inst == Instruction.ImageLoad || inst == Instruction.ImageStore || inst == Instruction.ImageAtomic;
|
|
|
|
bool isWrite = inst == Instruction.ImageStore || inst == Instruction.ImageAtomic;
|
2021-09-01 20:17:43 -07:00
|
|
|
bool accurateType = inst != Instruction.Lod;
|
2021-05-19 14:15:26 -07:00
|
|
|
|
|
|
|
if (isImage)
|
|
|
|
{
|
|
|
|
SetUsedTextureOrImage(_usedImages, cbufSlot, handle, type, format, true, isWrite, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-08 20:09:07 -07:00
|
|
|
bool intCoords = flags.HasFlag(TextureFlags.IntCoords) || inst == Instruction.TextureSize;
|
|
|
|
SetUsedTextureOrImage(_usedTextures, cbufSlot, handle, type, TextureFormat.Unknown, intCoords, false, accurateType);
|
2021-05-19 14:15:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
private void SetUsedTextureOrImage(
|
2021-05-19 14:15:26 -07:00
|
|
|
Dictionary<TextureInfo, TextureMeta> dict,
|
|
|
|
int cbufSlot,
|
|
|
|
int handle,
|
|
|
|
SamplerType type,
|
|
|
|
TextureFormat format,
|
|
|
|
bool intCoords,
|
|
|
|
bool write,
|
|
|
|
bool accurateType)
|
|
|
|
{
|
|
|
|
var dimensions = type.GetDimensions();
|
|
|
|
var isIndexed = type.HasFlag(SamplerType.Indexed);
|
|
|
|
|
|
|
|
var usageFlags = TextureUsageFlags.None;
|
|
|
|
|
|
|
|
if (intCoords)
|
|
|
|
{
|
|
|
|
usageFlags |= TextureUsageFlags.NeedsScaleValue;
|
|
|
|
|
2021-05-20 16:09:18 -07:00
|
|
|
var canScale = (Stage == ShaderStage.Fragment || Stage == ShaderStage.Compute) && !isIndexed && !write && dimensions == 2;
|
2021-05-20 11:12:15 -07:00
|
|
|
|
2021-05-19 14:15:26 -07:00
|
|
|
if (!canScale)
|
|
|
|
{
|
|
|
|
// Resolution scaling cannot be applied to this texture right now.
|
|
|
|
// Flag so that we know to blacklist scaling on related textures when binding them.
|
|
|
|
usageFlags |= TextureUsageFlags.ResScaleUnsupported;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write)
|
|
|
|
{
|
|
|
|
usageFlags |= TextureUsageFlags.ImageStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
int arraySize = isIndexed ? SamplerArraySize : 1;
|
|
|
|
|
|
|
|
for (int layer = 0; layer < arraySize; layer++)
|
|
|
|
{
|
|
|
|
var info = new TextureInfo(cbufSlot, handle + layer * 2, isIndexed, format);
|
|
|
|
var meta = new TextureMeta()
|
|
|
|
{
|
|
|
|
AccurateType = accurateType,
|
|
|
|
Type = type,
|
|
|
|
UsageFlags = usageFlags
|
|
|
|
};
|
|
|
|
|
|
|
|
if (dict.TryGetValue(info, out var existingMeta))
|
|
|
|
{
|
2021-05-20 12:43:23 -07:00
|
|
|
dict[info] = MergeTextureMeta(meta, existingMeta);
|
2021-05-19 14:15:26 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dict.Add(info, meta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-20 12:43:23 -07:00
|
|
|
private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta)
|
|
|
|
{
|
|
|
|
meta.UsageFlags |= existingMeta.UsageFlags;
|
|
|
|
|
|
|
|
// If the texture we have has inaccurate type information, then
|
|
|
|
// we prefer the most accurate one.
|
|
|
|
if (existingMeta.AccurateType)
|
|
|
|
{
|
|
|
|
meta.AccurateType = true;
|
|
|
|
meta.Type = existingMeta.Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta;
|
|
|
|
}
|
|
|
|
|
2021-05-19 14:15:26 -07:00
|
|
|
public BufferDescriptor[] GetConstantBufferDescriptors()
|
|
|
|
{
|
|
|
|
if (_cachedConstantBufferDescriptors != null)
|
|
|
|
{
|
|
|
|
return _cachedConstantBufferDescriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usedMask = _usedConstantBuffers;
|
|
|
|
|
|
|
|
if (UsedFeatures.HasFlag(FeatureFlags.CbIndexing))
|
|
|
|
{
|
2021-05-20 11:12:15 -07:00
|
|
|
usedMask |= (int)GpuAccessor.QueryConstantBufferUse();
|
2021-05-19 14:15:26 -07:00
|
|
|
}
|
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
FirstConstantBufferBinding = _counts.UniformBuffersCount;
|
|
|
|
|
|
|
|
return _cachedConstantBufferDescriptors = GetBufferDescriptors(
|
|
|
|
usedMask,
|
|
|
|
0,
|
|
|
|
UsedFeatures.HasFlag(FeatureFlags.CbIndexing),
|
|
|
|
_counts.IncrementUniformBuffersCount);
|
2021-05-19 14:15:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public BufferDescriptor[] GetStorageBufferDescriptors()
|
|
|
|
{
|
2021-05-20 11:12:15 -07:00
|
|
|
if (_cachedStorageBufferDescriptors != null)
|
|
|
|
{
|
|
|
|
return _cachedStorageBufferDescriptors;
|
|
|
|
}
|
2021-05-19 14:15:26 -07:00
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
FirstStorageBufferBinding = _counts.StorageBuffersCount;
|
|
|
|
|
|
|
|
return _cachedStorageBufferDescriptors = GetBufferDescriptors(
|
|
|
|
_usedStorageBuffers,
|
|
|
|
_usedStorageBuffersWrite,
|
|
|
|
true,
|
|
|
|
_counts.IncrementStorageBuffersCount);
|
2021-05-19 14:15:26 -07:00
|
|
|
}
|
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
private static BufferDescriptor[] GetBufferDescriptors(
|
|
|
|
int usedMask,
|
|
|
|
int writtenMask,
|
|
|
|
bool isArray,
|
|
|
|
Func<int> getBindingCallback)
|
2021-05-19 14:15:26 -07:00
|
|
|
{
|
|
|
|
var descriptors = new BufferDescriptor[BitOperations.PopCount((uint)usedMask)];
|
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
int lastSlot = -1;
|
|
|
|
|
2021-05-19 14:15:26 -07:00
|
|
|
for (int i = 0; i < descriptors.Length; i++)
|
|
|
|
{
|
|
|
|
int slot = BitOperations.TrailingZeroCount(usedMask);
|
|
|
|
|
2021-05-20 11:12:15 -07:00
|
|
|
if (isArray)
|
|
|
|
{
|
|
|
|
// The next array entries also consumes bindings, even if they are unused.
|
|
|
|
for (int j = lastSlot + 1; j < slot; j++)
|
|
|
|
{
|
|
|
|
getBindingCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastSlot = slot;
|
|
|
|
|
2021-05-19 14:15:26 -07:00
|
|
|
descriptors[i] = new BufferDescriptor(getBindingCallback(), slot);
|
|
|
|
|
|
|
|
if ((writtenMask & (1 << slot)) != 0)
|
|
|
|
{
|
|
|
|
descriptors[i].SetFlag(BufferUsageFlags.Write);
|
|
|
|
}
|
|
|
|
|
|
|
|
usedMask &= ~(1 << slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TextureDescriptor[] GetTextureDescriptors()
|
|
|
|
{
|
|
|
|
return _cachedTextureDescriptors ??= GetTextureOrImageDescriptors(_usedTextures, _counts.IncrementTexturesCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public TextureDescriptor[] GetImageDescriptors()
|
|
|
|
{
|
|
|
|
return _cachedImageDescriptors ??= GetTextureOrImageDescriptors(_usedImages, _counts.IncrementImagesCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static TextureDescriptor[] GetTextureOrImageDescriptors(Dictionary<TextureInfo, TextureMeta> dict, Func<int> getBindingCallback)
|
|
|
|
{
|
|
|
|
var descriptors = new TextureDescriptor[dict.Count];
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
foreach (var kv in dict.OrderBy(x => x.Key.Indexed).OrderBy(x => x.Key.Handle))
|
|
|
|
{
|
|
|
|
var info = kv.Key;
|
|
|
|
var meta = kv.Value;
|
|
|
|
|
|
|
|
int binding = getBindingCallback();
|
|
|
|
|
|
|
|
descriptors[i] = new TextureDescriptor(binding, meta.Type, info.Format, info.CbufSlot, info.Handle);
|
|
|
|
descriptors[i].SetFlag(meta.UsageFlags);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptors;
|
|
|
|
}
|
2019-10-12 23:02:07 -07:00
|
|
|
}
|
|
|
|
}
|