• 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/GrProgramInfo.h"
9 
10 #include "src/gpu/GrStencilSettings.h"
11 
nonGLStencilSettings() const12 GrStencilSettings GrProgramInfo::nonGLStencilSettings() const {
13     GrStencilSettings stencil;
14 
15     if (this->pipeline().isStencilEnabled()) {
16         stencil.reset(*this->pipeline().getUserStencil(),
17                       this->pipeline().hasStencilClip(),
18                       8);
19     }
20 
21     return stencil;
22 }
23 
24 #ifdef SK_DEBUG
25 #include "src/gpu/GrMesh.h"
26 #include "src/gpu/GrTexturePriv.h"
27 
validate(bool flushTime) const28 void GrProgramInfo::validate(bool flushTime) const {
29     if (flushTime) {
30         SkASSERT(fPipeline->allProxiesInstantiated());
31     }
32 
33     if (this->hasDynamicPrimProcTextures()) {
34         SkASSERT(!this->hasFixedPrimProcTextures());
35         SkASSERT(fPrimProc->numTextureSamplers());
36     } else if (this->hasFixedPrimProcTextures()) {
37         SkASSERT(fPrimProc->numTextureSamplers());
38     } else {
39         SkASSERT(!fPrimProc->numTextureSamplers());
40     }
41 
42     SkASSERT(!fPipeline->isScissorEnabled() || this->hasFixedScissor() ||
43              this->hasDynamicScissors());
44 
45     if (this->hasDynamicPrimProcTextures()) {
46         // Check that, for a given sampler, the properties of the dynamic textures remain
47         // the same for all the meshes
48         for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
49             auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0);
50 
51             const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat();
52             GrTextureType type = dynamicPrimProcTextures[s]->backendFormat().textureType();
53 
54             for (int m = 1; m < fNumDynamicStateArrays; ++m) {
55                 dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
56 
57                 auto testProxy = dynamicPrimProcTextures[s];
58                 SkASSERT(testProxy->asTextureProxy());
59                 SkASSERT(testProxy->backendFormat() == format);
60                 SkASSERT(testProxy->backendFormat().textureType() == type);
61             }
62         }
63     }
64 }
65 
checkAllInstantiated() const66 void GrProgramInfo::checkAllInstantiated() const {
67     if (this->hasFixedPrimProcTextures()) {
68         auto fixedPrimProcTextures = this->fixedPrimProcTextures();
69         for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
70             SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
71         }
72     }
73 
74     if (this->hasDynamicPrimProcTextures()) {
75         for (int m = 0; m < fNumDynamicStateArrays; ++m) {
76             auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
77             for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
78                 SkASSERT(dynamicPrimProcTextures[s]->isInstantiated());
79             }
80         }
81     }
82 }
83 
checkMSAAAndMIPSAreResolved() const84 void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
85     auto assertResolved = [](GrTexture* tex, GrSamplerState sampler) {
86         SkASSERT(tex);
87 
88         // Ensure mipmaps were all resolved ahead of time by the DAG.
89         if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
90             (tex->width() != 1 || tex->height() != 1)) {
91             // There are some cases where we might be given a non-mipmapped texture with a mipmap
92             // filter. See skbug.com/7094.
93             SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
94                      !tex->texturePriv().mipMapsAreDirty());
95         }
96     };
97 
98     if (this->hasDynamicPrimProcTextures()) {
99         for (int m = 0; m < fNumDynamicStateArrays; ++m) {
100             auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
101 
102             for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
103                 auto* tex = dynamicPrimProcTextures[s]->peekTexture();
104                 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
105             }
106         }
107     } else if (this->hasFixedPrimProcTextures()) {
108         auto fixedPrimProcTextures = this->fixedPrimProcTextures();
109 
110         for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
111             auto* tex = fixedPrimProcTextures[s]->peekTexture();
112             assertResolved(tex, this->primProc().textureSampler(s).samplerState());
113         }
114     }
115 
116     for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
117         assertResolved(sampler.peekTexture(), sampler.samplerState());
118     }
119 }
120 
121 #endif
122