Skip to content
Permalink
Browse files

[Vulkan] Properly store info if a texel buffer need to be integer or …

…float.
  • Loading branch information
xen2 committed Sep 6, 2019
1 parent ae24533 commit cb9b3178ed563a9483c9e3cc9e086785825e32c2
@@ -27,14 +27,14 @@ public class DescriptorSetLayoutBuilder
/// Gets (or creates) an entry to the DescriptorSetLayout and gets its index.
/// </summary>
/// <returns>The future entry index.</returns>
public void AddBinding(ParameterKey key, string logicalGroup, EffectParameterClass @class, EffectParameterType type, int arraySize = 1, SamplerState immutableSampler = null)
public void AddBinding(ParameterKey key, string logicalGroup, EffectParameterClass @class, EffectParameterType type, EffectParameterType elementType, int arraySize = 1, SamplerState immutableSampler = null)
{
hashBuilder.Write(key.Name);
hashBuilder.Write(@class);
hashBuilder.Write(arraySize);

ElementCount += arraySize;
Entries.Add(new Entry { Key = key, LogicalGroup = logicalGroup, Class = @class, Type = type, ArraySize = arraySize, ImmutableSampler = immutableSampler });
Entries.Add(new Entry { Key = key, LogicalGroup = logicalGroup, Class = @class, Type = type, ElementType = elementType, ArraySize = arraySize, ImmutableSampler = immutableSampler });
}

internal struct Entry
@@ -43,6 +43,7 @@ internal struct Entry
public string LogicalGroup;
public EffectParameterClass Class;
public EffectParameterType Type;
public EffectParameterType ElementType;
public int ArraySize;
public SamplerState ImmutableSampler;
}
@@ -23,7 +23,7 @@ public static EffectDescriptorSetReflection New(GraphicsDevice graphicsDevice, E
bool hasBindings = false;
foreach (var resourceBinding in effectBytecode.Reflection.ResourceBindings
.Where(x => x.ResourceGroup == effectDescriptorSetSlot || (effectDescriptorSetSlot == defaultSetSlot && (x.ResourceGroup == null || x.ResourceGroup == "Globals")))
.GroupBy(x => new { Key = x.KeyInfo.Key, Class = x.Class, Type = x.Type, SlotCount = x.SlotCount, LogicalGroup = x.LogicalGroup })
.GroupBy(x => new { Key = x.KeyInfo.Key, Class = x.Class, Type = x.Type, ElementType = x.ElementType.Type, SlotCount = x.SlotCount, LogicalGroup = x.LogicalGroup })
.OrderBy(x => x.Key.Class == EffectParameterClass.ConstantBuffer ? 0 : 1)) // Note: Putting cbuffer first for now
{
SamplerState samplerState = null;
@@ -35,7 +35,7 @@ public static EffectDescriptorSetReflection New(GraphicsDevice graphicsDevice, E
}
hasBindings = true;

descriptorSetLayoutBuilder.AddBinding(resourceBinding.Key.Key, resourceBinding.Key.LogicalGroup, resourceBinding.Key.Class, resourceBinding.Key.Type, resourceBinding.Key.SlotCount, samplerState);
descriptorSetLayoutBuilder.AddBinding(resourceBinding.Key.Key, resourceBinding.Key.LogicalGroup, resourceBinding.Key.Class, resourceBinding.Key.Type, resourceBinding.Key.ElementType, resourceBinding.Key.SlotCount, samplerState);
}

descriptorSetLayouts.AddLayout(effectDescriptorSetSlot, hasBindings ? descriptorSetLayoutBuilder : null);
@@ -352,7 +352,7 @@ private unsafe void PrepareDraw()

case DescriptorType.UniformTexelBuffer:
buffer = heapObject.Value as Buffer;
descriptorData->BufferView = buffer?.NativeBufferView ?? GraphicsDevice.EmptyTexelBuffer.NativeBufferView;
descriptorData->BufferView = buffer?.NativeBufferView ?? (mapping.ResourceElementIsInteger ? GraphicsDevice.EmptyTexelBufferInt.NativeBufferView : GraphicsDevice.EmptyTexelBufferFloat.NativeBufferView);
write->TexelBufferView = new IntPtr(descriptorData);
break;

@@ -63,7 +63,7 @@ public partial class GraphicsDevice
0 // InputAttachment
};

internal Buffer EmptyTexelBuffer;
internal Buffer EmptyTexelBufferInt, EmptyTexelBufferFloat;
internal Texture EmptyTexture;

internal PhysicalDevice NativePhysicalDevice => Adapter.GetPhysicalDevice(IsDebugMode);
@@ -361,7 +361,8 @@ private unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles,
nativeResourceCollector = new NativeResourceCollector(this);
graphicsResourceLinkCollector = new GraphicsResourceLinkCollector(this);

EmptyTexelBuffer = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_Float);
EmptyTexelBufferInt = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_UInt);
EmptyTexelBufferFloat = Buffer.Typed.New(this, 1, PixelFormat.R32G32B32A32_Float);
EmptyTexture = Texture.New2D(this, 1, 1, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource);
}

@@ -451,8 +452,10 @@ protected void DestroyPlatformDevice()

private unsafe void ReleaseDevice()
{
EmptyTexelBuffer.Dispose();
EmptyTexelBuffer = null;
EmptyTexelBufferInt.Dispose();
EmptyTexelBufferInt = null;
EmptyTexelBufferFloat.Dispose();
EmptyTexelBufferFloat = null;

EmptyTexture.Dispose();
EmptyTexture = null;
@@ -315,6 +315,8 @@ internal struct DescriptorSetInfo
public int SourceBinding;
public int DestinationBinding;
public DescriptorType DescriptorType;
// Used for buffer/texture (to know what type to match)
public bool ResourceElementIsInteger;
}

internal List<DescriptorSetInfo> DescriptorBindingMapping;
@@ -369,7 +371,8 @@ private unsafe void CreatePipelineLayout(PipelineStateDescription pipelineStateD
SourceSet = layoutIndex,
SourceBinding = sourceBinding,
DestinationBinding = destinationBinding,
DescriptorType = VulkanConvertExtensions.ConvertDescriptorType(sourceEntry.Class, sourceEntry.Type)
DescriptorType = VulkanConvertExtensions.ConvertDescriptorType(sourceEntry.Class, sourceEntry.Type),
ResourceElementIsInteger = sourceEntry.ElementType != EffectParameterType.Float && sourceEntry.ElementType != EffectParameterType.Double,
});
}
}
@@ -308,7 +308,7 @@ private string Compile(string shaderSource, string entryPoint, ShaderStage stage

var bindings = resourceGroups.SelectMany(resourceGroup => reflection.ResourceBindings
.Where(x => x.ResourceGroup == resourceGroup || (x.ResourceGroup == null && resourceGroup == "Globals"))
.GroupBy(x => new { KeyName = x.KeyInfo.KeyName, RawName = x.RawName, Class = x.Class, Type = x.Type, SlotCount = x.SlotCount, LogicalGroup = x.LogicalGroup })
.GroupBy(x => new { KeyName = x.KeyInfo.KeyName, RawName = x.RawName, Class = x.Class, Type = x.Type, ElementType = x.ElementType.Type, SlotCount = x.SlotCount, LogicalGroup = x.LogicalGroup })
.OrderBy(x => x.Key.Class == EffectParameterClass.ConstantBuffer ? 0 : 1))
.ToList();

@@ -652,7 +652,7 @@ private void ParseConstantBufferVariable(string cbName, Variable variable)

private static void LinkVariable(EffectReflection reflection, string variableName, LocalParameterKey parameterKey, int slotCount)
{
var binding = new EffectResourceBindingDescription { KeyInfo = { KeyName = parameterKey.Name }, Class = parameterKey.Type.Class, Type = parameterKey.Type.Type, RawName = variableName, SlotStart = -1, SlotCount = slotCount > 0 ? slotCount : 1, ResourceGroup = parameterKey.ResourceGroup, LogicalGroup = parameterKey.LogicalGroup };
var binding = new EffectResourceBindingDescription { KeyInfo = { KeyName = parameterKey.Name }, Class = parameterKey.Type.Class, Type = parameterKey.Type.Type, ElementType = parameterKey.ElementType, RawName = variableName, SlotStart = -1, SlotCount = slotCount > 0 ? slotCount : 1, ResourceGroup = parameterKey.ResourceGroup, LogicalGroup = parameterKey.LogicalGroup };
reflection.ResourceBindings.Add(binding);
}

0 comments on commit cb9b317

Please sign in to comment.
You can’t perform that action at this time.