|
|
Created:
7 years, 7 months ago by Stephen White Modified:
7 years, 6 months ago CC:
skia-review_googlegroups.com, jvanverth1 Base URL:
https://skia.googlecode.com/svn/trunk Visibility:
Public. |
DescriptionProvide a GPU implementation of SkArithmeticMode, using a custom GrEffect exposed via asNewEffectOrCoeff().
Doing it this way required modifying the arithmode GM to use saveLayer()/restore() rather than creating an offscreen SkBitmap, since otherwise the compositing is always done in raster mode. Fixing that in turn exposed that SkArithmeticMode did not work in Picture mode, since it wasn't flattenable. Made it so.
Note: this will require rebaselining the arithmode GM (again).
R=bsalomon@google.com, reed@google.com
Originally committed: https://code.google.com/p/skia/source/detail?r=9324
Reverted: https://code.google.com/p/skia/source/detail?r=9325
Committed: https://code.google.com/p/skia/source/detail?r=9330
Patch Set 1 #Patch Set 2 : Fix spacing #
Total comments: 4
Patch Set 3 : Changed k's to a vec4 in the shader. #
Total comments: 1
Patch Set 4 : Add comment, as per review #Patch Set 5 : Convert to effect on SkArithmeticMode (forget image filter for now) #Patch Set 6 : Fix flattening for out-of-process pictures. #Patch Set 7 : Fix a typo. #Patch Set 8 : Don't attempt to write to inputColor. #
Messages
Total messages: 32 (0 generated)
PTAL. Thanks!
The GPU code mostly looks good to me. A couple of questions inline. https://codereview.chromium.org/16064002/diff/2001/src/effects/SkArithmeticIm... File src/effects/SkArithmeticImageFilter.cpp (right): https://codereview.chromium.org/16064002/diff/2001/src/effects/SkArithmeticIm... src/effects/SkArithmeticImageFilter.cpp:238: fK1Uni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, Just wondering if it'd make sense to use a vec4 for the k values, just to reduce the amount of C code and gl calls to upload. https://codereview.chromium.org/16064002/diff/2001/src/effects/SkArithmeticIm... src/effects/SkArithmeticImageFilter.cpp:267: builder->fsCodeAppend("\t\tfgColor.rgb = clamp(fgColor.rgb / fgColor.a, 0.0, 1.0);\n"); What does clamp do if the first param is NaN?
https://codereview.chromium.org/16064002/diff/2001/src/effects/SkArithmeticIm... File src/effects/SkArithmeticImageFilter.cpp (right): https://codereview.chromium.org/16064002/diff/2001/src/effects/SkArithmeticIm... src/effects/SkArithmeticImageFilter.cpp:238: fK1Uni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, On 2013/05/28 14:21:20, bsalomon wrote: > Just wondering if it'd make sense to use a vec4 for the k values, just to reduce > the amount of C code and gl calls to upload. Yeah, I thought of that. Just thought it might make the shader look less readable/obvious. Would help with uniform allocation on dumb drivers, though. Will try it out. https://codereview.chromium.org/16064002/diff/2001/src/effects/SkArithmeticIm... src/effects/SkArithmeticImageFilter.cpp:267: builder->fsCodeAppend("\t\tfgColor.rgb = clamp(fgColor.rgb / fgColor.a, 0.0, 1.0);\n"); On 2013/05/28 14:21:20, bsalomon wrote: > What does clamp do if the first param is NaN? It returns zero, as far as I can tell (empirically and according to the spec): clamp is defined to return min(max(x, minVal), maxVal). max(x, minVal) is defined to return x if x > minVal, minVal otherwise. Since x is NaN, the comparison always fails, so it returns minVal, or 0. Then min(0, 1) => 0. So, 0.
Changed the shader as requested. PTAnotherL. :)
On 2013/05/28 15:35:27, Stephen White wrote: > Changed the shader as requested. PTAnotherL. :) gpu lgtm
SkArithmeticMode.cpp -- might want to land this on its own. https://codereview.chromium.org/16064002/diff/7001/include/effects/SkArithmet... File include/effects/SkArithmeticImageFilter.h (right): https://codereview.chromium.org/16064002/diff/7001/include/effects/SkArithmet... include/effects/SkArithmeticImageFilter.h:16: SkArithmeticImageFilter(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4, SkImageFilter* background, SkImageFilter* foreground = NULL); Add some dox, both for the k values, and for the two additional filter objects.
Do we already have an imagefilter that just applies an arbitrary xfermode between two other filter results? Wouldn't that subsume this subclass?
On 2013/05/28 16:25:37, reed1 wrote: > Do we already have an imagefilter that just applies an arbitrary xfermode > between two other filter results? Wouldn't that subsume this subclass? We do (at least I wrote one over in Blink-land), but it's lower performing on the GPU-side, since we already have both inputs as textures in this case. This way, we can do the draw as a single pass.
Hmmm, sounds like we want a way for the xfermode to emit some effect snippet so we can handle this optimally... brian?
Why can't we just add a asNewEffectOrCoeff method to SkArithmeticMode and use that?
On 2013/05/28 16:49:56, robertphillips wrote: > Why can't we just add a asNewEffectOrCoeff method to SkArithmeticMode and use > that? The image filter version takes two inputs and produces a third output rather than replacing one of the inputs. We would need some additional info to communicate that the "dst" isn't really the dst surface. Is this not a problem for the raster implementation as well?
On 2013/05/28 16:49:56, robertphillips wrote: > Why can't we just add a asNewEffectOrCoeff method to SkArithmeticMode and use > that? We could, but it would require a two-pass draw on the GPU side, where in this case we already have both inputs as textures.
On 2013/05/28 16:59:14, bsalomon wrote: > On 2013/05/28 16:49:56, robertphillips wrote: > > Why can't we just add a asNewEffectOrCoeff method to SkArithmeticMode and use > > that? > > The image filter version takes two inputs and produces a third output rather > than replacing one of the inputs. We would need some additional info to > communicate that the "dst" isn't really the dst surface. > > Is this not a problem for the raster implementation as well? The raster implementation does a 2-pass draw (as does SkBlendImageFilter). Since we're not yet using the raster implementation in Blink (and the Blink raster implementation is also 2-pass), I'm not too concerned about it yet.
On 2013/05/28 17:11:00, Stephen White wrote: > On 2013/05/28 16:49:56, robertphillips wrote: > > Why can't we just add a asNewEffectOrCoeff method to SkArithmeticMode and use > > that? > > We could, but it would require a two-pass draw on the GPU side, where in this > case we already have both inputs as textures. Actually, hmm. I haven't looked into the new effect-based compositing modes, but maybe we could do both: move the effect creation to SkArithmeticMode::asNewEffectOrCoeff, and call that from a generic SkXferModeImageFilter which applies the effect to the two given inputs. Then it would be 2-pass for the generic compositing path, but still 1-pass for image filters. Brian, would that work?
On 2013/05/28 17:21:00, Stephen White wrote: > On 2013/05/28 17:11:00, Stephen White wrote: > > On 2013/05/28 16:49:56, robertphillips wrote: > > > Why can't we just add a asNewEffectOrCoeff method to SkArithmeticMode and > use > > > that? > > > > We could, but it would require a two-pass draw on the GPU side, where in this > > case we already have both inputs as textures. > > Actually, hmm. I haven't looked into the new effect-based compositing modes, but > maybe we could do both: move the effect creation to > SkArithmeticMode::asNewEffectOrCoeff, and call that from a generic > SkXferModeImageFilter which applies the effect to the two given inputs. Then it > would be 2-pass for the generic compositing path, but still 1-pass for image > filters. Brian, would that work? We'd to somehow communicate the second input texture to SkArithmeticMode::asNewEffectOrCoeff. Otherwise, yes, that should work.
I'm fine for me to change the raster virtual for xfermodes to take the dst as a 3rd buffer.
On 2013/05/28 18:14:52, reed1 wrote: > I'm fine for me to change the raster virtual for xfermodes to take the dst as a > 3rd buffer. For the GPU we can add a texture param to asNewEffectOrCoeff that takes the place of the dst if non-null. I think we'd also have document that only a successful "answer" to the request can only be an effect (not coeffs) in that case. That function is pretty new so there should only be a few implementations to update.
On 2013/05/28 18:38:44, bsalomon wrote: > On 2013/05/28 18:14:52, reed1 wrote: > > I'm fine for me to change the raster virtual for xfermodes to take the dst as > a > > 3rd buffer. > > For the GPU we can add a texture param to asNewEffectOrCoeff that takes the > place of the dst if non-null. I think we'd also have document that only a > successful "answer" to the request can only be an effect (not coeffs) in that > case. That function is pretty new so there should only be a few implementations > to update. I've logged this as https://code.google.com/p/skia/issues/detail?id=1320 Since it would be a moderately deep change, can be proceed with this filter for now (with the raster side extracted to https://codereview.chromium.org/15917010/) and refactor it once the infrastructure changes are done?
Brian thought he could update the gpu signature to allow for SkXfermodeImageFilter to take its place. Can we wait for that to happen? I'm not worried about the raster optimization, since there is no regression from today's perf.
On 2013/05/28 18:52:26, reed1 wrote: > Brian thought he could update the gpu signature to allow for > SkXfermodeImageFilter to take its place. Can we wait for that to happen? I'm not > worried about the raster optimization, since there is no regression from today's > perf. Sure, that sounds fine.
On 2013/05/28 18:55:21, Stephen White wrote: > On 2013/05/28 18:52:26, reed1 wrote: > > Brian thought he could update the gpu signature to allow for > > SkXfermodeImageFilter to take its place. Can we wait for that to happen? I'm > not > > worried about the raster optimization, since there is no regression from > today's > > perf. > > Sure, that sounds fine. Updating the signature is pretty trivial. It probably makes sense to just do it in the change that adds SkXfermodeImageFilter since that would be the only caller that would use the new param.
This patch moves the arithmetic effect to SkArithmeticMode's GPU path, using a custom GrEffect exposed via asNewEffectOrCoeff(). This will be reused later in a future generic SkXfermodeImageFilter, but is simply implemented as an xfermode for now. Doing it this way required modifying the GM to use saveLayer()/restore() rather than creating an offscreen SkBitmap, since otherwise the compositing is always done in raster mode. Fixing that in turn exposed that SkArithmeticMode did not work in Picture mode, since it wasn't flattenable. Made it so. Note: this will require rebaselining the arithmode GM (again).
Thanks for the flattening catch/fix. Will need to add this mode to SkGlobalInitialization_default.cpp. raster change lgtm, deferring to brian for the gpu code.
On 2013/05/29 18:15:24, reed1 wrote: > Thanks for the flattening catch/fix. Will need to add this mode to > SkGlobalInitialization_default.cpp. > > raster change lgtm, deferring to brian for the gpu code. gpu lgtm
On 2013/05/29 18:15:24, reed1 wrote: > Thanks for the flattening catch/fix. Will need to add this mode to > SkGlobalInitialization_default.cpp. Good point! Done. PTAL? > raster change lgtm, deferring to brian for the gpu code.
lgtm
Message was sent while issue was closed.
Committed patchset #7 manually as r9324 (presubmit successful).
Brian: PTAL. I was assuming I could write to the inputColor variable, which isn't always true. (BTW, Is it safe to assume I can always write to dstColor, or should I put that one in a temporary too?)
On 2013/05/29 19:33:12, Stephen White wrote: > Brian: PTAL. I was assuming I could write to the inputColor variable, which > isn't always true. > > (BTW, Is it safe to assume I can always write to dstColor, or should I put that > one in a temporary too?) Oh right, I should have caught that. It is always safe to write to the output color. The input color might be varying or uniform but the output color is always just a non-const var scoped by the main funciton.
On 2013/05/29 20:48:48, bsalomon wrote: > On 2013/05/29 19:33:12, Stephen White wrote: > > Brian: PTAL. I was assuming I could write to the inputColor variable, which > > isn't always true. > > > > (BTW, Is it safe to assume I can always write to dstColor, or should I put > that > > one in a temporary too?) > > Oh right, I should have caught that. It is always safe to write to the output > color. The input color might be varying or uniform but the output color is > always just a non-const var scoped by the main funciton. lgtm
Message was sent while issue was closed.
Committed patchset #8 manually as r9330 (presubmit successful). |