blob: a80b088a0f1786dcd4b9fbc5c33bfb3640fb6b1b [file] [log] [blame]
egdaniel9cb63402016-06-23 08:37:05 -07001/*
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
robertphillips28a838e2016-06-23 14:07:00 -070010#include "GrCaps.h"
Robert Phillipsbe9aff22019-02-15 11:33:22 -050011#include "GrContext.h"
12#include "GrContextPriv.h"
csmartdalton29df7602016-08-31 11:55:52 -070013#include "GrFixedClip.h"
egdaniel9cb63402016-06-23 08:37:05 -070014#include "GrGpu.h"
Brian Salomon2a55c8e2017-05-09 09:57:19 -040015#include "GrMesh.h"
egdaniel9cb63402016-06-23 08:37:05 -070016#include "GrPrimitiveProcessor.h"
17#include "GrRenderTarget.h"
Chris Dalton8c4cafd2019-04-15 19:14:36 -060018#include "GrRenderTargetPriv.h"
egdaniel9cb63402016-06-23 08:37:05 -070019#include "SkRect.h"
20
Brian Osman9a9baae2018-11-05 15:06:26 -050021void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
Robert Phillips4912d902018-04-27 12:09:35 -040022 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050023 // 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 Phillips19e51dc2017-08-09 09:30:51 -040027 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070028}
29
Greg Daniel500d58b2017-08-24 15:59:33 -040030void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050031 // 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 Phillips19e51dc2017-08-09 09:30:51 -040033 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070034}
35
Brian Salomon49348902018-06-26 09:12:38 -040036bool GrGpuRTCommandBuffer::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 Daltonbca46e22017-05-15 11:03:26 -060040#ifdef SK_DEBUG
Brian Salomon92be2f72018-06-19 14:33:47 -040041 SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
Chris Daltonbca46e22017-05-15 11:03:26 -060042 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060043 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060044 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Brian Salomon92be2f72018-06-19 14:33:47 -040045 SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
Chris Dalton906430d2019-02-27 18:16:59 -070046 SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData());
Chris Daltonbca46e22017-05-15 11:03:26 -060047 }
48#endif
Brian Salomond818ebf2018-07-02 14:08:49 +000049 SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
Brian Salomon49348902018-06-26 09:12:38 -040050 (dynamicStateArrays && dynamicStateArrays->fScissorRects));
51
Robert Phillips9da87e02019-02-04 13:26:26 -050052 auto resourceProvider = this->gpu()->getContext()->priv().resourceProvider();
Chris Daltonbca46e22017-05-15 11:03:26 -060053
Brian Salomon7eae3e02018-08-07 14:02:38 +000054 if (pipeline.isBad()) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040055 return false;
56 }
Brian Salomonf7232642018-09-19 08:58:08 -040057 if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
Robert Phillips7eeb74f2019-03-29 07:26:46 -040058 GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures;
Brian Salomonf7232642018-09-19 08:58:08 -040059 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
Robert Phillips7eeb74f2019-03-29 07:26:46 -040060 if (resourceProvider->explicitlyAllocateGPUResources()) {
61 SkASSERT(processorProxies[i]->isInstantiated());
62 } else if (!processorProxies[i]->instantiate(resourceProvider)) {
Brian Salomonf7232642018-09-19 08:58:08 -040063 return false;
64 }
65 }
66 }
67 if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) {
68 int n = primProc.numTextureSamplers() * meshCount;
69 const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
70 for (int i = 0; i < n; ++i) {
Robert Phillips7eeb74f2019-03-29 07:26:46 -040071 if (resourceProvider->explicitlyAllocateGPUResources()) {
72 SkASSERT(textures[i]->isInstantiated());
73 } else if (!textures[i]->instantiate(resourceProvider)) {
Brian Salomonf7232642018-09-19 08:58:08 -040074 return false;
75 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000076 }
Greg Daniel9a51a862018-11-30 10:18:14 -050077#ifdef SK_DEBUG
78 SkASSERT(meshCount >= 1);
79 const GrTextureProxy* const* primProcProxies =
80 dynamicStateArrays->fPrimitiveProcessorTextures;
81 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
82 const GrBackendFormat& format = primProcProxies[i]->backendFormat();
83 GrTextureType type = primProcProxies[i]->textureType();
84 GrPixelConfig config = primProcProxies[i]->config();
85 for (int j = 1; j < meshCount; ++j) {
86 const GrTextureProxy* testProxy =
87 primProcProxies[j*primProc.numTextureSamplers() + i];
88 SkASSERT(testProxy->backendFormat() == format);
89 SkASSERT(testProxy->textureType() == type);
90 SkASSERT(testProxy->config() == config);
91 }
92 }
93#endif
94
Brian Salomon7eae3e02018-08-07 14:02:38 +000095 }
Robert Phillipsa91e0b72017-05-01 13:12:20 -040096
Brian Salomon92be2f72018-06-19 14:33:47 -040097 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070098 this->gpu()->stats()->incNumFailedDraws();
99 return false;
100 }
Brian Salomon49348902018-06-26 09:12:38 -0400101 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
102 bounds);
Chris Dalton8c4cafd2019-04-15 19:14:36 -0600103#ifdef SK_DEBUG
104 GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures();
105 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
106 processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures();
107 }
108 processorFeatures |= pipeline.getXferProcessor().requestedFeatures();
109 if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
110 // Verify we always have the same sample pattern key, regardless of graphics state.
111 SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
112 == fRenderTarget->renderTargetPriv().getSamplePatternKey());
113 }
114#endif
egdaniel9cb63402016-06-23 08:37:05 -0700115 return true;
116}