blob: 929b7df31914f53ea1e048d362d48862c28d0ae3 [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 {
Brian Salomonccb61422020-01-09 10:46:36 -050087 auto assertResolved = [](GrTexture* tex, GrSamplerState sampler) {
Robert Phillips865d8d62019-10-09 14:15:55 -040088 SkASSERT(tex);
89
90 // Ensure mipmaps were all resolved ahead of time by the DAG.
91 if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
92 (tex->width() != 1 || tex->height() != 1)) {
93 // There are some cases where we might be given a non-mipmapped texture with a mipmap
94 // filter. See skbug.com/7094.
95 SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
96 !tex->texturePriv().mipMapsAreDirty());
97 }
98 };
99
100 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400101 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400102 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
103
104 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
105 auto* tex = dynamicPrimProcTextures[s]->peekTexture();
106 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
107 }
108 }
109 } else if (this->hasFixedPrimProcTextures()) {
110 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
111
112 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
113 auto* tex = fixedPrimProcTextures[s]->peekTexture();
114 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
115 }
116 }
117
Brian Salomonc241b582019-11-27 08:57:17 -0500118 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
119 assertResolved(sampler.peekTexture(), sampler.samplerState());
Robert Phillips865d8d62019-10-09 14:15:55 -0400120 }
121}
122
Chris Dalton5a2f9622019-12-27 14:56:38 -0700123void GrProgramInfo::compatibleWithMeshes(const GrMesh meshes[], int meshCount,
124 const GrCaps& caps) const {
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400125 SkASSERT(!fNumDynamicStateArrays || meshCount == fNumDynamicStateArrays);
126
127 for (int i = 0; i < meshCount; ++i) {
Chris Dalton5a2f9622019-12-27 14:56:38 -0700128 SkASSERT(fPrimitiveType == meshes[i].primitiveType());
129 if (GrPrimitiveType::kPatches == fPrimitiveType) {
130 SkASSERT(fTessellationPatchVertexCount == meshes[i].tessellationPatchVertexCount());
131 }
Chris Dalton34280e22019-12-20 11:08:25 -0700132 SkASSERT(fPrimProc->hasVertexAttributes() == SkToBool(meshes[i].vertexBuffer()));
133 SkASSERT(fPrimProc->hasInstanceAttributes() == SkToBool(meshes[i].instanceBuffer()));
Chris Daltonce425af2019-12-16 10:39:03 -0700134 if (fPipeline->usesConservativeRaster()) {
135 // Conservative raster, by default, only supports triangles. Implementations can
136 // optionally indicate that they also support points and lines, but we don't currently
137 // query or track that info.
138 SkASSERT(GrIsPrimTypeTris(meshes[i].primitiveType()));
139 }
Chris Dalton5a2f9622019-12-27 14:56:38 -0700140 SkASSERT(GrPrimitiveType::kPatches != meshes[i].primitiveType() ||
141 caps.shaderCaps()->tessellationSupport());
142 SkASSERT(GrPrimitiveRestart::kNo == meshes[i].primitiveRestart() ||
143 caps.usePrimitiveRestart());
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400144 }
145}
146
Robert Phillips865d8d62019-10-09 14:15:55 -0400147#endif