예제 #1
0
        string GetShaderMemberDeclaration(ShaderTypeMember member, int indent)
        {
            string declaration = GetShaderTypeDeclaration(member.Type, indent, root: false) + " " + member.Name;

            if (member.Type.ElementCount > 0)
            {
                declaration += string.Format("[{0}]", member.Type.ElementCount);
            }
            declaration += ";";
            declaration += $" // Offset {member.Offset} CBSize {member.GetCBVarSize(true)}";
            return(declaration);
        }
예제 #2
0
        internal ShaderTypeMember IsOffsetInType(ShaderTypeMember member, uint parentOffset, uint offsetToFind, out string fullName, out bool isArray)
        {
            uint thisOffset = parentOffset + member.Offset;
            uint thisSize   = member.GetCBVarSize();
            uint paddedSize = ((thisSize + 15) / 16) * 16;
            uint arraySize  = thisSize;

            fullName = null;
            if (member.Type.ElementCount > 1)
            {
                arraySize = (paddedSize * ((uint)member.Type.ElementCount - 1)) + thisSize;
            }
            isArray = false;
            if (offsetToFind < thisOffset || offsetToFind >= (thisOffset + arraySize))
            {
                return(null);
            }
            string arrayIndex = "";

            if (member.Type.VariableClass == ShaderVariableClass.Struct)
            {
                uint offsetInStruct = (offsetToFind - thisOffset) % paddedSize;
                foreach (var child in member.Type.Members)
                {
                    var foundType = IsOffsetInType(child, thisOffset, thisOffset + offsetInStruct, out string childName, out isArray);
                    if (foundType != null)
                    {
                        if (child.Type.ElementCount > 1)
                        {
                            arrayIndex = $"[{(offsetToFind - thisOffset) / thisSize}]";
                        }
                        fullName = $"{member.Name}{arrayIndex}.{childName}";
                        return(foundType);
                    }
                }
            }
            else if ((member.Type.VariableClass == ShaderVariableClass.MatrixRows ||
                      member.Type.VariableClass == ShaderVariableClass.MatrixColumns) ||
                     ((member.Type.VariableClass == ShaderVariableClass.Scalar ||
                       member.Type.VariableClass == ShaderVariableClass.Vector) &&
                      member.Type.ElementCount > 1))
            {
                isArray    = true;
                arrayIndex = $"[{(offsetToFind - thisOffset) / 16}]";
            }
            else if (member.Type.VariableClass == ShaderVariableClass.Vector)
            {
                //Check for vector starting at a non-vec4 offset.
            }
            fullName = $"{member.Name}{arrayIndex}";
            return(member);
        }
예제 #3
0
        void InitMember(ShaderTypeMember member, string registerName, uint bindPoint, uint parentOffset = 0, string prefix = "")
        {
            uint thisOffset   = parentOffset + member.Offset;
            uint thisSize     = member.GetCBVarSize();
            var  elementCount = member.Type.ElementCount == 0 ? 1 : member.Type.ElementCount;

            for (uint i = 0; i < elementCount; i++)
            {
                string arrayIndex = member.Type.ElementCount > 1 ? $"[{i}]" : "";
                if (member.Type.VariableClass == ShaderVariableClass.MatrixColumns)
                {
                    for (int j = 0; j < member.Type.Columns; j++)
                    {
                        var key = $"{registerName}{bindPoint}[{thisOffset / 16 + i * member.Type.Columns + j}]";
                        AddRegister(key, new Register($"{prefix}{member.Name}{arrayIndex}[{j}]"));
                    }
                }
                else if (member.Type.VariableClass == ShaderVariableClass.MatrixRows)
                {
                    for (int j = 0; j < member.Type.Rows; j++)
                    {
                        var key = $"{registerName}{bindPoint}[{thisOffset / 16 + i * member.Type.Rows + j}]";
                        AddRegister(key, new Register($"{prefix}{member.Name}{arrayIndex}[{j}]"));
                    }
                }
                else if (member.Type.VariableClass == ShaderVariableClass.Struct)
                {
                    uint paddedSize   = ((thisSize + 15) / 16) * 16;
                    uint structOffset = thisOffset + paddedSize * i;
                    foreach (var child in member.Type.Members)
                    {
                        InitMember(child, registerName, bindPoint, structOffset, $"{prefix}{member.Name}{arrayIndex}.");
                    }
                }
                else
                {
                    var key = $"{registerName}{bindPoint}[{thisOffset / 16 + i}]";
                    AddRegister(key, new Register($"{prefix}{member.Name}{arrayIndex}"));
                }
            }
        }