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