Skip to content

Commit f3cfdb1

Browse files
committed
Add a SpirvReflection LoadFromJson test.
1 parent e17187b commit f3cfdb1

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.IO;
2+
using System.Text;
3+
using Xunit;
4+
5+
namespace Veldrid.SPIRV.Tests
6+
{
7+
public class SerializationTests
8+
{
9+
[Fact]
10+
public void SpirvReflection_DeserializeFromString()
11+
{
12+
const string SerializedJson =
13+
@"{
14+
""VertexElements"": [],
15+
""ResourceLayouts"": [
16+
{
17+
""Elements"": [
18+
{
19+
""Name"": ""vdspv_0_0"",
20+
""Kind"": ""TextureReadOnly"",
21+
""Stages"": ""Fragment"",
22+
""Options"": ""None""
23+
},
24+
{
25+
""Name"": ""vdspv_0_1"",
26+
""Kind"": ""Sampler"",
27+
""Stages"": ""Fragment"",
28+
""Options"": ""None""
29+
}
30+
]
31+
},
32+
{
33+
""Elements"": [
34+
{
35+
""Name"": ""vdspv_1_0"",
36+
""Kind"": ""UniformBuffer"",
37+
""Stages"": ""Fragment"",
38+
""Options"": ""None""
39+
}
40+
]
41+
}
42+
]
43+
}";
44+
byte[] bytes = Encoding.UTF8.GetBytes(SerializedJson);
45+
using (MemoryStream ms = new MemoryStream(bytes))
46+
{
47+
SpirvReflection refl = SpirvReflection.LoadFromJson(ms);
48+
Assert.Empty(refl.VertexElements);
49+
Assert.Equal(2, refl.ResourceLayouts.Length);
50+
Assert.Equal(2, refl.ResourceLayouts[0].Elements.Length);
51+
Assert.Single(refl.ResourceLayouts[1].Elements);
52+
}
53+
}
54+
}
55+
}

src/Veldrid.SPIRV/SpirvReflection.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ public class SpirvReflection
2525
/// </summary>
2626
public ResourceLayoutDescription[] ResourceLayouts { get; }
2727

28-
internal SpirvReflection(
28+
/// <summary>
29+
/// Constructs a new <see cref="SpirvReflection"/> instance.
30+
/// </summary>
31+
/// <param name="vertexElements">/// An array containing a description of each vertex element that is used by
32+
/// the compiled shader set.</param>
33+
/// <param name="resourceLayouts">An array containing a description of each set of resources used by the
34+
/// compiled shader set.</param>
35+
public SpirvReflection(
2936
VertexElementDescription[] vertexElements,
3037
ResourceLayoutDescription[] resourceLayouts)
3138
{

0 commit comments

Comments
 (0)