MCPcopy Create free account
hub / github.com/crosire/reshade / define_entry_point

Function define_entry_point

source/effect_codegen_hlsl.cpp:1190–1340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1188 }
1189
1190 void define_entry_point(function &func) override
1191 {
1192 // Modify entry point name since a new function is created for it below
1193 assert(!func.unique_name.empty() && func.unique_name[0] == 'F');
1194 if (_shader_model < 40 || func.type == shader_type::compute)
1195 func.unique_name[0] = 'E';
1196
1197 if (func.type == shader_type::compute)
1198 func.unique_name +=
1199 '_' + std::to_string(func.num_threads[0]) +
1200 '_' + std::to_string(func.num_threads[1]) +
1201 '_' + std::to_string(func.num_threads[2]);
1202
1203 if (std::find_if(_module.entry_points.begin(), _module.entry_points.end(),
1204 [&func](const std::pair<std::string, shader_type> &entry_point) {
1205 return entry_point.first == func.unique_name;
1206 }) != _module.entry_points.end())
1207 return;
1208
1209 _module.entry_points.emplace_back(func.unique_name, func.type);
1210
1211 // Only have to rewrite the entry point function signature in shader model 3 and for compute (to write "numthreads" attribute)
1212 if (_shader_model >= 40 && func.type != shader_type::compute)
1213 return;
1214
1215 function entry_point = func;
1216 entry_point.referenced_functions.push_back(func.id);
1217
1218 const auto is_color_semantic = [](const std::string &semantic) {
1219 return semantic.compare(0, 9, "SV_TARGET") == 0 || semantic.compare(0, 5, "COLOR") == 0; };
1220 const auto is_position_semantic = [](const std::string &semantic) {
1221 return semantic == "SV_POSITION" || semantic == "POSITION"; };
1222
1223 const id ret = make_id();
1224 define_name<naming::general>(ret, "ret");
1225
1226 std::string position_variable_name;
1227 {
1228 if (func.type == shader_type::vertex && func.return_type.is_struct())
1229 {
1230 // If this function returns a struct which contains a position output, keep track of its member name
1231 for (const member_type &member : get_struct(func.return_type.struct_definition).member_list)
1232 if (is_position_semantic(member.semantic))
1233 position_variable_name = id_to_name(ret) + '.' + member.name;
1234 }
1235
1236 if (is_color_semantic(func.return_semantic))
1237 {
1238 // The COLOR output semantic has to be a four-component vector in shader model 3, so enforce that
1239 entry_point.return_type.rows = 4;
1240 }
1241 if (is_position_semantic(func.return_semantic))
1242 {
1243 if (func.type == shader_type::vertex)
1244 // Keep track of the position output variable
1245 position_variable_name = id_to_name(ret);
1246 }
1247 }

Callers

nothing calls this directly

Calls 12

to_stringFunction · 0.85
id_to_nameFunction · 0.85
define_functionFunction · 0.85
write_typeFunction · 0.85
is_structMethod · 0.80
atMethod · 0.80
is_voidMethod · 0.80
enter_blockFunction · 0.70
create_blockFunction · 0.70
leave_block_and_returnFunction · 0.70
leave_functionFunction · 0.70
eraseMethod · 0.45

Tested by

no test coverage detected