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" |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrGeometryProcessor.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrPipeline.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 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: |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 19 | GrProgramInfo(const GrCaps& caps, |
| 20 | const GrSurfaceProxyView& targetView, |
| 21 | bool usesMSAASurface, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 22 | const GrPipeline* pipeline, |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 23 | const GrUserStencilSettings* userStencilSettings, |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 24 | const GrGeometryProcessor* geomProc, |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 25 | GrPrimitiveType primitiveType, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 26 | uint8_t tessellationPatchVertexCount, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 27 | GrXferBarrierFlags renderPassXferBarriers, |
| 28 | GrLoadOp colorLoadOp) |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 29 | : fNeedsStencil(targetView.asRenderTargetProxy()->needsStencil()) |
Robert Phillips | 5c80964 | 2020-11-20 12:28:45 -0500 | [diff] [blame] | 30 | , fBackendFormat(targetView.proxy()->backendFormat()) |
| 31 | , fOrigin(targetView.origin()) |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 32 | , fTargetHasVkResolveAttachmentWithInput( |
| 33 | targetView.asRenderTargetProxy()->supportsVkInputAttachment() && |
| 34 | ((targetView.asRenderTargetProxy()->numSamples() > 1 && |
| 35 | targetView.asTextureProxy()) || |
| 36 | targetView.asRenderTargetProxy()->numSamples() == 1)) |
| 37 | , fTargetsNumSamples(targetView.asRenderTargetProxy()->numSamples()) |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 38 | , fPipeline(pipeline) |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 39 | , fUserStencilSettings(userStencilSettings) |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 40 | , fGeomProc(geomProc) |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 41 | , fPrimitiveType(primitiveType) |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 42 | , fTessellationPatchVertexCount(tessellationPatchVertexCount) |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 43 | , fRenderPassXferBarriers(renderPassXferBarriers) |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 44 | , fColorLoadOp(colorLoadOp) { |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 45 | SkASSERT(fTargetsNumSamples > 0); |
| 46 | fNumSamples = fTargetsNumSamples; |
| 47 | if (fNumSamples == 1 && usesMSAASurface) { |
| 48 | fNumSamples = caps.internalMultisampleCount(this->backendFormat()); |
| 49 | } |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 50 | SkASSERT((GrPrimitiveType::kPatches == fPrimitiveType) == |
| 51 | (fTessellationPatchVertexCount > 0)); |
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 | fe3dce2 | 2020-05-08 15:15:46 -0400 | [diff] [blame] | 55 | int numSamples() const { return fNumSamples; } |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 56 | int needsStencil() const { return fNeedsStencil; } |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 57 | bool isStencilEnabled() const { |
| 58 | return fUserStencilSettings != &GrUserStencilSettings::kUnused || |
| 59 | fPipeline->hasStencilClip(); |
| 60 | } |
| 61 | const GrUserStencilSettings* userStencilSettings() const { return fUserStencilSettings; } |
Robert Phillips | 933484f | 2019-11-26 09:38:55 -0500 | [diff] [blame] | 62 | // The backend format of the destination render target [proxy] |
| 63 | const GrBackendFormat& backendFormat() const { return fBackendFormat; } |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 64 | GrSurfaceOrigin origin() const { return fOrigin; } |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 65 | const GrPipeline& pipeline() const { return *fPipeline; } |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 66 | const GrGeometryProcessor& geomProc() const { return *fGeomProc; } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 67 | |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 68 | GrPrimitiveType primitiveType() const { return fPrimitiveType; } |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 69 | uint8_t tessellationPatchVertexCount() const { |
| 70 | SkASSERT(GrPrimitiveType::kPatches == fPrimitiveType); |
| 71 | return fTessellationPatchVertexCount; |
| 72 | } |
| 73 | |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 74 | bool targetHasVkResolveAttachmentWithInput() const { |
| 75 | return fTargetHasVkResolveAttachmentWithInput; |
| 76 | } |
| 77 | |
| 78 | int targetsNumSamples() const { return fTargetsNumSamples; } |
Greg Daniel | c76f7d0 | 2020-12-16 09:39:29 -0500 | [diff] [blame] | 79 | |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 80 | GrXferBarrierFlags renderPassBarriers() const { return fRenderPassXferBarriers; } |
| 81 | |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 82 | GrLoadOp colorLoadOp() const { return fColorLoadOp; } |
| 83 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 84 | uint16_t primitiveTypeKey() const { |
| 85 | return ((uint16_t)fPrimitiveType << 8) | fTessellationPatchVertexCount; |
| 86 | } |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 87 | |
Robert Phillips | a87c529 | 2019-11-12 10:12:42 -0500 | [diff] [blame] | 88 | // For Dawn, Metal and Vulkan the number of stencil bits is known a priori so we can |
| 89 | // create the stencil settings here. |
| 90 | GrStencilSettings nonGLStencilSettings() const; |
| 91 | |
Chris Dalton | be45742 | 2020-03-16 18:05:03 -0600 | [diff] [blame] | 92 | // Invokes the visitor function on all FP proxies in the pipeline. The caller is responsible |
| 93 | // to call the visitor on its own primProc proxies. |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 94 | void visitFPProxies(const GrVisitProxyFunc& func) const { fPipeline->visitProxies(func); } |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 95 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 96 | #ifdef SK_DEBUG |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 97 | void validate(bool flushTime) const; |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 98 | void checkAllInstantiated() const; |
| 99 | void checkMSAAAndMIPSAreResolved() const; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 100 | #endif |
| 101 | |
| 102 | private: |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 103 | int fNumSamples; |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 104 | bool fNeedsStencil; |
| 105 | GrBackendFormat fBackendFormat; |
| 106 | GrSurfaceOrigin fOrigin; |
Greg Daniel | 1e16937 | 2021-08-24 15:44:15 -0400 | [diff] [blame] | 107 | bool fTargetHasVkResolveAttachmentWithInput; |
| 108 | int fTargetsNumSamples; |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 109 | const GrPipeline* fPipeline; |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 110 | const GrUserStencilSettings* fUserStencilSettings; |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 111 | const GrGeometryProcessor* fGeomProc; |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 112 | GrPrimitiveType fPrimitiveType; |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 113 | uint8_t fTessellationPatchVertexCount; // GrPrimType::kPatches. |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 114 | GrXferBarrierFlags fRenderPassXferBarriers; |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 115 | GrLoadOp fColorLoadOp; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | #endif |