| 106 | } |
| 107 | |
| 108 | void MSLGenerator::Prepass(HLSLTree* tree, HLSLTarget target, HLSLFunction* entryFunction) |
| 109 | { |
| 110 | // Hide unused arguments. @@ It would be good to do this in the other generators too. |
| 111 | |
| 112 | // PruneTree resets hidden flags to true, then marks visible elements |
| 113 | // based on whether entry point visits them. |
| 114 | PruneTree(tree, entryFunction->name); // Note: takes second entry |
| 115 | |
| 116 | // This sorts tree by type, but keeps ordering |
| 117 | SortTree(tree); |
| 118 | |
| 119 | // This strips any unused inputs to the entry point function |
| 120 | HideUnusedArguments(entryFunction); |
| 121 | |
| 122 | // Note sure if/where to add these calls. Just wanted to point |
| 123 | // out that nothing is calling them, but could be useful. |
| 124 | FlattenExpressions(tree); |
| 125 | |
| 126 | HLSLRoot* root = tree->GetRoot(); |
| 127 | HLSLStatement* statement = root->statement; |
| 128 | ASSERT(m_firstClassArgument == NULL); |
| 129 | |
| 130 | //HLSLType samplerType(HLSLBaseType_Sampler); |
| 131 | |
| 132 | int nextTextureRegister = 0; |
| 133 | int nextSamplerRegister = 0; |
| 134 | int nextBufferRegister = 0; |
| 135 | |
| 136 | while (statement != NULL) { |
| 137 | if (statement->hidden) { |
| 138 | statement = statement->nextStatement; |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | if (statement->nodeType == HLSLNodeType_Declaration) { |
| 143 | HLSLDeclaration* declaration = (HLSLDeclaration*)statement; |
| 144 | |
| 145 | if (IsTextureType(declaration->type)) { |
| 146 | const char* textureName = declaration->name; |
| 147 | |
| 148 | int textureRegister = ParseRegister(declaration->registerName, nextTextureRegister); |
| 149 | const char* textureRegisterName = m_tree->AddStringFormat("texture(%d)", textureRegister); |
| 150 | |
| 151 | if (declaration->type.addressSpace == HLSLAddressSpace_Undefined) |
| 152 | declaration->type.addressSpace = HLSLAddressSpace_Device; |
| 153 | |
| 154 | AddClassArgument(new ClassArgument(textureName, declaration->type, textureRegisterName, true)); |
| 155 | } |
| 156 | else if (IsSamplerType(declaration->type)) { |
| 157 | const char* samplerName = declaration->name; |
| 158 | |
| 159 | int samplerRegister = ParseRegister(declaration->registerName, nextSamplerRegister); |
| 160 | const char* samplerRegisterName = m_tree->AddStringFormat("sampler(%d)", samplerRegister); |
| 161 | |
| 162 | if (declaration->type.addressSpace == HLSLAddressSpace_Undefined) |
| 163 | declaration->type.addressSpace = HLSLAddressSpace_Device; |
| 164 | |
| 165 | AddClassArgument(new ClassArgument(samplerName, declaration->type, samplerRegisterName, true)); |
nothing calls this directly
no test coverage detected