[OpenJDK 2D-Dev] [9] Review Request: 8041129 [OGL] surface->sw blit is extremely slow
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Wed May 7 19:10:46 UTC 2014
Hello, Jim.
I have started to implement the second solution, and a prototype looks
good to me.
But I got a problem with an appropriate test, do I understand correctly
that there is no way to understand is transparent volatile image
premultiply alpha or not?
Because if I draw a transparent volatile image to the
bufferedImage_argb_pre, i get completely different results from getRGB()
on different pipelines.
For example what is correct value in the attached test:
2000080 - when I draw directly to BI_ARGB_PRE, (on my opengl prototype i
get the same value when draw via transparent VI).
2008080 - when I draw to BI_ARGB_PRE via transparent VI(on d3d and gdi)?
Who is right?
On 29.04.2014 23:25, Sergey Bylokhov wrote:
> Hello, Jim.
> I have started working with another issue, which touches the same code.
> https://bugs.openjdk.java.net/browse/JDK-8017626
> The problem is clear our surface in opengl contains data in
> premultiplied mode[1][2], but we have only one surface->sw loop in
> opengl which is:
> new OGLSurfaceToSwBlit(SurfaceType.IntArgb,
> OGLSurfaceData.PF_INT_ARGB);
>
> Note that both parameters are argb. As you remember this blit is
> implemented via glReadPixels which transfer data without modification.
> So we are in trouble in case of translucent volatile image, when alpha
> != 1.0.
> I see two possible solutions:
> 1. Change the type of the surface->sw blit to _pre and change all
> related code to fail back to this blit, other draws will be done via
> intermediate backbuffer.
> 2. Restore the colors during the flip operation for case of argb blit
> + create new blit to cover argb_pre(it will have current implementation).
>
> What do you think?
>
> [1]
> http://mail.openjdk.java.net/pipermail/2d-dev/2013-October/003783.html
> [2] https://bugs.openjdk.java.net/browse/JDK-8017626
>
> On 4/24/14 3:48 AM, Jim Graham wrote:
>> The benchmark spreads look much better and the code looks good, but I
>> worry that we are being inconsistent in whether or not we set the
>> SKIP_ values. This function sets them back to 0 when done, but can
>> we assume that about all code that uses these methods?
>>
>> ...jim
>>
>> On 4/23/14 1:46 PM, Sergey Bylokhov wrote:
>>> Hello.
>>> Please review an updated version of the fix.
>>>
>>> Bugs which were found in the previous version:
>>> - Destination vertical offset was
>>> ignored(j2d_glPixelStorei(GL_PACK_SKIP_ROWS, dsty)) now we take it into
>>> account using PtrAddBytes(pDst, dsty * dstInfo.scanStride)
>>> - srcy wasn't recalculated for the correct direction
>>> - In the first version of the fix scanStride was used for iteration
>>> over destination memory and as a parameter of memcpy. This is
>>> incorrect,
>>> because we should flip only a drawable part of destination. Now memcpy
>>> uses pixelStride * width
>>>
>>> Because no one of these problems were not found by the tests a new ones
>>> were added.
>>>
>>> I filed another issue related to the surface->sw blit, opengl and d3d
>>> ignore the clip of the destination JDK-8041644
>>>
>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8041129
>>> Webrev can be found at:
>>> http://cr.openjdk.java.net/~serb/8041129/webrev.03/webrev
>>>
>>> Benchmarks: to decrease the spread I increased the time per test from
>>> 2500 ms to 25 seconds
>>> =======================================================================
>>> Windows 7 x64, lenovo T410, nvidia NVS 3100M
>>> http://cr.openjdk.java.net/~serb/8041129/webrev.03/J2DBench/results-nvidia-windows.txt
>>>
>>>
>>> Summary:
>>> OGL-base-nvidia-windows:
>>> Number of tests: 10
>>> Overall average: 1943.4318817726798
>>> Best spread: 0.36% variance
>>> Worst spread: 4.16% variance
>>> (Basis for results comparison)
>>>
>>> OGL-fix2-nvidia-windows:
>>> Number of tests: 10
>>> Overall average: 181165.51031119752
>>> Best spread: 0.35% variance
>>> Worst spread: 2.57% variance
>>> Comparison to basis:
>>> Best result: 19142.77% of basis
>>> Worst result: 97.75% of basis
>>> Number of wins: 8
>>> Number of ties: 2
>>> Number of losses: 0
>>>
>>> D3D-base-nvidia-windows:
>>> Number of tests: 10
>>> Overall average: 30046.475416066532
>>> Best spread: 0.05% variance
>>> Worst spread: 4.56% variance
>>> Comparison to basis:
>>> Best result: 13660.29% of basis
>>> Worst result: 9.34% of basis
>>> Number of wins: 6
>>> Number of ties: 1
>>> Number of losses: 3
>>>
>>> =======================================================================
>>> OSX 10.8.5, macbook pro retina, nvidia GeForce GT 650M 1024 MB
>>> http://cr.openjdk.java.net/~serb/8041129/webrev.03/J2DBench/results-nvidia-osx.txt
>>>
>>>
>>> Summary:
>>> OGL-base-nvidia-osx:
>>> Number of tests: 10
>>> Overall average: 719.3548194040994
>>> Best spread: 0.1% variance
>>> Worst spread: 4.09% variance
>>> (Basis for results comparison)
>>>
>>> OGL-fix2-nvidia-osx:
>>> Number of tests: 10
>>> Overall average: 11050.087724732544
>>> Best spread: 0.11% variance
>>> Worst spread: 3.54% variance
>>> Comparison to basis:
>>> Best result: 4713.13% of basis
>>> Worst result: 175.51% of basis
>>> Number of wins: 10
>>> Number of ties: 0
>>> Number of losses: 0
>>>
>>> =======================================================================
>>> OSX 10.8.5, macbook pro retina, Intel HD Graphics 4000
>>> http://cr.openjdk.java.net/~serb/8041129/webrev.03/J2DBench/results-intel-osx.txt
>>>
>>>
>>> Summary:
>>> OGL-base-intel-osx:
>>> Number of tests: 10
>>> Overall average: 3958.228739879219
>>> Best spread: 0.4% variance
>>> Worst spread: 8.09% variance
>>> (Basis for results comparison)
>>>
>>> OGL-fix2-intel-osx:
>>> Number of tests: 10
>>> Overall average: 10098.091503211792
>>> Best spread: 0.35% variance
>>> Worst spread: 17.97% variance
>>> Comparison to basis:
>>> Best result: 477.95% of basis
>>> Worst result: 105.42% of basis
>>> Number of wins: 10
>>> Number of ties: 0
>>> Number of losses: 0
>>>
>>> On 21.04.2014 18:52, Andrew Brygin wrote:
>>>> Hello Sergey,
>>>>
>>>> the fast path skips j2d_glPixelStorei(GL_PACK_SKIP_ROWS, dsty).
>>>>
>>>> Could you please clarify why? I think that initial value of dsty
>>>> (dstInfo.bounds.y1) can be non-zero, and this operation
>>>> seem to be required...
>>>>
>>>> Thanks,
>>>> Andrew
>>>>
>>>> On 4/21/2014 6:17 PM, Sergey Bylokhov wrote:
>>>>> Hello.
>>>>> Please review the fix for jdk 9.
>>>>> This issue initially was found in FX[1], and there is description of
>>>>> this problem.
>>>>> In the fix the flip operation is done using memcpy after the whole
>>>>> image was moved from gpu to cpu.
>>>>>
>>>>> [1] https://javafx-jira.kenai.com/browse/RT-30035
>>>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8041129
>>>>> Webrev can be found at:
>>>>> http://cr.openjdk.java.net/~serb/8041129/webrev.01
>>>>>
>>>>> Benchmarks:
>>>>> ==========================================================
>>>>> Windows 7 x64, lenovo T410, nvidia NVS 3100M
>>>>> http://cr.openjdk.java.net/~serb/8041129/J2DBench/results
>>>>> base ogl vs base d3d vs fixed ogl
>>>>> Summary:
>>>>> OGL-base-nvidia-windows:
>>>>> Number of tests: 10
>>>>> Overall average: 2239.9261323744704
>>>>> Best spread: 1.72% variance
>>>>> Worst spread: 88.61% variance
>>>>> (Basis for results comparison)
>>>>>
>>>>> OGL-fix-nvidia-windows:
>>>>> Number of tests: 10
>>>>> Overall average: 166667.93024226945
>>>>> Best spread: 1.23% variance
>>>>> Worst spread: 66.19% variance
>>>>> Comparison to basis:
>>>>> Best result: 13719.74% of basis
>>>>> Worst result: 97.17% of basis
>>>>> Number of wins: 8
>>>>> Number of ties: 1
>>>>> Number of losses: 1
>>>>>
>>>>> D3D-base-nvidia-windows:
>>>>> Number of tests: 10
>>>>> Overall average: 29755.21747098
>>>>> Best spread: 0.34% variance
>>>>> Worst spread: 61.12% variance
>>>>> Comparison to basis:
>>>>> Best result: 12068.41% of basis
>>>>> Worst result: 8.05% of basis
>>>>> Number of wins: 6
>>>>> Number of ties: 0
>>>>> Number of losses: 4
>>>>>
>>>>> ==========================================================
>>>>> OSX 10.8.5, macbook pro retina, nvidia GeForce GT 650M 1024 MB
>>>>> http://cr.openjdk.java.net/~serb/8041129/J2DBench-osx/results-nvidia-osx.txt
>>>>>
>>>>>
>>>>> Summary:
>>>>> OGL-base-nvidia-osx:
>>>>> Number of tests: 10
>>>>> Overall average: 710.7070782394075
>>>>> Best spread: 0.73% variance
>>>>> Worst spread: 5.72% variance
>>>>> (Basis for results comparison)
>>>>>
>>>>> OGL-fix-nvidia-osx:
>>>>> Number of tests: 10
>>>>> Overall average: 11032.674771293528
>>>>> Best spread: 0.62% variance
>>>>> Worst spread: 8.14% variance
>>>>> Comparison to basis:
>>>>> Best result: 4659.95% of basis
>>>>> Worst result: 169.66% of basis
>>>>> Number of wins: 10
>>>>> Number of ties: 0
>>>>> Number of losses: 0
>>>>>
>>>>> ==========================================================
>>>>> OSX 10.8.5, macbook pro retina, Intel HD Graphics 4000
>>>>> http://cr.openjdk.java.net/~serb/8041129/J2DBench-osx/results-intel-osx.txt
>>>>>
>>>>>
>>>>> Summary:
>>>>> OGL-base-intel-osx:
>>>>> Number of tests: 10
>>>>> Overall average: 3993.5366388495613
>>>>> Best spread: 0.65% variance
>>>>> Worst spread: 20.91% variance
>>>>> (Basis for results comparison)
>>>>>
>>>>> OGL-fix-intel-osx:
>>>>> Number of tests: 10
>>>>> Overall average: 10197.361705976433
>>>>> Best spread: 0.72% variance
>>>>> Worst spread: 38.4% variance
>>>>> Comparison to basis:
>>>>> Best result: 491.0% of basis
>>>>> Worst result: 108.61% of basis
>>>>> Number of wins: 10
>>>>> Number of ties: 0
>>>>> Number of losses: 0
>>>>>
>>>>> Thanks to Anton for the initial version of the fix.
>>>>>
>>>>
>>>
>>>
>
>
--
Best regards, Sergey.
-------------- next part --------------
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import static java.awt.image.BufferedImage.TRANSLUCENT;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE;
public final class IncorrectAlphaPreSurface2SW2 {
private static final int S = 1;
public static void main(final String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
BufferedImage bi = new BufferedImage(S, S, TYPE_INT_ARGB_PRE);
BufferedImage gold = new BufferedImage(S, S, TYPE_INT_ARGB_PRE);
VolatileImage vi = gc.createCompatibleVolatileImage(S, S, TRANSLUCENT);
fill(gold);
fill(vi);
Graphics2D big = bi.createGraphics();
big.setComposite(AlphaComposite.Src);
big.drawImage(vi, 0, 0, S, S, null);
big.dispose();
System.out.printf("gold.getRGB(0,0) = %1$h\n", gold.getRGB(0, 0));
System.out.printf("bi.getRGB(0,0) = %1$h\n", bi.getRGB(0, 0));
}
private static void fill(final Image image) {
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setComposite(AlphaComposite.Src);
graphics.setColor(new Color(23, 127, 189, 2));
graphics.fillRect(0, 0, S, S);
graphics.dispose();
}
}
More information about the 2d-dev
mailing list