Skip to content

Commit dbb4641

Browse files
authored
Needle Shader updates (#49)
* Fixed terminator logic in global shader variable class * Updated Shader Compute buffer to be UAVs * Unified UAV and Texture structure
1 parent 1bb23dd commit dbb4641

File tree

4 files changed

+19
-55
lines changed

4 files changed

+19
-55
lines changed

Source/SharpNeedle/Framework/HedgehogEngine/Needle/Shader/ShaderGlobalVariables.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ShaderGlobalVariables : IBinarySerializable
77
{
88
public bool IncludeTerminator { get; set; }
99

10-
public List<Texture> Textures { get; set; } = [];
10+
public List<Resource> Textures { get; set; } = [];
1111

1212
public List<Sampler> Samplers { get; set; } = [];
1313

@@ -19,7 +19,7 @@ public class ShaderGlobalVariables : IBinarySerializable
1919

2020
public List<ConstantBufferField> CBFloats { get; set; } = [];
2121

22-
public List<ComputeBuffer> ComputeBuffers { get; set; } = [];
22+
public List<Resource> UnorderedAccessViews { get; set; } = [];
2323

2424

2525
public void Read(BinaryObjectReader reader)
@@ -30,14 +30,14 @@ public void Read(BinaryObjectReader reader)
3030
CBBooleans = [];
3131
CBIntegers = [];
3232
CBFloats = [];
33-
ComputeBuffers = [];
33+
UnorderedAccessViews = [];
3434

3535
long start = reader.Position;
3636
int size = reader.ReadInt32();
3737
long end = start + size;
3838

3939
// In games before SXSG, the lists seem to terminate
40-
// on the type "9", aka ComputeBuffer. This is easily
40+
// on the type "9", aka UAVs. This is easily
4141
// checkable by comparing pos + 4 to the end
4242

4343
while (reader.Position + 4 < end)
@@ -56,7 +56,7 @@ public void Read(BinaryObjectReader reader)
5656
case VariantVariableType.Float:
5757
throw new NotImplementedException("Not implemented yet (if this occured with a vanilla file, please open a github issue for it!!!)");
5858
case VariantVariableType.Texture:
59-
Textures.Add(reader.ReadObject<Texture>());
59+
Textures.Add(reader.ReadObject<Resource>());
6060
break;
6161
case VariantVariableType.Sampler:
6262
Samplers.Add(reader.ReadObject<Sampler>());
@@ -73,8 +73,8 @@ public void Read(BinaryObjectReader reader)
7373
case VariantVariableType.CBFloat:
7474
CBFloats.Add(reader.ReadObject<ConstantBufferField>());
7575
break;
76-
case VariantVariableType.ComputeBuffer:
77-
ComputeBuffers.Add(reader.ReadObject<ComputeBuffer>());
76+
case VariantVariableType.UnorderedAccessView:
77+
UnorderedAccessViews.Add(reader.ReadObject<Resource>());
7878
break;
7979
default:
8080
throw new InvalidDataException("Unknown variable type!");
@@ -123,12 +123,15 @@ void WriteArray<T>(List<T> list, VariantVariableType type) where T : IBinarySeri
123123
WriteArray(CBBooleans, VariantVariableType.CBBoolean);
124124
WriteArray(CBIntegers, VariantVariableType.CBInteger);
125125
WriteArray(CBFloats, VariantVariableType.CBFloat);
126-
WriteArray(ComputeBuffers, VariantVariableType.ComputeBuffer);
127126

128127
if (IncludeTerminator)
129128
{
130129
writer.WriteUInt32(9);
131130
}
131+
else
132+
{
133+
WriteArray(UnorderedAccessViews, VariantVariableType.UnorderedAccessView);
134+
}
132135

133136
long endPosition = writer.Position;
134137
using (SeekToken temp = writer.At())

Source/SharpNeedle/Framework/HedgehogEngine/Needle/Shader/Variable/ComputeBuffer.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

Source/SharpNeedle/Framework/HedgehogEngine/Needle/Shader/Variable/Texture.cs renamed to Source/SharpNeedle/Framework/HedgehogEngine/Needle/Shader/Variable/Resource.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
namespace SharpNeedle.Framework.HedgehogEngine.Needle.Shader.Variable;
22

3-
public enum TextureType : int
3+
public enum ResourceType : int
44
{
55
Buffer = 0,
66
Texture1D = 1,
77
Texture1DArray = 2,
88
Texture2D = 3,
99
Texture2DArray = 4,
10-
// 5,6 missing?
10+
Texture2DMultisampled = 5,
11+
Texture2DMultisampledArray = 6,
1112
Texture3D = 7,
1213
TextureCube = 8,
1314
TextureCubeArray = 9,
14-
RWTexture = 10
15+
BufferExtended = 10
1516
}
1617

17-
public struct Texture : IBinarySerializable
18+
public struct Resource : IBinarySerializable
1819
{
1920
private string? _name;
2021

21-
public TextureType Type { get; set; }
22+
public ResourceType Type { get; set; }
2223

2324
public int ID { get; set; }
2425

@@ -30,7 +31,7 @@ public string Name
3031

3132
public void Read(BinaryObjectReader reader)
3233
{
33-
Type = (TextureType)reader.ReadInt32();
34+
Type = (ResourceType)reader.ReadInt32();
3435
ID = reader.ReadInt32();
3536
Name = reader.ReadString(StringBinaryFormat.NullTerminated);
3637
reader.Align(4);

Source/SharpNeedle/Framework/HedgehogEngine/Needle/Shader/VariantVariableType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ public enum VariantVariableType : int
1717
CBFloat = 8,
1818

1919
// Only used in compute buffers in SXSG, so likely just "compute buffer"
20-
ComputeBuffer = 9
20+
UnorderedAccessView = 9
2121
}

0 commit comments

Comments
 (0)