public static DebugLevel9ShaderChunk Parse(DebugBytecodeReader chunkContentReader, uint chunkSize)
        {
            var  result     = new DebugLevel9ShaderChunk();
            uint chunkSize2 = chunkContentReader.ReadUInt32("chunkSize2");

            result.Version = DebugShaderVersion.ParseAon9(chunkContentReader);
            uint shaderSize                   = chunkContentReader.ReadUInt32("shaderSize");
            var  shaderOffset                 = chunkContentReader.ReadUInt32("shaderOffset");
            var  cbMappingCount               = chunkContentReader.ReadUInt16("cbMappingCount");
            var  cbMappingOffset              = chunkContentReader.ReadUInt16("cbMappingOffset");
            var  loopRegisterMappingCount     = chunkContentReader.ReadUInt16("loopRegisterMappingCount");
            var  loopRegisterMappingOffset    = chunkContentReader.ReadUInt16("loopRegisterMappingOffset");
            var  unk0MappingCount             = chunkContentReader.ReadUInt16("unk0MappingCount");
            var  unk0MappingOffset            = chunkContentReader.ReadUInt16("unk0MappingOffset");
            var  samplerMappingCount          = chunkContentReader.ReadUInt16("samplerMappingCount");
            var  samplerMappingOffset         = chunkContentReader.ReadUInt16("samplerMappingOffset");
            var  runtimeConstantMappingCount  = chunkContentReader.ReadUInt16("runtimeConstantMappingCount");
            var  runtimeConstantMappingOffset = chunkContentReader.ReadUInt16("runtimeConstantMappingOffset");

            if (cbMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset("mappingReader", chunkContentReader, cbMappingOffset);
                for (int i = 0; i < cbMappingCount; i++)
                {
                    result.ConstantBufferMappings.Add(DebugConstantBufferMapping.Parse(mappingReader));
                }
            }
            if (loopRegisterMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset("mappingReader", chunkContentReader, loopRegisterMappingOffset);
                for (int i = 0; i < loopRegisterMappingCount; i++)
                {
                    result.LoopRegisterMappings.Add(DebugLoopRegisterMapping.Parse(mappingReader));
                }
            }
            if (unk0MappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset("mappingReader", chunkContentReader, unk0MappingOffset);
                for (int i = 0; i < unk0MappingCount; i++)
                {
                    result.Unknown0Mappings.Add(DebugUnknown1Mapping.Parse(mappingReader));
                }
            }
            if (samplerMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset("mappingReader", chunkContentReader, samplerMappingOffset);
                for (int i = 0; i < samplerMappingCount; i++)
                {
                    result.SamplerMappings.Add(DebugSamplerMapping.Parse(mappingReader));
                }
                // FXC dissassembly sorts sampler mappings
                result.SamplerMappings = result.SamplerMappings
                                         .OrderBy(s => s.TargetSampler)
                                         .ToList();
            }
            if (runtimeConstantMappingCount > 0)
            {
                var mappingReader = chunkContentReader.CopyAtOffset("mappingReader", chunkContentReader, runtimeConstantMappingOffset);
                for (int i = 0; i < runtimeConstantMappingCount; i++)
                {
                    result.RuntimeConstantMappings.Add(DebugRuntimeConstantMapping.Parse(mappingReader));
                }
            }
            var shaderChunkReader = chunkContentReader.CopyAtOffset("shaderChunkReader", chunkContentReader, (int)shaderOffset);
            var byteCode          = shaderChunkReader.ReadBytes("bytecode", (int)shaderSize);

            return(result);
        }
Beispiel #2
0
        public static DebugRawShaderResourceViewDeclarationToken Parse(DebugBytecodeReader reader, DebugShaderVersion version)
        {
            var token0 = reader.ReadUInt32("token0");

            DebugOpcodeHeader.AddNotes(reader, token0);
            var result = new DebugRawShaderResourceViewDeclarationToken
            {
                Operand = DebugOperand.Parse(reader, token0.DecodeValue <OpcodeType>(0, 10))
            };

            if (version.IsSM51)
            {
                result.SpaceIndex = reader.ReadUInt32("SpaceIndex");
            }
            return(result);
        }
Beispiel #3
0
        internal static DebugEffectNumericVariable Parse(DebugBytecodeReader reader,
                                                         DebugBytecodeReader variableReader, DebugShaderVersion version, bool isShared)
        {
            var result     = new DebugEffectNumericVariable();
            var nameOffset = result.NameOffset = variableReader.ReadUInt32("NameOffset");
            var nameReader = reader.CopyAtOffset("NameReader", variableReader, (int)nameOffset);

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

            result.Type = DebugEffectType.Parse(reader, typeReader, version);
            var semanticOffset = result.SemanticOffset = variableReader.ReadUInt32("SemeanticOffset");

            if (semanticOffset != 0)
            {
                var semanticReader = reader.CopyAtOffset("SemanticReader", variableReader, (int)semanticOffset);
                result.Semantic = semanticReader.ReadString("Semantic");
            }
            else
            {
                result.Semantic = "";
            }
            result.BufferOffset = variableReader.ReadUInt32("BufferOffset");
            var defaultValueOffset = result.DefaultValueOffset = variableReader.ReadUInt32("DefaultValueOffset");

            List <Number> defaultValue = null;
            var           size         = result.Type.PackedSize;

            if (defaultValueOffset != 0)
            {
                defaultValue = new List <Number>();
                var defaultValueReader = reader.CopyAtOffset("DefaultValueReader", variableReader, (int)defaultValueOffset);
                if (size % 4 != 0)
                {
                    throw new ParseException("Can only deal with 4-byte default values at the moment.");
                }
                for (int i = 0; i < size; i += 4)
                {
                    defaultValue.Add(new Number(defaultValueReader.ReadBytes("Number", 4)));
                }
            }
            result.DefaultValue = defaultValue;

            if (!isShared)
            {
                result.ExplicitBindPoint = variableReader.ReadUInt32("ExplicitBindPoint");
                //TODO: Unknown1
                //Debug.Assert(result.Unknown1 == 0, $"EffectBufferVariable.Unknown1 {result.Unknown1}");
            }
            result.AnnotationCount = variableReader.ReadUInt32("AnnotationCount");
            for (int i = 0; i < result.AnnotationCount; i++)
            {
                variableReader.AddIndent($"Annotation {i}");
                result.Annotations.Add(DebugEffectAnnotation.Parse(reader, variableReader, version));
                variableReader.RemoveIndent();
            }
            return(result);
        }
        internal static DebugEffectInterfaceVariable Parse(DebugBytecodeReader reader, DebugBytecodeReader variableReader, DebugShaderVersion version)
        {
            var result     = new DebugEffectInterfaceVariable();
            var nameOffset = result.NameOffset = variableReader.ReadUInt32("NameOffset");
            var nameReader = reader.CopyAtOffset("NameReader", variableReader, (int)nameOffset);

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

            result.Type = DebugEffectType.Parse(reader, typeReader, version);
            //Pointer to InterfaceInitializer
            result.DefaultValueOffset = variableReader.ReadUInt32("DefaultValueOffset");
            var initializerReader  = reader.CopyAtOffset("InitializerReader", variableReader, (int)result.DefaultValueOffset);
            var instanceNameOffset = result.InstanceNameOffset = initializerReader.ReadUInt32("InstanceNameOffset");
            var instanceNameReader = reader.CopyAtOffset("InstanceNameReader", variableReader, (int)instanceNameOffset);

            result.InstanceName    = instanceNameReader.ReadString("InstanceName");
            result.Flags           = variableReader.ReadUInt32("Flags");
            result.AnnotationCount = variableReader.ReadUInt32("AnnotationCount");
            for (int i = 0; i < result.AnnotationCount; i++)
            {
                variableReader.AddIndent($"Annotation {i}");
                result.Annotations.Add(DebugEffectAnnotation.Parse(reader, variableReader, version));
                variableReader.RemoveIndent();
            }

            return(result);
        }
Beispiel #5
0
        public static DebugRawUnorderedAccessViewDeclarationToken Parse(DebugBytecodeReader reader, DebugShaderVersion version)
        {
            var token0 = reader.ReadUInt32("token0");

            DebugOpcodeHeader.AddNotes(reader, token0);
            reader.AddNote("Coherency", token0.DecodeValue <UnorderedAccessViewCoherency>(16, 16));
            reader.AddNote("IsRasterOrderedAccess", token0.DecodeValue <bool>(17, 17));
            reader.AddNote("OpcodeType", token0.DecodeValue <OpcodeType>(0, 10));

            var result = new DebugRawUnorderedAccessViewDeclarationToken
            {
                Coherency             = token0.DecodeValue <UnorderedAccessViewCoherency>(16, 16),
                IsRasterOrderedAccess = token0.DecodeValue <bool>(17, 17),
                Operand = DebugOperand.Parse(reader, token0.DecodeValue <OpcodeType>(0, 10))
            };

            if (version.IsSM51)
            {
                result.SpaceIndex = reader.ReadUInt32("SpaceIndex");
            }
            return(result);
        }
Beispiel #6
0
        public static DebugShaderTypeMember Parse(DebugBytecodeReader reader, DebugBytecodeReader memberReader, DebugShaderVersion target,
                                                  int indent, bool isFirst, uint parentOffset)
        {
            var nameOffset = memberReader.ReadUInt32("nameOffset");
            var nameReader = reader.CopyAtOffset("nameReader", memberReader, (int)nameOffset);
            var name       = nameReader.ReadString("name");

            var memberTypeOffset = memberReader.ReadUInt32("memberTypeOffset");

            var offset = memberReader.ReadUInt32("offset");

            var memberTypeReader = reader.CopyAtOffset("memberTypeReader", memberReader, (int)memberTypeOffset);
            var memberType       = DebugShaderType.Parse(reader, memberTypeReader, target, indent, isFirst, parentOffset + offset);

            return(new DebugShaderTypeMember(parentOffset)
            {
                Name = name,
                Type = memberType,
                Offset = offset
            });
        }
        public static DebugEffectPass Parse(DebugBytecodeReader reader, DebugBytecodeReader passReader, DebugShaderVersion version)
        {
            var result     = new DebugEffectPass();
            var nameOffset = result.NameOffset = passReader.ReadUInt32("NameOffset");
            var nameReader = reader.CopyAtOffset("NameReader", passReader, (int)nameOffset);

            result.Name            = nameReader.ReadString("Name");
            result.ShaderCount     = passReader.ReadUInt32("ShaderCount");
            result.AnnotationCount = passReader.ReadUInt32("AnnotationCount");
            for (int i = 0; i < result.AnnotationCount; i++)
            {
                passReader.AddIndent($"Annotation {i}");
                result.Annotations.Add(DebugEffectAnnotation.Parse(reader, passReader, version));
                passReader.RemoveIndent();
            }
            for (int i = 0; i < result.ShaderCount; i++)
            {
                passReader.AddIndent($"Shader {i}");
                result.Assignments.Add(DebugEffectAssignment.Parse(reader, passReader));
                passReader.RemoveIndent();
            }
            return(result);
        }
Beispiel #8
0
        public static DebugResourceBinding Parse(DebugBytecodeReader reader, DebugBytecodeReader resourceBindingReader, DebugShaderVersion target)
        {
            uint nameOffset = resourceBindingReader.ReadUInt32("nameOffset");
            var  nameReader = reader.CopyAtOffset("nameReader", resourceBindingReader, (int)nameOffset);
            var  result     = new DebugResourceBinding
            {
                Name       = nameReader.ReadString("Name"),
                Type       = (ShaderInputType)resourceBindingReader.ReadUInt32("Type"),
                ReturnType = (ResourceReturnType)resourceBindingReader.ReadUInt32("ReturnType"),
                Dimension  = (ShaderResourceViewDimension)resourceBindingReader.ReadUInt32("Dimension"),
                NumSamples = resourceBindingReader.ReadUInt32("NumSamples"),
                BindPoint  = resourceBindingReader.ReadUInt32("BindPoint"),
                BindCount  = resourceBindingReader.ReadUInt32("BindCount"),
                Flags      = (ShaderInputFlags)resourceBindingReader.ReadUInt32("Flags")
            };

            if (target.MajorVersion == 5 && target.MinorVersion == 1)
            {
                result.SpaceIndex = resourceBindingReader.ReadUInt32("SpaceIndex");
                result.ID         = resourceBindingReader.ReadUInt32("ID");
            }
            else
            {
                result.ID = result.BindPoint;
            }
            return(result);
        }
        internal static DebugShaderVariable Parse(DebugBytecodeReader reader,
                                                  DebugBytecodeReader variableReader, DebugShaderVersion target, bool isFirst)
        {
            uint nameOffset = variableReader.ReadUInt32("nameOffset");
            var  nameReader = reader.CopyAtOffset("nameReader", variableReader, (int)nameOffset);
            var  name       = nameReader.ReadString("name");

            var  startOffset = variableReader.ReadUInt32("startOffset");
            uint size        = variableReader.ReadUInt32("size");
            var  flags       = variableReader.ReadEnum32 <ShaderVariableFlags>("flags");

            var typeOffset = variableReader.ReadUInt32("typeOffset");
            var typeReader = reader.CopyAtOffset("typeReader", variableReader, (int)typeOffset);
            var shaderType = DebugShaderType.Parse(reader, typeReader, target, 2, isFirst, startOffset);

            var           defaultValueOffset = variableReader.ReadUInt32("defaultValueOffset");
            List <Number> defaultValue       = null;

            if (defaultValueOffset != 0)
            {
                defaultValue = new List <Number>();
                var defaultValueReader = reader.CopyAtOffset("defaultValueReader", variableReader, (int)defaultValueOffset);
                if (size % 4 != 0)
                {
                    throw new ParseException("Can only deal with 4-byte default values at the moment.");
                }
                for (int i = 0; i < size; i += 4)
                {
                    defaultValue.Add(new Number(defaultValueReader.ReadBytes($"defaultValue{i}", 4)));
                }
            }


            var result = new DebugShaderVariable
            {
                DefaultValue = defaultValue,
                Member       = new DebugShaderTypeMember(0)
                {
                    Name   = name,
                    Offset = startOffset,
                    Type   = shaderType
                },
                BaseType = name,
                Size     = size,
                Flags    = flags
            };

            if (target.MajorVersion >= 5 || target.ProgramType == ProgramType.LibraryShader)
            {
                result.StartTexture = variableReader.ReadInt32("startTexture");
                result.TextureSize  = variableReader.ReadInt32("textureSize");
                result.StartSampler = variableReader.ReadInt32("startSampler");
                result.SamplerSize  = variableReader.ReadInt32("samplerSize");
            }

            return(result);
        }
Beispiel #10
0
        public static DebugEffectTechnique Parse(DebugBytecodeReader reader,
                                                 DebugBytecodeReader techniqueReader, DebugShaderVersion version)
        {
            var result     = new DebugEffectTechnique(version);
            var nameOffset = result.NameOffset = techniqueReader.ReadUInt32("NameOffset");
            var nameReader = reader.CopyAtOffset("NameReader", techniqueReader, (int)nameOffset);

            result.Name            = nameReader.ReadString("Name");
            result.PassCount       = techniqueReader.ReadUInt32("PassCount");
            result.AnnotationCount = techniqueReader.ReadUInt32("AnnotationCount");

            for (int i = 0; i < result.AnnotationCount; i++)
            {
                techniqueReader.AddIndent("Annotation");
                result.Annotations.Add(DebugEffectAnnotation.Parse(reader, techniqueReader, version));
                techniqueReader.RemoveIndent();
            }
            for (int i = 0; i < result.PassCount; i++)
            {
                techniqueReader.AddIndent($"Pass {i}");
                result.Passes.Add(DebugEffectPass.Parse(reader, techniqueReader, version));
                techniqueReader.RemoveIndent();
            }
            return(result);
        }
Beispiel #11
0
 public DebugEffectTechnique(DebugShaderVersion version)
 {
     Annotations = new List <DebugEffectAnnotation>();
     Passes      = new List <DebugEffectPass>();
     m_Version   = version;
 }