private TextureLoadOutputNode CreateTextureLoadOutputNode(InstructionToken instruction, int outputComponent) { const int TextureCoordsIndex = 1; const int SamplerIndex = 2; RegisterKey samplerRegister = instruction.GetParamRegisterKey(SamplerIndex); if (!_samplers.TryGetValue(samplerRegister, out HlslTreeNode samplerInput)) { throw new InvalidOperationException(); } var samplerRegisterInput = (RegisterInputNode)samplerInput; int numSamplerOutputComponents = samplerRegisterInput.SamplerTextureDimension; IList <HlslTreeNode> texCoords = new List <HlslTreeNode>(); for (int component = 0; component < numSamplerOutputComponents; component++) { RegisterComponentKey textureCoordsKey = GetParamRegisterComponentKey(instruction, TextureCoordsIndex, component); HlslTreeNode textureCoord = _activeOutputs[textureCoordsKey]; texCoords.Add(textureCoord); } return(new TextureLoadOutputNode(samplerRegisterInput, texCoords, outputComponent)); }
private static RegisterComponentKey GetParamRegisterComponentKey(InstructionToken instruction, int paramIndex, int component) { RegisterKey registerKey = instruction.GetParamRegisterKey(paramIndex); byte[] swizzle = instruction.GetSourceSwizzleComponents(paramIndex); int componentIndex = swizzle[component]; return(new RegisterComponentKey(registerKey, componentIndex)); }
public string GetDestinationName(InstructionToken instruction) { int destIndex = instruction.GetDestinationParamIndex(); RegisterKey registerKey = instruction.GetParamRegisterKey(destIndex); string registerName = GetRegisterName(registerKey); registerName = registerName ?? instruction.GetParamRegisterName(destIndex); var registerLength = GetRegisterFullLength(registerKey); string writeMaskName = instruction.GetDestinationWriteMaskName(registerLength, true); return(string.Format("{0}{1}", registerName, writeMaskName)); }
private static IEnumerable <RegisterComponentKey> GetDestinationKeys(InstructionToken instruction) { int index = instruction.GetDestinationParamIndex(); RegisterKey registerKey = instruction.GetParamRegisterKey(index); if (registerKey.Type == RegisterType.Sampler) { yield break; } ComponentFlags mask = instruction.GetDestinationWriteMask(); for (int component = 0; component < 4; component++) { if ((mask & (ComponentFlags)(1 << component)) == 0) { continue; } yield return(new RegisterComponentKey(registerKey, component)); } }
public RegisterDeclaration(InstructionToken declInstruction) { RegisterKey = declInstruction.GetParamRegisterKey(1); _semantic = declInstruction.GetDeclSemantic(); _maskedLength = declInstruction.GetDestinationMaskedLength(); }
public string GetSourceName(InstructionToken instruction, int srcIndex) { string sourceRegisterName; RegisterKey registerKey = instruction.GetParamRegisterKey(srcIndex); var registerType = instruction.GetParamRegisterType(srcIndex); switch (registerType) { case RegisterType.Const: case RegisterType.Const2: case RegisterType.Const3: case RegisterType.Const4: case RegisterType.ConstBool: case RegisterType.ConstInt: sourceRegisterName = GetSourceConstantName(instruction, srcIndex); if (sourceRegisterName != null) { return(sourceRegisterName); } ParameterType parameterType; switch (registerType) { case RegisterType.Const: case RegisterType.Const2: case RegisterType.Const3: case RegisterType.Const4: parameterType = ParameterType.Float; break; case RegisterType.ConstBool: parameterType = ParameterType.Bool; break; case RegisterType.ConstInt: parameterType = ParameterType.Int; break; default: throw new NotImplementedException(); } var registerNumber = instruction.GetParamRegisterNumber(srcIndex); ConstantDeclaration decl = FindConstant(registerNumber); if (decl == null) { // Constant register not found in def statements nor the constant table //TODO: return($"Error {registerType}{registerNumber}"); //throw new NotImplementedException(); } var totalOffset = registerNumber - decl.RegisterIndex; var data = decl.GetRegisterTypeByOffset(totalOffset); var offsetFromMember = registerNumber - data.RegisterIndex; sourceRegisterName = decl.GetMemberNameByOffset(totalOffset); if (data.Type.ParameterClass == ParameterClass.MatrixRows) { sourceRegisterName = string.Format("{0}[{1}]", decl.Name, offsetFromMember); } else if (data.Type.ParameterClass == ParameterClass.MatrixColumns) { sourceRegisterName = string.Format("transpose({0})[{1}]", decl.Name, offsetFromMember); } break; default: sourceRegisterName = GetRegisterName(registerKey); break; } sourceRegisterName = sourceRegisterName ?? instruction.GetParamRegisterName(srcIndex); sourceRegisterName += instruction.GetSourceSwizzleName(srcIndex, true); return(ApplyModifier(instruction.GetSourceModifier(srcIndex), sourceRegisterName)); }