// Copyright (c) 2010-2014 SharpDX - SharpDX Team
//
// 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 SharpDX.Direct3D;
namespace SharpDX.D3DCompiler
{
///
/// [This documentation is preliminary and is subject to change.]
A function-linking-graph interface is used for constructing shaders that consist of a sequence of precompiled function calls that pass values to each other .
///
///
/// To get a function-linking-graph interface, call .
You can use the function-linking-graph (FLG) interface methods to construct shaders that consist of a sequence of precompiled function calls that pass values to each other. You don't need to write HLSL and then call the HLSL compiler. Instead, the shader structure is specified programmatically via a C++ API. FLG nodes represent input and output signatures and invocations of precompiled library functions. The order of registering the function-call nodes defines the sequence of invocations. You must specify the input signature node first and the output signature node last. FLG edges define how values are passed from one node to another. The data types of passed values must be the same; there is no implicit type conversion. Shape and swizzling rules follow the HLSL behavior. Values can only be passed forward in this sequence.
///
///
/// dn280535
/// ID3D11FunctionLinkingGraph
/// ID3D11FunctionLinkingGraph
public partial class FunctionLinkingGraph
{
// Slot ID for library function return
// #define D3D_RETURN_PARAMETER_INDEX (-1)
private const int ReturnParameterIndex = -1;
///
/// Initializes a new instance of .
///
public FunctionLinkingGraph()
{
D3D.CreateFunctionLinkingGraph(0, this);
}
///
/// [This documentation is preliminary and is subject to change.]
Sets the input signature of the function-linking-graph.
///
///
An array of structures for the parameters of the input signature.
/// A reference to the interface that represents the input signature of the function-linking-graph.
/// dn280542
/// HRESULT ID3D11FunctionLinkingGraph::SetInputSignature([In, Buffer] const D3D11_PARAMETER_DESC* pInputParameters,[In] unsigned int cInputParameters,[Out] ID3D11LinkingNode** ppInputNode)
/// ID3D11FunctionLinkingGraph::SetInputSignature
public LinkingNode SetInputSignature(params ParameterDescription[] parameters)
{
LinkingNode node;
SetInputSignature(parameters, parameters.Length, out node);
return node;
}
///
/// [This documentation is preliminary and is subject to change.]
Sets the output signature of the function-linking-graph.
///
/// An array of structures for the parameters of the output signature.
/// A reference to the interface that represents the output signature of the function-linking-graph.
/// dn280543
/// HRESULT ID3D11FunctionLinkingGraph::SetOutputSignature([In, Buffer] const D3D11_PARAMETER_DESC* pOutputParameters,[In] unsigned int cOutputParameters,[Out] ID3D11LinkingNode** ppOutputNode)
/// ID3D11FunctionLinkingGraph::SetOutputSignature
public LinkingNode SetOutputSignature(params ParameterDescription[] parameters)
{
LinkingNode node;
SetOutputSignature(parameters, parameters.Length, out node);
return node;
}
///
/// [This documentation is preliminary and is subject to change.]
Initializes a shader module from the function-linking-graph object.
///
/// A reference to an interface for the shader module to initialize.
/// dn280537
/// HRESULT ID3D11FunctionLinkingGraph::CreateModuleInstance([Out] ID3D11ModuleInstance** ppModuleInstance,[Out, Optional] ID3D10Blob** ppErrorBuffer)
/// ID3D11FunctionLinkingGraph::CreateModuleInstance
/// Is thrown when creation fails and the error text is available.
/// Is thrown when creation fails and the error text is not available.
public ModuleInstance CreateModuleInstance()
{
ModuleInstance module;
Blob errorBlob;
var resultCode = CreateModuleInstance(out module, out errorBlob);
if (resultCode.Failure)
{
if (errorBlob != null)
throw new CompilationException(resultCode, Utilities.BlobToString(errorBlob));
throw new SharpDXException(resultCode);
}
return module;
}
///
/// Gets the error from the last function call of the function-linking-graph, as a string
///
public string LastErrorString
{
get { return Utilities.BlobToString(this.LastError); }
}
///
/// [This documentation is preliminary and is subject to change.]
Creates a call-function linking node to use in the function-linking-graph.
///
/// A reference to the interface for the library module that contains the function prototype.
/// The name of the function.
/// A reference to a variable that receives a reference to the interface that represents the function in the function-linking-graph.
/// dn280536
/// HRESULT ID3D11FunctionLinkingGraph::CallFunction([In, Optional] const char* pModuleInstanceNamespace,[In] ID3D11Module* pModuleWithFunctionPrototype,[In] const char* pFunctionName,[Out] ID3D11LinkingNode** ppCallNode)
/// ID3D11FunctionLinkingGraph::CallFunction
public LinkingNode CallFunction(Module moduleWithFunctionPrototypeRef, string functionNameRef)
{
return CallFunction(string.Empty, moduleWithFunctionPrototypeRef, functionNameRef);
}
///
/// [This documentation is preliminary and is subject to change.]
Passes the return value from a source linking node to a destination linking node.
///
/// As return value is used the constant D3D_RETURN_PARAMETER_INDEX.
/// A reference to the interface for the source linking node.
/// A reference to the interface for the destination linking node.
/// The zero-based index of the destination parameter.
/// Returns if successful; otherwise, returns one of the Direct3D 11 Return Codes.
/// dn280540
/// HRESULT ID3D11FunctionLinkingGraph::PassValue([In] ID3D11LinkingNode* pSrcNode,[In] int SrcParameterIndex,[In] ID3D11LinkingNode* pDstNode,[In] int DstParameterIndex)
/// ID3D11FunctionLinkingGraph::PassValue
public void PassValue(LinkingNode sourceNode, LinkingNode destinationNode, int destinationParameterIndex)
{
PassValue(sourceNode, ReturnParameterIndex, destinationNode, destinationParameterIndex);
}
///
/// Generates hlsl code for function linking grpah
///
/// Flags (unused by the runtime for now)
/// Hlsl code as string
public string GenerateHlsl(int uFlags)
{
SharpDX.Direct3D.Blob blob;
GenerateHlsl(0, out blob);
string result = SharpDX.Utilities.BlobToString(blob);
blob.Dispose();
return result;
}
}
}