/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.GeometryShader" /> class. /// </summary> /// <param name = "device">The device used to create the shader.</param> /// <param name = "shaderBytecode">The compiled shader bytecode.</param> /// <param name = "linkage">A dynamic class linkage interface.</param> public GeometryShader(Device device, byte[] shaderBytecode, ClassLinkage linkage = null) : base(IntPtr.Zero) { if (shaderBytecode == null) throw new ArgumentNullException("shaderBytecode", "ShaderBytecode cannot be null"); unsafe { fixed (void* pBuffer = shaderBytecode) device.CreateGeometryShader((IntPtr)pBuffer, shaderBytecode.Length, linkage, this); } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.GeometryShader" /> class. /// </summary> /// <param name = "device">The device used to create the shader.</param> /// <param name = "shaderBytecode">The compiled shader bytecode.</param> /// <param name = "elements">An array of <see cref = "T:SharpDX.Direct3D11.StreamOutputElement" /> instances describing the layout of the output buffers.</param> /// <param name = "bufferedStrides">An array of buffer strides; each stride is the size of an element for that buffer.</param> /// <param name = "rasterizedStream">The index number of the stream to be sent to the rasterizer stage. Set to NoRasterizedStream if no stream is to be rasterized.</param> /// <param name = "linkage">A dynamic class linkage interface.</param> public GeometryShader(Device device, byte[] shaderBytecode, StreamOutputElement[] elements, int[] bufferedStrides, int rasterizedStream, ClassLinkage linkage = null) : base(IntPtr.Zero) { unsafe { fixed (void* pBuffer = shaderBytecode) device.CreateGeometryShaderWithStreamOutput((IntPtr)pBuffer, shaderBytecode.Length, elements, elements.Length, bufferedStrides, bufferedStrides.Length, rasterizedStream, linkage, this); } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.GeometryShader" /> class. /// </summary> /// <param name = "device">The device used to create the shader.</param> /// <param name = "shaderBytecode">The compiled shader bytecode.</param> /// <param name = "elements">An array of <see cref = "T:SharpDX.Direct3D11.StreamOutputElement" /> instances describing the layout of the output buffers.</param> /// <param name = "bufferedStrides">An array of buffer strides; each stride is the size of an element for that buffer.</param> /// <param name = "rasterizedStream">The index number of the stream to be sent to the rasterizer stage. Set to NoRasterizedStream if no stream is to be rasterized.</param> /// <param name = "linkage">A dynamic class linkage interface.</param> public GeometryShader(Device device, byte[] shaderBytecode, StreamOutputElement[] elements, int[] bufferedStrides, int rasterizedStream, ClassLinkage linkage = null) : base(IntPtr.Zero) { unsafe { fixed(void *pBuffer = shaderBytecode) device.CreateGeometryShaderWithStreamOutput((IntPtr)pBuffer, shaderBytecode.Length, elements, elements.Length, bufferedStrides, bufferedStrides.Length, rasterizedStream, linkage, this); } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D11.DomainShader" /> class. /// </summary> /// <param name = "device">The device used to create the shader.</param> /// <param name = "shaderBytecode">The compiled shader bytecode.</param> /// <param name = "linkage">A dynamic class linkage interface.</param> public DomainShader(Device device, byte[] shaderBytecode, ClassLinkage linkage = null) : base(IntPtr.Zero) { if (shaderBytecode == null) { throw new ArgumentNullException("shaderBytecode", "ShaderBytecode cannot be null"); } unsafe { fixed(void *pBuffer = shaderBytecode) device.CreateDomainShader((IntPtr)pBuffer, shaderBytecode.Length, linkage, this); } }
private ComputeShader CreateShader(Device device, string sourceCode, string entrypoint) { CompilationResult result = null; try { result = ShaderBytecode.Compile(sourceCode, entrypoint, "cs_5_0", ShaderFlags.EnableStrictness); } catch(CompilationException e) { System.Console.WriteLine(string.Format("[ERROR] failed to compile shader function: {0}", entrypoint)); System.Console.WriteLine(e.Message); return null; } if (result.HasErrors) { System.Console.WriteLine(result.ResultCode.Code); System.Console.WriteLine(result.Message); return null; } var linkage = new ClassLinkage(device); return new ComputeShader(device, result.Bytecode, linkage); }
/// <summary> /// Initializes a class-instance object that represents an HLSL class instance. /// </summary> /// <remarks> /// Instances can be created (or gotten) before or after a shader is created. Use the same shader linkage object to acquire a class instance and create the shader the instance is going to be used in. For more information about using the <see cref="SharpDX.Direct3D11.ClassLinkage"/> interface, see {{Dynamic Linking}}. /// </remarks> /// <param name="linkage">An instance of <see cref="ClassLinkage"/>.</param> /// <param name="classTypeName">The type name of a class to initialize. </param> /// <param name="constantBufferOffset">Identifies the constant buffer that contains the class data. </param> /// <param name="constantVectorOffset">The four-component vector offset from the start of the constant buffer where the class data will begin. Consequently, this is not a byte offset. </param> /// <param name="textureOffset">The texture slot for the first texture; there may be multiple textures following the offset. </param> /// <param name="samplerOffset">The sampler slot for the first sampler; there may be multiple samplers following the offset. </param> /// <returns>Returns S_OK if successful; otherwise, returns one of the following {{Direct3D 11 Return Codes}}. </returns> /// <unmanaged>HRESULT ID3D11ClassLinkage::CreateClassInstance([In] const char* pClassTypeName,[In] int ConstantBufferOffset,[In] int ConstantVectorOffset,[In] int TextureOffset,[In] int SamplerOffset,[Out] ID3D11ClassInstance** ppInstance)</unmanaged> public ClassInstance(ClassLinkage linkage, string classTypeName, int constantBufferOffset, int constantVectorOffset, int textureOffset, int samplerOffset) : base(IntPtr.Zero) { linkage.CreateClassInstance(classTypeName, constantBufferOffset, constantVectorOffset, textureOffset, samplerOffset, this); }
/// <summary> /// Initializes a class-instance object that represents an HLSL class instance. /// </summary> /// <remarks> /// Instances can be created (or gotten) before or after a shader is created. Use the same shader linkage object to acquire a class instance and create the shader the instance is going to be used in. For more information about using the <see cref="SharpDX.Direct3D11.ClassLinkage"/> interface, see {{Dynamic Linking}}. /// </remarks> /// <param name="linkage">An instance of <see cref="ClassLinkage"/>.</param> /// <param name="classTypeName">The type name of a class to initialize. </param> /// <param name="constantBufferOffset">Identifies the constant buffer that contains the class data. </param> /// <param name="constantVectorOffset">The four-component vector offset from the start of the constant buffer where the class data will begin. Consequently, this is not a byte offset. </param> /// <param name="textureOffset">The texture slot for the first texture; there may be multiple textures following the offset. </param> /// <param name="samplerOffset">The sampler slot for the first sampler; there may be multiple samplers following the offset. </param> /// <returns>Returns S_OK if successful; otherwise, returns one of the following {{Direct3D 11 Return Codes}}. </returns> /// <unmanaged>HRESULT ID3D11ClassLinkage::CreateClassInstance([In] const char* pClassTypeName,[In] int ConstantBufferOffset,[In] int ConstantVectorOffset,[In] int TextureOffset,[In] int SamplerOffset,[Out] ID3D11ClassInstance** ppInstance)</unmanaged> public ClassInstance(ClassLinkage linkage, string classTypeName, int constantBufferOffset, int constantVectorOffset, int textureOffset, int samplerOffset) : base(IntPtr.Zero) { linkage.CreateClassInstance(classTypeName, constantBufferOffset, constantVectorOffset, textureOffset, samplerOffset, this); }