2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include "../ComObject.h"
\r
26 #include "IncludeDC.h"
\r
27 #include "ShaderMacroDC.h"
\r
31 namespace D3DCompiler
\r
34 /// Represents the compiled bytecode of a shader or effect.
\r
36 /// <unmanaged>ID3D10Blob</unmanaged>
\r
37 public ref class ShaderBytecode : ComObject
\r
39 COMOBJECT(ID3D10Blob, ShaderBytecode);
\r
42 ShaderBytecode( const BYTE* data, UINT length );
\r
46 /// Initializes a new instance of the <see cref="ShaderBytecode"/> class.
\r
48 /// <param name="data">A <see cref="DataStream"/> containing the compiled bytecode.</param>
\r
49 ShaderBytecode( DataStream^ data );
\r
52 /// Compiles the provided shader or effect source.
\r
54 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
\r
55 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
56 /// <param name="shaderFlags">Shader compilation options.</param>
\r
57 /// <param name="effectFlags">Effect compilation options.</param>
\r
58 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
59 static ShaderBytecode^ Compile( System::String^ shaderSource, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags );
\r
62 /// Compiles the provided shader or effect source.
\r
64 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
\r
65 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
66 /// <param name="shaderFlags">Shader compilation options.</param>
\r
67 /// <param name="effectFlags">Effect compilation options.</param>
\r
68 /// <param name="defines">A set of macros to define during compilation.</param>
\r
69 /// <param name="include">An interface for handling include files.</param>
\r
70 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
71 static ShaderBytecode^ Compile( System::String^ shaderSource, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include );
\r
74 /// Compiles the provided shader or effect source.
\r
76 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
\r
77 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
78 /// <param name="shaderFlags">Shader compilation options.</param>
\r
79 /// <param name="effectFlags">Effect compilation options.</param>
\r
80 /// <param name="defines">A set of macros to define during compilation.</param>
\r
81 /// <param name="include">An interface for handling include files.</param>
\r
82 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
\r
83 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
84 static ShaderBytecode^ Compile( System::String^ shaderSource, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
87 /// Compiles the provided shader or effect source.
\r
89 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
\r
90 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
91 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
92 /// <param name="shaderFlags">Shader compilation options.</param>
\r
93 /// <param name="effectFlags">Effect compilation options.</param>
\r
94 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
95 static ShaderBytecode^ Compile( System::String^ shaderSource, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags );
\r
98 /// Compiles the provided shader or effect source.
\r
100 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
\r
101 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
102 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
103 /// <param name="shaderFlags">Shader compilation options.</param>
\r
104 /// <param name="effectFlags">Effect compilation options.</param>
\r
105 /// <param name="defines">A set of macros to define during compilation.</param>
\r
106 /// <param name="include">An interface for handling include files.</param>
\r
107 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
108 static ShaderBytecode^ Compile( System::String^ shaderSource, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include );
\r
111 /// Compiles the provided shader or effect source.
\r
113 /// <param name="shaderSource">A string containing the source of the shader or effect to compile.</param>
\r
114 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
115 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
116 /// <param name="shaderFlags">Shader compilation options.</param>
\r
117 /// <param name="effectFlags">Effect compilation options.</param>
\r
118 /// <param name="defines">A set of macros to define during compilation.</param>
\r
119 /// <param name="include">An interface for handling include files.</param>
\r
120 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
\r
121 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
122 static ShaderBytecode^ Compile( System::String^ shaderSource, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
125 /// Compiles the provided shader or effect source.
\r
127 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
\r
128 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
129 /// <param name="shaderFlags">Shader compilation options.</param>
\r
130 /// <param name="effectFlags">Effect compilation options.</param>
\r
131 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
132 static ShaderBytecode^ Compile( array<System::Byte>^ shaderSource, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags );
\r
135 /// Compiles the provided shader or effect source.
\r
137 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
\r
138 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
139 /// <param name="shaderFlags">Shader compilation options.</param>
\r
140 /// <param name="effectFlags">Effect compilation options.</param>
\r
141 /// <param name="defines">A set of macros to define during compilation.</param>
\r
142 /// <param name="include">An interface for handling include files.</param>
\r
143 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
144 static ShaderBytecode^ Compile( array<System::Byte>^ shaderSource, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include );
\r
147 /// Compiles the provided shader or effect source.
\r
149 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
\r
150 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
151 /// <param name="shaderFlags">Shader compilation options.</param>
\r
152 /// <param name="effectFlags">Effect compilation options.</param>
\r
153 /// <param name="defines">A set of macros to define during compilation.</param>
\r
154 /// <param name="include">An interface for handling include files.</param>
\r
155 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
\r
156 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
157 static ShaderBytecode^ Compile( array<System::Byte>^ shaderSource, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
160 /// Compiles the provided shader or effect source.
\r
162 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
\r
163 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
164 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
165 /// <param name="shaderFlags">Shader compilation options.</param>
\r
166 /// <param name="effectFlags">Effect compilation options.</param>
\r
167 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
168 static ShaderBytecode^ Compile( array<System::Byte>^ shaderSource, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags );
\r
171 /// Compiles the provided shader or effect source.
\r
173 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
\r
174 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
175 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
176 /// <param name="shaderFlags">Shader compilation options.</param>
\r
177 /// <param name="effectFlags">Effect compilation options.</param>
\r
178 /// <param name="defines">A set of macros to define during compilation.</param>
\r
179 /// <param name="include">An interface for handling include files.</param>
\r
180 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
181 static ShaderBytecode^ Compile( array<System::Byte>^ shaderSource, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include );
\r
184 /// Compiles the provided shader or effect source.
\r
186 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
\r
187 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
188 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
189 /// <param name="shaderFlags">Shader compilation options.</param>
\r
190 /// <param name="effectFlags">Effect compilation options.</param>
\r
191 /// <param name="defines">A set of macros to define during compilation.</param>
\r
192 /// <param name="include">An interface for handling include files.</param>
\r
193 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
\r
194 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
195 static ShaderBytecode^ Compile( array<System::Byte>^ shaderSource, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
198 /// Compiles a shader or effect from a file on disk.
\r
200 /// <param name="fileName">The name of the source file to compile.</param>
\r
201 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
202 /// <param name="shaderFlags">Shader compilation options.</param>
\r
203 /// <param name="effectFlags">Effect compilation options.</param>
\r
204 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
205 static ShaderBytecode^ CompileFromFile( System::String^ fileName, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags );
\r
208 /// Compiles a shader or effect from a file on disk.
\r
210 /// <param name="fileName">The name of the source file to compile.</param>
\r
211 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
212 /// <param name="shaderFlags">Shader compilation options.</param>
\r
213 /// <param name="effectFlags">Effect compilation options.</param>
\r
214 /// <param name="defines">A set of macros to define during compilation.</param>
\r
215 /// <param name="include">An interface for handling include files.</param>
\r
216 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
217 static ShaderBytecode^ CompileFromFile( System::String^ fileName, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include );
\r
220 /// Compiles a shader or effect from a file on disk.
\r
222 /// <param name="fileName">The name of the source file to compile.</param>
\r
223 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
224 /// <param name="shaderFlags">Shader compilation options.</param>
\r
225 /// <param name="effectFlags">Effect compilation options.</param>
\r
226 /// <param name="defines">A set of macros to define during compilation.</param>
\r
227 /// <param name="include">An interface for handling include files.</param>
\r
228 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
\r
229 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
230 static ShaderBytecode^ CompileFromFile( System::String^ fileName, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
233 /// Compiles a shader or effect from a file on disk.
\r
235 /// <param name="fileName">The name of the source file to compile.</param>
\r
236 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
237 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
238 /// <param name="shaderFlags">Shader compilation options.</param>
\r
239 /// <param name="effectFlags">Effect compilation options.</param>
\r
240 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
241 static ShaderBytecode^ CompileFromFile( System::String^ fileName, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags );
\r
244 /// Compiles a shader or effect from a file on disk.
\r
246 /// <param name="fileName">The name of the source file to compile.</param>
\r
247 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
248 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
249 /// <param name="shaderFlags">Shader compilation options.</param>
\r
250 /// <param name="effectFlags">Effect compilation options.</param>
\r
251 /// <param name="defines">A set of macros to define during compilation.</param>
\r
252 /// <param name="include">An interface for handling include files.</param>
\r
253 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
254 static ShaderBytecode^ CompileFromFile( System::String^ fileName, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include );
\r
257 /// Compiles a shader or effect from a file on disk.
\r
259 /// <param name="fileName">The name of the source file to compile.</param>
\r
260 /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
\r
261 /// <param name="profile">The shader target or set of shader features to compile against.</param>
\r
262 /// <param name="shaderFlags">Shader compilation options.</param>
\r
263 /// <param name="effectFlags">Effect compilation options.</param>
\r
264 /// <param name="defines">A set of macros to define during compilation.</param>
\r
265 /// <param name="include">An interface for handling include files.</param>
\r
266 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if compilation succeeded.</param>
\r
267 /// <returns>The compiled shader bytecode, or <c>null</c> if the method fails.</returns>
\r
268 static ShaderBytecode^ CompileFromFile( System::String^ fileName, System::String^ entryPoint, System::String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
271 /// Preprocesses the provided shader or effect source.
\r
273 /// <param name="shaderSource">A string containing the source of the shader or effect to preprocess.</param>
\r
274 /// <returns>The preprocessed shader source.</returns>
\r
275 static System::String^ Preprocess( System::String^ shaderSource );
\r
278 /// Preprocesses the provided shader or effect source.
\r
280 /// <param name="shaderSource">A string containing the source of the shader or effect to preprocess.</param>
\r
281 /// <param name="defines">A set of macros to define during preprocessing.</param>
\r
282 /// <param name="include">An interface for handling include files.</param>
\r
283 /// <returns>The preprocessed shader source.</returns>
\r
284 static System::String^ Preprocess( System::String^ shaderSource, array<ShaderMacro>^ defines, Include^ include );
\r
287 /// Preprocesses the provided shader or effect source.
\r
289 /// <param name="shaderSource">A string containing the source of the shader or effect to preprocess.</param>
\r
290 /// <param name="defines">A set of macros to define during preprocessing.</param>
\r
291 /// <param name="include">An interface for handling include files.</param>
\r
292 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if preprocessing succeeded.</param>
\r
293 /// <returns>The preprocessed shader source.</returns>
\r
294 static System::String^ Preprocess( System::String^ shaderSource, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
297 /// Preprocesses the provided shader or effect source.
\r
299 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to preprocess.</param>
\r
300 /// <returns>The preprocessed shader source.</returns>
\r
301 static System::String^ Preprocess( array<System::Byte>^ shaderSource );
\r
304 /// Preprocesses the provided shader or effect source.
\r
306 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to preprocess.</param>
\r
307 /// <param name="defines">A set of macros to define during preprocessing.</param>
\r
308 /// <param name="include">An interface for handling include files.</param>
\r
309 /// <returns>The preprocessed shader source.</returns>
\r
310 static System::String^ Preprocess( array<System::Byte>^ shaderSource, array<ShaderMacro>^ defines, Include^ include );
\r
313 /// Preprocesses the provided shader or effect source.
\r
315 /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to preprocess.</param>
\r
316 /// <param name="defines">A set of macros to define during preprocessing.</param>
\r
317 /// <param name="include">An interface for handling include files.</param>
\r
318 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if preprocessing succeeded.</param>
\r
319 /// <returns>The preprocessed shader source.</returns>
\r
320 static System::String^ Preprocess( array<System::Byte>^ shaderSource, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
323 /// Preprocesses a shader or effect from a file on disk.
\r
325 /// <param name="fileName">The name of the source file to compile.</param>
\r
326 /// <returns>The preprocessed shader source.</returns>
\r
327 static System::String^ PreprocessFromFile( System::String^ fileName );
\r
330 /// Preprocesses a shader or effect from a file on disk.
\r
332 /// <param name="fileName">The name of the source file to compile.</param>
\r
333 /// <param name="defines">A set of macros to define during preprocessing.</param>
\r
334 /// <param name="include">An interface for handling include files.</param>
\r
335 /// <returns>The preprocessed shader source.</returns>
\r
336 static System::String^ PreprocessFromFile( System::String^ fileName, array<ShaderMacro>^ defines, Include^ include );
\r
339 /// Preprocesses a shader or effect from a file on disk.
\r
341 /// <param name="fileName">The name of the source file to compile.</param>
\r
342 /// <param name="defines">A set of macros to define during preprocessing.</param>
\r
343 /// <param name="include">An interface for handling include files.</param>
\r
344 /// <param name="compilationErrors">When the method completes, contains a string of compilation errors, or an empty string if preprocessing succeeded.</param>
\r
345 /// <returns>The preprocessed shader source.</returns>
\r
346 static System::String^ PreprocessFromFile( System::String^ fileName, array<ShaderMacro>^ defines, Include^ include, [Out] System::String^ %compilationErrors );
\r
349 /// Gets the raw data of the compiled bytecode.
\r
351 property DataStream^ Data
\r
357 /// Disassembles compiled HLSL code back into textual source.
\r
359 /// <returns>The textual source of the shader or effect.</returns>
\r
360 System::String^ Disassemble();
\r
363 /// Disassembles compiled HLSL code back into textual source.
\r
365 /// <param name="flags">Flags affecting the output of the disassembly.</param>
\r
366 /// <returns>The textual source of the shader or effect.</returns>
\r
367 System::String^ Disassemble(DisassemblyFlags flags);
\r
370 /// Disassembles compiled HLSL code back into textual source.
\r
372 /// <param name="flags">Flags affecting the output of the disassembly.</param>
\r
373 /// <param name="comments">Commenting information to embed in the disassembly.</param>
\r
374 /// <returns>The textual source of the shader or effect.</returns>
\r
375 System::String^ Disassemble(DisassemblyFlags flags, System::String^ comments);
\r
378 /// Strips extraneous information from a compiled shader or effect.
\r
380 /// <param name="flags">Options specifying what to remove from the shader.</param>
\r
381 /// <returns>A string containing any errors that may have occurred.</returns>
\r
382 System::String^ Strip(StripFlags flags);
\r
385 /// Returns the hash code for this instance.
\r
387 /// <returns>A 32-bit signed integer hash code.</returns>
\r
388 virtual int GetHashCode() override;
\r