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

Function write_constant

source/effect_codegen_hlsl.cpp:563–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561 s += 'x', s += to_digit(type.cols);
562 }
563 void write_constant(std::string &s, const type &data_type, const constant &data) const
564 {
565 if (data_type.is_array())
566 {
567 assert(data_type.is_bounded_array());
568
569 type elem_type = data_type;
570 elem_type.array_length = 0;
571
572 s += "{ ";
573
574 for (unsigned int a = 0; a < data_type.array_length; ++a)
575 {
576 write_constant(s, elem_type, a < static_cast<unsigned int>(data.array_data.size()) ? data.array_data[a] : constant {});
577 s += ", ";
578 }
579
580 // Remove trailing ", "
581 s.erase(s.size() - 2);
582
583 s += " }";
584 return;
585 }
586
587 if (data_type.is_struct())
588 {
589 // The can only be zero initializer struct constants
590 assert(data.as_uint[0] == 0);
591
592 s += '(' + id_to_name(data_type.struct_definition) + ")0";
593 return;
594 }
595
596 // There can only be numeric constants
597 assert(data_type.is_numeric());
598
599 if (!data_type.is_scalar())
600 write_type<false, false>(s, data_type), s += '(';
601
602 for (unsigned int i = 0; i < data_type.components(); ++i)
603 {
604 switch (data_type.base)
605 {
606 case type::t_bool:
607 s += data.as_uint[i] ? "true" : "false";
608 break;
609 case type::t_min16int:
610 case type::t_int:
611 s += std::to_string(data.as_int[i]);
612 break;
613 case type::t_min16uint:
614 case type::t_uint:
615 s += std::to_string(data.as_uint[i]);
616 if (_shader_model >= 40)
617 s += 'u';
618 break;
619 case type::t_min16float:
620 case type::t_float:

Callers 5

write_constantMethod · 0.85
emit_constantMethod · 0.85
leave_block_and_killFunction · 0.85
emit_constantFunction · 0.85
leave_block_and_killFunction · 0.85

Calls 10

id_to_nameFunction · 0.85
to_stringFunction · 0.85
is_arrayMethod · 0.80
is_bounded_arrayMethod · 0.80
is_structMethod · 0.80
is_numericMethod · 0.80
is_scalarMethod · 0.80
componentsMethod · 0.80
eraseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected