671 {
672 const FunctionDeclaration&
function = c.function();
673 const ExpressionArray& arguments = c.arguments();
674 bool isTextureFunctionWithBias = false;
675 bool nameWritten = false;
676 const char* closingParen = ")";
677 switch (c.function().intrinsicKind()) {
678 case k_abs_IntrinsicKind: {
680 break;
683 break;
684 }
685
686 this->
write(
"_absemulation");
687 nameWritten = true;
691 }
692 break;
693 }
694 case k_atan_IntrinsicKind:
696 arguments.size() == 2 &&
697 arguments[1]->is<PrefixExpression>()) {
698 const PrefixExpression&
p = arguments[1]->as<PrefixExpression>();
699 if (
p.getOperator().kind() == Operator::Kind::MINUS) {
700 this->
write(
"atan(");
702 this->
write(
", -1.0 * ");
705 return;
706 }
707 }
708 break;
709 case k_ldexp_IntrinsicKind:
711 arguments.size() == 2 &&
712 arguments[1]->is<PrefixExpression>()) {
713 const PrefixExpression&
p = arguments[1]->as<PrefixExpression>();
714 if (
p.getOperator().kind() == Operator::Kind::MINUS) {
715 this->
write(
"ldexp(");
719 this->
write(
" * -1)");
720 return;
721 }
722 }
723 break;
724 case k_dFdy_IntrinsicKind:
725
726 closingParen = "))";
730 }
732 nameWritten = true;
733 [[fallthrough]];
734 case k_dFdx_IntrinsicKind:
735 case k_fwidth_IntrinsicKind:
740 }
741 break;
742 case k_determinant_IntrinsicKind:
746 return;
747 }
748 break;
749 case k_fma_IntrinsicKind:
754 this->
write(
") * (");
756 this->
write(
") + (");
759 return;
760 }
761 break;
762 case k_fract_IntrinsicKind:
765 this->
write(
"(0.5 - sign(");
767 this->
write(
") * (0.5 - fract(abs(");
770 return;
771 }
772 break;
773 case k_inverse_IntrinsicKind:
777 return;
778 }
779 break;
780 case k_inversesqrt_IntrinsicKind:
784 return;
785 }
786 break;
787 case k_min_IntrinsicKind:
790 if (
is_abs(*arguments[0])) {
792 return;
793 }
794 if (
is_abs(*arguments[1])) {
795
796
798 return;
799 }
800 }
801 break;
802 case k_pow_IntrinsicKind:
804 break;
805 }
806
807
808
809
810 this->
write(
"exp2(");
812 this->
write(
" * log2(");
815 return;
816 case k_saturate_IntrinsicKind:
818 this->
write(
"clamp(");
820 this->
write(
", 0.0, 1.0)");
821 return;
822 case k_sample_IntrinsicKind: {
823 const char* dim = "";
824 bool proj = false;
825 const Type& arg0Type = arguments[0]->type();
826 const Type& arg1Type = arguments[1]->type();
827 switch (arg0Type.dimensions()) {
829 dim = "1D";
830 isTextureFunctionWithBias = true;
832 proj = false;
833 } else {
835 proj = true;
836 }
837 break;
839 dim = "2D";
841 isTextureFunctionWithBias = true;
842 }
844 proj = false;
845 } else {
847 proj = true;
848 }
849 break;
851 dim = "3D";
852 isTextureFunctionWithBias = true;
854 proj = false;
855 } else {
857 proj = true;
858 }
859 break;
861 dim = "Cube";
862 isTextureFunctionWithBias = true;
863 proj = false;
864 break;
866 dim = "2DRect";
867 proj = false;
868 break;
871 dim = "Buffer";
872 proj = false;
873 break;
876 dim = "SubpassData";
877 proj = false;
878 break;
879 }
880 this->
write(
"texture");
883 }
884 if (proj) {
886 }
887 nameWritten = true;
888 break;
889 }
890 case k_sampleGrad_IntrinsicKind: {
892 this->
write(
"textureGrad");
893 nameWritten = true;
894 break;
895 }
896 case k_sampleLod_IntrinsicKind: {
898 this->
write(
"textureLod");
899 nameWritten = true;
900 break;
901 }
902 case k_transpose_IntrinsicKind:
906 return;
907 }
908 break;
909 default:
910 break;
911 }
912
913 if (!nameWritten) {
915 }
918 for (const auto& arg : arguments) {
919 this->
write(separator());
921 }
922 if (
fProgram.
fConfig->fSettings.fSharpenTextures && isTextureFunctionWithBias) {
924 }
925 this->
write(closingParen);
926}
const std::unique_ptr< Type > fFloat2
const std::unique_ptr< Type > fFloat4
const std::unique_ptr< Type > fSamplerExternalOES
const std::unique_ptr< Type > fFloat3
static constexpr float kSharpenTexturesBias
void writeInverseSqrtHack(const Expression &x)
bool fWrittenAbsEmulation
void writeInverseHack(const Expression &mat)
void writeTransposeHack(const Expression &mat)
void writeMinAbsHack(Expression &absExpr, Expression &otherExpr)
void writeDeterminantHack(const Expression &mat)
void writeExtension(std::string_view name, bool require=true)
Dart_NativeFunction function
static bool is_abs(Expression &expr)
const char * shaderDerivativeExtensionString() const
bool fMustForceNegatedAtanParamToFloat
bool fEmulateAbsIntFunction
bool fRemovePowWithConstantExponent
bool fBuiltinDeterminantSupport
bool fMustForceNegatedLdexpParamToMultiply
bool fCanUseFractForNegativeValues
bool fCanUseMinAndAbsTogether
SkSL::GLSLGeneration fGLSLGeneration