Beispiel #1
0
        public static EffectShaderData5 Parse(BytecodeReader reader, BytecodeReader variableReader)
        {
            var result       = new EffectShaderData5();
            var shaderOffset = variableReader.ReadUInt32();

            result.SODeclsOffset[0] = variableReader.ReadUInt32();
            result.SODeclsOffset[1] = variableReader.ReadUInt32();
            result.SODeclsOffset[2] = variableReader.ReadUInt32();
            result.SODeclsOffset[3] = variableReader.ReadUInt32();
            result.SODeclsCount     = variableReader.ReadUInt32();
            result.RasterizedStream = variableReader.ReadUInt32();
            var interfaceBindingCount  = variableReader.ReadUInt32();
            var interfaceBindingOffset = variableReader.ReadUInt32();
            var shaderReader           = reader.CopyAtOffset((int)shaderOffset);
            var shaderSize             = shaderReader.ReadUInt32();

            if (shaderSize != 0)
            {
                result.Shader = BytecodeContainer.Parse(shaderReader.ReadBytes((int)shaderSize));
            }
            for (int i = 0; i < 4; i++)
            {
                var offset = result.SODeclsOffset[i];
                if (offset != 0)
                {
                    var soDeclReader = reader.CopyAtOffset((int)offset);
                    result.SODecls.Add(soDeclReader.ReadString());
                }
            }
            var interfaceReader = reader.CopyAtOffset((int)interfaceBindingOffset);

            for (int i = 0; i < interfaceBindingCount; i++)
            {
                result.InterfaceBindings.Add(EffectInterfaceInitializer.Parse(reader, interfaceReader));
            }
            return(result);
        }
Beispiel #2
0
        public static EffectObjectVariable Parse(BytecodeReader reader, BytecodeReader variableReader, ShaderVersion version, bool isShared = false)
        {
            var result     = new EffectObjectVariable();
            var nameOffset = variableReader.ReadUInt32();
            var nameReader = reader.CopyAtOffset((int)nameOffset);

            result.Name = nameReader.ReadString();
            var typeOffset = variableReader.ReadUInt32();
            var typeReader = reader.CopyAtOffset((int)typeOffset);

            result.Type = EffectType.Parse(reader, typeReader, version);
            var semanticOffset = variableReader.ReadUInt32();

            if (semanticOffset != 0)
            {
                var semanticReader = reader.CopyAtOffset((int)semanticOffset);
                result.Semantic = semanticReader.ReadString();
            }
            else
            {
                result.Semantic = "";
            }
            result.BufferOffset = variableReader.ReadUInt32();
            if (isShared)
            {
                return(result);
            }
            // Initializer data
            if (result.Type.ObjectType == EffectObjectType.String)
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    var stringValueOffset = variableReader.ReadUInt32();
                    var stringValueReader = reader.CopyAtOffset((int)stringValueOffset);
                    result.Strings.Add(stringValueReader.ReadString());
                }
            }
            if (IfHasAssignments(result.Type))
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    var assignmentCount = variableReader.ReadUInt32();
                    var assignments     = new List <EffectAssignment>();
                    result.Assignments.Add(assignments);
                    for (int j = 0; j < assignmentCount; j++)
                    {
                        assignments.Add(EffectAssignment.Parse(reader, variableReader));
                    }
                }
            }
            if (result.Type.ObjectType == EffectObjectType.GeometryShaderWithStream)
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.GSSOInitializers.Add(EffectGSSOInitializer.Parse(reader, variableReader));
                }
            }
            else if (IsShader5(result.Type))
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.ShaderData5.Add(EffectShaderData5.Parse(reader, variableReader));
                }
            }
            else if (IsShader(result.Type))
            {
                for (int i = 0; i < result.ElementCount; i++)
                {
                    result.ShaderData.Add(EffectShaderData.Parse(reader, variableReader));
                }
            }
            var annotationCount = variableReader.ReadUInt32();

            for (int i = 0; i < annotationCount; i++)
            {
                result.Annotations.Add(EffectAnnotation.Parse(reader, variableReader, version));
            }
            return(result);
        }