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