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