xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrProgramInfo.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include "src/gpu/ganesh/GrProgramInfo.h"
8 
9 #include "include/gpu/GpuTypes.h"
10 #include "include/private/base/SkAssert.h"
11 #include "src/gpu/ganesh/GrCaps.h"
12 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
13 #include "src/gpu/ganesh/GrSamplerState.h"
14 #include "src/gpu/ganesh/GrStencilSettings.h"
15 #include "src/gpu/ganesh/GrSurfaceProxy.h"
16 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
17 #include "src/gpu/ganesh/GrTexture.h"
18 #include "src/gpu/ganesh/effects/GrTextureEffect.h"
19 
20 #include <functional>
21 
22 class GrGeometryProcessor;
23 enum class GrXferBarrierFlags;
24 
GrProgramInfo(const GrCaps & caps,const GrSurfaceProxyView & targetView,bool usesMSAASurface,const GrPipeline * pipeline,const GrUserStencilSettings * userStencilSettings,const GrGeometryProcessor * geomProc,GrPrimitiveType primitiveType,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)25 GrProgramInfo::GrProgramInfo(const GrCaps& caps,
26                              const GrSurfaceProxyView& targetView,
27                              bool usesMSAASurface,
28                              const GrPipeline* pipeline,
29                              const GrUserStencilSettings* userStencilSettings,
30                              const GrGeometryProcessor* geomProc,
31                              GrPrimitiveType primitiveType,
32                              GrXferBarrierFlags renderPassXferBarriers,
33                              GrLoadOp colorLoadOp)
34         : fNeedsStencil(targetView.asRenderTargetProxy()->needsStencil())
35         , fBackendFormat(targetView.proxy()->backendFormat())
36         , fOrigin(targetView.origin())
37         , fTargetHasVkResolveAttachmentWithInput(
38                   targetView.asRenderTargetProxy()->supportsVkInputAttachment() &&
39                   ((targetView.asRenderTargetProxy()->numSamples() > 1 &&
40                     targetView.asTextureProxy()) ||
41                    targetView.asRenderTargetProxy()->numSamples() == 1))
42         , fTargetsNumSamples(targetView.asRenderTargetProxy()->numSamples())
43         , fPipeline(pipeline)
44         , fUserStencilSettings(userStencilSettings)
45         , fGeomProc(geomProc)
46         , fPrimitiveType(primitiveType)
47         , fRenderPassXferBarriers(renderPassXferBarriers)
48         , fColorLoadOp(colorLoadOp) {
49     SkASSERT(fTargetsNumSamples > 0);
50     fNumSamples = fTargetsNumSamples;
51     if (fNumSamples == 1 && usesMSAASurface) {
52         fNumSamples = caps.internalMultisampleCount(this->backendFormat());
53     }
54     SkDEBUGCODE(this->validate(false);)
55 }
56 
nonGLStencilSettings() const57 GrStencilSettings GrProgramInfo::nonGLStencilSettings() const {
58     GrStencilSettings stencil;
59 
60     if (this->isStencilEnabled()) {
61         stencil.reset(*fUserStencilSettings, this->pipeline().hasStencilClip(), 8);
62     }
63 
64     return stencil;
65 }
66 
67 #ifdef SK_DEBUG
68 
validate(bool flushTime) const69 void GrProgramInfo::validate(bool flushTime) const {
70     if (flushTime) {
71         SkASSERT(fPipeline->allProxiesInstantiated());
72     }
73 }
74 
checkAllInstantiated() const75 void GrProgramInfo::checkAllInstantiated() const {
76     this->pipeline().visitProxies([](GrSurfaceProxy* proxy, skgpu::Mipmapped) {
77         SkASSERT(proxy->isInstantiated());
78         return true;
79     });
80 }
81 
checkMSAAAndMIPSAreResolved() const82 void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
83     this->pipeline().visitTextureEffects([](const GrTextureEffect& te) {
84         GrTexture* tex = te.texture();
85         SkASSERT(tex);
86 
87         // Ensure mipmaps were all resolved ahead of time by the DAG.
88         if (te.samplerState().mipmapped() == skgpu::Mipmapped::kYes &&
89             (tex->width() != 1 || tex->height() != 1)) {
90             // There are some cases where we might be given a non-mipmapped texture with a
91             // mipmap filter. See skbug.com/7094.
92             SkASSERT(tex->mipmapped() != skgpu::Mipmapped::kYes || !tex->mipmapsAreDirty());
93         }
94     });
95 }
96 
97 #endif
98