Ejemplo n.º 1
0
        private void LinkConstant(string cbName, Variable variable, LocalParameterKey parameterKey)
        {
            // If the constant buffer is not present, add it
            var constantBuffer = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == cbName);

            if (constantBuffer == null)
            {
                constantBuffer = new EffectConstantBufferDescription()
                {
                    Name = cbName, Type = ConstantBufferType.ConstantBuffer
                };
                effectReflection.ConstantBuffers.Add(constantBuffer);
                var constantBufferBinding = new EffectResourceBindingDescription {
                    KeyInfo = { KeyName = cbName }, Class = EffectParameterClass.ConstantBuffer, Type = EffectParameterType.ConstantBuffer, RawName = cbName, SlotStart = -1, SlotCount = 1, ResourceGroup = cbName
                };
                effectReflection.ResourceBindings.Add(constantBufferBinding);
                valueBindings.Add(constantBuffer, new List <EffectValueDescription>());
            }

            // Get the list of members of this constant buffer
            var members = valueBindings[constantBuffer];

            var binding = new EffectValueDescription
            {
                KeyInfo =
                {
                    KeyName = parameterKey.Name,
                },
                LogicalGroup = (string)variable.GetTag(XenkoTags.LogicalGroup),
                Type         = parameterKey.Type,
                RawName      = variable.Name,
            };

            members.Add(binding);
        }
Ejemplo n.º 2
0
        private LocalParameterKey GetLinkParameterKey(Node node)
        {
            var qualifiers   = node as IQualifiers;
            var attributable = node as IAttributes;

            if ((qualifiers != null &&
                 (qualifiers.Qualifiers.Contains(Stride.Core.Shaders.Ast.Hlsl.StorageQualifier.Static) ||
                  qualifiers.Qualifiers.Contains(StorageQualifier.Const) ||
                  qualifiers.Qualifiers.Contains(Stride.Core.Shaders.Ast.Hlsl.StorageQualifier.Groupshared))) ||
                attributable is null)
            {
                return(null);
            }

            foreach (var annotation in attributable.Attributes.OfType <AttributeDeclaration>())
            {
                if (annotation.Name != "Link" || annotation.Parameters.Count < 1)
                {
                    continue;
                }

                var variableName = (string)annotation.Parameters[0].Value;
                var parameterKey = new LocalParameterKey()
                {
                    Name = variableName
                };
                var variable = node as Variable;
                if (variable != null)
                {
                    var cbuffer = (ConstantBuffer)variable.GetTag(StrideTags.ConstantBuffer);
                    if (cbuffer != null && cbuffer.Type == StrideConstantBufferType.ResourceGroup)
                    {
                        parameterKey.ResourceGroup = cbuffer.Name;
                    }

                    parameterKey.LogicalGroup = (string)variable.GetTag(StrideTags.LogicalGroup);

                    var variableType = variable.Type;

                    parameterKey.Type = CreateTypeInfo(variableType, attributable.Attributes, out parameterKey.ElementType);
                }

                return(parameterKey);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private void LinkConstant(string cbName, Variable variable, LocalParameterKey parameterKey)
        {
            // If the constant buffer is not present, add it
            var constantBuffer = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == cbName);

            if (constantBuffer == null)
            {
                constantBuffer = new ShaderConstantBufferDescription()
                {
                    Name = cbName, Type = ConstantBufferType.ConstantBuffer
                };
                effectReflection.ConstantBuffers.Add(constantBuffer);
                var constantBufferBinding = new EffectParameterResourceData {
                    Param = { KeyName = cbName, Class = EffectParameterClass.ConstantBuffer, Type = EffectParameterType.Buffer, RawName = cbName, ResourceGroup = cbName }, SlotStart = -1, SlotCount = 1
                };
                effectReflection.ResourceBindings.Add(constantBufferBinding);
                valueBindings.Add(constantBuffer, new List <EffectParameterValueData>());
            }

            // Get the list of members of this constant buffer
            var members = valueBindings[constantBuffer];

            var binding = new EffectParameterValueData
            {
                Param =
                {
                    KeyName = parameterKey.Name,
                    Class   = parameterKey.Class,
                    Type    = parameterKey.Type,
                    RawName = variable.Name
                },
                RowCount    = parameterKey.RowCount,
                ColumnCount = parameterKey.ColumnCount,
                Count       = parameterKey.Count,
            };

            members.Add(binding);
        }
Ejemplo n.º 4
0
 private static void LinkVariable(EffectReflection reflection, string variableName, LocalParameterKey parameterKey, int slotCount)
 {
     reflection.ResourceBindings.Add(new EffectResourceBindingDescription
     {
         KeyInfo       = { KeyName = parameterKey.Name },
         Class         = parameterKey.Type.Class,
         Type          = parameterKey.Type.Type,
         ElementType   = parameterKey.ElementType,
         RawName       = variableName,
         SlotStart     = -1,
         SlotCount     = slotCount > 0 ? slotCount : 1,
         ResourceGroup = parameterKey.ResourceGroup,
         LogicalGroup  = parameterKey.LogicalGroup
     });
 }
Ejemplo n.º 5
0
        private void LinkConstant(string cbName, Variable variable, LocalParameterKey parameterKey)
        {
            // If the constant buffer is not present, add it
            var constantBuffer = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == cbName);
            if (constantBuffer == null)
            {
                constantBuffer = new ShaderConstantBufferDescription() {Name = cbName};
                effectReflection.ConstantBuffers.Add(constantBuffer);
                var constantBufferBinding = new EffectParameterResourceData { Param = { KeyName = cbName, Class = EffectParameterClass.ConstantBuffer, Type = EffectParameterType.Buffer, RawName = cbName }, SlotStart = -1 };
                effectReflection.ResourceBindings.Add(constantBufferBinding);
                valueBindings.Add(constantBuffer, new List<EffectParameterValueData>());
            }

            // Get the list of members of this constant buffer
            var members = valueBindings[constantBuffer];

            var binding = new EffectParameterValueData
                {
                    Param =
                        {
                            KeyName = parameterKey.Name,
                            Class = parameterKey.Class,
                            Type = parameterKey.Type,
                            RawName = variable.Name
                        },
                    RowCount = parameterKey.RowCount,
                    ColumnCount = parameterKey.ColumnCount,
                    Count = parameterKey.Count,
                };
            
            members.Add(binding);
        }
Ejemplo n.º 6
0
 private static void LinkVariable(EffectReflection reflection, string variableName, LocalParameterKey parameterKey)
 {
     var binding = new EffectParameterResourceData { Param = { KeyName = parameterKey.Name, Class = parameterKey.Class, Type = parameterKey.Type, RawName = variableName }, SlotStart = -1 };
     reflection.ResourceBindings.Add(binding);
 }
Ejemplo n.º 7
0
        private LocalParameterKey GetLinkParameterKey(Node node)
        {
            var qualifiers = node as IQualifiers;
            var attributable = node as IAttributes;

            if ((qualifiers != null && (qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Static) ||
                                        qualifiers.Qualifiers.Contains(StorageQualifier.Const) ||
                                        qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Groupshared)
                                       )) || attributable == null)
            {
                return null;
            }

            bool isColor = attributable.Attributes.OfType<AttributeDeclaration>().Any(x => x.Name == "Color");

            foreach (var annotation in attributable.Attributes.OfType<AttributeDeclaration>())
            {
                if (annotation.Name != "Link" || annotation.Parameters.Count < 1)
                {
                    continue;
                }

                var variableName = (string)annotation.Parameters[0].Value;
                var parameterKey = new LocalParameterKey() {Name = variableName};
                var variable = node as Variable;
                if (variable != null)
                {
                    var variableType = variable.Type;

                    if (variableType.TypeInference.TargetType != null)
                        variableType = variableType.TypeInference.TargetType;

                    if (variableType is ArrayType)
                    {
                        var arrayType = (ArrayType)variableType;
                        variableType = arrayType.Type;
                        parameterKey.Count = (int)((LiteralExpression)arrayType.Dimensions[0]).Literal.Value;

                        if (variableType.TypeInference.TargetType != null)
                            variableType = variableType.TypeInference.TargetType;
                    }
                    
                    if (variableType.IsBuiltIn)
                    {
                        var variableTypeName = variableType.Name.Text.ToLower();

                        switch (variableTypeName)
                        {
                            case "cbuffer":
                                parameterKey.Class = EffectParameterClass.ConstantBuffer;
                                parameterKey.Type = EffectParameterType.ConstantBuffer;
                                break;

                            case "tbuffer":
                                parameterKey.Class = EffectParameterClass.TextureBuffer;
                                parameterKey.Type = EffectParameterType.TextureBuffer;
                                break;

                            case "structuredbuffer":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.StructuredBuffer;
                                break;
                            case "rwstructuredbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWStructuredBuffer;
                                break;
                            case "consumestructuredbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.ConsumeStructuredBuffer;
                                break;
                            case "appendstructuredbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.AppendStructuredBuffer;
                                break;
                            case "buffer":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Buffer;
                                break;
                            case "rwbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWBuffer;
                                break;
                            case "byteaddressbuffer":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.ByteAddressBuffer;
                                break;
                            case "rwbyteaddressbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWByteAddressBuffer;
                                break;

                            case "texture1d":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Texture1D;
                                break;

                            case "texturecube":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.TextureCube;
                                break;

                            case "texture2d":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Texture2D;
                                break;

                            case "texture3d":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Texture3D;
                                break;

                            case "rwtexture1d":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWTexture1D;
                                break;

                            case "rwtexture2d":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWTexture2D;
                                break;

                            case "rwtexture3d":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWTexture3D;
                                break;

                            case "samplerstate":
                                parameterKey.Class = EffectParameterClass.Sampler;
                                parameterKey.Type = EffectParameterType.Sampler;
                                break;
                        }
                    }
                    else if (variableType is ScalarType)
                    {
                        // Uint and int are collapsed to int
                        if (variableType == ScalarType.Int || variableType == ScalarType.UInt)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type = variableType == ScalarType.Int ? EffectParameterType.Int : EffectParameterType.UInt;
                        }
                        else if (variableType == ScalarType.Float)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type = EffectParameterType.Float;
                        }
                        else if (variableType == ScalarType.Bool)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type = EffectParameterType.Bool;
                        }

                        parameterKey.RowCount = 1;
                        parameterKey.ColumnCount = 1;
                    }
                    else if (variableType is VectorType)
                    {
                        if (variableType == VectorType.Float2 || variableType == VectorType.Float3 || variableType == VectorType.Float4)
                        {
                            parameterKey.Class = isColor ? EffectParameterClass.Color : EffectParameterClass.Vector;
                            parameterKey.Type = EffectParameterType.Float;
                        }
                        else if (variableType == VectorType.Int2 || variableType == VectorType.Int3 || variableType == VectorType.Int4)
                        {
                            parameterKey.Class = EffectParameterClass.Vector;
                            parameterKey.Type = EffectParameterType.Int;
                        }
                        else if (variableType == VectorType.UInt2 || variableType == VectorType.UInt3 || variableType == VectorType.UInt4)
                        {
                            parameterKey.Class = EffectParameterClass.Vector;
                            parameterKey.Type = EffectParameterType.UInt;
                        }

                        parameterKey.RowCount = 1;
                        parameterKey.ColumnCount = (variableType as VectorType).Dimension;
                    }
                    else if (variableType is MatrixType)
                    {
                        parameterKey.Class = EffectParameterClass.MatrixColumns;
                        parameterKey.Type = EffectParameterType.Float;
                        parameterKey.RowCount = (variableType as MatrixType).RowCount;
                        parameterKey.ColumnCount = (variableType as MatrixType).ColumnCount;
                    }
                    else if (variableType is StructType)
                    {
                        parameterKey.Class = EffectParameterClass.Struct;
                        parameterKey.RowCount = 1;
                        parameterKey.ColumnCount = 1;
                    }
                }

                return parameterKey;
            }

            return null;
        }
Ejemplo n.º 8
0
        private static void LinkVariable(EffectReflection reflection, string variableName, LocalParameterKey parameterKey, int slotCount)
        {
            var binding = new EffectParameterResourceData {
                Param = { KeyName = parameterKey.Name, Class = parameterKey.Class, Type = parameterKey.Type, ResourceGroup = parameterKey.ResourceGroup, RawName = variableName }, SlotStart = -1, SlotCount = slotCount > 0 ? slotCount : 1
            };

            reflection.ResourceBindings.Add(binding);
        }
Ejemplo n.º 9
0
        private LocalParameterKey GetLinkParameterKey(Node node)
        {
            var qualifiers   = node as IQualifiers;
            var attributable = node as IAttributes;

            if ((qualifiers != null && (qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Static) ||
                                        qualifiers.Qualifiers.Contains(StorageQualifier.Const) ||
                                        qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Groupshared)
                                        )) || attributable == null)
            {
                return(null);
            }

            bool isColor = attributable.Attributes.OfType <AttributeDeclaration>().Any(x => x.Name == "Color");

            foreach (var annotation in attributable.Attributes.OfType <AttributeDeclaration>())
            {
                if (annotation.Name != "Link" || annotation.Parameters.Count < 1)
                {
                    continue;
                }

                var variableName = (string)annotation.Parameters[0].Value;
                var parameterKey = new LocalParameterKey()
                {
                    Name = variableName
                };
                var variable = node as Variable;
                if (variable != null)
                {
                    var variableType = variable.Type;

                    var cbuffer = (ConstantBuffer)variable.GetTag(XenkoTags.ConstantBuffer);
                    if (cbuffer != null && cbuffer.Type == XenkoConstantBufferType.ResourceGroup)
                    {
                        parameterKey.ResourceGroup = cbuffer.Name;
                    }

                    if (variableType.TypeInference.TargetType != null)
                    {
                        variableType = variableType.TypeInference.TargetType;
                    }

                    if (variableType is ArrayType)
                    {
                        var arrayType = (ArrayType)variableType;
                        variableType       = arrayType.Type;
                        parameterKey.Count = (int)((LiteralExpression)arrayType.Dimensions[0]).Literal.Value;

                        if (variableType.TypeInference.TargetType != null)
                        {
                            variableType = variableType.TypeInference.TargetType;
                        }
                    }

                    if (variableType.IsBuiltIn)
                    {
                        var variableTypeName = variableType.Name.Text.ToLower();

                        switch (variableTypeName)
                        {
                        case "cbuffer":
                            parameterKey.Class = EffectParameterClass.ConstantBuffer;
                            parameterKey.Type  = EffectParameterType.ConstantBuffer;
                            break;

                        case "tbuffer":
                            parameterKey.Class = EffectParameterClass.TextureBuffer;
                            parameterKey.Type  = EffectParameterType.TextureBuffer;
                            break;

                        case "structuredbuffer":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.StructuredBuffer;
                            break;

                        case "rwstructuredbuffer":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.RWStructuredBuffer;
                            break;

                        case "consumestructuredbuffer":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.ConsumeStructuredBuffer;
                            break;

                        case "appendstructuredbuffer":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.AppendStructuredBuffer;
                            break;

                        case "buffer":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.Buffer;
                            break;

                        case "rwbuffer":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.RWBuffer;
                            break;

                        case "byteaddressbuffer":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.ByteAddressBuffer;
                            break;

                        case "rwbyteaddressbuffer":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.RWByteAddressBuffer;
                            break;

                        case "texture1d":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.Texture1D;
                            break;

                        case "texturecube":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.TextureCube;
                            break;

                        case "texture2d":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.Texture2D;
                            break;

                        case "texture3d":
                            parameterKey.Class = EffectParameterClass.ShaderResourceView;
                            parameterKey.Type  = EffectParameterType.Texture3D;
                            break;

                        case "rwtexture1d":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.RWTexture1D;
                            break;

                        case "rwtexture2d":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.RWTexture2D;
                            break;

                        case "rwtexture3d":
                            parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                            parameterKey.Type  = EffectParameterType.RWTexture3D;
                            break;

                        case "samplerstate":
                        case "samplercomparisonstate":
                            parameterKey.Class = EffectParameterClass.Sampler;
                            parameterKey.Type  = EffectParameterType.Sampler;
                            break;
                        }
                    }
                    else if (variableType is ScalarType)
                    {
                        // Uint and int are collapsed to int
                        if (variableType == ScalarType.Int || variableType == ScalarType.UInt)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type  = variableType == ScalarType.Int ? EffectParameterType.Int : EffectParameterType.UInt;
                        }
                        else if (variableType == ScalarType.Float)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type  = EffectParameterType.Float;
                        }
                        else if (variableType == ScalarType.Bool)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type  = EffectParameterType.Bool;
                        }

                        parameterKey.RowCount    = 1;
                        parameterKey.ColumnCount = 1;
                    }
                    else if (variableType is VectorType)
                    {
                        if (variableType == VectorType.Float2 || variableType == VectorType.Float3 || variableType == VectorType.Float4)
                        {
                            parameterKey.Class = isColor ? EffectParameterClass.Color : EffectParameterClass.Vector;
                            parameterKey.Type  = EffectParameterType.Float;
                        }
                        else if (variableType == VectorType.Int2 || variableType == VectorType.Int3 || variableType == VectorType.Int4)
                        {
                            parameterKey.Class = EffectParameterClass.Vector;
                            parameterKey.Type  = EffectParameterType.Int;
                        }
                        else if (variableType == VectorType.UInt2 || variableType == VectorType.UInt3 || variableType == VectorType.UInt4)
                        {
                            parameterKey.Class = EffectParameterClass.Vector;
                            parameterKey.Type  = EffectParameterType.UInt;
                        }

                        parameterKey.RowCount    = 1;
                        parameterKey.ColumnCount = (variableType as VectorType).Dimension;
                    }
                    else if (variableType is MatrixType)
                    {
                        parameterKey.Class       = EffectParameterClass.MatrixColumns;
                        parameterKey.Type        = EffectParameterType.Float;
                        parameterKey.RowCount    = (variableType as MatrixType).RowCount;
                        parameterKey.ColumnCount = (variableType as MatrixType).ColumnCount;
                    }
                    else if (variableType is StructType)
                    {
                        parameterKey.Class       = EffectParameterClass.Struct;
                        parameterKey.RowCount    = 1;
                        parameterKey.ColumnCount = 1;
                    }
                }

                return(parameterKey);
            }

            return(null);
        }
Ejemplo n.º 10
0
        private void LinkConstant(string cbName, Variable variable, LocalParameterKey parameterKey)
        {
            // If the constant buffer is not present, add it
            var constantBuffer = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == cbName);
            if (constantBuffer == null)
            {
                constantBuffer = new EffectConstantBufferDescription() {Name = cbName, Type = ConstantBufferType.ConstantBuffer};
                effectReflection.ConstantBuffers.Add(constantBuffer);
                var constantBufferBinding = new EffectResourceBindingDescription { KeyInfo = { KeyName = cbName }, Class = EffectParameterClass.ConstantBuffer, Type = EffectParameterType.ConstantBuffer, RawName = cbName, SlotStart = -1, SlotCount = 1, ResourceGroup = cbName };
                effectReflection.ResourceBindings.Add(constantBufferBinding);
                valueBindings.Add(constantBuffer, new List<EffectValueDescription>());
            }

            // Get the list of members of this constant buffer
            var members = valueBindings[constantBuffer];

            var binding = new EffectValueDescription
            {
                KeyInfo =
                {
                    KeyName = parameterKey.Name,
                },
                LogicalGroup = (string)variable.GetTag(XenkoTags.LogicalGroup),
                Type = parameterKey.Type,
                RawName = variable.Name,
            };
            
            members.Add(binding);
        }
Ejemplo n.º 11
0
 private static void LinkVariable(EffectReflection reflection, string variableName, LocalParameterKey parameterKey, int slotCount)
 {
     var binding = new EffectResourceBindingDescription { KeyInfo = { KeyName = parameterKey.Name }, Class = parameterKey.Type.Class, Type = parameterKey.Type.Type, RawName = variableName, SlotStart = -1, SlotCount = slotCount > 0 ? slotCount : 1, ResourceGroup = parameterKey.ResourceGroup, LogicalGroup = parameterKey.LogicalGroup };
     reflection.ResourceBindings.Add(binding);
 }
Ejemplo n.º 12
0
        private LocalParameterKey GetLinkParameterKey(Node node)
        {
            var qualifiers = node as IQualifiers;
            var attributable = node as IAttributes;

            if ((qualifiers != null && (qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Static) ||
                                        qualifiers.Qualifiers.Contains(StorageQualifier.Const) ||
                                        qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Groupshared)
                                       )) || attributable == null)
            {
                return null;
            }

            foreach (var annotation in attributable.Attributes.OfType<AttributeDeclaration>())
            {
                if (annotation.Name != "Link" || annotation.Parameters.Count < 1)
                {
                    continue;
                }

                var variableName = (string)annotation.Parameters[0].Value;
                var parameterKey = new LocalParameterKey() {Name = variableName};
                var variable = node as Variable;
                if (variable != null)
                {
                    var cbuffer = (ConstantBuffer)variable.GetTag(XenkoTags.ConstantBuffer);
                    if (cbuffer != null && cbuffer.Type == XenkoConstantBufferType.ResourceGroup)
                    {
                        parameterKey.ResourceGroup = cbuffer.Name;
                    }

                    parameterKey.LogicalGroup = (string)variable.GetTag(XenkoTags.LogicalGroup);

                    var variableType = variable.Type;

                    parameterKey.Type = CreateTypeInfo(variableType, attributable.Attributes);
                }

                return parameterKey;
            }

            return null;
        }
Ejemplo n.º 13
0
        private static void LinkVariable(EffectReflection reflection, string variableName, LocalParameterKey parameterKey)
        {
            var binding = new EffectParameterResourceData {
                Param = { KeyName = parameterKey.Name, Class = parameterKey.Class, Type = parameterKey.Type, RawName = variableName }
            };

            reflection.ResourceBindings.Add(binding);
        }