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 | |
| 8 | #include "GrGpuCommandBuffer.h" |
| 9 | |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 10 | #include "GrContext.h" |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 12 | #include "GrFixedClip.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 13 | #include "GrGpu.h" |
Brian Salomon | 2a55c8e | 2017-05-09 09:57:19 -0400 | [diff] [blame] | 14 | #include "GrMesh.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 15 | #include "GrPrimitiveProcessor.h" |
| 16 | #include "GrRenderTarget.h" |
| 17 | #include "SkRect.h" |
| 18 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 19 | void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) { |
Robert Phillips | 4912d90 | 2018-04-27 12:09:35 -0400 | [diff] [blame] | 20 | SkASSERT(fRenderTarget); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 21 | // A clear at this level will always be a true clear, so make sure clears were not supposed to |
| 22 | // be redirected to draws instead |
| 23 | SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws()); |
| 24 | SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 25 | this->onClear(clip, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 28 | void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 29 | // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings |
| 30 | SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 31 | this->onClearStencilClip(clip, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 34 | bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline, |
| 35 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 36 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
| 37 | const GrMesh meshes[], int meshCount, const SkRect& bounds) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 38 | #ifdef SK_DEBUG |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 39 | SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport()); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 40 | for (int i = 0; i < meshCount; ++i) { |
Chris Dalton | b894c2b | 2017-06-14 12:39:19 -0600 | [diff] [blame] | 41 | SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) || |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 42 | this->gpu()->caps()->shaderCaps()->geometryShaderSupport()); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 43 | SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData()); |
| 44 | SkASSERT(primProc.hasInstanceAttributes() == meshes[i].isInstanced()); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 45 | } |
| 46 | #endif |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 47 | SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState || |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 48 | (dynamicStateArrays && dynamicStateArrays->fScissorRects)); |
| 49 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 50 | auto resourceProvider = this->gpu()->getContext()->priv().resourceProvider(); |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 51 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 52 | if (pipeline.isBad()) { |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 53 | return false; |
| 54 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 55 | if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) { |
| 56 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
| 57 | if (!fixedDynamicState->fPrimitiveProcessorTextures[i]->instantiate(resourceProvider)) { |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) { |
| 63 | int n = primProc.numTextureSamplers() * meshCount; |
| 64 | const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures; |
| 65 | for (int i = 0; i < n; ++i) { |
| 66 | if (!textures[i]->instantiate(resourceProvider)) { |
| 67 | return false; |
| 68 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 69 | } |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 70 | #ifdef SK_DEBUG |
| 71 | SkASSERT(meshCount >= 1); |
| 72 | const GrTextureProxy* const* primProcProxies = |
| 73 | dynamicStateArrays->fPrimitiveProcessorTextures; |
| 74 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
| 75 | const GrBackendFormat& format = primProcProxies[i]->backendFormat(); |
| 76 | GrTextureType type = primProcProxies[i]->textureType(); |
| 77 | GrPixelConfig config = primProcProxies[i]->config(); |
| 78 | for (int j = 1; j < meshCount; ++j) { |
| 79 | const GrTextureProxy* testProxy = |
| 80 | primProcProxies[j*primProc.numTextureSamplers() + i]; |
| 81 | SkASSERT(testProxy->backendFormat() == format); |
| 82 | SkASSERT(testProxy->textureType() == type); |
| 83 | SkASSERT(testProxy->config() == config); |
| 84 | } |
| 85 | } |
| 86 | #endif |
| 87 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 88 | } |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 89 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 90 | if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 91 | this->gpu()->stats()->incNumFailedDraws(); |
| 92 | return false; |
| 93 | } |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 94 | this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount, |
| 95 | bounds); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 96 | return true; |
| 97 | } |