forked from sharpdx/SharpDX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShaderSignature.cs
176 lines (165 loc) · 7.96 KB
/
ShaderSignature.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// -----------------------------------------------------------------------------
// Original code comments from SlimDX project, ported from C++/CLI.
// Greetings to SlimDX Group. Original code published with the following license:
// -----------------------------------------------------------------------------
/*
* Copyright (c) 2007-2011 SlimDX Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;
using SharpDX.Direct3D;
namespace SharpDX.D3DCompiler
{
/// <summary>
/// Represents a shader signature.
/// </summary>
public class ShaderSignature : IDisposable
{
/// <summary>
/// Initializes a new instance of the <see cref="T:SharpDX.D3DCompiler.ShaderSignature"/> class.
/// </summary>
/// <param name="ptr">A pointer to a shader signature bytecode.</param>
/// <param name="size">The size.</param>
public ShaderSignature(IntPtr ptr, int size)
{
Data = new byte[size];
Utilities.Read(ptr, Data, 0, Data.Length);
}
/// <summary>
/// Initializes a new instance of the <see cref="T:SharpDX.D3DCompiler.ShaderSignature"/> class.
/// </summary>
/// <param name="blob">The BLOB.</param>
public ShaderSignature(Blob blob)
{
Data = new byte[blob.BufferSize];
Utilities.Read(blob.BufferPointer, Data, 0, Data.Length);
blob.Dispose();
}
/// <summary>
/// Initializes a new instance of the <see cref="T:SharpDX.D3DCompiler.ShaderSignature"/> class.
/// </summary>
/// <param name="data">The data.</param>
public ShaderSignature(DataStream data)
{
Data = new byte[data.Length];
data.Read(Data, 0, Data.Length);
}
/// <summary>
/// Initializes a new instance of the <see cref="T:SharpDX.D3DCompiler.ShaderSignature"/> class.
/// </summary>
/// <param name="data">The data.</param>
public ShaderSignature(byte[] data)
{
Data = data;
}
/// <summary>
/// Gets the raw data of the shader signature.
/// </summary>
public byte[] Data
{
get;
private set;
}
// Win 8.1 SDK removed the corresponding functions from the WinRT platform
#if DESKTOP_APP
/// <summary>
/// Extracts the input and output signatures from a compiled shader or effect.
/// </summary>
/// <param name = "shaderBytecode">The bytecode of the compiled shader or effect.</param>
/// <returns>The input and output signatures of the shader or effect.</returns>
/// <msdn-id>dd607329</msdn-id>
/// <unmanaged>HRESULT D3DGetInputAndOutputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob)</unmanaged>
/// <unmanaged-short>D3DGetInputAndOutputSignatureBlob</unmanaged-short>
public unsafe static ShaderSignature GetInputOutputSignature(byte[] shaderBytecode)
{
Blob shaderSignature;
fixed (void* ptr = shaderBytecode)
if (D3D.GetInputAndOutputSignatureBlob((IntPtr)ptr, shaderBytecode.Length, out shaderSignature).Failure)
return null;
return new ShaderSignature(shaderSignature);
}
/// <summary>
/// Extracts the input signature from a compiled shader or effect.
/// </summary>
/// <param name = "shaderBytecode">The bytecode of the compiled shader or effect.</param>
/// <returns>The input signature of the shader or effect.</returns>
/// <msdn-id>dd607330</msdn-id>
/// <unmanaged>HRESULT D3DGetInputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob)</unmanaged>
/// <unmanaged-short>D3DGetInputSignatureBlob</unmanaged-short>
public unsafe static ShaderSignature GetInputSignature(byte[] shaderBytecode)
{
Blob shaderSignature;
fixed (void* ptr = shaderBytecode)
if (D3D.GetInputSignatureBlob((IntPtr)ptr, shaderBytecode.Length, out shaderSignature).Failure)
return null;
return new ShaderSignature(shaderSignature);
}
/// <summary>
/// Extracts the output signature from a compiled shader or effect.
/// </summary>
/// <param name = "shaderBytecode">The bytecode of the compiled shader or effect.</param>
/// <returns>The output signature of the shader or effect.</returns>
/// <unmanaged>HRESULT D3DGetOutputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob)</unmanaged>
/// <msdn-id>dd607331</msdn-id>
/// <unmanaged>HRESULT D3DGetOutputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob)</unmanaged>
/// <unmanaged-short>D3DGetOutputSignatureBlob</unmanaged-short>
public unsafe static ShaderSignature GetOutputSignature(byte[] shaderBytecode)
{
Blob shaderSignature;
fixed (void* ptr = shaderBytecode)
if (D3D.GetOutputSignatureBlob((IntPtr)ptr, shaderBytecode.Length, out shaderSignature).Failure)
return null;
return new ShaderSignature(shaderSignature);
}
#endif
/// <summary>
/// Cast this <see cref="ShaderSignature"/> to the underlying byte buffer.
/// </summary>
/// <param name="shaderSignature"></param>
/// <returns>A byte buffer</returns>
public static implicit operator byte[](ShaderSignature shaderSignature)
{
return (shaderSignature != null) ? shaderSignature.Data : null;
}
public void Dispose()
{
// Obsolete, just here for backward compatibility
}
}
}