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 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 51 | bool hasDynamicScissors() const { |
| 52 | return fPipeline.isScissorEnabled() && |
| 53 | fDynamicStateArrays && fDynamicStateArrays->fScissorRects; |
| 54 | } |
| 55 | |
| 56 | const SkIRect& dynamicScissor(int i) const { |
| 57 | SkASSERT(this->hasDynamicScissors()); |
| 58 | |
| 59 | return fDynamicStateArrays->fScissorRects[i]; |
| 60 | } |
| 61 | |
| 62 | bool hasFixedScissor() const { return fPipeline.isScissorEnabled() && fFixedDynamicState; } |
| 63 | |
| 64 | const SkIRect& fixedScissor() const { |
| 65 | SkASSERT(this->hasFixedScissor()); |
| 66 | |
| 67 | return fFixedDynamicState->fScissorRect; |
| 68 | } |
| 69 | |
| 70 | bool hasDynamicPrimProcTextures() const { |
| 71 | return fDynamicStateArrays && fDynamicStateArrays->fPrimitiveProcessorTextures; |
| 72 | } |
| 73 | |
| 74 | const GrTextureProxy* const* dynamicPrimProcTextures(int i) const { |
| 75 | SkASSERT(this->hasDynamicPrimProcTextures()); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 76 | SkASSERT(i < fNumDynamicStateArrays); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 77 | |
| 78 | return fDynamicStateArrays->fPrimitiveProcessorTextures + |
| 79 | i * fPrimProc.numTextureSamplers(); |
| 80 | } |
| 81 | |
| 82 | bool hasFixedPrimProcTextures() const { |
| 83 | return fFixedDynamicState && fFixedDynamicState->fPrimitiveProcessorTextures; |
| 84 | } |
| 85 | |
| 86 | const GrTextureProxy* const* fixedPrimProcTextures() const { |
| 87 | SkASSERT(this->hasFixedPrimProcTextures()); |
| 88 | |
| 89 | return fFixedDynamicState->fPrimitiveProcessorTextures; |
| 90 | } |
| 91 | |
| 92 | #ifdef SK_DEBUG |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 93 | void validate() const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 94 | void checkAllInstantiated() const; |
| 95 | void checkMSAAAndMIPSAreResolved() const; |
| 96 | void compatibleWithMeshes(const GrMesh meshes[], int meshCount) const; |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 97 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 98 | bool isNVPR() const { |
| 99 | return fPrimProc.isPathRendering() && !fPrimProc.willUseGeoShader() && |
| 100 | !fPrimProc.numVertexAttributes() && !fPrimProc.numInstanceAttributes(); |
| 101 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 102 | #endif |
| 103 | |
| 104 | private: |
| 105 | const int fNumSamples; |
| 106 | const GrSurfaceOrigin fOrigin; |
| 107 | const GrPipeline& fPipeline; |
| 108 | const GrPrimitiveProcessor& fPrimProc; |
| 109 | const GrPipeline::FixedDynamicState* fFixedDynamicState; |
| 110 | const GrPipeline::DynamicStateArrays* fDynamicStateArrays; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 111 | const int fNumDynamicStateArrays; |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 112 | GrProcessor::CustomFeatures fRequestedFeatures; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | #endif |