Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
csinkers committed May 26, 2024
1 parent d35ba2d commit ba5d8e2
Show file tree
Hide file tree
Showing 34 changed files with 122 additions and 132 deletions.
4 changes: 1 addition & 3 deletions src/Api/Eventing/AlbionTaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public void SetResult()

public void SetStateMachine(IAsyncStateMachine stateMachine)
{
if (stateMachine == null)
throw new ArgumentNullException(nameof(stateMachine));

/* Not used in .NET Core and later */
}

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/Api/Eventing/AlbionTaskBuilder_T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public void SetResult(TResult result)

public void SetStateMachine(IAsyncStateMachine stateMachine)
{
if (stateMachine == null)
throw new ArgumentNullException(nameof(stateMachine));

/* Not used in .NET Core and later */
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/CodeGen.Veldrid/FramebufferGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace UAlbion.CodeGen.Veldrid;

static class FramebufferGenerator
{
const string TexturesNamespace = "global::UAlbion.Core.Veldrid.Textures";
public static void Generate(StringBuilder sb, VeldridTypeInfo type)
{
var depth = type.Members.SingleOrDefault(x => x.DepthAttachment != null);
Expand All @@ -23,10 +24,10 @@ static void BuildConstructor(StringBuilder sb, VeldridTypeInfo type, VeldridMemb
$@" public {typeName}(string name, uint width, uint height) : base(name, width, height)
{{");
if (depth != null)
sb.AppendLine($@" {depth.Symbol.Name} = new global::UAlbion.Core.Veldrid.Textures.Texture2DHolder(name + "".{depth.Symbol.Name}"");");
sb.AppendLine($@" {depth.Symbol.Name} = new {TexturesNamespace}.Texture2DHolder(name + "".{depth.Symbol.Name}"");");

foreach (var color in type.Members.Where(member => member.ColorAttachment != null))
sb.AppendLine($@" {color.Symbol.Name} = new global::UAlbion.Core.Veldrid.Textures.Texture2DHolder(name + "".{color.Symbol.Name}"");");
sb.AppendLine($@" {color.Symbol.Name} = new {TexturesNamespace}.Texture2DHolder(name + "".{color.Symbol.Name}"");");

sb.AppendLine(@" }
");
Expand Down
10 changes: 3 additions & 7 deletions src/CodeGen.Veldrid/PipelineGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ public static void Generate(StringBuilder sb, VeldridTypeInfo type, GenerationCo
if (sets[set.slot] == null)
sets[set.slot] = set.type;
else
{
context.Report(DiagnosticSeverity.Error,
$"Tried to define ResourceSlot {set.slot} as {set.type}, " +
$"but it is already defined as {sets[set.slot]}!");
}
context.Error($"Tried to define ResourceSlot {set.slot} as {set.type}, but it is already defined as {sets[set.slot]}!");
}

for(int i = 0; i < sets.Count; i++)
if (sets[i] == null)
context.Report(DiagnosticSeverity.Error, $"No resource layout is defined for slot {i}!");
context.Error($"No resource layout is defined for slot {i}!");

first = true;
foreach (var set in sets)
Expand All @@ -90,7 +86,7 @@ public static void Generate(StringBuilder sb, VeldridTypeInfo type, GenerationCo
}
sb.AppendLine();
sb.AppendLine(" })");
sb.AppendLine(@" { }");
sb.AppendLine(" { }");

/* e.g.
static VertexLayoutDescription SpriteInstanceDataLayout
Expand Down
22 changes: 12 additions & 10 deletions src/CodeGen.Veldrid/ResourceSetGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Globalization;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
Expand All @@ -9,6 +8,9 @@ namespace UAlbion.CodeGen.Veldrid;

static class ResourceSetGenerator
{
const string NewLine = @"
";

public static void Generate(StringBuilder sb, VeldridTypeInfo type, GenerationContext context)
{
/* e.g.
Expand Down Expand Up @@ -56,7 +58,7 @@ member.Resource.Kind is KnownResourceKind.StructuredBufferReadOnly or KnownResou
break;

default:
context.Report($"Resource {member.Symbol.ToDisplayString()} was of unexpected kind {member.Resource.Kind}");
context.Error($"Resource {member.Symbol.ToDisplayString()} was of unexpected kind {member.Resource.Kind}");
break;
}
}
Expand All @@ -77,7 +79,7 @@ member.Resource.Kind is KnownResourceKind.StructuredBufferReadOnly or KnownResou
{
if (member.Symbol is not IFieldSymbol field)
{
context.Report($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in {type.Symbol.ToDisplayString()} was a {member.Symbol.GetType().Name})");
context.Error($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in {type.Symbol.ToDisplayString()} was a {member.Symbol.GetType().Name})");
continue;
}

Expand All @@ -90,7 +92,7 @@ member.Resource.Kind is KnownResourceKind.StructuredBufferReadOnly or KnownResou
" == null) throw new System.InvalidOperationException(\"Tried to construct {0}, but {1} has not been initialised. It may not have been attached to the exchange.\");{2}",
type.Symbol.Name,
VeldridGenUtil.UnderscoreToTitleCase(field.Name),
Environment.NewLine);
NewLine);
}

sb.AppendLine(@"#endif
Expand All @@ -108,7 +110,7 @@ member.Resource.Kind is KnownResourceKind.StructuredBufferReadOnly or KnownResou
sb.Append('.');
AppendDeviceMemberForKind(sb, member, context);
}

sb.AppendLine("));");
sb.AppendLine(" }");

Expand Down Expand Up @@ -167,7 +169,7 @@ static void AppendDeviceMemberForKind(StringBuilder sb, VeldridMemberInfo member

case KnownResourceKind.Unknown:
default:
context.Report($"Resource {member.Symbol.ToDisplayString()} was of unexpected kind \"{member.Resource.Kind}\"");
context.Error($"Resource {member.Symbol.ToDisplayString()} was of unexpected kind \"{member.Resource.Kind}\"");
break;
}
}
Expand All @@ -176,7 +178,7 @@ static void GenerateSampler(StringBuilder sb, VeldridMemberInfo member, Generati
{
if (member.Symbol is not IFieldSymbol field)
{
context.Report($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
context.Error($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
$"{member.Symbol.ContainingType.ToDisplayString()} was a {member.Symbol.GetType().Name})");
return;
}
Expand Down Expand Up @@ -220,7 +222,7 @@ static void GenerateTexture(StringBuilder sb, VeldridMemberInfo member, Generati
{
if (member.Symbol is not IFieldSymbol field)
{
context.Report($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
context.Error($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
$"{member.Symbol.ContainingType.ToDisplayString()} was a {member.Symbol.GetType().Name})");
return;
}
Expand Down Expand Up @@ -263,7 +265,7 @@ static void GenerateBuffer(StringBuilder sb, VeldridMemberInfo member, Generatio
{
if (member.Symbol is not IFieldSymbol field)
{
context.Report($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
context.Error($"Resource set backing members must be fields (member {member.Symbol.ToDisplayString()} in " +
$"{member.Symbol.ContainingType.ToDisplayString()} was a {member.Symbol.GetType().Name})");
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/CodeGen.Veldrid/ShaderEnumGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static Dictionary<INamedTypeSymbol, string> FindEnumTypes(VeldridTypeInfo shader

foreach (var member in typeInfo.Members)
{
var prefix = member.Vertex?.EnumPrefix
var prefix = member.Vertex?.EnumPrefix
?? member.UniformMember?.EnumPrefix
?? member.StructuredMember?.EnumPrefix;

Expand All @@ -86,15 +86,15 @@ static Dictionary<INamedTypeSymbol, string> FindEnumTypes(VeldridTypeInfo shader
default: continue;
}

if (memberType.TypeKind != TypeKind.Enum)
if (memberType.TypeKind != TypeKind.Enum)
continue;

if (enumTypes.TryGetValue(memberType, out var existingPrefix))
{
if (existingPrefix != prefix)
{
context.Report($"Member {member.Symbol.Name} of {typeSymbol.Name} was declared with enum " +
$"prefix \"{prefix}\", but another attribute has already declared it with the attribute \"{existingPrefix}\"");
context.Error($"Member {member.Symbol.Name} of {typeSymbol.Name} was declared with enum " +
$"prefix \"{prefix}\", but another attribute has already declared it with the attribute \"{existingPrefix}\"");
}
}
else enumTypes[memberType] = prefix;
Expand Down
10 changes: 5 additions & 5 deletions src/CodeGen.Veldrid/ShaderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void EmitResource(StringBuilder sb, int setNumber, int binding, VeldridTy
{
if (!context.Types.TryGetValue(resource.BufferType, out var bufferType))
{
context.Report(
context.Error(
$"Resource {resource.Name} in set {setInfo.Symbol.ToDisplayString()} was " +
$"of unknown type {resource.BufferType.ToDisplayString()}. " +
$"The buffer type must inherit from the {context.Symbols.Interfaces.UniformFormat.ToDisplayString()} interface");
Expand All @@ -94,7 +94,7 @@ static void EmitResource(StringBuilder sb, int setNumber, int binding, VeldridTy
{
if (!context.Types.TryGetValue(resource.BufferType, out var bufferType))
{
context.Report(
context.Error(
$"Resource {resource.Name} in set {setInfo.Symbol.ToDisplayString()} was " +
$"of unknown type {resource.BufferType.ToDisplayString()}. " +
$"The buffer type must inherit from the {context.Symbols.Interfaces.UniformFormat.ToDisplayString()} interface");
Expand Down Expand Up @@ -135,7 +135,7 @@ static void EmitResource(StringBuilder sb, int setNumber, int binding, VeldridTy
break;

default:
context.Report($"Resource {resource.Name} in {setInfo.Symbol.ToDisplayString()} was of unhandled type {resource.ResourceType}");
context.Error($"Resource {resource.Name} in {setInfo.Symbol.ToDisplayString()} was of unhandled type {resource.ResourceType}");
break;
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ static string TypeForMember(VeldridMemberInfo component, GenerationContext conte
{
return VeldridGenUtil.GetGlslTypeForColorAttachment(component.ColorAttachment.Format);
}
catch (FormatException e) { context.Report(e.Message); }
catch (FormatException e) { context.Error(e.Message); }
}

return null;
Expand All @@ -195,7 +195,7 @@ static int EmitVertexLayout(StringBuilder sb, GenerationContext context, INamedT
foreach (var component in layoutInfo.Members)
{
var glslType = TypeForMember(component, context, isInput);
if(glslType == null)
if (glslType == null)
continue;

sb.Append("layout(location = ");
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGen.Veldrid/ShaderStructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void EmitStructs(StringBuilder sb, VeldridTypeInfo shaderType, Gen

var missing = actualMembers.Where(x => x.Kind == SymbolKind.Field && typeInfo.Members.All(m => !m.Symbol.Equals(x, SymbolEqualityComparer.Default)));
foreach (var member in missing)
context.Report($"Found member in IStructuredFormat struct without a StructureAttribute: {member}");
context.Error($"Found member in IStructuredFormat struct without a StructureAttribute: {member}");

foreach (var member in typeInfo.Members)
{
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGen.Veldrid/UAlbion.CodeGen.Veldrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup Condition="!Exists('..\..\deps\VeldridGen\')">
<PackageReference Include="VeldridGen" Version="0.1.10" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="VeldridGen" Version="0.1.11" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition="Exists('..\..\deps\VeldridGen\')">
<ProjectReference Include="..\..\deps\VeldridGen\VeldridGen\VeldridGen.csproj" PrivateAssets="all" />
Expand Down
17 changes: 10 additions & 7 deletions src/Core.Veldrid/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,18 @@ public unsafe Image<Bgra32> ReadTexture2D(ITextureHolder textureHolder)
try
{
var result = new Image<Bgra32>((int)texture.Width, (int)texture.Height);
var sourceSpan = new Span<uint>(mapped.Data.ToPointer(), (int)mapped.SizeInBytes);
var stride = (int)mapped.RowPitch / sizeof(uint);

for (int j = 0; j < texture.Height; j++)
result.ProcessPixelRows(p =>
{
var sourceRow = sourceSpan.Slice(stride * j, (int)texture.Width);
var destRow = MemoryMarshal.Cast<Bgra32, uint>(result.GetPixelRowSpan(j));
sourceRow.CopyTo(destRow);
}
var sourceSpan = new Span<uint>(mapped.Data.ToPointer(), (int)mapped.SizeInBytes);
var stride = (int)mapped.RowPitch / sizeof(uint);
for (int j = 0; j < texture.Height; j++)
{
var sourceRow = sourceSpan.Slice(stride * j, (int)texture.Width);
var destRow = MemoryMarshal.Cast<Bgra32, uint>(p.GetRowSpan(j));
sourceRow.CopyTo(destRow);
}
});

return result;
}
Expand Down
20 changes: 11 additions & 9 deletions src/Core.Veldrid/Textures/ImageSharpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public static class ImageSharpUtil
public static Image<Rgba32> ToImageSharp(ReadOnlyImageBuffer<byte> from, ReadOnlySpan<uint> palette)
{
Image<Rgba32> image = new Image<Rgba32>(from.Width, from.Height);
if (!image.TryGetSinglePixelSpan(out var rgbaSpan))
if (!image.DangerousTryGetSinglePixelMemory(out var rgbaMemory))
throw new InvalidOperationException("Could not retrieve single span from Image");

Span<uint> toBuffer = MemoryMarshal.Cast<Rgba32, uint>(rgbaSpan);
Span<uint> toBuffer = MemoryMarshal.Cast<Rgba32, uint>(rgbaMemory.Span);
var to = new ImageBuffer<uint>(from.Width, from.Height, from.Width, toBuffer);
BlitUtil.BlitTiled8To32(from, to, palette, 255, 0);

Expand All @@ -25,10 +25,10 @@ public static Image<Rgba32> ToImageSharp(ReadOnlyImageBuffer<byte> from, ReadOnl
public static Image<Rgba32> ToImageSharp(ReadOnlyImageBuffer<uint> from)
{
Image<Rgba32> image = new Image<Rgba32>(from.Width, from.Height);
if (!image.TryGetSinglePixelSpan(out var rgbaSpan))
if (!image.DangerousTryGetSinglePixelMemory(out var rgbaMemory))
throw new InvalidOperationException("Could not retrieve single span from Image");

Span<uint> toBuffer = MemoryMarshal.Cast<Rgba32, uint>(rgbaSpan);
Span<uint> toBuffer = MemoryMarshal.Cast<Rgba32, uint>(rgbaMemory.Span);
var to = new ImageBuffer<uint>(from.Width, from.Height, from.Width, toBuffer);
BlitUtil.BlitDirect(from, to);
return image;
Expand All @@ -43,10 +43,10 @@ public static Image<Rgba32> PackSpriteSheet(uint[] palette, int frameCount, GetF
throw new InvalidOperationException("Could not pack sprite sheet into a single layer");

Image<Rgba32> image = new Image<Rgba32>(layout.Width, layout.Height);
if (!image.TryGetSinglePixelSpan(out var rgbaSpan))
if (!image.DangerousTryGetSinglePixelMemory(out var rgbaMemory))
throw new InvalidOperationException("Could not retrieve single span from Image");

Span<uint> pixels = MemoryMarshal.Cast<Rgba32, uint>(rgbaSpan);
Span<uint> pixels = MemoryMarshal.Cast<Rgba32, uint>(rgbaMemory.Span);
for (var i = 0; i < frameCount; i++)
{
var frame = getFrame(i);
Expand All @@ -59,11 +59,13 @@ public static Image<Rgba32> PackSpriteSheet(uint[] palette, int frameCount, GetF
return image;
}

public static object FromImageSharp(IAssetId id, string name, Image<Rgba32> image)
public static SimpleTexture<uint> FromImageSharp(IAssetId id, string name, Image<Rgba32> image)
{
if (image == null) throw new ArgumentNullException(nameof(image));
image.TryGetSinglePixelSpan(out var pixels);
var asUint = MemoryMarshal.Cast<Rgba32, uint>(pixels);
if (!image.DangerousTryGetSinglePixelMemory(out var rgbaMemory))
throw new InvalidOperationException("Could not retrieve single span from Image");

var asUint = MemoryMarshal.Cast<Rgba32, uint>(rgbaMemory.Span);
var result = new SimpleTexture<uint>(id, name, image.Width, image.Height, asUint);
result.AddRegion(0, 0, image.Width, image.Height);
return result;
Expand Down
14 changes: 0 additions & 14 deletions src/Core.Veldrid/Textures/VeldridTexture.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
using UAlbion.Api.Visual;
using Veldrid;
using Veldrid.ImageSharp;

namespace UAlbion.Core.Veldrid.Textures;

Expand Down Expand Up @@ -139,16 +137,4 @@ public static unsafe Texture CreateLazy<T>(GraphicsDevice gd, TextureUsage usage

return veldridTexture;
}

public static Texture CreateImageSharp(GraphicsDevice gd, TextureUsage usage, SixLabors.ImageSharp.Image<Rgba32> image, string name)
{
if (gd == null) throw new ArgumentNullException(nameof(gd));
if (usage != TextureUsage.Sampled && usage != (TextureUsage.Sampled | TextureUsage.GenerateMipmaps))
throw new ArgumentOutOfRangeException(nameof(usage), "Only sampled texture usage is currently supported (with optional mipmapping)");

ImageSharpTexture imageSharpTexture = new ImageSharpTexture(image, (usage & TextureUsage.GenerateMipmaps) != 0);
var texture = imageSharpTexture.CreateDeviceTexture(gd, gd.ResourceFactory);
texture.Name = "T_" + name;
return texture;
}
}
Loading

0 comments on commit ba5d8e2

Please sign in to comment.