[WHLSL] Support matrices
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jun 2019 02:36:42 +0000 (02:36 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jun 2019 02:36:42 +0000 (02:36 +0000)
commit81211342fc1715ef38e447b3df8f8ca90cf20b50
tree50e03153f0ccc9873c26d8e2b7b68621a2149abd
parent336229d8b1d9a2960c70a26c7e521013692e87fa
[WHLSL] Support matrices
https://bugs.webkit.org/show_bug.cgi?id=198876
<rdar://problem/51768882>

Reviewed by Dean Jackson and Myles Maxfield.

Source/WebCore:

This patch adds in support for matrices to WHLSL. Most matrix related code
is defined by the standard library. This patch just needed to add support
for the native functions operator[] and operator[]= on matrix types. The only
native functions that are named operator[] and operator[]= are for matrix
operations, so we strongly assume when generating code for native operator[] and
operator[]= that we're dealing with matrix types.

operator[]= ignores the write if the index is out of bounds. operator[]
returns a zeroed vector if the index is out of bounds.

This patch also incorporates two bug fixes:
1. This patch takes Robin's patch in https://bugs.webkit.org/show_bug.cgi?id=198313 to ensure
we don't have pointers to values in a hash map. This was needed in this patch
otherwise we'd crash parsing the standard library.

2. This patch fixes how we handle "break" in metal codegen. When I first
implemented break, I strongly assumed we were in a loop. However, break
can be either from a loop or from switch. This patch teaches the metal code
generator to track which context we're in and to emit code accordingly.

Tests: webgpu/whlsl-matrix-2.html
       webgpu/whlsl-matrix.html

* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::emitLoop):
* Modules/webgpu/WHLSL/Metal/WHLSLMetalCodeGenerator.cpp:
(WebCore::WHLSL::Metal::generateMetalCodeShared):
* Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
(WebCore::WHLSL::Metal::writeNativeFunction):
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::Checker::assignTypes):
(WebCore::WHLSL::Checker::getInfo):
(WebCore::WHLSL::Checker::assignType):
(WebCore::WHLSL::Checker::forwardType):
* Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:

LayoutTests:

* webgpu/whlsl-matrix-2-expected.txt: Added.
* webgpu/whlsl-matrix-2.html: Added.
* webgpu/whlsl-matrix-expected.txt: Added.
* webgpu/whlsl-matrix.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246579 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/webgpu/whlsl-matrix-2-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-matrix-2.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl-matrix-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl-matrix.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLMetalCodeGenerator.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt