0001-FELightningNEON.cpp-fails-to-build-NEON-fast-path-se.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. From 5ba2d275457c4fdf1efdcca8351792400bda5679 Mon Sep 17 00:00:00 2001
  2. From: Adrian Perez de Castro <aperez@igalia.com>
  3. Date: Thu, 2 Jun 2022 11:19:06 +0300
  4. Subject: [PATCH] FELightningNEON.cpp fails to build, NEON fast path seems
  5. unused https://bugs.webkit.org/show_bug.cgi?id=241182
  6. Reviewed by NOBODY (OOPS!).
  7. Move the NEON fast path for the SVG lighting filter effects into
  8. FELightingSoftwareApplier, and arrange to actually use them by
  9. forwarding calls to applyPlatformGeneric() into applyPlatformNeon().
  10. Some changes were needed to adapt platformApplyNeon() to the current
  11. state of filters after r286140. This was not detected because the code
  12. bitrotted due to it being guarded with CPU(ARM_TRADITIONAL), which does
  13. not get used much these days: CPU(ARM_THUMB2) is more common. It should
  14. be possible to use the NEON fast paths also in Thumb mode, but that is
  15. left for a follow-up fix.
  16. * Source/WebCore/Sources.txt:
  17. * Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.cpp:
  18. (WebCore::FELightingSoftwareApplier::platformApplyNeonWorker):
  19. (WebCore::FELightingSoftwareApplier::getPowerCoefficients):
  20. (WebCore::FELighting::platformApplyNeonWorker): Deleted.
  21. (WebCore::FELighting::getPowerCoefficients): Deleted.
  22. * Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h:
  23. (WebCore::FELightingSoftwareApplier::applyPlatformNeon):
  24. (WebCore::FELighting::platformApplyNeon): Deleted.
  25. * Source/WebCore/platform/graphics/filters/DistantLightSource.h:
  26. * Source/WebCore/platform/graphics/filters/FELighting.h:
  27. * Source/WebCore/platform/graphics/filters/PointLightSource.h:
  28. * Source/WebCore/platform/graphics/filters/SpotLightSource.h:
  29. * Source/WebCore/platform/graphics/filters/software/FELightingSoftwareApplier.h:
  30. Signed-off-by: Adrian Perez de Castro <aperez@igalia.com>
  31. Upstream: https://bugs.webkit.org/show_bug.cgi?id=241182
  32. ---
  33. Source/WebCore/Sources.txt | 1 +
  34. .../cpu/arm/filters/FELightingNEON.cpp | 6 +--
  35. .../graphics/cpu/arm/filters/FELightingNEON.h | 54 +++++++++----------
  36. .../graphics/filters/DistantLightSource.h | 4 ++
  37. .../platform/graphics/filters/FELighting.h | 7 ---
  38. .../graphics/filters/PointLightSource.h | 4 ++
  39. .../graphics/filters/SpotLightSource.h | 4 ++
  40. .../software/FELightingSoftwareApplier.h | 16 ++++++
  41. 8 files changed, 59 insertions(+), 37 deletions(-)
  42. diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt
  43. index 9ca28a7b2bc0..ed2c7f9f41ee 100644
  44. --- a/Source/WebCore/Sources.txt
  45. +++ b/Source/WebCore/Sources.txt
  46. @@ -2303,6 +2303,7 @@ platform/graphics/controls/MeterPart.cpp
  47. platform/graphics/controls/ProgressBarPart.cpp
  48. platform/graphics/controls/SliderTrackPart.cpp
  49. platform/graphics/cpu/arm/filters/FEBlendNeonApplier.cpp
  50. +platform/graphics/cpu/arm/filters/FELightingNEON.cpp
  51. platform/graphics/displaylists/DisplayList.cpp
  52. platform/graphics/displaylists/DisplayListDrawingContext.cpp
  53. platform/graphics/displaylists/DisplayListItems.cpp
  54. diff --git a/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.cpp b/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.cpp
  55. index f6ff8c20a5a8..dced3d55eb4e 100644
  56. --- a/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.cpp
  57. +++ b/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.cpp
  58. @@ -35,7 +35,7 @@ namespace WebCore {
  59. // ALPHAX_Q ALPHAY_Q REMAPX_D REMAPY_D
  60. -static alignas(16) short s_FELightingConstantsForNeon[] = {
  61. +alignas(16) static short s_FELightingConstantsForNeon[] = {
  62. // Alpha coefficients.
  63. -2, 1, 0, -1, 2, 1, 0, -1,
  64. 0, -1, -2, -1, 0, 1, 2, 1,
  65. @@ -49,7 +49,7 @@ short* feLightingConstantsForNeon()
  66. return s_FELightingConstantsForNeon;
  67. }
  68. -void FELighting::platformApplyNeonWorker(FELightingPaintingDataForNeon* parameters)
  69. +void FELightingSoftwareApplier::platformApplyNeonWorker(FELightingPaintingDataForNeon* parameters)
  70. {
  71. neonDrawLighting(parameters);
  72. }
  73. @@ -464,7 +464,7 @@ TOSTRING(neonDrawLighting) ":" NL
  74. "b .lightStrengthCalculated" NL
  75. ); // NOLINT
  76. -int FELighting::getPowerCoefficients(float exponent)
  77. +int FELightingSoftwareApplier::getPowerCoefficients(float exponent)
  78. {
  79. // Calling a powf function from the assembly code would require to save
  80. // and reload a lot of NEON registers. Since the base is in range [0..1]
  81. diff --git a/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h b/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h
  82. index b17c603d40d3..fd23e31cce29 100644
  83. --- a/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h
  84. +++ b/Source/WebCore/platform/graphics/cpu/arm/filters/FELightingNEON.h
  85. @@ -24,14 +24,15 @@
  86. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  87. */
  88. -#ifndef FELightingNEON_h
  89. -#define FELightingNEON_h
  90. +#pragma once
  91. #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC_COMPATIBLE)
  92. -#include "FELighting.h"
  93. +#include "FELightingSoftwareApplier.h"
  94. +#include "ImageBuffer.h"
  95. #include "PointLightSource.h"
  96. #include "SpotLightSource.h"
  97. +#include <wtf/ObjectIdentifier.h>
  98. #include <wtf/ParallelJobs.h>
  99. namespace WebCore {
  100. @@ -93,14 +94,14 @@ extern "C" {
  101. void neonDrawLighting(FELightingPaintingDataForNeon*);
  102. }
  103. -inline void FELighting::platformApplyNeon(const LightingData& data, const LightSource::PaintingData& paintingData)
  104. +inline void FELightingSoftwareApplier::applyPlatformNeon(const FELightingSoftwareApplier::LightingData& data, const LightSource::PaintingData& paintingData)
  105. {
  106. - alignas(16) FELightingFloatArgumentsForNeon floatArguments;
  107. - FELightingPaintingDataForNeon neonData = {
  108. - data.pixels->data(),
  109. + alignas(16) WebCore::FELightingFloatArgumentsForNeon floatArguments;
  110. + WebCore::FELightingPaintingDataForNeon neonData = {
  111. + data.pixels->bytes(),
  112. 1,
  113. - data.widthDecreasedByOne - 1,
  114. - data.heightDecreasedByOne - 1,
  115. + data.width - 2,
  116. + data.height - 2,
  117. 0,
  118. 0,
  119. 0,
  120. @@ -111,23 +112,23 @@ inline void FELighting::platformApplyNeon(const LightingData& data, const LightS
  121. // Set light source arguments.
  122. floatArguments.constOne = 1;
  123. - auto color = m_lightingColor.toColorTypeLossy<SRGBA<uint8_t>>().resolved();
  124. + auto color = data.lightingColor.toColorTypeLossy<SRGBA<uint8_t>>().resolved();
  125. floatArguments.colorRed = color.red;
  126. floatArguments.colorGreen = color.green;
  127. floatArguments.colorBlue = color.blue;
  128. floatArguments.padding4 = 0;
  129. - if (m_lightSource->type() == LS_POINT) {
  130. + if (data.lightSource->type() == LS_POINT) {
  131. neonData.flags |= FLAG_POINT_LIGHT;
  132. - PointLightSource& pointLightSource = static_cast<PointLightSource&>(m_lightSource.get());
  133. + const auto& pointLightSource = *static_cast<const PointLightSource*>(data.lightSource);
  134. floatArguments.lightX = pointLightSource.position().x();
  135. floatArguments.lightY = pointLightSource.position().y();
  136. floatArguments.lightZ = pointLightSource.position().z();
  137. floatArguments.padding2 = 0;
  138. - } else if (m_lightSource->type() == LS_SPOT) {
  139. + } else if (data.lightSource->type() == LS_SPOT) {
  140. neonData.flags |= FLAG_SPOT_LIGHT;
  141. - SpotLightSource& spotLightSource = static_cast<SpotLightSource&>(m_lightSource.get());
  142. + const auto& spotLightSource = *static_cast<const SpotLightSource*>(data.lightSource);
  143. floatArguments.lightX = spotLightSource.position().x();
  144. floatArguments.lightY = spotLightSource.position().y();
  145. floatArguments.lightZ = spotLightSource.position().z();
  146. @@ -145,7 +146,7 @@ inline void FELighting::platformApplyNeon(const LightingData& data, const LightS
  147. if (spotLightSource.specularExponent() == 1)
  148. neonData.flags |= FLAG_CONE_EXPONENT_IS_1;
  149. } else {
  150. - ASSERT(m_lightSource->type() == LS_DISTANT);
  151. + ASSERT(data.lightSource->type() == LS_DISTANT);
  152. floatArguments.lightX = paintingData.initialLightingData.lightVector.x();
  153. floatArguments.lightY = paintingData.initialLightingData.lightVector.y();
  154. floatArguments.lightZ = paintingData.initialLightingData.lightVector.z();
  155. @@ -155,38 +156,39 @@ inline void FELighting::platformApplyNeon(const LightingData& data, const LightS
  156. // Set lighting arguments.
  157. floatArguments.surfaceScale = data.surfaceScale;
  158. floatArguments.minusSurfaceScaleDividedByFour = -data.surfaceScale / 4;
  159. - if (m_lightingType == FELighting::DiffuseLighting)
  160. - floatArguments.diffuseConstant = m_diffuseConstant;
  161. + if (data.filterType == FilterEffect::Type::FEDiffuseLighting)
  162. + floatArguments.diffuseConstant = data.diffuseConstant;
  163. else {
  164. neonData.flags |= FLAG_SPECULAR_LIGHT;
  165. - floatArguments.diffuseConstant = m_specularConstant;
  166. - neonData.specularExponent = getPowerCoefficients(m_specularExponent);
  167. - if (m_specularExponent == 1)
  168. + floatArguments.diffuseConstant = data.specularConstant;
  169. + neonData.specularExponent = getPowerCoefficients(data.specularExponent);
  170. + if (data.specularExponent == 1)
  171. neonData.flags |= FLAG_SPECULAR_EXPONENT_IS_1;
  172. }
  173. if (floatArguments.diffuseConstant == 1)
  174. neonData.flags |= FLAG_DIFFUSE_CONST_IS_1;
  175. - int optimalThreadNumber = ((data.widthDecreasedByOne - 1) * (data.heightDecreasedByOne - 1)) / s_minimalRectDimension;
  176. + static constexpr int minimalRectDimension = 100 * 100; // Empirical data limit for parallel jobs
  177. + int optimalThreadNumber = ((data.width - 2) * (data.height - 2)) / minimalRectDimension;
  178. if (optimalThreadNumber > 1) {
  179. // Initialize parallel jobs
  180. - ParallelJobs<FELightingPaintingDataForNeon> parallelJobs(&WebCore::FELighting::platformApplyNeonWorker, optimalThreadNumber);
  181. + ParallelJobs<FELightingPaintingDataForNeon> parallelJobs(&FELightingSoftwareApplier::platformApplyNeonWorker, optimalThreadNumber);
  182. // Fill the parameter array
  183. int job = parallelJobs.numberOfJobs();
  184. if (job > 1) {
  185. int yStart = 1;
  186. - int yStep = (data.heightDecreasedByOne - 1) / job;
  187. + int yStep = (data.height - 2) / job;
  188. for (--job; job >= 0; --job) {
  189. FELightingPaintingDataForNeon& params = parallelJobs.parameter(job);
  190. params = neonData;
  191. params.yStart = yStart;
  192. - params.pixels += (yStart - 1) * (data.widthDecreasedByOne + 1) * 4;
  193. + params.pixels += (yStart - 1) * data.width * 4;
  194. if (job > 0) {
  195. params.absoluteHeight = yStep;
  196. yStart += yStep;
  197. } else
  198. - params.absoluteHeight = data.heightDecreasedByOne - yStart;
  199. + params.absoluteHeight = (data.height - 1) - yStart;
  200. }
  201. parallelJobs.execute();
  202. return;
  203. @@ -199,5 +201,3 @@ inline void FELighting::platformApplyNeon(const LightingData& data, const LightS
  204. } // namespace WebCore
  205. #endif // CPU(ARM_NEON) && COMPILER(GCC_COMPATIBLE)
  206. -
  207. -#endif // FELightingNEON_h
  208. diff --git a/Source/WebCore/platform/graphics/filters/DistantLightSource.h b/Source/WebCore/platform/graphics/filters/DistantLightSource.h
  209. index 70f583b36e2c..7d5d27e5ccf8 100644
  210. --- a/Source/WebCore/platform/graphics/filters/DistantLightSource.h
  211. +++ b/Source/WebCore/platform/graphics/filters/DistantLightSource.h
  212. @@ -26,6 +26,10 @@
  213. #include <wtf/ArgumentCoder.h>
  214. #include <wtf/Ref.h>
  215. +namespace WTF {
  216. +class TextStream;
  217. +} // namespace WTF
  218. +
  219. namespace WebCore {
  220. class DistantLightSource : public LightSource {
  221. diff --git a/Source/WebCore/platform/graphics/filters/FELighting.h b/Source/WebCore/platform/graphics/filters/FELighting.h
  222. index 179edf6dba24..694d712d56fd 100644
  223. --- a/Source/WebCore/platform/graphics/filters/FELighting.h
  224. +++ b/Source/WebCore/platform/graphics/filters/FELighting.h
  225. @@ -35,8 +35,6 @@
  226. namespace WebCore {
  227. -struct FELightingPaintingDataForNeon;
  228. -
  229. class FELighting : public FilterEffect {
  230. public:
  231. bool operator==(const FELighting&) const;
  232. @@ -68,11 +66,6 @@ protected:
  233. std::unique_ptr<FilterEffectApplier> createSoftwareApplier() const override;
  234. -#if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC_COMPATIBLE)
  235. - static int getPowerCoefficients(float exponent);
  236. - inline void platformApplyNeon(const LightingData&, const LightSource::PaintingData&);
  237. -#endif
  238. -
  239. Color m_lightingColor;
  240. float m_surfaceScale;
  241. float m_diffuseConstant;
  242. diff --git a/Source/WebCore/platform/graphics/filters/PointLightSource.h b/Source/WebCore/platform/graphics/filters/PointLightSource.h
  243. index a8cfdab895a9..34f867bba237 100644
  244. --- a/Source/WebCore/platform/graphics/filters/PointLightSource.h
  245. +++ b/Source/WebCore/platform/graphics/filters/PointLightSource.h
  246. @@ -26,6 +26,10 @@
  247. #include "LightSource.h"
  248. #include <wtf/Ref.h>
  249. +namespace WTF {
  250. +class TextStream;
  251. +} // namespace WTF
  252. +
  253. namespace WebCore {
  254. class PointLightSource : public LightSource {
  255. diff --git a/Source/WebCore/platform/graphics/filters/SpotLightSource.h b/Source/WebCore/platform/graphics/filters/SpotLightSource.h
  256. index 6404467a5b6f..5cac38f22362 100644
  257. --- a/Source/WebCore/platform/graphics/filters/SpotLightSource.h
  258. +++ b/Source/WebCore/platform/graphics/filters/SpotLightSource.h
  259. @@ -26,6 +26,10 @@
  260. #include "LightSource.h"
  261. #include <wtf/Ref.h>
  262. +namespace WTF {
  263. +class TextStream;
  264. +} // namespace WTF
  265. +
  266. namespace WebCore {
  267. class SpotLightSource : public LightSource {
  268. diff --git a/Source/WebCore/platform/graphics/filters/software/FELightingSoftwareApplier.h b/Source/WebCore/platform/graphics/filters/software/FELightingSoftwareApplier.h
  269. index c974d92115ff..e2896660cfbd 100644
  270. --- a/Source/WebCore/platform/graphics/filters/software/FELightingSoftwareApplier.h
  271. +++ b/Source/WebCore/platform/graphics/filters/software/FELightingSoftwareApplier.h
  272. @@ -36,6 +36,7 @@
  273. namespace WebCore {
  274. class FELighting;
  275. +struct FELightingPaintingDataForNeon;
  276. class FELightingSoftwareApplier final : public FilterEffectConcreteApplier<FELighting> {
  277. WTF_MAKE_FAST_ALLOCATED;
  278. @@ -132,8 +133,23 @@ private:
  279. static void applyPlatformGenericPaint(const LightingData&, const LightSource::PaintingData&, int startY, int endY);
  280. static void applyPlatformGenericWorker(ApplyParameters*);
  281. +
  282. +#if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC_COMPATIBLE)
  283. + static int getPowerCoefficients(float exponent);
  284. + static void platformApplyNeonWorker(FELightingPaintingDataForNeon*);
  285. + inline static void applyPlatformNeon(const LightingData&, const LightSource::PaintingData&);
  286. +
  287. + inline static void applyPlatformGeneric(const LightingData& data, const LightSource::PaintingData& paintingData)
  288. + {
  289. + applyPlatformNeon(data, paintingData);
  290. + }
  291. +#else
  292. static void applyPlatformGeneric(const LightingData&, const LightSource::PaintingData&);
  293. +#endif
  294. +
  295. static void applyPlatform(const LightingData&);
  296. };
  297. } // namespace WebCore
  298. +
  299. +#include "FELightingNEON.h"
  300. --
  301. 2.43.1