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

Function assemble_code_for_entry_point

source/effect_codegen_hlsl.cpp:355–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

353 return code;
354 }
355 bool assemble_code_for_entry_point(const std::string &entry_point_name, std::string &code, std::string &, std::string &) const override
356 {
357 const function *const entry_point = find_function(entry_point_name);
358 if (entry_point == nullptr)
359 return false;
360
361 code = finalize_preamble();
362
363 if (_shader_model < 40 && entry_point->type == shader_type::pixel)
364 // Overwrite position semantic in pixel shaders
365 code += "#define POSITION VPOS\n";
366
367 // Add global definitions (struct types, global variables, sampler state declarations, ...)
368 code += _blocks.at(0);
369
370 const auto replace_binding =
371 [](std::string &code, uint32_t binding) {
372 const size_t beg = code.find(": register(") + 12;
373 const size_t end = code.find(')', beg);
374 code.replace(beg, end - beg, std::to_string(binding));
375 };
376
377 // Add referenced texture and sampler definitions
378 for (uint32_t binding = 0; binding < entry_point->referenced_samplers.size(); ++binding)
379 {
380 if (entry_point->referenced_samplers[binding] == 0)
381 continue;
382
383 std::string block_code = _blocks.at(entry_point->referenced_samplers[binding]);
384 replace_binding(block_code, binding);
385 code += block_code;
386 }
387
388 // Add referenced storage definitions
389 for (uint32_t binding = 0; binding < entry_point->referenced_storages.size(); ++binding)
390 {
391 if (entry_point->referenced_storages[binding] == 0)
392 continue;
393
394 std::string block_code = _blocks.at(entry_point->referenced_storages[binding]);
395 replace_binding(block_code, binding);
396 code += block_code;
397 }
398
399 // Add referenced function definitions
400 for (const std::unique_ptr<function> &func : _functions)
401 {
402 if (func->id != entry_point->id &&
403 std::find(entry_point->referenced_functions.begin(), entry_point->referenced_functions.end(), func->id) == entry_point->referenced_functions.end())
404 continue;
405
406 code += _blocks.at(func->id);
407 }
408
409 return true;
410 }
411
412 template <bool is_param = false, bool is_decl = true>

Calls 3

finalize_preambleFunction · 0.85
to_stringFunction · 0.85
atMethod · 0.80

Tested by

no test coverage detected