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

Function convert_semantic

source/effect_codegen_hlsl.cpp:750–814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

748 }
749
750 std::string convert_semantic(const std::string &semantic, uint32_t max_attributes = 1)
751 {
752 if (_shader_model < 40)
753 {
754 if (semantic == "SV_POSITION")
755 return "POSITION"; // For pixel shaders this has to be "VPOS", so need to redefine that in post
756 if (semantic == "SV_POINTSIZE")
757 return "PSIZE";
758 if (semantic.compare(0, 9, "SV_TARGET") == 0)
759 return "COLOR" + semantic.substr(9);
760 if (semantic == "SV_DEPTH")
761 return "DEPTH";
762 if (semantic == "SV_VERTEXID")
763 return "TEXCOORD0 /* VERTEXID */";
764 if (semantic == "SV_ISFRONTFACE")
765 return "VFACE";
766 if (semantic.compare(0, 3, "SV_") == 0)
767 return semantic; // Unhandled system value semantic
768
769 size_t digit_index = semantic.size() - 1;
770 while (digit_index != 0 && semantic[digit_index] >= '0' && semantic[digit_index] <= '9')
771 digit_index--;
772 digit_index++;
773
774 const std::string semantic_base = semantic.substr(0, digit_index);
775
776 uint32_t semantic_digit = 0;
777 std::from_chars(semantic.c_str() + digit_index, semantic.c_str() + semantic.size(), semantic_digit);
778
779 if (semantic_base == "TEXCOORD")
780 {
781 if (semantic_digit < 15)
782 {
783 assert(_remapped_semantics[semantic_digit].empty() || _remapped_semantics[semantic_digit] == semantic); // Mixing custom semantic names and multiple TEXCOORD indices is not supported
784 _remapped_semantics[semantic_digit] = semantic;
785 }
786 }
787 // Shader model 3 only supports a selected list of semantic names, so need to remap custom ones to that
788 else if (
789 semantic_base != "COLOR" &&
790 semantic_base != "NORMAL" &&
791 semantic_base != "TANGENT" &&
792 semantic_base != "BINORMAL")
793 {
794 // Legal semantic indices are between 0 and 15, but skip first entry in case both custom semantic names and the common TEXCOORD0 exist
795 for (int i = 1; i < 15; ++i)
796 {
797 if (_remapped_semantics[i].empty() || _remapped_semantics[i] == semantic)
798 {
799 for (uint32_t a = 0; a < max_attributes && i + a < 15; ++a)
800 _remapped_semantics[i + a] = semantic_base + std::to_string(semantic_digit + a);
801
802 return "TEXCOORD" + std::to_string(i) + " /* " + semantic + " */";
803 }
804 }
805 }
806 }
807 else

Callers 2

define_structFunction · 0.85
define_functionFunction · 0.85

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected