672 {
673 const FunctionDeclaration&
function = c.function();
674 const ExpressionArray& arguments = c.arguments();
675 bool isTextureFunctionWithBias = false;
676 bool nameWritten = false;
677 const char* closingParen = ")";
678 switch (c.function().intrinsicKind()) {
679 case k_abs_IntrinsicKind: {
681 break;
684 break;
685 }
686
687 this->
write(
"_absemulation");
688 nameWritten = true;
692 }
693 break;
694 }
695 case k_atan_IntrinsicKind:
697 arguments.size() == 2 &&
698 arguments[1]->is<PrefixExpression>()) {
699 const PrefixExpression&
p = arguments[1]->as<PrefixExpression>();
700 if (
p.getOperator().kind() == Operator::Kind::MINUS) {
701 this->
write(
"atan(");
703 this->
write(
", -1.0 * ");
706 return;
707 }
708 }
709 break;
710 case k_ldexp_IntrinsicKind:
712 arguments.size() == 2 &&
713 arguments[1]->is<PrefixExpression>()) {
714 const PrefixExpression&
p = arguments[1]->as<PrefixExpression>();
715 if (
p.getOperator().kind() == Operator::Kind::MINUS) {
716 this->
write(
"ldexp(");
720 this->
write(
" * -1)");
721 return;
722 }
723 }
724 break;
725 case k_dFdy_IntrinsicKind:
726
727 closingParen = "))";
731 }
733 nameWritten = true;
734 [[fallthrough]];
735 case k_dFdx_IntrinsicKind:
736 case k_fwidth_IntrinsicKind:
741 }
742 break;
743 case k_determinant_IntrinsicKind:
747 return;
748 }
749 break;
750 case k_fma_IntrinsicKind:
755 this->
write(
") * (");
757 this->
write(
") + (");
760 return;
761 }
762 break;
763 case k_fract_IntrinsicKind:
766 this->
write(
"(0.5 - sign(");
768 this->
write(
") * (0.5 - fract(abs(");
771 return;
772 }
773 break;
774 case k_inverse_IntrinsicKind:
778 return;
779 }
780 break;
781 case k_inversesqrt_IntrinsicKind:
785 return;
786 }
787 break;
788 case k_min_IntrinsicKind:
791 if (
is_abs(*arguments[0])) {
793 return;
794 }
795 if (
is_abs(*arguments[1])) {
796
797
799 return;
800 }
801 }
802 break;
803 case k_pow_IntrinsicKind:
805 break;
806 }
807
808
809
810
811 this->
write(
"exp2(");
813 this->
write(
" * log2(");
816 return;
817 case k_saturate_IntrinsicKind:
819 this->
write(
"clamp(");
821 this->
write(
", 0.0, 1.0)");
822 return;
823 case k_sample_IntrinsicKind: {
824 const char* dim = "";
825 bool proj = false;
826 const Type& arg0Type = arguments[0]->type();
827 const Type& arg1Type = arguments[1]->type();
828 switch (arg0Type.dimensions()) {
830 dim = "1D";
831 isTextureFunctionWithBias = true;
833 proj = false;
834 } else {
836 proj = true;
837 }
838 break;
840 dim = "2D";
842 isTextureFunctionWithBias = true;
843 }
845 proj = false;
846 } else {
848 proj = true;
849 }
850 break;
852 dim = "3D";
853 isTextureFunctionWithBias = true;
855 proj = false;
856 } else {
858 proj = true;
859 }
860 break;
862 dim = "Cube";
863 isTextureFunctionWithBias = true;
864 proj = false;
865 break;
867 dim = "2DRect";
868 proj = false;
869 break;
872 dim = "Buffer";
873 proj = false;
874 break;
877 dim = "SubpassData";
878 proj = false;
879 break;
880 }
881 this->
write(
"texture");
884 }
885 if (proj) {
887 }
888 nameWritten = true;
889 break;
890 }
891 case k_sampleGrad_IntrinsicKind: {
893 this->
write(
"textureGrad");
894 nameWritten = true;
895 break;
896 }
897 case k_sampleLod_IntrinsicKind: {
899 this->
write(
"textureLod");
900 nameWritten = true;
901 break;
902 }
903 case k_transpose_IntrinsicKind:
907 return;
908 }
909 break;
910 case k_loadFloatBuffer_IntrinsicKind: {
914 c.position(),
915 c.arguments()[0]->clone());
916
918 return;
919 }
920 default:
921 break;
922 }
923
924 if (!nameWritten) {
926 }
929 for (const auto& arg : arguments) {
930 this->
write(separator());
932 }
933 if (
fProgram.
fConfig->fSettings.fSharpenTextures && isTextureFunctionWithBias) {
935 }
936 this->
write(closingParen);
937}
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)
static std::unique_ptr< Expression > LoadFloatBuffer(const Context &context, const SkSL::ShaderCaps &shaderCaps, Position position, std::unique_ptr< Expression > idx)
const char * shaderDerivativeExtensionString() const
bool fMustForceNegatedAtanParamToFloat
bool fEmulateAbsIntFunction
bool fRemovePowWithConstantExponent
bool fBuiltinDeterminantSupport
bool fMustForceNegatedLdexpParamToMultiply
bool fCanUseFractForNegativeValues
bool fCanUseMinAndAbsTogether
SkSL::GLSLGeneration fGLSLGeneration