blob: a646f56d6b0a2efe9cfb2756d0f4b222ed6812de [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
Robert Phillips2d8a95e2019-10-10 12:50:22 -040025#include "src/gpu/GrMesh.h"
Robert Phillips865d8d62019-10-09 14:15:55 -040026#include "src/gpu/GrTexturePriv.h"
27
28void GrProgramInfo::validate() const {
29 SkASSERT(!fPipeline.isBad());
30
31 if (this->hasDynamicPrimProcTextures()) {
32 SkASSERT(!this->hasFixedPrimProcTextures());
33 SkASSERT(fPrimProc.numTextureSamplers());
34 } else if (this->hasFixedPrimProcTextures()) {
35 SkASSERT(fPrimProc.numTextureSamplers());
36 } else {
37 SkASSERT(!fPrimProc.numTextureSamplers());
38 }
39
40 SkASSERT(!fPipeline.isScissorEnabled() || this->hasFixedScissor() ||
41 this->hasDynamicScissors());
Robert Phillips865d8d62019-10-09 14:15:55 -040042
43 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips865d8d62019-10-09 14:15:55 -040044 // Check that, for a given sampler, the properties of the dynamic textures remain
45 // the same for all the meshes
46 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
47 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0);
48
49 const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat();
50 GrTextureType type = dynamicPrimProcTextures[s]->textureType();
51 GrPixelConfig config = dynamicPrimProcTextures[s]->config();
52
Robert Phillips2d8a95e2019-10-10 12:50:22 -040053 for (int m = 1; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -040054 dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
55
56 auto testProxy = dynamicPrimProcTextures[s];
57 SkASSERT(testProxy->backendFormat() == format);
58 SkASSERT(testProxy->textureType() == type);
59 SkASSERT(testProxy->config() == config);
60 }
61 }
62 }
63}
64
Robert Phillips2d8a95e2019-10-10 12:50:22 -040065void GrProgramInfo::checkAllInstantiated() const {
66 if (this->hasFixedPrimProcTextures()) {
67 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
68 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
69 SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
70 }
71 }
72
73 if (this->hasDynamicPrimProcTextures()) {
74 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
75 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
76 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
77 SkASSERT(dynamicPrimProcTextures[s]->isInstantiated());
78 }
79 }
80 }
81}
82
83void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
Robert Phillips865d8d62019-10-09 14:15:55 -040084
85 auto assertResolved = [](GrTexture* tex, const 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()) {
Robert Phillips2d8a95e2019-10-10 12:50:22 -040099 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400100 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 GrFragmentProcessor::Iter iter(this->pipeline());
117 while (const GrFragmentProcessor* fp = iter.next()) {
118 for (int s = 0; s < fp->numTextureSamplers(); ++s) {
119 const auto& textureSampler = fp->textureSampler(s);
120 assertResolved(textureSampler.peekTexture(), textureSampler.samplerState());
121 }
122 }
123}
124
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400125void GrProgramInfo::compatibleWithMeshes(const GrMesh meshes[], int meshCount) const {
126 SkASSERT(!fNumDynamicStateArrays || meshCount == fNumDynamicStateArrays);
127
128 for (int i = 0; i < meshCount; ++i) {
129 SkASSERT(fPrimProc.hasVertexAttributes() == meshes[i].hasVertexData());
130 SkASSERT(fPrimProc.hasInstanceAttributes() == meshes[i].hasInstanceData());
131 }
132}
133
Robert Phillips865d8d62019-10-09 14:15:55 -0400134#endif