blob: 7fb105378221010067fe910c7decf77619353f8d [file] [log] [blame]
Robert Phillips865d8d62019-10-09 14:15:55 -04001/*
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
Robert Phillipsa87c5292019-11-12 10:12:42 -050010#include "src/gpu/GrStencilSettings.h"
11
12GrStencilSettings 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}
Robert Phillips865d8d62019-10-09 14:15:55 -040023
24#ifdef SK_DEBUG
25#include "src/gpu/GrTexturePriv.h"
26
Robert Phillips8053c972019-11-21 10:44:53 -050027void GrProgramInfo::validate(bool flushTime) const {
28 if (flushTime) {
29 SkASSERT(fPipeline->allProxiesInstantiated());
30 }
Robert Phillips865d8d62019-10-09 14:15:55 -040031
Chris Dalton3bf2f3a2020-03-17 11:48:23 -060032 if (this->hasFixedPrimProcTextures()) {
Robert Phillips67a625e2019-11-15 15:37:07 -050033 SkASSERT(fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040034 }
35
Chris Dalton012f8492020-03-05 11:49:15 -070036 if (!fPipeline->isScissorTestEnabled()) {
Chris Dalton3bf2f3a2020-03-17 11:48:23 -060037 SkASSERT(!this->hasFixedScissor());
Robert Phillips865d8d62019-10-09 14:15:55 -040038 }
39}
40
Robert Phillips2d8a95e2019-10-10 12:50:22 -040041void GrProgramInfo::checkAllInstantiated() const {
42 if (this->hasFixedPrimProcTextures()) {
43 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
44 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
45 SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
46 }
47 }
Chris Dalton3bf2f3a2020-03-17 11:48:23 -060048 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
49 SkASSERT(sampler.proxy()->isInstantiated());
Robert Phillips2d8a95e2019-10-10 12:50:22 -040050 }
51}
52
53void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
Brian Salomonccb61422020-01-09 10:46:36 -050054 auto assertResolved = [](GrTexture* tex, GrSamplerState sampler) {
Robert Phillips865d8d62019-10-09 14:15:55 -040055 SkASSERT(tex);
56
57 // Ensure mipmaps were all resolved ahead of time by the DAG.
58 if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
59 (tex->width() != 1 || tex->height() != 1)) {
60 // There are some cases where we might be given a non-mipmapped texture with a mipmap
61 // filter. See skbug.com/7094.
62 SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
63 !tex->texturePriv().mipMapsAreDirty());
64 }
65 };
66
Chris Dalton3bf2f3a2020-03-17 11:48:23 -060067 if (this->hasFixedPrimProcTextures()) {
Robert Phillips865d8d62019-10-09 14:15:55 -040068 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
69
70 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
71 auto* tex = fixedPrimProcTextures[s]->peekTexture();
72 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
73 }
74 }
75
Brian Salomonc241b582019-11-27 08:57:17 -050076 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
77 assertResolved(sampler.peekTexture(), sampler.samplerState());
Robert Phillips865d8d62019-10-09 14:15:55 -040078 }
79}
80
Robert Phillips865d8d62019-10-09 14:15:55 -040081#endif