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