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" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame^] | 20 | #include "src/gpu/GrTexturePriv.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 21 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 22 | void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) { |
Robert Phillips | 4912d90 | 2018-04-27 12:09:35 -0400 | [diff] [blame] | 23 | SkASSERT(fRenderTarget); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 24 | // A clear at this level will always be a true clear, so make sure clears were not supposed to |
| 25 | // be redirected to draws instead |
| 26 | SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws()); |
| 27 | SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 28 | this->onClear(clip, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 31 | void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 32 | // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings |
| 33 | SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 34 | this->onClearStencilClip(clip, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame^] | 37 | #ifdef SK_DEBUG |
| 38 | static void assert_msaa_and_mips_are_resolved( |
| 39 | const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline, |
| 40 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 41 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, int meshCount) { |
| 42 | auto assertResolved = [](GrTexture* tex, const GrSamplerState& sampler) { |
| 43 | SkASSERT(tex); |
| 44 | |
| 45 | // Ensure msaa was resolved ahead of time by the DAG. |
| 46 | SkASSERT(!tex->asRenderTarget() || !tex->asRenderTarget()->needsResolve()); |
| 47 | |
| 48 | // Ensure mipmaps were all resolved ahead of time by the DAG. |
| 49 | if (GrSamplerState::Filter::kMipMap == sampler.filter() && |
| 50 | (tex->width() != 1 || tex->height() != 1)) { |
| 51 | // There are some cases where we might be given a non-mipmapped texture with a mipmap |
| 52 | // filter. See skbug.com/7094. |
| 53 | SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes || |
| 54 | !tex->texturePriv().mipMapsAreDirty()); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) { |
| 59 | for (int m = 0, i = 0; m < meshCount; ++m) { |
| 60 | for (int s = 0; s < primProc.numTextureSamplers(); ++s, ++i) { |
| 61 | auto* tex = dynamicStateArrays->fPrimitiveProcessorTextures[i]->peekTexture(); |
| 62 | assertResolved(tex, primProc.textureSampler(s).samplerState()); |
| 63 | } |
| 64 | } |
| 65 | } else { |
| 66 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
| 67 | auto* tex = fixedDynamicState->fPrimitiveProcessorTextures[i]->peekTexture(); |
| 68 | assertResolved(tex, primProc.textureSampler(i).samplerState()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | GrFragmentProcessor::Iter iter(pipeline); |
| 73 | while (const GrFragmentProcessor* fp = iter.next()) { |
| 74 | for (int i = 0; i < fp->numTextureSamplers(); ++i) { |
| 75 | const auto& textureSampler = fp->textureSampler(i); |
| 76 | assertResolved(textureSampler.peekTexture(), textureSampler.samplerState()); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | #endif |
| 81 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 82 | bool GrOpsRenderPass::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline, |
| 83 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 84 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
| 85 | const GrMesh meshes[], int meshCount, const SkRect& bounds) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 86 | #ifdef SK_DEBUG |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 87 | SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport()); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 88 | for (int i = 0; i < meshCount; ++i) { |
Chris Dalton | b894c2b | 2017-06-14 12:39:19 -0600 | [diff] [blame] | 89 | SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) || |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 90 | this->gpu()->caps()->shaderCaps()->geometryShaderSupport()); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 91 | SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData()); |
Chris Dalton | 906430d | 2019-02-27 18:16:59 -0700 | [diff] [blame] | 92 | SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData()); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 93 | } |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame^] | 94 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 95 | SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState || |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 96 | (dynamicStateArrays && dynamicStateArrays->fScissorRects)); |
| 97 | |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 98 | SkASSERT(!pipeline.isBad()); |
| 99 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 100 | if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) { |
Robert Phillips | 7eeb74f | 2019-03-29 07:26:46 -0400 | [diff] [blame] | 101 | GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 102 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 103 | SkASSERT(processorProxies[i]->isInstantiated()); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) { |
| 107 | int n = primProc.numTextureSamplers() * meshCount; |
| 108 | const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures; |
| 109 | for (int i = 0; i < n; ++i) { |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 110 | SkASSERT(textures[i]->isInstantiated()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 111 | } |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 112 | SkASSERT(meshCount >= 1); |
| 113 | const GrTextureProxy* const* primProcProxies = |
| 114 | dynamicStateArrays->fPrimitiveProcessorTextures; |
| 115 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
| 116 | const GrBackendFormat& format = primProcProxies[i]->backendFormat(); |
| 117 | GrTextureType type = primProcProxies[i]->textureType(); |
| 118 | GrPixelConfig config = primProcProxies[i]->config(); |
| 119 | for (int j = 1; j < meshCount; ++j) { |
| 120 | const GrTextureProxy* testProxy = |
| 121 | primProcProxies[j*primProc.numTextureSamplers() + i]; |
| 122 | SkASSERT(testProxy->backendFormat() == format); |
| 123 | SkASSERT(testProxy->textureType() == type); |
| 124 | SkASSERT(testProxy->config() == config); |
| 125 | } |
| 126 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 127 | } |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame^] | 128 | |
| 129 | assert_msaa_and_mips_are_resolved( |
| 130 | primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshCount); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 131 | #endif |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 132 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 133 | if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 134 | this->gpu()->stats()->incNumFailedDraws(); |
| 135 | return false; |
| 136 | } |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 137 | this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount, |
| 138 | bounds); |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 139 | #ifdef SK_DEBUG |
| 140 | GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures(); |
| 141 | for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) { |
| 142 | processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures(); |
| 143 | } |
| 144 | processorFeatures |= pipeline.getXferProcessor().requestedFeatures(); |
| 145 | if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) { |
| 146 | // Verify we always have the same sample pattern key, regardless of graphics state. |
| 147 | SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget) |
| 148 | == fRenderTarget->renderTargetPriv().getSamplePatternKey()); |
| 149 | } |
| 150 | #endif |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 151 | return true; |
| 152 | } |