Re: API for matrix manipulation
Just wanted to throw in Sylvester, which is a fairly cool Math JS lib for generic Matrix and Vector computations (http://sylvester.jcoglan.com/). I especially like it as the API feels like it is designed for human beings. Having Matrix/Vector as generic interfaces sounds like a big win. Am 18.03.11 21:50 schrieb Chris Marrin unter cmar...@apple.com: On Mar 15, 2011, at 5:08 PM, Tab Atkins Jr. wrote: On Tue, Mar 15, 2011 at 5:00 PM, Chris Marrin cmar...@apple.com wrote: I think it would be nice to unify the classes somehow. But that might be difficult since SVG and CSS are (necessarily) separate specs. But maybe one of the API gurus has a solution? We just discussed this on Monday at the FXTF telcon. Sounds like people are, in general, okay with just using a 4x4 matrix, though there are some possible implementation issues with devices that can't do 3d at all. (It was suggested that they can simply do a 2d projection, which is simple.) I don't think there are implementation issues other than performance related ones. As you say, you can always flatten a 3D matrix for use in a purely 2D renderer. We do this in the WebKit implementation in some cases. But doing 4x4 matrix math can be expensive, especially on less capable hardware,. So it would probably be valuable to have a set of 2D affine calls on any future 4x4 class, so an implementation can easily optimize by knowing they can get away with doing a subset of the math if all the operands are 2D affine matrices. But that's just a bit of extra API. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
On Mar 15, 2011, at 5:08 PM, Tab Atkins Jr. wrote: On Tue, Mar 15, 2011 at 5:00 PM, Chris Marrin cmar...@apple.com wrote: I think it would be nice to unify the classes somehow. But that might be difficult since SVG and CSS are (necessarily) separate specs. But maybe one of the API gurus has a solution? We just discussed this on Monday at the FXTF telcon. Sounds like people are, in general, okay with just using a 4x4 matrix, though there are some possible implementation issues with devices that can't do 3d at all. (It was suggested that they can simply do a 2d projection, which is simple.) I don't think there are implementation issues other than performance related ones. As you say, you can always flatten a 3D matrix for use in a purely 2D renderer. We do this in the WebKit implementation in some cases. But doing 4x4 matrix math can be expensive, especially on less capable hardware,. So it would probably be valuable to have a set of 2D affine calls on any future 4x4 class, so an implementation can easily optimize by knowing they can get away with doing a subset of the math if all the operands are 2D affine matrices. But that's just a bit of extra API. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
Hi, related to this: Is there any work ongoing to tie these (or more generic vector / matrix) classes to OpenCL / WebCL for faster computation across CPUs and GPUs? - Lars On Mon, Mar 14, 2011 at 5:17 PM, Chris Marrin cmar...@apple.com wrote: On Mar 14, 2011, at 7:56 AM, João Eiras wrote: Hi. Given that a number of API are being developed that require complex matricial calculations (transforms, device orientation, web gl), I would suggest that perhaps an API with a big number of common calculations could be made available ? And a proper way to represent them. Perhaps, the best way to add this would be to extend the Math object with things like. Math.mAdd(m1, m2) Math.mSub(m1, m2) Math.mMult(m1, m2) Math.mDiv(m1, m2) Math.mInverse(m1) Math.mGaussianReduce(m1) Math.mRank(m1) Math.mRank(m1) Being the matrix an array like object like (could even be one of those fast arrays like ArrayBuffer). # { # w: width, # h: height, # length: width * heigth # 0: ..., # 1: ..., # 2: ... # (...) # } Comments or is something already being worked on ? There are already 2 such classes: SVGMatrix and CSSMatrix. The former is an affine transformation matrix (commonly misnamed a 2x3 matrix) and the latter is a 3D homogeneous transformation matrix (commonly correctly named a 4x4 matrix). We added CSSMatrix to the CSS Transform Spec to give us the same functionality as SVG Matrix, but for 3D transforms. Therefore both of these classes are pretty light on their operators. It might be useful to discuss one matrix to rule them all, which could be used in place of the current classes and with more functionality. But it's important not to go too far down this path, or you'll end up defining classes for Points, Lines, Planes, Bounding Boxes and View Volumes with dozens of functions. Down that path lies madness. I think the current spec handles the more complex (inverse and multiply) and more commonly used (scale, rotate, translate) functions. I'm not sure what adding and subtracting 2 matrices means, and division is handled by inverse and multiply. The others seem pretty domain specific for a general class. And remember you can (and many people have) created JS libraries to add funcrtions to the built-in matrix classes. I wrote one: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/demos/webkit/resources/J3DIMath.js which uses CSSMatrix if it exists and uses JS otherwise. It exposed some interesting deficiencies in the current CSSMatrix class. There are several bugs on WebKit to address these and other issues of matrix efficiency and functionality: 23799 https://bugs.webkit.org/show_bug.cgi?id=23799, 28850 https://bugs.webkit.org/show_bug.cgi?id=28850, 50633https://bugs.webkit.org/show_bug.cgi?id=50633 , 52488 https://bugs.webkit.org/show_bug.cgi?id=52488. Perhaps it would be useful to open these (or similar) bugs on the w3c bug system? That's where I believe we are on the Matrix front. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
On Mon, Mar 14, 2011 at 4:27 PM, Chris Marrin cmar...@apple.com wrote: On Mar 14, 2011, at 12:19 PM, Lars Knudsen wrote: Hi, related to this: Is there any work ongoing to tie these (or more generic vector / matrix) classes to OpenCL / WebCL for faster computation across CPUs and GPUs? On WebKit I've experimented with an API to copy a CSSMatrix to an Float32Array, which can be directly uploaded to the GPU. It's surprising how much more efficient this was than copying the 16 floating point values out of the CSSMatrix using JS. But I've hesitated proposing such an API while WebGL and Typed Arrays were still in draft. Now that they're not, maybe it's time to discuss it. I've also experimented with API in CSSMatrix to do in-place operations, rather than creating a new CSSMatrix to hold the results. This too was a big win, mostly I think because you get rid of all the churn of creating and collecting CSSMatrix objects. Would it be an even bigger win if CSSMatrix took a destination? That way you can avoid all allocations where as if they do it in place then you always need to make at least some copies to temps to get anything done. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
On Mar 14, 2011, at 6:54 PM, João Eiras wrote: Comments or is something already being worked on ? There are already 2 such classes: SVGMatrix and CSSMatrix. The former is an affine transformation matrix (commonly misnamed a 2x3 matrix) and the latter is a 3D homogeneous transformation matrix (commonly correctly named a 4x4 matrix). Are those classes in their current implementations thread-safe ? Could a Web Worker easily do matrix calculations with them ? I would guess a basic physics engine in a worker would be a nice use case. They are as thread safe as any other JavaScript classes, which is not at all :-) As I understand it, the data would have to be serialized to be sent between Workers and the main thread. And what about making something that is generic enough for both SVG and CSS, or even full blown algebra ? And then specify bindings of implicit conversions from those DOM classes into a basic ES matrix (if you would like to call it that) ? Proposing a Matrix class in JavaScript is much different than adding classes to the browser to support the DOM API, which is what SVGMatrix and CSSMatrix are. I think it would be nice to unify the classes somehow. But that might be difficult since SVG and CSS are (necessarily) separate specs. But maybe one of the API gurus has a solution? - ~Chris cmar...@apple.com
Re: API for matrix manipulation
On Mar 15, 2011, at 2:49 PM, Gregg Tavares (wrk) wrote: On Mon, Mar 14, 2011 at 4:27 PM, Chris Marrin cmar...@apple.com wrote: On Mar 14, 2011, at 12:19 PM, Lars Knudsen wrote: Hi, related to this: Is there any work ongoing to tie these (or more generic vector / matrix) classes to OpenCL / WebCL for faster computation across CPUs and GPUs? On WebKit I've experimented with an API to copy a CSSMatrix to an Float32Array, which can be directly uploaded to the GPU. It's surprising how much more efficient this was than copying the 16 floating point values out of the CSSMatrix using JS. But I've hesitated proposing such an API while WebGL and Typed Arrays were still in draft. Now that they're not, maybe it's time to discuss it. I've also experimented with API in CSSMatrix to do in-place operations, rather than creating a new CSSMatrix to hold the results. This too was a big win, mostly I think because you get rid of all the churn of creating and collecting CSSMatrix objects. Would it be an even bigger win if CSSMatrix took a destination? That way you can avoid all allocations where as if they do it in place then you always need to make at least some copies to temps to get anything done. When you say destination are you talking about operating on a Typed Array buffer directly? I suppose that would be possible, but that would really just be like having 3D matrix operations on the Float32Array object. I think it would be a mistake to make yet another set of matrix functions! And one way or the other you need to copy data between types. You might be doing a CSS animation and you want to get the current matrix, put it in a Float32Array and send it to WebGL (I've done this, works great!). The cost of copying a matrix from a CSSMatrix to a Float32Array is so low relative to all the other call overhead that I don't think eliding that copy would buy much. But I might be wrong. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
On Tue, Mar 15, 2011 at 5:00 PM, Chris Marrin cmar...@apple.com wrote: I think it would be nice to unify the classes somehow. But that might be difficult since SVG and CSS are (necessarily) separate specs. But maybe one of the API gurus has a solution? We just discussed this on Monday at the FXTF telcon. Sounds like people are, in general, okay with just using a 4x4 matrix, though there are some possible implementation issues with devices that can't do 3d at all. (It was suggested that they can simply do a 2d projection, which is simple.) ~TJ
API for matrix manipulation
Hi. Given that a number of API are being developed that require complex matricial calculations (transforms, device orientation, web gl), I would suggest that perhaps an API with a big number of common calculations could be made available ? And a proper way to represent them. Perhaps, the best way to add this would be to extend the Math object with things like. Math.mAdd(m1, m2) Math.mSub(m1, m2) Math.mMult(m1, m2) Math.mDiv(m1, m2) Math.mInverse(m1) Math.mGaussianReduce(m1) Math.mRank(m1) Math.mRank(m1) Being the matrix an array like object like (could even be one of those fast arrays like ArrayBuffer). # { # w: width, # h: height, # length: width * heigth # 0: ..., # 1: ..., # 2: ... # (...) # } Comments or is something already being worked on ? Thank you.
Re: API for matrix manipulation
On 3/14/11 10:56 AM, João Eiras wrote: Math.mAdd(m1, m2) Math.mSub(m1, m2) Math.mMult(m1, m2) Presumably throwing on size mismatches? Math.mDiv(m1, m2) I don't think we should add this. Matrix division is a pretty fuzzy concept with non-square matrices. And if you stick to square matrices, it's easy to clearly do whatever you're trying to do with inverses. Math.mInverse(m1) Presumably throwing for non-square matrices? Math.mGaussianReduce(m1) This could be fun to define. Are you actually talking about Gaussian elimination, or Gauss-Jordan? For either one the output is not uniquely defined (at least not if you might want to make it fast), last I checked -Boris
Re: API for matrix manipulation
On Mar 14, 2011, at 7:56 AM, João Eiras wrote: Hi. Given that a number of API are being developed that require complex matricial calculations (transforms, device orientation, web gl), I would suggest that perhaps an API with a big number of common calculations could be made available ? And a proper way to represent them. Perhaps, the best way to add this would be to extend the Math object with things like. Math.mAdd(m1, m2) Math.mSub(m1, m2) Math.mMult(m1, m2) Math.mDiv(m1, m2) Math.mInverse(m1) Math.mGaussianReduce(m1) Math.mRank(m1) Math.mRank(m1) Being the matrix an array like object like (could even be one of those fast arrays like ArrayBuffer). # { # w: width, # h: height, # length: width * heigth # 0: ..., # 1: ..., # 2: ... # (...) # } Comments or is something already being worked on ? There are already 2 such classes: SVGMatrix and CSSMatrix. The former is an affine transformation matrix (commonly misnamed a 2x3 matrix) and the latter is a 3D homogeneous transformation matrix (commonly correctly named a 4x4 matrix). We added CSSMatrix to the CSS Transform Spec to give us the same functionality as SVG Matrix, but for 3D transforms. Therefore both of these classes are pretty light on their operators. It might be useful to discuss one matrix to rule them all, which could be used in place of the current classes and with more functionality. But it's important not to go too far down this path, or you'll end up defining classes for Points, Lines, Planes, Bounding Boxes and View Volumes with dozens of functions. Down that path lies madness. I think the current spec handles the more complex (inverse and multiply) and more commonly used (scale, rotate, translate) functions. I'm not sure what adding and subtracting 2 matrices means, and division is handled by inverse and multiply. The others seem pretty domain specific for a general class. And remember you can (and many people have) created JS libraries to add funcrtions to the built-in matrix classes. I wrote one: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/demos/webkit/resources/J3DIMath.js which uses CSSMatrix if it exists and uses JS otherwise. It exposed some interesting deficiencies in the current CSSMatrix class. There are several bugs on WebKit to address these and other issues of matrix efficiency and functionality: 23799, 28850, 50633, 52488. Perhaps it would be useful to open these (or similar) bugs on the w3c bug system? That's where I believe we are on the Matrix front. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
On Mar 14, 2011, at 12:19 PM, Lars Knudsen wrote: Hi, related to this: Is there any work ongoing to tie these (or more generic vector / matrix) classes to OpenCL / WebCL for faster computation across CPUs and GPUs? On WebKit I've experimented with an API to copy a CSSMatrix to an Float32Array, which can be directly uploaded to the GPU. It's surprising how much more efficient this was than copying the 16 floating point values out of the CSSMatrix using JS. But I've hesitated proposing such an API while WebGL and Typed Arrays were still in draft. Now that they're not, maybe it's time to discuss it. I've also experimented with API in CSSMatrix to do in-place operations, rather than creating a new CSSMatrix to hold the results. This too was a big win, mostly I think because you get rid of all the churn of creating and collecting CSSMatrix objects. - ~Chris cmar...@apple.com
Re: API for matrix manipulation
Comments or is something already being worked on ? There are already 2 such classes: SVGMatrix and CSSMatrix. The former is an affine transformation matrix (commonly misnamed a 2x3 matrix) and the latter is a 3D homogeneous transformation matrix (commonly correctly named a 4x4 matrix). Are those classes in their current implementations thread-safe ? Could a Web Worker easily do matrix calculations with them ? I would guess a basic physics engine in a worker would be a nice use case. And what about making something that is generic enough for both SVG and CSS, or even full blown algebra ? And then specify bindings of implicit conversions from those DOM classes into a basic ES matrix (if you would like to call it that) ?