Beispiel #1
0
        private void WriteVariableHeader(EndianWriter writer, VariableHeader header)
        {
            //name offset
            writer.Write(header.nameOffset);
            //startOffset
            writer.Write(header.startOffset);
            //Size
            writer.Write(header.variable.Length);
            //flags
            writer.Write((uint)ShaderVariableFlags.Used);             //Unity only packs used variables as far as I can tell

            var typeOffset = typeLookup[header.variable.ShaderType];

            //type offset
            writer.Write(typeOffset);
            //default value offset
            writer.Write((uint)0);             //Not used
            if (majorVersion >= 5)
            {
                //StartTexture
                writer.Write((uint)0);
                //TextureSize
                writer.Write((uint)0);
                //StartSampler
                writer.Write((uint)0);
                //SamplerSize
                writer.Write((uint)0);
            }
        }
Beispiel #2
0
        public VariableChunk(ConstantBuffer constantBuffer, int constantBufferIndex, uint variableOffset, ShaderGpuProgramType programType)
        {
            const int memberSize = 12;

            this.constantBuffer      = constantBuffer;
            this.constantBufferIndex = constantBufferIndex;
            this.programType         = programType;
            this.variables           = BuildVariables(constantBuffer);

            majorVersion = DXShaderObjectExporter.GetMajorVersion(programType);
            uint variableSize  = majorVersion >= 5 ? (uint)40 : (uint)24;
            uint variableCount = (uint)variables.Count;
            uint dataOffset    = variableOffset + variableCount * variableSize;

            foreach (var variable in variables)
            {
                variableNameLookup[variable.Name] = dataOffset;
                var header = new VariableHeader();
                header.nameOffset  = dataOffset;
                dataOffset        += (uint)variable.Name.Length + 1;
                header.startOffset = (uint)variable.Index;
                header.variable    = variable;

                typeLookup[variable.ShaderType] = dataOffset;
                dataOffset += variable.ShaderType.Size();

                variable.ShaderType.MemberOffset = variable.ShaderType.members.Count > 0 ? dataOffset : 0;
                dataOffset += (uint)variable.ShaderType.members.Count * memberSize;

                foreach (var member in variable.ShaderType.members)
                {
                    variableNameLookup[member.Name] = dataOffset;
                    dataOffset += (uint)member.Name.Length + 1;

                    typeLookup[member.ShaderType] = dataOffset;
                    dataOffset += member.ShaderType.Size();
                }

                variableHeaders.Add(header);
            }
            size = dataOffset - variableOffset;
        }