blob: bc36ae31979cb91c63b10b2f3236675100657c1d [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
Robert Phillips8053c972019-11-21 10:44:53 -050028void GrProgramInfo::validate(bool flushTime) const {
29 if (flushTime) {
30 SkASSERT(fPipeline->allProxiesInstantiated());
31 }
Robert Phillips865d8d62019-10-09 14:15:55 -040032
33 if (this->hasDynamicPrimProcTextures()) {
34 SkASSERT(!this->hasFixedPrimProcTextures());
Robert Phillips67a625e2019-11-15 15:37:07 -050035 SkASSERT(fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040036 } else if (this->hasFixedPrimProcTextures()) {
Robert Phillips67a625e2019-11-15 15:37:07 -050037 SkASSERT(fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040038 } else {
Robert Phillips67a625e2019-11-15 15:37:07 -050039 SkASSERT(!fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040040 }
41
Robert Phillips67a625e2019-11-15 15:37:07 -050042 SkASSERT(!fPipeline->isScissorEnabled() || this->hasFixedScissor() ||
Robert Phillips865d8d62019-10-09 14:15:55 -040043 this->hasDynamicScissors());
Robert Phillips865d8d62019-10-09 14:15:55 -040044
45 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips865d8d62019-10-09 14:15:55 -040046 // 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();
Michael Ludwigfcdd0612019-11-25 08:34:31 -050052 GrTextureType type = dynamicPrimProcTextures[s]->backendFormat().textureType();
Robert Phillips865d8d62019-10-09 14:15:55 -040053 GrPixelConfig config = dynamicPrimProcTextures[s]->config();
54
Robert Phillips2d8a95e2019-10-10 12:50:22 -040055 for (int m = 1; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -040056 dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
57
58 auto testProxy = dynamicPrimProcTextures[s];
Michael Ludwigfcdd0612019-11-25 08:34:31 -050059 SkASSERT(testProxy->asTextureProxy());
Robert Phillips865d8d62019-10-09 14:15:55 -040060 SkASSERT(testProxy->backendFormat() == format);
Michael Ludwigfcdd0612019-11-25 08:34:31 -050061 SkASSERT(testProxy->backendFormat().textureType() == type);
Robert Phillips865d8d62019-10-09 14:15:55 -040062 SkASSERT(testProxy->config() == config);
63 }
64 }
65 }
66}
67
Robert Phillips2d8a95e2019-10-10 12:50:22 -040068void GrProgramInfo::checkAllInstantiated() const {
69 if (this->hasFixedPrimProcTextures()) {
70 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
71 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
72 SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
73 }
74 }
75
76 if (this->hasDynamicPrimProcTextures()) {
77 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
78 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
79 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
80 SkASSERT(dynamicPrimProcTextures[s]->isInstantiated());
81 }
82 }
83 }
84}
85
86void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
Robert Phillips865d8d62019-10-09 14:15:55 -040087
88 auto assertResolved = [](GrTexture* tex, const GrSamplerState& sampler) {
89 SkASSERT(tex);
90
91 // Ensure mipmaps were all resolved ahead of time by the DAG.
92 if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
93 (tex->width() != 1 || tex->height() != 1)) {
94 // There are some cases where we might be given a non-mipmapped texture with a mipmap
95 // filter. See skbug.com/7094.
96 SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
97 !tex->texturePriv().mipMapsAreDirty());
98 }
99 };
100
101 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400102 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400103 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
104
105 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
106 auto* tex = dynamicPrimProcTextures[s]->peekTexture();
107 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
108 }
109 }
110 } else if (this->hasFixedPrimProcTextures()) {
111 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
112
113 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
114 auto* tex = fixedPrimProcTextures[s]->peekTexture();
115 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
116 }
117 }
118
Brian Salomonc241b582019-11-27 08:57:17 -0500119 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
120 assertResolved(sampler.peekTexture(), sampler.samplerState());
Robert Phillips865d8d62019-10-09 14:15:55 -0400121 }
122}
123
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400124void GrProgramInfo::compatibleWithMeshes(const GrMesh meshes[], int meshCount) const {
125 SkASSERT(!fNumDynamicStateArrays || meshCount == fNumDynamicStateArrays);
126
127 for (int i = 0; i < meshCount; ++i) {
Robert Phillips67a625e2019-11-15 15:37:07 -0500128 SkASSERT(fPrimProc->hasVertexAttributes() == meshes[i].hasVertexData());
129 SkASSERT(fPrimProc->hasInstanceAttributes() == meshes[i].hasInstanceData());
Chris Daltonce425af2019-12-16 10:39:03 -0700130 if (fPipeline->usesConservativeRaster()) {
131 // Conservative raster, by default, only supports triangles. Implementations can
132 // optionally indicate that they also support points and lines, but we don't currently
133 // query or track that info.
134 SkASSERT(GrIsPrimTypeTris(meshes[i].primitiveType()));
135 }
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400136 }
137}
138
Robert Phillips865d8d62019-10-09 14:15:55 -0400139#endif