Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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 | #ifndef GrProgramInfo_DEFINED |
| 9 | #define GrProgramInfo_DEFINED |
| 10 | |
| 11 | #include "include/gpu/GrTypes.h" |
| 12 | #include "src/gpu/GrPipeline.h" |
| 13 | #include "src/gpu/GrPrimitiveProcessor.h" |
| 14 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 15 | class GrMesh; |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 16 | class GrStencilSettings; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 17 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 18 | class GrProgramInfo { |
| 19 | public: |
| 20 | GrProgramInfo(int numSamples, |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 21 | int numStencilSamples, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 22 | GrSurfaceOrigin origin, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 23 | const GrPipeline* pipeline, |
| 24 | const GrPrimitiveProcessor* primProc, |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 25 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 26 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 27 | int numDynamicStateArrays, |
| 28 | GrPrimitiveType primitiveType) |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 29 | : fNumRasterSamples(pipeline->isStencilEnabled() ? numStencilSamples : numSamples) |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 30 | , fIsMixedSampled(fNumRasterSamples > numSamples) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 31 | , fOrigin(origin) |
| 32 | , fPipeline(pipeline) |
| 33 | , fPrimProc(primProc) |
| 34 | , fFixedDynamicState(fixedDynamicState) |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 35 | , fDynamicStateArrays(dynamicStateArrays) |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 36 | , fNumDynamicStateArrays(numDynamicStateArrays) |
| 37 | , fPrimitiveType(primitiveType) { |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 38 | SkASSERT(fNumRasterSamples > 0); |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 39 | fRequestedFeatures = fPrimProc->requestedFeatures(); |
| 40 | for (int i = 0; i < fPipeline->numFragmentProcessors(); ++i) { |
| 41 | fRequestedFeatures |= fPipeline->getFragmentProcessor(i).requestedFeatures(); |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 42 | } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 43 | fRequestedFeatures |= fPipeline->getXferProcessor().requestedFeatures(); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 44 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame^] | 45 | SkDEBUGCODE(this->validate(false);) |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 46 | (void) fNumDynamicStateArrays; // touch this to quiet unused member warnings |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 49 | GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; } |
| 50 | |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 51 | int numRasterSamples() const { return fNumRasterSamples; } |
| 52 | bool isMixedSampled() const { return fIsMixedSampled; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 53 | GrSurfaceOrigin origin() const { return fOrigin; } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 54 | const GrPipeline& pipeline() const { return *fPipeline; } |
| 55 | const GrPrimitiveProcessor& primProc() const { return *fPrimProc; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 56 | const GrPipeline::FixedDynamicState* fixedDynamicState() const { return fFixedDynamicState; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 57 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 58 | bool hasDynamicScissors() const { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 59 | return fPipeline->isScissorEnabled() && |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 60 | fDynamicStateArrays && fDynamicStateArrays->fScissorRects; |
| 61 | } |
| 62 | |
| 63 | const SkIRect& dynamicScissor(int i) const { |
| 64 | SkASSERT(this->hasDynamicScissors()); |
| 65 | |
| 66 | return fDynamicStateArrays->fScissorRects[i]; |
| 67 | } |
| 68 | |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 69 | bool hasFixedScissor() const { return fPipeline->isScissorEnabled() && fFixedDynamicState; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 70 | |
| 71 | const SkIRect& fixedScissor() const { |
| 72 | SkASSERT(this->hasFixedScissor()); |
| 73 | |
| 74 | return fFixedDynamicState->fScissorRect; |
| 75 | } |
| 76 | |
| 77 | bool hasDynamicPrimProcTextures() const { |
| 78 | return fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures; |
| 79 | } |
| 80 | |
| 81 | const GrTextureProxy* const* dynamicPrimProcTextures(int i) const { |
| 82 | SkASSERT(this->hasDynamicPrimProcTextures()); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 83 | SkASSERT(i < fNumDynamicStateArrays); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 84 | |
| 85 | return fDynamicStateArrays->fPrimitiveProcessorTextures + |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 86 | i * fPrimProc->numTextureSamplers(); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | bool hasFixedPrimProcTextures() const { |
| 90 | return fFixedDynamicState && fFixedDynamicState->fPrimitiveProcessorTextures; |
| 91 | } |
| 92 | |
| 93 | const GrTextureProxy* const* fixedPrimProcTextures() const { |
| 94 | SkASSERT(this->hasFixedPrimProcTextures()); |
| 95 | |
| 96 | return fFixedDynamicState->fPrimitiveProcessorTextures; |
| 97 | } |
| 98 | |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 99 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
| 100 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 101 | // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can |
| 102 | // create the stencil settings here. |
| 103 | GrStencilSettings nonGLStencilSettings() const; |
| 104 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame^] | 105 | void visitProxies(const GrOp::VisitProxyFunc& fn) const { |
| 106 | fPipeline->visitProxies(fn); |
| 107 | } |
| 108 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 109 | #ifdef SK_DEBUG |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame^] | 110 | void validate(bool flushTime) const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 111 | void checkAllInstantiated() const; |
| 112 | void checkMSAAAndMIPSAreResolved() const; |
| 113 | void compatibleWithMeshes(const GrMesh meshes[], int meshCount) const; |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 114 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 115 | bool isNVPR() const { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 116 | return fPrimProc->isPathRendering() && !fPrimProc->willUseGeoShader() && |
| 117 | !fPrimProc->numVertexAttributes() && !fPrimProc->numInstanceAttributes(); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 118 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | private: |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 122 | const int fNumRasterSamples; |
| 123 | const bool fIsMixedSampled; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 124 | const GrSurfaceOrigin fOrigin; |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 125 | const GrPipeline* fPipeline; |
| 126 | const GrPrimitiveProcessor* fPrimProc; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 127 | const GrPipeline::FixedDynamicState* fFixedDynamicState; |
| 128 | const GrPipeline::DynamicStateArrays* fDynamicStateArrays; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 129 | const int fNumDynamicStateArrays; |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 130 | GrProcessor::CustomFeatures fRequestedFeatures; |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 131 | GrPrimitiveType fPrimitiveType; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | #endif |