Ejemplo n.º 1
0
        internal void AddField(MappedField field)
        {
            int size = field.GetTotalSizeOf();

            if (field.PackOffsetBytes.HasValue)
            {
                int minSize = field.PackOffsetBytes.Value + size;
                SizeOf = Math.Max(minSize, SizeOf);
            }
            else
            {
                field.PackOffsetBytes = SizeOf;
                SizeOf += size;
            }

            Variables.Add(field);
        }
Ejemplo n.º 2
0
        private ShaderMember PopulateMember(MappedField mField)
        {
            ShaderElementInfo eInfo = new ShaderElementInfo(
                dataType: mField.Type.DataType,
                dimensions: new List <int>(mField.Type.Dimensions),
                size: mField.Type.SizeOf,
                subElementCount: mField.Type.SubElementCount,
                subElementSize: mField.Type.SubElementSizeOf,
                strucType: mField.StructureType
                );

            return(new ShaderMember(
                       name: mField.Name,
                       arrayDimensions: new List <int>(mField.ArrayDimensions),
                       elementCount: mField.GetTotalArrayElements(),
                       startOffset: mField.PackOffsetBytes.HasValue ? mField.PackOffsetBytes.Value : 0,
                       elementInfo: eInfo,
                       sizeOf: mField.GetTotalSizeOf(),
                       resType: mField.ResourceType,
                       resBaseType: mField.ResourceBaseType
                       ));
        }
Ejemplo n.º 3
0
 internal override void TranslateFieldPostfix(ShaderTranslationContext sc, VariableDeclaratorSyntax syntax, MappedField field, int fieldIndex, MappedConstantBuffer cBufferMap)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
 internal abstract void TranslateFieldPostfix(ShaderTranslationContext sc, VariableDeclaratorSyntax syntax, MappedField field, int fieldIndex, MappedConstantBuffer cBufferMap);
Ejemplo n.º 5
0
        internal override void TranslateFieldPostfix(ShaderTranslationContext sc, VariableDeclaratorSyntax syntax, MappedField field, int fieldIndex, MappedConstantBuffer cBufferMap)
        {
            char?regName = null;

            // Constant buffer fields do not have registers assigned to them.
            if (cBufferMap == null)
            {
                if (field.ResourceBaseType == ShaderResourceBaseType.Sampler)
                {
                    regName = 's';
                }
                else if (field.ResourceBaseType == ShaderResourceBaseType.Texture || field.ResourceBaseType == ShaderResourceBaseType.Buffer)
                {
                    regName = 't';
                }
                else if (field.Type.IsUnorderedAccessType)
                {
                    regName = 'u';
                }
            }

            int fieldTypeSize = field.Info.FieldType.IsValueType ? Marshal.SizeOf(field.Info.FieldType) : 0;

            TranslatePostfixAttributes(sc, field.Attributes, regName, fieldIndex, fieldTypeSize, cBufferMap);
        }
Ejemplo n.º 6
0
        internal override void TranslateFieldPrefix(ShaderTranslationContext sc, VariableDeclaratorSyntax syntax, MappedField field, int fieldIndex, MappedConstantBuffer cBufferMap)
        {
            if (typeof(IShaderResource).IsAssignableFrom(field.Info.FieldType))
            {
                sc.MappedFields.Add(field);
            }
            else
            {
                // HLSL puts all global, non-const static variables into the $Global constant buffer.
                if (cBufferMap == null && field.Info.FieldType.DeclaringType == sc.ShaderType)
                {
                    MappedConstantBuffer cBufferGlobal = null;
                    if (!sc.ConstantBuffers.TryGetValue(GLOBAL_CBUFFER_NAME, out cBufferGlobal))
                    {
                        cBufferGlobal = Pooling.MappedConstBuffers.Get();
                        sc.ConstantBuffers.Add(GLOBAL_CBUFFER_NAME, cBufferGlobal);
                    }

                    cBufferGlobal.AddField(field);
                }

                if (typeof(IMatrix).IsAssignableFrom(field.Info.FieldType))
                {
                    if (field.StructureType == ShaderStructureType.MatrixRowMajor)
                    {
                        sc.Source.Append("row_major ");
                    }
                    if (field.StructureType == ShaderStructureType.MatrixColumnMajor)
                    {
                        sc.Source.Append("column_Major ");
                    }
                }
            }

            foreach (Attribute at in field.Attributes)
            {
                switch (at)
                {
                case InterpolationAttribute attInterpolation:
                    foreach (InterpolationMode m in InterpolationAttribute.ModeValues)
                    {
                        if (m == InterpolationMode.None)
                        {
                            continue;
                        }

                        if ((attInterpolation.Flags & m) == m)
                        {
                            sc.Source.Append($" {m.ToString().ToLower()}");
                        }
                    }
                    break;

                case ComputeGroupSharedAttribute attGroupShared:
                    sc.Source.Append(" groupshared ");
                    break;

                case GloballyCoherentAttribute attGlobCoherent:
                    if (field.ResourceBaseType == ShaderResourceBaseType.RWBuffer || field.ResourceBaseType == ShaderResourceBaseType.RWTexture)
                    {
                        sc.Source.Append(" globallycoherent ");
                    }
                    break;
                }
            }
        }