This repository has been archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
ResourceDefinitionChunk.cs
120 lines (95 loc) · 3.49 KB
/
ResourceDefinitionChunk.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using SlimShader.Chunks.Common;
using SlimShader.Util;
namespace SlimShader.Chunks.Rdef
{
/// <summary>
/// Roughly corresponds to the D3D11_SHADER_DESC structure.
/// </summary>
public class ResourceDefinitionChunk : BytecodeChunk
{
public List<ConstantBuffer> ConstantBuffers { get; private set; }
public List<ResourceBinding> ResourceBindings { get; private set; }
public ShaderVersion Target { get; private set; }
public ShaderFlags Flags { get; private set; }
public string Creator { get; private set; }
public uint InterfaceSlotCount { get; private set; }
public ResourceDefinitionChunk()
{
ConstantBuffers = new List<ConstantBuffer>();
ResourceBindings = new List<ResourceBinding>();
}
public static ResourceDefinitionChunk Parse(BytecodeReader reader)
{
var headerReader = reader.CopyAtCurrentPosition();
uint constantBufferCount = headerReader.ReadUInt32();
uint constantBufferOffset = headerReader.ReadUInt32();
uint resourceBindingCount = headerReader.ReadUInt32();
uint resourceBindingOffset = headerReader.ReadUInt32();
var target = ShaderVersion.ParseRdef(headerReader);
uint flags = headerReader.ReadUInt32();
var creatorOffset = headerReader.ReadUInt32();
var creatorReader = reader.CopyAtOffset((int) creatorOffset);
var creator = creatorReader.ReadString();
var result = new ResourceDefinitionChunk
{
Target = target,
Flags = (ShaderFlags) flags,
Creator = creator
};
if (target.MajorVersion >= 5)
{
string rd11 = headerReader.ReadUInt32().ToFourCcString();
if (rd11 != "RD11")
throw new ParseException("Expected RD11.");
var unknown1 = headerReader.ReadUInt32(); // TODO
Debug.Assert(unknown1 == 60);
var unknown2 = headerReader.ReadUInt32();
Debug.Assert(unknown2 == 24);
var unknown3 = headerReader.ReadUInt32();
Debug.Assert(unknown3 == 32);
var unknown4 = headerReader.ReadUInt32();
Debug.Assert(unknown4 == 40);
var unknown5 = headerReader.ReadUInt32();
Debug.Assert(unknown5 == 36);
var unknown6 = headerReader.ReadUInt32();
Debug.Assert(unknown6 == 12);
result.InterfaceSlotCount = headerReader.ReadUInt32();
}
var constantBufferReader = reader.CopyAtOffset((int) constantBufferOffset);
for (int i = 0; i < constantBufferCount; i++)
result.ConstantBuffers.Add(ConstantBuffer.Parse(reader, constantBufferReader, result.Target));
var resourceBindingReader = reader.CopyAtOffset((int) resourceBindingOffset);
for (int i = 0; i < resourceBindingCount; i++)
result.ResourceBindings.Add(ResourceBinding.Parse(reader, resourceBindingReader));
return result;
}
public override string ToString()
{
var sb = new StringBuilder();
if (ConstantBuffers.Any())
{
sb.AppendLine("// Buffer Definitions: ");
sb.AppendLine("//");
foreach (var constantBuffer in ConstantBuffers)
sb.Append(constantBuffer);
sb.AppendLine("//");
}
if (ResourceBindings.Any())
{
sb.AppendLine("// Resource Bindings:");
sb.AppendLine("//");
sb.AppendLine("// Name Type Format Dim Slot Elements");
sb.AppendLine("// ------------------------------ ---------- ------- ----------- ---- --------");
foreach (var resourceBinding in ResourceBindings)
sb.AppendLine(resourceBinding.ToString());
sb.AppendLine("//");
sb.AppendLine("//");
}
return sb.ToString();
}
}
}