// 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 { /// /// Represents a shader signature. /// public class ShaderSignature : IDisposable { /// /// Initializes a new instance of the class. /// /// A pointer to a shader signature bytecode. /// The size. public ShaderSignature(IntPtr ptr, int size) { Data = new byte[size]; Utilities.Read(ptr, Data, 0, Data.Length); } /// /// Initializes a new instance of the class. /// /// The BLOB. public ShaderSignature(Blob blob) { Data = new byte[blob.BufferSize]; Utilities.Read(blob.BufferPointer, Data, 0, Data.Length); blob.Dispose(); } /// /// Initializes a new instance of the class. /// /// The data. public ShaderSignature(DataStream data) { Data = new byte[data.Length]; data.Read(Data, 0, Data.Length); } /// /// Initializes a new instance of the class. /// /// The data. public ShaderSignature(byte[] data) { Data = data; } /// /// Gets the raw data of the shader signature. /// public byte[] Data { get; private set; } /// /// Extracts the input and output signatures from a compiled shader or effect. /// /// The bytecode of the compiled shader or effect. /// The input and output signatures of the shader or effect. /// dd607329 /// HRESULT D3DGetInputAndOutputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob) /// D3DGetInputAndOutputSignatureBlob 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); } /// /// Extracts the input signature from a compiled shader or effect. /// /// The bytecode of the compiled shader or effect. /// The input signature of the shader or effect. /// dd607330 /// HRESULT D3DGetInputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob) /// D3DGetInputSignatureBlob 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); } /// /// Extracts the output signature from a compiled shader or effect. /// /// The bytecode of the compiled shader or effect. /// The output signature of the shader or effect. /// HRESULT D3DGetOutputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob) /// dd607331 /// HRESULT D3DGetOutputSignatureBlob([In, Buffer] const void* pSrcData,[In] SIZE_T SrcDataSize,[Out] ID3D10Blob** ppSignatureBlob) /// D3DGetOutputSignatureBlob 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); } /// /// Cast this to the underlying byte buffer. /// /// /// A byte buffer public static implicit operator byte[](ShaderSignature shaderSignature) { return (shaderSignature != null) ? shaderSignature.Data : null; } public void Dispose() { // Obsolete, just here for backward compatibility } } }