Bug 244564 - TextureMapper: Calculate zFar and zNear for the projection matrix
Summary: TextureMapper: Calculate zFar and zNear for the projection matrix
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Fujii Hironori
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-08-30 19:45 PDT by Fujii Hironori
Modified: 2022-09-26 22:59 PDT (History)
9 users (show)

See Also:


Attachments
Patch (9.84 KB, patch)
2022-08-30 19:52 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (9.83 KB, patch)
2022-08-31 23:40 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (9.56 KB, patch)
2022-08-31 23:46 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
test case of w<0 (472 bytes, text/html)
2022-09-01 23:52 PDT, Fujii Hironori
no flags Details
Patch (10.00 KB, patch)
2022-09-02 00:05 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (11.17 KB, patch)
2022-09-02 00:42 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
[fast-cq] Patch for landing (10.18 KB, patch)
2022-09-26 22:55 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fujii Hironori 2022-08-30 19:45:52 PDT
TextureMapper: Calculate zFar and zNear for the projection matrix

This is blocking bug#244526 comment#2.
Comment 1 Fujii Hironori 2022-08-30 19:52:55 PDT
Created attachment 462019 [details]
Patch
Comment 2 Darin Adler 2022-08-31 10:56:47 PDT
Comment on attachment 462019 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=462019&action=review

> Source/WebCore/platform/graphics/texmap/TextureMapper.h:86
> +    virtual void setDepthRange(float, float) { }

Need argument names here. It’s not obvious what the two floats are.

This class is mixing float with double. TransformationMatrix uses double, but we also use FloatRect and FloatPoint. It’s not obvious to me what would be best.

> Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp:872
> +static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored, float zNear, float zFar)

Here we are converting floats to doubles when we put the results of our expression into a TransformationMatrix object. Maybe they should just be doubles from the start? I am not sure this mix of doubles and floats in the existing code is OK.

I’d like to see tests that cover this somehow in the future.

> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h:38
> +struct TextureMapperComputeTransformData;

I think this struct should be a member of the TextureMapperLayer class. It’s an implementation detail. I suggest naming it TextureMapperLayer::ComputeTransformsData.
Comment 3 Fujii Hironori 2022-08-31 23:35:14 PDT
Comment on attachment 462019 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=462019&action=review

>> Source/WebCore/platform/graphics/texmap/TextureMapper.h:86
>> +    virtual void setDepthRange(float, float) { }
> 
> Need argument names here. It’s not obvious what the two floats are.
> 
> This class is mixing float with double. TransformationMatrix uses double, but we also use FloatRect and FloatPoint. It’s not obvious to me what would be best.

Will add argument names.

WebCore is heavily depending on float values, and mixing floats and doubles.
I don't think it's a problem to use float here.

>> Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp:872
>> +static inline TransformationMatrix createProjectionMatrix(const IntSize& size, bool mirrored, float zNear, float zFar)
> 
> Here we are converting floats to doubles when we put the results of our expression into a TransformationMatrix object. Maybe they should just be doubles from the start? I am not sure this mix of doubles and floats in the existing code is OK.
> 
> I’d like to see tests that cover this somehow in the future.

Those values come from TransformationMatrix::mapPoint. It inputs FloatPoint3D and outputs FloatPoint3D.
FloatPoint3D TransformationMatrix::mapPoint(const FloatPoint3D&)
I want the double version of FloatPoint3D, and TransformationMatrix::mapPoint should take it.

>> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h:38
>> +struct TextureMapperComputeTransformData;
> 
> I think this struct should be a member of the TextureMapperLayer class. It’s an implementation detail. I suggest naming it TextureMapperLayer::ComputeTransformsData.

Will fix.
Comment 4 Fujii Hironori 2022-08-31 23:40:00 PDT
Created attachment 462068 [details]
Patch
Comment 5 Fujii Hironori 2022-08-31 23:46:45 PDT
Created attachment 462069 [details]
Patch
Comment 6 Fujii Hironori 2022-09-01 00:36:47 PDT
Comment on attachment 462069 [details]
Patch

I found out a regression for this page. http://wpt.live/css/css-transforms/perspective-split-by-zero-w.html
Comment 7 Fujii Hironori 2022-09-01 23:52:19 PDT
Created attachment 462089 [details]
test case of w<0

In the test case, the perspective is 500px, and the part of the element is placed at z>500px.
Then, w <= 0. It's beyond the infinity.
Comment 8 Fujii Hironori 2022-09-02 00:05:54 PDT
Created attachment 462090 [details]
Patch
Comment 9 Fujii Hironori 2022-09-02 00:22:58 PDT
This patch introduces new warnings.

/app/webkit/Source/WebCore/platform/graphics/texmap/TextureMapper.h:86:39: warning: unused parameter ‘zNear’ [-Wunused-parameter]
/app/webkit/Source/WebCore/platform/graphics/texmap/TextureMapper.h:86:53: warning: unused parameter ‘zFar’ [-Wunused-parameter]
Comment 10 Fujii Hironori 2022-09-02 00:42:43 PDT
Created attachment 462091 [details]
Patch
Comment 11 Fujii Hironori 2022-09-02 03:49:20 PDT
Comment on attachment 462091 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=462091&action=review

> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:136
> +            return std::numeric_limits<double>::max();

It should be possible to calculate zfar and znear more precisely by intersecting with the surface rect.
Comment 12 Radar WebKit Bug Importer 2022-09-06 21:00:25 PDT
<rdar://problem/99633080>
Comment 13 Fujii Hironori 2022-09-26 22:55:40 PDT
Created attachment 462648 [details]
[fast-cq] Patch for landing
Comment 14 EWS 2022-09-26 22:59:35 PDT
Committed 254897@main (922f8f09f0ca): <https://commits.webkit.org/254897@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 462648 [details].