示例#1
0
		public static InterfaceSlot Parse(BytecodeReader reader, BytecodeReader interfaceSlotReader)
		{
			var slotSpan = interfaceSlotReader.ReadUInt32();

			var count = interfaceSlotReader.ReadUInt32();

			var typeIDsOffset = interfaceSlotReader.ReadUInt32();
			var typeIDsReader = reader.CopyAtOffset((int) typeIDsOffset);

			var tableIDsOffset = interfaceSlotReader.ReadUInt32();
			var tableIDsReader = reader.CopyAtOffset((int) tableIDsOffset);

			var result = new InterfaceSlot
			{
				SlotSpan = slotSpan
			};

			for (int i = 0; i < count; i++)
			{
				result.TypeIDs.Add(typeIDsReader.ReadUInt16());
				result.TableIDs.Add(tableIDsReader.ReadUInt32());
			}

			return result;
		}
		public static TempRegisterDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new TempRegisterDeclarationToken
			{
				TempCount = reader.ReadUInt32()
			};
		}
		public static GeometryShaderMaxOutputVertexCountDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new GeometryShaderMaxOutputVertexCountDeclarationToken
			{
				MaxPrimitives = reader.ReadUInt32()
			};
		}
		public static GeometryShaderInstanceCountDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new GeometryShaderInstanceCountDeclarationToken
			{
				InstanceCount = reader.ReadUInt32()
			};
		}
		public static HullShaderForkPhaseInstanceCountDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new HullShaderForkPhaseInstanceCountDeclarationToken
			{
				InstanceCount = reader.ReadUInt32()
			};
		}
		public static FunctionBodyDeclarationToken Parse(BytecodeReader reader)
		{
			uint token0 = reader.ReadUInt32();
			return new FunctionBodyDeclarationToken
			{
				Identifier = reader.ReadUInt32()
			};
		}
		public static StructuredShaderResourceViewDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new StructuredShaderResourceViewDeclarationToken
			{
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)),
				StructByteStride = reader.ReadUInt32()
			};
		}
		public static RawThreadGroupSharedMemoryDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new RawThreadGroupSharedMemoryDeclarationToken
			{
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)),
				ElementCount = reader.ReadUInt32()
			};
		}
		public static StructuredThreadGroupSharedMemoryDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new StructuredThreadGroupSharedMemoryDeclarationToken
			{
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)),
				StructByteStride = reader.ReadUInt32(),
				StructCount = reader.ReadUInt32()
			};
		}
		public static IndexableTempRegisterDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new IndexableTempRegisterDeclarationToken
			{
				RegisterIndex = reader.ReadUInt32(),
				RegisterCount = reader.ReadUInt32(),
				NumComponents = reader.ReadUInt32()
			};
		}
		public static StructuredUnorderedAccessViewDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new StructuredUnorderedAccessViewDeclarationToken
			{
				Coherency = token0.DecodeValue<UnorderedAccessViewCoherency>(16, 16),
				HasOrderPreservingCounter = (token0.DecodeValue(23, 23) == 0),
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10)),
				ByteStride = reader.ReadUInt32()
			};
		}
		public static ThreadGroupDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();

			var result = new ThreadGroupDeclarationToken();
			result.Dimensions[0] = reader.ReadUInt32();
			result.Dimensions[1] = reader.ReadUInt32();
			result.Dimensions[2] = reader.ReadUInt32();

			return result;
		}
		public static IndexingRangeDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			var operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10));
			var registerCount = reader.ReadUInt32();
			return new IndexingRangeDeclarationToken
			{
				Operand = operand,
				RegisterCount = registerCount
			};
		}
		public static FunctionTableDeclarationToken Parse(BytecodeReader reader)
		{
			uint token0 = reader.ReadUInt32();
			var result = new FunctionTableDeclarationToken
			{
				Identifier = reader.ReadUInt32()
			};

			uint tableLength = reader.ReadUInt32();
			for (int i = 0; i < tableLength; i++)
				result.FunctionBodyIndices.Add(reader.ReadUInt32());

			return result;
		}
		public static ImmediateConstantBufferDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			var length = reader.ReadUInt32() - 2;

			var result = new ImmediateConstantBufferDeclarationToken
			{
				DeclarationLength = length,
				Data = new Number[length]
			};

			for (int i = 0; i < length; i++)
				result.Data[i] = Number.Parse(reader);

			return result;
		}
		public static ResourceDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();

			var resourceDimension = token0.DecodeValue<ResourceDimension>(11, 15);

			byte sampleCount;
			switch (resourceDimension)
			{
				case ResourceDimension.Texture2DMultiSampled:
				case ResourceDimension.Texture2DMultiSampledArray:
					sampleCount = token0.DecodeValue<byte>(16, 22);
					break;
				default:
					sampleCount = 0;
					break;
			}

			var operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10));
			var returnType = ResourceReturnTypeToken.Parse(reader);

			return new ResourceDeclarationToken
			{
				ResourceDimension = resourceDimension,
				SampleCount = sampleCount,
				Operand = operand,
				ReturnType = returnType
			};
		}
		public static ShaderProgramChunk Parse(BytecodeReader reader)
		{
			var program = new ShaderProgramChunk
			{
				Version = ShaderVersion.ParseShex(reader),

				// Length Token (LenTok)
				// Always follows VerTok
				// [31:00] Unsigned integer count of number of DWORDs in program code, including version and length tokens.
				// So the minimum value is 0x00000002 (if an empty program is ever valid).
				Length = reader.ReadUInt32()
			};

			while (!reader.EndOfBuffer)
			{
				// Opcode Format (OpcodeToken0)
				//
				// [10:00] D3D10_SB_OPCODE_TYPE
				// if( [10:00] == D3D10_SB_OPCODE_CUSTOMDATA )
				// {
				//    Token starts a custom-data block.  See "Custom-Data Block Format".
				// }
				// else // standard opcode token
				// {
				//    [23:11] Opcode-Specific Controls
				//    [30:24] Instruction length in DWORDs including the opcode token.
				//    [31]    0 normally. 1 if extended operand definition, meaning next DWORD
				//            contains extended opcode token.
				// }
				var opcodeHeaderReader = reader.CopyAtCurrentPosition();
				var opcodeToken0 = opcodeHeaderReader.ReadUInt32();
				var opcodeHeader = new OpcodeHeader
				{
					OpcodeType = opcodeToken0.DecodeValue<OpcodeType>(0, 10),
					Length = opcodeToken0.DecodeValue(24, 30),
					IsExtended = (opcodeToken0.DecodeValue(31, 31) == 1)
				};

				OpcodeToken opcodeToken;
				if (opcodeHeader.OpcodeType == OpcodeType.CustomData)
				{
					opcodeToken = CustomDataToken.Parse(reader, opcodeToken0);
				}
				else if (opcodeHeader.OpcodeType.IsDeclaration())
				{
					opcodeToken = DeclarationToken.Parse(reader, opcodeHeader.OpcodeType);
				}
				else // Not custom data or declaration, so must be instruction.
				{
					opcodeToken = InstructionToken.Parse(reader, opcodeHeader);
				}

				opcodeToken.Header = opcodeHeader;
				program.Tokens.Add(opcodeToken);
			}

			program.LinkControlFlowInstructions();

			return program;
		}
		public static ControlPointCountDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new ControlPointCountDeclarationToken
			{
				ControlPointCount = token0.DecodeValue(11, 16)
			};
		}
		public static GeometryShaderOutputPrimitiveTopologyDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new GeometryShaderOutputPrimitiveTopologyDeclarationToken
			{
				PrimitiveTopology = token0.DecodeValue<PrimitiveTopology>(11, 17)
			};
		}
		public static StreamDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new StreamDeclarationToken
			{
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10))
			};
		}
		public static TessellatorDomainDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new TessellatorDomainDeclarationToken
			{
				Domain = token0.DecodeValue<TessellatorDomain>(11, 12)
			};
		}
		public static GeometryShaderInputPrimitiveDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new GeometryShaderInputPrimitiveDeclarationToken
			{
				Primitive = token0.DecodeValue<Primitive>(11, 16)
			};
		}
		public static TessellatorOutputPrimitiveDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new TessellatorOutputPrimitiveDeclarationToken
			{
				OutputPrimitive = token0.DecodeValue<TessellatorOutputPrimitive>(11, 13)
			};
		}
		public static HullShaderMaxTessFactorDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new HullShaderMaxTessFactorDeclarationToken
			{
				MaxTessFactor = reader.ReadSingle()
			};
		}
		public static TessellatorPartitioningDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new TessellatorPartitioningDeclarationToken
			{
				Partitioning = token0.DecodeValue<TessellatorPartitioning>(11, 13)
			};
		}
		public static GlobalFlagsDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new GlobalFlagsDeclarationToken
			{
				Flags = token0.DecodeValue<GlobalFlags>(11, 18)
			};
		}
		public static ShaderMessageDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			var length = reader.ReadUInt32() - 2;

			var result = new ShaderMessageDeclarationToken
			{
				DeclarationLength = length,
				InfoQueueMessageID = reader.ReadUInt32(),
				MessageFormat = (ShaderMessageFormat) reader.ReadUInt32(),
				NumCharacters = reader.ReadUInt32(),
				NumOperands = reader.ReadUInt32(),
				OperandsLength = reader.ReadUInt32()
			};

			for (int i = 0; i < result.NumOperands; i++)
				result.Operands.Add(Operand.Parse(reader, OpcodeType.CustomData));

			result.Format = reader.ReadString();

			// String is padded to a multiple of DWORDs.
			uint remainingBytes = (4 - ((result.NumCharacters + 1) % 4)) % 4;
			reader.ReadBytes((int) remainingBytes);

			return result;
		}
		public static ConstantBufferDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new ConstantBufferDeclarationToken
			{
				AccessPattern = token0.DecodeValue<ConstantBufferAccessPattern>(11, 11),
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10))
			};
		}
		public static RawUnorderedAccessViewDeclarationToken Parse(BytecodeReader reader)
		{
			var token0 = reader.ReadUInt32();
			return new RawUnorderedAccessViewDeclarationToken
			{
				Coherency = token0.DecodeValue<UnorderedAccessViewCoherency>(16, 16),
				Operand = Operand.Parse(reader, token0.DecodeValue<OpcodeType>(0, 10))
			};
		}
示例#30
0
 public static ShaderVersion ParseShex(BytecodeReader reader)
 {
     uint versionToken = reader.ReadUInt32();
     return new ShaderVersion
     {
         MinorVersion = versionToken.DecodeValue<byte>(0, 3),
         MajorVersion = versionToken.DecodeValue<byte>(4, 7),
         ProgramType = versionToken.DecodeValue<ProgramType>(16, 31)
     };
 }