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; |
| 16 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 17 | class GrProgramInfo { |
| 18 | public: |
| 19 | GrProgramInfo(int numSamples, |
| 20 | GrSurfaceOrigin origin, |
| 21 | const GrPipeline& pipeline, |
| 22 | const GrPrimitiveProcessor& primProc, |
| 23 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 24 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
| 25 | int numDynamicStateArrays) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 26 | : fNumSamples(numSamples) |
| 27 | , fOrigin(origin) |
| 28 | , fPipeline(pipeline) |
| 29 | , fPrimProc(primProc) |
| 30 | , fFixedDynamicState(fixedDynamicState) |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 31 | , fDynamicStateArrays(dynamicStateArrays) |
| 32 | , fNumDynamicStateArrays(numDynamicStateArrays) { |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 33 | fRequestedFeatures = fPrimProc.requestedFeatures(); |
| 34 | for (int i = 0; i < fPipeline.numFragmentProcessors(); ++i) { |
| 35 | fRequestedFeatures |= fPipeline.getFragmentProcessor(i).requestedFeatures(); |
| 36 | } |
| 37 | fRequestedFeatures |= fPipeline.getXferProcessor().requestedFeatures(); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 38 | |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 39 | SkDEBUGCODE(this->validate();) |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 40 | (void) fNumDynamicStateArrays; // touch this to quiet unused member warnings |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 43 | GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; } |
| 44 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 45 | int numSamples() const { return fNumSamples; } |
| 46 | GrSurfaceOrigin origin() const { return fOrigin; } |
| 47 | const GrPipeline& pipeline() const { return fPipeline; } |
| 48 | const GrPrimitiveProcessor& primProc() const { return fPrimProc; } |
| 49 | const GrPipeline::FixedDynamicState* fixedDynamicState() const { return fFixedDynamicState; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 50 | |
| 51 | // TODO: can this be removed? |
| 52 | const GrTextureProxy* const* primProcProxies() const { |
| 53 | const GrTextureProxy* const* primProcProxies = nullptr; |
| 54 | if (fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures) { |
| 55 | primProcProxies = fDynamicStateArrays->fPrimitiveProcessorTextures; |
| 56 | } else if (fFixedDynamicState) { |
| 57 | primProcProxies = fFixedDynamicState->fPrimitiveProcessorTextures; |
| 58 | } |
| 59 | |
| 60 | SkASSERT(SkToBool(primProcProxies) == SkToBool(fPrimProc.numTextureSamplers())); |
| 61 | return primProcProxies; |
| 62 | } |
| 63 | |
| 64 | bool hasDynamicScissors() const { |
| 65 | return fPipeline.isScissorEnabled() && |
| 66 | fDynamicStateArrays && fDynamicStateArrays->fScissorRects; |
| 67 | } |
| 68 | |
| 69 | const SkIRect& dynamicScissor(int i) const { |
| 70 | SkASSERT(this->hasDynamicScissors()); |
| 71 | |
| 72 | return fDynamicStateArrays->fScissorRects[i]; |
| 73 | } |
| 74 | |
| 75 | bool hasFixedScissor() const { return fPipeline.isScissorEnabled() && fFixedDynamicState; } |
| 76 | |
| 77 | const SkIRect& fixedScissor() const { |
| 78 | SkASSERT(this->hasFixedScissor()); |
| 79 | |
| 80 | return fFixedDynamicState->fScissorRect; |
| 81 | } |
| 82 | |
| 83 | bool hasDynamicPrimProcTextures() const { |
| 84 | return fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures; |
| 85 | } |
| 86 | |
| 87 | const GrTextureProxy* const* dynamicPrimProcTextures(int i) const { |
| 88 | SkASSERT(this->hasDynamicPrimProcTextures()); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 89 | SkASSERT(i < fNumDynamicStateArrays); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 90 | |
| 91 | return fDynamicStateArrays->fPrimitiveProcessorTextures + |
| 92 | i * fPrimProc.numTextureSamplers(); |
| 93 | } |
| 94 | |
| 95 | bool hasFixedPrimProcTextures() const { |
| 96 | return fFixedDynamicState && fFixedDynamicState->fPrimitiveProcessorTextures; |
| 97 | } |
| 98 | |
| 99 | const GrTextureProxy* const* fixedPrimProcTextures() const { |
| 100 | SkASSERT(this->hasFixedPrimProcTextures()); |
| 101 | |
| 102 | return fFixedDynamicState->fPrimitiveProcessorTextures; |
| 103 | } |
| 104 | |
| 105 | #ifdef SK_DEBUG |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 106 | void validate() const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 107 | void checkAllInstantiated() const; |
| 108 | void checkMSAAAndMIPSAreResolved() const; |
| 109 | void compatibleWithMeshes(const GrMesh meshes[], int meshCount) const; |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 110 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 111 | bool isNVPR() const { |
| 112 | return fPrimProc.isPathRendering() && !fPrimProc.willUseGeoShader() && |
| 113 | !fPrimProc.numVertexAttributes() && !fPrimProc.numInstanceAttributes(); |
| 114 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 115 | #endif |
| 116 | |
| 117 | private: |
| 118 | const int fNumSamples; |
| 119 | const GrSurfaceOrigin fOrigin; |
| 120 | const GrPipeline& fPipeline; |
| 121 | const GrPrimitiveProcessor& fPrimProc; |
| 122 | const GrPipeline::FixedDynamicState* fFixedDynamicState; |
| 123 | const GrPipeline::DynamicStateArrays* fDynamicStateArrays; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame^] | 124 | const int fNumDynamicStateArrays; |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 125 | GrProcessor::CustomFeatures fRequestedFeatures; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | #endif |