egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame^] | 8 | #include "src/gpu/GrOpsRenderPass.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkRect.h" |
| 11 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrCaps.h" |
| 13 | #include "src/gpu/GrContextPriv.h" |
| 14 | #include "src/gpu/GrFixedClip.h" |
| 15 | #include "src/gpu/GrGpu.h" |
| 16 | #include "src/gpu/GrMesh.h" |
| 17 | #include "src/gpu/GrPrimitiveProcessor.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTargetPriv.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 20 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame^] | 21 | void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) { |
Robert Phillips | 4912d90 | 2018-04-27 12:09:35 -0400 | [diff] [blame] | 22 | SkASSERT(fRenderTarget); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 23 | // A clear at this level will always be a true clear, so make sure clears were not supposed to |
| 24 | // be redirected to draws instead |
| 25 | SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws()); |
| 26 | SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 27 | this->onClear(clip, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame^] | 30 | void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 31 | // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings |
| 32 | SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 33 | this->onClearStencilClip(clip, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame^] | 36 | bool GrOpsRenderPass::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline, |
| 37 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 38 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
| 39 | const GrMesh meshes[], int meshCount, const SkRect& bounds) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 40 | #ifdef SK_DEBUG |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 41 | SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport()); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 42 | for (int i = 0; i < meshCount; ++i) { |
Chris Dalton | b894c2b | 2017-06-14 12:39:19 -0600 | [diff] [blame] | 43 | SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) || |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 44 | this->gpu()->caps()->shaderCaps()->geometryShaderSupport()); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 45 | SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData()); |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 46 | SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData()); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 47 | } |
| 48 | #endif |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 49 | SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState || |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 50 | (dynamicStateArrays && dynamicStateArrays->fScissorRects)); |
| 51 | |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 52 | SkASSERT(!pipeline.isBad()); |
| 53 | |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 54 | #ifdef SK_DEBUG |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 55 | if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) { |
Robert Phillips | 7eeb74f | 2019-03-29 07:26:46 -0400 | [diff] [blame] | 56 | GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 57 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 58 | SkASSERT(processorProxies[i]->isInstantiated()); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) { |
| 62 | int n = primProc.numTextureSamplers() * meshCount; |
| 63 | const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures; |
| 64 | for (int i = 0; i < n; ++i) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 65 | SkASSERT(textures[i]->isInstantiated()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 66 | } |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 67 | SkASSERT(meshCount >= 1); |
| 68 | const GrTextureProxy* const* primProcProxies = |
| 69 | dynamicStateArrays->fPrimitiveProcessorTextures; |
| 70 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
| 71 | const GrBackendFormat& format = primProcProxies[i]->backendFormat(); |
| 72 | GrTextureType type = primProcProxies[i]->textureType(); |
| 73 | GrPixelConfig config = primProcProxies[i]->config(); |
| 74 | for (int j = 1; j < meshCount; ++j) { |
| 75 | const GrTextureProxy* testProxy = |
| 76 | primProcProxies[j*primProc.numTextureSamplers() + i]; |
| 77 | SkASSERT(testProxy->backendFormat() == format); |
| 78 | SkASSERT(testProxy->textureType() == type); |
| 79 | SkASSERT(testProxy->config() == config); |
| 80 | } |
| 81 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 82 | } |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 83 | #endif |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 84 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 85 | if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 86 | this->gpu()->stats()->incNumFailedDraws(); |
| 87 | return false; |
| 88 | } |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 89 | this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount, |
| 90 | bounds); |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 91 | #ifdef SK_DEBUG |
| 92 | GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures(); |
| 93 | for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) { |
| 94 | processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures(); |
| 95 | } |
| 96 | processorFeatures |= pipeline.getXferProcessor().requestedFeatures(); |
| 97 | if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) { |
| 98 | // Verify we always have the same sample pattern key, regardless of graphics state. |
| 99 | SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget) |
| 100 | == fRenderTarget->renderTargetPriv().getSamplePatternKey()); |
| 101 | } |
| 102 | #endif |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 103 | return true; |
| 104 | } |