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