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 | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 15 | class GrStencilSettings; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 16 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 17 | class GrProgramInfo { |
| 18 | public: |
Robert Phillips | 5c80964 | 2020-11-20 12:28:45 -0500 | [diff] [blame] | 19 | GrProgramInfo(const GrSurfaceProxyView& targetView, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 20 | const GrPipeline* pipeline, |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 21 | const GrUserStencilSettings* userStencilSettings, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 22 | const GrPrimitiveProcessor* primProc, |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 23 | GrPrimitiveType primitiveType, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 24 | uint8_t tessellationPatchVertexCount, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 25 | GrXferBarrierFlags renderPassXferBarriers, |
| 26 | GrLoadOp colorLoadOp) |
Robert Phillips | 5c80964 | 2020-11-20 12:28:45 -0500 | [diff] [blame] | 27 | : fNumSamples(targetView.asRenderTargetProxy()->numSamples()) |
| 28 | , fNumStencilSamples(targetView.asRenderTargetProxy()->numStencilSamples()) |
| 29 | , fBackendFormat(targetView.proxy()->backendFormat()) |
| 30 | , fOrigin(targetView.origin()) |
Greg Daniel | c76f7d0 | 2020-12-16 09:39:29 -0500 | [diff] [blame^] | 31 | , fTargetSupportsVkResolveLoad( |
| 32 | targetView.asRenderTargetProxy()->numSamples() && |
| 33 | targetView.asTextureProxy() && |
| 34 | targetView.asRenderTargetProxy()->supportsVkInputAttachment()) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 35 | , fPipeline(pipeline) |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 36 | , fUserStencilSettings(userStencilSettings) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 37 | , fPrimProc(primProc) |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 38 | , fPrimitiveType(primitiveType) |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 39 | , fTessellationPatchVertexCount(tessellationPatchVertexCount) |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 40 | , fRenderPassXferBarriers(renderPassXferBarriers) |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 41 | , fColorLoadOp(colorLoadOp) |
Robert Phillips | 5c80964 | 2020-11-20 12:28:45 -0500 | [diff] [blame] | 42 | , fIsMixedSampled(this->isStencilEnabled() && fNumStencilSamples > fNumSamples) { |
Robert Phillips | fe3dce2 | 2020-05-08 15:15:46 -0400 | [diff] [blame] | 43 | SkASSERT(this->numRasterSamples() > 0); |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 44 | SkASSERT((GrPrimitiveType::kPatches == fPrimitiveType) == |
| 45 | (fTessellationPatchVertexCount > 0)); |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 46 | fRequestedFeatures = fPrimProc->requestedFeatures(); |
| 47 | for (int i = 0; i < fPipeline->numFragmentProcessors(); ++i) { |
| 48 | fRequestedFeatures |= fPipeline->getFragmentProcessor(i).requestedFeatures(); |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 49 | } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 50 | fRequestedFeatures |= fPipeline->getXferProcessor().requestedFeatures(); |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 51 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 52 | SkDEBUGCODE(this->validate(false);) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 55 | GrProcessor::CustomFeatures requestedFeatures() const { return fRequestedFeatures; } |
| 56 | |
Robert Phillips | fe3dce2 | 2020-05-08 15:15:46 -0400 | [diff] [blame] | 57 | int numSamples() const { return fNumSamples; } |
| 58 | int numStencilSamples() const { return fNumStencilSamples; } |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 59 | bool isStencilEnabled() const { |
| 60 | return fUserStencilSettings != &GrUserStencilSettings::kUnused || |
| 61 | fPipeline->hasStencilClip(); |
| 62 | } |
| 63 | const GrUserStencilSettings* userStencilSettings() const { return fUserStencilSettings; } |
Robert Phillips | fe3dce2 | 2020-05-08 15:15:46 -0400 | [diff] [blame] | 64 | int numRasterSamples() const { |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 65 | return this->isStencilEnabled() ? fNumStencilSamples : fNumSamples; |
Robert Phillips | fe3dce2 | 2020-05-08 15:15:46 -0400 | [diff] [blame] | 66 | } |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 67 | bool isMixedSampled() const { return fIsMixedSampled; } |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 68 | // The backend format of the destination render target [proxy] |
| 69 | const GrBackendFormat& backendFormat() const { return fBackendFormat; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 70 | GrSurfaceOrigin origin() const { return fOrigin; } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 71 | const GrPipeline& pipeline() const { return *fPipeline; } |
| 72 | const GrPrimitiveProcessor& primProc() const { return *fPrimProc; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 73 | |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 74 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 75 | uint8_t tessellationPatchVertexCount() const { |
| 76 | SkASSERT(GrPrimitiveType::kPatches == fPrimitiveType); |
| 77 | return fTessellationPatchVertexCount; |
| 78 | } |
| 79 | |
Greg Daniel | c76f7d0 | 2020-12-16 09:39:29 -0500 | [diff] [blame^] | 80 | bool targetSupportsVkResolveLoad() const { return fTargetSupportsVkResolveLoad; } |
| 81 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 82 | GrXferBarrierFlags renderPassBarriers() const { return fRenderPassXferBarriers; } |
| 83 | |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 84 | GrLoadOp colorLoadOp() const { return fColorLoadOp; } |
| 85 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 86 | uint16_t primitiveTypeKey() const { |
| 87 | return ((uint16_t)fPrimitiveType << 8) | fTessellationPatchVertexCount; |
| 88 | } |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 89 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 90 | // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can |
| 91 | // create the stencil settings here. |
| 92 | GrStencilSettings nonGLStencilSettings() const; |
| 93 | |
Chris Dalton | be45742 | 2020-03-16 18:05:03 -0600 | [diff] [blame] | 94 | // Invokes the visitor function on all FP proxies in the pipeline. The caller is responsible |
| 95 | // to call the visitor on its own primProc proxies. |
| 96 | void visitFPProxies(const GrOp::VisitProxyFunc& func) const { fPipeline->visitProxies(func); } |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 97 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 98 | #ifdef SK_DEBUG |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 99 | void validate(bool flushTime) const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 100 | void checkAllInstantiated() const; |
| 101 | void checkMSAAAndMIPSAreResolved() const; |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 102 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 103 | bool isNVPR() const { |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 104 | return fPrimProc->isPathRendering() && !fPrimProc->willUseGeoShader() && |
| 105 | !fPrimProc->numVertexAttributes() && !fPrimProc->numInstanceAttributes(); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 106 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 107 | #endif |
| 108 | |
| 109 | private: |
Robert Phillips | fe3dce2 | 2020-05-08 15:15:46 -0400 | [diff] [blame] | 110 | const int fNumSamples; |
| 111 | const int fNumStencilSamples; |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 112 | const GrBackendFormat fBackendFormat; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 113 | const GrSurfaceOrigin fOrigin; |
Greg Daniel | c76f7d0 | 2020-12-16 09:39:29 -0500 | [diff] [blame^] | 114 | const bool fTargetSupportsVkResolveLoad; |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 115 | const GrPipeline* fPipeline; |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 116 | const GrUserStencilSettings* fUserStencilSettings; |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 117 | const GrPrimitiveProcessor* fPrimProc; |
Robert Phillips | 7de1333 | 2019-10-09 15:44:54 -0400 | [diff] [blame] | 118 | GrProcessor::CustomFeatures fRequestedFeatures; |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 119 | GrPrimitiveType fPrimitiveType; |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 120 | uint8_t fTessellationPatchVertexCount; // GrPrimType::kPatches. |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 121 | GrXferBarrierFlags fRenderPassXferBarriers; |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 122 | GrLoadOp fColorLoadOp; |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 123 | const bool fIsMixedSampled; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | #endif |